QGIS API Documentation 4.1.0-Master (60fea48833c)
Loading...
Searching...
No Matches
qgsapplication.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsapplication.h - Accessors for application-wide data
3 --------------------------------------
4 Date : 02-Jan-2006
5 Copyright : (C) 2006 by Tom Elwertowski
6 Email : telwertowski at users dot sourceforge dot net
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15#ifndef QGSAPPLICATION_H
16#define QGSAPPLICATION_H
17
18#include "qgsconfig.h"
19
20#include <memory>
21
22#include "qgis_core.h"
23#include "qgis_sip.h"
26
27#include <QApplication>
28#include <QColor>
29#include <QEvent>
30#include <QStringList>
31
38class QgsTaskManager;
47class QgsSvgCache;
48class QgsImageCache;
49class QgsSourceCache;
57class QgsMessageLog;
59class QgsAnnotationRegistry;
61class QgsUserProfile;
64class QgsAuthManager;
67class QTranslator;
69class QgsPlotRegistry;
71class QgsStyleModel;
82class QgsFontManager;
86
87// clang-format off
102class CORE_EXPORT QgsApplication : public QApplication
103{
104// clang-format on
105#ifdef SIP_RUN
106 // clang-format off
107 % TypeCode
108 // Convert a Python argv list to a conventional C argc count and argv array.
109 static char **qtgui_ArgvToC( PyObject *argvlist, int &argc )
110 {
111 char **argv;
112
113 argc = PyList_GET_SIZE( argvlist );
114
115 // Allocate space for two copies of the argument pointers, plus the
116 // terminating NULL.
117 if ( ( argv = ( char ** )sipMalloc( 2 * ( argc + 1 ) * sizeof( char * ) ) ) == NULL )
118 return NULL;
119
120 // Convert the list.
121 for ( int a = 0; a < argc; ++a )
122 {
123 char *arg;
124 // Get the argument and allocate memory for it.
125 if ( ( arg = PyBytes_AsString( PyList_GET_ITEM( argvlist, a ) ) ) == NULL ||
126 ( argv[a] = ( char * )sipMalloc( strlen( arg ) + 1 ) ) == NULL )
127 return NULL;
128 // Copy the argument and save a pointer to it.
129 strcpy( argv[a], arg );
130 argv[a + argc + 1] = argv[a];
131 }
132
133 argv[argc + argc + 1] = argv[argc] = NULL;
134
135 return argv;
136 }
137
138 // Remove arguments from the Python argv list that have been removed from the
139 // C argv array.
140 static void qtgui_UpdatePyArgv( PyObject *argvlist, int argc, char **argv )
141 {
142 for ( int a = 0, na = 0; a < argc; ++a )
143 {
144 // See if it was removed.
145 if ( argv[na] == argv[a + argc + 1] )
146 ++na;
147 else
148 PyList_SetSlice( argvlist, na, na + 1, NULL );
149 }
150 }
151 % End
152// clang-format on
153#endif
154
155 // clang-format off
156 Q_OBJECT
157
158 public:
159
173 // clang-format on
174 static const char *QGIS_ORGANIZATION_NAME;
175 static const char *QGIS_ORGANIZATION_DOMAIN;
176 static const char *QGIS_APPLICATION_NAME;
177#ifndef SIP_RUN
178
191 QgsApplication(int &argc, char **argv, bool GUIenabled,
192 const QString &profileFolder = QString(),
193 const QString &platformName = "external");
194#else
195 // clang-format off
196
205 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" )];
206 % MethodCode
207 // The Python interface is a list of argument strings that is modified.
208
209 int argc;
210 char **argv;
211
212 // Convert the list.
213 if ( ( argv = qtgui_ArgvToC( a0, argc ) ) == NULL )
214 sipIsErr = 1;
215 else
216 {
217 // Create it now the arguments are right.
218 static int nargc = argc;
219
220 sipCpp = new sipQgsApplication( nargc, argv, a1, *a2, *a3 );
221
222 // Now modify the original list.
223 qtgui_UpdatePyArgv( a0, argc, argv );
224 }
225 % End
226// clang-format on
227#endif
228
229 ~QgsApplication() override;
230
235 static QgsApplication *instance();
236
244 static void init(QString profileFolder = QString()) SIP_SKIP;
245
247 bool event(QEvent *event) override;
248
250 bool notify(QObject *receiver, QEvent *event) override;
251
253 static void setFileOpenEventReceiver(QObject *receiver);
254
265 static void setThemeName(const QString &themeName);
266
271 static QString resolvePkgPath();
272
280 static QString themeName();
281
289 static void setUITheme(const QString &themeName);
290
298 static QHash<QString, QString> uiThemes();
299
301 static QString authorsFilePath();
302
308 static QString contributorsFilePath();
309
311 static QString sponsorsFilePath();
312
314 static QString donorsFilePath();
315
317 static QString serverResourcesPath();
318
322 static QString translatorsFilePath();
323
327 static QString licenceFilePath();
328
330 static QString i18nPath();
331
335 static QString metadataPath();
336
338 static QString qgisMasterDatabaseFilePath();
339
341 static QString qgisSettingsDirPath();
342
344 static QString qgisUserDatabaseFilePath();
345
350 Q_DECL_DEPRECATED static QString qgisAuthDatabaseFilePath() SIP_DEPRECATED;
351
361 static QString qgisAuthDatabaseUri();
362
364 static QString splashPath();
365
367 static QString iconsPath();
368
370 static QString srsDatabaseFilePath();
371
377 static void setSvgPaths(const QStringList &svgPaths);
378
380 static QStringList svgPaths();
381
385 static QStringList layoutTemplatePaths();
386
388 static QMap<QString, QString> systemEnvVars();
389
391 static QString prefixPath();
392
394 static QString pluginPath();
395
397 static QString pkgDataPath();
398
400 static QString activeThemePath();
401
403 static QString defaultThemePath();
404
409 static QString iconPath(const QString &iconFile);
410
418 static QIcon getThemeIcon(const QString &name,
419 const QColor &fillColor = QColor(),
420 const QColor &strokeColor = QColor());
421
422 // clang-format off
437 // clang-format on
438
445 static QCursor getThemeCursor(Cursor cursor);
446
455 static QPixmap getThemePixmap(const QString &name,
456 const QColor &foreColor = QColor(),
457 const QColor &backColor = QColor(),
458 int size = 16);
459
461 static QString userStylePath();
462
469 static QRegularExpression shortNameRegularExpression();
470
475 static QString userLoginName();
476
481 static QString userFullName();
482
487 static QString osName();
488
497 static int systemMemorySizeMb();
498
504 static QString platform();
505
517 static QString applicationFullName();
518
522 static QString locale();
523
530 static void setLocale(const QLocale &locale);
531
533 static QString userThemesFolder();
534
536 static QString defaultStylePath();
537
542 static QString defaultThemesFolder();
543
548 static QString libraryPath();
549
551 static QString libexecPath();
552
559 static QString qmlImportPath();
560
562 static void setPrefixPath(const QString &prefixPath,
563 bool useDefaultPaths = false);
564
566 static void setPluginPath(const QString &pluginPath);
567
569 static void setPkgDataPath(const QString &pkgDataPath);
570
572 static void setDefaultSvgPaths(const QStringList &pathList);
573
575 static void setAuthDatabaseDirPath(const QString &authDbDirPath);
576
578 static void initQgis();
579
581 static bool createDatabase(QString *errorMessage = nullptr);
582
584 static bool createThemeFolder();
585
587 static void exitQgis();
588
590 static QString appIconPath();
591
592 // clang-format off
595 {
596 XDR = 0, // network, or big-endian, byte order
597 NDR = 1 // little-endian byte order
598 };
599 // clang-format on
600
602 static endian_t endian();
603
622 static QString
623 reportStyleSheet(QgsApplication::StyleSheetType styleSheetType =
625
630 static QString showSettings();
631
639 static void registerOgrDrivers();
640
642 static QString absolutePathToRelativePath(const QString &apath,
643 const QString &targetPath);
645 static QString relativePathToAbsolutePath(const QString &rpath,
646 const QString &targetPath);
647
649 static bool isRunningFromBuildDir() { return ABISYM(mRunningFromBuildDir); }
650#if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
651 static QString cfgIntDir() SIP_SKIP;
652#endif
653
658 static QString buildSourcePath();
659
664 static QString buildOutputPath();
665
671 static void skipGdalDriver(const QString &driver);
672
678 static void restoreGdalDriver(const QString &driver);
679
684 static QStringList skippedGdalDrivers();
685
692 static void applyGdalSkippedDrivers();
693
699 static void registerGdalDriversFromSettings();
700
707 static QStringList deferredSkippedGdalDrivers();
708
715 static void
716 setSkippedGdalDrivers(const QStringList &skippedGdalDrivers,
717 const QStringList &deferredSkippedGdalDrivers);
718
722 static int maxThreads();
723
728 static void setMaxThreads(int maxThreads);
729
734 static QgsTaskManager *taskManager();
735
742 Q_DECL_DEPRECATED static QgsSettingsRegistryCore *
743 settingsRegistryCore() SIP_KEEPREFERENCE SIP_DEPRECATED;
744
749 static QgsColorSchemeRegistry *colorSchemeRegistry() SIP_KEEPREFERENCE;
750
755 static QgsPaintEffectRegistry *paintEffectRegistry() SIP_KEEPREFERENCE;
756
761 static QgsRendererRegistry *rendererRegistry() SIP_KEEPREFERENCE;
762
768 static QgsRasterRendererRegistry *rasterRendererRegistry() SIP_SKIP;
769
776 pointCloudRendererRegistry() SIP_KEEPREFERENCE;
777
784 tiledSceneRendererRegistry() SIP_KEEPREFERENCE;
785
791 dataItemProviderRegistry() SIP_KEEPREFERENCE;
792
800 coordinateReferenceSystemRegistry() SIP_KEEPREFERENCE;
801
808 static QgsSvgCache *svgCache();
809
817 static QgsImageCache *imageCache();
818
825 static QgsSourceCache *sourceCache();
826
833 networkContentFetcherRegistry() SIP_KEEPREFERENCE;
834
840 static QgsValidityCheckRegistry *validityCheckRegistry() SIP_KEEPREFERENCE;
841
846 static QgsSymbolLayerRegistry *symbolLayerRegistry() SIP_KEEPREFERENCE;
847
853 static QgsCalloutRegistry *calloutRegistry() SIP_KEEPREFERENCE;
854
858 static QgsLayoutItemRegistry *layoutItemRegistry() SIP_KEEPREFERENCE;
859
865 static QgsAnnotationItemRegistry *annotationItemRegistry() SIP_KEEPREFERENCE;
866
871 static QgsGpsConnectionRegistry *gpsConnectionRegistry() SIP_KEEPREFERENCE;
872
878 static QgsBabelFormatRegistry *gpsBabelFormatRegistry() SIP_KEEPREFERENCE;
879
884 static QgsPluginLayerRegistry *pluginLayerRegistry() SIP_KEEPREFERENCE;
885
892 classificationMethodRegistry() SIP_KEEPREFERENCE;
893
899 static QgsBookmarkManager *bookmarkManager();
900
907 static QgsTileDownloadManager *tileDownloadManager() SIP_SKIP;
908
913 static QgsRecentStyleHandler *recentStyleHandler() SIP_KEEPREFERENCE;
914
920 static QgsDatabaseQueryLog *databaseQueryLog() SIP_KEEPREFERENCE;
921
931 static QgsStyleModel *defaultStyleModel();
932
939 static QgsFontManager *fontManager() SIP_KEEPREFERENCE;
940
945 static QgsSensorRegistry *sensorRegistry() SIP_KEEPREFERENCE;
946
951 static QgsPlotRegistry *plotRegistry() SIP_KEEPREFERENCE;
952
956 static QgsMessageLog *messageLog();
957
963 static QgsAuthManager *authManager();
964
970 authConfigurationStorageRegistry();
971
976 static QgsProcessingRegistry *processingRegistry();
977
982 static QgsPageSizeRegistry *pageSizeRegistry() SIP_KEEPREFERENCE;
983
989 static QgsAnnotationRegistry *annotationRegistry() SIP_SKIP;
990
997 applicationThemeRegistry() SIP_KEEPREFERENCE;
998
1003 static QgsActionScopeRegistry *actionScopeRegistry() SIP_KEEPREFERENCE;
1004
1010 static QgsConnectionRegistry *connectionRegistry();
1011
1015 static QgsRuntimeProfiler *profiler();
1016
1022 static QgsNumericFormatRegistry *numericFormatRegistry() SIP_KEEPREFERENCE;
1023
1027 static QgsFieldFormatterRegistry *fieldFormatterRegistry() SIP_KEEPREFERENCE;
1028
1032 static Qgs3DRendererRegistry *renderer3DRegistry() SIP_KEEPREFERENCE;
1033
1038 static Qgs3DSymbolRegistry *symbol3DRegistry() SIP_KEEPREFERENCE;
1039
1046 scaleBarRendererRegistry() SIP_KEEPREFERENCE;
1047
1054 labelingEngineRuleRegistry() SIP_KEEPREFERENCE;
1055
1060 static QgsProjectStorageRegistry *projectStorageRegistry() SIP_KEEPREFERENCE;
1061
1067 layerMetadataProviderRegistry() SIP_KEEPREFERENCE;
1068
1074 externalStorageRegistry() SIP_KEEPREFERENCE;
1075
1080 static QgsProfileSourceRegistry *profileSourceRegistry() SIP_KEEPREFERENCE;
1081
1090 localizedDataPathRegistry() SIP_KEEPREFERENCE;
1091
1103 static QString nullRepresentation();
1104
1116 static void setNullRepresentation(const QString &nullRepresentation);
1117
1125 static QVariantMap customVariables();
1126
1133 static void setCustomVariables(const QVariantMap &customVariables);
1134
1139 static void setCustomVariable(const QString &name, const QVariant &value);
1140
1147 static QStringList temporarilyTrustedProjectsFolders();
1148
1155 static void setTemporarilyTrustedProjectsFolders(
1156 const QStringList &trustedProjectsFolders);
1157
1164 static QStringList temporarilyUntrustedProjectsFolders();
1165
1172 static void setTemporarilyUntrustedProjectsFolders(
1173 const QStringList &untrustedProjectsFolders);
1174
1185 static int scaleIconSize(int standardSize,
1186 bool applyDevicePixelRatio = false);
1187
1196 int maxConcurrentConnectionsPerPool() const;
1197
1203 static void setTranslation(const QString &translation);
1204
1210 QString translation() const;
1211
1218 void collectTranslatableObjects(QgsTranslationContext *translationContext);
1219
1220#ifndef SIP_RUN
1231
1236 static const QgsSettingsEntryInteger
1238#endif
1239
1240#ifdef SIP_RUN
1241 SIP_IF_FEATURE(ANDROID)
1242 // dummy method to workaround sip generation issue
1243 bool x11EventFilter(XEvent *event);
1244 SIP_END
1245#endif
1246
1247signals:
1249 void preNotify(QObject *receiver, QEvent *event, bool *done) SIP_SKIP;
1250
1255
1263
1273
1280
1287
1288private:
1289 static void copyPath(const QString &src, const QString &dst);
1290 static QObject *ABISYM(mFileOpenEventReceiver);
1291
1292 static bool ABISYM(mInitialized);
1293
1295 static bool ABISYM(mRunningFromBuildDir);
1296
1299 static int ABISYM(sMaxThreads);
1300
1301 QMap<QString, QIcon> mIconCache;
1302 QMap<Cursor, QCursor> mCursorCache;
1303
1304 std::unique_ptr<QTranslator> mQgisTranslator;
1305 std::unique_ptr<QTranslator> mQtTranslator;
1306 std::unique_ptr<QTranslator> mQtBaseTranslator;
1307
1308 std::unique_ptr<QgsDataItemProviderRegistry> mDataItemProviderRegistry;
1309 QgsAuthManager *mAuthManager = nullptr;
1310
1311 struct ApplicationMembers;
1312
1313 // Applications members which belong to an instance of QgsApplication
1314 std::unique_ptr<ApplicationMembers> mApplicationMembers;
1315 // ... but in case QgsApplication is never instantiated (eg with custom
1316 // designer widgets), we fall back to static members
1317 static ApplicationMembers *sApplicationMembers;
1318
1319 static QgsAuthManager *sAuthManager;
1320
1321 static ApplicationMembers *members();
1322
1323 static void invalidateCaches();
1324
1329 void installTranslators() SIP_SKIP;
1330
1331 QStringList mTemporarilyTrustedProjectFolders;
1332 QStringList mTemporarilyUntrustedProjectFolders;
1333
1335};
1336
1337// clazy:excludeall=qstring-allocations
1338
1339#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,...
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.
void customVariablesChanged()
Emitted whenever a custom global variable changes.
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
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).
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,...
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.
Used for settings introspection and collects all QgsSettingsEntry instances of core.
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.
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)