QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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
QgsApplication::QGIS_ORGANIZATION_NAME
static const char * QGIS_ORGANIZATION_NAME
Definition: qgsapplication.h:147
QgsConnectionRegistry
Definition: qgsconnectionregistry.h:38
QgsGpsConnectionRegistry
Definition: qgsgpsconnectionregistry.h:36
QgsApplication::Cursor
Cursor
The Cursor enum defines constants for QGIS custom cursors.
Definition: qgsapplication.h:355
qgstranslationcontext.h
QgsApplication::WebBrowser
@ WebBrowser
StyleSheet for Qt GUI widgets (based on QLabel or QTextBrowser), supports basic CSS and Qt extensions...
Definition: qgsapplication.h:144
QgsRuntimeProfiler
Definition: qgsruntimeprofiler.h:31
QgsStyleModel
Definition: qgsstylemodel.h:45
QgsApplication::CrossHair
@ CrossHair
Precisely identify a point on the canvas.
Definition: qgsapplication.h:360
QgsNumericFormatRegistry
Definition: qgsnumericformatregistry.h:38
QgsApplication::Sampler
@ Sampler
Color/Value picker.
Definition: qgsapplication.h:363
QgsDataItemProviderRegistry
Definition: qgsdataitemproviderregistry.h:39
QgsActionScopeRegistry
Definition: qgsactionscoperegistry.h:39
QgsBookmarkManager
Manages storage of a set of bookmarks.
Definition: qgsbookmarkmanager.h:144
QgsSymbolLayerRegistry
Definition: qgssymbollayerregistry.h:144
QgsPageSizeRegistry
A registry for known page sizes.
Definition: qgspagesizeregistry.h:73
SIP_KEEPREFERENCE
#define SIP_KEEPREFERENCE
Definition: qgis_sip.h:86
QgsCalloutRegistry
Definition: qgscalloutsregistry.h:155
Qgs3DRendererRegistry
Keeps track of available 3D renderers.
Definition: qgs3drendererregistry.h:69
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsMessageLog
Definition: qgsmessagelog.h:38
QgsAuthManager
Definition: qgsauthmanager.h:64
QgsClassificationMethodRegistry
Definition: qgsclassificationmethodregistry.h:38
QgsSvgCache
Definition: qgssvgcache.h:107
QgsTaskManager
Task manager for managing a set of long-running QgsTask tasks. This class can be created directly,...
Definition: qgstaskmanager.h:388
qgis_sip.h
QgsApplication::endian_t
endian_t
Constants for endian-ness.
Definition: qgsapplication.h:474
QgsPaintEffectRegistry
Registry of available paint effects.
Definition: qgspainteffectregistry.h:174
QgsTranslationContext
Used for the collecting of strings from projects for translation and creation of ts files.
Definition: qgstranslationcontext.h:35
QgsApplication::QGIS_APPLICATION_NAME
static const char * QGIS_APPLICATION_NAME
Definition: qgsapplication.h:149
QgsScaleBarRendererRegistry
Definition: qgsscalebarrendererregistry.h:33
QgsApplication::Select
@ Select
Select a rectangle.
Definition: qgsapplication.h:362
QgsApplication::isRunningFromBuildDir
static bool isRunningFromBuildDir()
Indicates whether running from build directory (not installed)
Definition: qgsapplication.h:519
QgsApplication::StyleSheetType
StyleSheetType
The StyleSheetType enum represents the stylesheet type that a widget supports.
Definition: qgsapplication.h:141
QgsApplication
Definition: qgsapplication.h:78
QgsColorSchemeRegistry
Registry of color schemes.
Definition: qgscolorschemeregistry.h:34
SIP_IF_FEATURE
#define SIP_IF_FEATURE(feature)
Definition: qgis_sip.h:162
QgsLocalizedDataPathRegistry
Definition: qgslocalizeddatapathregistry.h:41
QgsProjectStorageRegistry
Definition: qgsprojectstorageregistry.h:33
QgsRasterRendererRegistry
Definition: qgsrasterrendererregistry.h:69
QgsApplication::ZoomIn
@ ZoomIn
Zoom in.
Definition: qgsapplication.h:357
QgsApplication::Identify
@ Identify
Identify: obtain information about the object.
Definition: qgsapplication.h:359
QgsUserProfile
Definition: qgsuserprofile.h:34
ABISYM
QObject * ABISYM(QgsApplication::mFileOpenEventReceiver)
QgsApplication::CapturePoint
@ CapturePoint
Select and capture a point or a feature.
Definition: qgsapplication.h:361
QgsApplication::Qt
@ Qt
Definition: qgsapplication.h:143
QgsProcessingRegistry
Definition: qgsprocessingregistry.h:39
QgsLayoutItemRegistry
Registry of available layout item types.
Definition: qgslayoutitemregistry.h:299
QgsImageCache
Definition: qgsimagecache.h:96
QgsRendererRegistry
Registry of renderers.
Definition: qgsrendererregistry.h:223
QgsValidityCheckRegistry
Definition: qgsvaliditycheckregistry.h:36
SIP_END
#define SIP_END
Definition: qgis_sip.h:189
QgsApplication::QGIS_ORGANIZATION_DOMAIN
static const char * QGIS_ORGANIZATION_DOMAIN
Definition: qgsapplication.h:148
QgsPluginLayerRegistry
Definition: qgspluginlayerregistry.h:68
QgsFieldFormatterRegistry
Definition: qgsfieldformatterregistry.h:37
QgsUserProfileManager
Definition: qgsuserprofilemanager.h:41
QgsApplication::ZoomOut
@ ZoomOut
Zoom out.
Definition: qgsapplication.h:358
QgsNetworkContentFetcherRegistry
Registry for temporary fetched files.
Definition: qgsnetworkcontentfetcherregistry.h:123