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