QGIS API Documentation  3.13.0-Master (9729a43df7)
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 
23 #include "qgis_sip.h"
24 #include "qgsconfig.h"
25 #include "qgstranslationcontext.h"
26 
29 class QgsRuntimeProfiler;
30 class QgsTaskManager;
37 class QgsSvgCache;
38 class QgsImageCache;
45 class QgsMessageLog;
47 class QgsAnnotationRegistry;
48 class QgsUserProfile;
52 class QgsAuthManager;
55 class QTranslator;
56 class QgsCalloutRegistry;
57 class QgsBookmarkManager;
58 class QgsStyleModel;
62 
78 class CORE_EXPORT QgsApplication : public QApplication
79 {
80 
81 #ifdef SIP_RUN
82  % TypeCode
83  // Convert a Python argv list to a conventional C argc count and argv array.
84  static char **qtgui_ArgvToC( PyObject *argvlist, int &argc )
85  {
86  char **argv;
87 
88  argc = PyList_GET_SIZE( argvlist );
89 
90  // Allocate space for two copies of the argument pointers, plus the
91  // terminating NULL.
92  if ( ( argv = ( char ** )sipMalloc( 2 * ( argc + 1 ) * sizeof( char * ) ) ) == NULL )
93  return NULL;
94 
95  // Convert the list.
96  for ( int a = 0; a < argc; ++a )
97  {
98  char *arg;
99  // Get the argument and allocate memory for it.
100  if ( ( arg = PyBytes_AsString( PyList_GET_ITEM( argvlist, a ) ) ) == NULL ||
101  ( argv[a] = ( char * )sipMalloc( strlen( arg ) + 1 ) ) == NULL )
102  return NULL;
103  // Copy the argument and save a pointer to it.
104  strcpy( argv[a], arg );
105  argv[a + argc + 1] = argv[a];
106  }
107 
108  argv[argc + argc + 1] = argv[argc] = NULL;
109 
110  return argv;
111  }
112 
113  // Remove arguments from the Python argv list that have been removed from the
114  // C argv array.
115  static void qtgui_UpdatePyArgv( PyObject *argvlist, int argc, char **argv )
116  {
117  for ( int a = 0, na = 0; a < argc; ++a )
118  {
119  // See if it was removed.
120  if ( argv[na] == argv[a + argc + 1] )
121  ++na;
122  else
123  PyList_SetSlice( argvlist, na, na + 1, NULL );
124  }
125  }
126  % End
127 #endif
128 
129  Q_OBJECT
130 
131  public:
132 
142  {
143  Qt,
145  };
146 
147  static const char *QGIS_ORGANIZATION_NAME;
148  static const char *QGIS_ORGANIZATION_DOMAIN;
149  static const char *QGIS_APPLICATION_NAME;
150 #ifndef SIP_RUN
151  QgsApplication( int &argc, char **argv, bool GUIenabled, const QString &profileFolder = QString(), const QString &platformName = "desktop" );
152 #else
153  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" )];
154  % MethodCode
155  // The Python interface is a list of argument strings that is modified.
156 
157  int argc;
158  char **argv;
159 
160  // Convert the list.
161  if ( ( argv = qtgui_ArgvToC( a0, argc ) ) == NULL )
162  sipIsErr = 1;
163  else
164  {
165  // Create it now the arguments are right.
166  static int nargc = argc;
167 
168  sipCpp = new sipQgsApplication( nargc, argv, a1, *a2, *a3 );
169 
170  // Now modify the original list.
171  qtgui_UpdatePyArgv( a0, argc, argv );
172  }
173  % End
174 #endif
175 
176  ~QgsApplication() override;
177 
183  static QgsApplication *instance();
184 
192  static void init( QString profileFolder = QString() ) SIP_SKIP;
193 
195  bool event( QEvent *event ) override;
196 
198  bool notify( QObject *receiver, QEvent *event ) override;
199 
201  static void setFileOpenEventReceiver( QObject *receiver );
202 
213  static void setThemeName( const QString &themeName );
214 
219  static QString resolvePkgPath();
220 
228  static QString themeName();
229 
237  static void setUITheme( const QString &themeName );
238 
245  static QHash<QString, QString> uiThemes();
246 
248  static QString authorsFilePath();
249 
254  static QString contributorsFilePath();
255 
261  static QString developersMapFilePath();
262 
264  static QString sponsorsFilePath();
265 
267  static QString donorsFilePath();
268 
270  static QString serverResourcesPath();
271 
275  static QString translatorsFilePath();
276 
280  static QString licenceFilePath();
281 
283  static QString i18nPath();
284 
289  static QString metadataPath();
290 
292  static QString qgisMasterDatabaseFilePath();
293 
295  static QString qgisSettingsDirPath();
296 
298  static QString qgisUserDatabaseFilePath();
299 
301  static QString qgisAuthDatabaseFilePath();
302 
304  static QString splashPath();
305 
307  static QString iconsPath();
308 
310  static QString srsDatabaseFilePath();
311 
313  static QStringList svgPaths();
314 
319  static QStringList layoutTemplatePaths();
320 
322  static QMap<QString, QString> systemEnvVars();
323 
325  static QString prefixPath();
326 
328  static QString pluginPath();
329 
331  static QString pkgDataPath();
332 
334  static QString activeThemePath();
335 
337  static QString defaultThemePath();
338 
343  static QString iconPath( const QString &iconFile );
344 
349  static QIcon getThemeIcon( const QString &name );
350 
355  enum Cursor
356  {
364  };
365 
372  static QCursor getThemeCursor( Cursor cursor );
373 
378  static QPixmap getThemePixmap( const QString &name );
379 
381  static QString userStylePath();
382 
384  static QRegExp shortNameRegExp();
385 
391  static QString userLoginName();
392 
398  static QString userFullName();
399 
405  static QString osName();
406 
412  static QString platform();
413 
418  static QString locale();
419 
421  static QString userThemesFolder();
422 
424  static QString defaultStylePath();
425 
427  static QString defaultThemesFolder();
428 
430  static QString libraryPath();
431 
433  static QString libexecPath();
434 
441  static QString qmlImportPath();
442 
444  static void setPrefixPath( const QString &prefixPath, bool useDefaultPaths = false );
445 
447  static void setPluginPath( const QString &pluginPath );
448 
450  static void setPkgDataPath( const QString &pkgDataPath );
451 
453  static void setDefaultSvgPaths( const QStringList &pathList );
454 
456  static void setAuthDatabaseDirPath( const QString &authDbDirPath );
457 
459  static void initQgis();
460 
462  static bool createDatabase( QString *errorMessage = nullptr );
463 
465  static bool createThemeFolder();
466 
468  static void exitQgis();
469 
471  static QString appIconPath();
472 
474  enum endian_t
475  {
476  XDR = 0, // network, or big-endian, byte order
477  NDR = 1 // little-endian byte order
478  };
479 
481  static endian_t endian();
482 
497  static QString reportStyleSheet( QgsApplication::StyleSheetType styleSheetType = QgsApplication::StyleSheetType::Qt );
498 
502  static QString showSettings();
503 
511  static void registerOgrDrivers();
512 
514  static QString absolutePathToRelativePath( const QString &apath, const QString &targetPath );
516  static QString relativePathToAbsolutePath( const QString &rpath, const QString &targetPath );
517 
519  static bool isRunningFromBuildDir() { return ABISYM( mRunningFromBuildDir ); }
520 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
521  static QString cfgIntDir() SIP_SKIP;
522 #endif
523  static QString buildSourcePath();
526  static QString buildOutputPath();
527 
533  static void skipGdalDriver( const QString &driver );
534 
540  static void restoreGdalDriver( const QString &driver );
541 
546  static QStringList skippedGdalDrivers();
547 
554  static void applyGdalSkippedDrivers();
555 
560  static void registerGdalDriversFromSettings();
561 
568  static QStringList deferredSkippedGdalDrivers();
569 
576  static void setSkippedGdalDrivers( const QStringList &skippedGdalDrivers,
577  const QStringList &deferredSkippedGdalDrivers );
578 
582  static int maxThreads();
583 
588  static void setMaxThreads( int maxThreads );
589 
595  static QgsTaskManager *taskManager();
596 
601  static QgsColorSchemeRegistry *colorSchemeRegistry() SIP_KEEPREFERENCE;
602 
607  static QgsPaintEffectRegistry *paintEffectRegistry() SIP_KEEPREFERENCE;
608 
613  static QgsRendererRegistry *rendererRegistry() SIP_KEEPREFERENCE;
614 
620  static QgsRasterRendererRegistry *rasterRendererRegistry() SIP_SKIP;
621 
627  static QgsDataItemProviderRegistry *dataItemProviderRegistry() SIP_KEEPREFERENCE;
628 
636  static QgsSvgCache *svgCache();
637 
644  static QgsImageCache *imageCache();
645 
650  static QgsNetworkContentFetcherRegistry *networkContentFetcherRegistry() SIP_KEEPREFERENCE;
651 
656  static QgsValidityCheckRegistry *validityCheckRegistry() SIP_KEEPREFERENCE;
657 
662  static QgsSymbolLayerRegistry *symbolLayerRegistry() SIP_KEEPREFERENCE;
663 
668  static QgsCalloutRegistry *calloutRegistry() SIP_KEEPREFERENCE;
669 
674  static QgsLayoutItemRegistry *layoutItemRegistry() SIP_KEEPREFERENCE;
675 
680  static QgsGpsConnectionRegistry *gpsConnectionRegistry() SIP_KEEPREFERENCE;
681 
686  static QgsPluginLayerRegistry *pluginLayerRegistry() SIP_KEEPREFERENCE;
687 
692  static QgsClassificationMethodRegistry *classificationMethodRegistry() SIP_KEEPREFERENCE;
693 
698  static QgsBookmarkManager *bookmarkManager();
699 
707  static QgsStyleModel *defaultStyleModel();
708 
713  static QgsMessageLog *messageLog();
714 
721  static QgsAuthManager *authManager();
722 
728  static QgsProcessingRegistry *processingRegistry();
729 
734  static QgsPageSizeRegistry *pageSizeRegistry() SIP_KEEPREFERENCE;
735 
741  static QgsAnnotationRegistry *annotationRegistry() SIP_SKIP;
742 
748  static QgsActionScopeRegistry *actionScopeRegistry() SIP_KEEPREFERENCE;
749 
754  static QgsConnectionRegistry *connectionRegistry();
755 
760  static QgsRuntimeProfiler *profiler();
761 
767  static QgsNumericFormatRegistry *numericFormatRegistry() SIP_KEEPREFERENCE;
768 
772  static QgsFieldFormatterRegistry *fieldFormatterRegistry() SIP_KEEPREFERENCE;
773 
778  static Qgs3DRendererRegistry *renderer3DRegistry() SIP_KEEPREFERENCE;
779 
785  static QgsScaleBarRendererRegistry *scaleBarRendererRegistry() SIP_KEEPREFERENCE;
786 
791  static QgsProjectStorageRegistry *projectStorageRegistry() SIP_KEEPREFERENCE;
792 
800  static QgsLocalizedDataPathRegistry *localizedDataPathRegistry() SIP_KEEPREFERENCE;
801 
810  static QString nullRepresentation();
811 
815  static void setNullRepresentation( const QString &nullRepresentation );
816 
824  static QVariantMap customVariables();
825 
833  static void setCustomVariables( const QVariantMap &customVariables );
834 
840  static void setCustomVariable( const QString &name, const QVariant &value );
841 
850  int maxConcurrentConnectionsPerPool() const;
851 
857  static void setTranslation( const QString &translation );
858 
864  void collectTranslatableObjects( QgsTranslationContext *translationContext );
865 
866 #ifdef SIP_RUN
867  SIP_IF_FEATURE( ANDROID )
868  //dummy method to workaround sip generation issue
869  bool x11EventFilter( XEvent *event );
870  SIP_END
871 #endif
872 
873  signals:
875  void preNotify( QObject *receiver, QEvent *event, bool *done ) SIP_SKIP;
876 
881  void customVariablesChanged();
882 
883 
887  void nullRepresentationChanged();
888 
895  void requestForTranslatableObjects( QgsTranslationContext *translationContext );
896 
897  private:
898 
899  static void copyPath( const QString &src, const QString &dst );
900  static QObject *ABISYM( mFileOpenEventReceiver );
901 
902  static bool ABISYM( mInitialized );
903 
905  static bool ABISYM( mRunningFromBuildDir );
906 
909  static int ABISYM( sMaxThreads );
910 
911  QMap<QString, QIcon> mIconCache;
912  QMap<Cursor, QCursor> mCursorCache;
913 
914  QTranslator *mQgisTranslator = nullptr;
915  QTranslator *mQtTranslator = nullptr;
916 
917  QgsDataItemProviderRegistry *mDataItemProviderRegistry = nullptr;
918  QgsAuthManager *mAuthManager = nullptr;
919 
920  struct ApplicationMembers
921  {
922  Qgs3DRendererRegistry *m3DRendererRegistry = nullptr;
923  QgsActionScopeRegistry *mActionScopeRegistry = nullptr;
924  QgsAnnotationRegistry *mAnnotationRegistry = nullptr;
925  QgsColorSchemeRegistry *mColorSchemeRegistry = nullptr;
926  QgsLocalizedDataPathRegistry *mLocalizedDataPathRegistry = nullptr;
927  QgsNumericFormatRegistry *mNumericFormatRegistry = nullptr;
928  QgsFieldFormatterRegistry *mFieldFormatterRegistry = nullptr;
929  QgsGpsConnectionRegistry *mGpsConnectionRegistry = nullptr;
930  QgsNetworkContentFetcherRegistry *mNetworkContentFetcherRegistry = nullptr;
931  QgsScaleBarRendererRegistry *mScaleBarRendererRegistry = nullptr;
932  QgsValidityCheckRegistry *mValidityCheckRegistry = nullptr;
933  QgsMessageLog *mMessageLog = nullptr;
934  QgsPaintEffectRegistry *mPaintEffectRegistry = nullptr;
935  QgsPluginLayerRegistry *mPluginLayerRegistry = nullptr;
936  QgsClassificationMethodRegistry *mClassificationMethodRegistry = nullptr;
937  QgsProcessingRegistry *mProcessingRegistry = nullptr;
938  QgsConnectionRegistry *mConnectionRegistry = nullptr;
939  QgsProjectStorageRegistry *mProjectStorageRegistry = nullptr;
940  QgsPageSizeRegistry *mPageSizeRegistry = nullptr;
941  QgsRasterRendererRegistry *mRasterRendererRegistry = nullptr;
942  QgsRendererRegistry *mRendererRegistry = nullptr;
943  QgsRuntimeProfiler *mProfiler = nullptr;
944  QgsSvgCache *mSvgCache = nullptr;
945  QgsImageCache *mImageCache = nullptr;
946  QgsSymbolLayerRegistry *mSymbolLayerRegistry = nullptr;
947  QgsCalloutRegistry *mCalloutRegistry = nullptr;
948  QgsTaskManager *mTaskManager = nullptr;
949  QgsLayoutItemRegistry *mLayoutItemRegistry = nullptr;
950  QgsUserProfileManager *mUserConfigManager = nullptr;
951  QgsBookmarkManager *mBookmarkManager = nullptr;
952  QgsStyleModel *mStyleModel = nullptr;
953  QString mNullRepresentation;
954 
955  ApplicationMembers();
956  ~ApplicationMembers();
957  };
958 
959  // Applications members which belong to an instance of QgsApplication
960  ApplicationMembers *mApplicationMembers = nullptr;
961  // ... but in case QgsApplication is never instantiated (eg with custom designer widgets), we fall back to static members
962  static ApplicationMembers *sApplicationMembers;
963 
964  static QgsAuthManager *sAuthManager;
965 
966  static ApplicationMembers *members();
967 
968  static void invalidateCaches();
969 };
970 
971 // clazy:excludeall=qstring-allocations
972 
973 #endif
A QAbstractItemModel subclass for showing symbol and color ramp entities contained within a QgsStyle ...
Definition: qgsstylemodel.h:45
Singleton offering an interface to manage the authentication configuration database and to utilize co...
This class keeps a list of data item providers that may add items to the browser tree.
Extends QApplication to provide access to QGIS specific resources such as theme paths, database paths etc.
Cursor
The Cursor enum defines constants for QGIS custom cursors.
Registry of color schemes.
A registry of plugin layers types.
A registry class to hold localized data paths which can be used for basemaps, logos, etc.
A cache for images / pictures derived from svg files.
Definition: qgssvgcache.h:107
Registry of renderers.
Registry for raster renderers.
StyleSheet for Qt GUI widgets (based on QLabel or QTextBrowser), supports basic CSS and Qt extensions...
User profile contains information about the user profile folders on the machine.
Precisely identify a point on the canvas.
Manages storage of a set of bookmarks.
The QgsFieldFormatterRegistry manages registered classes of QgsFieldFormatter.
This class keeps a list of QgsAbstractValidityCheck checks which can be used when performing validity...
static bool isRunningFromBuildDir()
Indicates whether running from build directory (not installed)
Color/Value picker.
endian_t
Constants for endian-ness.
Keeps track of available 3D renderers.
Registry of available symbol layer classes.
#define SIP_SKIP
Definition: qgis_sip.h:126
Registry for temporary fetched files.
#define SIP_END
Definition: qgis_sip.h:189
#define SIP_KEEPREFERENCE
Definition: qgis_sip.h:86
A registry for known page sizes.
static const char * QGIS_ORGANIZATION_NAME
This class manages all known classification methods.
Task manager for managing a set of long-running QgsTask tasks.
Used for the collecting of strings from projects for translation and creation of ts files...
#define SIP_IF_FEATURE(feature)
Definition: qgis_sip.h:162
Select a rectangle.
StyleSheetType
The StyleSheetType enum represents the stylesheet type that a widget supports.
Identify: obtain information about the object.
Registry for various processing components, including providers, algorithms and various parameters an...
static const char * QGIS_ORGANIZATION_DOMAIN
Registry of available layout item types.
The QgsScaleBarRendererRegistry manages registered scalebar renderers.
The QgsNumericFormatRegistry manages registered classes of QgsNumericFormat.
A class to register / unregister existing GPS connections such that the information is available to a...
Registry of available callout classes.
QObject * ABISYM(QgsApplication::mFileOpenEventReceiver)
A cache for images derived from raster files.
Definition: qgsimagecache.h:96
Registry of storage backends that QgsProject may use.
A registry for saved data provider connections, allowing retrieval of saved connections by name and p...
The action scope registry is an application wide registry that contains a list of available action sc...
static const char * QGIS_APPLICATION_NAME
User profile manager is used to manager list, and manage user profiles on the users machine...
Interface for logging messages from QGIS in GUI independent way.
Definition: qgsmessagelog.h:38
Select and capture a point or a feature.
Registry of available paint effects.