QGIS API Documentation 4.3.0-Master (7c7bd4d7018)
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
357 static QString qgisSettingsDirPath();
358
360 static QString qgisUserDatabaseFilePath();
361
366 Q_DECL_DEPRECATED static QString qgisAuthDatabaseFilePath() SIP_DEPRECATED;
367
377 static QString qgisAuthDatabaseUri();
378
380 static QString splashPath();
381
383 static QString iconsPath();
384
386 static QString srsDatabaseFilePath();
387
393 static void setSvgPaths(const QStringList &svgPaths);
394
396 static QStringList svgPaths();
397
401 static QStringList layoutTemplatePaths();
402
404 static QMap<QString, QString> systemEnvVars();
405
407 static QString prefixPath();
408
410 static QString pluginPath();
411
413 static QString pkgDataPath();
414
416 static QString activeThemePath();
417
419 static QString defaultThemePath();
420
425 static QString iconPath(const QString &iconFile);
426
434 static QIcon getThemeIcon(const QString &name,
435 const QColor &fillColor = QColor(),
436 const QColor &strokeColor = QColor());
437
438 // clang-format off
453 // clang-format on
454
461 static QCursor getThemeCursor(Cursor cursor);
462
471 static QPixmap getThemePixmap(const QString &name,
472 const QColor &foreColor = QColor(),
473 const QColor &backColor = QColor(),
474 int size = 16);
475
477 static QString userStylePath();
478
485 static QRegularExpression shortNameRegularExpression();
486
491 static QString userLoginName();
492
497 static QString userFullName();
498
503 static QString osName();
504
513 static int systemMemorySizeMb();
514
520 static QString platform();
521
533 static QString applicationFullName();
534
538 static QString locale();
539
546 static void setLocale(const QLocale &locale);
547
549 static QString userThemesFolder();
550
552 static QString defaultStylePath();
553
558 static QString defaultThemesFolder();
559
564 static QString libraryPath();
565
567 static QString libexecPath();
568
575 static QString qmlImportPath();
576
578 static void setPrefixPath(const QString &prefixPath,
579 bool useDefaultPaths = false);
580
582 static void setPluginPath(const QString &pluginPath);
583
585 static void setPkgDataPath(const QString &pkgDataPath);
586
588 static void setDefaultSvgPaths(const QStringList &pathList);
589
591 static void setAuthDatabaseDirPath(const QString &authDbDirPath);
592
594 static void initQgis();
595
597 static bool createDatabase(QString *errorMessage = nullptr);
598
600 static bool createThemeFolder();
601
603 static void exitQgis();
604
606 static QString appIconPath();
607
608 // clang-format off
611 {
612 XDR = 0,
613 NDR = 1
614 };
615 // clang-format on
616
618 static endian_t endian();
619
638 static QString
639 reportStyleSheet(QgsApplication::StyleSheetType styleSheetType =
641
646 static QString showSettings();
647
655 static void registerOgrDrivers();
656
658 static QString absolutePathToRelativePath(const QString &apath,
659 const QString &targetPath);
661 static QString relativePathToAbsolutePath(const QString &rpath,
662 const QString &targetPath);
663
665 static bool isRunningFromBuildDir() { return ABISYM(mRunningFromBuildDir); }
666#if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
667 static QString cfgIntDir() SIP_SKIP;
668#endif
669
674 static QString buildSourcePath();
675
680 static QString buildOutputPath();
681
687 static void skipGdalDriver(const QString &driver);
688
694 static void restoreGdalDriver(const QString &driver);
695
700 static QStringList skippedGdalDrivers();
701
708 static void applyGdalSkippedDrivers();
709
715 static void registerGdalDriversFromSettings();
716
723 static QStringList deferredSkippedGdalDrivers();
724
731 static void
732 setSkippedGdalDrivers(const QStringList &skippedGdalDrivers,
733 const QStringList &deferredSkippedGdalDrivers);
734
738 static int maxThreads();
739
744 static void setMaxThreads(int maxThreads);
745
750 static QgsTaskManager *taskManager();
751
758 Q_DECL_DEPRECATED static QgsSettingsRegistryCore *
759 settingsRegistryCore() SIP_KEEPREFERENCE SIP_DEPRECATED;
760
765 static QgsColorSchemeRegistry *colorSchemeRegistry() SIP_KEEPREFERENCE;
766
771 static QgsPaintEffectRegistry *paintEffectRegistry() SIP_KEEPREFERENCE;
772
777 static QgsRendererRegistry *rendererRegistry() SIP_KEEPREFERENCE;
778
784 static QgsRasterRendererRegistry *rasterRendererRegistry() SIP_SKIP;
785
792 pointCloudRendererRegistry() SIP_KEEPREFERENCE;
793
800 tiledSceneRendererRegistry() SIP_KEEPREFERENCE;
801
807 dataItemProviderRegistry() SIP_KEEPREFERENCE;
808
816 coordinateReferenceSystemRegistry() SIP_KEEPREFERENCE;
817
824 static QgsSvgCache *svgCache();
825
833 static QgsImageCache *imageCache();
834
841 static QgsSourceCache *sourceCache();
842
849 networkContentFetcherRegistry() SIP_KEEPREFERENCE;
850
856 static QgsValidityCheckRegistry *validityCheckRegistry() SIP_KEEPREFERENCE;
857
862 static QgsSymbolLayerRegistry *symbolLayerRegistry() SIP_KEEPREFERENCE;
863
869 static QgsCalloutRegistry *calloutRegistry() SIP_KEEPREFERENCE;
870
874 static QgsLayoutItemRegistry *layoutItemRegistry() SIP_KEEPREFERENCE;
875
881 static QgsAnnotationItemRegistry *annotationItemRegistry() SIP_KEEPREFERENCE;
882
887 static QgsGpsConnectionRegistry *gpsConnectionRegistry() SIP_KEEPREFERENCE;
888
894 static QgsBabelFormatRegistry *gpsBabelFormatRegistry() SIP_KEEPREFERENCE;
895
900 static QgsPluginLayerRegistry *pluginLayerRegistry() SIP_KEEPREFERENCE;
901
908 classificationMethodRegistry() SIP_KEEPREFERENCE;
909
915 static QgsBookmarkManager *bookmarkManager();
916
923 static QgsTileDownloadManager *tileDownloadManager() SIP_SKIP;
924
929 static QgsRecentStyleHandler *recentStyleHandler() SIP_KEEPREFERENCE;
930
936 static QgsDatabaseQueryLog *databaseQueryLog() SIP_KEEPREFERENCE;
937
947 static QgsStyleModel *defaultStyleModel();
948
955 static QgsFontManager *fontManager() SIP_KEEPREFERENCE;
956
961 static QgsSensorRegistry *sensorRegistry() SIP_KEEPREFERENCE;
962
967 static QgsPlotRegistry *plotRegistry() SIP_KEEPREFERENCE;
968
972 static QgsMessageLog *messageLog();
973
979 static QgsAuthManager *authManager();
980
986 authConfigurationStorageRegistry();
987
992 static QgsProcessingRegistry *processingRegistry();
993
998 static QgsPageSizeRegistry *pageSizeRegistry() SIP_KEEPREFERENCE;
999
1005 static QgsAnnotationRegistry *annotationRegistry() SIP_SKIP;
1006
1013 applicationThemeRegistry() SIP_KEEPREFERENCE;
1014
1019 static QgsActionScopeRegistry *actionScopeRegistry() SIP_KEEPREFERENCE;
1020
1026 static QgsConnectionRegistry *connectionRegistry();
1027
1031 static QgsRuntimeProfiler *profiler();
1032
1038 static QgsNumericFormatRegistry *numericFormatRegistry() SIP_KEEPREFERENCE;
1039
1043 static QgsFieldFormatterRegistry *fieldFormatterRegistry() SIP_KEEPREFERENCE;
1044
1048 static Qgs3DRendererRegistry *renderer3DRegistry() SIP_KEEPREFERENCE;
1049
1054 static Qgs3DSymbolRegistry *symbol3DRegistry() SIP_KEEPREFERENCE;
1055
1064 static QgsMaterialRegistry *materialRegistry() SIP_KEEPREFERENCE;
1065
1072 scaleBarRendererRegistry() SIP_KEEPREFERENCE;
1073
1080 labelingEngineRuleRegistry() SIP_KEEPREFERENCE;
1081
1088 symbolConverterRegistry() SIP_KEEPREFERENCE;
1089
1094 static QgsProjectStorageRegistry *projectStorageRegistry() SIP_KEEPREFERENCE;
1095
1101 layerMetadataProviderRegistry() SIP_KEEPREFERENCE;
1102
1108 externalStorageRegistry() SIP_KEEPREFERENCE;
1109
1114 static QgsProfileSourceRegistry *profileSourceRegistry() SIP_KEEPREFERENCE;
1115
1124 localizedDataPathRegistry() SIP_KEEPREFERENCE;
1125
1137 static QString nullRepresentation();
1138
1150 static void setNullRepresentation(const QString &nullRepresentation);
1151
1159 static QVariantMap customVariables();
1160
1167 static void setCustomVariables(const QVariantMap &customVariables);
1168
1173 static void setCustomVariable(const QString &name, const QVariant &value);
1174
1181 static QStringList temporarilyTrustedProjectsFolders();
1182
1189 static void setTemporarilyTrustedProjectsFolders(
1190 const QStringList &trustedProjectsFolders);
1191
1198 static QStringList temporarilyUntrustedProjectsFolders();
1199
1206 static void setTemporarilyUntrustedProjectsFolders(
1207 const QStringList &untrustedProjectsFolders);
1208
1219 static int scaleIconSize(int standardSize,
1220 bool applyDevicePixelRatio = false);
1221
1230 int maxConcurrentConnectionsPerPool() const;
1231
1237 static void setTranslation(const QString &translation);
1238
1244 QString translation() const;
1245
1252 void collectTranslatableObjects(QgsTranslationContext *translationContext);
1253
1255
1256#ifndef SIP_RUN
1267
1272 static const QgsSettingsEntryInteger
1274#endif
1275
1276#ifdef SIP_RUN
1277 SIP_IF_FEATURE(ANDROID)
1278 // dummy method to workaround sip generation issue
1279 bool x11EventFilter(XEvent *event);
1280 SIP_END
1281#endif
1282
1283signals:
1285 void preNotify(QObject *receiver, QEvent *event, bool *done) SIP_SKIP;
1286
1291
1299
1309
1316
1323
1324private:
1325 static void copyPath(const QString &src, const QString &dst);
1326 static QObject *ABISYM(mFileOpenEventReceiver);
1327
1328 static bool ABISYM(mInitialized);
1329
1331 static bool ABISYM(mRunningFromBuildDir);
1332
1335 static int ABISYM(sMaxThreads);
1336
1337 QMap<QString, QIcon> mIconCache;
1338 QMap<Cursor, QCursor> mCursorCache;
1339
1340 std::unique_ptr<QTranslator> mQgisTranslator;
1341 std::unique_ptr<QTranslator> mQtTranslator;
1342 std::unique_ptr<QTranslator> mQtBaseTranslator;
1343
1344 std::unique_ptr<QgsDataItemProviderRegistry> mDataItemProviderRegistry;
1345 QgsAuthManager *mAuthManager = nullptr;
1346
1347 struct ApplicationMembers;
1348
1349 // Applications members which belong to an instance of QgsApplication
1350 std::unique_ptr<ApplicationMembers> mApplicationMembers;
1351 // ... but in case QgsApplication is never instantiated (eg with custom
1352 // designer widgets), we fall back to static members
1353 static ApplicationMembers *sApplicationMembers;
1354
1355 static QgsAuthManager *sAuthManager;
1356
1357 static ApplicationMembers *members();
1358
1359 static void invalidateCaches();
1360
1365 void installTranslators() SIP_SKIP;
1366
1367 QStringList mTemporarilyTrustedProjectFolders;
1368 QStringList mTemporarilyUntrustedProjectFolders;
1369
1371};
1372
1373// clazy:excludeall=qstring-allocations
1374
1375#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.
@ XDR
Network, or big-endian, byte order.
@ NDR
Little-endian byte order.
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)