QGIS API Documentation 4.1.0-Master (3b8ef1f72a3)
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
39class QgsTaskManager;
48class QgsSvgCache;
49class QgsImageCache;
50class QgsSourceCache;
58class QgsMessageLog;
60class QgsAnnotationRegistry;
62class QgsUserProfile;
65class QgsAuthManager;
68class QTranslator;
70class QgsPlotRegistry;
72class QgsStyleModel;
83class QgsFontManager;
89
90// clang-format off
105class CORE_EXPORT QgsApplication : public QApplication
106{
107// clang-format on
108#ifdef SIP_RUN
109 // clang-format off
110 % TypeCode
111 // Convert a Python argv list to a conventional C argc count and argv array.
112 static char **qtgui_ArgvToC( PyObject *argvlist, int &argc )
113 {
114 char **argv;
115
116 argc = PyList_GET_SIZE( argvlist );
117
118 // Allocate space for two copies of the argument pointers, plus the
119 // terminating NULL.
120 if ( ( argv = ( char ** )sipMalloc( 2 * ( argc + 1 ) * sizeof( char * ) ) ) == NULL )
121 return NULL;
122
123 // Convert the list.
124 for ( int a = 0; a < argc; ++a )
125 {
126 char *arg;
127 // Get the argument and allocate memory for it.
128 if ( ( arg = PyBytes_AsString( PyList_GET_ITEM( argvlist, a ) ) ) == NULL ||
129 ( argv[a] = ( char * )sipMalloc( strlen( arg ) + 1 ) ) == NULL )
130 return NULL;
131 // Copy the argument and save a pointer to it.
132 strcpy( argv[a], arg );
133 argv[a + argc + 1] = argv[a];
134 }
135
136 argv[argc + argc + 1] = argv[argc] = NULL;
137
138 return argv;
139 }
140
141 // Remove arguments from the Python argv list that have been removed from the
142 // C argv array.
143 static void qtgui_UpdatePyArgv( PyObject *argvlist, int argc, char **argv )
144 {
145 for ( int a = 0, na = 0; a < argc; ++a )
146 {
147 // See if it was removed.
148 if ( argv[na] == argv[a + argc + 1] )
149 ++na;
150 else
151 PyList_SetSlice( argvlist, na, na + 1, NULL );
152 }
153 }
154 % End
155// clang-format on
156#endif
157
158 // clang-format off
159 Q_OBJECT
160
161 public:
162
176 // clang-format on
177 static const char *QGIS_ORGANIZATION_NAME;
178 static const char *QGIS_ORGANIZATION_DOMAIN;
179 static const char *QGIS_APPLICATION_NAME;
180#ifndef SIP_RUN
181
194 QgsApplication(int &argc, char **argv, bool GUIenabled,
195 const QString &profileFolder = QString(),
196 const QString &platformName = "external");
197#else
198 // clang-format off
199
208 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" )];
209 % MethodCode
210 // The Python interface is a list of argument strings that is modified.
211
212 int argc;
213 char **argv;
214
215 // Convert the list.
216 if ( ( argv = qtgui_ArgvToC( a0, argc ) ) == NULL )
217 sipIsErr = 1;
218 else
219 {
220 // Create it now the arguments are right.
221 static int nargc = argc;
222
223 sipCpp = new sipQgsApplication( nargc, argv, a1, *a2, *a3 );
224
225 // Now modify the original list.
226 qtgui_UpdatePyArgv( a0, argc, argv );
227 }
228 % End
229// clang-format on
230#endif
231
232 ~QgsApplication() override;
233
238 static QgsApplication *instance();
239
247 static void init(QString profileFolder = QString()) SIP_SKIP;
248
250 bool event(QEvent *event) override;
251
253 bool notify(QObject *receiver, QEvent *event) override;
254
256 static void setFileOpenEventReceiver(QObject *receiver);
257
268 static void setThemeName(const QString &themeName);
269
274 static QString resolvePkgPath();
275
283 static QString themeName();
284
292 static void setUITheme(const QString &themeName);
293
301 static QHash<QString, QString> uiThemes();
302
304 static QString authorsFilePath();
305
311 static QString contributorsFilePath();
312
314 static QString sponsorsFilePath();
315
317 static QString donorsFilePath();
318
320 static QString serverResourcesPath();
321
325 static QString translatorsFilePath();
326
330 static QString licenceFilePath();
331
333 static QString i18nPath();
334
338 static QString metadataPath();
339
341 static QString qgisMasterDatabaseFilePath();
342
344 static QString qgisSettingsDirPath();
345
347 static QString qgisUserDatabaseFilePath();
348
353 Q_DECL_DEPRECATED static QString qgisAuthDatabaseFilePath() SIP_DEPRECATED;
354
364 static QString qgisAuthDatabaseUri();
365
367 static QString splashPath();
368
370 static QString iconsPath();
371
373 static QString srsDatabaseFilePath();
374
380 static void setSvgPaths(const QStringList &svgPaths);
381
383 static QStringList svgPaths();
384
388 static QStringList layoutTemplatePaths();
389
391 static QMap<QString, QString> systemEnvVars();
392
394 static QString prefixPath();
395
397 static QString pluginPath();
398
400 static QString pkgDataPath();
401
403 static QString activeThemePath();
404
406 static QString defaultThemePath();
407
412 static QString iconPath(const QString &iconFile);
413
421 static QIcon getThemeIcon(const QString &name,
422 const QColor &fillColor = QColor(),
423 const QColor &strokeColor = QColor());
424
425 // clang-format off
440 // clang-format on
441
448 static QCursor getThemeCursor(Cursor cursor);
449
458 static QPixmap getThemePixmap(const QString &name,
459 const QColor &foreColor = QColor(),
460 const QColor &backColor = QColor(),
461 int size = 16);
462
464 static QString userStylePath();
465
472 static QRegularExpression shortNameRegularExpression();
473
478 static QString userLoginName();
479
484 static QString userFullName();
485
490 static QString osName();
491
500 static int systemMemorySizeMb();
501
507 static QString platform();
508
520 static QString applicationFullName();
521
525 static QString locale();
526
533 static void setLocale(const QLocale &locale);
534
536 static QString userThemesFolder();
537
539 static QString defaultStylePath();
540
545 static QString defaultThemesFolder();
546
551 static QString libraryPath();
552
554 static QString libexecPath();
555
562 static QString qmlImportPath();
563
565 static void setPrefixPath(const QString &prefixPath,
566 bool useDefaultPaths = false);
567
569 static void setPluginPath(const QString &pluginPath);
570
572 static void setPkgDataPath(const QString &pkgDataPath);
573
575 static void setDefaultSvgPaths(const QStringList &pathList);
576
578 static void setAuthDatabaseDirPath(const QString &authDbDirPath);
579
581 static void initQgis();
582
584 static bool createDatabase(QString *errorMessage = nullptr);
585
587 static bool createThemeFolder();
588
590 static void exitQgis();
591
593 static QString appIconPath();
594
595 // clang-format off
598 {
599 XDR = 0, // network, or big-endian, byte order
600 NDR = 1 // little-endian byte order
601 };
602 // clang-format on
603
605 static endian_t endian();
606
625 static QString
626 reportStyleSheet(QgsApplication::StyleSheetType styleSheetType =
628
633 static QString showSettings();
634
642 static void registerOgrDrivers();
643
645 static QString absolutePathToRelativePath(const QString &apath,
646 const QString &targetPath);
648 static QString relativePathToAbsolutePath(const QString &rpath,
649 const QString &targetPath);
650
652 static bool isRunningFromBuildDir() { return ABISYM(mRunningFromBuildDir); }
653#if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
654 static QString cfgIntDir() SIP_SKIP;
655#endif
656
661 static QString buildSourcePath();
662
667 static QString buildOutputPath();
668
674 static void skipGdalDriver(const QString &driver);
675
681 static void restoreGdalDriver(const QString &driver);
682
687 static QStringList skippedGdalDrivers();
688
695 static void applyGdalSkippedDrivers();
696
702 static void registerGdalDriversFromSettings();
703
710 static QStringList deferredSkippedGdalDrivers();
711
718 static void
719 setSkippedGdalDrivers(const QStringList &skippedGdalDrivers,
720 const QStringList &deferredSkippedGdalDrivers);
721
725 static int maxThreads();
726
731 static void setMaxThreads(int maxThreads);
732
737 static QgsTaskManager *taskManager();
738
745 Q_DECL_DEPRECATED static QgsSettingsRegistryCore *
746 settingsRegistryCore() SIP_KEEPREFERENCE SIP_DEPRECATED;
747
752 static QgsColorSchemeRegistry *colorSchemeRegistry() SIP_KEEPREFERENCE;
753
758 static QgsPaintEffectRegistry *paintEffectRegistry() SIP_KEEPREFERENCE;
759
764 static QgsRendererRegistry *rendererRegistry() SIP_KEEPREFERENCE;
765
771 static QgsRasterRendererRegistry *rasterRendererRegistry() SIP_SKIP;
772
779 pointCloudRendererRegistry() SIP_KEEPREFERENCE;
780
787 tiledSceneRendererRegistry() SIP_KEEPREFERENCE;
788
794 dataItemProviderRegistry() SIP_KEEPREFERENCE;
795
803 coordinateReferenceSystemRegistry() SIP_KEEPREFERENCE;
804
811 static QgsSvgCache *svgCache();
812
820 static QgsImageCache *imageCache();
821
828 static QgsSourceCache *sourceCache();
829
836 networkContentFetcherRegistry() SIP_KEEPREFERENCE;
837
843 static QgsValidityCheckRegistry *validityCheckRegistry() SIP_KEEPREFERENCE;
844
849 static QgsSymbolLayerRegistry *symbolLayerRegistry() SIP_KEEPREFERENCE;
850
856 static QgsCalloutRegistry *calloutRegistry() SIP_KEEPREFERENCE;
857
861 static QgsLayoutItemRegistry *layoutItemRegistry() SIP_KEEPREFERENCE;
862
868 static QgsAnnotationItemRegistry *annotationItemRegistry() SIP_KEEPREFERENCE;
869
874 static QgsGpsConnectionRegistry *gpsConnectionRegistry() SIP_KEEPREFERENCE;
875
881 static QgsBabelFormatRegistry *gpsBabelFormatRegistry() SIP_KEEPREFERENCE;
882
887 static QgsPluginLayerRegistry *pluginLayerRegistry() SIP_KEEPREFERENCE;
888
895 classificationMethodRegistry() SIP_KEEPREFERENCE;
896
902 static QgsBookmarkManager *bookmarkManager();
903
910 static QgsTileDownloadManager *tileDownloadManager() SIP_SKIP;
911
916 static QgsRecentStyleHandler *recentStyleHandler() SIP_KEEPREFERENCE;
917
923 static QgsDatabaseQueryLog *databaseQueryLog() SIP_KEEPREFERENCE;
924
934 static QgsStyleModel *defaultStyleModel();
935
942 static QgsFontManager *fontManager() SIP_KEEPREFERENCE;
943
948 static QgsSensorRegistry *sensorRegistry() SIP_KEEPREFERENCE;
949
954 static QgsPlotRegistry *plotRegistry() SIP_KEEPREFERENCE;
955
959 static QgsMessageLog *messageLog();
960
966 static QgsAuthManager *authManager();
967
973 authConfigurationStorageRegistry();
974
979 static QgsProcessingRegistry *processingRegistry();
980
985 static QgsPageSizeRegistry *pageSizeRegistry() SIP_KEEPREFERENCE;
986
992 static QgsAnnotationRegistry *annotationRegistry() SIP_SKIP;
993
1000 applicationThemeRegistry() SIP_KEEPREFERENCE;
1001
1006 static QgsActionScopeRegistry *actionScopeRegistry() SIP_KEEPREFERENCE;
1007
1013 static QgsConnectionRegistry *connectionRegistry();
1014
1018 static QgsRuntimeProfiler *profiler();
1019
1025 static QgsNumericFormatRegistry *numericFormatRegistry() SIP_KEEPREFERENCE;
1026
1030 static QgsFieldFormatterRegistry *fieldFormatterRegistry() SIP_KEEPREFERENCE;
1031
1035 static Qgs3DRendererRegistry *renderer3DRegistry() SIP_KEEPREFERENCE;
1036
1041 static Qgs3DSymbolRegistry *symbol3DRegistry() SIP_KEEPREFERENCE;
1042
1051 static QgsMaterialRegistry *materialRegistry() SIP_KEEPREFERENCE;
1052
1059 scaleBarRendererRegistry() SIP_KEEPREFERENCE;
1060
1067 labelingEngineRuleRegistry() SIP_KEEPREFERENCE;
1068
1075 symbolConverterRegistry() SIP_KEEPREFERENCE;
1076
1081 static QgsProjectStorageRegistry *projectStorageRegistry() SIP_KEEPREFERENCE;
1082
1088 layerMetadataProviderRegistry() SIP_KEEPREFERENCE;
1089
1095 externalStorageRegistry() SIP_KEEPREFERENCE;
1096
1101 static QgsProfileSourceRegistry *profileSourceRegistry() SIP_KEEPREFERENCE;
1102
1111 localizedDataPathRegistry() SIP_KEEPREFERENCE;
1112
1124 static QString nullRepresentation();
1125
1137 static void setNullRepresentation(const QString &nullRepresentation);
1138
1146 static QVariantMap customVariables();
1147
1154 static void setCustomVariables(const QVariantMap &customVariables);
1155
1160 static void setCustomVariable(const QString &name, const QVariant &value);
1161
1168 static QStringList temporarilyTrustedProjectsFolders();
1169
1176 static void setTemporarilyTrustedProjectsFolders(
1177 const QStringList &trustedProjectsFolders);
1178
1185 static QStringList temporarilyUntrustedProjectsFolders();
1186
1193 static void setTemporarilyUntrustedProjectsFolders(
1194 const QStringList &untrustedProjectsFolders);
1195
1206 static int scaleIconSize(int standardSize,
1207 bool applyDevicePixelRatio = false);
1208
1217 int maxConcurrentConnectionsPerPool() const;
1218
1224 static void setTranslation(const QString &translation);
1225
1231 QString translation() const;
1232
1239 void collectTranslatableObjects(QgsTranslationContext *translationContext);
1240
1242
1243#ifndef SIP_RUN
1254
1259 static const QgsSettingsEntryInteger
1261#endif
1262
1263#ifdef SIP_RUN
1264 SIP_IF_FEATURE(ANDROID)
1265 // dummy method to workaround sip generation issue
1266 bool x11EventFilter(XEvent *event);
1267 SIP_END
1268#endif
1269
1270signals:
1272 void preNotify(QObject *receiver, QEvent *event, bool *done) SIP_SKIP;
1273
1278
1286
1296
1303
1310
1311private:
1312 static void copyPath(const QString &src, const QString &dst);
1313 static QObject *ABISYM(mFileOpenEventReceiver);
1314
1315 static bool ABISYM(mInitialized);
1316
1318 static bool ABISYM(mRunningFromBuildDir);
1319
1322 static int ABISYM(sMaxThreads);
1323
1324 QMap<QString, QIcon> mIconCache;
1325 QMap<Cursor, QCursor> mCursorCache;
1326
1327 std::unique_ptr<QTranslator> mQgisTranslator;
1328 std::unique_ptr<QTranslator> mQtTranslator;
1329 std::unique_ptr<QTranslator> mQtBaseTranslator;
1330
1331 std::unique_ptr<QgsDataItemProviderRegistry> mDataItemProviderRegistry;
1332 QgsAuthManager *mAuthManager = nullptr;
1333
1334 struct ApplicationMembers;
1335
1336 // Applications members which belong to an instance of QgsApplication
1337 std::unique_ptr<ApplicationMembers> mApplicationMembers;
1338 // ... but in case QgsApplication is never instantiated (eg with custom
1339 // designer widgets), we fall back to static members
1340 static ApplicationMembers *sApplicationMembers;
1341
1342 static QgsAuthManager *sAuthManager;
1343
1344 static ApplicationMembers *members();
1345
1346 static void invalidateCaches();
1347
1352 void installTranslators() SIP_SKIP;
1353
1354 QStringList mTemporarilyTrustedProjectFolders;
1355 QStringList mTemporarilyUntrustedProjectFolders;
1356
1358};
1359
1360// clazy:excludeall=qstring-allocations
1361
1362#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.
static const QgsSettingsEntryString * settingsNullRepresentation
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,...
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.
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.
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)