Gazebo Gui

API Reference

6.8.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 QApplication
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 
104  public: bool LoadConfig(const std::string &_path);
105 
111  public: bool LoadDefaultConfig();
112 
120  public: void SetDefaultConfigPath(const std::string &_path);
121 
126  public: std::string DefaultConfigPath();
127 
131  public: void SetPluginPathEnv(const std::string &_env);
132 
135  public: void AddPluginPath(const std::string &_path);
136 
149  PluginList();
150 
157  public: bool RemovePlugin(const std::string &_pluginName);
158 
159 
164  public: std::shared_ptr<Plugin> PluginByName(
165  const std::string &_pluginName) const;
166 
169  signals: void PluginAdded(const QString &_objectName);
170 
172  public slots: void OnPluginClose();
173 
177  public: bool CreateMainWindow();
178 
185  private: bool InitializeMainWindow();
186 
192  private: bool InitializeDialogs();
193 
196  private: void RemovePlugin(std::shared_ptr<Plugin> _plugin);
197 
202  private: bool AddPluginsToWindow();
203 
207  private: bool ApplyConfig();
208 
211  private: std::unique_ptr<ApplicationPrivate> dataPtr;
212  };
213 
216  IGNITION_GUI_VISIBLE
217  Application *App();
218  }
219 }
220 
221 #ifdef _MSC_VER
222 #pragma warning(pop)
223 #endif
224 
225 #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...
A Gazebo GUI application loads a QML engine and provides an API to load plugins and configuration fil...
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.