Skip to content

Commit

Permalink
Change main gui classes to implptr
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll committed Oct 5, 2023
1 parent 8b9677b commit f3e8923
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 116 deletions.
15 changes: 2 additions & 13 deletions include/gz/gui/Application.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@
#include "gz/gui/qt.h"
#include "gz/gui/Export.hh"

#ifdef _WIN32
// Disable warning C4251 which is triggered by
// std::unique_ptr
#pragma warning(push)
#pragma warning(disable: 4251)
#endif
#include <gz/utils/ImplPtr.hh>

namespace tinyxml2
{
Expand All @@ -39,7 +34,6 @@ namespace tinyxml2

namespace gz::gui
{
class ApplicationPrivate;
class Dialog;
class MainWindow;
class Plugin;
Expand Down Expand Up @@ -208,17 +202,12 @@ class GZ_GUI_VISIBLE Application : public QApplication

/// \internal
/// \brief Private data pointer
private: std::unique_ptr<ApplicationPrivate> dataPtr;
GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
};

/// \brief Get current running application, this is a cast of qGuiApp.
/// \return Pointer to running application, or nullptr if none is running.
GZ_GUI_VISIBLE
Application *App();
} // namespace gz::gui

#ifdef _MSC_VER
#pragma warning(pop)
#endif

#endif // GZ_GUI_APPLICATION_HH_
17 changes: 2 additions & 15 deletions include/gz/gui/Dialog.hh
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,10 @@
#include "gz/gui/qt.h"
#include "gz/gui/Export.hh"

#ifdef _WIN32
// Disable warning C4251 which is triggered by
// std::unique_ptr
#pragma warning(push)
#pragma warning(disable: 4251)
#endif
#include <gz/utils/ImplPtr.hh>

namespace gz::gui
{
/// Forward declarations
class DialogPrivate;

/// \brief Gui plugin
class GZ_GUI_VISIBLE Dialog : public QObject
{
Expand Down Expand Up @@ -91,12 +83,7 @@ class GZ_GUI_VISIBLE Dialog : public QObject

/// \internal
/// \brief Private data pointer
private: std::unique_ptr<DialogPrivate> dataPtr;
GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
};
} // namespace gz::gui

#ifdef _MSC_VER
#pragma warning(pop)
#endif

#endif // GZ_GUI_DIALOG_HH_
10 changes: 1 addition & 9 deletions include/gz/gui/MainWindow.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,9 @@
#include "gz/gui/qt.h"
#include "gz/gui/Export.hh"

#ifdef _WIN32
// Disable warning C4251 which is triggered by
// std::unique_ptr
#pragma warning(push)
#pragma warning(disable: 4251)
#endif

namespace gz::gui
{
Q_NAMESPACE
class MainWindowPrivate;
struct WindowConfig;

/// \brief The action executed when GUI is closed without prompt.
Expand Down Expand Up @@ -583,7 +575,7 @@ class GZ_GUI_VISIBLE MainWindow : public QObject

/// \internal
/// \brief Private data pointer
private: std::unique_ptr<MainWindowPrivate> dataPtr;
private: GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
};

/// \brief Holds configurations related to a MainWindow.
Expand Down
20 changes: 7 additions & 13 deletions include/gz/gui/PlottingInterface.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@

#include "gz/gui/Export.hh"

#include <gz/utils/ImplPtr.hh>

namespace gz::gui
{
class PlotDataPrivate;

/// \brief Plot Data containter to hold value and registered charts
/// Can be a Field or a PlotComponent
/// Used by PlottingInterface and Gazebo Plotting
Expand Down Expand Up @@ -85,11 +85,9 @@ class GZ_GUI_VISIBLE PlotData
public: std::set<int> &Charts();

/// \brief Private data member.
private: std::unique_ptr<PlotDataPrivate> dataPtr;
GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
};

class TopicPrivate;

/// \brief Plotting Topic to handle published topics & their registered fields
class GZ_GUI_VISIBLE Topic : public QObject
{
Expand Down Expand Up @@ -149,11 +147,9 @@ class GZ_GUI_VISIBLE Topic : public QObject
public: void SetPlottingTimeRef(const std::shared_ptr<double> &_time);

/// \brief Private data member.
private: std::unique_ptr<TopicPrivate> dataPtr;
GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
};

class TransportPrivate;

/// \brief Handle transport topics subscribing for one object (Chart)
class GZ_GUI_VISIBLE Transport : public QObject
{
Expand Down Expand Up @@ -203,12 +199,11 @@ class GZ_GUI_VISIBLE Transport : public QObject
/// \param[in] _y y coordinates of the plot point
signals: void plot(int _chart, QString _fieldID, double _x, double _y);

private:
/// \brief Private data member.
private: std::unique_ptr<TransportPrivate> dataPtr;
GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
};

class PlottingIfacePrivate;

/// \brief Plotting Interface
/// Responsible for plotting transport msgs-fields
/// Used by TransportPlotting Plugin & GazeboPlotting Plugin
Expand Down Expand Up @@ -328,8 +323,7 @@ class GZ_GUI_VISIBLE PlottingInterface : public QObject
public slots: void UpdateTime();

/// \brief Private data member.
private: std::unique_ptr<PlottingIfacePrivate> dataPtr;
private: GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
};

} // namespace gz::gui
#endif // GZ_GUI_PLOTTINGINTERFACE_HH_
24 changes: 4 additions & 20 deletions include/gz/gui/Plugin.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,18 @@
#define GZ_GUI_PLUGIN_HH_

#include <tinyxml2.h>
#include <gz/utils/ImplPtr.hh>
#include <memory>
#include <string>

#include "gz/gui/qt.h"
#include "gz/gui/Export.hh"

#ifdef _WIN32
// Disable warning C4251 which is triggered by
// std::unique_ptr
#pragma warning(push)
#pragma warning(disable: 4251)
#endif

namespace gz::gui
{
/// \brief Namespace for all plugins
namespace plugins {}

class PluginPrivate;

/// \brief Base class for Gazebo GUI plugins.
///
/// When inheriting from this plugin, the following are assumed:
Expand Down Expand Up @@ -102,15 +94,11 @@ class GZ_GUI_VISIBLE Plugin : public QObject
///
/// \sa Load
/// \param[in] _pluginElem Element containing configuration
protected: virtual void LoadConfig(
const tinyxml2::XMLElement *_pluginElem)
{
(void)_pluginElem;
}
protected: virtual void LoadConfig(const tinyxml2::XMLElement *_pluginElem);

/// \brief Get title
/// \return Plugin title.
public: virtual std::string Title() const {return this->title;}
public: virtual std::string Title() const;

/// \brief Get the value of the the `delete_later` element from the
/// configuration file, which defaults to false.
Expand Down Expand Up @@ -142,11 +130,7 @@ class GZ_GUI_VISIBLE Plugin : public QObject

/// \internal
/// \brief Pointer to private data
private: std::unique_ptr<PluginPrivate> dataPtr;
GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
};
} // namespace gz::gui

#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif // GZ_GUI_PLUGIN_HH_
8 changes: 4 additions & 4 deletions src/Application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ enum class GZ_COMMON_HIDDEN AvailableAPIs

namespace gz::gui
{
class ApplicationPrivate
class Application::Implementation
{
/// \brief QML engine
public: QQmlApplicationEngine *engine{nullptr};
Expand Down Expand Up @@ -91,7 +91,7 @@ class ApplicationPrivate
Application::Application(int &_argc, char **_argv, const WindowType _type,
const char *_renderEngineGuiApiBackend) :
QApplication(_argc, _argv),
dataPtr(new ApplicationPrivate)
dataPtr(gz::utils::MakeUniqueImpl<Implementation>())
{
gzdbg << "Initializing application." << std::endl;

Expand Down Expand Up @@ -880,7 +880,7 @@ void Application::RemovePlugin(std::shared_ptr<Plugin> _plugin)
}

//////////////////////////////////////////////////
void ApplicationPrivate::MessageHandler(QtMsgType _type,
void Application::Implementation::MessageHandler(QtMsgType _type,
const QMessageLogContext &_context, const QString &_msg)
{
std::string msg = "[QT] " + _msg.toStdString();
Expand Down Expand Up @@ -908,4 +908,4 @@ void ApplicationPrivate::MessageHandler(QtMsgType _type,
break;
}
}
} // namepace gz::gui
} // namespace gz::gui
9 changes: 4 additions & 5 deletions src/Dialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@
#include <tinyxml2.h>

#include <gz/common/Console.hh>
#include <gz/utils/ImplPtr.hh>
#include "gz/gui/Application.hh"
#include "gz/gui/Dialog.hh"

namespace gz::gui
{
class DialogPrivate
class Dialog::Implementation
{
/// \brief Pointer to quick window
public: QQuickWindow *quickWindow{nullptr};
};

/////////////////////////////////////////////////
Dialog::Dialog()
: dataPtr(new DialogPrivate)
: dataPtr(gz::utils::MakeUniqueImpl<Implementation>())
{
// Load QML and keep pointer to generated QQuickWindow
std::string qmlFile("qrc:qml/StandaloneDialog.qml");
Expand All @@ -50,9 +51,7 @@ Dialog::Dialog()
}

/////////////////////////////////////////////////
Dialog::~Dialog()
{
}
Dialog::~Dialog() = default;

/////////////////////////////////////////////////
QQuickWindow *Dialog::QuickWindow() const
Expand Down
30 changes: 15 additions & 15 deletions src/MainWindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include <tinyxml2.h>
#include <gz/utils/ImplPtr.hh>
#include <regex>
#include <string>

Expand All @@ -29,11 +30,21 @@
#include "gz/msgs/server_control.pb.h"
#include "gz/transport/Node.hh"

namespace {
/// \brief Strip last component from a path.
/// \return Original path without its last component.
/// \ToDo: Move this function to common::Filesystem
std::string dirName(const std::string &_path)
{
std::size_t found = _path.find_last_of("/\\");
return _path.substr(0, found);
}
} // namespace

namespace gz::gui
{
class MainWindowPrivate
class MainWindow::Implementation
{
/// \brief Number of plugins on the window
public: int pluginCount{0};

/// \brief Pointer to quick window
Expand Down Expand Up @@ -77,18 +88,9 @@ class MainWindowPrivate
public: gz::transport::Node node;
};

/// \brief Strip last component from a path.
/// \return Original path without its last component.
/// \ToDo: Move this function to common::Filesystem
std::string dirName(const std::string &_path)
{
std::size_t found = _path.find_last_of("/\\");
return _path.substr(0, found);
}

/////////////////////////////////////////////////
MainWindow::MainWindow()
: dataPtr(new MainWindowPrivate)
: dataPtr(gz::utils::MakeUniqueImpl<Implementation>())
{
// Expose the ExitAction enum to QML via ExitAction 1.0 module
qRegisterMetaType<ExitAction>("ExitAction");
Expand All @@ -115,9 +117,7 @@ MainWindow::MainWindow()
}

/////////////////////////////////////////////////
MainWindow::~MainWindow()
{
}
MainWindow::~MainWindow() = default;

/////////////////////////////////////////////////
QStringList MainWindow::PluginListModel() const
Expand Down
Loading

0 comments on commit f3e8923

Please sign in to comment.