QGIS API Documentation  3.9.0-Master (224899f119)
qgsgui.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsgui.cpp
3  ----------
4  begin : May 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgsgui.h"
23 #include "qgslayoutitemregistry.h"
26 #ifdef Q_OS_MACX
27 #include "qgsmacnative.h"
28 #elif defined (Q_OS_WIN)
29 #ifndef __MINGW32__
30 #include "qgswinnative.h"
31 #else
32 #include "qgsnative.h"
33 #endif
34 #elif defined (Q_OS_LINUX)
35 #include "qgslinuxnative.h"
36 #else
37 #include "qgsnative.h"
38 #endif
40 #include "qgsshortcutsmanager.h"
41 #include "qgswidgetstatehelper_p.h"
42 #include "qgslogger.h"
45 #include "qgssettings.h"
47 #include "qgsgdalguiprovider.h"
48 #include "qgsogrguiprovider.h"
49 #include "qgsproviderregistry.h"
50 #include "qgsproviderguiregistry.h"
52 
54 {
55  static QgsGui *sInstance( new QgsGui() );
56  return sInstance;
57 }
58 
60 {
61  return instance()->mNative;
62 }
63 
65 {
66  return instance()->mEditorWidgetRegistry;
67 }
68 
70 {
71  return instance()->mSourceSelectProviderRegistry;
72 }
73 
75 {
76  return instance()->mShortcutsManager;
77 }
78 
80 {
81  return instance()->mLayerTreeEmbeddedWidgetRegistry;
82 }
83 
85 {
86  return instance()->mMapLayerActionRegistry;
87 }
88 
90 {
91  return instance()->mLayoutItemGuiRegistry;
92 }
93 
95 {
96  return instance()->mProcessingGuiRegistry;
97 }
98 
99 QgsProcessingRecentAlgorithmLog *QgsGui::processingRecentAlgorithmLog()
100 {
101  return instance()->mProcessingRecentAlgorithmLog;
102 }
103 
105 {
106  return instance()->mDataItemGuiProviderRegistry;
107 }
108 
110 {
111  return instance()->mProjectStorageGuiRegistry;
112 }
113 
115 {
116  return instance()->mProviderGuiRegistry;
117 }
118 
119 void QgsGui::enableAutoGeometryRestore( QWidget *widget, const QString &key )
120 {
121  if ( widget->objectName().isEmpty() )
122  {
123  QgsDebugMsg( QStringLiteral( "WARNING: No object name set. Best for it to be set objectName when using QgsGui::enableAutoGeometryRestore" ) );
124  }
125  instance()->mWidgetStateHelper->registerWidget( widget, key );
126 }
127 
128 QgsWindowManagerInterface *QgsGui::windowManager()
129 {
130  return instance()->mWindowManager.get();
131 }
132 
133 void QgsGui::setWindowManager( QgsWindowManagerInterface *manager )
134 {
135  instance()->mWindowManager.reset( manager );
136 }
137 
138 QgsGui::HigFlags QgsGui::higFlags()
139 {
140  QgsSettings settings;
141  if ( settings.value( QStringLiteral( "locale/userLocale" ), QString() ).toString().startsWith( QLatin1String( "en" ) ) )
142  {
144  }
145  else
146  {
147  return nullptr;
148  }
149 }
150 
152 {
153  delete mProcessingGuiRegistry;
154  delete mDataItemGuiProviderRegistry;
155  delete mProcessingRecentAlgorithmLog;
156  delete mLayoutItemGuiRegistry;
157  delete mLayerTreeEmbeddedWidgetRegistry;
158  delete mEditorWidgetRegistry;
159  delete mMapLayerActionRegistry;
160  delete mSourceSelectProviderRegistry;
161  delete mShortcutsManager;
162  delete mNative;
163  delete mWidgetStateHelper;
164  delete mProjectStorageGuiRegistry;
165  delete mProviderGuiRegistry;
166 }
167 
169 {
170 #ifdef Q_OS_MAC
171  QgsMacNative *macNative = new QgsMacNative();
172  macNative->setIconPath( QgsApplication::iconsPath() + QStringLiteral( "qgis-icon-macos.png" ) );
173  mNative = macNative;
174 #elif defined (Q_OS_WIN)
175 #ifndef __MINGW32__
176  mNative = new QgsWinNative();
177 #else
178  mNative = new QgsNative();
179 #endif
180 #elif defined(Q_OS_LINUX)
181  mNative = new QgsLinuxNative();
182 #else
183  mNative = new QgsNative();
184 #endif
185 
186  // provider gui registry initialize QgsProviderRegistry too
187  mProviderGuiRegistry = new QgsProviderGuiRegistry( QgsApplication::pluginPath() );
188  mProjectStorageGuiRegistry = new QgsProjectStorageGuiRegistry();
189  mDataItemGuiProviderRegistry = new QgsDataItemGuiProviderRegistry();
190  mSourceSelectProviderRegistry = new QgsSourceSelectProviderRegistry();
191 
192  mProjectStorageGuiRegistry->initializeFromProviderGuiRegistry( mProviderGuiRegistry );
193  mDataItemGuiProviderRegistry->initializeFromProviderGuiRegistry( mProviderGuiRegistry );
194  mSourceSelectProviderRegistry->initializeFromProviderGuiRegistry( mProviderGuiRegistry );
195 
196  mEditorWidgetRegistry = new QgsEditorWidgetRegistry();
197  mShortcutsManager = new QgsShortcutsManager();
198  mLayerTreeEmbeddedWidgetRegistry = new QgsLayerTreeEmbeddedWidgetRegistry();
199  mMapLayerActionRegistry = new QgsMapLayerActionRegistry();
200  mLayoutItemGuiRegistry = new QgsLayoutItemGuiRegistry();
201  mWidgetStateHelper = new QgsWidgetStateHelper();
202  mProcessingRecentAlgorithmLog = new QgsProcessingRecentAlgorithmLog();
203  mProcessingGuiRegistry = new QgsProcessingGuiRegistry();
204 
205 
206 }
static QgsProviderGuiRegistry * providerGuiRegistry()
Returns the registry of GUI-related components of data providers.
Definition: qgsgui.cpp:114
static QgsProcessingGuiRegistry * processingGuiRegistry()
Returns the global processing gui registry, used for registering the GUI behavior of processing algor...
Definition: qgsgui.cpp:94
static QgsWindowManagerInterface * windowManager()
Returns the global window manager, if set.
Definition: qgsgui.cpp:128
A registry / canonical manager of GUI parts of project storage backends.
This class is a composition of two QSettings instances:
Definition: qgssettings.h:58
Dialog titles should be title case.
Definition: qgsgui.h:169
static QgsNative * nativePlatformInterface()
Returns the global native interface, which offers abstraction to the host OS's underlying public inte...
Definition: qgsgui.cpp:59
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
This class manages all known edit widget factories.
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QgsGui is a singleton class containing various registry and other global members related to GUI class...
Definition: qgsgui.h:47
static QgsDataItemGuiProviderRegistry * dataItemGuiProviderRegistry()
Returns the global data item GUI provider registry, used for tracking providers which affect the brow...
Definition: qgsgui.cpp:104
static QgsSourceSelectProviderRegistry * sourceSelectProviderRegistry()
Returns the global source select provider registry, used for managing all known source select widget ...
Definition: qgsgui.cpp:69
Shortcuts manager is a class that contains a list of QActions and QShortcuts that have been registere...
The QgsProcessingGuiRegistry is a home for widgets for processing configuration widgets.
void initializeFromProviderGuiRegistry(QgsProviderGuiRegistry *providerGuiRegistry)
Initializes the registry.
~QgsGui()
Definition: qgsgui.cpp:151
Registry of available layout item GUI behavior.
static QgsGui * instance()
Returns a pointer to the singleton instance.
Definition: qgsgui.cpp:53
static QgsProjectStorageGuiRegistry * projectStorageGuiRegistry()
Returns the global GUI-related project storage registry.
Definition: qgsgui.cpp:109
void initializeFromProviderGuiRegistry(QgsProviderGuiRegistry *providerGuiRegistry)
Initializes the registry.
QgsGui(const QgsGui &other)=delete
QgsGui cannot be copied.
static QgsShortcutsManager * shortcutsManager()
Returns the global shortcuts manager, used for managing a QAction and QShortcut sequences.
Definition: qgsgui.cpp:74
void initializeFromProviderGuiRegistry(QgsProviderGuiRegistry *providerGuiRegistry)
Initializes the registry.
static QgsLayoutItemGuiRegistry * layoutItemGuiRegistry()
Returns the global layout item GUI registry, used for registering the GUI behavior of layout items...
Definition: qgsgui.cpp:89
static QString pluginPath()
Returns the path to the application plugin directory.
static QgsLayerTreeEmbeddedWidgetRegistry * layerTreeEmbeddedWidgetRegistry()
Returns the global layer tree embedded widget registry, used for registering widgets that may be embe...
Definition: qgsgui.cpp:79
static QgsEditorWidgetRegistry * editorWidgetRegistry()
Returns the global editor widget registry, used for managing all known edit widget factories...
Definition: qgsgui.cpp:64
static QgsProcessingRecentAlgorithmLog * processingRecentAlgorithmLog()
Returns the global processing recent algorithm log, used for tracking recently used processing algori...
Definition: qgsgui.cpp:99
Registry of widgets that may be embedded into layer tree view.
This class tracks map layer actions.
This class keeps a list of source select providers that may add items to the QgsDataSourceManagerDial...
This class keeps a list of data item GUI providers that may affect how QgsDataItems behave within the...
Menu action texts should be title case.
Definition: qgsgui.h:168
static void setWindowManager(QgsWindowManagerInterface *manager)
Sets the global window manager.
Definition: qgsgui.cpp:133
QgsWidgetStateHelper is a helper class to save and restore the geometry of QWidgets in the applicatio...
static QgsGui::HigFlags higFlags()
Returns the platform's HIG flags.
Definition: qgsgui.cpp:138
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
Definition: qgsgui.cpp:119
static QString iconsPath()
Returns the path to the icons image directory.
void registerWidget(QWidget *widget, const QString &key=QString())
Register a widget to have it geometry state automatically saved and restored.
static QgsMapLayerActionRegistry * mapLayerActionRegistry()
Returns the global map layer action registry, used for registering map layer actions.
Definition: qgsgui.cpp:84
A registry / canonical manager of GUI parts of data providers.