QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
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 "qgsconfig.h"
19
20#include <memory>
21
22#include "qgis_core.h"
23#include "qgis_sip.h"
26
27#include <QApplication>
28#include <QColor>
29#include <QEvent>
30#include <QStringList>
31
38class QgsTaskManager;
47class QgsSvgCache;
48class QgsImageCache;
49class QgsSourceCache;
57class QgsMessageLog;
59class QgsAnnotationRegistry;
60class QgsUserProfile;
63class QgsAuthManager;
66class QTranslator;
68class QgsPlotRegistry;
70class QgsStyleModel;
81class QgsFontManager;
85
100class CORE_EXPORT QgsApplication : public QApplication
101{
102
103#ifdef SIP_RUN
104 % TypeCode
105 // Convert a Python argv list to a conventional C argc count and argv array.
106 static char **qtgui_ArgvToC( PyObject *argvlist, int &argc )
107 {
108 char **argv;
109
110 argc = PyList_GET_SIZE( argvlist );
111
112 // Allocate space for two copies of the argument pointers, plus the
113 // terminating NULL.
114 if ( ( argv = ( char ** )sipMalloc( 2 * ( argc + 1 ) * sizeof( char * ) ) ) == NULL )
115 return NULL;
116
117 // Convert the list.
118 for ( int a = 0; a < argc; ++a )
119 {
120 char *arg;
121 // Get the argument and allocate memory for it.
122 if ( ( arg = PyBytes_AsString( PyList_GET_ITEM( argvlist, a ) ) ) == NULL ||
123 ( argv[a] = ( char * )sipMalloc( strlen( arg ) + 1 ) ) == NULL )
124 return NULL;
125 // Copy the argument and save a pointer to it.
126 strcpy( argv[a], arg );
127 argv[a + argc + 1] = argv[a];
128 }
129
130 argv[argc + argc + 1] = argv[argc] = NULL;
131
132 return argv;
133 }
134
135 // Remove arguments from the Python argv list that have been removed from the
136 // C argv array.
137 static void qtgui_UpdatePyArgv( PyObject *argvlist, int argc, char **argv )
138 {
139 for ( int a = 0, na = 0; a < argc; ++a )
140 {
141 // See if it was removed.
142 if ( argv[na] == argv[a + argc + 1] )
143 ++na;
144 else
145 PyList_SetSlice( argvlist, na, na + 1, NULL );
146 }
147 }
148 % End
149#endif
150
151 Q_OBJECT
152
153 public:
154
168
169 static const char *QGIS_ORGANIZATION_NAME;
170 static const char *QGIS_ORGANIZATION_DOMAIN;
171 static const char *QGIS_APPLICATION_NAME;
172#ifndef SIP_RUN
173
183 QgsApplication( int &argc, char **argv, bool GUIenabled, const QString &profileFolder = QString(), const QString &platformName = "external" );
184#else
185
194 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" )];
195 % MethodCode
196 // The Python interface is a list of argument strings that is modified.
197
198 int argc;
199 char **argv;
200
201 // Convert the list.
202 if ( ( argv = qtgui_ArgvToC( a0, argc ) ) == NULL )
203 sipIsErr = 1;
204 else
205 {
206 // Create it now the arguments are right.
207 static int nargc = argc;
208
209 sipCpp = new sipQgsApplication( nargc, argv, a1, *a2, *a3 );
210
211 // Now modify the original list.
212 qtgui_UpdatePyArgv( a0, argc, argv );
213 }
214 % End
215#endif
216
217 ~QgsApplication() override;
218
223 static QgsApplication *instance();
224
232 static void init( QString profileFolder = QString() ) SIP_SKIP;
233
235 bool event( QEvent *event ) override;
236
238 bool notify( QObject *receiver, QEvent *event ) override;
239
241 static void setFileOpenEventReceiver( QObject *receiver );
242
253 static void setThemeName( const QString &themeName );
254
259 static QString resolvePkgPath();
260
268 static QString themeName();
269
277 static void setUITheme( const QString &themeName );
278
285 static QHash<QString, QString> uiThemes();
286
288 static QString authorsFilePath();
289
295 static QString contributorsFilePath();
296
298 static QString sponsorsFilePath();
299
301 static QString donorsFilePath();
302
304 static QString serverResourcesPath();
305
309 static QString translatorsFilePath();
310
314 static QString licenceFilePath();
315
317 static QString i18nPath();
318
322 static QString metadataPath();
323
325 static QString qgisMasterDatabaseFilePath();
326
328 static QString qgisSettingsDirPath();
329
331 static QString qgisUserDatabaseFilePath();
332
337 Q_DECL_DEPRECATED static QString qgisAuthDatabaseFilePath() SIP_DEPRECATED;
338
346 static QString qgisAuthDatabaseUri();
347
349 static QString splashPath();
350
352 static QString iconsPath();
353
355 static QString srsDatabaseFilePath();
356
362 static void setSvgPaths( const QStringList &svgPaths );
363
365 static QStringList svgPaths();
366
370 static QStringList layoutTemplatePaths();
371
373 static QMap<QString, QString> systemEnvVars();
374
376 static QString prefixPath();
377
379 static QString pluginPath();
380
382 static QString pkgDataPath();
383
385 static QString activeThemePath();
386
388 static QString defaultThemePath();
389
394 static QString iconPath( const QString &iconFile );
395
403 static QIcon getThemeIcon( const QString &name, const QColor &fillColor = QColor(), const QColor &strokeColor = QColor() );
404
419
426 static QCursor getThemeCursor( Cursor cursor );
427
436 static QPixmap getThemePixmap( const QString &name, const QColor &foreColor = QColor(), const QColor &backColor = QColor(), int size = 16 );
437
439 static QString userStylePath();
440
446 static QRegularExpression shortNameRegularExpression();
447
452 static QString userLoginName();
453
458 static QString userFullName();
459
464 static QString osName();
465
473 static int systemMemorySizeMb();
474
479 static QString platform();
480
481
493 static QString applicationFullName();
494
498 static QString locale();
499
506 static void setLocale( const QLocale &locale );
507
509 static QString userThemesFolder();
510
512 static QString defaultStylePath();
513
515 static QString defaultThemesFolder();
516
518 static QString libraryPath();
519
521 static QString libexecPath();
522
529 static QString qmlImportPath();
530
532 static void setPrefixPath( const QString &prefixPath, bool useDefaultPaths = false );
533
535 static void setPluginPath( const QString &pluginPath );
536
538 static void setPkgDataPath( const QString &pkgDataPath );
539
541 static void setDefaultSvgPaths( const QStringList &pathList );
542
544 static void setAuthDatabaseDirPath( const QString &authDbDirPath );
545
547 static void initQgis();
548
550 static bool createDatabase( QString *errorMessage = nullptr );
551
553 static bool createThemeFolder();
554
556 static void exitQgis();
557
559 static QString appIconPath();
560
563 {
564 XDR = 0, // network, or big-endian, byte order
565 NDR = 1 // little-endian byte order
566 };
567
569 static endian_t endian();
570
589 static QString reportStyleSheet( QgsApplication::StyleSheetType styleSheetType = QgsApplication::StyleSheetType::Qt );
590
595 static QString showSettings();
596
604 static void registerOgrDrivers();
605
607 static QString absolutePathToRelativePath( const QString &apath, const QString &targetPath );
609 static QString relativePathToAbsolutePath( const QString &rpath, const QString &targetPath );
610
612 static bool isRunningFromBuildDir() { return ABISYM( mRunningFromBuildDir ); }
613#if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
614 static QString cfgIntDir() SIP_SKIP;
615#endif
617 static QString buildSourcePath();
619 static QString buildOutputPath();
620
626 static void skipGdalDriver( const QString &driver );
627
633 static void restoreGdalDriver( const QString &driver );
634
639 static QStringList skippedGdalDrivers();
640
647 static void applyGdalSkippedDrivers();
648
653 static void registerGdalDriversFromSettings();
654
661 static QStringList deferredSkippedGdalDrivers();
662
669 static void setSkippedGdalDrivers( const QStringList &skippedGdalDrivers,
670 const QStringList &deferredSkippedGdalDrivers );
671
675 static int maxThreads();
676
681 static void setMaxThreads( int maxThreads );
682
687 static QgsTaskManager *taskManager();
688
694 Q_DECL_DEPRECATED static QgsSettingsRegistryCore *settingsRegistryCore() SIP_KEEPREFERENCE SIP_DEPRECATED;
695
699 static QgsColorSchemeRegistry *colorSchemeRegistry() SIP_KEEPREFERENCE;
700
704 static QgsPaintEffectRegistry *paintEffectRegistry() SIP_KEEPREFERENCE;
705
709 static QgsRendererRegistry *rendererRegistry() SIP_KEEPREFERENCE;
710
715 static QgsRasterRendererRegistry *rasterRendererRegistry() SIP_SKIP;
716
721 static QgsPointCloudRendererRegistry *pointCloudRendererRegistry() SIP_KEEPREFERENCE;
722
727 static QgsTiledSceneRendererRegistry *tiledSceneRendererRegistry() SIP_KEEPREFERENCE;
728
733 static QgsDataItemProviderRegistry *dataItemProviderRegistry() SIP_KEEPREFERENCE;
734
741 static QgsCoordinateReferenceSystemRegistry *coordinateReferenceSystemRegistry() SIP_KEEPREFERENCE;
742
749 static QgsSvgCache *svgCache();
750
757 static QgsImageCache *imageCache();
758
764 static QgsSourceCache *sourceCache();
765
770 static QgsNetworkContentFetcherRegistry *networkContentFetcherRegistry() SIP_KEEPREFERENCE;
771
776 static QgsValidityCheckRegistry *validityCheckRegistry() SIP_KEEPREFERENCE;
777
781 static QgsSymbolLayerRegistry *symbolLayerRegistry() SIP_KEEPREFERENCE;
782
787 static QgsCalloutRegistry *calloutRegistry() SIP_KEEPREFERENCE;
788
792 static QgsLayoutItemRegistry *layoutItemRegistry() SIP_KEEPREFERENCE;
793
798 static QgsAnnotationItemRegistry *annotationItemRegistry() SIP_KEEPREFERENCE;
799
803 static QgsGpsConnectionRegistry *gpsConnectionRegistry() SIP_KEEPREFERENCE;
804
809 static QgsBabelFormatRegistry *gpsBabelFormatRegistry() SIP_KEEPREFERENCE;
810
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 QgsSensorRegistry *sensorRegistry() SIP_KEEPREFERENCE;
869
874 static QgsPlotRegistry *plotRegistry() SIP_KEEPREFERENCE;
875
879 static QgsMessageLog *messageLog();
880
886 static QgsAuthManager *authManager();
887
892 static QgsAuthConfigurationStorageRegistry *authConfigurationStorageRegistry();
893
898 static QgsProcessingRegistry *processingRegistry();
899
903 static QgsPageSizeRegistry *pageSizeRegistry() SIP_KEEPREFERENCE;
904
909 static QgsAnnotationRegistry *annotationRegistry() SIP_SKIP;
910
915 static QgsActionScopeRegistry *actionScopeRegistry() SIP_KEEPREFERENCE;
916
921 static QgsConnectionRegistry *connectionRegistry();
922
926 static QgsRuntimeProfiler *profiler();
927
933 static QgsNumericFormatRegistry *numericFormatRegistry() SIP_KEEPREFERENCE;
934
938 static QgsFieldFormatterRegistry *fieldFormatterRegistry() SIP_KEEPREFERENCE;
939
943 static Qgs3DRendererRegistry *renderer3DRegistry() SIP_KEEPREFERENCE;
944
949 static Qgs3DSymbolRegistry *symbol3DRegistry() SIP_KEEPREFERENCE;
950
956 static QgsScaleBarRendererRegistry *scaleBarRendererRegistry() SIP_KEEPREFERENCE;
957
963 static QgsLabelingEngineRuleRegistry *labelingEngineRuleRegistry() SIP_KEEPREFERENCE;
964
969 static QgsProjectStorageRegistry *projectStorageRegistry() SIP_KEEPREFERENCE;
970
975 static QgsLayerMetadataProviderRegistry *layerMetadataProviderRegistry() SIP_KEEPREFERENCE;
976
981 static QgsExternalStorageRegistry *externalStorageRegistry() SIP_KEEPREFERENCE;
982
987 static QgsProfileSourceRegistry *profileSourceRegistry() SIP_KEEPREFERENCE;
988
996 static QgsLocalizedDataPathRegistry *localizedDataPathRegistry() SIP_KEEPREFERENCE;
997
1008 static QString nullRepresentation();
1009
1020 static void setNullRepresentation( const QString &nullRepresentation );
1021
1028 static QVariantMap customVariables();
1029
1036 static void setCustomVariables( const QVariantMap &customVariables );
1037
1042 static void setCustomVariable( const QString &name, const QVariant &value );
1043
1049 static QStringList temporarilyTrustedProjectsFolders();
1050
1056 static void setTemporarilyTrustedProjectsFolders( const QStringList &trustedProjectsFolders );
1057
1063 static QStringList temporarilyUntrustedProjectsFolders();
1064
1070 static void setTemporarilyUntrustedProjectsFolders( const QStringList &untrustedProjectsFolders );
1071
1081 static int scaleIconSize( int standardSize, bool applyDevicePixelRatio = false );
1082
1091 int maxConcurrentConnectionsPerPool() const;
1092
1098 static void setTranslation( const QString &translation );
1099
1105 QString translation() const;
1106
1112 void collectTranslatableObjects( QgsTranslationContext *translationContext );
1113
1114
1115#ifndef SIP_RUN
1128#endif
1129
1130#ifdef SIP_RUN
1131 SIP_IF_FEATURE( ANDROID )
1132 //dummy method to workaround sip generation issue
1133 bool x11EventFilter( XEvent *event );
1134 SIP_END
1135#endif
1136
1137 signals:
1139 void preNotify( QObject *receiver, QEvent *event, bool *done ) SIP_SKIP;
1140
1145
1153
1161
1162
1169
1170
1171 private:
1172
1173 static void copyPath( const QString &src, const QString &dst );
1174 static QObject *ABISYM( mFileOpenEventReceiver );
1175
1176 static bool ABISYM( mInitialized );
1177
1179 static bool ABISYM( mRunningFromBuildDir );
1180
1183 static int ABISYM( sMaxThreads );
1184
1185 QMap<QString, QIcon> mIconCache;
1186 QMap<Cursor, QCursor> mCursorCache;
1187
1188 std::unique_ptr<QTranslator> mQgisTranslator;
1189 std::unique_ptr<QTranslator> mQtTranslator;
1190 std::unique_ptr<QTranslator> mQtBaseTranslator;
1191
1192 std::unique_ptr<QgsDataItemProviderRegistry> mDataItemProviderRegistry;
1193 QgsAuthManager *mAuthManager = nullptr;
1194
1195 struct ApplicationMembers;
1196
1197 // Applications members which belong to an instance of QgsApplication
1198 std::unique_ptr<ApplicationMembers> mApplicationMembers;
1199 // ... but in case QgsApplication is never instantiated (eg with custom designer widgets), we fall back to static members
1200 static ApplicationMembers *sApplicationMembers;
1201
1202 static QgsAuthManager *sAuthManager;
1203
1204 static ApplicationMembers *members();
1205
1206 static void invalidateCaches();
1207
1212 void installTranslators() SIP_SKIP;
1213
1214 QStringList mTemporarilyTrustedProjectFolders;
1215 QStringList mTemporarilyUntrustedProjectFolders;
1216
1218};
1219
1220// clazy:excludeall=qstring-allocations
1221
1222#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.
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.
friend class TestQgsApplication
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.
@ 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
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).
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,...
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.
Used for settings introspection and collects all QgsSettingsEntry instances of core.
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.
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:114
#define SIP_KEEPREFERENCE
Definition qgis_sip.h:94
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_IF_FEATURE(feature)
Definition qgis_sip.h:189
#define SIP_END
Definition qgis_sip.h:216
QObject * ABISYM(QgsApplication::mFileOpenEventReceiver)