QGIS API Documentation 4.1.0-Master (376402f9aeb)
Loading...
Searching...
No Matches
qgsapplication.h
Go to the documentation of this file.
1
2/***************************************************************************
3 qgsapplication.h - Accessors for application-wide data
4 --------------------------------------
5 Date : 02-Jan-2006
6 Copyright : (C) 2006 by Tom Elwertowski
7 Email : telwertowski at users dot sourceforge dot net
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16#ifndef QGSAPPLICATION_H
17#define QGSAPPLICATION_H
18
19#include "qgsconfig.h"
20
21#include <memory>
22
23#include "qgis_core.h"
24#include "qgis_sip.h"
27
28#include <QApplication>
29#include <QColor>
30#include <QEvent>
31#include <QStringList>
32
40class QgsTaskManager;
49class QgsSvgCache;
50class QgsImageCache;
51class QgsSourceCache;
59class QgsMessageLog;
61class QgsAnnotationRegistry;
63class QgsUserProfile;
66class QgsAuthManager;
69class QTranslator;
71class QgsPlotRegistry;
73class QgsStyleModel;
84class QgsFontManager;
90
91// clang-format off
106class CORE_EXPORT QgsApplication : public QApplication
107{
108// clang-format on
109#ifdef SIP_RUN
110 // clang-format off
111 % TypeCode
112 // Convert a Python argv list to a conventional C argc count and argv array.
113 static char **qtgui_ArgvToC( PyObject *argvlist, int &argc )
114 {
115 char **argv;
116
117 argc = PyList_GET_SIZE( argvlist );
118
119 // Allocate space for two copies of the argument pointers, plus the
120 // terminating NULL.
121 if ( ( argv = ( char ** )sipMalloc( 2 * ( argc + 1 ) * sizeof( char * ) ) ) == NULL )
122 return NULL;
123
124 // Convert the list.
125 for ( int a = 0; a < argc; ++a )
126 {
127 char *arg;
128 // Get the argument and allocate memory for it.
129 if ( ( arg = PyBytes_AsString( PyList_GET_ITEM( argvlist, a ) ) ) == NULL ||
130 ( argv[a] = ( char * )sipMalloc( strlen( arg ) + 1 ) ) == NULL )
131 return NULL;
132 // Copy the argument and save a pointer to it.
133 strcpy( argv[a], arg );
134 argv[a + argc + 1] = argv[a];
135 }
136
137 argv[argc + argc + 1] = argv[argc] = NULL;
138
139 return argv;
140 }
141
142 // Remove arguments from the Python argv list that have been removed from the
143 // C argv array.
144 static void qtgui_UpdatePyArgv( PyObject *argvlist, int argc, char **argv )
145 {
146 for ( int a = 0, na = 0; a < argc; ++a )
147 {
148 // See if it was removed.
149 if ( argv[na] == argv[a + argc + 1] )
150 ++na;
151 else
152 PyList_SetSlice( argvlist, na, na + 1, NULL );
153 }
154 }
155 % End
156// clang-format on
157#endif
158
159 // clang-format off
160 Q_OBJECT
161
162 public:
163
177 // clang-format on
178 static const char *QGIS_ORGANIZATION_NAME;
179 static const char *QGIS_ORGANIZATION_DOMAIN;
180 static const char *QGIS_APPLICATION_NAME;
181#ifndef SIP_RUN
182
184
186
189
202 QgsApplication(int &argc, char **argv, bool GUIenabled,
203 const QString &profileFolder = QString(),
204 const QString &platformName = "external");
205#else
206 // clang-format off
207
216 QgsApplication( SIP_PYLIST argv, bool GUIenabled, QString profileFolder = QString(), QString platformName = "external" ) / PostHook = __pyQtQAppHook__ / [( int &argc, char **argv, bool GUIenabled, const QString &profileFolder = QString(), const QString &platformName = "desktop" )];
217 % MethodCode
218 // The Python interface is a list of argument strings that is modified.
219
220 int argc;
221 char **argv;
222
223 // Convert the list.
224 if ( ( argv = qtgui_ArgvToC( a0, argc ) ) == NULL )
225 sipIsErr = 1;
226 else
227 {
228 // Create it now the arguments are right.
229 static int nargc = argc;
230
231 sipCpp = new sipQgsApplication( nargc, argv, a1, *a2, *a3 );
232
233 // Now modify the original list.
234 qtgui_UpdatePyArgv( a0, argc, argv );
235 }
236 % End
237// clang-format on
238#endif
239
240 ~QgsApplication() override;
241
246 static QgsApplication *instance();
247
255 static void init(QString profileFolder = QString()) SIP_SKIP;
256
258 bool event(QEvent *event) override;
259
261 bool notify(QObject *receiver, QEvent *event) override;
262
264 static void setFileOpenEventReceiver(QObject *receiver);
265
276 static void setThemeName(const QString &themeName);
277
282 static QString resolvePkgPath();
283
291 static QString themeName();
292
300 static void setUITheme(const QString &themeName);
301
309 static QHash<QString, QString> uiThemes();
310
312 static QString authorsFilePath();
313
319 static QString contributorsFilePath();
320
322 static QString sponsorsFilePath();
323
325 static QString donorsFilePath();
326
328 static QString serverResourcesPath();
329
333 static QString translatorsFilePath();
334
338 static QString licenceFilePath();
339
341 static QString i18nPath();
342
346 static QString metadataPath();
347
349 static QString qgisMasterDatabaseFilePath();
350
352 static QString qgisSettingsDirPath();
353
355 static QString qgisUserDatabaseFilePath();
356
361 Q_DECL_DEPRECATED static QString qgisAuthDatabaseFilePath() SIP_DEPRECATED;
362
372 static QString qgisAuthDatabaseUri();
373
375 static QString splashPath();
376
378 static QString iconsPath();
379
381 static QString srsDatabaseFilePath();
382
388 static void setSvgPaths(const QStringList &svgPaths);
389
391 static QStringList svgPaths();
392
396 static QStringList layoutTemplatePaths();
397
399 static QMap<QString, QString> systemEnvVars();
400
402 static QString prefixPath();
403
405 static QString pluginPath();
406
408 static QString pkgDataPath();
409
411 static QString activeThemePath();
412
414 static QString defaultThemePath();
415
420 static QString iconPath(const QString &iconFile);
421
429 static QIcon getThemeIcon(const QString &name,
430 const QColor &fillColor = QColor(),
431 const QColor &strokeColor = QColor());
432
433 // clang-format off
448 // clang-format on
449
456 static QCursor getThemeCursor(Cursor cursor);
457
466 static QPixmap getThemePixmap(const QString &name,
467 const QColor &foreColor = QColor(),
468 const QColor &backColor = QColor(),
469 int size = 16);
470
472 static QString userStylePath();
473
480 static QRegularExpression shortNameRegularExpression();
481
486 static QString userLoginName();
487
492 static QString userFullName();
493
498 static QString osName();
499
508 static int systemMemorySizeMb();
509
515 static QString platform();
516
528 static QString applicationFullName();
529
533 static QString locale();
534
541 static void setLocale(const QLocale &locale);
542
544 static QString userThemesFolder();
545
547 static QString defaultStylePath();
548
553 static QString defaultThemesFolder();
554
559 static QString libraryPath();
560
562 static QString libexecPath();
563
570 static QString qmlImportPath();
571
573 static void setPrefixPath(const QString &prefixPath,
574 bool useDefaultPaths = false);
575
577 static void setPluginPath(const QString &pluginPath);
578
580 static void setPkgDataPath(const QString &pkgDataPath);
581
583 static void setDefaultSvgPaths(const QStringList &pathList);
584
586 static void setAuthDatabaseDirPath(const QString &authDbDirPath);
587
589 static void initQgis();
590
592 static bool createDatabase(QString *errorMessage = nullptr);
593
595 static bool createThemeFolder();
596
598 static void exitQgis();
599
601 static QString appIconPath();
602
603 // clang-format off
606 {
607 XDR = 0, // network, or big-endian, byte order
608 NDR = 1 // little-endian byte order
609 };
610 // clang-format on
611
613 static endian_t endian();
614
633 static QString
634 reportStyleSheet(QgsApplication::StyleSheetType styleSheetType =
636
641 static QString showSettings();
642
650 static void registerOgrDrivers();
651
653 static QString absolutePathToRelativePath(const QString &apath,
654 const QString &targetPath);
656 static QString relativePathToAbsolutePath(const QString &rpath,
657 const QString &targetPath);
658
660 static bool isRunningFromBuildDir() { return ABISYM(mRunningFromBuildDir); }
661#if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
662 static QString cfgIntDir() SIP_SKIP;
663#endif
664
669 static QString buildSourcePath();
670
675 static QString buildOutputPath();
676
682 static void skipGdalDriver(const QString &driver);
683
689 static void restoreGdalDriver(const QString &driver);
690
695 static QStringList skippedGdalDrivers();
696
703 static void applyGdalSkippedDrivers();
704
710 static void registerGdalDriversFromSettings();
711
718 static QStringList deferredSkippedGdalDrivers();
719
726 static void
727 setSkippedGdalDrivers(const QStringList &skippedGdalDrivers,
728 const QStringList &deferredSkippedGdalDrivers);
729
733 static int maxThreads();
734
739 static void setMaxThreads(int maxThreads);
740
745 static QgsTaskManager *taskManager();
746
753 Q_DECL_DEPRECATED static QgsSettingsRegistryCore *
754 settingsRegistryCore() SIP_KEEPREFERENCE SIP_DEPRECATED;
755
760 static QgsColorSchemeRegistry *colorSchemeRegistry() SIP_KEEPREFERENCE;
761
766 static QgsPaintEffectRegistry *paintEffectRegistry() SIP_KEEPREFERENCE;
767
772 static QgsRendererRegistry *rendererRegistry() SIP_KEEPREFERENCE;
773
779 static QgsRasterRendererRegistry *rasterRendererRegistry() SIP_SKIP;
780
787 pointCloudRendererRegistry() SIP_KEEPREFERENCE;
788
795 tiledSceneRendererRegistry() SIP_KEEPREFERENCE;
796
802 dataItemProviderRegistry() SIP_KEEPREFERENCE;
803
811 coordinateReferenceSystemRegistry() SIP_KEEPREFERENCE;
812
819 static QgsSvgCache *svgCache();
820
828 static QgsImageCache *imageCache();
829
836 static QgsSourceCache *sourceCache();
837
844 networkContentFetcherRegistry() SIP_KEEPREFERENCE;
845
851 static QgsValidityCheckRegistry *validityCheckRegistry() SIP_KEEPREFERENCE;
852
857 static QgsSymbolLayerRegistry *symbolLayerRegistry() SIP_KEEPREFERENCE;
858
864 static QgsCalloutRegistry *calloutRegistry() SIP_KEEPREFERENCE;
865
869 static QgsLayoutItemRegistry *layoutItemRegistry() SIP_KEEPREFERENCE;
870
876 static QgsAnnotationItemRegistry *annotationItemRegistry() SIP_KEEPREFERENCE;
877
882 static QgsGpsConnectionRegistry *gpsConnectionRegistry() SIP_KEEPREFERENCE;
883
889 static QgsBabelFormatRegistry *gpsBabelFormatRegistry() SIP_KEEPREFERENCE;
890
895 static QgsPluginLayerRegistry *pluginLayerRegistry() SIP_KEEPREFERENCE;
896
903 classificationMethodRegistry() SIP_KEEPREFERENCE;
904
910 static QgsBookmarkManager *bookmarkManager();
911
918 static QgsTileDownloadManager *tileDownloadManager() SIP_SKIP;
919
924 static QgsRecentStyleHandler *recentStyleHandler() SIP_KEEPREFERENCE;
925
931 static QgsDatabaseQueryLog *databaseQueryLog() SIP_KEEPREFERENCE;
932
942 static QgsStyleModel *defaultStyleModel();
943
950 static QgsFontManager *fontManager() SIP_KEEPREFERENCE;
951
956 static QgsSensorRegistry *sensorRegistry() SIP_KEEPREFERENCE;
957
962 static QgsPlotRegistry *plotRegistry() SIP_KEEPREFERENCE;
963
967 static QgsMessageLog *messageLog();
968
974 static QgsAuthManager *authManager();
975
981 authConfigurationStorageRegistry();
982
987 static QgsProcessingRegistry *processingRegistry();
988
993 static QgsPageSizeRegistry *pageSizeRegistry() SIP_KEEPREFERENCE;
994
1000 static QgsAnnotationRegistry *annotationRegistry() SIP_SKIP;
1001
1008 applicationThemeRegistry() SIP_KEEPREFERENCE;
1009
1014 static QgsActionScopeRegistry *actionScopeRegistry() SIP_KEEPREFERENCE;
1015
1021 static QgsConnectionRegistry *connectionRegistry();
1022
1026 static QgsRuntimeProfiler *profiler();
1027
1033 static QgsNumericFormatRegistry *numericFormatRegistry() SIP_KEEPREFERENCE;
1034
1038 static QgsFieldFormatterRegistry *fieldFormatterRegistry() SIP_KEEPREFERENCE;
1039
1043 static Qgs3DRendererRegistry *renderer3DRegistry() SIP_KEEPREFERENCE;
1044
1049 static Qgs3DSymbolRegistry *symbol3DRegistry() SIP_KEEPREFERENCE;
1050
1059 static QgsMaterialRegistry *materialRegistry() SIP_KEEPREFERENCE;
1060
1067 scaleBarRendererRegistry() SIP_KEEPREFERENCE;
1068
1075 labelingEngineRuleRegistry() SIP_KEEPREFERENCE;
1076
1083 symbolConverterRegistry() SIP_KEEPREFERENCE;
1084
1089 static QgsProjectStorageRegistry *projectStorageRegistry() SIP_KEEPREFERENCE;
1090
1096 layerMetadataProviderRegistry() SIP_KEEPREFERENCE;
1097
1103 externalStorageRegistry() SIP_KEEPREFERENCE;
1104
1109 static QgsProfileSourceRegistry *profileSourceRegistry() SIP_KEEPREFERENCE;
1110
1119 localizedDataPathRegistry() SIP_KEEPREFERENCE;
1120
1132 static QString nullRepresentation();
1133
1145 static void setNullRepresentation(const QString &nullRepresentation);
1146
1154 static QVariantMap customVariables();
1155
1162 static void setCustomVariables(const QVariantMap &customVariables);
1163
1168 static void setCustomVariable(const QString &name, const QVariant &value);
1169
1176 static QStringList temporarilyTrustedProjectsFolders();
1177
1184 static void setTemporarilyTrustedProjectsFolders(
1185 const QStringList &trustedProjectsFolders);
1186
1193 static QStringList temporarilyUntrustedProjectsFolders();
1194
1201 static void setTemporarilyUntrustedProjectsFolders(
1202 const QStringList &untrustedProjectsFolders);
1203
1214 static int scaleIconSize(int standardSize,
1215 bool applyDevicePixelRatio = false);
1216
1225 int maxConcurrentConnectionsPerPool() const;
1226
1232 static void setTranslation(const QString &translation);
1233
1239 QString translation() const;
1240
1247 void collectTranslatableObjects(QgsTranslationContext *translationContext);
1248
1250
1251#ifndef SIP_RUN
1262
1267 static const QgsSettingsEntryInteger
1269#endif
1270
1271#ifdef SIP_RUN
1272 SIP_IF_FEATURE(ANDROID)
1273 // dummy method to workaround sip generation issue
1274 bool x11EventFilter(XEvent *event);
1275 SIP_END
1276#endif
1277
1278signals:
1280 void preNotify(QObject *receiver, QEvent *event, bool *done) SIP_SKIP;
1281
1286
1294
1304
1311
1318
1319private:
1320 static void copyPath(const QString &src, const QString &dst);
1321 static QObject *ABISYM(mFileOpenEventReceiver);
1322
1323 static bool ABISYM(mInitialized);
1324
1326 static bool ABISYM(mRunningFromBuildDir);
1327
1330 static int ABISYM(sMaxThreads);
1331
1332 QMap<QString, QIcon> mIconCache;
1333 QMap<Cursor, QCursor> mCursorCache;
1334
1335 std::unique_ptr<QTranslator> mQgisTranslator;
1336 std::unique_ptr<QTranslator> mQtTranslator;
1337 std::unique_ptr<QTranslator> mQtBaseTranslator;
1338
1339 std::unique_ptr<QgsDataItemProviderRegistry> mDataItemProviderRegistry;
1340 QgsAuthManager *mAuthManager = nullptr;
1341
1342 struct ApplicationMembers;
1343
1344 // Applications members which belong to an instance of QgsApplication
1345 std::unique_ptr<ApplicationMembers> mApplicationMembers;
1346 // ... but in case QgsApplication is never instantiated (eg with custom
1347 // designer widgets), we fall back to static members
1348 static ApplicationMembers *sApplicationMembers;
1349
1350 static QgsAuthManager *sAuthManager;
1351
1352 static ApplicationMembers *members();
1353
1354 static void invalidateCaches();
1355
1360 void installTranslators() SIP_SKIP;
1361
1362 QStringList mTemporarilyTrustedProjectFolders;
1363 QStringList mTemporarilyUntrustedProjectFolders;
1364
1366};
1367
1368// clazy:excludeall=qstring-allocations
1369
1370#endif
A registry for available 3D renderers.
Registry of available 3D symbol classes.
The action scope registry is an application wide registry that contains a list of available action sc...
Registry of available annotation item types.
Registry of user interface themes.
Extends QApplication to provide access to QGIS specific resources such as theme paths,...
static const QgsSettingsEntryString * settingsApplicationFullName
endian_t
Constants for endian-ness.
static const QgsSettingsEntryStringList * settingsSearchPathsForSVG
Settings entry search path for SVG.
void themeChanged()
Emitted when the application theme has changed.
friend class TestQgsApplication
static const QgsSettingsEntryBool * settingsLocaleOverrideFlag
Settings entry locale override flag.
static const QgsSettingsEntryString * settingsNullRepresentation
void customVariablesChanged()
Emitted whenever a custom global variable changes.
static QgsSettingsTreeNamedListNode * sTreeCustomVariables
StyleSheetType
The StyleSheetType enum represents the stylesheet type that a widget supports.
@ Qt
StyleSheet for Qt GUI widgets (based on QLabel or QTextBrowser), supports basic CSS and Qt extensions...
@ WebBrowser
StyleSheet for embedded browsers (QtWebKit), supports full standard CSS.
static const QgsSettingsEntryString * settingsLocaleGlobalLocale
Settings entry locale global locale.
bool event(QEvent *event) override
Watch for QFileOpenEvent.
static const QgsSettingsEntryString * settingsLocaleUserLocale
Settings entry locale user locale.
static const char * QGIS_APPLICATION_NAME
static const char * QGIS_ORGANIZATION_DOMAIN
static const QgsSettingsEntryStringList * settingsSkippedGdalDrivers
void preNotify(QObject *receiver, QEvent *event, bool *done)
void localeChanged()
Emitted when project locale has been changed.
static const char * QGIS_ORGANIZATION_NAME
QgsApplication(int &argc, char **argv, bool GUIenabled, const QString &profileFolder=QString(), const QString &platformName="external")
Constructor for QgsApplication.
Cursor
The Cursor enum defines constants for QGIS custom cursors.
@ ZoomOut
Zoom out.
@ CrossHair
Precisely identify a point on the canvas.
@ Identify
Identify: obtain information about the object.
@ Select
Select a rectangle.
@ CapturePoint
Select and capture a point or a feature.
@ Sampler
Color/Value picker.
static const QgsSettingsEntryInteger * settingsConnectionPoolMaximumConcurrentConnections
Settings entry to configure the maximum number of concurrent connections within connection pools.
void requestForTranslatableObjects(QgsTranslationContext *translationContext)
Emitted when project strings which require translation are being collected for inclusion in a ....
void nullRepresentationChanged()
Emitted when the string representing the NULL value is changed.
static const QgsSettingsEntryBool * settingsLocaleShowGroupSeparator
Settings entry locale show group separator.
static bool isRunningFromBuildDir()
Indicates whether running from build directory (not installed).
static const QgsSettingsEntryVariant * settingsCustomVariable
Registry for authentication configuration storages.
Singleton which offers an interface to manage the authentication configuration database and to utiliz...
A registry for QgsAbstractBabelFormat GPSBabel formats.
Manages storage of a set of bookmarks.
Registry of available callout classes.
Manages all known classification methods.
Registry of color schemes.
A registry for saved data provider connections, allowing retrieval of saved connections by name and p...
A registry for known coordinate reference system (CRS) definitions, including any user-defined CRSes.
A registry for data item providers that may add items to the browser tree.
Handles logging of database queries.
Registry of external storage backends used by QgsExternalResourceWidget.
A registry which manages classes of QgsFieldFormatter.
Manages available fonts and font installation for a QGIS instance.
Registers existing GPS connections such that the information is available to all classes and plugins.
A cache for images derived from raster files.
A registry for labeling engine rules.
Registry of layer metadata provider backends.
Registry of available layout item types.
A registry class to hold localized data paths which can be used for basemaps, logos,...
Registry of available 3d material settings classes.
Interface for logging messages from QGIS in GUI independent way.
Registry for temporary fetched files.
A registry which manages classes of QgsNumericFormat.
A registry for known page sizes.
Registry of available paint effects.
Registry of available plot types.
A registry of plugin layers types.
Registry of 2D renderers for point clouds.
Registry for various processing components, including providers, algorithms and various parameters an...
Registry of profile sources used by QgsProfilePlotRenderer.
Registry of storage backends that QgsProject may use.
Registry for raster renderers.
Handles and tracks style items recently used in the QGIS GUI.
Registry of renderers.
Provides a method of recording run time profiles of operations, allowing easy recording of their over...
A registry which manages registered scalebar renderers.
Registry of available sensor types.
A boolean settings entry.
An integer settings entry.
A string list settings entry.
A string settings entry.
A variant settings entry.
Used for settings introspection and collects all QgsSettingsEntry instances of core.
A named list tree node for the settings tree to help organizing and introspecting the tree.
A cache for source strings that returns a local file path containing the source content.
A QAbstractItemModel subclass for showing symbol and color ramp entities contained within a QgsStyle ...
A cache for images / pictures derived from SVG files.
A registry of known symbol converters.
Registry of available symbol layer classes.
Task manager for managing a set of long-running QgsTask tasks.
Tile download manager handles downloads of map tiles for the purpose of map rendering.
Registry of 2D renderers for tiled scenes.
Used for the collecting of strings from projects for translation and creation of ts files.
User profile contains information about the user profile folders on the machine.
A registry that keeps a list of QgsAbstractValidityCheck checks which can be used when performing val...
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_KEEPREFERENCE
Definition qgis_sip.h:93
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_IF_FEATURE(feature)
Definition qgis_sip.h:188
#define SIP_END
Definition qgis_sip.h:215
QObject * ABISYM(QgsApplication::mFileOpenEventReceiver)