QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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 "qgis_core.h"
19#include <QApplication>
20#include <QEvent>
21#include <QStringList>
22#include <QColor>
23
24#include <memory>
25#include "qgis_sip.h"
26#include "qgsconfig.h"
29
35class QgsTaskManager;
44class QgsSvgCache;
45class QgsImageCache;
46class QgsSourceCache;
54class QgsMessageLog;
56class QgsAnnotationRegistry;
57class QgsUserProfile;
61class QgsAuthManager;
64class QTranslator;
67class QgsStyleModel;
77class QgsFontManager;
78
93class CORE_EXPORT QgsApplication : public QApplication
94{
95
96#ifdef SIP_RUN
97 % TypeCode
98 // Convert a Python argv list to a conventional C argc count and argv array.
99 static char **qtgui_ArgvToC( PyObject *argvlist, int &argc )
100 {
101 char **argv;
102
103 argc = PyList_GET_SIZE( argvlist );
104
105 // Allocate space for two copies of the argument pointers, plus the
106 // terminating NULL.
107 if ( ( argv = ( char ** )sipMalloc( 2 * ( argc + 1 ) * sizeof( char * ) ) ) == NULL )
108 return NULL;
109
110 // Convert the list.
111 for ( int a = 0; a < argc; ++a )
112 {
113 char *arg;
114 // Get the argument and allocate memory for it.
115 if ( ( arg = PyBytes_AsString( PyList_GET_ITEM( argvlist, a ) ) ) == NULL ||
116 ( argv[a] = ( char * )sipMalloc( strlen( arg ) + 1 ) ) == NULL )
117 return NULL;
118 // Copy the argument and save a pointer to it.
119 strcpy( argv[a], arg );
120 argv[a + argc + 1] = argv[a];
121 }
122
123 argv[argc + argc + 1] = argv[argc] = NULL;
124
125 return argv;
126 }
127
128 // Remove arguments from the Python argv list that have been removed from the
129 // C argv array.
130 static void qtgui_UpdatePyArgv( PyObject *argvlist, int argc, char **argv )
131 {
132 for ( int a = 0, na = 0; a < argc; ++a )
133 {
134 // See if it was removed.
135 if ( argv[na] == argv[a + argc + 1] )
136 ++na;
137 else
138 PyList_SetSlice( argvlist, na, na + 1, NULL );
139 }
140 }
141 % End
142#endif
143
144 Q_OBJECT
145
146 public:
147
157 {
160 };
161
162 static const char *QGIS_ORGANIZATION_NAME;
163 static const char *QGIS_ORGANIZATION_DOMAIN;
164 static const char *QGIS_APPLICATION_NAME;
165#ifndef SIP_RUN
166
176 QgsApplication( int &argc, char **argv, bool GUIenabled, const QString &profileFolder = QString(), const QString &platformName = "external" );
177#else
178
187 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" )];
188 % MethodCode
189 // The Python interface is a list of argument strings that is modified.
190
191 int argc;
192 char **argv;
193
194 // Convert the list.
195 if ( ( argv = qtgui_ArgvToC( a0, argc ) ) == NULL )
196 sipIsErr = 1;
197 else
198 {
199 // Create it now the arguments are right.
200 static int nargc = argc;
201
202 sipCpp = new sipQgsApplication( nargc, argv, a1, *a2, *a3 );
203
204 // Now modify the original list.
205 qtgui_UpdatePyArgv( a0, argc, argv );
206 }
207 % End
208#endif
209
210 ~QgsApplication() override;
211
217 static QgsApplication *instance();
218
226 static void init( QString profileFolder = QString() ) SIP_SKIP;
227
229 bool event( QEvent *event ) override;
230
232 bool notify( QObject *receiver, QEvent *event ) override;
233
235 static void setFileOpenEventReceiver( QObject *receiver );
236
247 static void setThemeName( const QString &themeName );
248
253 static QString resolvePkgPath();
254
262 static QString themeName();
263
271 static void setUITheme( const QString &themeName );
272
279 static QHash<QString, QString> uiThemes();
280
282 static QString authorsFilePath();
283
289 static QString contributorsFilePath();
290
297 static QString developersMapFilePath();
298
300 static QString sponsorsFilePath();
301
303 static QString donorsFilePath();
304
306 static QString serverResourcesPath();
307
311 static QString translatorsFilePath();
312
316 static QString licenceFilePath();
317
319 static QString i18nPath();
320
325 static QString metadataPath();
326
328 static QString qgisMasterDatabaseFilePath();
329
331 static QString qgisSettingsDirPath();
332
334 static QString qgisUserDatabaseFilePath();
335
337 static QString qgisAuthDatabaseFilePath();
338
340 static QString splashPath();
341
343 static QString iconsPath();
344
346 static QString srsDatabaseFilePath();
347
353 static void setSvgPaths( const QStringList &svgPaths );
354
356 static QStringList svgPaths();
357
362 static QStringList layoutTemplatePaths();
363
365 static QMap<QString, QString> systemEnvVars();
366
368 static QString prefixPath();
369
371 static QString pluginPath();
372
374 static QString pkgDataPath();
375
377 static QString activeThemePath();
378
380 static QString defaultThemePath();
381
386 static QString iconPath( const QString &iconFile );
387
395 static QIcon getThemeIcon( const QString &name, const QColor &fillColor = QColor(), const QColor &strokeColor = QColor() );
396
402 {
410 };
411
418 static QCursor getThemeCursor( Cursor cursor );
419
428 static QPixmap getThemePixmap( const QString &name, const QColor &foreColor = QColor(), const QColor &backColor = QColor(), int size = 16 );
429
431 static QString userStylePath();
432
438 static QRegularExpression shortNameRegularExpression();
439
445 static QString userLoginName();
446
452 static QString userFullName();
453
459 static QString osName();
460
468 static int systemMemorySizeMb();
469
475 static QString platform();
476
477
489 static QString applicationFullName();
490
495 static QString locale();
496
503 static void setLocale( const QLocale &locale );
504
506 static QString userThemesFolder();
507
509 static QString defaultStylePath();
510
512 static QString defaultThemesFolder();
513
515 static QString libraryPath();
516
518 static QString libexecPath();
519
526 static QString qmlImportPath();
527
529 static void setPrefixPath( const QString &prefixPath, bool useDefaultPaths = false );
530
532 static void setPluginPath( const QString &pluginPath );
533
535 static void setPkgDataPath( const QString &pkgDataPath );
536
538 static void setDefaultSvgPaths( const QStringList &pathList );
539
541 static void setAuthDatabaseDirPath( const QString &authDbDirPath );
542
544 static void initQgis();
545
547 static bool createDatabase( QString *errorMessage = nullptr );
548
550 static bool createThemeFolder();
551
553 static void exitQgis();
554
556 static QString appIconPath();
557
560 {
561 XDR = 0, // network, or big-endian, byte order
562 NDR = 1 // little-endian byte order
563 };
564
566 static endian_t endian();
567
582 static QString reportStyleSheet( QgsApplication::StyleSheetType styleSheetType = QgsApplication::StyleSheetType::Qt );
583
588 static QString showSettings();
589
597 static void registerOgrDrivers();
598
600 static QString absolutePathToRelativePath( const QString &apath, const QString &targetPath );
602 static QString relativePathToAbsolutePath( const QString &rpath, const QString &targetPath );
603
605 static bool isRunningFromBuildDir() { return ABISYM( mRunningFromBuildDir ); }
606#if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
607 static QString cfgIntDir() SIP_SKIP;
608#endif
610 static QString buildSourcePath();
612 static QString buildOutputPath();
613
619 static void skipGdalDriver( const QString &driver );
620
626 static void restoreGdalDriver( const QString &driver );
627
632 static QStringList skippedGdalDrivers();
633
640 static void applyGdalSkippedDrivers();
641
646 static void registerGdalDriversFromSettings();
647
654 static QStringList deferredSkippedGdalDrivers();
655
662 static void setSkippedGdalDrivers( const QStringList &skippedGdalDrivers,
663 const QStringList &deferredSkippedGdalDrivers );
664
669 static int maxThreads();
670
676 static void setMaxThreads( int maxThreads );
677
683 static QgsTaskManager *taskManager();
684
690 Q_DECL_DEPRECATED static QgsSettingsRegistryCore *settingsRegistryCore() SIP_KEEPREFERENCE SIP_DEPRECATED;
691
696 static QgsColorSchemeRegistry *colorSchemeRegistry() SIP_KEEPREFERENCE;
697
702 static QgsPaintEffectRegistry *paintEffectRegistry() SIP_KEEPREFERENCE;
703
708 static QgsRendererRegistry *rendererRegistry() SIP_KEEPREFERENCE;
709
715 static QgsRasterRendererRegistry *rasterRendererRegistry() SIP_SKIP;
716
721 static QgsPointCloudRendererRegistry *pointCloudRendererRegistry() SIP_KEEPREFERENCE;
722
728 static QgsDataItemProviderRegistry *dataItemProviderRegistry() SIP_KEEPREFERENCE;
729
736 static QgsCoordinateReferenceSystemRegistry *coordinateReferenceSystemRegistry() SIP_KEEPREFERENCE;
737
745 static QgsSvgCache *svgCache();
746
753 static QgsImageCache *imageCache();
754
760 static QgsSourceCache *sourceCache();
761
766 static QgsNetworkContentFetcherRegistry *networkContentFetcherRegistry() SIP_KEEPREFERENCE;
767
772 static QgsValidityCheckRegistry *validityCheckRegistry() SIP_KEEPREFERENCE;
773
778 static QgsSymbolLayerRegistry *symbolLayerRegistry() SIP_KEEPREFERENCE;
779
784 static QgsCalloutRegistry *calloutRegistry() SIP_KEEPREFERENCE;
785
790 static QgsLayoutItemRegistry *layoutItemRegistry() SIP_KEEPREFERENCE;
791
796 static QgsAnnotationItemRegistry *annotationItemRegistry() SIP_KEEPREFERENCE;
797
802 static QgsGpsConnectionRegistry *gpsConnectionRegistry() SIP_KEEPREFERENCE;
803
808 static QgsBabelFormatRegistry *gpsBabelFormatRegistry() SIP_KEEPREFERENCE;
809
814 static QgsPluginLayerRegistry *pluginLayerRegistry() SIP_KEEPREFERENCE;
815
820 static QgsClassificationMethodRegistry *classificationMethodRegistry() SIP_KEEPREFERENCE;
821
826 static QgsBookmarkManager *bookmarkManager();
827
833 static QgsTileDownloadManager *tileDownloadManager() SIP_SKIP;
834
839 static QgsRecentStyleHandler *recentStyleHandler() SIP_KEEPREFERENCE;
840
846 static QgsDatabaseQueryLog *databaseQueryLog() SIP_KEEPREFERENCE;
847
855 static QgsStyleModel *defaultStyleModel();
856
862 static QgsFontManager *fontManager() SIP_KEEPREFERENCE;
863
868 static QgsMessageLog *messageLog();
869
876 static QgsAuthManager *authManager();
877
883 static QgsProcessingRegistry *processingRegistry();
884
889 static QgsPageSizeRegistry *pageSizeRegistry() SIP_KEEPREFERENCE;
890
896 static QgsAnnotationRegistry *annotationRegistry() SIP_SKIP;
897
903 static QgsActionScopeRegistry *actionScopeRegistry() SIP_KEEPREFERENCE;
904
909 static QgsConnectionRegistry *connectionRegistry();
910
915 static QgsRuntimeProfiler *profiler();
916
922 static QgsNumericFormatRegistry *numericFormatRegistry() SIP_KEEPREFERENCE;
923
927 static QgsFieldFormatterRegistry *fieldFormatterRegistry() SIP_KEEPREFERENCE;
928
933 static Qgs3DRendererRegistry *renderer3DRegistry() SIP_KEEPREFERENCE;
934
939 static Qgs3DSymbolRegistry *symbol3DRegistry() SIP_KEEPREFERENCE;
940
946 static QgsScaleBarRendererRegistry *scaleBarRendererRegistry() SIP_KEEPREFERENCE;
947
952 static QgsProjectStorageRegistry *projectStorageRegistry() SIP_KEEPREFERENCE;
953
958 static QgsLayerMetadataProviderRegistry *layerMetadataProviderRegistry() SIP_KEEPREFERENCE;
959
964 static QgsExternalStorageRegistry *externalStorageRegistry() SIP_KEEPREFERENCE;
965
973 static QgsLocalizedDataPathRegistry *localizedDataPathRegistry() SIP_KEEPREFERENCE;
974
983 static QString nullRepresentation();
984
988 static void setNullRepresentation( const QString &nullRepresentation );
989
997 static QVariantMap customVariables();
998
1006 static void setCustomVariables( const QVariantMap &customVariables );
1007
1013 static void setCustomVariable( const QString &name, const QVariant &value );
1014
1024 static int scaleIconSize( int standardSize, bool applyDevicePixelRatio = false );
1025
1034 int maxConcurrentConnectionsPerPool() const;
1035
1041 static void setTranslation( const QString &translation );
1042
1048 QString translation() const;
1049
1055 void collectTranslatableObjects( QgsTranslationContext *translationContext );
1056
1057
1058#ifndef SIP_RUN
1069#endif
1070
1071#ifdef SIP_RUN
1072 SIP_IF_FEATURE( ANDROID )
1073 //dummy method to workaround sip generation issue
1074 bool x11EventFilter( XEvent *event );
1075 SIP_END
1076#endif
1077
1078 signals:
1080 void preNotify( QObject *receiver, QEvent *event, bool *done ) SIP_SKIP;
1081
1087
1088
1093
1101
1102
1109
1110
1111 private:
1112
1113 static void copyPath( const QString &src, const QString &dst );
1114 static QObject *ABISYM( mFileOpenEventReceiver );
1115
1116 static bool ABISYM( mInitialized );
1117
1119 static bool ABISYM( mRunningFromBuildDir );
1120
1124 static int ABISYM( sMaxThreads );
1125
1126 QMap<QString, QIcon> mIconCache;
1127 QMap<Cursor, QCursor> mCursorCache;
1128
1129 QTranslator *mQgisTranslator = nullptr;
1130 QTranslator *mQtTranslator = nullptr;
1131 QTranslator *mQtBaseTranslator = nullptr;
1132
1133 QgsDataItemProviderRegistry *mDataItemProviderRegistry = nullptr;
1134 QgsAuthManager *mAuthManager = nullptr;
1135
1136 struct ApplicationMembers
1137 {
1138 QgsSettingsRegistryCore *mSettingsRegistryCore = nullptr;
1139 QgsCoordinateReferenceSystemRegistry *mCrsRegistry = nullptr;
1140 Qgs3DRendererRegistry *m3DRendererRegistry = nullptr;
1141 Qgs3DSymbolRegistry *m3DSymbolRegistry = nullptr;
1142 QgsActionScopeRegistry *mActionScopeRegistry = nullptr;
1143 QgsAnnotationRegistry *mAnnotationRegistry = nullptr;
1144 QgsColorSchemeRegistry *mColorSchemeRegistry = nullptr;
1145 QgsLocalizedDataPathRegistry *mLocalizedDataPathRegistry = nullptr;
1146 QgsNumericFormatRegistry *mNumericFormatRegistry = nullptr;
1147 QgsFieldFormatterRegistry *mFieldFormatterRegistry = nullptr;
1148 QgsGpsConnectionRegistry *mGpsConnectionRegistry = nullptr;
1149 QgsBabelFormatRegistry *mGpsBabelFormatRegistry = nullptr;
1150 QgsNetworkContentFetcherRegistry *mNetworkContentFetcherRegistry = nullptr;
1151 QgsScaleBarRendererRegistry *mScaleBarRendererRegistry = nullptr;
1152 QgsValidityCheckRegistry *mValidityCheckRegistry = nullptr;
1153 QgsMessageLog *mMessageLog = nullptr;
1154 QgsPaintEffectRegistry *mPaintEffectRegistry = nullptr;
1155 QgsPluginLayerRegistry *mPluginLayerRegistry = nullptr;
1156 QgsClassificationMethodRegistry *mClassificationMethodRegistry = nullptr;
1157 QgsProcessingRegistry *mProcessingRegistry = nullptr;
1158 QgsConnectionRegistry *mConnectionRegistry = nullptr;
1159 QgsProjectStorageRegistry *mProjectStorageRegistry = nullptr;
1160 QgsLayerMetadataProviderRegistry *mLayerMetadataProviderRegistry = nullptr;
1161 QgsExternalStorageRegistry *mExternalStorageRegistry = nullptr;
1162 QgsPageSizeRegistry *mPageSizeRegistry = nullptr;
1163 QgsRasterRendererRegistry *mRasterRendererRegistry = nullptr;
1164 QgsRendererRegistry *mRendererRegistry = nullptr;
1165 QgsPointCloudRendererRegistry *mPointCloudRendererRegistry = nullptr;
1166 QgsSvgCache *mSvgCache = nullptr;
1167 QgsImageCache *mImageCache = nullptr;
1168 QgsSourceCache *mSourceCache = nullptr;
1169 QgsSymbolLayerRegistry *mSymbolLayerRegistry = nullptr;
1170 QgsCalloutRegistry *mCalloutRegistry = nullptr;
1171 QgsTaskManager *mTaskManager = nullptr;
1172 QgsLayoutItemRegistry *mLayoutItemRegistry = nullptr;
1173 QgsAnnotationItemRegistry *mAnnotationItemRegistry = nullptr;
1174 QgsUserProfileManager *mUserConfigManager = nullptr;
1175 QgsBookmarkManager *mBookmarkManager = nullptr;
1176 QgsTileDownloadManager *mTileDownloadManager = nullptr;
1177 QgsStyleModel *mStyleModel = nullptr;
1178 QgsRecentStyleHandler *mRecentStyleHandler = nullptr;
1179 QgsDatabaseQueryLog *mQueryLogger = nullptr;
1180 QgsFontManager *mFontManager;
1181 QString mNullRepresentation;
1182 QStringList mSvgPathCache;
1183 bool mSvgPathCacheValid = false;
1184
1185 ApplicationMembers();
1186 ~ApplicationMembers();
1187 };
1188
1189 // Applications members which belong to an instance of QgsApplication
1190 ApplicationMembers *mApplicationMembers = nullptr;
1191 // ... but in case QgsApplication is never instantiated (eg with custom designer widgets), we fall back to static members
1192 static ApplicationMembers *sApplicationMembers;
1193
1194 static QgsAuthManager *sAuthManager;
1195
1196 static ApplicationMembers *members();
1197
1198 static void invalidateCaches();
1199
1200 friend class TestQgsApplication;
1201};
1202
1203// clazy:excludeall=qstring-allocations
1204
1205#endif
Keeps track of 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.
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.
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.
@ WebBrowser
StyleSheet for Qt GUI widgets (based on QLabel or QTextBrowser), supports basic CSS and Qt extensions...
static const QgsSettingsEntryString * settingsLocaleGlobalLocale
Settings entry locale global locale.
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
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.
@ ZoomIn
Zoom in.
void requestForTranslatableObjects(QgsTranslationContext *translationContext)
Emitted when project strings which require translation are being collected for inclusion in a ....
void nullRepresentationChanged()
This string is used to represent the value NULL throughout QGIS.
static const QgsSettingsEntryBool * settingsLocaleShowGroupSeparator
Settings entry locale show group separator.
static bool isRunningFromBuildDir()
Indicates whether running from build directory (not installed)
Singleton offering an interface to manage the authentication configuration database and to utilize co...
A registry for QgsAbstractBabelFormat GPSBabel formats.
Manages storage of a set of bookmarks.
Registry of available callout classes.
This class 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.
This class keeps a list of data item providers that may add items to the browser tree.
Handles logging of database queries.
Registry of external storage backends used by QgsExternalResourceWidget.
The QgsFieldFormatterRegistry manages registered classes of QgsFieldFormatter.
Manages available fonts and font installation for a QGIS instance.
A class to register / unregister existing GPS connections such that the information is available to a...
A cache for images derived from raster files.
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.
Definition: qgsmessagelog.h:40
Registry for temporary fetched files.
The QgsNumericFormatRegistry manages registered classes of QgsNumericFormat.
A registry for known page sizes.
Registry of available paint effects.
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 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...
The QgsScaleBarRendererRegistry manages registered scalebar renderers.
A boolean settings entry.
A string list settings entry.
A string settings entry.
QgsSettingsRegistryCore is used for settings introspection and collects all QgsSettingsEntry instance...
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.
Definition: qgssvgcache.h:123
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.
Used for the collecting of strings from projects for translation and creation of ts files.
User profile manager is used to manager list, and manage user profiles on the users machine.
User profile contains information about the user profile folders on the machine.
This class keeps a list of QgsAbstractValidityCheck checks which can be used when performing validity...
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly,...
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
#define SIP_KEEPREFERENCE
Definition: qgis_sip.h:86
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_IF_FEATURE(feature)
Definition: qgis_sip.h:176
#define SIP_END
Definition: qgis_sip.h:203
QObject * ABISYM(QgsApplication::mFileOpenEventReceiver)