Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use gz::utils::ImplPtr as much as possible #583

Merged
merged 4 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ namespace gz::gui

/// \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_
16 changes: 2 additions & 14 deletions include/gz/gui/Dialog.hh
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +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
{
class DialogPrivate;

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

/// \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_
16 changes: 2 additions & 14 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,8 @@ namespace gz::gui

/// \internal
/// \brief Private data pointer
private: std::unique_ptr<MainWindowPrivate> dataPtr;
/// Private is necessary here for the Qt MOC
private: GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
};

/// \brief Holds configurations related to a MainWindow.
Expand Down Expand Up @@ -675,9 +668,4 @@ namespace gz::gui
std::string plugins{""};
};
} // namespace gz::gui

#ifdef _MSC_VER
#pragma warning(pop)
#endif

#endif // GZ_GUI_MAINWINDOW_HH_
20 changes: 8 additions & 12 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,7 +323,8 @@ class GZ_GUI_VISIBLE PlottingInterface : public QObject
public slots: void UpdateTime();

/// \brief Private data member.
private: std::unique_ptr<PlottingIfacePrivate> dataPtr;
/// Private is necessary here for the Qt MOC
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 @@ -103,14 +95,11 @@ namespace gz::gui
/// \sa Load
/// \param[in] _pluginElem Element containing configuration
protected: virtual void LoadConfig(
const tinyxml2::XMLElement *_pluginElem)
{
(void)_pluginElem;
}
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,12 +131,7 @@ namespace gz::gui

/// \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_
6 changes: 3 additions & 3 deletions src/Application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

namespace gz::gui
{
class ApplicationPrivate
class Application::Implementation
{
/// \brief QML engine
public: QQmlApplicationEngine *engine{nullptr};
Expand Down Expand Up @@ -91,7 +91,7 @@ enum class GZ_COMMON_HIDDEN AvailableAPIs
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
5 changes: 3 additions & 2 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 Down
28 changes: 15 additions & 13 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 @@ -74,21 +85,12 @@ class MainWindowPrivate
public: std::string controlService{"/server_control"};

/// \brief Communication node
public: gz::transport::Node node;
public: gz::transport::Node node {gz::transport::NodeOptions()};
};

/// \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 Down
Loading