QGIS API Documentation 3.27.0-Master (75dc696944)
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;
43class QgsSvgCache;
44class QgsImageCache;
45class QgsSourceCache;
53class QgsMessageLog;
55class QgsAnnotationRegistry;
56class QgsUserProfile;
60class QgsAuthManager;
63class QTranslator;
66class QgsStyleModel;
76class QgsFontManager;
77
92class CORE_EXPORT QgsApplication : public QApplication
93{
94
95#ifdef SIP_RUN
96 % TypeCode
97 // Convert a Python argv list to a conventional C argc count and argv array.
98 static char **qtgui_ArgvToC( PyObject *argvlist, int &argc )
99 {
100 char **argv;
101
102 argc = PyList_GET_SIZE( argvlist );
103
104 // Allocate space for two copies of the argument pointers, plus the
105 // terminating NULL.
106 if ( ( argv = ( char ** )sipMalloc( 2 * ( argc + 1 ) * sizeof( char * ) ) ) == NULL )
107 return NULL;
108
109 // Convert the list.
110 for ( int a = 0; a < argc; ++a )
111 {
112 char *arg;
113 // Get the argument and allocate memory for it.
114 if ( ( arg = PyBytes_AsString( PyList_GET_ITEM( argvlist, a ) ) ) == NULL ||
115 ( argv[a] = ( char * )sipMalloc( strlen( arg ) + 1 ) ) == NULL )
116 return NULL;
117 // Copy the argument and save a pointer to it.
118 strcpy( argv[a], arg );
119 argv[a + argc + 1] = argv[a];
120 }
121
122 argv[argc + argc + 1] = argv[argc] = NULL;
123
124 return argv;
125 }
126
127 // Remove arguments from the Python argv list that have been removed from the
128 // C argv array.
129 static void qtgui_UpdatePyArgv( PyObject *argvlist, int argc, char **argv )
130 {
131 for ( int a = 0, na = 0; a < argc; ++a )
132 {
133 // See if it was removed.
134 if ( argv[na] == argv[a + argc + 1] )
135 ++na;
136 else
137 PyList_SetSlice( argvlist, na, na + 1, NULL );
138 }
139 }
140 % End
141#endif
142
143 Q_OBJECT
144
145 public:
146
156 {
159 };
160
161 static const char *QGIS_ORGANIZATION_NAME;
162 static const char *QGIS_ORGANIZATION_DOMAIN;
163 static const char *QGIS_APPLICATION_NAME;
164#ifndef SIP_RUN
165
175 QgsApplication( int &argc, char **argv, bool GUIenabled, const QString &profileFolder = QString(), const QString &platformName = "external" );
176#else
177
186 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" )];
187 % MethodCode
188 // The Python interface is a list of argument strings that is modified.
189
190 int argc;
191 char **argv;
192
193 // Convert the list.
194 if ( ( argv = qtgui_ArgvToC( a0, argc ) ) == NULL )
195 sipIsErr = 1;
196 else
197 {
198 // Create it now the arguments are right.
199 static int nargc = argc;
200
201 sipCpp = new sipQgsApplication( nargc, argv, a1, *a2, *a3 );
202
203 // Now modify the original list.
204 qtgui_UpdatePyArgv( a0, argc, argv );
205 }
206 % End
207#endif
208
209 ~QgsApplication() override;
210
216 static QgsApplication *instance();
217
225 static void init( QString profileFolder = QString() ) SIP_SKIP;
226
228 bool event( QEvent *event ) override;
229
231 bool notify( QObject *receiver, QEvent *event ) override;
232
234 static void setFileOpenEventReceiver( QObject *receiver );
235
246 static void setThemeName( const QString &themeName );
247
252 static QString resolvePkgPath();
253
261 static QString themeName();
262
270 static void setUITheme( const QString &themeName );
271
278 static QHash<QString, QString> uiThemes();
279
281 static QString authorsFilePath();
282
288 static QString contributorsFilePath();
289
296 static QString developersMapFilePath();
297
299 static QString sponsorsFilePath();
300
302 static QString donorsFilePath();
303
305 static QString serverResourcesPath();
306
310 static QString translatorsFilePath();
311
315 static QString licenceFilePath();
316
318 static QString i18nPath();
319
324 static QString metadataPath();
325
327 static QString qgisMasterDatabaseFilePath();
328
330 static QString qgisSettingsDirPath();
331
333 static QString qgisUserDatabaseFilePath();
334
336 static QString qgisAuthDatabaseFilePath();
337
339 static QString splashPath();
340
342 static QString iconsPath();
343
345 static QString srsDatabaseFilePath();
346
352 static void setSvgPaths( const QStringList &svgPaths );
353
355 static QStringList svgPaths();
356
361 static QStringList layoutTemplatePaths();
362
364 static QMap<QString, QString> systemEnvVars();
365
367 static QString prefixPath();
368
370 static QString pluginPath();
371
373 static QString pkgDataPath();
374
376 static QString activeThemePath();
377
379 static QString defaultThemePath();
380
385 static QString iconPath( const QString &iconFile );
386
394 static QIcon getThemeIcon( const QString &name, const QColor &fillColor = QColor(), const QColor &strokeColor = QColor() );
395
401 {
409 };
410
417 static QCursor getThemeCursor( Cursor cursor );
418
427 static QPixmap getThemePixmap( const QString &name, const QColor &foreColor = QColor(), const QColor &backColor = QColor(), int size = 16 );
428
430 static QString userStylePath();
431
437 static QRegularExpression shortNameRegularExpression();
438
444 static QString userLoginName();
445
451 static QString userFullName();
452
458 static QString osName();
459
467 static int systemMemorySizeMb();
468
474 static QString platform();
475
480 static QString locale();
481
488 static void setLocale( const QLocale &locale );
489
491 static QString userThemesFolder();
492
494 static QString defaultStylePath();
495
497 static QString defaultThemesFolder();
498
500 static QString libraryPath();
501
503 static QString libexecPath();
504
511 static QString qmlImportPath();
512
514 static void setPrefixPath( const QString &prefixPath, bool useDefaultPaths = false );
515
517 static void setPluginPath( const QString &pluginPath );
518
520 static void setPkgDataPath( const QString &pkgDataPath );
521
523 static void setDefaultSvgPaths( const QStringList &pathList );
524
526 static void setAuthDatabaseDirPath( const QString &authDbDirPath );
527
529 static void initQgis();
530
532 static bool createDatabase( QString *errorMessage = nullptr );
533
535 static bool createThemeFolder();
536
538 static void exitQgis();
539
541 static QString appIconPath();
542
545 {
546 XDR = 0, // network, or big-endian, byte order
547 NDR = 1 // little-endian byte order
548 };
549
551 static endian_t endian();
552
567 static QString reportStyleSheet( QgsApplication::StyleSheetType styleSheetType = QgsApplication::StyleSheetType::Qt );
568
573 static QString showSettings();
574
582 static void registerOgrDrivers();
583
585 static QString absolutePathToRelativePath( const QString &apath, const QString &targetPath );
587 static QString relativePathToAbsolutePath( const QString &rpath, const QString &targetPath );
588
590 static bool isRunningFromBuildDir() { return ABISYM( mRunningFromBuildDir ); }
591#if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
592 static QString cfgIntDir() SIP_SKIP;
593#endif
595 static QString buildSourcePath();
597 static QString buildOutputPath();
598
604 static void skipGdalDriver( const QString &driver );
605
611 static void restoreGdalDriver( const QString &driver );
612
617 static QStringList skippedGdalDrivers();
618
625 static void applyGdalSkippedDrivers();
626
631 static void registerGdalDriversFromSettings();
632
639 static QStringList deferredSkippedGdalDrivers();
640
647 static void setSkippedGdalDrivers( const QStringList &skippedGdalDrivers,
648 const QStringList &deferredSkippedGdalDrivers );
649
654 static int maxThreads();
655
661 static void setMaxThreads( int maxThreads );
662
668 static QgsTaskManager *taskManager();
669
674 static QgsSettingsRegistryCore *settingsRegistryCore() SIP_KEEPREFERENCE;
675
680 static QgsColorSchemeRegistry *colorSchemeRegistry() SIP_KEEPREFERENCE;
681
686 static QgsPaintEffectRegistry *paintEffectRegistry() SIP_KEEPREFERENCE;
687
692 static QgsRendererRegistry *rendererRegistry() SIP_KEEPREFERENCE;
693
699 static QgsRasterRendererRegistry *rasterRendererRegistry() SIP_SKIP;
700
705 static QgsPointCloudRendererRegistry *pointCloudRendererRegistry() SIP_KEEPREFERENCE;
706
712 static QgsDataItemProviderRegistry *dataItemProviderRegistry() SIP_KEEPREFERENCE;
713
720 static QgsCoordinateReferenceSystemRegistry *coordinateReferenceSystemRegistry() SIP_KEEPREFERENCE;
721
729 static QgsSvgCache *svgCache();
730
737 static QgsImageCache *imageCache();
738
744 static QgsSourceCache *sourceCache();
745
750 static QgsNetworkContentFetcherRegistry *networkContentFetcherRegistry() SIP_KEEPREFERENCE;
751
756 static QgsValidityCheckRegistry *validityCheckRegistry() SIP_KEEPREFERENCE;
757
762 static QgsSymbolLayerRegistry *symbolLayerRegistry() SIP_KEEPREFERENCE;
763
768 static QgsCalloutRegistry *calloutRegistry() SIP_KEEPREFERENCE;
769
774 static QgsLayoutItemRegistry *layoutItemRegistry() SIP_KEEPREFERENCE;
775
780 static QgsAnnotationItemRegistry *annotationItemRegistry() SIP_KEEPREFERENCE;
781
786 static QgsGpsConnectionRegistry *gpsConnectionRegistry() SIP_KEEPREFERENCE;
787
792 static QgsBabelFormatRegistry *gpsBabelFormatRegistry() SIP_KEEPREFERENCE;
793
798 static QgsPluginLayerRegistry *pluginLayerRegistry() SIP_KEEPREFERENCE;
799
804 static QgsClassificationMethodRegistry *classificationMethodRegistry() SIP_KEEPREFERENCE;
805
810 static QgsBookmarkManager *bookmarkManager();
811
817 static QgsTileDownloadManager *tileDownloadManager() SIP_SKIP;
818
823 static QgsRecentStyleHandler *recentStyleHandler() SIP_KEEPREFERENCE;
824
830 static QgsDatabaseQueryLog *databaseQueryLog() SIP_KEEPREFERENCE;
831
839 static QgsStyleModel *defaultStyleModel();
840
846 static QgsFontManager *fontManager() SIP_KEEPREFERENCE;
847
852 static QgsMessageLog *messageLog();
853
860 static QgsAuthManager *authManager();
861
867 static QgsProcessingRegistry *processingRegistry();
868
873 static QgsPageSizeRegistry *pageSizeRegistry() SIP_KEEPREFERENCE;
874
880 static QgsAnnotationRegistry *annotationRegistry() SIP_SKIP;
881
887 static QgsActionScopeRegistry *actionScopeRegistry() SIP_KEEPREFERENCE;
888
893 static QgsConnectionRegistry *connectionRegistry();
894
899 static QgsRuntimeProfiler *profiler();
900
906 static QgsNumericFormatRegistry *numericFormatRegistry() SIP_KEEPREFERENCE;
907
911 static QgsFieldFormatterRegistry *fieldFormatterRegistry() SIP_KEEPREFERENCE;
912
917 static Qgs3DRendererRegistry *renderer3DRegistry() SIP_KEEPREFERENCE;
918
923 static Qgs3DSymbolRegistry *symbol3DRegistry() SIP_KEEPREFERENCE;
924
930 static QgsScaleBarRendererRegistry *scaleBarRendererRegistry() SIP_KEEPREFERENCE;
931
936 static QgsProjectStorageRegistry *projectStorageRegistry() SIP_KEEPREFERENCE;
937
942 static QgsExternalStorageRegistry *externalStorageRegistry() SIP_KEEPREFERENCE;
943
951 static QgsLocalizedDataPathRegistry *localizedDataPathRegistry() SIP_KEEPREFERENCE;
952
961 static QString nullRepresentation();
962
966 static void setNullRepresentation( const QString &nullRepresentation );
967
975 static QVariantMap customVariables();
976
984 static void setCustomVariables( const QVariantMap &customVariables );
985
991 static void setCustomVariable( const QString &name, const QVariant &value );
992
1002 static int scaleIconSize( int standardSize, bool applyDevicePixelRatio = false );
1003
1012 int maxConcurrentConnectionsPerPool() const;
1013
1019 static void setTranslation( const QString &translation );
1020
1026 QString translation() const;
1027
1033 void collectTranslatableObjects( QgsTranslationContext *translationContext );
1034
1035#ifndef SIP_RUN
1037 static const inline QgsSettingsEntryString settingsLocaleUserLocale = QgsSettingsEntryString( QStringLiteral( "userLocale" ), QgsSettings::Prefix::LOCALE, QString() );
1039 static const inline QgsSettingsEntryBool settingsLocaleOverrideFlag = QgsSettingsEntryBool( QStringLiteral( "overrideFlag" ), QgsSettings::Prefix::LOCALE, false );
1041 static const inline QgsSettingsEntryString settingsLocaleGlobalLocale = QgsSettingsEntryString( QStringLiteral( "globalLocale" ), QgsSettings::Prefix::LOCALE, QString() );
1043 static const inline QgsSettingsEntryBool settingsLocaleShowGroupSeparator = QgsSettingsEntryBool( QStringLiteral( "showGroupSeparator" ), QgsSettings::Prefix::LOCALE, false );
1045 static const inline QgsSettingsEntryStringList settingsSearchPathsForSVG = QgsSettingsEntryStringList( QStringLiteral( "searchPathsForSVG" ), QgsSettings::Prefix::SVG, QStringList() );
1046#endif
1047
1048#ifdef SIP_RUN
1049 SIP_IF_FEATURE( ANDROID )
1050 //dummy method to workaround sip generation issue
1051 bool x11EventFilter( XEvent *event );
1052 SIP_END
1053#endif
1054
1055 signals:
1057 void preNotify( QObject *receiver, QEvent *event, bool *done ) SIP_SKIP;
1058
1064
1065
1070
1078
1079
1086
1087
1088 private:
1089
1090 static void copyPath( const QString &src, const QString &dst );
1091 static QObject *ABISYM( mFileOpenEventReceiver );
1092
1093 static bool ABISYM( mInitialized );
1094
1096 static bool ABISYM( mRunningFromBuildDir );
1097
1101 static int ABISYM( sMaxThreads );
1102
1103 QMap<QString, QIcon> mIconCache;
1104 QMap<Cursor, QCursor> mCursorCache;
1105
1106 QTranslator *mQgisTranslator = nullptr;
1107 QTranslator *mQtTranslator = nullptr;
1108 QTranslator *mQtBaseTranslator = nullptr;
1109
1110 QgsDataItemProviderRegistry *mDataItemProviderRegistry = nullptr;
1111 QgsAuthManager *mAuthManager = nullptr;
1112
1113 struct ApplicationMembers
1114 {
1115 QgsSettingsRegistryCore *mSettingsRegistryCore = nullptr;
1116 QgsCoordinateReferenceSystemRegistry *mCrsRegistry = nullptr;
1117 Qgs3DRendererRegistry *m3DRendererRegistry = nullptr;
1118 Qgs3DSymbolRegistry *m3DSymbolRegistry = nullptr;
1119 QgsActionScopeRegistry *mActionScopeRegistry = nullptr;
1120 QgsAnnotationRegistry *mAnnotationRegistry = nullptr;
1121 QgsColorSchemeRegistry *mColorSchemeRegistry = nullptr;
1122 QgsLocalizedDataPathRegistry *mLocalizedDataPathRegistry = nullptr;
1123 QgsNumericFormatRegistry *mNumericFormatRegistry = nullptr;
1124 QgsFieldFormatterRegistry *mFieldFormatterRegistry = nullptr;
1125 QgsGpsConnectionRegistry *mGpsConnectionRegistry = nullptr;
1126 QgsBabelFormatRegistry *mGpsBabelFormatRegistry = nullptr;
1127 QgsNetworkContentFetcherRegistry *mNetworkContentFetcherRegistry = nullptr;
1128 QgsScaleBarRendererRegistry *mScaleBarRendererRegistry = nullptr;
1129 QgsValidityCheckRegistry *mValidityCheckRegistry = nullptr;
1130 QgsMessageLog *mMessageLog = nullptr;
1131 QgsPaintEffectRegistry *mPaintEffectRegistry = nullptr;
1132 QgsPluginLayerRegistry *mPluginLayerRegistry = nullptr;
1133 QgsClassificationMethodRegistry *mClassificationMethodRegistry = nullptr;
1134 QgsProcessingRegistry *mProcessingRegistry = nullptr;
1135 QgsConnectionRegistry *mConnectionRegistry = nullptr;
1136 std::unique_ptr<QgsProjectStorageRegistry> mProjectStorageRegistry;
1137 QgsExternalStorageRegistry *mExternalStorageRegistry = nullptr;
1138 QgsPageSizeRegistry *mPageSizeRegistry = nullptr;
1139 QgsRasterRendererRegistry *mRasterRendererRegistry = nullptr;
1140 QgsRendererRegistry *mRendererRegistry = nullptr;
1141 QgsPointCloudRendererRegistry *mPointCloudRendererRegistry = nullptr;
1142 QgsSvgCache *mSvgCache = nullptr;
1143 QgsImageCache *mImageCache = nullptr;
1144 QgsSourceCache *mSourceCache = nullptr;
1145 QgsSymbolLayerRegistry *mSymbolLayerRegistry = nullptr;
1146 QgsCalloutRegistry *mCalloutRegistry = nullptr;
1147 QgsTaskManager *mTaskManager = nullptr;
1148 QgsLayoutItemRegistry *mLayoutItemRegistry = nullptr;
1149 QgsAnnotationItemRegistry *mAnnotationItemRegistry = nullptr;
1150 QgsUserProfileManager *mUserConfigManager = nullptr;
1151 QgsBookmarkManager *mBookmarkManager = nullptr;
1152 QgsTileDownloadManager *mTileDownloadManager = nullptr;
1153 QgsStyleModel *mStyleModel = nullptr;
1154 QgsRecentStyleHandler *mRecentStyleHandler = nullptr;
1155 QgsDatabaseQueryLog *mQueryLogger = nullptr;
1156 QgsFontManager *mFontManager;
1157 QString mNullRepresentation;
1158 QStringList mSvgPathCache;
1159 bool mSvgPathCacheValid = false;
1160
1161 ApplicationMembers();
1162 ~ApplicationMembers();
1163 };
1164
1165 // Applications members which belong to an instance of QgsApplication
1166 ApplicationMembers *mApplicationMembers = nullptr;
1167 // ... but in case QgsApplication is never instantiated (eg with custom designer widgets), we fall back to static members
1168 static ApplicationMembers *sApplicationMembers;
1169
1170 static QgsAuthManager *sAuthManager;
1171
1172 static ApplicationMembers *members();
1173
1174 static void invalidateCaches();
1175
1176 friend class TestQgsApplication;
1177};
1178
1179// clazy:excludeall=qstring-allocations
1180
1181#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.
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 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 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 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...
static const char * SVG
Definition: qgssettings.h:105
static const char * LOCALE
Definition: qgssettings.h:97
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_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)