QGIS API Documentation  3.17.0-Master (a035f434f4)
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;
67 
83 class CORE_EXPORT QgsApplication : public QApplication
84 {
85 
86 #ifdef SIP_RUN
87  % TypeCode
88  // Convert a Python argv list to a conventional C argc count and argv array.
89  static char **qtgui_ArgvToC( PyObject *argvlist, int &argc )
90  {
91  char **argv;
92 
93  argc = PyList_GET_SIZE( argvlist );
94 
95  // Allocate space for two copies of the argument pointers, plus the
96  // terminating NULL.
97  if ( ( argv = ( char ** )sipMalloc( 2 * ( argc + 1 ) * sizeof( char * ) ) ) == NULL )
98  return NULL;
99 
100  // Convert the list.
101  for ( int a = 0; a < argc; ++a )
102  {
103  char *arg;
104  // Get the argument and allocate memory for it.
105  if ( ( arg = PyBytes_AsString( PyList_GET_ITEM( argvlist, a ) ) ) == NULL ||
106  ( argv[a] = ( char * )sipMalloc( strlen( arg ) + 1 ) ) == NULL )
107  return NULL;
108  // Copy the argument and save a pointer to it.
109  strcpy( argv[a], arg );
110  argv[a + argc + 1] = argv[a];
111  }
112 
113  argv[argc + argc + 1] = argv[argc] = NULL;
114 
115  return argv;
116  }
117 
118  // Remove arguments from the Python argv list that have been removed from the
119  // C argv array.
120  static void qtgui_UpdatePyArgv( PyObject *argvlist, int argc, char **argv )
121  {
122  for ( int a = 0, na = 0; a < argc; ++a )
123  {
124  // See if it was removed.
125  if ( argv[na] == argv[a + argc + 1] )
126  ++na;
127  else
128  PyList_SetSlice( argvlist, na, na + 1, NULL );
129  }
130  }
131  % End
132 #endif
133 
134  Q_OBJECT
135 
136  public:
137 
147  {
148  Qt,
150  };
151 
152  static const char *QGIS_ORGANIZATION_NAME;
153  static const char *QGIS_ORGANIZATION_DOMAIN;
154  static const char *QGIS_APPLICATION_NAME;
155 #ifndef SIP_RUN
156  QgsApplication( int &argc, char **argv, bool GUIenabled, const QString &profileFolder = QString(), const QString &platformName = "desktop" );
157 #else
158  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" )];
159  % MethodCode
160  // The Python interface is a list of argument strings that is modified.
161 
162  int argc;
163  char **argv;
164 
165  // Convert the list.
166  if ( ( argv = qtgui_ArgvToC( a0, argc ) ) == NULL )
167  sipIsErr = 1;
168  else
169  {
170  // Create it now the arguments are right.
171  static int nargc = argc;
172 
173  sipCpp = new sipQgsApplication( nargc, argv, a1, *a2, *a3 );
174 
175  // Now modify the original list.
176  qtgui_UpdatePyArgv( a0, argc, argv );
177  }
178  % End
179 #endif
180 
181  ~QgsApplication() override;
182 
188  static QgsApplication *instance();
189 
197  static void init( QString profileFolder = QString() ) SIP_SKIP;
198 
200  bool event( QEvent *event ) override;
201 
203  bool notify( QObject *receiver, QEvent *event ) override;
204 
206  static void setFileOpenEventReceiver( QObject *receiver );
207 
218  static void setThemeName( const QString &themeName );
219 
224  static QString resolvePkgPath();
225 
233  static QString themeName();
234 
242  static void setUITheme( const QString &themeName );
243 
250  static QHash<QString, QString> uiThemes();
251 
253  static QString authorsFilePath();
254 
260  static QString contributorsFilePath();
261 
268  static QString developersMapFilePath();
269 
271  static QString sponsorsFilePath();
272 
274  static QString donorsFilePath();
275 
277  static QString serverResourcesPath();
278 
282  static QString translatorsFilePath();
283 
287  static QString licenceFilePath();
288 
290  static QString i18nPath();
291 
296  static QString metadataPath();
297 
299  static QString qgisMasterDatabaseFilePath();
300 
302  static QString qgisSettingsDirPath();
303 
305  static QString qgisUserDatabaseFilePath();
306 
308  static QString qgisAuthDatabaseFilePath();
309 
311  static QString splashPath();
312 
314  static QString iconsPath();
315 
317  static QString srsDatabaseFilePath();
318 
320  static QStringList svgPaths();
321 
326  static QStringList layoutTemplatePaths();
327 
329  static QMap<QString, QString> systemEnvVars();
330 
332  static QString prefixPath();
333 
335  static QString pluginPath();
336 
338  static QString pkgDataPath();
339 
341  static QString activeThemePath();
342 
344  static QString defaultThemePath();
345 
350  static QString iconPath( const QString &iconFile );
351 
356  static QIcon getThemeIcon( const QString &name );
357 
362  enum Cursor
363  {
371  };
372 
379  static QCursor getThemeCursor( Cursor cursor );
380 
389  static QPixmap getThemePixmap( const QString &name, const QColor &foreColor = QColor(), const QColor &backColor = QColor(), int size = 16 );
390 
392  static QString userStylePath();
393 
395  static QRegExp shortNameRegExp();
396 
402  static QString userLoginName();
403 
409  static QString userFullName();
410 
416  static QString osName();
417 
423  static QString platform();
424 
429  static QString locale();
430 
432  static QString userThemesFolder();
433 
435  static QString defaultStylePath();
436 
438  static QString defaultThemesFolder();
439 
441  static QString libraryPath();
442 
444  static QString libexecPath();
445 
452  static QString qmlImportPath();
453 
455  static void setPrefixPath( const QString &prefixPath, bool useDefaultPaths = false );
456 
458  static void setPluginPath( const QString &pluginPath );
459 
461  static void setPkgDataPath( const QString &pkgDataPath );
462 
464  static void setDefaultSvgPaths( const QStringList &pathList );
465 
467  static void setAuthDatabaseDirPath( const QString &authDbDirPath );
468 
470  static void initQgis();
471 
473  static bool createDatabase( QString *errorMessage = nullptr );
474 
476  static bool createThemeFolder();
477 
479  static void exitQgis();
480 
482  static QString appIconPath();
483 
485  enum endian_t
486  {
487  XDR = 0, // network, or big-endian, byte order
488  NDR = 1 // little-endian byte order
489  };
490 
492  static endian_t endian();
493 
508  static QString reportStyleSheet( QgsApplication::StyleSheetType styleSheetType = QgsApplication::StyleSheetType::Qt );
509 
514  static QString showSettings();
515 
523  static void registerOgrDrivers();
524 
526  static QString absolutePathToRelativePath( const QString &apath, const QString &targetPath );
528  static QString relativePathToAbsolutePath( const QString &rpath, const QString &targetPath );
529 
531  static bool isRunningFromBuildDir() { return ABISYM( mRunningFromBuildDir ); }
532 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
533  static QString cfgIntDir() SIP_SKIP;
534 #endif
535  static QString buildSourcePath();
538  static QString buildOutputPath();
539 
545  static void skipGdalDriver( const QString &driver );
546 
552  static void restoreGdalDriver( const QString &driver );
553 
558  static QStringList skippedGdalDrivers();
559 
566  static void applyGdalSkippedDrivers();
567 
572  static void registerGdalDriversFromSettings();
573 
580  static QStringList deferredSkippedGdalDrivers();
581 
588  static void setSkippedGdalDrivers( const QStringList &skippedGdalDrivers,
589  const QStringList &deferredSkippedGdalDrivers );
590 
595  static int maxThreads();
596 
602  static void setMaxThreads( int maxThreads );
603 
609  static QgsTaskManager *taskManager();
610 
615  static QgsColorSchemeRegistry *colorSchemeRegistry() SIP_KEEPREFERENCE;
616 
621  static QgsPaintEffectRegistry *paintEffectRegistry() SIP_KEEPREFERENCE;
622 
627  static QgsRendererRegistry *rendererRegistry() SIP_KEEPREFERENCE;
628 
634  static QgsRasterRendererRegistry *rasterRendererRegistry() SIP_SKIP;
635 
640  static QgsPointCloudRendererRegistry *pointCloudRendererRegistry() SIP_KEEPREFERENCE;
641 
647  static QgsDataItemProviderRegistry *dataItemProviderRegistry() SIP_KEEPREFERENCE;
648 
656  static QgsSvgCache *svgCache();
657 
664  static QgsImageCache *imageCache();
665 
671  static QgsSourceCache *sourceCache();
672 
677  static QgsNetworkContentFetcherRegistry *networkContentFetcherRegistry() SIP_KEEPREFERENCE;
678 
683  static QgsValidityCheckRegistry *validityCheckRegistry() SIP_KEEPREFERENCE;
684 
689  static QgsSymbolLayerRegistry *symbolLayerRegistry() SIP_KEEPREFERENCE;
690 
695  static QgsCalloutRegistry *calloutRegistry() SIP_KEEPREFERENCE;
696 
701  static QgsLayoutItemRegistry *layoutItemRegistry() SIP_KEEPREFERENCE;
702 
707  static QgsAnnotationItemRegistry *annotationItemRegistry() SIP_KEEPREFERENCE;
708 
713  static QgsGpsConnectionRegistry *gpsConnectionRegistry() SIP_KEEPREFERENCE;
714 
719  static QgsPluginLayerRegistry *pluginLayerRegistry() SIP_KEEPREFERENCE;
720 
725  static QgsClassificationMethodRegistry *classificationMethodRegistry() SIP_KEEPREFERENCE;
726 
731  static QgsBookmarkManager *bookmarkManager();
732 
740  static QgsStyleModel *defaultStyleModel();
741 
746  static QgsMessageLog *messageLog();
747 
754  static QgsAuthManager *authManager();
755 
761  static QgsProcessingRegistry *processingRegistry();
762 
767  static QgsPageSizeRegistry *pageSizeRegistry() SIP_KEEPREFERENCE;
768 
774  static QgsAnnotationRegistry *annotationRegistry() SIP_SKIP;
775 
781  static QgsActionScopeRegistry *actionScopeRegistry() SIP_KEEPREFERENCE;
782 
787  static QgsConnectionRegistry *connectionRegistry();
788 
793  static QgsRuntimeProfiler *profiler();
794 
800  static QgsNumericFormatRegistry *numericFormatRegistry() SIP_KEEPREFERENCE;
801 
805  static QgsFieldFormatterRegistry *fieldFormatterRegistry() SIP_KEEPREFERENCE;
806 
811  static Qgs3DRendererRegistry *renderer3DRegistry() SIP_KEEPREFERENCE;
812 
817  static Qgs3DSymbolRegistry *symbol3DRegistry() SIP_KEEPREFERENCE;
818 
824  static QgsScaleBarRendererRegistry *scaleBarRendererRegistry() SIP_KEEPREFERENCE;
825 
830  static QgsProjectStorageRegistry *projectStorageRegistry() SIP_KEEPREFERENCE;
831 
839  static QgsLocalizedDataPathRegistry *localizedDataPathRegistry() SIP_KEEPREFERENCE;
840 
849  static QString nullRepresentation();
850 
854  static void setNullRepresentation( const QString &nullRepresentation );
855 
863  static QVariantMap customVariables();
864 
872  static void setCustomVariables( const QVariantMap &customVariables );
873 
879  static void setCustomVariable( const QString &name, const QVariant &value );
880 
890  static int scaleIconSize( int standardSize, bool applyDevicePixelRatio = false );
891 
900  int maxConcurrentConnectionsPerPool() const;
901 
907  static void setTranslation( const QString &translation );
908 
914  void collectTranslatableObjects( QgsTranslationContext *translationContext );
915 
916 #ifdef SIP_RUN
917  SIP_IF_FEATURE( ANDROID )
918  //dummy method to workaround sip generation issue
919  bool x11EventFilter( XEvent *event );
920  SIP_END
921 #endif
922 
923  signals:
925  void preNotify( QObject *receiver, QEvent *event, bool *done ) SIP_SKIP;
926 
931  void customVariablesChanged();
932 
933 
937  void nullRepresentationChanged();
938 
945  void requestForTranslatableObjects( QgsTranslationContext *translationContext );
946 
947  private:
948 
949  static void copyPath( const QString &src, const QString &dst );
950  static QObject *ABISYM( mFileOpenEventReceiver );
951 
952  static bool ABISYM( mInitialized );
953 
955  static bool ABISYM( mRunningFromBuildDir );
956 
960  static int ABISYM( sMaxThreads );
961 
962  QMap<QString, QIcon> mIconCache;
963  QMap<Cursor, QCursor> mCursorCache;
964 
965  QTranslator *mQgisTranslator = nullptr;
966  QTranslator *mQtTranslator = nullptr;
967 
968  QgsDataItemProviderRegistry *mDataItemProviderRegistry = nullptr;
969  QgsAuthManager *mAuthManager = nullptr;
970 
971  struct ApplicationMembers
972  {
973  Qgs3DRendererRegistry *m3DRendererRegistry = nullptr;
974  Qgs3DSymbolRegistry *m3DSymbolRegistry = nullptr;
975  QgsActionScopeRegistry *mActionScopeRegistry = nullptr;
976  QgsAnnotationRegistry *mAnnotationRegistry = nullptr;
977  QgsColorSchemeRegistry *mColorSchemeRegistry = nullptr;
978  QgsLocalizedDataPathRegistry *mLocalizedDataPathRegistry = nullptr;
979  QgsNumericFormatRegistry *mNumericFormatRegistry = nullptr;
980  QgsFieldFormatterRegistry *mFieldFormatterRegistry = nullptr;
981  QgsGpsConnectionRegistry *mGpsConnectionRegistry = nullptr;
982  QgsNetworkContentFetcherRegistry *mNetworkContentFetcherRegistry = nullptr;
983  QgsScaleBarRendererRegistry *mScaleBarRendererRegistry = nullptr;
984  QgsValidityCheckRegistry *mValidityCheckRegistry = nullptr;
985  QgsMessageLog *mMessageLog = nullptr;
986  QgsPaintEffectRegistry *mPaintEffectRegistry = nullptr;
987  QgsPluginLayerRegistry *mPluginLayerRegistry = nullptr;
988  QgsClassificationMethodRegistry *mClassificationMethodRegistry = nullptr;
989  QgsProcessingRegistry *mProcessingRegistry = nullptr;
990  QgsConnectionRegistry *mConnectionRegistry = nullptr;
991  QgsProjectStorageRegistry *mProjectStorageRegistry = nullptr;
992  QgsPageSizeRegistry *mPageSizeRegistry = nullptr;
993  QgsRasterRendererRegistry *mRasterRendererRegistry = nullptr;
994  QgsRendererRegistry *mRendererRegistry = nullptr;
995  QgsPointCloudRendererRegistry *mPointCloudRendererRegistry = nullptr;
996  QgsSvgCache *mSvgCache = nullptr;
997  QgsImageCache *mImageCache = nullptr;
998  QgsSourceCache *mSourceCache = nullptr;
999  QgsSymbolLayerRegistry *mSymbolLayerRegistry = nullptr;
1000  QgsCalloutRegistry *mCalloutRegistry = nullptr;
1001  QgsTaskManager *mTaskManager = nullptr;
1002  QgsLayoutItemRegistry *mLayoutItemRegistry = nullptr;
1003  QgsAnnotationItemRegistry *mAnnotationItemRegistry = nullptr;
1004  QgsUserProfileManager *mUserConfigManager = nullptr;
1005  QgsBookmarkManager *mBookmarkManager = nullptr;
1006  QgsStyleModel *mStyleModel = nullptr;
1007  QString mNullRepresentation;
1008 
1009  ApplicationMembers();
1010  ~ApplicationMembers();
1011  };
1012 
1013  // Applications members which belong to an instance of QgsApplication
1014  ApplicationMembers *mApplicationMembers = nullptr;
1015  // ... but in case QgsApplication is never instantiated (eg with custom designer widgets), we fall back to static members
1016  static ApplicationMembers *sApplicationMembers;
1017 
1018  static QgsAuthManager *sAuthManager;
1019 
1020  static ApplicationMembers *members();
1021 
1022  static void invalidateCaches();
1023 };
1024 
1025 // clazy:excludeall=qstring-allocations
1026 
1027 #endif
A QAbstractItemModel subclass for showing symbol and color ramp entities contained within a QgsStyle ...
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.
Provides a method of recording run time profiles of operations, allowing easy recording of their over...
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.
Registry of available 3D symbol classes.
A registry class to hold localized data paths which can be used for basemaps, logos, etc.
A cache for source strings that returns a local file path containing the source content.
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly...
Registry of 2D renderers for point clouds.
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:194
#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:167
Select a rectangle.
StyleSheetType
The StyleSheetType enum represents the stylesheet type that a widget supports.
Registry of available annotation item types.
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.