QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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 
49 {
50  static QgsGui *sInstance( new QgsGui() );
51  return sInstance;
52 }
53 
55 {
56  return instance()->mNative;
57 }
58 
60 {
61  return instance()->mEditorWidgetRegistry;
62 }
63 
65 {
66  return instance()->mSourceSelectProviderRegistry;
67 }
68 
70 {
71  return instance()->mShortcutsManager;
72 }
73 
75 {
76  return instance()->mLayerTreeEmbeddedWidgetRegistry;
77 }
78 
80 {
81  return instance()->mMapLayerActionRegistry;
82 }
83 
85 {
86  return instance()->mLayoutItemGuiRegistry;
87 }
88 
90 {
91  return instance()->mProcessingGuiRegistry;
92 }
93 
94 QgsProcessingRecentAlgorithmLog *QgsGui::processingRecentAlgorithmLog()
95 {
96  return instance()->mProcessingRecentAlgorithmLog;
97 }
98 
100 {
101  return instance()->mDataItemGuiProviderRegistry;
102 }
103 
104 void QgsGui::enableAutoGeometryRestore( QWidget *widget, const QString &key )
105 {
106  if ( widget->objectName().isEmpty() )
107  {
108  QgsDebugMsg( QStringLiteral( "WARNING: No object name set. Best for it to be set objectName when using QgsGui::enableAutoGeometryRestore" ) );
109  }
110  instance()->mWidgetStateHelper->registerWidget( widget, key );
111 }
112 
113 QgsWindowManagerInterface *QgsGui::windowManager()
114 {
115  return instance()->mWindowManager.get();
116 }
117 
118 void QgsGui::setWindowManager( QgsWindowManagerInterface *manager )
119 {
120  instance()->mWindowManager.reset( manager );
121 }
122 
123 QgsGui::HigFlags QgsGui::higFlags()
124 {
125  QgsSettings settings;
126  if ( settings.value( QStringLiteral( "locale/userLocale" ), QString() ).toString().startsWith( QLatin1String( "en" ) ) )
127  {
129  }
130  else
131  {
132  return nullptr;
133  }
134 }
135 
137 {
138  delete mProcessingGuiRegistry;
139  delete mDataItemGuiProviderRegistry;
140  delete mProcessingRecentAlgorithmLog;
141  delete mLayoutItemGuiRegistry;
142  delete mLayerTreeEmbeddedWidgetRegistry;
143  delete mEditorWidgetRegistry;
144  delete mMapLayerActionRegistry;
145  delete mSourceSelectProviderRegistry;
146  delete mShortcutsManager;
147  delete mNative;
148  delete mWidgetStateHelper;
149 }
150 
152 {
153 #ifdef Q_OS_MAC
154  QgsMacNative *macNative = new QgsMacNative();
155  macNative->setIconPath( QgsApplication::iconsPath() + QStringLiteral( "qgis-icon-macos.png" ) );
156  mNative = macNative;
157 #elif defined (Q_OS_WIN)
158 #ifndef __MINGW32__
159  mNative = new QgsWinNative();
160 #else
161  mNative = new QgsNative();
162 #endif
163 #elif defined(Q_OS_LINUX)
164  mNative = new QgsLinuxNative();
165 #else
166  mNative = new QgsNative();
167 #endif
168 
169  mEditorWidgetRegistry = new QgsEditorWidgetRegistry();
170  mShortcutsManager = new QgsShortcutsManager();
171  mLayerTreeEmbeddedWidgetRegistry = new QgsLayerTreeEmbeddedWidgetRegistry();
172  mMapLayerActionRegistry = new QgsMapLayerActionRegistry();
173  mSourceSelectProviderRegistry = new QgsSourceSelectProviderRegistry();
174  mLayoutItemGuiRegistry = new QgsLayoutItemGuiRegistry();
175  mWidgetStateHelper = new QgsWidgetStateHelper();
176  mProcessingRecentAlgorithmLog = new QgsProcessingRecentAlgorithmLog();
177  mProcessingGuiRegistry = new QgsProcessingGuiRegistry();
178  mDataItemGuiProviderRegistry = new QgsDataItemGuiProviderRegistry();
179 }
static QgsProcessingGuiRegistry * processingGuiRegistry()
Returns the global processing gui registry, used for registering the GUI behavior of processing algor...
Definition: qgsgui.cpp:89
static QgsWindowManagerInterface * windowManager()
Returns the global window manager, if set.
Definition: qgsgui.cpp:113
This class is a composition of two QSettings instances:
Definition: qgssettings.h:58
Dialog titles should be title case.
Definition: qgsgui.h:155
static QgsNative * nativePlatformInterface()
Returns the global native interface, which offers abstraction to the host OS's underlying public inte...
Definition: qgsgui.cpp:54
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:45
static QgsDataItemGuiProviderRegistry * dataItemGuiProviderRegistry()
Returns the global data item GUI provider registry, used for tracking providers which affect the brow...
Definition: qgsgui.cpp:99
static QgsSourceSelectProviderRegistry * sourceSelectProviderRegistry()
Returns the global source select provider registry, used for managing all known source select widget ...
Definition: qgsgui.cpp:64
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.
~QgsGui()
Definition: qgsgui.cpp:136
Registry of available layout item GUI behavior.
static QgsGui * instance()
Returns a pointer to the singleton instance.
Definition: qgsgui.cpp:48
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:69
static QgsLayoutItemGuiRegistry * layoutItemGuiRegistry()
Returns the global layout item GUI registry, used for registering the GUI behavior of layout items...
Definition: qgsgui.cpp:84
static QgsLayerTreeEmbeddedWidgetRegistry * layerTreeEmbeddedWidgetRegistry()
Returns the global layer tree embedded widget registry, used for registering widgets that may be embe...
Definition: qgsgui.cpp:74
static QgsEditorWidgetRegistry * editorWidgetRegistry()
Returns the global editor widget registry, used for managing all known edit widget factories...
Definition: qgsgui.cpp:59
static QgsProcessingRecentAlgorithmLog * processingRecentAlgorithmLog()
Returns the global processing recent algorithm log, used for tracking recently used processing algori...
Definition: qgsgui.cpp:94
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:154
static void setWindowManager(QgsWindowManagerInterface *manager)
Sets the global window manager.
Definition: qgsgui.cpp:118
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:123
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:104
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:79