QGIS API Documentation  3.19.0-Master (c022ae99b5)
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 "qgis_sip.h"
25 #include "qgsconfig.h"
26 #include "qgssettingsentry.h"
27 #include "qgstranslationcontext.h"
28 
29 class QgsSettingsRegistryCore;
33 class QgsRuntimeProfiler;
34 class QgsTaskManager;
41 class QgsSvgCache;
42 class QgsImageCache;
43 class QgsSourceCache;
50 class QgsMessageLog;
52 class QgsAnnotationRegistry;
53 class QgsUserProfile;
57 class QgsAuthManager;
60 class QTranslator;
61 class QgsCalloutRegistry;
62 class QgsBookmarkManager;
63 class QgsStyleModel;
71 
86 class CORE_EXPORT QgsApplication : public QApplication
87 {
88 
89 #ifdef SIP_RUN
90  % TypeCode
91  // Convert a Python argv list to a conventional C argc count and argv array.
92  static char **qtgui_ArgvToC( PyObject *argvlist, int &argc )
93  {
94  char **argv;
95 
96  argc = PyList_GET_SIZE( argvlist );
97 
98  // Allocate space for two copies of the argument pointers, plus the
99  // terminating NULL.
100  if ( ( argv = ( char ** )sipMalloc( 2 * ( argc + 1 ) * sizeof( char * ) ) ) == NULL )
101  return NULL;
102 
103  // Convert the list.
104  for ( int a = 0; a < argc; ++a )
105  {
106  char *arg;
107  // Get the argument and allocate memory for it.
108  if ( ( arg = PyBytes_AsString( PyList_GET_ITEM( argvlist, a ) ) ) == NULL ||
109  ( argv[a] = ( char * )sipMalloc( strlen( arg ) + 1 ) ) == NULL )
110  return NULL;
111  // Copy the argument and save a pointer to it.
112  strcpy( argv[a], arg );
113  argv[a + argc + 1] = argv[a];
114  }
115 
116  argv[argc + argc + 1] = argv[argc] = NULL;
117 
118  return argv;
119  }
120 
121  // Remove arguments from the Python argv list that have been removed from the
122  // C argv array.
123  static void qtgui_UpdatePyArgv( PyObject *argvlist, int argc, char **argv )
124  {
125  for ( int a = 0, na = 0; a < argc; ++a )
126  {
127  // See if it was removed.
128  if ( argv[na] == argv[a + argc + 1] )
129  ++na;
130  else
131  PyList_SetSlice( argvlist, na, na + 1, NULL );
132  }
133  }
134  % End
135 #endif
136 
137  Q_OBJECT
138 
139  public:
140 
150  {
151  Qt,
153  };
154 
155  static const char *QGIS_ORGANIZATION_NAME;
156  static const char *QGIS_ORGANIZATION_DOMAIN;
157  static const char *QGIS_APPLICATION_NAME;
158 #ifndef SIP_RUN
159  QgsApplication( int &argc, char **argv, bool GUIenabled, const QString &profileFolder = QString(), const QString &platformName = "desktop" );
160 #else
161  QgsApplication( SIP_PYLIST argv, bool GUIenabled, QString profileFolder = QString(), QString platformName = "desktop" ) / PostHook = __pyQtQAppHook__ / [( int &argc, char **argv, bool GUIenabled, const QString &profileFolder = QString(), const QString &platformName = "desktop" )];
162  % MethodCode
163  // The Python interface is a list of argument strings that is modified.
164 
165  int argc;
166  char **argv;
167 
168  // Convert the list.
169  if ( ( argv = qtgui_ArgvToC( a0, argc ) ) == NULL )
170  sipIsErr = 1;
171  else
172  {
173  // Create it now the arguments are right.
174  static int nargc = argc;
175 
176  sipCpp = new sipQgsApplication( nargc, argv, a1, *a2, *a3 );
177 
178  // Now modify the original list.
179  qtgui_UpdatePyArgv( a0, argc, argv );
180  }
181  % End
182 #endif
183 
184  ~QgsApplication() override;
185 
191  static QgsApplication *instance();
192 
200  static void init( QString profileFolder = QString() ) SIP_SKIP;
201 
203  bool event( QEvent *event ) override;
204 
206  bool notify( QObject *receiver, QEvent *event ) override;
207 
209  static void setFileOpenEventReceiver( QObject *receiver );
210 
221  static void setThemeName( const QString &themeName );
222 
227  static QString resolvePkgPath();
228 
236  static QString themeName();
237 
245  static void setUITheme( const QString &themeName );
246 
253  static QHash<QString, QString> uiThemes();
254 
256  static QString authorsFilePath();
257 
263  static QString contributorsFilePath();
264 
271  static QString developersMapFilePath();
272 
274  static QString sponsorsFilePath();
275 
277  static QString donorsFilePath();
278 
280  static QString serverResourcesPath();
281 
285  static QString translatorsFilePath();
286 
290  static QString licenceFilePath();
291 
293  static QString i18nPath();
294 
299  static QString metadataPath();
300 
302  static QString qgisMasterDatabaseFilePath();
303 
305  static QString qgisSettingsDirPath();
306 
308  static QString qgisUserDatabaseFilePath();
309 
311  static QString qgisAuthDatabaseFilePath();
312 
314  static QString splashPath();
315 
317  static QString iconsPath();
318 
320  static QString srsDatabaseFilePath();
321 
327  static void setSvgPaths( const QStringList &svgPaths );
328 
330  static QStringList svgPaths();
331 
336  static QStringList layoutTemplatePaths();
337 
339  static QMap<QString, QString> systemEnvVars();
340 
342  static QString prefixPath();
343 
345  static QString pluginPath();
346 
348  static QString pkgDataPath();
349 
351  static QString activeThemePath();
352 
354  static QString defaultThemePath();
355 
360  static QString iconPath( const QString &iconFile );
361 
366  static QIcon getThemeIcon( const QString &name );
367 
372  enum Cursor
373  {
381  };
382 
389  static QCursor getThemeCursor( Cursor cursor );
390 
399  static QPixmap getThemePixmap( const QString &name, const QColor &foreColor = QColor(), const QColor &backColor = QColor(), int size = 16 );
400 
402  static QString userStylePath();
403 
405  static QRegExp shortNameRegExp();
406 
412  static QString userLoginName();
413 
419  static QString userFullName();
420 
426  static QString osName();
427 
433  static QString platform();
434 
439  static QString locale();
440 
442  static QString userThemesFolder();
443 
445  static QString defaultStylePath();
446 
448  static QString defaultThemesFolder();
449 
451  static QString libraryPath();
452 
454  static QString libexecPath();
455 
462  static QString qmlImportPath();
463 
465  static void setPrefixPath( const QString &prefixPath, bool useDefaultPaths = false );
466 
468  static void setPluginPath( const QString &pluginPath );
469 
471  static void setPkgDataPath( const QString &pkgDataPath );
472 
474  static void setDefaultSvgPaths( const QStringList &pathList );
475 
477  static void setAuthDatabaseDirPath( const QString &authDbDirPath );
478 
480  static void initQgis();
481 
483  static bool createDatabase( QString *errorMessage = nullptr );
484 
486  static bool createThemeFolder();
487 
489  static void exitQgis();
490 
492  static QString appIconPath();
493 
495  enum endian_t
496  {
497  XDR = 0, // network, or big-endian, byte order
498  NDR = 1 // little-endian byte order
499  };
500 
502  static endian_t endian();
503 
518  static QString reportStyleSheet( QgsApplication::StyleSheetType styleSheetType = QgsApplication::StyleSheetType::Qt );
519 
524  static QString showSettings();
525 
533  static void registerOgrDrivers();
534 
536  static QString absolutePathToRelativePath( const QString &apath, const QString &targetPath );
538  static QString relativePathToAbsolutePath( const QString &rpath, const QString &targetPath );
539 
541  static bool isRunningFromBuildDir() { return ABISYM( mRunningFromBuildDir ); }
542 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
543  static QString cfgIntDir() SIP_SKIP;
544 #endif
546  static QString buildSourcePath();
548  static QString buildOutputPath();
549 
555  static void skipGdalDriver( const QString &driver );
556 
562  static void restoreGdalDriver( const QString &driver );
563 
568  static QStringList skippedGdalDrivers();
569 
576  static void applyGdalSkippedDrivers();
577 
582  static void registerGdalDriversFromSettings();
583 
590  static QStringList deferredSkippedGdalDrivers();
591 
598  static void setSkippedGdalDrivers( const QStringList &skippedGdalDrivers,
599  const QStringList &deferredSkippedGdalDrivers );
600 
605  static int maxThreads();
606 
612  static void setMaxThreads( int maxThreads );
613 
619  static QgsTaskManager *taskManager();
620 
625  static QgsSettingsRegistryCore *settingsRegistryCore() SIP_KEEPREFERENCE;
626 
631  static QgsColorSchemeRegistry *colorSchemeRegistry() SIP_KEEPREFERENCE;
632 
637  static QgsPaintEffectRegistry *paintEffectRegistry() SIP_KEEPREFERENCE;
638 
643  static QgsRendererRegistry *rendererRegistry() SIP_KEEPREFERENCE;
644 
650  static QgsRasterRendererRegistry *rasterRendererRegistry() SIP_SKIP;
651 
656  static QgsPointCloudRendererRegistry *pointCloudRendererRegistry() SIP_KEEPREFERENCE;
657 
663  static QgsDataItemProviderRegistry *dataItemProviderRegistry() SIP_KEEPREFERENCE;
664 
671  static QgsCoordinateReferenceSystemRegistry *coordinateReferenceSystemRegistry() SIP_KEEPREFERENCE;
672 
680  static QgsSvgCache *svgCache();
681 
688  static QgsImageCache *imageCache();
689 
695  static QgsSourceCache *sourceCache();
696 
701  static QgsNetworkContentFetcherRegistry *networkContentFetcherRegistry() SIP_KEEPREFERENCE;
702 
707  static QgsValidityCheckRegistry *validityCheckRegistry() SIP_KEEPREFERENCE;
708 
713  static QgsSymbolLayerRegistry *symbolLayerRegistry() SIP_KEEPREFERENCE;
714 
719  static QgsCalloutRegistry *calloutRegistry() SIP_KEEPREFERENCE;
720 
725  static QgsLayoutItemRegistry *layoutItemRegistry() SIP_KEEPREFERENCE;
726 
731  static QgsAnnotationItemRegistry *annotationItemRegistry() SIP_KEEPREFERENCE;
732 
737  static QgsGpsConnectionRegistry *gpsConnectionRegistry() SIP_KEEPREFERENCE;
738 
743  static QgsPluginLayerRegistry *pluginLayerRegistry() SIP_KEEPREFERENCE;
744 
749  static QgsClassificationMethodRegistry *classificationMethodRegistry() SIP_KEEPREFERENCE;
750 
755  static QgsBookmarkManager *bookmarkManager();
756 
762  static QgsTileDownloadManager *tileDownloadManager() SIP_SKIP;
763 
771  static QgsStyleModel *defaultStyleModel();
772 
777  static QgsMessageLog *messageLog();
778 
785  static QgsAuthManager *authManager();
786 
792  static QgsProcessingRegistry *processingRegistry();
793 
798  static QgsPageSizeRegistry *pageSizeRegistry() SIP_KEEPREFERENCE;
799 
805  static QgsAnnotationRegistry *annotationRegistry() SIP_SKIP;
806 
812  static QgsActionScopeRegistry *actionScopeRegistry() SIP_KEEPREFERENCE;
813 
818  static QgsConnectionRegistry *connectionRegistry();
819 
824  static QgsRuntimeProfiler *profiler();
825 
831  static QgsNumericFormatRegistry *numericFormatRegistry() SIP_KEEPREFERENCE;
832 
836  static QgsFieldFormatterRegistry *fieldFormatterRegistry() SIP_KEEPREFERENCE;
837 
842  static Qgs3DRendererRegistry *renderer3DRegistry() SIP_KEEPREFERENCE;
843 
848  static Qgs3DSymbolRegistry *symbol3DRegistry() SIP_KEEPREFERENCE;
849 
855  static QgsScaleBarRendererRegistry *scaleBarRendererRegistry() SIP_KEEPREFERENCE;
856 
861  static QgsProjectStorageRegistry *projectStorageRegistry() SIP_KEEPREFERENCE;
862 
870  static QgsLocalizedDataPathRegistry *localizedDataPathRegistry() SIP_KEEPREFERENCE;
871 
880  static QString nullRepresentation();
881 
885  static void setNullRepresentation( const QString &nullRepresentation );
886 
894  static QVariantMap customVariables();
895 
903  static void setCustomVariables( const QVariantMap &customVariables );
904 
910  static void setCustomVariable( const QString &name, const QVariant &value );
911 
921  static int scaleIconSize( int standardSize, bool applyDevicePixelRatio = false );
922 
931  int maxConcurrentConnectionsPerPool() const;
932 
938  static void setTranslation( const QString &translation );
939 
945  void collectTranslatableObjects( QgsTranslationContext *translationContext );
946 
947 #ifndef SIP_RUN
949  static const inline QgsSettingsEntryString settingsLocaleUserLocale = QgsSettingsEntryString( QStringLiteral( "locale/userLocale" ), QgsSettings::NoSection, QString() );
951  static const inline QgsSettingsEntryBool settingsLocaleOverrideFlag = QgsSettingsEntryBool( QStringLiteral( "locale/overrideFlag" ), QgsSettings::NoSection, false );
953  static const inline QgsSettingsEntryString settingsLocaleGlobalLocale = QgsSettingsEntryString( QStringLiteral( "locale/globalLocale" ), QgsSettings::NoSection, QString() );
955  static const inline QgsSettingsEntryBool settingsLocaleShowGroupSeparator = QgsSettingsEntryBool( QStringLiteral( "locale/showGroupSeparator" ), QgsSettings::NoSection, false );
957  static const inline QgsSettingsEntryStringList settingsSearchPathsForSVG = QgsSettingsEntryStringList( QStringLiteral( "svg/searchPathsForSVG" ), QgsSettings::NoSection, QStringList() );
958 #endif
959 
960 #ifdef SIP_RUN
961  SIP_IF_FEATURE( ANDROID )
962  //dummy method to workaround sip generation issue
963  bool x11EventFilter( XEvent *event );
964  SIP_END
965 #endif
966 
967  signals:
969  void preNotify( QObject *receiver, QEvent *event, bool *done ) SIP_SKIP;
970 
976 
977 
982 
990 
991  private:
992 
993  static void copyPath( const QString &src, const QString &dst );
994  static QObject *ABISYM( mFileOpenEventReceiver );
995 
996  static bool ABISYM( mInitialized );
997 
999  static bool ABISYM( mRunningFromBuildDir );
1000 
1004  static int ABISYM( sMaxThreads );
1005 
1006  QMap<QString, QIcon> mIconCache;
1007  QMap<Cursor, QCursor> mCursorCache;
1008 
1009  QTranslator *mQgisTranslator = nullptr;
1010  QTranslator *mQtTranslator = nullptr;
1011 
1012  QgsDataItemProviderRegistry *mDataItemProviderRegistry = nullptr;
1013  QgsAuthManager *mAuthManager = nullptr;
1014 
1015  struct ApplicationMembers
1016  {
1017  QgsSettingsRegistryCore *mSettingsRegistryCore = nullptr;
1018  QgsCoordinateReferenceSystemRegistry *mCrsRegistry = nullptr;
1019  Qgs3DRendererRegistry *m3DRendererRegistry = nullptr;
1020  Qgs3DSymbolRegistry *m3DSymbolRegistry = nullptr;
1021  QgsActionScopeRegistry *mActionScopeRegistry = nullptr;
1022  QgsAnnotationRegistry *mAnnotationRegistry = nullptr;
1023  QgsColorSchemeRegistry *mColorSchemeRegistry = nullptr;
1024  QgsLocalizedDataPathRegistry *mLocalizedDataPathRegistry = nullptr;
1025  QgsNumericFormatRegistry *mNumericFormatRegistry = nullptr;
1026  QgsFieldFormatterRegistry *mFieldFormatterRegistry = nullptr;
1027  QgsGpsConnectionRegistry *mGpsConnectionRegistry = nullptr;
1028  QgsNetworkContentFetcherRegistry *mNetworkContentFetcherRegistry = nullptr;
1029  QgsScaleBarRendererRegistry *mScaleBarRendererRegistry = nullptr;
1030  QgsValidityCheckRegistry *mValidityCheckRegistry = nullptr;
1031  QgsMessageLog *mMessageLog = nullptr;
1032  QgsPaintEffectRegistry *mPaintEffectRegistry = nullptr;
1033  QgsPluginLayerRegistry *mPluginLayerRegistry = nullptr;
1034  QgsClassificationMethodRegistry *mClassificationMethodRegistry = nullptr;
1035  QgsProcessingRegistry *mProcessingRegistry = nullptr;
1036  QgsConnectionRegistry *mConnectionRegistry = nullptr;
1037  QgsProjectStorageRegistry *mProjectStorageRegistry = nullptr;
1038  QgsPageSizeRegistry *mPageSizeRegistry = nullptr;
1039  QgsRasterRendererRegistry *mRasterRendererRegistry = nullptr;
1040  QgsRendererRegistry *mRendererRegistry = nullptr;
1041  QgsPointCloudRendererRegistry *mPointCloudRendererRegistry = nullptr;
1042  QgsSvgCache *mSvgCache = nullptr;
1043  QgsImageCache *mImageCache = nullptr;
1044  QgsSourceCache *mSourceCache = nullptr;
1045  QgsSymbolLayerRegistry *mSymbolLayerRegistry = nullptr;
1046  QgsCalloutRegistry *mCalloutRegistry = nullptr;
1047  QgsTaskManager *mTaskManager = nullptr;
1048  QgsLayoutItemRegistry *mLayoutItemRegistry = nullptr;
1049  QgsAnnotationItemRegistry *mAnnotationItemRegistry = nullptr;
1050  QgsUserProfileManager *mUserConfigManager = nullptr;
1051  QgsBookmarkManager *mBookmarkManager = nullptr;
1052  QgsTileDownloadManager *mTileDownloadManager = nullptr;
1053  QgsStyleModel *mStyleModel = nullptr;
1054  QString mNullRepresentation;
1055  QStringList mSvgPathCache;
1056  bool mSvgPathCacheValid = false;
1057 
1058  ApplicationMembers();
1059  ~ApplicationMembers();
1060  };
1061 
1062  // Applications members which belong to an instance of QgsApplication
1063  ApplicationMembers *mApplicationMembers = nullptr;
1064  // ... but in case QgsApplication is never instantiated (eg with custom designer widgets), we fall back to static members
1065  static ApplicationMembers *sApplicationMembers;
1066 
1067  static QgsAuthManager *sAuthManager;
1068 
1069  static ApplicationMembers *members();
1070 
1071  static void invalidateCaches();
1072 };
1073 
1074 // clazy:excludeall=qstring-allocations
1075 
1076 #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)
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...
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.
The QgsFieldFormatterRegistry manages registered classes of QgsFieldFormatter.
A class to register / unregister existing GPS connections such that the information is available to a...
A cache for images derived from raster files.
Definition: qgsimagecache.h:97
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.
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 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:167
#define SIP_END
Definition: qgis_sip.h:194
QObject * ABISYM(QgsApplication::mFileOpenEventReceiver)