QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 
369  static QIcon getThemeIcon( const QString &name, const QColor &fillColor = QColor(), const QColor &strokeColor = QColor() );
370 
375  enum Cursor
376  {
384  };
385 
392  static QCursor getThemeCursor( Cursor cursor );
393 
402  static QPixmap getThemePixmap( const QString &name, const QColor &foreColor = QColor(), const QColor &backColor = QColor(), int size = 16 );
403 
405  static QString userStylePath();
406 
408  static QRegExp shortNameRegExp();
409 
415  static QString userLoginName();
416 
422  static QString userFullName();
423 
429  static QString osName();
430 
436  static QString platform();
437 
442  static QString locale();
443 
445  static QString userThemesFolder();
446 
448  static QString defaultStylePath();
449 
451  static QString defaultThemesFolder();
452 
454  static QString libraryPath();
455 
457  static QString libexecPath();
458 
465  static QString qmlImportPath();
466 
468  static void setPrefixPath( const QString &prefixPath, bool useDefaultPaths = false );
469 
471  static void setPluginPath( const QString &pluginPath );
472 
474  static void setPkgDataPath( const QString &pkgDataPath );
475 
477  static void setDefaultSvgPaths( const QStringList &pathList );
478 
480  static void setAuthDatabaseDirPath( const QString &authDbDirPath );
481 
483  static void initQgis();
484 
486  static bool createDatabase( QString *errorMessage = nullptr );
487 
489  static bool createThemeFolder();
490 
492  static void exitQgis();
493 
495  static QString appIconPath();
496 
498  enum endian_t
499  {
500  XDR = 0, // network, or big-endian, byte order
501  NDR = 1 // little-endian byte order
502  };
503 
505  static endian_t endian();
506 
521  static QString reportStyleSheet( QgsApplication::StyleSheetType styleSheetType = QgsApplication::StyleSheetType::Qt );
522 
527  static QString showSettings();
528 
536  static void registerOgrDrivers();
537 
539  static QString absolutePathToRelativePath( const QString &apath, const QString &targetPath );
541  static QString relativePathToAbsolutePath( const QString &rpath, const QString &targetPath );
542 
544  static bool isRunningFromBuildDir() { return ABISYM( mRunningFromBuildDir ); }
545 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
546  static QString cfgIntDir() SIP_SKIP;
547 #endif
549  static QString buildSourcePath();
551  static QString buildOutputPath();
552 
558  static void skipGdalDriver( const QString &driver );
559 
565  static void restoreGdalDriver( const QString &driver );
566 
571  static QStringList skippedGdalDrivers();
572 
579  static void applyGdalSkippedDrivers();
580 
585  static void registerGdalDriversFromSettings();
586 
593  static QStringList deferredSkippedGdalDrivers();
594 
601  static void setSkippedGdalDrivers( const QStringList &skippedGdalDrivers,
602  const QStringList &deferredSkippedGdalDrivers );
603 
608  static int maxThreads();
609 
615  static void setMaxThreads( int maxThreads );
616 
622  static QgsTaskManager *taskManager();
623 
628  static QgsSettingsRegistryCore *settingsRegistryCore() SIP_KEEPREFERENCE;
629 
634  static QgsColorSchemeRegistry *colorSchemeRegistry() SIP_KEEPREFERENCE;
635 
640  static QgsPaintEffectRegistry *paintEffectRegistry() SIP_KEEPREFERENCE;
641 
646  static QgsRendererRegistry *rendererRegistry() SIP_KEEPREFERENCE;
647 
653  static QgsRasterRendererRegistry *rasterRendererRegistry() SIP_SKIP;
654 
659  static QgsPointCloudRendererRegistry *pointCloudRendererRegistry() SIP_KEEPREFERENCE;
660 
666  static QgsDataItemProviderRegistry *dataItemProviderRegistry() SIP_KEEPREFERENCE;
667 
674  static QgsCoordinateReferenceSystemRegistry *coordinateReferenceSystemRegistry() SIP_KEEPREFERENCE;
675 
683  static QgsSvgCache *svgCache();
684 
691  static QgsImageCache *imageCache();
692 
698  static QgsSourceCache *sourceCache();
699 
704  static QgsNetworkContentFetcherRegistry *networkContentFetcherRegistry() SIP_KEEPREFERENCE;
705 
710  static QgsValidityCheckRegistry *validityCheckRegistry() SIP_KEEPREFERENCE;
711 
716  static QgsSymbolLayerRegistry *symbolLayerRegistry() SIP_KEEPREFERENCE;
717 
722  static QgsCalloutRegistry *calloutRegistry() SIP_KEEPREFERENCE;
723 
728  static QgsLayoutItemRegistry *layoutItemRegistry() SIP_KEEPREFERENCE;
729 
734  static QgsAnnotationItemRegistry *annotationItemRegistry() SIP_KEEPREFERENCE;
735 
740  static QgsGpsConnectionRegistry *gpsConnectionRegistry() SIP_KEEPREFERENCE;
741 
746  static QgsPluginLayerRegistry *pluginLayerRegistry() SIP_KEEPREFERENCE;
747 
752  static QgsClassificationMethodRegistry *classificationMethodRegistry() SIP_KEEPREFERENCE;
753 
758  static QgsBookmarkManager *bookmarkManager();
759 
765  static QgsTileDownloadManager *tileDownloadManager() SIP_SKIP;
766 
774  static QgsStyleModel *defaultStyleModel();
775 
780  static QgsMessageLog *messageLog();
781 
788  static QgsAuthManager *authManager();
789 
795  static QgsProcessingRegistry *processingRegistry();
796 
801  static QgsPageSizeRegistry *pageSizeRegistry() SIP_KEEPREFERENCE;
802 
808  static QgsAnnotationRegistry *annotationRegistry() SIP_SKIP;
809 
815  static QgsActionScopeRegistry *actionScopeRegistry() SIP_KEEPREFERENCE;
816 
821  static QgsConnectionRegistry *connectionRegistry();
822 
827  static QgsRuntimeProfiler *profiler();
828 
834  static QgsNumericFormatRegistry *numericFormatRegistry() SIP_KEEPREFERENCE;
835 
839  static QgsFieldFormatterRegistry *fieldFormatterRegistry() SIP_KEEPREFERENCE;
840 
845  static Qgs3DRendererRegistry *renderer3DRegistry() SIP_KEEPREFERENCE;
846 
851  static Qgs3DSymbolRegistry *symbol3DRegistry() SIP_KEEPREFERENCE;
852 
858  static QgsScaleBarRendererRegistry *scaleBarRendererRegistry() SIP_KEEPREFERENCE;
859 
864  static QgsProjectStorageRegistry *projectStorageRegistry() SIP_KEEPREFERENCE;
865 
873  static QgsLocalizedDataPathRegistry *localizedDataPathRegistry() SIP_KEEPREFERENCE;
874 
883  static QString nullRepresentation();
884 
888  static void setNullRepresentation( const QString &nullRepresentation );
889 
897  static QVariantMap customVariables();
898 
906  static void setCustomVariables( const QVariantMap &customVariables );
907 
913  static void setCustomVariable( const QString &name, const QVariant &value );
914 
924  static int scaleIconSize( int standardSize, bool applyDevicePixelRatio = false );
925 
934  int maxConcurrentConnectionsPerPool() const;
935 
941  static void setTranslation( const QString &translation );
942 
948  void collectTranslatableObjects( QgsTranslationContext *translationContext );
949 
950 #ifndef SIP_RUN
952  static const inline QgsSettingsEntryString settingsLocaleUserLocale = QgsSettingsEntryString( QStringLiteral( "locale/userLocale" ), QgsSettings::NoSection, QString() );
954  static const inline QgsSettingsEntryBool settingsLocaleOverrideFlag = QgsSettingsEntryBool( QStringLiteral( "locale/overrideFlag" ), QgsSettings::NoSection, false );
956  static const inline QgsSettingsEntryString settingsLocaleGlobalLocale = QgsSettingsEntryString( QStringLiteral( "locale/globalLocale" ), QgsSettings::NoSection, QString() );
958  static const inline QgsSettingsEntryBool settingsLocaleShowGroupSeparator = QgsSettingsEntryBool( QStringLiteral( "locale/showGroupSeparator" ), QgsSettings::NoSection, false );
960  static const inline QgsSettingsEntryStringList settingsSearchPathsForSVG = QgsSettingsEntryStringList( QStringLiteral( "svg/searchPathsForSVG" ), QgsSettings::NoSection, QStringList() );
961 #endif
962 
963 #ifdef SIP_RUN
964  SIP_IF_FEATURE( ANDROID )
965  //dummy method to workaround sip generation issue
966  bool x11EventFilter( XEvent *event );
967  SIP_END
968 #endif
969 
970  signals:
972  void preNotify( QObject *receiver, QEvent *event, bool *done ) SIP_SKIP;
973 
979 
980 
985 
993 
994  private:
995 
996  static void copyPath( const QString &src, const QString &dst );
997  static QObject *ABISYM( mFileOpenEventReceiver );
998 
999  static bool ABISYM( mInitialized );
1000 
1002  static bool ABISYM( mRunningFromBuildDir );
1003 
1007  static int ABISYM( sMaxThreads );
1008 
1009  QMap<QString, QIcon> mIconCache;
1010  QMap<Cursor, QCursor> mCursorCache;
1011 
1012  QTranslator *mQgisTranslator = nullptr;
1013  QTranslator *mQtTranslator = nullptr;
1014 
1015  QgsDataItemProviderRegistry *mDataItemProviderRegistry = nullptr;
1016  QgsAuthManager *mAuthManager = nullptr;
1017 
1018  struct ApplicationMembers
1019  {
1020  QgsSettingsRegistryCore *mSettingsRegistryCore = nullptr;
1021  QgsCoordinateReferenceSystemRegistry *mCrsRegistry = nullptr;
1022  Qgs3DRendererRegistry *m3DRendererRegistry = nullptr;
1023  Qgs3DSymbolRegistry *m3DSymbolRegistry = nullptr;
1024  QgsActionScopeRegistry *mActionScopeRegistry = nullptr;
1025  QgsAnnotationRegistry *mAnnotationRegistry = nullptr;
1026  QgsColorSchemeRegistry *mColorSchemeRegistry = nullptr;
1027  QgsLocalizedDataPathRegistry *mLocalizedDataPathRegistry = nullptr;
1028  QgsNumericFormatRegistry *mNumericFormatRegistry = nullptr;
1029  QgsFieldFormatterRegistry *mFieldFormatterRegistry = nullptr;
1030  QgsGpsConnectionRegistry *mGpsConnectionRegistry = nullptr;
1031  QgsNetworkContentFetcherRegistry *mNetworkContentFetcherRegistry = nullptr;
1032  QgsScaleBarRendererRegistry *mScaleBarRendererRegistry = nullptr;
1033  QgsValidityCheckRegistry *mValidityCheckRegistry = nullptr;
1034  QgsMessageLog *mMessageLog = nullptr;
1035  QgsPaintEffectRegistry *mPaintEffectRegistry = nullptr;
1036  QgsPluginLayerRegistry *mPluginLayerRegistry = nullptr;
1037  QgsClassificationMethodRegistry *mClassificationMethodRegistry = nullptr;
1038  QgsProcessingRegistry *mProcessingRegistry = nullptr;
1039  QgsConnectionRegistry *mConnectionRegistry = nullptr;
1040  QgsProjectStorageRegistry *mProjectStorageRegistry = nullptr;
1041  QgsPageSizeRegistry *mPageSizeRegistry = nullptr;
1042  QgsRasterRendererRegistry *mRasterRendererRegistry = nullptr;
1043  QgsRendererRegistry *mRendererRegistry = nullptr;
1044  QgsPointCloudRendererRegistry *mPointCloudRendererRegistry = nullptr;
1045  QgsSvgCache *mSvgCache = nullptr;
1046  QgsImageCache *mImageCache = nullptr;
1047  QgsSourceCache *mSourceCache = nullptr;
1048  QgsSymbolLayerRegistry *mSymbolLayerRegistry = nullptr;
1049  QgsCalloutRegistry *mCalloutRegistry = nullptr;
1050  QgsTaskManager *mTaskManager = nullptr;
1051  QgsLayoutItemRegistry *mLayoutItemRegistry = nullptr;
1052  QgsAnnotationItemRegistry *mAnnotationItemRegistry = nullptr;
1053  QgsUserProfileManager *mUserConfigManager = nullptr;
1054  QgsBookmarkManager *mBookmarkManager = nullptr;
1055  QgsTileDownloadManager *mTileDownloadManager = nullptr;
1056  QgsStyleModel *mStyleModel = nullptr;
1057  QString mNullRepresentation;
1058  QStringList mSvgPathCache;
1059  bool mSvgPathCacheValid = false;
1060 
1061  ApplicationMembers();
1062  ~ApplicationMembers();
1063  };
1064 
1065  // Applications members which belong to an instance of QgsApplication
1066  ApplicationMembers *mApplicationMembers = nullptr;
1067  // ... but in case QgsApplication is never instantiated (eg with custom designer widgets), we fall back to static members
1068  static ApplicationMembers *sApplicationMembers;
1069 
1070  static QgsAuthManager *sAuthManager;
1071 
1072  static ApplicationMembers *members();
1073 
1074  static void invalidateCaches();
1075 
1076  friend class TestQgsApplication;
1077 };
1078 
1079 // clazy:excludeall=qstring-allocations
1080 
1081 #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)