QGIS API Documentation  3.19.0-Master (67c226385a)
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 "qgstranslationcontext.h"
27 
31 class QgsRuntimeProfiler;
32 class QgsTaskManager;
39 class QgsSvgCache;
40 class QgsImageCache;
41 class QgsSourceCache;
48 class QgsMessageLog;
50 class QgsAnnotationRegistry;
51 class QgsUserProfile;
55 class QgsAuthManager;
58 class QTranslator;
59 class QgsCalloutRegistry;
60 class QgsBookmarkManager;
61 class QgsStyleModel;
69 
85 class CORE_EXPORT QgsApplication : public QApplication
86 {
87 
88 #ifdef SIP_RUN
89  % TypeCode
90  // Convert a Python argv list to a conventional C argc count and argv array.
91  static char **qtgui_ArgvToC( PyObject *argvlist, int &argc )
92  {
93  char **argv;
94 
95  argc = PyList_GET_SIZE( argvlist );
96 
97  // Allocate space for two copies of the argument pointers, plus the
98  // terminating NULL.
99  if ( ( argv = ( char ** )sipMalloc( 2 * ( argc + 1 ) * sizeof( char * ) ) ) == NULL )
100  return NULL;
101 
102  // Convert the list.
103  for ( int a = 0; a < argc; ++a )
104  {
105  char *arg;
106  // Get the argument and allocate memory for it.
107  if ( ( arg = PyBytes_AsString( PyList_GET_ITEM( argvlist, a ) ) ) == NULL ||
108  ( argv[a] = ( char * )sipMalloc( strlen( arg ) + 1 ) ) == NULL )
109  return NULL;
110  // Copy the argument and save a pointer to it.
111  strcpy( argv[a], arg );
112  argv[a + argc + 1] = argv[a];
113  }
114 
115  argv[argc + argc + 1] = argv[argc] = NULL;
116 
117  return argv;
118  }
119 
120  // Remove arguments from the Python argv list that have been removed from the
121  // C argv array.
122  static void qtgui_UpdatePyArgv( PyObject *argvlist, int argc, char **argv )
123  {
124  for ( int a = 0, na = 0; a < argc; ++a )
125  {
126  // See if it was removed.
127  if ( argv[na] == argv[a + argc + 1] )
128  ++na;
129  else
130  PyList_SetSlice( argvlist, na, na + 1, NULL );
131  }
132  }
133  % End
134 #endif
135 
136  Q_OBJECT
137 
138  public:
139 
149  {
150  Qt,
152  };
153 
154  static const char *QGIS_ORGANIZATION_NAME;
155  static const char *QGIS_ORGANIZATION_DOMAIN;
156  static const char *QGIS_APPLICATION_NAME;
157 #ifndef SIP_RUN
158  QgsApplication( int &argc, char **argv, bool GUIenabled, const QString &profileFolder = QString(), const QString &platformName = "desktop" );
159 #else
160  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" )];
161  % MethodCode
162  // The Python interface is a list of argument strings that is modified.
163 
164  int argc;
165  char **argv;
166 
167  // Convert the list.
168  if ( ( argv = qtgui_ArgvToC( a0, argc ) ) == NULL )
169  sipIsErr = 1;
170  else
171  {
172  // Create it now the arguments are right.
173  static int nargc = argc;
174 
175  sipCpp = new sipQgsApplication( nargc, argv, a1, *a2, *a3 );
176 
177  // Now modify the original list.
178  qtgui_UpdatePyArgv( a0, argc, argv );
179  }
180  % End
181 #endif
182 
183  ~QgsApplication() override;
184 
190  static QgsApplication *instance();
191 
199  static void init( QString profileFolder = QString() ) SIP_SKIP;
200 
202  bool event( QEvent *event ) override;
203 
205  bool notify( QObject *receiver, QEvent *event ) override;
206 
208  static void setFileOpenEventReceiver( QObject *receiver );
209 
220  static void setThemeName( const QString &themeName );
221 
226  static QString resolvePkgPath();
227 
235  static QString themeName();
236 
244  static void setUITheme( const QString &themeName );
245 
252  static QHash<QString, QString> uiThemes();
253 
255  static QString authorsFilePath();
256 
262  static QString contributorsFilePath();
263 
270  static QString developersMapFilePath();
271 
273  static QString sponsorsFilePath();
274 
276  static QString donorsFilePath();
277 
279  static QString serverResourcesPath();
280 
284  static QString translatorsFilePath();
285 
289  static QString licenceFilePath();
290 
292  static QString i18nPath();
293 
298  static QString metadataPath();
299 
301  static QString qgisMasterDatabaseFilePath();
302 
304  static QString qgisSettingsDirPath();
305 
307  static QString qgisUserDatabaseFilePath();
308 
310  static QString qgisAuthDatabaseFilePath();
311 
313  static QString splashPath();
314 
316  static QString iconsPath();
317 
319  static QString srsDatabaseFilePath();
320 
326  static void setSvgPaths( const QStringList &svgPaths );
327 
329  static QStringList svgPaths();
330 
335  static QStringList layoutTemplatePaths();
336 
338  static QMap<QString, QString> systemEnvVars();
339 
341  static QString prefixPath();
342 
344  static QString pluginPath();
345 
347  static QString pkgDataPath();
348 
350  static QString activeThemePath();
351 
353  static QString defaultThemePath();
354 
359  static QString iconPath( const QString &iconFile );
360 
365  static QIcon getThemeIcon( const QString &name );
366 
371  enum Cursor
372  {
380  };
381 
388  static QCursor getThemeCursor( Cursor cursor );
389 
398  static QPixmap getThemePixmap( const QString &name, const QColor &foreColor = QColor(), const QColor &backColor = QColor(), int size = 16 );
399 
401  static QString userStylePath();
402 
404  static QRegExp shortNameRegExp();
405 
411  static QString userLoginName();
412 
418  static QString userFullName();
419 
425  static QString osName();
426 
432  static QString platform();
433 
438  static QString locale();
439 
441  static QString userThemesFolder();
442 
444  static QString defaultStylePath();
445 
447  static QString defaultThemesFolder();
448 
450  static QString libraryPath();
451 
453  static QString libexecPath();
454 
461  static QString qmlImportPath();
462 
464  static void setPrefixPath( const QString &prefixPath, bool useDefaultPaths = false );
465 
467  static void setPluginPath( const QString &pluginPath );
468 
470  static void setPkgDataPath( const QString &pkgDataPath );
471 
473  static void setDefaultSvgPaths( const QStringList &pathList );
474 
476  static void setAuthDatabaseDirPath( const QString &authDbDirPath );
477 
479  static void initQgis();
480 
482  static bool createDatabase( QString *errorMessage = nullptr );
483 
485  static bool createThemeFolder();
486 
488  static void exitQgis();
489 
491  static QString appIconPath();
492 
494  enum endian_t
495  {
496  XDR = 0, // network, or big-endian, byte order
497  NDR = 1 // little-endian byte order
498  };
499 
501  static endian_t endian();
502 
517  static QString reportStyleSheet( QgsApplication::StyleSheetType styleSheetType = QgsApplication::StyleSheetType::Qt );
518 
523  static QString showSettings();
524 
532  static void registerOgrDrivers();
533 
535  static QString absolutePathToRelativePath( const QString &apath, const QString &targetPath );
537  static QString relativePathToAbsolutePath( const QString &rpath, const QString &targetPath );
538 
540  static bool isRunningFromBuildDir() { return ABISYM( mRunningFromBuildDir ); }
541 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
542  static QString cfgIntDir() SIP_SKIP;
543 #endif
545  static QString buildSourcePath();
547  static QString buildOutputPath();
548 
554  static void skipGdalDriver( const QString &driver );
555 
561  static void restoreGdalDriver( const QString &driver );
562 
567  static QStringList skippedGdalDrivers();
568 
575  static void applyGdalSkippedDrivers();
576 
581  static void registerGdalDriversFromSettings();
582 
589  static QStringList deferredSkippedGdalDrivers();
590 
597  static void setSkippedGdalDrivers( const QStringList &skippedGdalDrivers,
598  const QStringList &deferredSkippedGdalDrivers );
599 
604  static int maxThreads();
605 
611  static void setMaxThreads( int maxThreads );
612 
618  static QgsTaskManager *taskManager();
619 
624  static QgsColorSchemeRegistry *colorSchemeRegistry() SIP_KEEPREFERENCE;
625 
630  static QgsPaintEffectRegistry *paintEffectRegistry() SIP_KEEPREFERENCE;
631 
636  static QgsRendererRegistry *rendererRegistry() SIP_KEEPREFERENCE;
637 
643  static QgsRasterRendererRegistry *rasterRendererRegistry() SIP_SKIP;
644 
649  static QgsPointCloudRendererRegistry *pointCloudRendererRegistry() SIP_KEEPREFERENCE;
650 
656  static QgsDataItemProviderRegistry *dataItemProviderRegistry() SIP_KEEPREFERENCE;
657 
664  static QgsCoordinateReferenceSystemRegistry *coordinateReferenceSystemRegistry() SIP_KEEPREFERENCE;
665 
673  static QgsSvgCache *svgCache();
674 
681  static QgsImageCache *imageCache();
682 
688  static QgsSourceCache *sourceCache();
689 
694  static QgsNetworkContentFetcherRegistry *networkContentFetcherRegistry() SIP_KEEPREFERENCE;
695 
700  static QgsValidityCheckRegistry *validityCheckRegistry() SIP_KEEPREFERENCE;
701 
706  static QgsSymbolLayerRegistry *symbolLayerRegistry() SIP_KEEPREFERENCE;
707 
712  static QgsCalloutRegistry *calloutRegistry() SIP_KEEPREFERENCE;
713 
718  static QgsLayoutItemRegistry *layoutItemRegistry() SIP_KEEPREFERENCE;
719 
724  static QgsAnnotationItemRegistry *annotationItemRegistry() SIP_KEEPREFERENCE;
725 
730  static QgsGpsConnectionRegistry *gpsConnectionRegistry() SIP_KEEPREFERENCE;
731 
736  static QgsPluginLayerRegistry *pluginLayerRegistry() SIP_KEEPREFERENCE;
737 
742  static QgsClassificationMethodRegistry *classificationMethodRegistry() SIP_KEEPREFERENCE;
743 
748  static QgsBookmarkManager *bookmarkManager();
749 
755  static QgsTileDownloadManager *tileDownloadManager() SIP_SKIP;
756 
764  static QgsStyleModel *defaultStyleModel();
765 
770  static QgsMessageLog *messageLog();
771 
778  static QgsAuthManager *authManager();
779 
785  static QgsProcessingRegistry *processingRegistry();
786 
791  static QgsPageSizeRegistry *pageSizeRegistry() SIP_KEEPREFERENCE;
792 
798  static QgsAnnotationRegistry *annotationRegistry() SIP_SKIP;
799 
805  static QgsActionScopeRegistry *actionScopeRegistry() SIP_KEEPREFERENCE;
806 
811  static QgsConnectionRegistry *connectionRegistry();
812 
817  static QgsRuntimeProfiler *profiler();
818 
824  static QgsNumericFormatRegistry *numericFormatRegistry() SIP_KEEPREFERENCE;
825 
829  static QgsFieldFormatterRegistry *fieldFormatterRegistry() SIP_KEEPREFERENCE;
830 
835  static Qgs3DRendererRegistry *renderer3DRegistry() SIP_KEEPREFERENCE;
836 
841  static Qgs3DSymbolRegistry *symbol3DRegistry() SIP_KEEPREFERENCE;
842 
848  static QgsScaleBarRendererRegistry *scaleBarRendererRegistry() SIP_KEEPREFERENCE;
849 
854  static QgsProjectStorageRegistry *projectStorageRegistry() SIP_KEEPREFERENCE;
855 
863  static QgsLocalizedDataPathRegistry *localizedDataPathRegistry() SIP_KEEPREFERENCE;
864 
873  static QString nullRepresentation();
874 
878  static void setNullRepresentation( const QString &nullRepresentation );
879 
887  static QVariantMap customVariables();
888 
896  static void setCustomVariables( const QVariantMap &customVariables );
897 
903  static void setCustomVariable( const QString &name, const QVariant &value );
904 
914  static int scaleIconSize( int standardSize, bool applyDevicePixelRatio = false );
915 
924  int maxConcurrentConnectionsPerPool() const;
925 
931  static void setTranslation( const QString &translation );
932 
938  void collectTranslatableObjects( QgsTranslationContext *translationContext );
939 
940 #ifdef SIP_RUN
941  SIP_IF_FEATURE( ANDROID )
942  //dummy method to workaround sip generation issue
943  bool x11EventFilter( XEvent *event );
944  SIP_END
945 #endif
946 
947  signals:
949  void preNotify( QObject *receiver, QEvent *event, bool *done ) SIP_SKIP;
950 
956 
957 
962 
970 
971  private:
972 
973  static void copyPath( const QString &src, const QString &dst );
974  static QObject *ABISYM( mFileOpenEventReceiver );
975 
976  static bool ABISYM( mInitialized );
977 
979  static bool ABISYM( mRunningFromBuildDir );
980 
984  static int ABISYM( sMaxThreads );
985 
986  QMap<QString, QIcon> mIconCache;
987  QMap<Cursor, QCursor> mCursorCache;
988 
989  QTranslator *mQgisTranslator = nullptr;
990  QTranslator *mQtTranslator = nullptr;
991 
992  QgsDataItemProviderRegistry *mDataItemProviderRegistry = nullptr;
993  QgsAuthManager *mAuthManager = nullptr;
994 
995  struct ApplicationMembers
996  {
997  QgsCoordinateReferenceSystemRegistry *mCrsRegistry = nullptr;
998  Qgs3DRendererRegistry *m3DRendererRegistry = nullptr;
999  Qgs3DSymbolRegistry *m3DSymbolRegistry = nullptr;
1000  QgsActionScopeRegistry *mActionScopeRegistry = nullptr;
1001  QgsAnnotationRegistry *mAnnotationRegistry = nullptr;
1002  QgsColorSchemeRegistry *mColorSchemeRegistry = nullptr;
1003  QgsLocalizedDataPathRegistry *mLocalizedDataPathRegistry = nullptr;
1004  QgsNumericFormatRegistry *mNumericFormatRegistry = nullptr;
1005  QgsFieldFormatterRegistry *mFieldFormatterRegistry = nullptr;
1006  QgsGpsConnectionRegistry *mGpsConnectionRegistry = nullptr;
1007  QgsNetworkContentFetcherRegistry *mNetworkContentFetcherRegistry = nullptr;
1008  QgsScaleBarRendererRegistry *mScaleBarRendererRegistry = nullptr;
1009  QgsValidityCheckRegistry *mValidityCheckRegistry = nullptr;
1010  QgsMessageLog *mMessageLog = nullptr;
1011  QgsPaintEffectRegistry *mPaintEffectRegistry = nullptr;
1012  QgsPluginLayerRegistry *mPluginLayerRegistry = nullptr;
1013  QgsClassificationMethodRegistry *mClassificationMethodRegistry = nullptr;
1014  QgsProcessingRegistry *mProcessingRegistry = nullptr;
1015  QgsConnectionRegistry *mConnectionRegistry = nullptr;
1016  QgsProjectStorageRegistry *mProjectStorageRegistry = nullptr;
1017  QgsPageSizeRegistry *mPageSizeRegistry = nullptr;
1018  QgsRasterRendererRegistry *mRasterRendererRegistry = nullptr;
1019  QgsRendererRegistry *mRendererRegistry = nullptr;
1020  QgsPointCloudRendererRegistry *mPointCloudRendererRegistry = nullptr;
1021  QgsSvgCache *mSvgCache = nullptr;
1022  QgsImageCache *mImageCache = nullptr;
1023  QgsSourceCache *mSourceCache = nullptr;
1024  QgsSymbolLayerRegistry *mSymbolLayerRegistry = nullptr;
1025  QgsCalloutRegistry *mCalloutRegistry = nullptr;
1026  QgsTaskManager *mTaskManager = nullptr;
1027  QgsLayoutItemRegistry *mLayoutItemRegistry = nullptr;
1028  QgsAnnotationItemRegistry *mAnnotationItemRegistry = nullptr;
1029  QgsUserProfileManager *mUserConfigManager = nullptr;
1030  QgsBookmarkManager *mBookmarkManager = nullptr;
1031  QgsTileDownloadManager *mTileDownloadManager = nullptr;
1032  QgsStyleModel *mStyleModel = nullptr;
1033  QString mNullRepresentation;
1034  QStringList mSvgPathCache;
1035  bool mSvgPathCacheValid = false;
1036 
1037  ApplicationMembers();
1038  ~ApplicationMembers();
1039  };
1040 
1041  // Applications members which belong to an instance of QgsApplication
1042  ApplicationMembers *mApplicationMembers = nullptr;
1043  // ... but in case QgsApplication is never instantiated (eg with custom designer widgets), we fall back to static members
1044  static ApplicationMembers *sApplicationMembers;
1045 
1046  static QgsAuthManager *sAuthManager;
1047 
1048  static ApplicationMembers *members();
1049 
1050  static void invalidateCaches();
1051 };
1052 
1053 // clazy:excludeall=qstring-allocations
1054 
1055 #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)