QGIS API Documentation 3.99.0-Master (a8882ad4560)
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;
61class QgsUserProfile;
64class QgsAuthManager;
67class QTranslator;
69class QgsPlotRegistry;
71class QgsStyleModel;
82class QgsFontManager;
86
101class CORE_EXPORT QgsApplication : public QApplication
102{
103
104#ifdef SIP_RUN
105 % TypeCode
106 // Convert a Python argv list to a conventional C argc count and argv array.
107 static char **qtgui_ArgvToC( PyObject *argvlist, int &argc )
108 {
109 char **argv;
110
111 argc = PyList_GET_SIZE( argvlist );
112
113 // Allocate space for two copies of the argument pointers, plus the
114 // terminating NULL.
115 if ( ( argv = ( char ** )sipMalloc( 2 * ( argc + 1 ) * sizeof( char * ) ) ) == NULL )
116 return NULL;
117
118 // Convert the list.
119 for ( int a = 0; a < argc; ++a )
120 {
121 char *arg;
122 // Get the argument and allocate memory for it.
123 if ( ( arg = PyBytes_AsString( PyList_GET_ITEM( argvlist, a ) ) ) == NULL ||
124 ( argv[a] = ( char * )sipMalloc( strlen( arg ) + 1 ) ) == NULL )
125 return NULL;
126 // Copy the argument and save a pointer to it.
127 strcpy( argv[a], arg );
128 argv[a + argc + 1] = argv[a];
129 }
130
131 argv[argc + argc + 1] = argv[argc] = NULL;
132
133 return argv;
134 }
135
136 // Remove arguments from the Python argv list that have been removed from the
137 // C argv array.
138 static void qtgui_UpdatePyArgv( PyObject *argvlist, int argc, char **argv )
139 {
140 for ( int a = 0, na = 0; a < argc; ++a )
141 {
142 // See if it was removed.
143 if ( argv[na] == argv[a + argc + 1] )
144 ++na;
145 else
146 PyList_SetSlice( argvlist, na, na + 1, NULL );
147 }
148 }
149 % End
150#endif
151
152 Q_OBJECT
153
154 public:
155
169
170 static const char *QGIS_ORGANIZATION_NAME;
171 static const char *QGIS_ORGANIZATION_DOMAIN;
172 static const char *QGIS_APPLICATION_NAME;
173#ifndef SIP_RUN
174
184 QgsApplication( int &argc, char **argv, bool GUIenabled, const QString &profileFolder = QString(), const QString &platformName = "external" );
185#else
186
195 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" )];
196 % MethodCode
197 // The Python interface is a list of argument strings that is modified.
198
199 int argc;
200 char **argv;
201
202 // Convert the list.
203 if ( ( argv = qtgui_ArgvToC( a0, argc ) ) == NULL )
204 sipIsErr = 1;
205 else
206 {
207 // Create it now the arguments are right.
208 static int nargc = argc;
209
210 sipCpp = new sipQgsApplication( nargc, argv, a1, *a2, *a3 );
211
212 // Now modify the original list.
213 qtgui_UpdatePyArgv( a0, argc, argv );
214 }
215 % End
216#endif
217
218 ~QgsApplication() override;
219
224 static QgsApplication *instance();
225
233 static void init( QString profileFolder = QString() ) SIP_SKIP;
234
236 bool event( QEvent *event ) override;
237
239 bool notify( QObject *receiver, QEvent *event ) override;
240
242 static void setFileOpenEventReceiver( QObject *receiver );
243
254 static void setThemeName( const QString &themeName );
255
260 static QString resolvePkgPath();
261
269 static QString themeName();
270
278 static void setUITheme( const QString &themeName );
279
286 static QHash<QString, QString> uiThemes();
287
289 static QString authorsFilePath();
290
296 static QString contributorsFilePath();
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
323 static QString metadataPath();
324
326 static QString qgisMasterDatabaseFilePath();
327
329 static QString qgisSettingsDirPath();
330
332 static QString qgisUserDatabaseFilePath();
333
338 Q_DECL_DEPRECATED static QString qgisAuthDatabaseFilePath() SIP_DEPRECATED;
339
347 static QString qgisAuthDatabaseUri();
348
350 static QString splashPath();
351
353 static QString iconsPath();
354
356 static QString srsDatabaseFilePath();
357
363 static void setSvgPaths( const QStringList &svgPaths );
364
366 static QStringList svgPaths();
367
371 static QStringList layoutTemplatePaths();
372
374 static QMap<QString, QString> systemEnvVars();
375
377 static QString prefixPath();
378
380 static QString pluginPath();
381
383 static QString pkgDataPath();
384
386 static QString activeThemePath();
387
389 static QString defaultThemePath();
390
395 static QString iconPath( const QString &iconFile );
396
404 static QIcon getThemeIcon( const QString &name, const QColor &fillColor = QColor(), const QColor &strokeColor = QColor() );
405
420
427 static QCursor getThemeCursor( Cursor cursor );
428
437 static QPixmap getThemePixmap( const QString &name, const QColor &foreColor = QColor(), const QColor &backColor = QColor(), int size = 16 );
438
440 static QString userStylePath();
441
447 static QRegularExpression shortNameRegularExpression();
448
453 static QString userLoginName();
454
459 static QString userFullName();
460
465 static QString osName();
466
474 static int systemMemorySizeMb();
475
480 static QString platform();
481
482
494 static QString applicationFullName();
495
499 static QString locale();
500
507 static void setLocale( const QLocale &locale );
508
510 static QString userThemesFolder();
511
513 static QString defaultStylePath();
514
516 static QString defaultThemesFolder();
517
519 static QString libraryPath();
520
522 static QString libexecPath();
523
530 static QString qmlImportPath();
531
533 static void setPrefixPath( const QString &prefixPath, bool useDefaultPaths = false );
534
536 static void setPluginPath( const QString &pluginPath );
537
539 static void setPkgDataPath( const QString &pkgDataPath );
540
542 static void setDefaultSvgPaths( const QStringList &pathList );
543
545 static void setAuthDatabaseDirPath( const QString &authDbDirPath );
546
548 static void initQgis();
549
551 static bool createDatabase( QString *errorMessage = nullptr );
552
554 static bool createThemeFolder();
555
557 static void exitQgis();
558
560 static QString appIconPath();
561
564 {
565 XDR = 0, // network, or big-endian, byte order
566 NDR = 1 // little-endian byte order
567 };
568
570 static endian_t endian();
571
590 static QString reportStyleSheet( QgsApplication::StyleSheetType styleSheetType = QgsApplication::StyleSheetType::Qt );
591
596 static QString showSettings();
597
605 static void registerOgrDrivers();
606
608 static QString absolutePathToRelativePath( const QString &apath, const QString &targetPath );
610 static QString relativePathToAbsolutePath( const QString &rpath, const QString &targetPath );
611
613 static bool isRunningFromBuildDir() { return ABISYM( mRunningFromBuildDir ); }
614#if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
615 static QString cfgIntDir() SIP_SKIP;
616#endif
618 static QString buildSourcePath();
620 static QString buildOutputPath();
621
627 static void skipGdalDriver( const QString &driver );
628
634 static void restoreGdalDriver( const QString &driver );
635
640 static QStringList skippedGdalDrivers();
641
648 static void applyGdalSkippedDrivers();
649
654 static void registerGdalDriversFromSettings();
655
662 static QStringList deferredSkippedGdalDrivers();
663
670 static void setSkippedGdalDrivers( const QStringList &skippedGdalDrivers,
671 const QStringList &deferredSkippedGdalDrivers );
672
676 static int maxThreads();
677
682 static void setMaxThreads( int maxThreads );
683
688 static QgsTaskManager *taskManager();
689
695 Q_DECL_DEPRECATED static QgsSettingsRegistryCore *settingsRegistryCore() SIP_KEEPREFERENCE SIP_DEPRECATED;
696
700 static QgsColorSchemeRegistry *colorSchemeRegistry() SIP_KEEPREFERENCE;
701
705 static QgsPaintEffectRegistry *paintEffectRegistry() SIP_KEEPREFERENCE;
706
710 static QgsRendererRegistry *rendererRegistry() SIP_KEEPREFERENCE;
711
716 static QgsRasterRendererRegistry *rasterRendererRegistry() SIP_SKIP;
717
722 static QgsPointCloudRendererRegistry *pointCloudRendererRegistry() SIP_KEEPREFERENCE;
723
728 static QgsTiledSceneRendererRegistry *tiledSceneRendererRegistry() SIP_KEEPREFERENCE;
729
734 static QgsDataItemProviderRegistry *dataItemProviderRegistry() SIP_KEEPREFERENCE;
735
742 static QgsCoordinateReferenceSystemRegistry *coordinateReferenceSystemRegistry() SIP_KEEPREFERENCE;
743
750 static QgsSvgCache *svgCache();
751
758 static QgsImageCache *imageCache();
759
765 static QgsSourceCache *sourceCache();
766
771 static QgsNetworkContentFetcherRegistry *networkContentFetcherRegistry() SIP_KEEPREFERENCE;
772
777 static QgsValidityCheckRegistry *validityCheckRegistry() SIP_KEEPREFERENCE;
778
782 static QgsSymbolLayerRegistry *symbolLayerRegistry() SIP_KEEPREFERENCE;
783
788 static QgsCalloutRegistry *calloutRegistry() SIP_KEEPREFERENCE;
789
793 static QgsLayoutItemRegistry *layoutItemRegistry() SIP_KEEPREFERENCE;
794
799 static QgsAnnotationItemRegistry *annotationItemRegistry() SIP_KEEPREFERENCE;
800
804 static QgsGpsConnectionRegistry *gpsConnectionRegistry() SIP_KEEPREFERENCE;
805
810 static QgsBabelFormatRegistry *gpsBabelFormatRegistry() SIP_KEEPREFERENCE;
811
815 static QgsPluginLayerRegistry *pluginLayerRegistry() SIP_KEEPREFERENCE;
816
821 static QgsClassificationMethodRegistry *classificationMethodRegistry() SIP_KEEPREFERENCE;
822
827 static QgsBookmarkManager *bookmarkManager();
828
834 static QgsTileDownloadManager *tileDownloadManager() SIP_SKIP;
835
840 static QgsRecentStyleHandler *recentStyleHandler() SIP_KEEPREFERENCE;
841
847 static QgsDatabaseQueryLog *databaseQueryLog() SIP_KEEPREFERENCE;
848
856 static QgsStyleModel *defaultStyleModel();
857
863 static QgsFontManager *fontManager() SIP_KEEPREFERENCE;
864
869 static QgsSensorRegistry *sensorRegistry() SIP_KEEPREFERENCE;
870
875 static QgsPlotRegistry *plotRegistry() SIP_KEEPREFERENCE;
876
880 static QgsMessageLog *messageLog();
881
887 static QgsAuthManager *authManager();
888
893 static QgsAuthConfigurationStorageRegistry *authConfigurationStorageRegistry();
894
899 static QgsProcessingRegistry *processingRegistry();
900
904 static QgsPageSizeRegistry *pageSizeRegistry() SIP_KEEPREFERENCE;
905
910 static QgsAnnotationRegistry *annotationRegistry() SIP_SKIP;
911
916 static QgsApplicationThemeRegistry *applicationThemeRegistry() SIP_KEEPREFERENCE;
917
922 static QgsActionScopeRegistry *actionScopeRegistry() SIP_KEEPREFERENCE;
923
928 static QgsConnectionRegistry *connectionRegistry();
929
933 static QgsRuntimeProfiler *profiler();
934
940 static QgsNumericFormatRegistry *numericFormatRegistry() SIP_KEEPREFERENCE;
941
945 static QgsFieldFormatterRegistry *fieldFormatterRegistry() SIP_KEEPREFERENCE;
946
950 static Qgs3DRendererRegistry *renderer3DRegistry() SIP_KEEPREFERENCE;
951
956 static Qgs3DSymbolRegistry *symbol3DRegistry() SIP_KEEPREFERENCE;
957
963 static QgsScaleBarRendererRegistry *scaleBarRendererRegistry() SIP_KEEPREFERENCE;
964
970 static QgsLabelingEngineRuleRegistry *labelingEngineRuleRegistry() SIP_KEEPREFERENCE;
971
976 static QgsProjectStorageRegistry *projectStorageRegistry() SIP_KEEPREFERENCE;
977
982 static QgsLayerMetadataProviderRegistry *layerMetadataProviderRegistry() SIP_KEEPREFERENCE;
983
988 static QgsExternalStorageRegistry *externalStorageRegistry() SIP_KEEPREFERENCE;
989
994 static QgsProfileSourceRegistry *profileSourceRegistry() SIP_KEEPREFERENCE;
995
1003 static QgsLocalizedDataPathRegistry *localizedDataPathRegistry() SIP_KEEPREFERENCE;
1004
1015 static QString nullRepresentation();
1016
1027 static void setNullRepresentation( const QString &nullRepresentation );
1028
1035 static QVariantMap customVariables();
1036
1043 static void setCustomVariables( const QVariantMap &customVariables );
1044
1049 static void setCustomVariable( const QString &name, const QVariant &value );
1050
1056 static QStringList temporarilyTrustedProjectsFolders();
1057
1063 static void setTemporarilyTrustedProjectsFolders( const QStringList &trustedProjectsFolders );
1064
1070 static QStringList temporarilyUntrustedProjectsFolders();
1071
1077 static void setTemporarilyUntrustedProjectsFolders( const QStringList &untrustedProjectsFolders );
1078
1088 static int scaleIconSize( int standardSize, bool applyDevicePixelRatio = false );
1089
1098 int maxConcurrentConnectionsPerPool() const;
1099
1105 static void setTranslation( const QString &translation );
1106
1112 QString translation() const;
1113
1119 void collectTranslatableObjects( QgsTranslationContext *translationContext );
1120
1121
1122#ifndef SIP_RUN
1135#endif
1136
1137#ifdef SIP_RUN
1138 SIP_IF_FEATURE( ANDROID )
1139 //dummy method to workaround sip generation issue
1140 bool x11EventFilter( XEvent *event );
1141 SIP_END
1142#endif
1143
1144 signals:
1146 void preNotify( QObject *receiver, QEvent *event, bool *done ) SIP_SKIP;
1147
1152
1160
1168
1169
1176
1183
1184 private:
1185
1186 static void copyPath( const QString &src, const QString &dst );
1187 static QObject *ABISYM( mFileOpenEventReceiver );
1188
1189 static bool ABISYM( mInitialized );
1190
1192 static bool ABISYM( mRunningFromBuildDir );
1193
1196 static int ABISYM( sMaxThreads );
1197
1198 QMap<QString, QIcon> mIconCache;
1199 QMap<Cursor, QCursor> mCursorCache;
1200
1201 std::unique_ptr<QTranslator> mQgisTranslator;
1202 std::unique_ptr<QTranslator> mQtTranslator;
1203 std::unique_ptr<QTranslator> mQtBaseTranslator;
1204
1205 std::unique_ptr<QgsDataItemProviderRegistry> mDataItemProviderRegistry;
1206 QgsAuthManager *mAuthManager = nullptr;
1207
1208 struct ApplicationMembers;
1209
1210 // Applications members which belong to an instance of QgsApplication
1211 std::unique_ptr<ApplicationMembers> mApplicationMembers;
1212 // ... but in case QgsApplication is never instantiated (eg with custom designer widgets), we fall back to static members
1213 static ApplicationMembers *sApplicationMembers;
1214
1215 static QgsAuthManager *sAuthManager;
1216
1217 static ApplicationMembers *members();
1218
1219 static void invalidateCaches();
1220
1225 void installTranslators() SIP_SKIP;
1226
1227 QStringList mTemporarilyTrustedProjectFolders;
1228 QStringList mTemporarilyUntrustedProjectFolders;
1229
1231};
1232
1233// clazy:excludeall=qstring-allocations
1234
1235#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,...
endian_t
Constants for endian-ness.
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.
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)