diff --git a/include/gz/gui/Application.hh b/include/gz/gui/Application.hh index d557cb2d8..662a62725 100644 --- a/include/gz/gui/Application.hh +++ b/include/gz/gui/Application.hh @@ -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 namespace tinyxml2 { @@ -39,7 +34,6 @@ namespace tinyxml2 namespace gz::gui { -class ApplicationPrivate; class Dialog; class MainWindow; class Plugin; @@ -208,7 +202,7 @@ class GZ_GUI_VISIBLE Application : public QApplication /// \internal /// \brief Private data pointer - private: std::unique_ptr dataPtr; + GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr) }; /// \brief Get current running application, this is a cast of qGuiApp. @@ -216,9 +210,4 @@ class GZ_GUI_VISIBLE Application : public QApplication GZ_GUI_VISIBLE Application *App(); } // namespace gz::gui - -#ifdef _MSC_VER -#pragma warning(pop) -#endif - #endif // GZ_GUI_APPLICATION_HH_ diff --git a/include/gz/gui/Dialog.hh b/include/gz/gui/Dialog.hh index ad366037e..04a165607 100644 --- a/include/gz/gui/Dialog.hh +++ b/include/gz/gui/Dialog.hh @@ -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 namespace gz::gui { -/// Forward declarations -class DialogPrivate; - /// \brief Gui plugin class GZ_GUI_VISIBLE Dialog : public QObject { @@ -91,12 +83,7 @@ class GZ_GUI_VISIBLE Dialog : public QObject /// \internal /// \brief Private data pointer - private: std::unique_ptr dataPtr; + GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr) }; } // namespace gz::gui - -#ifdef _MSC_VER -#pragma warning(pop) -#endif - #endif // GZ_GUI_DIALOG_HH_ diff --git a/include/gz/gui/MainWindow.hh b/include/gz/gui/MainWindow.hh index 58bd9584d..a970f2654 100644 --- a/include/gz/gui/MainWindow.hh +++ b/include/gz/gui/MainWindow.hh @@ -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. @@ -583,7 +575,7 @@ class GZ_GUI_VISIBLE MainWindow : public QObject /// \internal /// \brief Private data pointer - private: std::unique_ptr dataPtr; + private: GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr) }; /// \brief Holds configurations related to a MainWindow. diff --git a/include/gz/gui/PlottingInterface.hh b/include/gz/gui/PlottingInterface.hh index fefd6c3e3..85b7ae2e5 100644 --- a/include/gz/gui/PlottingInterface.hh +++ b/include/gz/gui/PlottingInterface.hh @@ -38,10 +38,10 @@ #include "gz/gui/Export.hh" +#include + 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 @@ -85,11 +85,9 @@ class GZ_GUI_VISIBLE PlotData public: std::set &Charts(); /// \brief Private data member. - private: std::unique_ptr 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 { @@ -149,11 +147,9 @@ class GZ_GUI_VISIBLE Topic : public QObject public: void SetPlottingTimeRef(const std::shared_ptr &_time); /// \brief Private data member. - private: std::unique_ptr 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 { @@ -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 dataPtr; + GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr) }; -class PlottingIfacePrivate; - /// \brief Plotting Interface /// Responsible for plotting transport msgs-fields /// Used by TransportPlotting Plugin & GazeboPlotting Plugin @@ -328,8 +323,7 @@ class GZ_GUI_VISIBLE PlottingInterface : public QObject public slots: void UpdateTime(); /// \brief Private data member. - private: std::unique_ptr dataPtr; + private: GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr) }; - } // namespace gz::gui #endif // GZ_GUI_PLOTTINGINTERFACE_HH_ diff --git a/include/gz/gui/Plugin.hh b/include/gz/gui/Plugin.hh index 323ac37d8..5d608c807 100644 --- a/include/gz/gui/Plugin.hh +++ b/include/gz/gui/Plugin.hh @@ -18,26 +18,18 @@ #define GZ_GUI_PLUGIN_HH_ #include +#include #include #include #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: @@ -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. @@ -142,11 +130,7 @@ class GZ_GUI_VISIBLE Plugin : public QObject /// \internal /// \brief Pointer to private data - private: std::unique_ptr dataPtr; + GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr) }; } // namespace gz::gui - -#ifdef _MSC_VER -#pragma warning(pop) -#endif #endif // GZ_GUI_PLUGIN_HH_ diff --git a/src/Application.cc b/src/Application.cc index e1e18cf78..397b343ba 100644 --- a/src/Application.cc +++ b/src/Application.cc @@ -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}; @@ -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()) { gzdbg << "Initializing application." << std::endl; @@ -880,7 +880,7 @@ void Application::RemovePlugin(std::shared_ptr _plugin) } ////////////////////////////////////////////////// -void ApplicationPrivate::MessageHandler(QtMsgType _type, +void Application::Implementation::MessageHandler(QtMsgType _type, const QMessageLogContext &_context, const QString &_msg) { std::string msg = "[QT] " + _msg.toStdString(); @@ -908,4 +908,4 @@ void ApplicationPrivate::MessageHandler(QtMsgType _type, break; } } -} // namepace gz::gui +} // namespace gz::gui diff --git a/src/Dialog.cc b/src/Dialog.cc index 796dfed39..7701c2cfd 100644 --- a/src/Dialog.cc +++ b/src/Dialog.cc @@ -18,12 +18,13 @@ #include #include +#include #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}; @@ -31,7 +32,7 @@ class DialogPrivate ///////////////////////////////////////////////// Dialog::Dialog() - : dataPtr(new DialogPrivate) + : dataPtr(gz::utils::MakeUniqueImpl()) { // Load QML and keep pointer to generated QQuickWindow std::string qmlFile("qrc:qml/StandaloneDialog.qml"); @@ -50,9 +51,7 @@ Dialog::Dialog() } ///////////////////////////////////////////////// -Dialog::~Dialog() -{ -} +Dialog::~Dialog() = default; ///////////////////////////////////////////////// QQuickWindow *Dialog::QuickWindow() const diff --git a/src/MainWindow.cc b/src/MainWindow.cc index ec009c0af..df1e0fe5f 100644 --- a/src/MainWindow.cc +++ b/src/MainWindow.cc @@ -16,6 +16,7 @@ */ #include +#include #include #include @@ -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 @@ -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()) { // Expose the ExitAction enum to QML via ExitAction 1.0 module qRegisterMetaType("ExitAction"); @@ -115,9 +117,7 @@ MainWindow::MainWindow() } ///////////////////////////////////////////////// -MainWindow::~MainWindow() -{ -} +MainWindow::~MainWindow() = default; ///////////////////////////////////////////////// QStringList MainWindow::PluginListModel() const diff --git a/src/PlottingInterface.cc b/src/PlottingInterface.cc index 3c8f69359..1feea96b6 100644 --- a/src/PlottingInterface.cc +++ b/src/PlottingInterface.cc @@ -25,13 +25,15 @@ #include "gz/gui/PlottingInterface.hh" #include "gz/gui/Application.hh" +#include + #define DEFAULT_TIME (INT_MIN) // 1/60 Period like the GuiSystem frequency (60Hz) #define MAX_PERIOD_DIFF (0.0166666667) namespace gz::gui { -class PlotDataPrivate +class PlotData::Implementation { /// \brief Value of that field public: double value; @@ -43,8 +45,7 @@ class PlotDataPrivate public: std::set charts; }; - -class TopicPrivate +class Topic::Implementation { /// \brief Check the plotable types and get data from reflection /// \param[in] _msg Message to get data from @@ -66,7 +67,7 @@ class TopicPrivate public: std::map fields; }; -class TransportPrivate +class Transport::Implementation { /// \brief Node for Commincation public: gz::transport::Node node; @@ -75,7 +76,7 @@ class TransportPrivate public: std::map topics; }; -class PlottingIfacePrivate +class PlottingInterface::Implementation { /// \brief Responsible for transport messages and topics public: Transport transport; @@ -87,20 +88,18 @@ class PlottingIfacePrivate public: int timeout; /// \brief timer to update the plotting each time step - public: QTimer timer; + public: QTimer timer {nullptr}; }; ////////////////////////////////////////////////////// PlotData::PlotData() : - dataPtr(std::make_unique()) + dataPtr(gz::utils::MakeUniqueImpl()) { this->dataPtr->value = 0; } ////////////////////////////////////////////////////// -PlotData::~PlotData() -{ -} +PlotData::~PlotData() = default; ////////////////////////////////////////////////////// void PlotData::SetValue(const double _value) @@ -153,8 +152,8 @@ std::set &PlotData::Charts() } ////////////////////////////////////////////////////// -Topic::Topic(const std::string &_name) : QObject(), - dataPtr(std::make_unique()) +Topic::Topic(const std::string &_name): + dataPtr(gz::utils::MakeUniqueImpl()) { this->dataPtr->name = _name; } @@ -364,7 +363,7 @@ void Topic::SetPlottingTimeRef(const std::shared_ptr &_timeRef) } ////////////////////////////////////////////////////// -double TopicPrivate::FieldData(const google::protobuf::Message &_msg, +double Topic::Implementation::FieldData(const google::protobuf::Message &_msg, const google::protobuf::FieldDescriptor *_field) { using namespace google::protobuf; @@ -393,7 +392,8 @@ double TopicPrivate::FieldData(const google::protobuf::Message &_msg, } //////////////////////////////////////////// -Transport::Transport() : dataPtr(std::make_unique()) +Transport::Transport(): + dataPtr(gz::utils::MakeUniqueImpl()) { } @@ -484,7 +484,7 @@ void Transport::UnsubscribeOutdatedTopics() ////////////////////////////////////////////////////// PlottingInterface::PlottingInterface() : QObject(), - dataPtr(std::make_unique()) + dataPtr(gz::utils::MakeUniqueImpl()) { connect(&this->dataPtr->transport, SIGNAL(plot(int, QString, double, double)), this, diff --git a/src/Plugin.cc b/src/Plugin.cc index fbdc02762..2f9e7855d 100644 --- a/src/Plugin.cc +++ b/src/Plugin.cc @@ -15,6 +15,7 @@ * */ +#include #include #include @@ -23,6 +24,8 @@ #include "gz/gui/MainWindow.hh" #include "gz/gui/Plugin.hh" +namespace +{ /// \brief Used to store information about anchors set by the user. struct Anchors { @@ -36,7 +39,7 @@ struct Anchors }; /// \brief Set of all possible lines. -static const std::unordered_set kAnchorLineSet{ +const std::unordered_set kAnchorLineSet{ "top", "bottom", "left", @@ -46,14 +49,15 @@ static const std::unordered_set kAnchorLineSet{ "baseline"}; /// \brief Properties which shouldn't be saved or loaded -static const std::unordered_set kIgnoredProps{ +const std::unordered_set kIgnoredProps{ "objectName", "pluginName", "anchored"}; +} // namespace namespace gz::gui { -class PluginPrivate +class Plugin::Implementation { /// \brief Set this to true if the plugin should be deleted as soon as it has /// a parent. @@ -82,11 +86,8 @@ class PluginPrivate public: Anchors anchors; }; -using namespace gz; -using namespace gui; - ///////////////////////////////////////////////// -Plugin::Plugin() : dataPtr(new PluginPrivate) +Plugin::Plugin() : dataPtr(gz::utils::MakeUniqueImpl()) { } @@ -517,6 +518,17 @@ void Plugin::PostParentChanges() } } +///////////////////////////////////////////////// +void Plugin::LoadConfig(const tinyxml2::XMLElement *_pluginElem) +{ + (void) _pluginElem; +} + +///////////////////////////////////////////////// +std::string Plugin::Title() const { + return this->title; +} + ///////////////////////////////////////////////// void Plugin::ApplyAnchors() {