Gazebo Gui

API Reference

3.12.0
gz/gui/Application.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef GZ_GUI_APPLICATION_HH_
18 #define GZ_GUI_APPLICATION_HH_
19 
20 #include <memory>
21 #include <string>
22 #include <utility>
23 #include <vector>
24 
25 #include "gz/gui/qt.h"
26 #include "gz/gui/Export.hh"
27 
28 #ifdef _WIN32
29 // Disable warning C4251 which is triggered by
30 // std::unique_ptr
31 #pragma warning(push)
32 #pragma warning(disable: 4251)
33 #endif
34 
35 namespace tinyxml2
36 {
37  class XMLElement;
38 }
39 
40 namespace ignition
41 {
42  namespace gui
43  {
44  class ApplicationPrivate;
45  class Dialog;
46  class MainWindow;
47  class Plugin;
48 
50  enum class WindowType : int
51  {
54  kMainWindow = 0,
55 
58  kDialog = 1
59  };
60 
65  class IGNITION_GUI_VISIBLE Application : public QGuiApplication
66  {
67  Q_OBJECT
68 
73  public: Application(int &_argc, char **_argv,
74  const WindowType _type = WindowType::kMainWindow);
75 
77  public: virtual ~Application();
78 
81  public: QQmlApplicationEngine *Engine() const;
82 
93  public: bool LoadPlugin(const std::string &_filename,
94  const tinyxml2::XMLElement *_pluginElem = nullptr);
95 
105  public: bool LoadConfig(const std::string &_path);
106 
112  public: bool LoadDefaultConfig();
113 
121  public: void SetDefaultConfigPath(const std::string &_path);
122 
127  public: std::string DefaultConfigPath();
128 
132  public: void SetPluginPathEnv(const std::string &_env);
133 
136  public: void AddPluginPath(const std::string &_path);
137 
150  PluginList();
151 
158  public: bool RemovePlugin(const std::string &_pluginName);
159 
160 
165  public: std::shared_ptr<Plugin> PluginByName(
166  const std::string &_pluginName) const;
167 
170  signals: void PluginAdded(const QString &_objectName);
171 
173  public slots: void OnPluginClose();
174 
178  public: bool CreateMainWindow();
179 
186  private: bool InitializeMainWindow();
187 
193  private: bool InitializeDialogs();
194 
197  private: void RemovePlugin(std::shared_ptr<Plugin> _plugin);
198 
203  private: bool AddPluginsToWindow();
204 
208  private: bool ApplyConfig();
209 
212  private: std::unique_ptr<ApplicationPrivate> dataPtr;
213  };
214 
217  IGNITION_GUI_VISIBLE
218  Application *App();
219  }
220 }
221 
222 #ifdef _MSC_VER
223 #pragma warning(pop)
224 #endif
225 
226 #endif
std::vector< std::pair< std::string, std::vector< std::string > > > PluginList()
Get the list of available plugins, organized by path. The paths are given in the following order:
STL class.
STL class.
virtual ~Application()
Destructor.
std::string DefaultConfigPath()
Get the location of the default configuration file.
STL class.
bool LoadConfig(const std::string &_path)
Load a configuration file, which includes window configurations and plugins. This function doesn't in...
An Gazebo GUI application loads a QML engine and provides an API to load plugins and configuration fi...
Definition: gz/gui/Application.hh:65
@ kDialog
One independent dialog per plugin. Also useful to open a startup dialog before the main window.
void PluginAdded(const QString &_objectName)
Notify that a plugin has been added.
bool LoadDefaultConfig()
Load the configuration from the default config file.
The main window class creates a QQuickWindow and acts as an interface which provides properties and f...
Definition: gz/gui/MainWindow.hh:61
QQmlApplicationEngine * Engine() const
Get the QML engine.
bool RemovePlugin(const std::string &_pluginName)
Remove plugin by name. The plugin is removed from the application and its shared library unloaded if ...
bool CreateMainWindow()
Create a main window. Just calls InitializeMainWindow.
Application(int &_argc, char **_argv, const WindowType _type=WindowType::kMainWindow)
Constructor.
void AddPluginPath(const std::string &_path)
Add an path to look for plugins.
Base class for Gazebo GUI plugins.
Definition: gz/gui/Plugin.hh:54
bool LoadPlugin(const std::string &_filename, const tinyxml2::XMLElement *_pluginElem=nullptr)
Load a plugin from a file name. The plugin file must be in the path. If a window has been initialized...
void OnPluginClose()
Callback when user requests to close a plugin.
std::shared_ptr< Plugin > PluginByName(const std::string &_pluginName) const
Get a plugin by its unique name.
void SetDefaultConfigPath(const std::string &_path)
Specifies the location of the default configuration file. This is the file that stores the user setti...
Gui plugin.
Definition: gz/gui/Dialog.hh:41
Application * App()
Get current running application, this is a cast of qGuiApp.
Definition: gz/gui/Application.hh:35
WindowType
Type of window which the application will display.
Definition: gz/gui/Application.hh:50
@ kMainWindow
A main window, which may contain top-level menus and multiple plugins.
void SetPluginPathEnv(const std::string &_env)
Set the environment variable which defines the paths to look for plugins.