QGIS API Documentation 4.3.0-Master (01f22706ec5)
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() SIP_DISALLOWNONE;
751
758 Q_DECL_DEPRECATED static QgsSettingsRegistryCore *
759 settingsRegistryCore() SIP_KEEPREFERENCE SIP_DEPRECATED;
760
766 colorSchemeRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
767
773 paintEffectRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
774
779 static QgsRendererRegistry *
780 rendererRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
781
788 rasterRendererRegistry() SIP_DISALLOWNONE SIP_SKIP;
789
796 pointCloudRendererRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
797
804 tiledSceneRendererRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
805
811 dataItemProviderRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
812
820 coordinateReferenceSystemRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
821
828 static QgsSvgCache *svgCache() SIP_DISALLOWNONE;
829
837 static QgsImageCache *imageCache() SIP_DISALLOWNONE;
838
845 static QgsSourceCache *sourceCache() SIP_DISALLOWNONE;
846
853 networkContentFetcherRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
854
861 validityCheckRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
862
868 symbolLayerRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
869
875 static QgsCalloutRegistry *
876 calloutRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
877
881 static QgsLayoutItemRegistry *
882 layoutItemRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
883
890 annotationItemRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
891
897 gpsConnectionRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
898
905 gpsBabelFormatRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
906
912 pluginLayerRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
913
920 classificationMethodRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
921
927 static QgsBookmarkManager *bookmarkManager() SIP_DISALLOWNONE;
928
935 static QgsTileDownloadManager *tileDownloadManager() SIP_SKIP;
936
941 static QgsRecentStyleHandler *
942 recentStyleHandler() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
943
949 static QgsDatabaseQueryLog *
950 databaseQueryLog() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
951
961 static QgsStyleModel *defaultStyleModel() SIP_DISALLOWNONE;
962
970
976
982
986 static QgsMessageLog *messageLog();
987
993 static QgsAuthManager *authManager();
994
1000 authConfigurationStorageRegistry();
1001
1006 static QgsProcessingRegistry *processingRegistry() SIP_DISALLOWNONE;
1007
1012 static QgsPageSizeRegistry *
1013 pageSizeRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1014
1020 static QgsAnnotationRegistry *annotationRegistry() SIP_DISALLOWNONE SIP_SKIP;
1021
1028 applicationThemeRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1029
1034 static QgsActionScopeRegistry *
1035 actionScopeRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1036
1042 static QgsConnectionRegistry *connectionRegistry() SIP_DISALLOWNONE;
1043
1047 static QgsRuntimeProfiler *profiler() SIP_DISALLOWNONE;
1048
1055 numericFormatRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1056
1061 fieldFormatterRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1062
1066 static Qgs3DRendererRegistry *
1067 renderer3DRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1068
1073 static Qgs3DSymbolRegistry *
1074 symbol3DRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1075
1084 static QgsMaterialRegistry *
1085 materialRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1086
1093 scaleBarRendererRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1094
1101 labelingEngineRuleRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1102
1109 symbolConverterRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1110
1116 projectStorageRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1117
1123 layerMetadataProviderRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1124
1130 externalStorageRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1131
1137 profileSourceRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1138
1147 localizedDataPathRegistry() SIP_DISALLOWNONE SIP_KEEPREFERENCE;
1148
1160 static QString nullRepresentation();
1161
1173 static void setNullRepresentation(const QString &nullRepresentation);
1174
1182 static QVariantMap customVariables();
1183
1190 static void setCustomVariables(const QVariantMap &customVariables);
1191
1196 static void setCustomVariable(const QString &name, const QVariant &value);
1197
1204 static QStringList temporarilyTrustedProjectsFolders();
1205
1212 static void setTemporarilyTrustedProjectsFolders(
1213 const QStringList &trustedProjectsFolders);
1214
1221 static QStringList temporarilyUntrustedProjectsFolders();
1222
1229 static void setTemporarilyUntrustedProjectsFolders(
1230 const QStringList &untrustedProjectsFolders);
1231
1242 static int scaleIconSize(int standardSize,
1243 bool applyDevicePixelRatio = false);
1244
1253 int maxConcurrentConnectionsPerPool() const;
1254
1260 static void setTranslation(const QString &translation);
1261
1267 QString translation() const;
1268
1275 void collectTranslatableObjects(QgsTranslationContext *translationContext);
1276
1278
1279#ifndef SIP_RUN
1290
1295 static const QgsSettingsEntryInteger
1297#endif
1298
1299#ifdef SIP_RUN
1300 SIP_IF_FEATURE(ANDROID)
1301 // dummy method to workaround sip generation issue
1302 bool x11EventFilter(XEvent *event);
1303 SIP_END
1304#endif
1305
1306signals:
1308 void preNotify(QObject *receiver, QEvent *event, bool *done) SIP_SKIP;
1309
1314
1322
1332
1339
1346
1347private:
1348 static void copyPath(const QString &src, const QString &dst);
1349 static QObject *ABISYM(mFileOpenEventReceiver);
1350
1351 static bool ABISYM(mInitialized);
1352
1354 static bool ABISYM(mRunningFromBuildDir);
1355
1358 static int ABISYM(sMaxThreads);
1359
1360 QMap<QString, QIcon> mIconCache;
1361 QMap<Cursor, QCursor> mCursorCache;
1362
1363 std::unique_ptr<QTranslator> mQgisTranslator;
1364 std::unique_ptr<QTranslator> mQtTranslator;
1365 std::unique_ptr<QTranslator> mQtBaseTranslator;
1366
1367 std::unique_ptr<QgsDataItemProviderRegistry> mDataItemProviderRegistry;
1368 QgsAuthManager *mAuthManager = nullptr;
1369
1370 struct ApplicationMembers;
1371
1372 // Applications members which belong to an instance of QgsApplication
1373 std::unique_ptr<ApplicationMembers> mApplicationMembers;
1374 // ... but in case QgsApplication is never instantiated (eg with custom
1375 // designer widgets), we fall back to static members
1376 static ApplicationMembers *sApplicationMembers;
1377
1378 static QgsAuthManager *sAuthManager;
1379
1380 static ApplicationMembers *members();
1381
1382 static void invalidateCaches();
1383
1388 void installTranslators() SIP_SKIP;
1389
1390 QStringList mTemporarilyTrustedProjectFolders;
1391 QStringList mTemporarilyUntrustedProjectFolders;
1392
1394};
1395
1396// clazy:excludeall=qstring-allocations
1397
1398#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_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)