From 187bbf1c5195da23b7e978e9bd5e9e4abcbf428a Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Thu, 5 Oct 2023 20:41:22 +0000 Subject: [PATCH] Tidy namespaces Signed-off-by: Michael Carroll --- include/gz/gui/Application.hh | 361 +++++---- include/gz/gui/Conversions.hh | 119 ++- include/gz/gui/Dialog.hh | 128 ++- include/gz/gui/DragDropModel.hh | 25 +- include/gz/gui/Enums.hh | 97 ++- include/gz/gui/GuiEvents.hh | 901 +++++++++++---------- include/gz/gui/Helpers.hh | 191 +++-- include/gz/gui/MainWindow.hh | 1145 +++++++++++++-------------- include/gz/gui/PlottingInterface.hh | 10 +- include/gz/gui/Plugin.hh | 232 +++--- include/gz/gui/SearchModel.hh | 119 ++- include/gz/gui/gz.hh | 2 +- src/Application.cc | 82 +- src/Application_TEST.cc | 37 +- src/Conversions.cc | 22 +- src/Dialog.cc | 20 +- src/DragDropModel.cc | 7 +- src/GuiEvents.cc | 48 +- src/Helpers.cc | 24 +- src/MainWindow.cc | 74 +- src/PlottingInterface.cc | 11 +- src/Plugin.cc | 5 +- src/SearchModel.cc | 7 +- 23 files changed, 1808 insertions(+), 1859 deletions(-) diff --git a/include/gz/gui/Application.hh b/include/gz/gui/Application.hh index edabeee15..d557cb2d8 100644 --- a/include/gz/gui/Application.hh +++ b/include/gz/gui/Application.hh @@ -37,191 +37,188 @@ namespace tinyxml2 class XMLElement; } -namespace gz +namespace gz::gui { - namespace gui - { - class ApplicationPrivate; - class Dialog; - class MainWindow; - class Plugin; - - /// \brief Type of window which the application will display - enum class WindowType : int - { - /// \brief A main window, which may contain top-level menus and multiple - /// plugins - kMainWindow = 0, - - /// \brief One independent dialog per plugin. Also useful to open a - /// startup dialog before the main window. - kDialog = 1 - }; - - /// \brief A Gazebo GUI application loads a QML engine and - /// provides an API to load plugins and configuration files. The application - /// supports either running a single main window or several plugins as - /// standalone dialogs. - class GZ_GUI_VISIBLE Application : public QApplication - { - Q_OBJECT - - /// \brief Constructor. - /// \param[in] _argc Argument count. - /// \param[in] _argv Argument values. - /// \param[in] _type Window type, by default it's a main window. - /// \param[in] _renderEngineGuiApiBackend --render-engine-gui-api-backend - /// option - public: Application(int &_argc, char **_argv, - const WindowType _type = WindowType::kMainWindow, - const char *_renderEngineGuiApiBackend = nullptr); - - /// \brief Destructor - public: virtual ~Application(); - - /// \brief Get the QML engine - /// \return Pointer to QML engine - public: QQmlApplicationEngine *Engine() const; - - /// \brief Load a plugin from a file name. The plugin file must be in the - /// path. - /// If a window has been initialized, the plugin is added to the window. - /// Otherwise, the plugin is stored and can be later added to a window or - /// dialog. - /// \param[in] _filename Plugin filename. - /// \param[in] _pluginElem Element containing plugin configuration - /// \return True if successful - /// \sa LoadConfig - /// \sa AddPluginsToWindow - public: bool LoadPlugin(const std::string &_filename, - const tinyxml2::XMLElement *_pluginElem = nullptr); - - /// \brief Load a configuration file, which includes window configurations - /// and plugins. This function doesn't instantiate the plugins, it just - /// keeps them in memory and they can be applied later by either - /// instantiating a window or several dialogs. - /// \param[in] _path Full path to configuration file. - /// \return True if successful - /// \sa InitializeMainWindow - /// \sa InitializeDialogs - public: bool LoadConfig(const std::string &_path); - - /// \brief Load the configuration from the default config file. - /// \return True if successful - /// \sa SetDefaultConfigPath - /// \sa DefaultConfigPath - /// \sa LoadConfig - public: bool LoadDefaultConfig(); - - /// \brief Specifies the location of the default configuration file. - /// This is the file that stores the user settings when pressing - /// "Save configuration". - /// \param[in] _path The default configuration full path including - /// filename. - /// \sa LoadDefaultConfig - /// \sa defaultConfigPath - public: void SetDefaultConfigPath(const std::string &_path); - - /// \brief Get the location of the default configuration file. - /// \return The default configuration path. - /// \sa LoadDefaultConfig - /// \sa SetDefaultConfigPath - public: std::string DefaultConfigPath(); - - /// \brief Set the environment variable which defines the paths to - /// look for plugins. - /// \param[in] _env Name of environment variable. - public: void SetPluginPathEnv(const std::string &_env); - - /// \brief Add an path to look for plugins. - /// \param[in] _path Full path. - public: void AddPluginPath(const std::string &_path); - - /// \brief Get the list of available plugins, organized by path. The - /// paths are given in the following order: - /// - /// 1. Paths given by the environment variable - /// 2. Paths added by calling addPluginPath - /// 3. Path ~/.gz/gui/plugins - /// 4. The path where Gazebo GUI plugins are installed - /// - /// \return A vector of pairs, where each pair contains: - /// * A path - /// * A vector of plugins in that path - public: std::vector>> - PluginList(); - - /// \brief Remove plugin by name. The plugin is removed from the - /// application and its shared library unloaded if this was its last - /// instance. - /// \param[in] _pluginName Plugn instance's unique name. This is the - /// plugin card's object name. - /// \return True if successful - public: bool RemovePlugin(const std::string &_pluginName); - - /// \brief Get a plugin by its unique name. - /// \param[in] _pluginName Plugn instance's unique name. This is the - /// plugin card's object name. - /// \return Pointer to plugin object, null if not found. - public: std::shared_ptr PluginByName( - const std::string &_pluginName) const; - - /// \brief Notify that a plugin has been added. - /// \param[in] _objectName Plugin's object name. - signals: void PluginAdded(const QString &_objectName); - - /// \brief Callback when user requests to close a plugin - public slots: void OnPluginClose(); - - /// \brief Create a main window. Just calls InitializeMainWindow. - /// \return True if successful - /// \sa InitializeMainWindow - public: bool CreateMainWindow(); - - /// \brief Create a main window, populate with previously loaded plugins - /// and apply previously loaded configuration. - /// An empty window will be created if no plugins have been loaded. - /// \return True if successful - /// \sa LoadConfig - /// \sa LoadPlugin - private: bool InitializeMainWindow(); - - /// \brief Create individual dialogs for all previously loaded plugins. - /// This has no effect if no plugins have been loaded. - /// \return True if successful - /// \sa LoadConfig - /// \sa LoadPlugin - private: bool InitializeDialogs(); - - /// \brief Remove plugin by pointer. - /// \param[in] _plugin Shared pointer to plugin - private: void RemovePlugin(std::shared_ptr _plugin); - - /// \brief Add previously loaded plugins to the main window. - /// \return True if successful. Will fail if the window hasn't been - /// created yet. - /// \sa LoadPlugin - private: bool AddPluginsToWindow(); - - /// \brief Apply previously loaded config to the main window. - /// \return True if successful, will fail if there's no main window - /// initialized. - private: bool ApplyConfig(); - - /// \internal - /// \brief Private data pointer - private: std::unique_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(); - } -} +class ApplicationPrivate; +class Dialog; +class MainWindow; +class Plugin; + +/// \brief Type of window which the application will display +enum class WindowType : int +{ + /// \brief A main window, which may contain top-level menus and multiple + /// plugins + kMainWindow = 0, + + /// \brief One independent dialog per plugin. Also useful to open a + /// startup dialog before the main window. + kDialog = 1 +}; + +/// \brief A Gazebo GUI application loads a QML engine and +/// provides an API to load plugins and configuration files. The application +/// supports either running a single main window or several plugins as +/// standalone dialogs. +class GZ_GUI_VISIBLE Application : public QApplication +{ + Q_OBJECT + + /// \brief Constructor. + /// \param[in] _argc Argument count. + /// \param[in] _argv Argument values. + /// \param[in] _type Window type, by default it's a main window. + /// \param[in] _renderEngineGuiApiBackend --render-engine-gui-api-backend + /// option + public: Application(int &_argc, char **_argv, + const WindowType _type = WindowType::kMainWindow, + const char *_renderEngineGuiApiBackend = nullptr); + + /// \brief Destructor + public: virtual ~Application(); + + /// \brief Get the QML engine + /// \return Pointer to QML engine + public: QQmlApplicationEngine *Engine() const; + + /// \brief Load a plugin from a file name. The plugin file must be in the + /// path. + /// If a window has been initialized, the plugin is added to the window. + /// Otherwise, the plugin is stored and can be later added to a window or + /// dialog. + /// \param[in] _filename Plugin filename. + /// \param[in] _pluginElem Element containing plugin configuration + /// \return True if successful + /// \sa LoadConfig + /// \sa AddPluginsToWindow + public: bool LoadPlugin(const std::string &_filename, + const tinyxml2::XMLElement *_pluginElem = nullptr); + + /// \brief Load a configuration file, which includes window configurations + /// and plugins. This function doesn't instantiate the plugins, it just + /// keeps them in memory and they can be applied later by either + /// instantiating a window or several dialogs. + /// \param[in] _path Full path to configuration file. + /// \return True if successful + /// \sa InitializeMainWindow + /// \sa InitializeDialogs + public: bool LoadConfig(const std::string &_path); + + /// \brief Load the configuration from the default config file. + /// \return True if successful + /// \sa SetDefaultConfigPath + /// \sa DefaultConfigPath + /// \sa LoadConfig + public: bool LoadDefaultConfig(); + + /// \brief Specifies the location of the default configuration file. + /// This is the file that stores the user settings when pressing + /// "Save configuration". + /// \param[in] _path The default configuration full path including + /// filename. + /// \sa LoadDefaultConfig + /// \sa defaultConfigPath + public: void SetDefaultConfigPath(const std::string &_path); + + /// \brief Get the location of the default configuration file. + /// \return The default configuration path. + /// \sa LoadDefaultConfig + /// \sa SetDefaultConfigPath + public: std::string DefaultConfigPath(); + + /// \brief Set the environment variable which defines the paths to + /// look for plugins. + /// \param[in] _env Name of environment variable. + public: void SetPluginPathEnv(const std::string &_env); + + /// \brief Add an path to look for plugins. + /// \param[in] _path Full path. + public: void AddPluginPath(const std::string &_path); + + /// \brief Get the list of available plugins, organized by path. The + /// paths are given in the following order: + /// + /// 1. Paths given by the environment variable + /// 2. Paths added by calling addPluginPath + /// 3. Path ~/.gz/gui/plugins + /// 4. The path where Gazebo GUI plugins are installed + /// + /// \return A vector of pairs, where each pair contains: + /// * A path + /// * A vector of plugins in that path + public: std::vector>> + PluginList(); + + /// \brief Remove plugin by name. The plugin is removed from the + /// application and its shared library unloaded if this was its last + /// instance. + /// \param[in] _pluginName Plugn instance's unique name. This is the + /// plugin card's object name. + /// \return True if successful + public: bool RemovePlugin(const std::string &_pluginName); + + /// \brief Get a plugin by its unique name. + /// \param[in] _pluginName Plugn instance's unique name. This is the + /// plugin card's object name. + /// \return Pointer to plugin object, null if not found. + public: std::shared_ptr PluginByName( + const std::string &_pluginName) const; + + /// \brief Notify that a plugin has been added. + /// \param[in] _objectName Plugin's object name. + signals: void PluginAdded(const QString &_objectName); + + /// \brief Callback when user requests to close a plugin + public slots: void OnPluginClose(); + + /// \brief Create a main window. Just calls InitializeMainWindow. + /// \return True if successful + /// \sa InitializeMainWindow + public: bool CreateMainWindow(); + + /// \brief Create a main window, populate with previously loaded plugins + /// and apply previously loaded configuration. + /// An empty window will be created if no plugins have been loaded. + /// \return True if successful + /// \sa LoadConfig + /// \sa LoadPlugin + private: bool InitializeMainWindow(); + + /// \brief Create individual dialogs for all previously loaded plugins. + /// This has no effect if no plugins have been loaded. + /// \return True if successful + /// \sa LoadConfig + /// \sa LoadPlugin + private: bool InitializeDialogs(); + + /// \brief Remove plugin by pointer. + /// \param[in] _plugin Shared pointer to plugin + private: void RemovePlugin(std::shared_ptr _plugin); + + /// \brief Add previously loaded plugins to the main window. + /// \return True if successful. Will fail if the window hasn't been + /// created yet. + /// \sa LoadPlugin + private: bool AddPluginsToWindow(); + + /// \brief Apply previously loaded config to the main window. + /// \return True if successful, will fail if there's no main window + /// initialized. + private: bool ApplyConfig(); + + /// \internal + /// \brief Private data pointer + private: std::unique_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 +#endif // GZ_GUI_APPLICATION_HH_ diff --git a/include/gz/gui/Conversions.hh b/include/gz/gui/Conversions.hh index 5ea10f116..7ea7a4fe5 100644 --- a/include/gz/gui/Conversions.hh +++ b/include/gz/gui/Conversions.hh @@ -27,74 +27,71 @@ #include "gz/gui/qt.h" #include "gz/gui/Export.hh" -namespace gz +namespace gz::common { - namespace common - { - class MouseEvent; - } +class MouseEvent; +} // namespace gz::common - namespace gui - { - /// \brief Return the equivalent Qt color - /// \param[in] _color Gazebo color to convert - /// \return Qt color value - GZ_GUI_VISIBLE - QColor convert(const math::Color &_color); +namespace gz::gui +{ +/// \brief Return the equivalent Qt color +/// \param[in] _color Gazebo color to convert +/// \return Qt color value +GZ_GUI_VISIBLE +QColor convert(const math::Color &_color); - /// \brief Return the equivalent Gazebo color - /// \param[in] _color Qt color to convert - /// \return Gazebo color value - GZ_GUI_VISIBLE - math::Color convert(const QColor &_color); +/// \brief Return the equivalent Gazebo color +/// \param[in] _color Qt color to convert +/// \return Gazebo color value +GZ_GUI_VISIBLE +math::Color convert(const QColor &_color); - /// \brief Return the equivalent QPointF. - /// \param[in] _pt Gazebo vector to convert. - /// \return QPointF. - GZ_GUI_VISIBLE - QPointF convert(const math::Vector2d &_pt); +/// \brief Return the equivalent QPointF. +/// \param[in] _pt Gazebo vector to convert. +/// \return QPointF. +GZ_GUI_VISIBLE +QPointF convert(const math::Vector2d &_pt); - /// \brief Return the equivalent Gazebo vector. - /// \param[in] _pt QPointF to convert - /// \return Gazebo Vector2d. - GZ_GUI_VISIBLE - math::Vector2d convert(const QPointF &_pt); +/// \brief Return the equivalent Gazebo vector. +/// \param[in] _pt QPointF to convert +/// \return Gazebo Vector2d. +GZ_GUI_VISIBLE +math::Vector2d convert(const QPointF &_pt); - /// \brief Return the equivalent Qt vector 3d. - /// \param[in] _vec Gazebo vector 3d to convert. - /// \return Qt vector 3d value. - GZ_GUI_VISIBLE - QVector3D convert(const math::Vector3d &_vec); +/// \brief Return the equivalent Qt vector 3d. +/// \param[in] _vec Gazebo vector 3d to convert. +/// \return Qt vector 3d value. +GZ_GUI_VISIBLE +QVector3D convert(const math::Vector3d &_vec); - /// \brief Return the equivalent Gazebo vector 3d. - /// \param[in] _vec Qt vector 3d to convert. - /// \return Gazebo vector 3d value - GZ_GUI_VISIBLE - math::Vector3d convert(const QVector3D &_vec); +/// \brief Return the equivalent Gazebo vector 3d. +/// \param[in] _vec Qt vector 3d to convert. +/// \return Gazebo vector 3d value +GZ_GUI_VISIBLE +math::Vector3d convert(const QVector3D &_vec); - /// \brief Return the equivalent Gazebo mouse event. - /// - /// Note that there isn't a 1-1 mapping between these types, so fields such - /// as common::MouseEvent::PressPos need to be set afterwards. - /// \param[in] _e Qt mouse event - /// \return Gazebo mouse event - GZ_GUI_VISIBLE - common::MouseEvent convert(const QMouseEvent &_e); +/// \brief Return the equivalent Gazebo mouse event. +/// +/// Note that there isn't a 1-1 mapping between these types, so fields such +/// as common::MouseEvent::PressPos need to be set afterwards. +/// \param[in] _e Qt mouse event +/// \return Gazebo mouse event +GZ_GUI_VISIBLE +common::MouseEvent convert(const QMouseEvent &_e); - /// \brief Return the equivalent Gazebo mouse event. - /// - /// Note that there isn't a 1-1 mapping between these types. - /// \param[in] _e Qt wheel event - /// \return Gazebo mouse event - GZ_GUI_VISIBLE - common::MouseEvent convert(const QWheelEvent &_e); +/// \brief Return the equivalent Gazebo mouse event. +/// +/// Note that there isn't a 1-1 mapping between these types. +/// \param[in] _e Qt wheel event +/// \return Gazebo mouse event +GZ_GUI_VISIBLE +common::MouseEvent convert(const QWheelEvent &_e); - /// \brief Return the equivalent Gazebo key event. - /// - /// \param[in] _e Qt key event - /// \return Gazebo key event - GZ_GUI_VISIBLE - common::KeyEvent convert(const QKeyEvent &_e); - } -} -#endif +/// \brief Return the equivalent Gazebo key event. +/// +/// \param[in] _e Qt key event +/// \return Gazebo key event +GZ_GUI_VISIBLE +common::KeyEvent convert(const QKeyEvent &_e); +} // namespace gz::gui +#endif // GZ_GUI_CONVERSIONS_HH_ diff --git a/include/gz/gui/Dialog.hh b/include/gz/gui/Dialog.hh index 2719c32f3..ad366037e 100644 --- a/include/gz/gui/Dialog.hh +++ b/include/gz/gui/Dialog.hh @@ -31,74 +31,72 @@ #pragma warning(disable: 4251) #endif -namespace gz +namespace gz::gui { - namespace gui - { - class DialogPrivate; - - /// \brief Gui plugin - class GZ_GUI_VISIBLE Dialog : public QObject - { - Q_OBJECT - - /// \brief Constructor - public: Dialog(); - - /// \brief Destructor - public: virtual ~Dialog(); - - /// \brief Get the QtQuick window created by this object - /// \return Pointer to the QtQuick window - public: QQuickWindow *QuickWindow() const; - - /// \brief Get the root quick item of this window - /// \return Pointer to the item - public: QQuickItem *RootItem() const; - - /// \brief Store dialog default config - /// \param[in] _config XML config as string - /// \deprecated Introduce deprecation warnings on v7. - public: void SetDefaultConfig(const std::string &_config); - - /// \brief Update an attribute on an XML file. The attribute belongs to - /// a `` element that has a `name` attrbute matching this dialog's - /// name, i.e. - /// - /// `` - /// - /// If a dialog element with this dialog's name doesn't exist yet, one - /// will be created. - /// - /// \param[in] _path File path. File must already exist, this function - /// will not create a new file. - /// \param[in] _attribute XMLElement attribute name - /// \param[in] _value XMLElement attribute value - /// \return True if written to config file - public: bool UpdateConfigAttribute( - const std::string &_path, const std::string &_attribute, - const bool _value) const; - - /// \brief Gets an attribute value from an XML file. The attribute belongs - /// to a `` element that has a `name` attribute matching this - /// dialog's name. - /// It will return an empty string if the file or the attribute - /// don't exist. - /// \param[in] _path File path - /// \param[in] _attribute attribute name - /// \return Attribute value as string - public: std::string ReadConfigAttribute(const std::string &_path, - const std::string &_attribute) const; - - /// \internal - /// \brief Private data pointer - private: std::unique_ptr dataPtr; - }; - } -} +/// Forward declarations +class DialogPrivate; + +/// \brief Gui plugin +class GZ_GUI_VISIBLE Dialog : public QObject +{ + Q_OBJECT + + /// \brief Constructor + public: Dialog(); + + /// \brief Destructor + public: virtual ~Dialog(); + + /// \brief Get the QtQuick window created by this object + /// \return Pointer to the QtQuick window + public: QQuickWindow *QuickWindow() const; + + /// \brief Get the root quick item of this window + /// \return Pointer to the item + public: QQuickItem *RootItem() const; + + /// \brief Store dialog default config + /// \param[in] _config XML config as string + /// \deprecated Introduce deprecation warnings on v7. + public: void SetDefaultConfig(const std::string &_config); + + /// \brief Update an attribute on an XML file. The attribute belongs to + /// a `` element that has a `name` attrbute matching this dialog's + /// name, i.e. + /// + /// `` + /// + /// If a dialog element with this dialog's name doesn't exist yet, one + /// will be created. + /// + /// \param[in] _path File path. File must already exist, this function + /// will not create a new file. + /// \param[in] _attribute XMLElement attribute name + /// \param[in] _value XMLElement attribute value + /// \return True if written to config file + public: bool UpdateConfigAttribute( + const std::string &_path, const std::string &_attribute, + const bool _value) const; + + /// \brief Gets an attribute value from an XML file. The attribute belongs + /// to a `` element that has a `name` attribute matching this + /// dialog's name. + /// It will return an empty string if the file or the attribute + /// don't exist. + /// \param[in] _path File path + /// \param[in] _attribute attribute name + /// \return Attribute value as string + public: std::string ReadConfigAttribute(const std::string &_path, + const std::string &_attribute) const; + + /// \internal + /// \brief Private data pointer + private: std::unique_ptr dataPtr; +}; +} // namespace gz::gui #ifdef _MSC_VER #pragma warning(pop) #endif -#endif +#endif // GZ_GUI_DIALOG_HH_ diff --git a/include/gz/gui/DragDropModel.hh b/include/gz/gui/DragDropModel.hh index b4ffa0271..ba70b2f5e 100644 --- a/include/gz/gui/DragDropModel.hh +++ b/include/gz/gui/DragDropModel.hh @@ -20,19 +20,16 @@ #include "gz/gui/Export.hh" #include "gz/gui/qt.h" -namespace gz +namespace gz::gui { -namespace gui +/// \brief Customized item model so that we can pass along an URI query as +/// MIME information during a drag-drop. +class GZ_GUI_VISIBLE DragDropModel : public QStandardItemModel { - /// \brief Customized item model so that we can pass along an URI query as - /// MIME information during a drag-drop. - class GZ_GUI_VISIBLE DragDropModel : public QStandardItemModel - { - /// \brief Overloaded from Qt. Custom MIME data function. - /// \param[in] _indexes List of selected items. - /// \return Mime data for the selected items. - public: QMimeData *mimeData(const QModelIndexList &_indexes) const; - }; -} -} -#endif + /// \brief Overloaded from Qt. Custom MIME data function. + /// \param[in] _indexes List of selected items. + /// \return Mime data for the selected items. + public: QMimeData *mimeData(const QModelIndexList &_indexes) const; +}; +} // namespace gz::gui +#endif // GZ_GUI_DRAGDROPMODEL_HH_ diff --git a/include/gz/gui/Enums.hh b/include/gz/gui/Enums.hh index b612fe6ea..3760d58a4 100644 --- a/include/gz/gui/Enums.hh +++ b/include/gz/gui/Enums.hh @@ -20,67 +20,64 @@ #include "gz/gui/qt.h" -namespace gz +namespace gz::gui { -namespace gui +/// \brief Data roles +enum DataRole { - /// \brief Data roles - enum DataRole - { - /// \brief Text which is displayed for the user. - DISPLAY_NAME = Qt::UserRole + 100, + /// \brief Text which is displayed for the user. + DISPLAY_NAME = Qt::UserRole + 100, - /// \brief URI including detailed query. This is the information carried - /// during a drag-drop operation. - URI_QUERY, + /// \brief URI including detailed query. This is the information carried + /// during a drag-drop operation. + URI_QUERY, - /// \brief Data type name, such as "Double" or "Bool", or "model", "link". - /// Used to specialize display according to type. - TYPE, + /// \brief Data type name, such as "Double" or "Bool", or "model", "link". + /// Used to specialize display according to type. + TYPE, - /// \brief Flag indicating whether an item should be expanded or not. - TO_EXPAND - }; + /// \brief Flag indicating whether an item should be expanded or not. + TO_EXPAND +}; - /// \brief String types - enum class StringType - { - /// \brief Undefined type - NONE, +/// \brief String types +enum class StringType +{ + /// \brief Undefined type + NONE, - /// \brief Use line for short strings which usually fit in a single - /// line. - LINE, + /// \brief Use line for short strings which usually fit in a single + /// line. + LINE, - /// \brief Use text for longer strings which span multiple lines. - PLAIN_TEXT - }; + /// \brief Use text for longer strings which span multiple lines. + PLAIN_TEXT +}; - /// \brief Number types - enum class NumberType - { - /// \brief Undefined type - NONE, +/// \brief Number types +enum class NumberType +{ + /// \brief Undefined type + NONE, - /// \brief Double - DOUBLE, + /// \brief Double + DOUBLE, - /// \brief Integer - INT, + /// \brief Integer + INT, - /// \brief Unsigned integer - UINT - }; + /// \brief Unsigned integer + UINT +}; - /// \brief File types - enum FileType - { - /// \brief Comma separated value (CSV) - CSVFile, +/// \brief File types +enum FileType +{ + /// \brief Comma separated value (CSV) + CSVFile, - /// \brief Portable document format (PDF) - PDFFile - }; -} -} -#endif + /// \brief Portable document format (PDF) + PDFFile +}; +} // namespace gz::gui +#endif // GZ_GUI_ENUMS_HH_ diff --git a/include/gz/gui/GuiEvents.hh b/include/gz/gui/GuiEvents.hh index fb5cf2efe..588b794ba 100644 --- a/include/gz/gui/GuiEvents.hh +++ b/include/gz/gui/GuiEvents.hh @@ -32,462 +32,455 @@ #include "gz/gui/Export.hh" -namespace gz +namespace gz::gui::events { - namespace gui + +/// User defined events should start from QEvent::MaxUser and +/// count down to avoid collision with gz-sim events + +/// \brief Event called in the render thread of a 3D scene after the user +/// camera has rendered. +/// It's safe to make rendering calls in this event's callback. +class Render : public QEvent +{ + public: Render() + : QEvent(kType) { - /// \brief Namespace for all events. - namespace events - { - /// User defined events should start from QEvent::MaxUser and - /// count down to avoid collision with gz-sim events - - /// \brief Event called in the render thread of a 3D scene after the user - /// camera has rendered. - /// It's safe to make rendering calls in this event's callback. - class Render : public QEvent - { - public: Render() - : QEvent(kType) - { - } - /// \brief Unique type for this event. - static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser); - }; - - /// \brief The class for sending and receiving custom snap value events. - /// This event is used in the Transform Control plugin tool when the - /// user manually alters their snapping values. - class GZ_GUI_VISIBLE SnapIntervals : public QEvent - { - /// \brief Constructor - /// \param[in] _xyz XYZ snapping values. - /// \param[in] _rpy RPY snapping values. - /// \param[in] _scale Scale snapping values. - public: SnapIntervals( - const math::Vector3d &_xyz, - const math::Vector3d &_rpy, - const math::Vector3d &_scale); - - /// \brief Get the XYZ snapping values. - /// \return The XYZ snapping values. - public: math::Vector3d Position() const; - - /// \brief Get the RPY snapping values. - /// \return The RPY snapping values. - public: math::Vector3d Rotation() const; - - /// \brief Get the scale snapping values. - /// \return The scale snapping values. - public: math::Vector3d Scale() const; - - /// \brief The QEvent representing a snap event occurrence. - static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 1); - - /// \internal - /// \brief Private data pointer - GZ_UTILS_IMPL_PTR(dataPtr) - }; - - /// \brief Event called to spawn a resource, given its description as a - /// string. - class GZ_GUI_VISIBLE SpawnFromDescription : public QEvent - { - /// \brief Constructor - /// \param[in] _description The resource's description as a string, such - /// as an SDF file. - public: explicit SpawnFromDescription(const std::string &_description); - - /// \brief Unique type for this event. - static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 2); - - /// \brief Get the string description of the resource. - /// \return The resource string - public: const std::string &Description() const; - - /// \internal - /// \brief Private data pointer - GZ_UTILS_IMPL_PTR(dataPtr) - }; - - /// \brief Event called to spawn a resource, which takes the path - /// to its file. - class GZ_GUI_VISIBLE SpawnFromPath : public QEvent - { - /// \brief Constructor - /// \param[in] _filePath The path to a file. - public: explicit SpawnFromPath(const std::string &_filePath); - - /// \brief Unique type for this event. - static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 3); - - /// \brief Get the path of the file. - /// \return The file path. - public: const std::string &FilePath() const; - - /// \internal - /// \brief Private data pointer - GZ_UTILS_IMPL_PTR(dataPtr) - }; - - /// \brief Event which is called to broadcast the 3D coordinates of a - /// user's mouse hover within the scene. - class GZ_GUI_VISIBLE HoverToScene : public QEvent - { - /// \brief Constructor - /// \param[in] _point The point at which the mouse is hovering within - /// the scene - public: explicit HoverToScene(const math::Vector3d &_point); - - /// \brief Unique type for this event. - static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 4); - - /// \brief Get the point within the scene over which the user is - /// hovering. - /// \return The 3D point - public: math::Vector3d Point() const; - - /// \internal - /// \brief Private data pointer - GZ_UTILS_IMPL_PTR(dataPtr) - }; - - /// \brief Event which is called to broadcast the 3D coordinates of a - /// user's releasing the left button within the scene. - /// \sa LeftClickOnScene - class GZ_GUI_VISIBLE LeftClickToScene : public QEvent - { - /// \brief Constructor - /// \param[in] _point The point which the user has left clicked within - /// the scene - public: explicit LeftClickToScene(const math::Vector3d &_point); - - /// \brief Unique type for this event. - static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 5); - - /// \brief Get the point within the scene that the user clicked. - /// \return The 3D point. - public: math::Vector3d Point() const; - - /// \internal - /// \brief Private data pointer - GZ_UTILS_IMPL_PTR(dataPtr) - }; - - /// \brief Event which is called to broadcast the 3D coordinates of a - /// user's releasing the right button within the scene. - /// \sa RightClickOnScene - class GZ_GUI_VISIBLE RightClickToScene : public QEvent - { - /// \brief Constructor - /// \param[in] _point The point which the user has right clicked - /// within the scene - public: explicit RightClickToScene(const math::Vector3d &_point); - - /// \brief Unique type for this event. - static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 6); - - /// \brief Get the point within the scene that the user clicked. - /// \return The 3D point. - public: math::Vector3d Point() const; - - /// \internal - /// \brief Private data pointer - GZ_UTILS_IMPL_PTR(dataPtr) - }; - - /// \brief Event which is called to enable or disable the dropdown menu. - /// This is primarily used by plugins which also use the right click - /// mouse event to cancel any actions currently in progress. - class GZ_GUI_VISIBLE DropdownMenuEnabled : public QEvent - { - /// \brief Constructor - /// \param[in] _menuEnabled The boolean indicating whether the dropdown - /// menu should be enabled or disabled. - public: explicit DropdownMenuEnabled(bool _menuEnabled); - - /// \brief Unique type for this event. - static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 7); - - /// \brief Gets whether the menu is enabled or not for this event. - /// \return True if enabling the menu, false if disabling the menu - public: bool MenuEnabled() const; - - /// \internal - /// \brief Private data pointer - GZ_UTILS_IMPL_PTR(dataPtr) - }; - - /// \brief Event which is called to broadcast the key release within - /// the scene. - class GZ_GUI_VISIBLE KeyReleaseOnScene : public QEvent - { - /// \brief Constructor - /// \param[in] _key The key released event within the scene - public: explicit KeyReleaseOnScene(const common::KeyEvent &_key); - - /// \brief Unique type for this event. - static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 8); - - /// \brief Get the released key within the scene that the user released. - /// \return The key code. - public: common::KeyEvent Key() const; - - /// \internal - /// \brief Private data pointer - GZ_UTILS_IMPL_PTR(dataPtr) - }; - - /// \brief Event which is called to broadcast the key press within - /// the scene. - class GZ_GUI_VISIBLE KeyPressOnScene : public QEvent - { - /// \brief Constructor - /// \param[in] _key The pressed key within the scene - public: explicit KeyPressOnScene(const common::KeyEvent &_key); - - /// \brief Unique type for this event. - static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 9); - - /// \brief Get the key within the scene that the user pressed - /// \return The key code. - public: common::KeyEvent Key() const; - - /// \internal - /// \brief Private data pointer - GZ_UTILS_IMPL_PTR(dataPtr) - }; - - /// \brief Event which is called to broadcast information about left - /// mouse releases on the scene. - /// For the 3D coordinates of that point on the scene, see - /// `LeftClickToScene`. - /// \sa LeftClickToScene - class GZ_GUI_VISIBLE LeftClickOnScene : public QEvent - { - /// \brief Constructor - /// \param[in] _mouse The left mouse event on the scene - public: explicit LeftClickOnScene( - const common::MouseEvent &_mouse); - - /// \brief Unique type for this event. - static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 10); - - /// \brief Return the left mouse event - public: const common::MouseEvent &Mouse() const; - - /// \internal - /// \brief Private data pointer - GZ_UTILS_IMPL_PTR(dataPtr) - }; - - /// \brief Event which is called to broadcast information about right - /// mouse releases on the scene. - /// For the 3D coordinates of that point on the scene, see - /// `RightClickToScene`. - /// \sa RightClickToScene - class GZ_GUI_VISIBLE RightClickOnScene : public QEvent - { - /// \brief Constructor - /// \param[in] _mouse The right mouse event on the scene - public: RightClickOnScene( - const common::MouseEvent &_mouse); - - /// \brief Unique type for this event. - static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 11); - - /// \brief Return the right mouse event - public: const common::MouseEvent &Mouse() const; - - /// \internal - /// \brief Private data pointer - GZ_UTILS_IMPL_PTR(dataPtr) - }; - - /// \brief Event that block the Interactive View control when some of the - /// other plugins require it. For example: When the transform control is - /// active we should block the movements of the camera. - class GZ_GUI_VISIBLE BlockOrbit : public QEvent - { - /// \brief Constructor - /// \param[in] _block True to block otherwise False - public: explicit BlockOrbit(const bool &_block); - - /// \brief Unique type for this event. - static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 12); - - /// \brief Get the if the event should block the Interactive view - /// controller - /// \return True to block otherwise False. - public: bool Block() const; - - /// \internal - /// \brief Private data pointer - GZ_UTILS_IMPL_PTR(dataPtr) - }; - - /// \brief Event which is called to broadcast the 2D coordinates of a - /// user's mouse hover within the scene. - class GZ_GUI_VISIBLE HoverOnScene : public QEvent - { - /// \brief Constructor - /// \param[in] _mouse The hover mouse event on the scene - public: explicit HoverOnScene(const common::MouseEvent &_mouse); - - /// \brief Unique type for this event. - static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 13); - - /// \brief Get the point within the scene over which the user is - /// hovering. - /// \return The 2D point - public: common::MouseEvent Mouse() const; - - /// \internal - /// \brief Private data pointer - GZ_UTILS_IMPL_PTR(dataPtr) - }; - - /// \brief Event called to clone a resource, given its name as a string. - class GZ_GUI_VISIBLE SpawnCloneFromName : public QEvent - { - /// \brief Constructor - /// \param[in] _name The name of the resource to clone - public: explicit SpawnCloneFromName(const std::string &_name); - - /// \brief Unique type for this event. - static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 14); - - /// \brief Get the name of the resource to be cloned - /// \return The name of the resource to be cloned - public: const std::string &Name() const; - - /// \internal - /// \brief Private data pointer - GZ_UTILS_IMPL_PTR(dataPtr) - }; - - /// \brief Event called to clone a resource, given its name as a string. - class GZ_GUI_VISIBLE DropOnScene : public QEvent - { - /// \brief Constructor - /// \param[in] _dropText Dropped string. - /// \param[in] _dropMouse x and y coordinate of mouse position. - public: explicit DropOnScene( - const std::string &_dropText, - const math::Vector2i &_dropMouse); - - /// \brief Get the text of the dropped thing on the scene - /// \return The name of the dropped thing on the scene - public: const std::string &DropText() const; - - /// \brief Get X and Y position - /// \return Get X and Y position - public: const math::Vector2i &Mouse() const; - - /// \brief Unique type for this event. - static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 15); - - /// \internal - /// \brief Private data pointer - GZ_UTILS_IMPL_PTR(dataPtr) - }; - - /// \brief Event which is called to broadcast information about mouse - /// scrolls on the scene. - class GZ_GUI_VISIBLE ScrollOnScene : public QEvent - { - /// \brief Constructor - /// \param[in] _mouse The scroll mouse event on the scene - public: explicit ScrollOnScene(const common::MouseEvent &_mouse); - - /// \brief Unique type for this event. - static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 16); - - /// \brief Return the scroll mouse event - public: const common::MouseEvent &Mouse() const; - - /// \internal - /// \brief Private data pointer - GZ_UTILS_IMPL_PTR(dataPtr) - }; - - /// \brief Event which is called to broadcast information about mouse - /// drags on the scene. - class GZ_GUI_VISIBLE DragOnScene : public QEvent - { - /// \brief Constructor - /// \param[in] _mouse The drag mouse event on the scene - public: explicit DragOnScene(const common::MouseEvent &_mouse); - - /// \brief Unique type for this event. - static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 17); - - /// \brief Get the point within the scene over which the user is - /// dragging. - /// \return The 2D point - public: common::MouseEvent Mouse() const; - - /// \internal - /// \brief Private data pointer - GZ_UTILS_IMPL_PTR(dataPtr) - }; - - /// \brief Event which is called to broadcast information about mouse - /// presses on the scene, with right, left or middle buttons. - class GZ_GUI_VISIBLE MousePressOnScene : public QEvent - { - /// \brief Constructor - /// \param[in] _mouse The mouse event on the scene - public: MousePressOnScene( - const common::MouseEvent &_mouse); - - /// \brief Unique type for this event. - static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 18); - - /// \brief Return the button press mouse event - public: const common::MouseEvent &Mouse() const; - - /// \internal - /// \brief Private data pointer - GZ_UTILS_IMPL_PTR(dataPtr) - }; - - /// \brief Event which is called to share WorldControl information. - class GZ_GUI_VISIBLE WorldControl : public QEvent - { - /// \brief Constructor - /// \param[in] _worldControl The WorldControl information - public: explicit WorldControl(const msgs::WorldControl &_worldControl); - - /// \brief Unique type for this event. - static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 19); - - /// \brief Get the WorldControl information - /// \return The WorldControl information - public: const msgs::WorldControl &WorldControlInfo() const; - - /// \internal - /// \brief Private data pointer - GZ_UTILS_IMPL_PTR(dataPtr) - }; - - /// \brief Event called in the render thread of a 3D scene, before the - /// user camera is rendered. - /// It's safe to make rendering calls in this event's callback. - class GZ_GUI_VISIBLE PreRender : public QEvent - { - /// \brief Constructor - public: PreRender(); - - /// \brief Unique type for this event. - static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 20); - - /// \internal - /// \brief Private data pointer - GZ_UTILS_IMPL_PTR(dataPtr) - }; - } } -} + /// \brief Unique type for this event. + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser); +}; + +/// \brief The class for sending and receiving custom snap value events. +/// This event is used in the Transform Control plugin tool when the +/// user manually alters their snapping values. +class GZ_GUI_VISIBLE SnapIntervals : public QEvent +{ + /// \brief Constructor + /// \param[in] _xyz XYZ snapping values. + /// \param[in] _rpy RPY snapping values. + /// \param[in] _scale Scale snapping values. + public: SnapIntervals( + const math::Vector3d &_xyz, + const math::Vector3d &_rpy, + const math::Vector3d &_scale); + + /// \brief Get the XYZ snapping values. + /// \return The XYZ snapping values. + public: math::Vector3d Position() const; + + /// \brief Get the RPY snapping values. + /// \return The RPY snapping values. + public: math::Vector3d Rotation() const; + + /// \brief Get the scale snapping values. + /// \return The scale snapping values. + public: math::Vector3d Scale() const; + + /// \brief The QEvent representing a snap event occurrence. + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 1); + + /// \internal + /// \brief Private data pointer + GZ_UTILS_IMPL_PTR(dataPtr) +}; + +/// \brief Event called to spawn a resource, given its description as a +/// string. +class GZ_GUI_VISIBLE SpawnFromDescription : public QEvent +{ + /// \brief Constructor + /// \param[in] _description The resource's description as a string, such + /// as an SDF file. + public: explicit SpawnFromDescription(const std::string &_description); + + /// \brief Unique type for this event. + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 2); + + /// \brief Get the string description of the resource. + /// \return The resource string + public: const std::string &Description() const; + + /// \internal + /// \brief Private data pointer + GZ_UTILS_IMPL_PTR(dataPtr) +}; + +/// \brief Event called to spawn a resource, which takes the path +/// to its file. +class GZ_GUI_VISIBLE SpawnFromPath : public QEvent +{ + /// \brief Constructor + /// \param[in] _filePath The path to a file. + public: explicit SpawnFromPath(const std::string &_filePath); + + /// \brief Unique type for this event. + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 3); + + /// \brief Get the path of the file. + /// \return The file path. + public: const std::string &FilePath() const; + + /// \internal + /// \brief Private data pointer + GZ_UTILS_IMPL_PTR(dataPtr) +}; + +/// \brief Event which is called to broadcast the 3D coordinates of a +/// user's mouse hover within the scene. +class GZ_GUI_VISIBLE HoverToScene : public QEvent +{ + /// \brief Constructor + /// \param[in] _point The point at which the mouse is hovering within + /// the scene + public: explicit HoverToScene(const math::Vector3d &_point); + + /// \brief Unique type for this event. + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 4); + + /// \brief Get the point within the scene over which the user is + /// hovering. + /// \return The 3D point + public: math::Vector3d Point() const; + + /// \internal + /// \brief Private data pointer + GZ_UTILS_IMPL_PTR(dataPtr) +}; + +/// \brief Event which is called to broadcast the 3D coordinates of a +/// user's releasing the left button within the scene. +/// \sa LeftClickOnScene +class GZ_GUI_VISIBLE LeftClickToScene : public QEvent +{ + /// \brief Constructor + /// \param[in] _point The point which the user has left clicked within + /// the scene + public: explicit LeftClickToScene(const math::Vector3d &_point); + + /// \brief Unique type for this event. + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 5); + + /// \brief Get the point within the scene that the user clicked. + /// \return The 3D point. + public: math::Vector3d Point() const; + + /// \internal + /// \brief Private data pointer + GZ_UTILS_IMPL_PTR(dataPtr) +}; + +/// \brief Event which is called to broadcast the 3D coordinates of a +/// user's releasing the right button within the scene. +/// \sa RightClickOnScene +class GZ_GUI_VISIBLE RightClickToScene : public QEvent +{ + /// \brief Constructor + /// \param[in] _point The point which the user has right clicked + /// within the scene + public: explicit RightClickToScene(const math::Vector3d &_point); + + /// \brief Unique type for this event. + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 6); + + /// \brief Get the point within the scene that the user clicked. + /// \return The 3D point. + public: math::Vector3d Point() const; + + /// \internal + /// \brief Private data pointer + GZ_UTILS_IMPL_PTR(dataPtr) +}; + +/// \brief Event which is called to enable or disable the dropdown menu. +/// This is primarily used by plugins which also use the right click +/// mouse event to cancel any actions currently in progress. +class GZ_GUI_VISIBLE DropdownMenuEnabled : public QEvent +{ + /// \brief Constructor + /// \param[in] _menuEnabled The boolean indicating whether the dropdown + /// menu should be enabled or disabled. + public: explicit DropdownMenuEnabled(bool _menuEnabled); + + /// \brief Unique type for this event. + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 7); + + /// \brief Gets whether the menu is enabled or not for this event. + /// \return True if enabling the menu, false if disabling the menu + public: bool MenuEnabled() const; + + /// \internal + /// \brief Private data pointer + GZ_UTILS_IMPL_PTR(dataPtr) +}; + +/// \brief Event which is called to broadcast the key release within +/// the scene. +class GZ_GUI_VISIBLE KeyReleaseOnScene : public QEvent +{ + /// \brief Constructor + /// \param[in] _key The key released event within the scene + public: explicit KeyReleaseOnScene(const common::KeyEvent &_key); + + /// \brief Unique type for this event. + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 8); + + /// \brief Get the released key within the scene that the user released. + /// \return The key code. + public: common::KeyEvent Key() const; + + /// \internal + /// \brief Private data pointer + GZ_UTILS_IMPL_PTR(dataPtr) +}; + +/// \brief Event which is called to broadcast the key press within +/// the scene. +class GZ_GUI_VISIBLE KeyPressOnScene : public QEvent +{ + /// \brief Constructor + /// \param[in] _key The pressed key within the scene + public: explicit KeyPressOnScene(const common::KeyEvent &_key); + + /// \brief Unique type for this event. + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 9); + + /// \brief Get the key within the scene that the user pressed + /// \return The key code. + public: common::KeyEvent Key() const; + + /// \internal + /// \brief Private data pointer + GZ_UTILS_IMPL_PTR(dataPtr) +}; + +/// \brief Event which is called to broadcast information about left +/// mouse releases on the scene. +/// For the 3D coordinates of that point on the scene, see +/// `LeftClickToScene`. +/// \sa LeftClickToScene +class GZ_GUI_VISIBLE LeftClickOnScene : public QEvent +{ + /// \brief Constructor + /// \param[in] _mouse The left mouse event on the scene + public: explicit LeftClickOnScene( + const common::MouseEvent &_mouse); + + /// \brief Unique type for this event. + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 10); + + /// \brief Return the left mouse event + public: const common::MouseEvent &Mouse() const; + + /// \internal + /// \brief Private data pointer + GZ_UTILS_IMPL_PTR(dataPtr) +}; + +/// \brief Event which is called to broadcast information about right +/// mouse releases on the scene. +/// For the 3D coordinates of that point on the scene, see +/// `RightClickToScene`. +/// \sa RightClickToScene +class GZ_GUI_VISIBLE RightClickOnScene : public QEvent +{ + /// \brief Constructor + /// \param[in] _mouse The right mouse event on the scene + public: RightClickOnScene( + const common::MouseEvent &_mouse); + + /// \brief Unique type for this event. + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 11); + + /// \brief Return the right mouse event + public: const common::MouseEvent &Mouse() const; + + /// \internal + /// \brief Private data pointer + GZ_UTILS_IMPL_PTR(dataPtr) +}; + +/// \brief Event that block the Interactive View control when some of the +/// other plugins require it. For example: When the transform control is +/// active we should block the movements of the camera. +class GZ_GUI_VISIBLE BlockOrbit : public QEvent +{ + /// \brief Constructor + /// \param[in] _block True to block otherwise False + public: explicit BlockOrbit(const bool &_block); + + /// \brief Unique type for this event. + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 12); + + /// \brief Get the if the event should block the Interactive view + /// controller + /// \return True to block otherwise False. + public: bool Block() const; + + /// \internal + /// \brief Private data pointer + GZ_UTILS_IMPL_PTR(dataPtr) +}; + +/// \brief Event which is called to broadcast the 2D coordinates of a +/// user's mouse hover within the scene. +class GZ_GUI_VISIBLE HoverOnScene : public QEvent +{ + /// \brief Constructor + /// \param[in] _mouse The hover mouse event on the scene + public: explicit HoverOnScene(const common::MouseEvent &_mouse); + + /// \brief Unique type for this event. + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 13); + + /// \brief Get the point within the scene over which the user is + /// hovering. + /// \return The 2D point + public: common::MouseEvent Mouse() const; + + /// \internal + /// \brief Private data pointer + GZ_UTILS_IMPL_PTR(dataPtr) +}; + +/// \brief Event called to clone a resource, given its name as a string. +class GZ_GUI_VISIBLE SpawnCloneFromName : public QEvent +{ + /// \brief Constructor + /// \param[in] _name The name of the resource to clone + public: explicit SpawnCloneFromName(const std::string &_name); + + /// \brief Unique type for this event. + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 14); + + /// \brief Get the name of the resource to be cloned + /// \return The name of the resource to be cloned + public: const std::string &Name() const; + + /// \internal + /// \brief Private data pointer + GZ_UTILS_IMPL_PTR(dataPtr) +}; + +/// \brief Event called to clone a resource, given its name as a string. +class GZ_GUI_VISIBLE DropOnScene : public QEvent +{ + /// \brief Constructor + /// \param[in] _dropText Dropped string. + /// \param[in] _dropMouse x and y coordinate of mouse position. + public: explicit DropOnScene( + const std::string &_dropText, + const math::Vector2i &_dropMouse); + + /// \brief Get the text of the dropped thing on the scene + /// \return The name of the dropped thing on the scene + public: const std::string &DropText() const; + + /// \brief Get X and Y position + /// \return Get X and Y position + public: const math::Vector2i &Mouse() const; + + /// \brief Unique type for this event. + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 15); + + /// \internal + /// \brief Private data pointer + GZ_UTILS_IMPL_PTR(dataPtr) +}; + +/// \brief Event which is called to broadcast information about mouse +/// scrolls on the scene. +class GZ_GUI_VISIBLE ScrollOnScene : public QEvent +{ + /// \brief Constructor + /// \param[in] _mouse The scroll mouse event on the scene + public: explicit ScrollOnScene(const common::MouseEvent &_mouse); + + /// \brief Unique type for this event. + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 16); + + /// \brief Return the scroll mouse event + public: const common::MouseEvent &Mouse() const; + + /// \internal + /// \brief Private data pointer + GZ_UTILS_IMPL_PTR(dataPtr) +}; + +/// \brief Event which is called to broadcast information about mouse +/// drags on the scene. +class GZ_GUI_VISIBLE DragOnScene : public QEvent +{ + /// \brief Constructor + /// \param[in] _mouse The drag mouse event on the scene + public: explicit DragOnScene(const common::MouseEvent &_mouse); + + /// \brief Unique type for this event. + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 17); + + /// \brief Get the point within the scene over which the user is + /// dragging. + /// \return The 2D point + public: common::MouseEvent Mouse() const; + + /// \internal + /// \brief Private data pointer + GZ_UTILS_IMPL_PTR(dataPtr) +}; + +/// \brief Event which is called to broadcast information about mouse +/// presses on the scene, with right, left or middle buttons. +class GZ_GUI_VISIBLE MousePressOnScene : public QEvent +{ + /// \brief Constructor + /// \param[in] _mouse The mouse event on the scene + public: MousePressOnScene( + const common::MouseEvent &_mouse); + + /// \brief Unique type for this event. + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 18); + + /// \brief Return the button press mouse event + public: const common::MouseEvent &Mouse() const; + + /// \internal + /// \brief Private data pointer + GZ_UTILS_IMPL_PTR(dataPtr) +}; + +/// \brief Event which is called to share WorldControl information. +class GZ_GUI_VISIBLE WorldControl : public QEvent +{ + /// \brief Constructor + /// \param[in] _worldControl The WorldControl information + public: explicit WorldControl(const msgs::WorldControl &_worldControl); + + /// \brief Unique type for this event. + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 19); + + /// \brief Get the WorldControl information + /// \return The WorldControl information + public: const msgs::WorldControl &WorldControlInfo() const; + + /// \internal + /// \brief Private data pointer + GZ_UTILS_IMPL_PTR(dataPtr) +}; + +/// \brief Event called in the render thread of a 3D scene, before the +/// user camera is rendered. +/// It's safe to make rendering calls in this event's callback. +class GZ_GUI_VISIBLE PreRender : public QEvent +{ + /// \brief Constructor + public: PreRender(); + + /// \brief Unique type for this event. + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 20); + /// \internal + /// \brief Private data pointer + GZ_UTILS_IMPL_PTR(dataPtr) +}; +} // namespace gz::gui::events #endif // GZ_GUI_GUIEVENTS_HH_ diff --git a/include/gz/gui/Helpers.hh b/include/gz/gui/Helpers.hh index a2e7a4d6c..bf6258113 100644 --- a/include/gz/gui/Helpers.hh +++ b/include/gz/gui/Helpers.hh @@ -22,114 +22,111 @@ #include "gz/gui/Enums.hh" #include "gz/gui/Export.hh" -namespace gz +namespace gz::gui { - namespace gui - { - /// \brief Create a human readable key, capitalizing the first letter - /// and removing characters like "_". - /// \param[in] _key Non-human-readable key. - /// \return Human-readable key. - GZ_GUI_VISIBLE - std::string humanReadable(const std::string &_key); +/// \brief Create a human readable key, capitalizing the first letter +/// and removing characters like "_". +/// \param[in] _key Non-human-readable key. +/// \return Human-readable key. +GZ_GUI_VISIBLE +std::string humanReadable(const std::string &_key); - /// \brief Returns the unit for a given key. For example, the key "mass" - /// returns "kg". - /// \param[in] _key The key. - /// \param[in] _type In case the key may have more than one type, the type - /// must be given too. For example, a prismatic joint will have different - /// units from a revolute joint. - /// \return The unit. - GZ_GUI_VISIBLE - std::string unitFromKey(const std::string &_key, - const std::string &_type = ""); +/// \brief Returns the unit for a given key. For example, the key "mass" +/// returns "kg". +/// \param[in] _key The key. +/// \param[in] _type In case the key may have more than one type, the type +/// must be given too. For example, a prismatic joint will have different +/// units from a revolute joint. +/// \return The unit. +GZ_GUI_VISIBLE +std::string unitFromKey(const std::string &_key, + const std::string &_type = ""); - /// \brief Returns the range for a given key. For example, the key - /// "transparency" returns min == 0, max == 1. - /// \param[in] _key The key. - /// \param[out] _min The minimum value. - /// \param[out] _max The maximum value. - GZ_GUI_VISIBLE - void rangeFromKey(const std::string &_key, double &_min, double &_max); +/// \brief Returns the range for a given key. For example, the key +/// "transparency" returns min == 0, max == 1. +/// \param[in] _key The key. +/// \param[out] _min The minimum value. +/// \param[out] _max The maximum value. +GZ_GUI_VISIBLE +void rangeFromKey(const std::string &_key, double &_min, double &_max); - /// \brief Returns the string type for a given key. For example, the key - /// "innerxml" has a PLAIN_TEXT type while "name" is a LINE. - /// \param[in] _key The key. - /// \return The string type. - GZ_GUI_VISIBLE - StringType stringTypeFromKey(const std::string &_key); +/// \brief Returns the string type for a given key. For example, the key +/// "innerxml" has a PLAIN_TEXT type while "name" is a LINE. +/// \param[in] _key The key. +/// \return The string type. +GZ_GUI_VISIBLE +StringType stringTypeFromKey(const std::string &_key); - /// \brief Generates a path for a file which doesn't collide with existing - /// files, by appending numbers to it (i.e. (0), (1), ...) - /// \param[in] _pathAndName Full absolute path and file name up to the - /// file extension. - /// \param[in] _extension File extension, such as "pdf". - /// \return Full path, with name and extension, which doesn't collide with - /// existing files - GZ_GUI_VISIBLE - std::string uniqueFilePath(const std::string &_pathAndName, - const std::string &_extension); +/// \brief Generates a path for a file which doesn't collide with existing +/// files, by appending numbers to it (i.e. (0), (1), ...) +/// \param[in] _pathAndName Full absolute path and file name up to the +/// file extension. +/// \param[in] _extension File extension, such as "pdf". +/// \return Full path, with name and extension, which doesn't collide with +/// existing files +GZ_GUI_VISIBLE +std::string uniqueFilePath(const std::string &_pathAndName, + const std::string &_extension); - /// \brief The main window's "worldNames" property may be filled with a list - /// of the names of all worlds currently loaded. This information can be - /// used by plugins to choose which world to work with. - /// This helper function provides a handy access to the world names list. - /// \return List of world names, as stored in the `MainWindow`'s - /// "worldNames" property. - GZ_GUI_VISIBLE - QStringList worldNames(); +/// \brief The main window's "worldNames" property may be filled with a list +/// of the names of all worlds currently loaded. This information can be +/// used by plugins to choose which world to work with. +/// This helper function provides a handy access to the world names list. +/// \return List of world names, as stored in the `MainWindow`'s +/// "worldNames" property. +GZ_GUI_VISIBLE +QStringList worldNames(); - /// \brief The main window's "renderEngine" property may be filled with - /// a string of the render engine gui name. This information can be - /// used by plugins to set the GUI render engine - /// This helper function provides a handy access to the render engine GUI - /// name - /// \return Name of render engine used on the GUI, as stored in the - /// `MainWindow`'s "renderEngine" property. - GZ_GUI_VISIBLE - std::string renderEngineName(); +/// \brief The main window's "renderEngine" property may be filled with +/// a string of the render engine gui name. This information can be +/// used by plugins to set the GUI render engine +/// This helper function provides a handy access to the render engine GUI +/// name +/// \return Name of render engine used on the GUI, as stored in the +/// `MainWindow`'s "renderEngine" property. +GZ_GUI_VISIBLE +std::string renderEngineName(); - /// \brief Just like renderEngineName(), but valid entries are: - /// - opengl (default) - /// - metal (Apple only) - /// - vulkan - /// \return Name of API backend used on the GUI, as stored in the - /// `MainWindow`'s "renderEngineBackendApiName" property. - GZ_GUI_VISIBLE - std::string renderEngineBackendApiName(); +/// \brief Just like renderEngineName(), but valid entries are: +/// - opengl (default) +/// - metal (Apple only) +/// - vulkan +/// \return Name of API backend used on the GUI, as stored in the +/// `MainWindow`'s "renderEngineBackendApiName" property. +GZ_GUI_VISIBLE +std::string renderEngineBackendApiName(); - /// \brief Import path for gz-gui QML modules added to the Qt resource - /// system. This helper function returns the QRC resource path where custom - /// Gazebo QML modules can be imported from. To import a Gazebo QML - /// module, add this path to the QML engine's import path list before - /// attempting to load a QML file that imports Gazebo QML modules. - /// \return Resousrce path prefix as a string - GZ_GUI_VISIBLE - const QString qmlQrcImportPath(); +/// \brief Import path for gz-gui QML modules added to the Qt resource +/// system. This helper function returns the QRC resource path where custom +/// Gazebo QML modules can be imported from. To import a Gazebo QML +/// module, add this path to the QML engine's import path list before +/// attempting to load a QML file that imports Gazebo QML modules. +/// \return Resousrce path prefix as a string +GZ_GUI_VISIBLE +const QString qmlQrcImportPath(); - /// \brief Returns the first element on a QList which matches the given - /// property. - /// \param[in] _list The list to search through. - /// \param[in] _key The property key value. - /// \param[in] _value The property value. - /// \return The first matching element. - template - T findFirstByProperty(const QList _list, const char *_key, - QVariant _value) - { - if (nullptr == _key) - return nullptr; +/// \brief Returns the first element on a QList which matches the given +/// property. +/// \param[in] _list The list to search through. +/// \param[in] _key The property key value. +/// \param[in] _value The property value. +/// \return The first matching element. +template +T findFirstByProperty(const QList _list, const char *_key, + QVariant _value) +{ + if (nullptr == _key) + return nullptr; - for (const auto &w : _list) - { - if (nullptr == w) - continue; + for (const auto &w : _list) + { + if (nullptr == w) + continue; - if (w->property(_key) == _value) - return w; - } - return nullptr; - } + if (w->property(_key) == _value) + return w; } + return nullptr; } -#endif +} // namespace gz::gui +#endif // GZ_GUI_HELPERS_HH_ diff --git a/include/gz/gui/MainWindow.hh b/include/gz/gui/MainWindow.hh index 766b43e59..4ed353b53 100644 --- a/include/gz/gui/MainWindow.hh +++ b/include/gz/gui/MainWindow.hh @@ -35,652 +35,649 @@ #pragma warning(disable: 4251) #endif -namespace gz +namespace gz::gui { - namespace gui - { - Q_NAMESPACE - class MainWindowPrivate; - struct WindowConfig; - - /// \brief The action executed when GUI is closed without prompt. - enum class ExitAction - { - /// \brief Close GUI and leave server running - CLOSE_GUI, - /// \brief Close GUI and shutdown server - SHUTDOWN_SERVER, - }; - /// \cond DO_NOT_DOCUMENT - Q_ENUM_NS(ExitAction) - /// \endcond - - /// \brief The main window class creates a QQuickWindow and acts as an - /// interface which provides properties and functions which can be called - /// from Main.qml - class GZ_GUI_VISIBLE MainWindow : public QObject - { - Q_OBJECT - - /// \brief Number of plugins currently instantiated inside the window. - Q_PROPERTY( - int pluginCount - READ PluginCount - WRITE SetPluginCount - NOTIFY PluginCountChanged - ) - - /// \brief Material theme (Light / Dark) - Q_PROPERTY( - QString materialTheme - READ MaterialTheme - WRITE SetMaterialTheme - NOTIFY MaterialThemeChanged - ) - - /// \brief Material primary color (Pre-defined color name or hex value) - Q_PROPERTY( - QString materialPrimary - READ MaterialPrimary - WRITE SetMaterialPrimary - NOTIFY MaterialPrimaryChanged - ) - - /// \brief Material accent color (Pre-defined color name or hex value) - Q_PROPERTY( - QString materialAccent - READ MaterialAccent - WRITE SetMaterialAccent - NOTIFY MaterialAccentChanged - ) - - /// \brief Top toolbar color for light theme (Pre-defined color name or - /// hex value). Defaults to material primary. - Q_PROPERTY( - QString toolBarColorLight - READ ToolBarColorLight - WRITE SetToolBarColorLight - NOTIFY ToolBarColorLightChanged - ) - - /// \brief Top toolbar text color for light theme (Pre-defined color name - /// or hex value). Defaults to material background. - Q_PROPERTY( - QString toolBarTextColorLight - READ ToolBarTextColorLight - WRITE SetToolBarTextColorLight - NOTIFY ToolBarTextColorLightChanged - ) - - /// \brief Top toolbar color for dark theme (Pre-defined color name or - /// hex value). Defaults to material primary. - Q_PROPERTY( - QString toolBarColorDark - READ ToolBarColorDark - WRITE SetToolBarColorDark - NOTIFY ToolBarColorDarkChanged - ) - - /// \brief Top toolbar text color for dark theme (Pre-defined color name - /// or hex value). Defaults to material background. - Q_PROPERTY( - QString toolBarTextColorDark - READ ToolBarTextColorDark - WRITE SetToolBarTextColorDark - NOTIFY ToolBarTextColorDarkChanged - ) - - /// \brief Plugin toolbar color for light theme (Pre-defined color name or - /// hex value). Defaults to material accent. - Q_PROPERTY( - QString pluginToolBarColorLight - READ PluginToolBarColorLight - WRITE SetPluginToolBarColorLight - NOTIFY PluginToolBarColorLightChanged - ) - - /// \brief Plugin toolbar text color for light theme (Pre-defined color - /// name or hex value). Defaults to material foreground. - Q_PROPERTY( - QString pluginToolBarTextColorLight - READ PluginToolBarTextColorLight - WRITE SetPluginToolBarTextColorLight - NOTIFY PluginToolBarTextColorLightChanged - ) - - /// \brief Plugin toolbar color for dark theme (Pre-defined color name or - /// hex value). Defaults to material accent. - Q_PROPERTY( - QString pluginToolBarColorDark - READ PluginToolBarColorDark - WRITE SetPluginToolBarColorDark - NOTIFY PluginToolBarColorDarkChanged - ) - - /// \brief Plugin toolbar text color for dark theme (Pre-defined color - /// name or hex value). Defaults to material foreground. - Q_PROPERTY( - QString pluginToolBarTextColorDark - READ PluginToolBarTextColorDark - WRITE SetPluginToolBarTextColorDark - NOTIFY PluginToolBarTextColorDarkChanged - ) - - /// \brief Flag to show side drawer - Q_PROPERTY( - bool showDrawer - READ ShowDrawer - WRITE SetShowDrawer - NOTIFY ShowDrawerChanged - ) - - /// \brief Flag to show side drawer's default options - Q_PROPERTY( - bool showDefaultDrawerOpts - READ ShowDefaultDrawerOpts - WRITE SetShowDefaultDrawerOpts - NOTIFY ShowDefaultDrawerOptsChanged - ) - - /// \brief Flag to show plugins menu - Q_PROPERTY( - bool showPluginMenu - READ ShowPluginMenu - WRITE SetShowPluginMenu - NOTIFY ShowPluginMenuChanged - ) - - /// \brief Flag to enable confirmation dialog on exit - Q_PROPERTY( - ExitAction defaultExitAction - READ DefaultExitAction - WRITE SetDefaultExitAction - NOTIFY DefaultExitActionChanged - ) - - /// \brief Flag to enable confirmation dialog on exit - Q_PROPERTY( - bool showDialogOnExit - READ ShowDialogOnExit - WRITE SetShowDialogOnExit - NOTIFY ShowDialogOnExitChanged - ) - - /// \brief Text of the prompt in confirmation dialog on exit - Q_PROPERTY( - QString dialogOnExitText - READ DialogOnExitText - WRITE SetDialogOnExitText - NOTIFY DialogOnExitTextChanged - ) - - /// \brief Flag to show "shutdown" button in confirmation dialog on exit - Q_PROPERTY( - bool exitDialogShowShutdown - READ ExitDialogShowShutdown - WRITE SetExitDialogShowShutdown - NOTIFY ExitDialogShowShutdownChanged - ) - - /// \brief Flag to show "close GUI" button in confirmation dialog on exit - Q_PROPERTY( - bool exitDialogShowCloseGui - READ ExitDialogShowCloseGui - WRITE SetExitDialogShowCloseGui - NOTIFY ExitDialogShowCloseGuiChanged - ) - - /// \brief Text of the "shutdown" button in confirmation dialog on exit - Q_PROPERTY( - QString exitDialogShutdownText - READ ExitDialogShutdownText - WRITE SetExitDialogShutdownText - NOTIFY ExitDialogShutdownTextChanged - ) - - /// \brief Text of the "Close GUI" button in confirmation dialog on exit - Q_PROPERTY( - QString exitDialogCloseGuiText - READ ExitDialogCloseGuiText - WRITE SetExitDialogCloseGuiText - NOTIFY ExitDialogCloseGuiTextChanged - ) - - /// \brief Constructor - public: MainWindow(); - - /// \brief Destructor - public: virtual ~MainWindow(); - - /// \brief Get the QtQuick window created by this object - /// \return Pointer to the QtQuick window - public: QQuickWindow *QuickWindow() const; - - /// \brief Save current window and plugin configuration to a file on disk. - /// Will open an error dialog in case it's not possible to write to the - /// path. - /// \param[in] _path The full destination path including filename. - public: void SaveConfig(const std::string &_path); - - /// \brief Apply a WindowConfig to this window and keep a copy of it. - /// \param[in] _config The configuration to apply. - /// \return True if successful. - public: bool ApplyConfig(const WindowConfig &_config); - - /// \brief Get the current window configuration. - /// \return Updated window config - public: WindowConfig CurrentWindowConfig() const; - - /// \brief Set the Render engine GUI name passed by the command line - /// \param[in] _renderEngine name of the render engine to use - public: void SetRenderEngine(const std::string &_renderEngine); - - /// \brief Add a plugin to the window. - /// \param [in] _plugin Plugin filename - public slots: void OnAddPlugin(QString _plugin); - - /// \brief Return a list of all plugin names found - /// \return List with plugin names - public: Q_INVOKABLE QStringList PluginListModel() const; - - /// \brief Returns the number of plugins current instantiated in the - /// window. - /// \return Number of plugins - public: Q_INVOKABLE int PluginCount() const; - - /// \brief Sets the number of plugins current instantiated in the - /// window. - /// \param[in] _pluginCount Number of plugins - public: Q_INVOKABLE void SetPluginCount(const int _pluginCount); - - /// \brief Returns the material theme. - /// \return Theme (Light / Dark) - public: Q_INVOKABLE QString MaterialTheme() const; - - /// \brief Sets the material theme - /// \param[in] _materialTheme Theme (Light / Dark) - public: Q_INVOKABLE void SetMaterialTheme( - const QString &_materialTheme); - - /// \brief Returns the material primary color. - /// \return Primary color - public: Q_INVOKABLE QString MaterialPrimary() const; - - /// \brief Sets the material primary color - /// \param[in] _materialPrimary Primary color - public: Q_INVOKABLE void SetMaterialPrimary( - const QString &_materialPrimary); - - /// \brief Returns the material accent color. - /// \return Accent color - public: Q_INVOKABLE QString MaterialAccent() const; - - /// \brief Sets the material accent color - /// \param[in] _materialAccent Accent color - public: Q_INVOKABLE void SetMaterialAccent( - const QString &_materialAccent); - - /// \brief Returns the top toolbar color for light theme. - /// \return Toolbar color - public: Q_INVOKABLE QString ToolBarColorLight() const; - - /// \brief Sets the top toolbar color for light theme. - /// \param[in] _toolBarColorLight Toolbar color - public: Q_INVOKABLE void SetToolBarColorLight( - const QString &_toolBarColorLight); - - /// \brief Returns the top toolbar text color for light theme. - /// \return Toolbar text color - public: Q_INVOKABLE QString ToolBarTextColorLight() const; - - /// \brief Sets the top toolbar text color for light theme. - /// \param[in] _toolBarTextColorLight Toolbar text color - public: Q_INVOKABLE void SetToolBarTextColorLight( - const QString &_toolBarTextColorLight); - - /// \brief Returns the top toolbar color for dark theme. - /// \return Toolbar color - public: Q_INVOKABLE QString ToolBarColorDark() const; - - /// \brief Sets the top toolbar color for dark theme. - /// \param[in] _toolBarColorDark Toolbar color - public: Q_INVOKABLE void SetToolBarColorDark( - const QString &_toolBarColorDark); - - /// \brief Returns the top toolbar text color for dark theme. - /// \return Toolbar text color - public: Q_INVOKABLE QString ToolBarTextColorDark() const; - - /// \brief Sets the top toolbar text color for dark theme. - /// \param[in] _toolBarTextColorDark Toolbar text color - public: Q_INVOKABLE void SetToolBarTextColorDark( - const QString &_toolBarTextColorDark); - - /// \brief Returns the plugin toolbar color for light theme. - /// \return Toolbar color - public: Q_INVOKABLE QString PluginToolBarColorLight() const; - - /// \brief Sets the plugin toolbar color for light theme. - /// \param[in] _pluginPluginToolBarColorLight Toolbar color - public: Q_INVOKABLE void SetPluginToolBarColorLight( - const QString &_pluginPluginToolBarColorLight); - - /// \brief Returns the plugin toolbar text color for light theme. - /// \return Toolbar text color - public: Q_INVOKABLE QString PluginToolBarTextColorLight() const; - - /// \brief Sets the plugin toolbar text color for light theme. - /// \param[in] _pluginPluginToolBarTextColorLight Toolbar text color - public: Q_INVOKABLE void SetPluginToolBarTextColorLight( - const QString &_pluginPluginToolBarTextColorLight); - - /// \brief Returns the plugin toolbar color for dark theme. - /// \return Toolbar color - public: Q_INVOKABLE QString PluginToolBarColorDark() const; - - /// \brief Sets the plugin toolbar color for dark theme. - /// \param[in] _pluginPluginToolBarColorDark Toolbar color - public: Q_INVOKABLE void SetPluginToolBarColorDark( - const QString &_pluginPluginToolBarColorDark); - - /// \brief Returns the plugin toolbar text color for dark theme. - /// \return Toolbar text color - public: Q_INVOKABLE QString PluginToolBarTextColorDark() const; - - /// \brief Sets the plugin toolbar text color for dark theme. - /// \param[in] _pluginPluginToolBarTextColorDark Toolbar text color - public: Q_INVOKABLE void SetPluginToolBarTextColorDark( - const QString &_pluginPluginToolBarTextColorDark); - - /// \brief Get the flag to show the side drawer. - /// \return True to show. - public: Q_INVOKABLE bool ShowDrawer() const; - - /// \brief Set the flag to show the side drawer. - /// \param[in] _showDrawer True to show. - public: Q_INVOKABLE void SetShowDrawer(const bool _showDrawer); - - /// \brief Get the flag to show the side drawer's default options. - /// \return True to show. - public: Q_INVOKABLE bool ShowDefaultDrawerOpts() const; - - /// \brief Set the flag to show the side drawer's default options. - /// \param[in] _showDefaultDrawerOpts True to show. - public: Q_INVOKABLE void SetShowDefaultDrawerOpts( - const bool _showDefaultDrawerOpts); - - /// \brief Get the flag to show the plugin menu. - /// \return True to show. - public: Q_INVOKABLE bool ShowPluginMenu() const; - - /// \brief Set the flag to show the plugin menu. - /// \param[in] _showPluginMenu True to show. - public: Q_INVOKABLE void SetShowPluginMenu(const bool _showPluginMenu); - - /// \brief Get the action performed when GUI closes without prompt. - /// \return The action. - public: Q_INVOKABLE ExitAction DefaultExitAction() const; - - /// \brief Set the action performed when GUI closes without prompt. - /// \param[in] _defaultExitAction The action. - public: Q_INVOKABLE void SetDefaultExitAction( - enum ExitAction _defaultExitAction); - - /// \brief Get the flag to show the plugin menu. - /// \return True to show. - public: Q_INVOKABLE bool ShowDialogOnExit() const; +Q_NAMESPACE +class MainWindowPrivate; +struct WindowConfig; - /// \brief Set the flag to show the confirmation dialog when exiting. - /// \param[in] _showDialogOnExit True to show. - public: Q_INVOKABLE void SetShowDialogOnExit(bool _showDialogOnExit); +/// \brief The action executed when GUI is closed without prompt. +enum class ExitAction +{ + /// \brief Close GUI and leave server running + CLOSE_GUI, + /// \brief Close GUI and shutdown server + SHUTDOWN_SERVER, +}; +/// \cond DO_NOT_DOCUMENT +Q_ENUM_NS(ExitAction) +/// \endcond + +/// \brief The main window class creates a QQuickWindow and acts as an +/// interface which provides properties and functions which can be called +/// from Main.qml +class GZ_GUI_VISIBLE MainWindow : public QObject +{ + Q_OBJECT + + /// \brief Number of plugins currently instantiated inside the window. + Q_PROPERTY( + int pluginCount + READ PluginCount + WRITE SetPluginCount + NOTIFY PluginCountChanged + ) + + /// \brief Material theme (Light / Dark) + Q_PROPERTY( + QString materialTheme + READ MaterialTheme + WRITE SetMaterialTheme + NOTIFY MaterialThemeChanged + ) + + /// \brief Material primary color (Pre-defined color name or hex value) + Q_PROPERTY( + QString materialPrimary + READ MaterialPrimary + WRITE SetMaterialPrimary + NOTIFY MaterialPrimaryChanged + ) + + /// \brief Material accent color (Pre-defined color name or hex value) + Q_PROPERTY( + QString materialAccent + READ MaterialAccent + WRITE SetMaterialAccent + NOTIFY MaterialAccentChanged + ) + + /// \brief Top toolbar color for light theme (Pre-defined color name or + /// hex value). Defaults to material primary. + Q_PROPERTY( + QString toolBarColorLight + READ ToolBarColorLight + WRITE SetToolBarColorLight + NOTIFY ToolBarColorLightChanged + ) + + /// \brief Top toolbar text color for light theme (Pre-defined color name + /// or hex value). Defaults to material background. + Q_PROPERTY( + QString toolBarTextColorLight + READ ToolBarTextColorLight + WRITE SetToolBarTextColorLight + NOTIFY ToolBarTextColorLightChanged + ) + + /// \brief Top toolbar color for dark theme (Pre-defined color name or + /// hex value). Defaults to material primary. + Q_PROPERTY( + QString toolBarColorDark + READ ToolBarColorDark + WRITE SetToolBarColorDark + NOTIFY ToolBarColorDarkChanged + ) + + /// \brief Top toolbar text color for dark theme (Pre-defined color name + /// or hex value). Defaults to material background. + Q_PROPERTY( + QString toolBarTextColorDark + READ ToolBarTextColorDark + WRITE SetToolBarTextColorDark + NOTIFY ToolBarTextColorDarkChanged + ) + + /// \brief Plugin toolbar color for light theme (Pre-defined color name or + /// hex value). Defaults to material accent. + Q_PROPERTY( + QString pluginToolBarColorLight + READ PluginToolBarColorLight + WRITE SetPluginToolBarColorLight + NOTIFY PluginToolBarColorLightChanged + ) + + /// \brief Plugin toolbar text color for light theme (Pre-defined color + /// name or hex value). Defaults to material foreground. + Q_PROPERTY( + QString pluginToolBarTextColorLight + READ PluginToolBarTextColorLight + WRITE SetPluginToolBarTextColorLight + NOTIFY PluginToolBarTextColorLightChanged + ) + + /// \brief Plugin toolbar color for dark theme (Pre-defined color name or + /// hex value). Defaults to material accent. + Q_PROPERTY( + QString pluginToolBarColorDark + READ PluginToolBarColorDark + WRITE SetPluginToolBarColorDark + NOTIFY PluginToolBarColorDarkChanged + ) + + /// \brief Plugin toolbar text color for dark theme (Pre-defined color + /// name or hex value). Defaults to material foreground. + Q_PROPERTY( + QString pluginToolBarTextColorDark + READ PluginToolBarTextColorDark + WRITE SetPluginToolBarTextColorDark + NOTIFY PluginToolBarTextColorDarkChanged + ) + + /// \brief Flag to show side drawer + Q_PROPERTY( + bool showDrawer + READ ShowDrawer + WRITE SetShowDrawer + NOTIFY ShowDrawerChanged + ) + + /// \brief Flag to show side drawer's default options + Q_PROPERTY( + bool showDefaultDrawerOpts + READ ShowDefaultDrawerOpts + WRITE SetShowDefaultDrawerOpts + NOTIFY ShowDefaultDrawerOptsChanged + ) + + /// \brief Flag to show plugins menu + Q_PROPERTY( + bool showPluginMenu + READ ShowPluginMenu + WRITE SetShowPluginMenu + NOTIFY ShowPluginMenuChanged + ) + + /// \brief Flag to enable confirmation dialog on exit + Q_PROPERTY( + ExitAction defaultExitAction + READ DefaultExitAction + WRITE SetDefaultExitAction + NOTIFY DefaultExitActionChanged + ) + + /// \brief Flag to enable confirmation dialog on exit + Q_PROPERTY( + bool showDialogOnExit + READ ShowDialogOnExit + WRITE SetShowDialogOnExit + NOTIFY ShowDialogOnExitChanged + ) + + /// \brief Text of the prompt in confirmation dialog on exit + Q_PROPERTY( + QString dialogOnExitText + READ DialogOnExitText + WRITE SetDialogOnExitText + NOTIFY DialogOnExitTextChanged + ) + + /// \brief Flag to show "shutdown" button in confirmation dialog on exit + Q_PROPERTY( + bool exitDialogShowShutdown + READ ExitDialogShowShutdown + WRITE SetExitDialogShowShutdown + NOTIFY ExitDialogShowShutdownChanged + ) + + /// \brief Flag to show "close GUI" button in confirmation dialog on exit + Q_PROPERTY( + bool exitDialogShowCloseGui + READ ExitDialogShowCloseGui + WRITE SetExitDialogShowCloseGui + NOTIFY ExitDialogShowCloseGuiChanged + ) + + /// \brief Text of the "shutdown" button in confirmation dialog on exit + Q_PROPERTY( + QString exitDialogShutdownText + READ ExitDialogShutdownText + WRITE SetExitDialogShutdownText + NOTIFY ExitDialogShutdownTextChanged + ) + + /// \brief Text of the "Close GUI" button in confirmation dialog on exit + Q_PROPERTY( + QString exitDialogCloseGuiText + READ ExitDialogCloseGuiText + WRITE SetExitDialogCloseGuiText + NOTIFY ExitDialogCloseGuiTextChanged + ) + + /// \brief Constructor + public: MainWindow(); + + /// \brief Destructor + public: virtual ~MainWindow(); + + /// \brief Get the QtQuick window created by this object + /// \return Pointer to the QtQuick window + public: QQuickWindow *QuickWindow() const; + + /// \brief Save current window and plugin configuration to a file on disk. + /// Will open an error dialog in case it's not possible to write to the + /// path. + /// \param[in] _path The full destination path including filename. + public: void SaveConfig(const std::string &_path); + + /// \brief Apply a WindowConfig to this window and keep a copy of it. + /// \param[in] _config The configuration to apply. + /// \return True if successful. + public: bool ApplyConfig(const WindowConfig &_config); + + /// \brief Get the current window configuration. + /// \return Updated window config + public: WindowConfig CurrentWindowConfig() const; + + /// \brief Set the Render engine GUI name passed by the command line + /// \param[in] _renderEngine name of the render engine to use + public: void SetRenderEngine(const std::string &_renderEngine); + + /// \brief Add a plugin to the window. + /// \param [in] _plugin Plugin filename + public slots: void OnAddPlugin(QString _plugin); + + /// \brief Return a list of all plugin names found + /// \return List with plugin names + public: Q_INVOKABLE QStringList PluginListModel() const; + + /// \brief Returns the number of plugins current instantiated in the + /// window. + /// \return Number of plugins + public: Q_INVOKABLE int PluginCount() const; + + /// \brief Sets the number of plugins current instantiated in the + /// window. + /// \param[in] _pluginCount Number of plugins + public: Q_INVOKABLE void SetPluginCount(const int _pluginCount); + + /// \brief Returns the material theme. + /// \return Theme (Light / Dark) + public: Q_INVOKABLE QString MaterialTheme() const; + + /// \brief Sets the material theme + /// \param[in] _materialTheme Theme (Light / Dark) + public: Q_INVOKABLE void SetMaterialTheme( + const QString &_materialTheme); + + /// \brief Returns the material primary color. + /// \return Primary color + public: Q_INVOKABLE QString MaterialPrimary() const; + + /// \brief Sets the material primary color + /// \param[in] _materialPrimary Primary color + public: Q_INVOKABLE void SetMaterialPrimary( + const QString &_materialPrimary); + + /// \brief Returns the material accent color. + /// \return Accent color + public: Q_INVOKABLE QString MaterialAccent() const; + + /// \brief Sets the material accent color + /// \param[in] _materialAccent Accent color + public: Q_INVOKABLE void SetMaterialAccent( + const QString &_materialAccent); + + /// \brief Returns the top toolbar color for light theme. + /// \return Toolbar color + public: Q_INVOKABLE QString ToolBarColorLight() const; + + /// \brief Sets the top toolbar color for light theme. + /// \param[in] _toolBarColorLight Toolbar color + public: Q_INVOKABLE void SetToolBarColorLight( + const QString &_toolBarColorLight); + + /// \brief Returns the top toolbar text color for light theme. + /// \return Toolbar text color + public: Q_INVOKABLE QString ToolBarTextColorLight() const; + + /// \brief Sets the top toolbar text color for light theme. + /// \param[in] _toolBarTextColorLight Toolbar text color + public: Q_INVOKABLE void SetToolBarTextColorLight( + const QString &_toolBarTextColorLight); + + /// \brief Returns the top toolbar color for dark theme. + /// \return Toolbar color + public: Q_INVOKABLE QString ToolBarColorDark() const; + + /// \brief Sets the top toolbar color for dark theme. + /// \param[in] _toolBarColorDark Toolbar color + public: Q_INVOKABLE void SetToolBarColorDark( + const QString &_toolBarColorDark); + + /// \brief Returns the top toolbar text color for dark theme. + /// \return Toolbar text color + public: Q_INVOKABLE QString ToolBarTextColorDark() const; + + /// \brief Sets the top toolbar text color for dark theme. + /// \param[in] _toolBarTextColorDark Toolbar text color + public: Q_INVOKABLE void SetToolBarTextColorDark( + const QString &_toolBarTextColorDark); + + /// \brief Returns the plugin toolbar color for light theme. + /// \return Toolbar color + public: Q_INVOKABLE QString PluginToolBarColorLight() const; + + /// \brief Sets the plugin toolbar color for light theme. + /// \param[in] _pluginPluginToolBarColorLight Toolbar color + public: Q_INVOKABLE void SetPluginToolBarColorLight( + const QString &_pluginPluginToolBarColorLight); + + /// \brief Returns the plugin toolbar text color for light theme. + /// \return Toolbar text color + public: Q_INVOKABLE QString PluginToolBarTextColorLight() const; + + /// \brief Sets the plugin toolbar text color for light theme. + /// \param[in] _pluginPluginToolBarTextColorLight Toolbar text color + public: Q_INVOKABLE void SetPluginToolBarTextColorLight( + const QString &_pluginPluginToolBarTextColorLight); + + /// \brief Returns the plugin toolbar color for dark theme. + /// \return Toolbar color + public: Q_INVOKABLE QString PluginToolBarColorDark() const; + + /// \brief Sets the plugin toolbar color for dark theme. + /// \param[in] _pluginPluginToolBarColorDark Toolbar color + public: Q_INVOKABLE void SetPluginToolBarColorDark( + const QString &_pluginPluginToolBarColorDark); + + /// \brief Returns the plugin toolbar text color for dark theme. + /// \return Toolbar text color + public: Q_INVOKABLE QString PluginToolBarTextColorDark() const; + + /// \brief Sets the plugin toolbar text color for dark theme. + /// \param[in] _pluginPluginToolBarTextColorDark Toolbar text color + public: Q_INVOKABLE void SetPluginToolBarTextColorDark( + const QString &_pluginPluginToolBarTextColorDark); + + /// \brief Get the flag to show the side drawer. + /// \return True to show. + public: Q_INVOKABLE bool ShowDrawer() const; + + /// \brief Set the flag to show the side drawer. + /// \param[in] _showDrawer True to show. + public: Q_INVOKABLE void SetShowDrawer(const bool _showDrawer); + + /// \brief Get the flag to show the side drawer's default options. + /// \return True to show. + public: Q_INVOKABLE bool ShowDefaultDrawerOpts() const; + + /// \brief Set the flag to show the side drawer's default options. + /// \param[in] _showDefaultDrawerOpts True to show. + public: Q_INVOKABLE void SetShowDefaultDrawerOpts( + const bool _showDefaultDrawerOpts); + + /// \brief Get the flag to show the plugin menu. + /// \return True to show. + public: Q_INVOKABLE bool ShowPluginMenu() const; + + /// \brief Set the flag to show the plugin menu. + /// \param[in] _showPluginMenu True to show. + public: Q_INVOKABLE void SetShowPluginMenu(const bool _showPluginMenu); + + /// \brief Get the action performed when GUI closes without prompt. + /// \return The action. + public: Q_INVOKABLE ExitAction DefaultExitAction() const; + + /// \brief Set the action performed when GUI closes without prompt. + /// \param[in] _defaultExitAction The action. + public: Q_INVOKABLE void SetDefaultExitAction( + enum ExitAction _defaultExitAction); + + /// \brief Get the flag to show the plugin menu. + /// \return True to show. + public: Q_INVOKABLE bool ShowDialogOnExit() const; - /// \brief Get the text of prompt in exit dialog. - /// \return Prompt text. - public: Q_INVOKABLE QString DialogOnExitText() const; + /// \brief Set the flag to show the confirmation dialog when exiting. + /// \param[in] _showDialogOnExit True to show. + public: Q_INVOKABLE void SetShowDialogOnExit(bool _showDialogOnExit); - /// \brief Set the text of the prompt in exit dialog. - /// \param[in] _dialogOnExitText Prompt text. - public: Q_INVOKABLE void SetDialogOnExitText( - const QString &_dialogOnExitText); + /// \brief Get the text of prompt in exit dialog. + /// \return Prompt text. + public: Q_INVOKABLE QString DialogOnExitText() const; - /// \brief Get the flag to show "shutdown" button in exit dialog. - /// \return True to show. - public: Q_INVOKABLE bool ExitDialogShowShutdown() const; + /// \brief Set the text of the prompt in exit dialog. + /// \param[in] _dialogOnExitText Prompt text. + public: Q_INVOKABLE void SetDialogOnExitText( + const QString &_dialogOnExitText); - /// \brief Set the flag to show "shutdown" button in exit dialog. - /// \param[in] _exitDialogShowShutdown True to show. - public: Q_INVOKABLE void SetExitDialogShowShutdown( - bool _exitDialogShowShutdown); + /// \brief Get the flag to show "shutdown" button in exit dialog. + /// \return True to show. + public: Q_INVOKABLE bool ExitDialogShowShutdown() const; - /// \brief Get the flag to show "Close GUI" button in exit dialog. - /// \return True to show. - public: Q_INVOKABLE bool ExitDialogShowCloseGui() const; + /// \brief Set the flag to show "shutdown" button in exit dialog. + /// \param[in] _exitDialogShowShutdown True to show. + public: Q_INVOKABLE void SetExitDialogShowShutdown( + bool _exitDialogShowShutdown); - /// \brief Set the flag to show "Close GUI" button in exit dialog. - /// \param[in] _exitDialogShowCloseGui True to show. - public: Q_INVOKABLE void SetExitDialogShowCloseGui( - bool _exitDialogShowCloseGui); + /// \brief Get the flag to show "Close GUI" button in exit dialog. + /// \return True to show. + public: Q_INVOKABLE bool ExitDialogShowCloseGui() const; - /// \brief Get the text of the "shutdown" button in exit dialog. - /// \return Button text. - public: Q_INVOKABLE QString ExitDialogShutdownText() const; + /// \brief Set the flag to show "Close GUI" button in exit dialog. + /// \param[in] _exitDialogShowCloseGui True to show. + public: Q_INVOKABLE void SetExitDialogShowCloseGui( + bool _exitDialogShowCloseGui); - /// \brief Set the text of the "shutdown" button in exit dialog. - /// \param[in] _exitDialogShutdownText Button text. - public: Q_INVOKABLE void SetExitDialogShutdownText( - const QString &_exitDialogShutdownText); + /// \brief Get the text of the "shutdown" button in exit dialog. + /// \return Button text. + public: Q_INVOKABLE QString ExitDialogShutdownText() const; - /// \brief Get the text of the "Close GUI" button in exit dialog. - /// \return Button text. - public: Q_INVOKABLE QString ExitDialogCloseGuiText() const; + /// \brief Set the text of the "shutdown" button in exit dialog. + /// \param[in] _exitDialogShutdownText Button text. + public: Q_INVOKABLE void SetExitDialogShutdownText( + const QString &_exitDialogShutdownText); - /// \brief Set the text of the "Close GUI" button in exit dialog. - /// \param[in] _exitDialogCloseGuiText Button text. - public: Q_INVOKABLE void SetExitDialogCloseGuiText( - const QString &_exitDialogCloseGuiText); + /// \brief Get the text of the "Close GUI" button in exit dialog. + /// \return Button text. + public: Q_INVOKABLE QString ExitDialogCloseGuiText() const; - /// \brief Get the topic of the server control service. - /// \return The service topic. - public: Q_INVOKABLE std::string ServerControlService() const; + /// \brief Set the text of the "Close GUI" button in exit dialog. + /// \param[in] _exitDialogCloseGuiText Button text. + public: Q_INVOKABLE void SetExitDialogCloseGuiText( + const QString &_exitDialogCloseGuiText); - /// \brief Set the topic of the server control service. - /// \param[in] _service The service topic. - public: Q_INVOKABLE void SetServerControlService( - const std::string &_service); + /// \brief Get the topic of the server control service. + /// \return The service topic. + public: Q_INVOKABLE std::string ServerControlService() const; - /// \brief Callback when load configuration is selected - public slots: void OnLoadConfig(const QString &_path); + /// \brief Set the topic of the server control service. + /// \param[in] _service The service topic. + public: Q_INVOKABLE void SetServerControlService( + const std::string &_service); - /// \brief Callback when "save configuration" is selected - public slots: void OnSaveConfig(); + /// \brief Callback when load configuration is selected + public slots: void OnLoadConfig(const QString &_path); - /// \brief Callback when "save configuration as" is selected - public slots: void OnSaveConfigAs(const QString &_path); + /// \brief Callback when "save configuration" is selected + public slots: void OnSaveConfig(); - /// \brief Callback when "shutdown simulation" is called - public slots: void OnStopServer(); + /// \brief Callback when "save configuration as" is selected + public slots: void OnSaveConfigAs(const QString &_path); - /// \brief Notifies when the number of plugins has changed. - signals: void PluginCountChanged(); + /// \brief Callback when "shutdown simulation" is called + public slots: void OnStopServer(); - /// \brief Notifies when the theme has changed. - signals: void MaterialThemeChanged(); + /// \brief Notifies when the number of plugins has changed. + signals: void PluginCountChanged(); - /// \brief Notifies when the primary color has changed. - signals: void MaterialPrimaryChanged(); + /// \brief Notifies when the theme has changed. + signals: void MaterialThemeChanged(); - /// \brief Notifies when the accent color has changed. - signals: void MaterialAccentChanged(); + /// \brief Notifies when the primary color has changed. + signals: void MaterialPrimaryChanged(); - /// \brief Notifies when the toolbar color light has changed. - signals: void ToolBarColorLightChanged(); + /// \brief Notifies when the accent color has changed. + signals: void MaterialAccentChanged(); - /// \brief Notifies when the toolbar text color light has changed. - signals: void ToolBarTextColorLightChanged(); + /// \brief Notifies when the toolbar color light has changed. + signals: void ToolBarColorLightChanged(); - /// \brief Notifies when the toolbar color dark has changed. - signals: void ToolBarColorDarkChanged(); + /// \brief Notifies when the toolbar text color light has changed. + signals: void ToolBarTextColorLightChanged(); - /// \brief Notifies when the toolbar text color dark has changed. - signals: void ToolBarTextColorDarkChanged(); + /// \brief Notifies when the toolbar color dark has changed. + signals: void ToolBarColorDarkChanged(); - /// \brief Notifies when the toolbar color light has changed. - signals: void PluginToolBarColorLightChanged(); + /// \brief Notifies when the toolbar text color dark has changed. + signals: void ToolBarTextColorDarkChanged(); - /// \brief Notifies when the toolbar text color light has changed. - signals: void PluginToolBarTextColorLightChanged(); + /// \brief Notifies when the toolbar color light has changed. + signals: void PluginToolBarColorLightChanged(); - /// \brief Notifies when the toolbar color dark has changed. - signals: void PluginToolBarColorDarkChanged(); + /// \brief Notifies when the toolbar text color light has changed. + signals: void PluginToolBarTextColorLightChanged(); - /// \brief Notifies when the toolbar text color dark has changed. - signals: void PluginToolBarTextColorDarkChanged(); + /// \brief Notifies when the toolbar color dark has changed. + signals: void PluginToolBarColorDarkChanged(); - /// \brief Notifies when the show drawer flag has changed. - signals: void ShowDrawerChanged(); + /// \brief Notifies when the toolbar text color dark has changed. + signals: void PluginToolBarTextColorDarkChanged(); - /// \brief Notifies when the show drawer default options flag has changed. - signals: void ShowDefaultDrawerOptsChanged(); + /// \brief Notifies when the show drawer flag has changed. + signals: void ShowDrawerChanged(); - /// \brief Notifies when the show menu flag has changed. - signals: void ShowPluginMenuChanged(); + /// \brief Notifies when the show drawer default options flag has changed. + signals: void ShowDefaultDrawerOptsChanged(); - /// \brief Notifies when the defaultExitAction has changed. - signals: void DefaultExitActionChanged(); + /// \brief Notifies when the show menu flag has changed. + signals: void ShowPluginMenuChanged(); - /// \brief Notifies when the showDialogOnExit flag has changed. - signals: void ShowDialogOnExitChanged(); + /// \brief Notifies when the defaultExitAction has changed. + signals: void DefaultExitActionChanged(); - /// \brief Notifies when dialogOnExitText has changed. - signals: void DialogOnExitTextChanged(); + /// \brief Notifies when the showDialogOnExit flag has changed. + signals: void ShowDialogOnExitChanged(); - /// \brief Notifies when the exitDialogShowShutdown flag has changed. - signals: void ExitDialogShowShutdownChanged(); + /// \brief Notifies when dialogOnExitText has changed. + signals: void DialogOnExitTextChanged(); - /// \brief Notifies when the exitDialogShowCloseGui flag has changed. - signals: void ExitDialogShowCloseGuiChanged(); + /// \brief Notifies when the exitDialogShowShutdown flag has changed. + signals: void ExitDialogShowShutdownChanged(); - /// \brief Notifies when exitDialogShutdownText has changed. - signals: void ExitDialogShutdownTextChanged(); + /// \brief Notifies when the exitDialogShowCloseGui flag has changed. + signals: void ExitDialogShowCloseGuiChanged(); - /// \brief Notifies when exitDialogCloseGuiText has changed. - signals: void ExitDialogCloseGuiTextChanged(); + /// \brief Notifies when exitDialogShutdownText has changed. + signals: void ExitDialogShutdownTextChanged(); - /// \brief Notifies when the window config has changed. - signals: void configChanged(); + /// \brief Notifies when exitDialogCloseGuiText has changed. + signals: void ExitDialogCloseGuiTextChanged(); - /// \brief Displays a message to the user - /// The message will appear in a snackbar, this message requires to - /// click on the botton "Dismiss" to close the dialog. - signals: void notify(const QString &_message); + /// \brief Notifies when the window config has changed. + signals: void configChanged(); - /// \brief Displays a message to the user - /// The message will appear in a snackbar, this message disappear when - /// the duration is over, or if the user clicks outside or escape before - /// that. - /// \param[in] _message Message to show - /// \param[in] _duration Time in milliseconds that the message will - /// appear - signals: void notifyWithDuration(const QString &_message, int _duration); + /// \brief Displays a message to the user + /// The message will appear in a snackbar, this message requires to + /// click on the botton "Dismiss" to close the dialog. + signals: void notify(const QString &_message); - /// \internal - /// \brief Private data pointer - private: std::unique_ptr dataPtr; - }; + /// \brief Displays a message to the user + /// The message will appear in a snackbar, this message disappear when + /// the duration is over, or if the user clicks outside or escape before + /// that. + /// \param[in] _message Message to show + /// \param[in] _duration Time in milliseconds that the message will + /// appear + signals: void notifyWithDuration(const QString &_message, int _duration); - /// \brief Holds configurations related to a MainWindow. - struct GZ_GUI_VISIBLE WindowConfig - { - /// \brief Update this config from an XML string. Only fields present on - /// the XML will be overriden / appended / created. - /// \param[in] _xml A config XML file in string format - /// \return True if successful. It may fail for example if the string - /// can't be parsed into XML. - bool MergeFromXML(const std::string &_xml); + /// \internal + /// \brief Private data pointer + private: std::unique_ptr dataPtr; +}; - /// \brief Return this configuration in XML format as a string. - /// \return String containing a complete config file. - std::string XMLString() const; +/// \brief Holds configurations related to a MainWindow. +struct GZ_GUI_VISIBLE WindowConfig +{ + /// \brief Update this config from an XML string. Only fields present on + /// the XML will be overriden / appended / created. + /// \param[in] _xml A config XML file in string format + /// \return True if successful. It may fail for example if the string + /// can't be parsed into XML. + bool MergeFromXML(const std::string &_xml); - /// \brief Get whether a property should be ignored - /// \return True if it's being ignored - bool IsIgnoring(const std::string &_prop) const; + /// \brief Return this configuration in XML format as a string. + /// \return String containing a complete config file. + std::string XMLString() const; - /// \brief Window X position in px - int posX{-1}; + /// \brief Get whether a property should be ignored + /// \return True if it's being ignored + bool IsIgnoring(const std::string &_prop) const; - /// \brief Window Y position in px - int posY{-1}; + /// \brief Window X position in px + int posX{-1}; - /// \brief Window width in px - int width{-1}; + /// \brief Window Y position in px + int posY{-1}; - /// \brief Window height in px - int height{-1}; + /// \brief Window width in px + int width{-1}; - /// \brief Window state (dock configuration) - QByteArray state; + /// \brief Window height in px + int height{-1}; - /// \brief Material theme (light / dark) - std::string materialTheme{""}; + /// \brief Window state (dock configuration) + QByteArray state; - /// \brief Material primary color - std::string materialPrimary{""}; + /// \brief Material theme (light / dark) + std::string materialTheme{""}; - /// \brief Material accent color - std::string materialAccent{""}; + /// \brief Material primary color + std::string materialPrimary{""}; - /// \brief Top toolbar color light - std::string toolBarColorLight{""}; + /// \brief Material accent color + std::string materialAccent{""}; - /// \brief Top toolbar text color light - std::string toolBarTextColorLight{""}; + /// \brief Top toolbar color light + std::string toolBarColorLight{""}; - /// \brief Top toolbar color dark - std::string toolBarColorDark{""}; + /// \brief Top toolbar text color light + std::string toolBarTextColorLight{""}; - /// \brief Top toolbar text color dark - std::string toolBarTextColorDark{""}; + /// \brief Top toolbar color dark + std::string toolBarColorDark{""}; - /// \brief Plugin toolbar color light - std::string pluginToolBarColorLight{""}; + /// \brief Top toolbar text color dark + std::string toolBarTextColorDark{""}; - /// \brief Plugin toolbar text color light - std::string pluginToolBarTextColorLight{""}; + /// \brief Plugin toolbar color light + std::string pluginToolBarColorLight{""}; - /// \brief Plugin toolbar color dark - std::string pluginToolBarColorDark{""}; + /// \brief Plugin toolbar text color light + std::string pluginToolBarTextColorLight{""}; - /// \brief Plugin toolbar text color dark - std::string pluginToolBarTextColorDark{""}; + /// \brief Plugin toolbar color dark + std::string pluginToolBarColorDark{""}; - /// \brief Show the side drawer - bool showDrawer{true}; + /// \brief Plugin toolbar text color dark + std::string pluginToolBarTextColorDark{""}; - /// \brief Show the default options of the drawer - bool showDefaultDrawerOpts{true}; + /// \brief Show the side drawer + bool showDrawer{true}; - /// \brief Show the plugins menu - bool showPluginMenu{true}; + /// \brief Show the default options of the drawer + bool showDefaultDrawerOpts{true}; - /// \brief True if plugins found in plugin paths should be listed under - /// the Plugins menu. True by default. - bool pluginsFromPaths{true}; + /// \brief Show the plugins menu + bool showPluginMenu{true}; - /// \brief List of plugins which should be shown on the list - std::vector showPlugins; + /// \brief True if plugins found in plugin paths should be listed under + /// the Plugins menu. True by default. + bool pluginsFromPaths{true}; - /// \brief List of window properties which should be ignored on load - std::set ignoredProps; + /// \brief List of plugins which should be shown on the list + std::vector showPlugins; - /// \brief Concatenation of all plugin configurations. - std::string plugins{""}; - }; - } -} + /// \brief List of window properties which should be ignored on load + std::set ignoredProps; + + /// \brief Concatenation of all plugin configurations. + std::string plugins{""}; +}; +} // namespace gz::gui #ifdef _MSC_VER #pragma warning(pop) #endif -#endif +#endif // GZ_GUI_MAINWINDOW_HH_ diff --git a/include/gz/gui/PlottingInterface.hh b/include/gz/gui/PlottingInterface.hh index 2953d8c25..fefd6c3e3 100644 --- a/include/gz/gui/PlottingInterface.hh +++ b/include/gz/gui/PlottingInterface.hh @@ -38,9 +38,7 @@ #include "gz/gui/Export.hh" -namespace gz -{ -namespace gui +namespace gz::gui { class PlotDataPrivate; @@ -333,7 +331,5 @@ class GZ_GUI_VISIBLE PlottingInterface : public QObject private: std::unique_ptr dataPtr; }; -} -} - -#endif +} // namespace gz::gui +#endif // GZ_GUI_PLOTTINGINTERFACE_HH_ diff --git a/include/gz/gui/Plugin.hh b/include/gz/gui/Plugin.hh index c025ed51f..323ac37d8 100644 --- a/include/gz/gui/Plugin.hh +++ b/include/gz/gui/Plugin.hh @@ -31,126 +31,122 @@ #pragma warning(disable: 4251) #endif -namespace gz +namespace gz::gui { - namespace 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: - /// - /// * The derived class' name is the same as the generated shared library - /// (i.e. if the Publisher class extends Plugin, the library file is - /// libPublisher.so) - /// - /// * There is a QML file with the same name as the plugin's shared library - /// name. - /// (i.e. there must be a Publisher.qml) - /// - /// * The QML file is prefixed by the library's name in the QRC file - /// (i.e. the file's resource is found at ':/Publisher/Publisher.qml') - class GZ_GUI_VISIBLE Plugin : public QObject - { - Q_OBJECT - - /// \brief Constructor - public: Plugin(); - - /// \brief Destructor - public: virtual ~Plugin(); - - /// \brief Load the plugin with a configuration file. - /// This loads the default parameters and then calls LoadConfig(), which - /// should be overridden to load custom parameters. - /// - /// Called when a plugin is first created. - /// This function should not be blocking. - /// - /// \sa Load - /// \param[in] _pluginElem Element containing configuration - public: void Load(const tinyxml2::XMLElement *_pluginElem); - - /// \brief Get the configuration XML as a string - /// \return Config element - public: virtual std::string ConfigStr(); - - /// \brief Get the card item which contains this plugin. The item is - /// generated the first time this function is run. - /// \return Pointer to card item. - public: QQuickItem *CardItem() const; - - /// \brief Get the plugin item. - /// \return Pointer to plugin item. - public: QQuickItem *PluginItem() const; - - /// \brief Get the QML context where the plugin was created. - /// \return Pointer context. - public: QQmlContext *Context() const; - - /// \brief Apply changes which should come after the plugin already - /// has a parent. - public: void PostParentChanges(); - - /// \brief Load the plugin with a configuration file. Override this - /// on custom plugins to handle custom configurations. - /// - /// Called when a plugin is first created. - /// This function should not be blocking. - /// - /// \sa Load - /// \param[in] _pluginElem Element containing configuration - protected: virtual void LoadConfig( - const tinyxml2::XMLElement *_pluginElem) - { - (void)_pluginElem; - } - - /// \brief Get title - /// \return Plugin title. - public: virtual std::string Title() const {return this->title;} - - /// \brief Get the value of the the `delete_later` element from the - /// configuration file, which defaults to false. - /// \return The value of `delete_later`. - public: bool DeleteLaterRequested() const; - - /// \brief Wait until the plugin has a parent, then close and delete the - /// parent. - protected: void DeleteLater(); - - /// \brief Title to be displayed on top of plugin. - protected: std::string title = ""; - - /// \brief XML configuration - protected: std::string configStr; - - /// \brief Load configuration which is common to all plugins and handled - /// by Gazebo GUI. - /// \details Called when a plugin is first created. - /// \sa LoadConfig - /// \param[in] _gzGuiElem element within the . - /// Will be nullptr if not present in the SDF. - private: virtual void LoadCommonConfig( - const tinyxml2::XMLElement *_gzGuiElem); - - /// \brief Apply any anchors which may have been specified on the config - /// through the tag and any state properties. - private: void ApplyAnchors(); - - /// \internal - /// \brief Pointer to private data - private: std::unique_ptr dataPtr; - }; - } -} +/// \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: +/// +/// * The derived class' name is the same as the generated shared library +/// (i.e. if the Publisher class extends Plugin, the library file is +/// libPublisher.so) +/// +/// * There is a QML file with the same name as the plugin's shared library +/// name. +/// (i.e. there must be a Publisher.qml) +/// +/// * The QML file is prefixed by the library's name in the QRC file +/// (i.e. the file's resource is found at ':/Publisher/Publisher.qml') +class GZ_GUI_VISIBLE Plugin : public QObject +{ + Q_OBJECT + + /// \brief Constructor + public: Plugin(); + + /// \brief Destructor + public: virtual ~Plugin(); + + /// \brief Load the plugin with a configuration file. + /// This loads the default parameters and then calls LoadConfig(), which + /// should be overridden to load custom parameters. + /// + /// Called when a plugin is first created. + /// This function should not be blocking. + /// + /// \sa Load + /// \param[in] _pluginElem Element containing configuration + public: void Load(const tinyxml2::XMLElement *_pluginElem); + + /// \brief Get the configuration XML as a string + /// \return Config element + public: virtual std::string ConfigStr(); + + /// \brief Get the card item which contains this plugin. The item is + /// generated the first time this function is run. + /// \return Pointer to card item. + public: QQuickItem *CardItem() const; + + /// \brief Get the plugin item. + /// \return Pointer to plugin item. + public: QQuickItem *PluginItem() const; + + /// \brief Get the QML context where the plugin was created. + /// \return Pointer context. + public: QQmlContext *Context() const; + + /// \brief Apply changes which should come after the plugin already + /// has a parent. + public: void PostParentChanges(); + + /// \brief Load the plugin with a configuration file. Override this + /// on custom plugins to handle custom configurations. + /// + /// Called when a plugin is first created. + /// This function should not be blocking. + /// + /// \sa Load + /// \param[in] _pluginElem Element containing configuration + protected: virtual void LoadConfig( + const tinyxml2::XMLElement *_pluginElem) + { + (void)_pluginElem; + } + + /// \brief Get title + /// \return Plugin title. + public: virtual std::string Title() const {return this->title;} + + /// \brief Get the value of the the `delete_later` element from the + /// configuration file, which defaults to false. + /// \return The value of `delete_later`. + public: bool DeleteLaterRequested() const; + + /// \brief Wait until the plugin has a parent, then close and delete the + /// parent. + protected: void DeleteLater(); + + /// \brief Title to be displayed on top of plugin. + protected: std::string title = ""; + + /// \brief XML configuration + protected: std::string configStr; + + /// \brief Load configuration which is common to all plugins and handled + /// by Gazebo GUI. + /// \details Called when a plugin is first created. + /// \sa LoadConfig + /// \param[in] _gzGuiElem element within the . + /// Will be nullptr if not present in the SDF. + private: virtual void LoadCommonConfig( + const tinyxml2::XMLElement *_gzGuiElem); + + /// \brief Apply any anchors which may have been specified on the config + /// through the tag and any state properties. + private: void ApplyAnchors(); + + /// \internal + /// \brief Pointer to private data + private: std::unique_ptr dataPtr; +}; +} // namespace gz::gui #ifdef _MSC_VER #pragma warning(pop) #endif - -#endif +#endif // GZ_GUI_PLUGIN_HH_ diff --git a/include/gz/gui/SearchModel.hh b/include/gz/gui/SearchModel.hh index 02996911b..e16ea4ec0 100644 --- a/include/gz/gui/SearchModel.hh +++ b/include/gz/gui/SearchModel.hh @@ -20,75 +20,72 @@ #include "gz/gui/Export.hh" #include "gz/gui/qt.h" -namespace gz +namespace gz::gui { -namespace gui +/// \brief Customize the proxy model to display search results. +/// +/// Features: +/// +/// * This has been tested with QTreeView and QTableView. +/// * Manages expansion of nested items through DataRole::TO_EXPAND when +/// applicable +/// * Items with DataRole::TYPE == "title" are ignored +/// +class GZ_GUI_VISIBLE SearchModel : public QSortFilterProxyModel { - /// \brief Customize the proxy model to display search results. + /// \brief Overloaded Qt method. Customize so we accept rows where: + /// 1. Each of the words can be found in its ancestors or itself, but not + /// necessarily all words on the same row, or + /// 2. One of its descendants matches rule 1, or + /// 3. One of its ancestors matches rule 1. /// - /// Features: + /// For example this structure: + /// - a + /// -- b + /// -- c + /// --- d /// - /// * This has been tested with QTreeView and QTableView. - /// * Manages expansion of nested items through DataRole::TO_EXPAND when - /// applicable - /// * Items with DataRole::TYPE == "title" are ignored + /// * A search of "a" will display all rows. + /// * A search of "b" or "a b" will display "a" and "b". + /// * A search of "c", "d", "a c", "a d", "a c d" or "c d" will display + /// "a", "c" and "d". + /// * A search of "a b c d", "b c" or "b d" will display nothing. /// - class GZ_GUI_VISIBLE SearchModel : public QSortFilterProxyModel - { - /// \brief Overloaded Qt method. Customize so we accept rows where: - /// 1. Each of the words can be found in its ancestors or itself, but not - /// necessarily all words on the same row, or - /// 2. One of its descendants matches rule 1, or - /// 3. One of its ancestors matches rule 1. - /// - /// For example this structure: - /// - a - /// -- b - /// -- c - /// --- d - /// - /// * A search of "a" will display all rows. - /// * A search of "b" or "a b" will display "a" and "b". - /// * A search of "c", "d", "a c", "a d", "a c d" or "c d" will display - /// "a", "c" and "d". - /// * A search of "a b c d", "b c" or "b d" will display nothing. - /// - /// \param[in] _srcRow Row on the source model. - /// \param[in] _srcParent Parent on the source model. - /// \return True if row is accepted. - public: bool filterAcceptsRow(const int _srcRow, - const QModelIndex &_srcParent) const; + /// \param[in] _srcRow Row on the source model. + /// \param[in] _srcParent Parent on the source model. + /// \return True if row is accepted. + public: bool filterAcceptsRow(const int _srcRow, + const QModelIndex &_srcParent) const; - /// \brief Check if row contains the word on itself. - /// \param[in] _srcRow Row on the source model. - /// \param[in] _srcParent Parent on the source model. - /// \param[in] _word Word to be checked. - /// \return True if row matches. - public: bool FilterAcceptsRowItself(const int _srcRow, - const QModelIndex &_srcParent, - const QString &_word) const; + /// \brief Check if row contains the word on itself. + /// \param[in] _srcRow Row on the source model. + /// \param[in] _srcParent Parent on the source model. + /// \param[in] _word Word to be checked. + /// \return True if row matches. + public: bool FilterAcceptsRowItself(const int _srcRow, + const QModelIndex &_srcParent, + const QString &_word) const; - /// \brief Check if any of the children is fully accepted. - /// \param[in] _srcRow Row on the source model. - /// \param[in] _srcParent Parent on the source model. - /// \return True if any of the children match. - public: bool HasAcceptedChildren(const int _srcRow, - const QModelIndex &_srcParent) const; + /// \brief Check if any of the children is fully accepted. + /// \param[in] _srcRow Row on the source model. + /// \param[in] _srcParent Parent on the source model. + /// \return True if any of the children match. + public: bool HasAcceptedChildren(const int _srcRow, + const QModelIndex &_srcParent) const; - /// \brief Check if any of the children accepts a specific word. - /// \param[in] _srcParent Parent on the source model. - /// \param[in] _word Word to be checked. - /// \return True if any of the children match. - public: bool HasChildAcceptsItself(const QModelIndex &_srcParent, - const QString &_word) const; + /// \brief Check if any of the children accepts a specific word. + /// \param[in] _srcParent Parent on the source model. + /// \param[in] _word Word to be checked. + /// \return True if any of the children match. + public: bool HasChildAcceptsItself(const QModelIndex &_srcParent, + const QString &_word) const; - /// \brief Set a new search value. - /// \param[in] _search Full search string. - public: void SetSearch(const QString &_search); + /// \brief Set a new search value. + /// \param[in] _search Full search string. + public: void SetSearch(const QString &_search); - /// \brief Full search string. - public: QString search; - }; -} -} + /// \brief Full search string. + public: QString search; +}; +} // namespace gz::gui #endif diff --git a/include/gz/gui/gz.hh b/include/gz/gui/gz.hh index 59a89b274..6db8f4fe4 100644 --- a/include/gz/gui/gz.hh +++ b/include/gz/gui/gz.hh @@ -42,4 +42,4 @@ extern "C" GZ_GUI_VISIBLE void cmdEmptyWindow(); /// \param[in] _filename Path to a QSS file. extern "C" GZ_GUI_VISIBLE void cmdSetStyleFromFile(const char *_filename); -#endif +#endif // GZ_GUI_GZ_HH_ diff --git a/src/Application.cc b/src/Application.cc index 062ce0f2e..e1e18cf78 100644 --- a/src/Application.cc +++ b/src/Application.cc @@ -36,60 +36,55 @@ #include "gz/transport/TopicUtils.hh" -namespace gz +namespace { +enum class GZ_COMMON_HIDDEN AvailableAPIs { - namespace gui - { - class ApplicationPrivate - { - /// \brief QML engine - public: QQmlApplicationEngine *engine{nullptr}; - - /// \brief Pointer to main window - public: MainWindow *mainWin{nullptr}; + OpenGL, + Vulkan, + Metal +}; +} // namespace - /// \brief Vector of pointers to dialogs - public: std::vector dialogs; +namespace gz::gui +{ +class ApplicationPrivate +{ + /// \brief QML engine + public: QQmlApplicationEngine *engine{nullptr}; - /// \brief Queue of plugins which should be added to the window - public: std::queue> pluginsToAdd; + /// \brief Pointer to main window + public: MainWindow *mainWin{nullptr}; - /// \brief Vector of pointers to plugins already added, we hang on to - /// these until it is ok to unload the plugin's shared library. - public: std::vector> pluginsAdded; + /// \brief Vector of pointers to dialogs + public: std::vector dialogs; - /// \brief Environment variable which holds paths to look for plugins - public: std::string pluginPathEnv = "GZ_GUI_PLUGIN_PATH"; + /// \brief Queue of plugins which should be added to the window + public: std::queue> pluginsToAdd; - /// \brief Vector of paths to look for plugins - public: std::vector pluginPaths; + /// \brief Vector of pointers to plugins already added, we hang on to + /// these until it is ok to unload the plugin's shared library. + public: std::vector> pluginsAdded; - /// \brief Holds a configuration which may be applied to mainWin once it - /// is created by calling applyConfig(). It's no longer needed and - /// should not be used after that. - public: WindowConfig windowConfig; + /// \brief Environment variable which holds paths to look for plugins + public: std::string pluginPathEnv = "GZ_GUI_PLUGIN_PATH"; - /// \brief The path containing the default configuration file. - public: std::string defaultConfigPath; + /// \brief Vector of paths to look for plugins + public: std::vector pluginPaths; - public: common::SignalHandler signalHandler; + /// \brief Holds a configuration which may be applied to mainWin once it + /// is created by calling applyConfig(). It's no longer needed and + /// should not be used after that. + public: WindowConfig windowConfig; - /// \brief QT message handler that pipes qt messages into our console - /// system. - public: static void MessageHandler(QtMsgType _type, - const QMessageLogContext &_context, const QString &_msg); - }; - } -} + /// \brief The path containing the default configuration file. + public: std::string defaultConfigPath; -using namespace gz; -using namespace gui; + public: common::SignalHandler signalHandler; -enum class GZ_COMMON_HIDDEN AvailableAPIs -{ - OpenGL, - Vulkan, - Metal + /// \brief QT message handler that pipes qt messages into our console + /// system. + public: static void MessageHandler(QtMsgType _type, + const QMessageLogContext &_context, const QString &_msg); }; ///////////////////////////////////////////////// @@ -279,7 +274,7 @@ QQmlApplicationEngine *Application::Engine() const } ///////////////////////////////////////////////// -Application *gz::gui::App() +Application *App() { return qobject_cast(qGuiApp); } @@ -913,3 +908,4 @@ void ApplicationPrivate::MessageHandler(QtMsgType _type, break; } } +} // namepace gz::gui diff --git a/src/Application_TEST.cc b/src/Application_TEST.cc index c3f3faefb..f573e581a 100644 --- a/src/Application_TEST.cc +++ b/src/Application_TEST.cc @@ -26,32 +26,35 @@ #include "gz/gui/MainWindow.hh" #include "gz/gui/Plugin.hh" +using Application = gz::gui::Application; +using Dialog = gz::gui::Dialog; +using MainWindow = gz::gui::MainWindow; +using Plugin = gz::gui::Plugin; +using WindowType = gz::gui::WindowType; + int g_argc = 1; char* g_argv[] = { reinterpret_cast(const_cast("./Application_TEST")), }; -using namespace gz; -using namespace gui; - // See https://github.com/gazebosim/gz-gui/issues/75 ////////////////////////////////////////////////// TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Constructor)) { - common::Console::SetVerbosity(4); + gz::common::Console::SetVerbosity(4); // No Qt app ASSERT_EQ(nullptr, qGuiApp); - ASSERT_EQ(nullptr, App()); + ASSERT_EQ(nullptr, gz::gui::App()); // One app construct - destruct { Application app(g_argc, g_argv); EXPECT_NE(nullptr, qGuiApp); - ASSERT_NE(nullptr, App()); - EXPECT_NE(nullptr, App()->Engine()); + ASSERT_NE(nullptr, gz::gui::App()); + EXPECT_NE(nullptr, gz::gui::App()->Engine()); // No crash if argc and argv were correctly set QCoreApplication::arguments(); @@ -59,7 +62,7 @@ TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Constructor)) // No Qt app EXPECT_EQ(nullptr, qGuiApp); - EXPECT_EQ(nullptr, App()); + EXPECT_EQ(nullptr, gz::gui::App()); } ////////////////////////////////////////////////// @@ -172,7 +175,7 @@ TEST(ApplicationTest, ////////////////////////////////////////////////// TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadConfig)) { - common::Console::SetVerbosity(4); + gz::common::Console::SetVerbosity(4); ASSERT_EQ(nullptr, qGuiApp); @@ -222,7 +225,7 @@ TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadConfig)) ////////////////////////////////////////////////// TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadDefaultConfig)) { - common::Console::SetVerbosity(4); + gz::common::Console::SetVerbosity(4); ASSERT_EQ(nullptr, qGuiApp); @@ -231,12 +234,12 @@ TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadDefaultConfig)) Application app(g_argc, g_argv); // Add test plugin to path (referenced in config) - auto testBuildPath = common::joinPaths( + auto testBuildPath = gz::common::joinPaths( std::string(PROJECT_BINARY_PATH), "lib"); app.AddPluginPath(testBuildPath); // Set default config file - auto configPath = common::joinPaths( + auto configPath = gz::common::joinPaths( std::string(PROJECT_SOURCE_PATH), "test", "config", "test.config"); app.SetDefaultConfigPath(configPath); @@ -248,7 +251,7 @@ TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadDefaultConfig)) TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(InitializeMainWindow)) { - common::Console::SetVerbosity(4); + gz::common::Console::SetVerbosity(4); ASSERT_EQ(nullptr, qGuiApp); @@ -272,7 +275,7 @@ TEST(ApplicationTest, EXPECT_TRUE(app.LoadPlugin("Publisher")); - auto win = App()->findChild(); + auto win = gz::gui::App()->findChild(); ASSERT_NE(nullptr, win); // Check plugin count @@ -300,7 +303,7 @@ TEST(ApplicationTest, // Load test config file EXPECT_TRUE(app.LoadConfig(testSourcePath + "config/test.config")); - auto win = App()->findChild(); + auto win = gz::gui::App()->findChild(); ASSERT_NE(nullptr, win); // Check plugin count @@ -318,7 +321,7 @@ TEST(ApplicationTest, ////////////////////////////////////////////////// TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Dialog)) { - common::Console::SetVerbosity(4); + gz::common::Console::SetVerbosity(4); ASSERT_EQ(nullptr, qGuiApp); @@ -393,7 +396,7 @@ TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Dialog)) ///////////////////////////////////////////////// TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(messageHandler)) { - common::Console::SetVerbosity(4); + gz::common::Console::SetVerbosity(4); ASSERT_EQ(nullptr, qGuiApp); diff --git a/src/Conversions.cc b/src/Conversions.cc index 3464ef7b2..09a6dd193 100644 --- a/src/Conversions.cc +++ b/src/Conversions.cc @@ -21,8 +21,10 @@ #include "gz/gui/Conversions.hh" +namespace gz::gui { + ////////////////////////////////////////////////// -QColor gz::gui::convert(const gz::math::Color &_color) +QColor convert(const gz::math::Color &_color) { return QColor(_color.R()*255.0, _color.G()*255.0, @@ -31,7 +33,7 @@ QColor gz::gui::convert(const gz::math::Color &_color) } ////////////////////////////////////////////////// -gz::math::Color gz::gui::convert(const QColor &_color) +gz::math::Color convert(const QColor &_color) { return gz::math::Color(_color.red() / 255.0, _color.green() / 255.0, @@ -40,31 +42,31 @@ gz::math::Color gz::gui::convert(const QColor &_color) } ////////////////////////////////////////////////// -QPointF gz::gui::convert(const gz::math::Vector2d &_pt) +QPointF convert(const gz::math::Vector2d &_pt) { return QPointF(_pt.X(), _pt.Y()); } ////////////////////////////////////////////////// -gz::math::Vector2d gz::gui::convert(const QPointF &_pt) +gz::math::Vector2d convert(const QPointF &_pt) { return gz::math::Vector2d(_pt.x(), _pt.y()); } ////////////////////////////////////////////////// -QVector3D gz::gui::convert(const gz::math::Vector3d &_vec) +QVector3D convert(const gz::math::Vector3d &_vec) { return QVector3D(_vec.X(), _vec.Y(), _vec.Z()); } ////////////////////////////////////////////////// -gz::math::Vector3d gz::gui::convert(const QVector3D &_vec) +gz::math::Vector3d convert(const QVector3D &_vec) { return gz::math::Vector3d(_vec.x(), _vec.y(), _vec.z()); } ////////////////////////////////////////////////// -gz::common::MouseEvent gz::gui::convert(const QMouseEvent &_e) +gz::common::MouseEvent convert(const QMouseEvent &_e) { common::MouseEvent event; event.SetPos(_e.pos().x(), _e.pos().y()); @@ -115,7 +117,7 @@ gz::common::MouseEvent gz::gui::convert(const QMouseEvent &_e) } ////////////////////////////////////////////////// -gz::common::MouseEvent gz::gui::convert(const QWheelEvent &_e) +gz::common::MouseEvent convert(const QWheelEvent &_e) { common::MouseEvent event; @@ -152,7 +154,7 @@ gz::common::MouseEvent gz::gui::convert(const QWheelEvent &_e) } ////////////////////////////////////////////////// -gz::common::KeyEvent gz::gui::convert(const QKeyEvent &_e) +gz::common::KeyEvent convert(const QKeyEvent &_e) { common::KeyEvent event; event.SetKey(_e.key()); @@ -177,4 +179,4 @@ gz::common::KeyEvent gz::gui::convert(const QKeyEvent &_e) return event; } - +} // namespace gz::gui diff --git a/src/Dialog.cc b/src/Dialog.cc index becaea62b..796dfed39 100644 --- a/src/Dialog.cc +++ b/src/Dialog.cc @@ -21,20 +21,13 @@ #include "gz/gui/Application.hh" #include "gz/gui/Dialog.hh" -namespace gz +namespace gz::gui { - namespace gui - { - class DialogPrivate - { - /// \brief Pointer to quick window - public: QQuickWindow *quickWindow{nullptr}; - }; - } -} - -using namespace gz; -using namespace gui; +class DialogPrivate +{ + /// \brief Pointer to quick window + public: QQuickWindow *quickWindow{nullptr}; +}; ///////////////////////////////////////////////// Dialog::Dialog() @@ -176,3 +169,4 @@ std::string Dialog::ReadConfigAttribute(const std::string &_path, return std::string(); } +} // namespace gz::gui diff --git a/src/DragDropModel.cc b/src/DragDropModel.cc index 73a645c0d..9c1623634 100644 --- a/src/DragDropModel.cc +++ b/src/DragDropModel.cc @@ -18,9 +18,8 @@ #include "gz/gui/Enums.hh" #include "gz/gui/DragDropModel.hh" -using namespace gz; -using namespace gui; - +namespace gz::gui +{ ///////////////////////////////////////////////// QMimeData *DragDropModel::mimeData(const QModelIndexList &_indexes) const { @@ -39,4 +38,4 @@ QMimeData *DragDropModel::mimeData(const QModelIndexList &_indexes) const return curMimeData; } - +} // namespace gz::gui diff --git a/src/GuiEvents.cc b/src/GuiEvents.cc index 053e306c4..5789e3980 100644 --- a/src/GuiEvents.cc +++ b/src/GuiEvents.cc @@ -17,7 +17,10 @@ #include "gz/gui/GuiEvents.hh" -class gz::gui::events::SnapIntervals::Implementation +namespace gz::gui::events +{ + +class events::SnapIntervals::Implementation { /// \brief XYZ snapping values in meters, these values must be positive. public: math::Vector3d xyz; @@ -31,85 +34,85 @@ class gz::gui::events::SnapIntervals::Implementation public: math::Vector3d scale; }; -class gz::gui::events::SpawnFromDescription::Implementation +class SpawnFromDescription::Implementation { /// \brief The string of the resource to be spawned. public: std::string description; }; -class gz::gui::events::SpawnFromPath::Implementation +class SpawnFromPath::Implementation { /// \brief The path of file to be previewed. public: std::string filePath; }; -class gz::gui::events::HoverToScene::Implementation +class HoverToScene::Implementation { /// \brief The 3D point over which the user is hovering. public: math::Vector3d point; }; -class gz::gui::events::HoverOnScene::Implementation +class HoverOnScene::Implementation { /// \brief The 2D point over which the user is hovering. public: common::MouseEvent mouse; }; -class gz::gui::events::LeftClickToScene::Implementation +class LeftClickToScene::Implementation { /// \brief The 3D point that the user clicked within the scene. public: math::Vector3d point; }; -class gz::gui::events::RightClickToScene::Implementation +class RightClickToScene::Implementation { /// \brief The 3D point that the user clicked within the scene. public: math::Vector3d point; }; -class gz::gui::events::DropdownMenuEnabled::Implementation +class DropdownMenuEnabled::Implementation { /// \brief The boolean indicating whether the menu is disabled or not /// for this event. public: bool menuEnabled; }; -class gz::gui::events::LeftClickOnScene::Implementation +class LeftClickOnScene::Implementation { /// \brief Mouse event public: common::MouseEvent mouse; }; -class gz::gui::events::RightClickOnScene::Implementation +class RightClickOnScene::Implementation { /// \brief Mouse event public: common::MouseEvent mouse; }; -class gz::gui::events::BlockOrbit::Implementation +class BlockOrbit::Implementation { public: bool block; }; -class gz::gui::events::KeyReleaseOnScene::Implementation +class KeyReleaseOnScene::Implementation { /// \brief Key event public: common::KeyEvent key; }; -class gz::gui::events::KeyPressOnScene::Implementation +class KeyPressOnScene::Implementation { /// \brief Key event public: common::KeyEvent key; }; -class gz::gui::events::SpawnCloneFromName::Implementation +class SpawnCloneFromName::Implementation { /// \brief The name of the resource to be cloned public: std::string name; }; -class gz::gui::events::DropOnScene::Implementation +class DropOnScene::Implementation { /// \brief The name of the dropped thing public: std::string dropText; @@ -118,38 +121,34 @@ class gz::gui::events::DropOnScene::Implementation public: gz::math::Vector2i mouse; }; -class gz::gui::events::ScrollOnScene::Implementation +class ScrollOnScene::Implementation { /// \brief Mouse event with scroll information. public: common::MouseEvent mouse; }; -class gz::gui::events::DragOnScene::Implementation +class DragOnScene::Implementation { /// \brief Mouse event with drag information. public: common::MouseEvent mouse; }; -class gz::gui::events::MousePressOnScene::Implementation +class MousePressOnScene::Implementation { /// \brief Mouse event with press information. public: common::MouseEvent mouse; }; -class gz::gui::events::WorldControl::Implementation +class WorldControl::Implementation { /// \brief WorldControl information. public: msgs::WorldControl worldControl; }; -class gz::gui::events::PreRender::Implementation +class PreRender::Implementation { }; -using namespace gz; -using namespace gui; -using namespace events; - ///////////////////////////////////////////////// SnapIntervals::SnapIntervals( const math::Vector3d &_xyz, @@ -430,3 +429,4 @@ PreRender::PreRender() : QEvent(kType), dataPtr(utils::MakeImpl()) { } +} // namespace gz::gui::events diff --git a/src/Helpers.cc b/src/Helpers.cc index 95b54a61c..3e53c7c17 100644 --- a/src/Helpers.cc +++ b/src/Helpers.cc @@ -25,8 +25,11 @@ #include "gz/gui/Helpers.hh" #include "gz/gui/MainWindow.hh" +namespace gz::gui +{ + ///////////////////////////////////////////////// -std::string gz::gui::humanReadable(const std::string &_key) +std::string humanReadable(const std::string &_key) { std::string humanKey = _key; humanKey[0] = toupper(humanKey[0]); @@ -35,7 +38,7 @@ std::string gz::gui::humanReadable(const std::string &_key) } ///////////////////////////////////////////////// -std::string gz::gui::unitFromKey(const std::string &_key, +std::string unitFromKey(const std::string &_key, const std::string &_type) { if (_key == "pos" || _key == "length" || _key == "min_depth") @@ -110,7 +113,7 @@ std::string gz::gui::unitFromKey(const std::string &_key, } ///////////////////////////////////////////////// -void gz::gui::rangeFromKey(const std::string &_key, double &_min, +void rangeFromKey(const std::string &_key, double &_min, double &_max) { // Maximum range by default @@ -139,19 +142,19 @@ void gz::gui::rangeFromKey(const std::string &_key, double &_min, } ///////////////////////////////////////////////// -gz::gui::StringType gz::gui::stringTypeFromKey( +StringType stringTypeFromKey( const std::string &_key) { if (_key == "innerxml") { - return gz::gui::StringType::PLAIN_TEXT; + return StringType::PLAIN_TEXT; } return StringType::LINE; } ///////////////////////////////////////////////// -std::string gz::gui::uniqueFilePath(const std::string &_pathAndName, +std::string uniqueFilePath(const std::string &_pathAndName, const std::string &_extension) { std::string result = _pathAndName + "." + _extension; @@ -168,7 +171,7 @@ std::string gz::gui::uniqueFilePath(const std::string &_pathAndName, } ///////////////////////////////////////////////// -QStringList gz::gui::worldNames() +QStringList worldNames() { auto win = App()->findChild(); if (nullptr == win) @@ -182,7 +185,7 @@ QStringList gz::gui::worldNames() } ///////////////////////////////////////////////// -std::string gz::gui::renderEngineName() +std::string renderEngineName() { auto win = App()->findChild(); if (nullptr == win) @@ -196,7 +199,7 @@ std::string gz::gui::renderEngineName() } ///////////////////////////////////////////////// -std::string gz::gui::renderEngineBackendApiName() +std::string renderEngineBackendApiName() { auto win = App()->findChild(); if (nullptr == win) @@ -210,7 +213,8 @@ std::string gz::gui::renderEngineBackendApiName() } ///////////////////////////////////////////////// -const QString gz::gui::qmlQrcImportPath() +const QString qmlQrcImportPath() { return "qrc:/gz-gui-qml/"; } +} // namespace gz::gui diff --git a/src/MainWindow.cc b/src/MainWindow.cc index a084d485d..ec009c0af 100644 --- a/src/MainWindow.cc +++ b/src/MainWindow.cc @@ -29,60 +29,53 @@ #include "gz/msgs/server_control.pb.h" #include "gz/transport/Node.hh" -namespace gz +namespace gz::gui { - namespace gui - { - class MainWindowPrivate - { - /// \brief Number of plugins on the window - public: int pluginCount{0}; - - /// \brief Pointer to quick window - public: QQuickWindow *quickWindow{nullptr}; +class MainWindowPrivate +{ + /// \brief Number of plugins on the window + public: int pluginCount{0}; - /// \brief Configuration for this window. - public: WindowConfig windowConfig; + /// \brief Pointer to quick window + public: QQuickWindow *quickWindow{nullptr}; - /// \brief Counts the times the window has been painted - public: unsigned int paintCount{0}; + /// \brief Configuration for this window. + public: WindowConfig windowConfig; - /// \brief Minimum number of paint events to consider the window to be - /// fully initialized. - public: const unsigned int paintCountMin{20}; + /// \brief Counts the times the window has been painted + public: unsigned int paintCount{0}; - /// \brief The action executed when GUI is closed without prompt. - public: ExitAction defaultExitAction{ExitAction::CLOSE_GUI}; + /// \brief Minimum number of paint events to consider the window to be + /// fully initialized. + public: const unsigned int paintCountMin{20}; - /// \brief Show the confirmation dialog on exit - public: bool showDialogOnExit{false}; + /// \brief The action executed when GUI is closed without prompt. + public: ExitAction defaultExitAction{ExitAction::CLOSE_GUI}; - /// \brief Text of the prompt in the confirmation dialog on exit - public: QString dialogOnExitText; + /// \brief Show the confirmation dialog on exit + public: bool showDialogOnExit{false}; - /// \brief Show "shutdown" button in exit dialog - public: bool exitDialogShowShutdown{false}; + /// \brief Text of the prompt in the confirmation dialog on exit + public: QString dialogOnExitText; - /// \brief Show "Close GUI" button in exit dialog - public: bool exitDialogShowCloseGui{true}; + /// \brief Show "shutdown" button in exit dialog + public: bool exitDialogShowShutdown{false}; - /// \brief Text of "shutdown" button in exit dialog - public: QString exitDialogShutdownText; + /// \brief Show "Close GUI" button in exit dialog + public: bool exitDialogShowCloseGui{true}; - /// \brief Text of "Close GUI" button in exit dialog - public: QString exitDialogCloseGuiText; + /// \brief Text of "shutdown" button in exit dialog + public: QString exitDialogShutdownText; - /// \brief Service to send server control requests - public: std::string controlService{"/server_control"}; + /// \brief Text of "Close GUI" button in exit dialog + public: QString exitDialogCloseGuiText; - /// \brief Communication node - public: gz::transport::Node node; - }; - } -} + /// \brief Service to send server control requests + public: std::string controlService{"/server_control"}; -using namespace gz; -using namespace gui; + /// \brief Communication node + public: gz::transport::Node node; +}; /// \brief Strip last component from a path. /// \return Original path without its last component. @@ -1029,3 +1022,4 @@ void MainWindow::SetServerControlService(const std::string &_service) { this->dataPtr->controlService = _service; } +} // namespace gz::gui diff --git a/src/PlottingInterface.cc b/src/PlottingInterface.cc index ae158f2b7..3c8f69359 100644 --- a/src/PlottingInterface.cc +++ b/src/PlottingInterface.cc @@ -29,9 +29,7 @@ // 1/60 Period like the GuiSystem frequency (60Hz) #define MAX_PERIOD_DIFF (0.0166666667) -namespace gz -{ -namespace gui +namespace gz::gui { class PlotDataPrivate { @@ -92,12 +90,6 @@ class PlottingIfacePrivate public: QTimer timer; }; -} -} - -using namespace gz; -using namespace gui; - ////////////////////////////////////////////////////// PlotData::PlotData() : dataPtr(std::make_unique()) @@ -677,3 +669,4 @@ bool PlottingInterface::exportCSV(QString _path, int _chart, } return true; } +} // namespace gz::gui diff --git a/src/Plugin.cc b/src/Plugin.cc index 3da524344..fbdc02762 100644 --- a/src/Plugin.cc +++ b/src/Plugin.cc @@ -51,7 +51,9 @@ static const std::unordered_set kIgnoredProps{ "pluginName", "anchored"}; -class gz::gui::PluginPrivate +namespace gz::gui +{ +class PluginPrivate { /// \brief Set this to true if the plugin should be deleted as soon as it has /// a parent. @@ -583,3 +585,4 @@ void Plugin::ApplyAnchors() } this->CardItem()->setProperty("anchored", true); } +} // namespace gz::gui diff --git a/src/SearchModel.cc b/src/SearchModel.cc index 3ccf2bbe3..6a41d93b1 100644 --- a/src/SearchModel.cc +++ b/src/SearchModel.cc @@ -20,9 +20,8 @@ #include "gz/gui/Enums.hh" #include "gz/gui/SearchModel.hh" -using namespace gz; -using namespace gui; - +namespace gz::gui +{ ///////////////////////////////////////////////// bool SearchModel::filterAcceptsRow(const int _srcRow, const QModelIndex &_srcParent) const @@ -155,4 +154,4 @@ void SearchModel::SetSearch(const QString &_search) // TopicsStats this->layoutChanged(); } - +} // namespace gz::gui