QGIS API Documentation 4.3.0-Master (4ecdf0f3f59)
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
405 static void setProjectTemplatePaths(const QStringList &projectTemplatePaths);
406
414 static QStringList projectTemplatePaths();
415
423 static QStringList defaultProjectTemplatePaths();
424
428 static QStringList layoutTemplatePaths();
429
431 static QMap<QString, QString> systemEnvVars();
432
434 static QString prefixPath();
435
437 static QString pluginPath();
438
440 static QString pkgDataPath();
441
443 static QString activeThemePath();
444
446 static QString defaultThemePath();
447
452 static QString iconPath(const QString &iconFile);
453
461 static QIcon getThemeIcon(const QString &name,
462 const QColor &fillColor = QColor(),
463 const QColor &strokeColor = QColor());
464
465 // clang-format off
480 // clang-format on
481
488 static QCursor getThemeCursor(Cursor cursor);
489
498 static QPixmap getThemePixmap(const QString &name,
499 const QColor &foreColor = QColor(),
500 const QColor &backColor = QColor(),
501 int size = 16);
502
504 static QString userStylePath();
505
512 static QRegularExpression shortNameRegularExpression();
513
518 static QString userLoginName();
519
524 static QString userFullName();
525
530 static QString osName();
531
540 static int systemMemorySizeMb();
541
547 static QString platform();
548
560 static QString applicationFullName();
561
565 static QString locale();
566
573 static void setLocale(const QLocale &locale);
574
576 static QString userThemesFolder();
577
579 static QString defaultStylePath();
580
585 static QString defaultThemesFolder();
586
591 static QString libraryPath();
592
594 static QString libexecPath();
595
602 static QString qmlImportPath();
603
605 static void setPrefixPath(const QString &prefixPath,
606 bool useDefaultPaths = false);
607
609 static void setPluginPath(const QString &pluginPath);
610
612 static void setPkgDataPath(const QString &pkgDataPath);
613
615 static void setDefaultSvgPaths(const QStringList &pathList);
616
618 static void setAuthDatabaseDirPath(const QString &authDbDirPath);
619
621 static void initQgis();
622
624 static bool createDatabase(QString *errorMessage = nullptr);
625
627 static bool createThemeFolder();
628
630 static void exitQgis();
631
633 static QString appIconPath();
634
635 // clang-format off
638 {
639 XDR = 0,
640 NDR = 1
641 };
642 // clang-format on
643
645 static endian_t endian();
646
665 static QString
666 reportStyleSheet(QgsApplication::StyleSheetType styleSheetType =
668
673 static QString showSettings();
674
682 static void registerOgrDrivers();
683
685 static QString absolutePathToRelativePath(const QString &apath,
686 const QString &targetPath);
688 static QString relativePathToAbsolutePath(const QString &rpath,
689 const QString &targetPath);
690
692 static bool isRunningFromBuildDir() { return ABISYM(mRunningFromBuildDir); }
693#if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
694 static QString cfgIntDir() SIP_SKIP;
695#endif
696
701 static QString buildSourcePath();
702
707 static QString buildOutputPath();
708
714 static void skipGdalDriver(const QString &driver);
715
721 static void restoreGdalDriver(const QString &driver);
722
727 static QStringList skippedGdalDrivers();
728
735 static void applyGdalSkippedDrivers();
736
742 static void registerGdalDriversFromSettings();
743
750 static QStringList deferredSkippedGdalDrivers();
751
758 static void
759 setSkippedGdalDrivers(const QStringList &skippedGdalDrivers,
760 const QStringList &deferredSkippedGdalDrivers);
761
765 static int maxThreads();
766
771 static void setMaxThreads(int maxThreads);
772
777 static QgsTaskManager *taskManager() SIP_DISALLOWNONE;
778
785 Q_DECL_DEPRECATED static QgsSettingsRegistryCore *
786 settingsRegistryCore() SIP_KEEPREFERENCE SIP_DEPRECATED;
787
793 colorSchemeRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
794
800 paintEffectRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
801
806 static QgsRendererRegistry *
807 rendererRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
808
815 rasterRendererRegistry() SIP_DISALLOWNONE SIP_SKIP;
816
823 pointCloudRendererRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
824
831 tiledSceneRendererRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
832
838 dataItemProviderRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
839
847 coordinateReferenceSystemRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
848
855 static QgsSvgCache *svgCache() SIP_DISALLOWNONE;
856
864 static QgsImageCache *imageCache() SIP_DISALLOWNONE;
865
872 static QgsSourceCache *sourceCache() SIP_DISALLOWNONE;
873
880 networkContentFetcherRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
881
888 validityCheckRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
889
895 symbolLayerRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
896
902 static QgsCalloutRegistry *
903 calloutRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
904
908 static QgsLayoutItemRegistry *
909 layoutItemRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
910
917 annotationItemRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
918
924 gpsConnectionRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
925
932 gpsBabelFormatRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
933
939 pluginLayerRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
940
947 classificationMethodRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
948
954 static QgsBookmarkManager *bookmarkManager() SIP_DISALLOWNONE;
955
962 static QgsTileDownloadManager *tileDownloadManager() SIP_SKIP;
963
968 static QgsRecentStyleHandler *
969 recentStyleHandler() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
970
976 static QgsDatabaseQueryLog *
977 databaseQueryLog() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
978
988 static QgsStyleModel *defaultStyleModel() SIP_DISALLOWNONE;
989
997
1002 static QgsSensorRegistry *sensorRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1003
1008 static QgsPlotRegistry *plotRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1009
1013 static QgsMessageLog *messageLog();
1014
1020 static QgsAuthManager *authManager();
1021
1027 authConfigurationStorageRegistry();
1028
1033 static QgsProcessingRegistry *processingRegistry() SIP_DISALLOWNONE;
1034
1039 static QgsPageSizeRegistry *
1040 pageSizeRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1041
1047 static QgsAnnotationRegistry *annotationRegistry() SIP_DISALLOWNONE SIP_SKIP;
1048
1055 applicationThemeRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1056
1061 static QgsActionScopeRegistry *
1062 actionScopeRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1063
1069 static QgsConnectionRegistry *connectionRegistry() SIP_DISALLOWNONE;
1070
1074 static QgsRuntimeProfiler *profiler() SIP_DISALLOWNONE;
1075
1082 numericFormatRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1083
1088 fieldFormatterRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1089
1093 static Qgs3DRendererRegistry *
1094 renderer3DRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1095
1100 static Qgs3DSymbolRegistry *
1101 symbol3DRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1102
1111 static QgsMaterialRegistry *
1112 materialRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1113
1120 scaleBarRendererRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1121
1128 labelingEngineRuleRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1129
1136 symbolConverterRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1137
1143 projectStorageRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1144
1150 layerMetadataProviderRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1151
1157 externalStorageRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1158
1164 profileSourceRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1165
1174 localizedDataPathRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1175
1187 static QString nullRepresentation();
1188
1200 static void setNullRepresentation(const QString &nullRepresentation);
1201
1209 static QVariantMap customVariables();
1210
1217 static void setCustomVariables(const QVariantMap &customVariables);
1218
1223 static void setCustomVariable(const QString &name, const QVariant &value);
1224
1231 static QStringList temporarilyTrustedProjectsFolders();
1232
1239 static void setTemporarilyTrustedProjectsFolders(
1240 const QStringList &trustedProjectsFolders);
1241
1248 static QStringList temporarilyUntrustedProjectsFolders();
1249
1256 static void setTemporarilyUntrustedProjectsFolders(
1257 const QStringList &untrustedProjectsFolders);
1258
1269 static int scaleIconSize(int standardSize,
1270 bool applyDevicePixelRatio = false);
1271
1280 int maxConcurrentConnectionsPerPool() const;
1281
1287 static void setTranslation(const QString &translation);
1288
1294 QString translation() const;
1295
1302 void collectTranslatableObjects(QgsTranslationContext *translationContext);
1303
1305
1306#ifndef SIP_RUN
1319
1324 static const QgsSettingsEntryInteger
1326#endif
1327
1328#ifdef SIP_RUN
1329 SIP_IF_FEATURE(ANDROID)
1330 // dummy method to workaround sip generation issue
1331 bool x11EventFilter(XEvent *event);
1332 SIP_END
1333#endif
1334
1335signals:
1337 void preNotify(QObject *receiver, QEvent *event, bool *done) SIP_SKIP;
1338
1343
1351
1361
1368
1375
1376private:
1377 static void copyPath(const QString &src, const QString &dst);
1378 static QObject *ABISYM(mFileOpenEventReceiver);
1379
1380 static bool ABISYM(mInitialized);
1381
1383 static bool ABISYM(mRunningFromBuildDir);
1384
1387 static int ABISYM(sMaxThreads);
1388
1389 QMap<QString, QIcon> mIconCache;
1390 QMap<Cursor, QCursor> mCursorCache;
1391
1392 std::unique_ptr<QTranslator> mQgisTranslator;
1393 std::unique_ptr<QTranslator> mQtTranslator;
1394 std::unique_ptr<QTranslator> mQtBaseTranslator;
1395
1396 std::unique_ptr<QgsDataItemProviderRegistry> mDataItemProviderRegistry;
1397 QgsAuthManager *mAuthManager = nullptr;
1398
1399 struct ApplicationMembers;
1400
1401 // Applications members which belong to an instance of QgsApplication
1402 std::unique_ptr<ApplicationMembers> mApplicationMembers;
1403 // ... but in case QgsApplication is never instantiated (eg with custom
1404 // designer widgets), we fall back to static members
1405 static ApplicationMembers *sApplicationMembers;
1406
1407 static QgsAuthManager *sAuthManager;
1408
1409 static ApplicationMembers *members();
1410
1411 static void invalidateCaches();
1412
1417 void installTranslators() SIP_SKIP;
1418
1419 QStringList mTemporarilyTrustedProjectFolders;
1420 QStringList mTemporarilyUntrustedProjectFolders;
1421
1423};
1424
1425// clazy:excludeall=qstring-allocations
1426
1427#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.
static const QgsSettingsEntryStringList * settingsProjectTemplatePaths
Settings entry search path for project templates.
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_DISALLOWNONE
Definition qgis_sip.h:133
#define SIP_SKIP
Definition qgis_sip.h:138
#define SIP_IF_FEATURE(feature)
Definition qgis_sip.h:193
#define SIP_END
Definition qgis_sip.h:220
QObject * ABISYM(QgsApplication::mFileOpenEventReceiver)