QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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;
36 class QgsSvgCache;
37 class QgsImageCache;
44 class QgsMessageLog;
46 class QgsAnnotationRegistry;
47 class QgsUserProfile;
51 class QgsAuthManager;
54 class QTranslator;
55 class QgsCalloutRegistry;
56 class QgsBookmarkManager;
57 class QgsStyleModel;
58 
74 class CORE_EXPORT QgsApplication : public QApplication
75 {
76 
77 #ifdef SIP_RUN
78  % TypeCode
79  // Convert a Python argv list to a conventional C argc count and argv array.
80  static char **qtgui_ArgvToC( PyObject *argvlist, int &argc )
81  {
82  char **argv;
83 
84  argc = PyList_GET_SIZE( argvlist );
85 
86  // Allocate space for two copies of the argument pointers, plus the
87  // terminating NULL.
88  if ( ( argv = ( char ** )sipMalloc( 2 * ( argc + 1 ) * sizeof( char * ) ) ) == NULL )
89  return NULL;
90 
91  // Convert the list.
92  for ( int a = 0; a < argc; ++a )
93  {
94  char *arg;
95  // Get the argument and allocate memory for it.
96  if ( ( arg = PyBytes_AsString( PyList_GET_ITEM( argvlist, a ) ) ) == NULL ||
97  ( argv[a] = ( char * )sipMalloc( strlen( arg ) + 1 ) ) == NULL )
98  return NULL;
99  // Copy the argument and save a pointer to it.
100  strcpy( argv[a], arg );
101  argv[a + argc + 1] = argv[a];
102  }
103 
104  argv[argc + argc + 1] = argv[argc] = NULL;
105 
106  return argv;
107  }
108 
109  // Remove arguments from the Python argv list that have been removed from the
110  // C argv array.
111  static void qtgui_UpdatePyArgv( PyObject *argvlist, int argc, char **argv )
112  {
113  for ( int a = 0, na = 0; a < argc; ++a )
114  {
115  // See if it was removed.
116  if ( argv[na] == argv[a + argc + 1] )
117  ++na;
118  else
119  PyList_SetSlice( argvlist, na, na + 1, NULL );
120  }
121  }
122  % End
123 #endif
124 
125  Q_OBJECT
126 
127  public:
128 
129  static const char *QGIS_ORGANIZATION_NAME;
130  static const char *QGIS_ORGANIZATION_DOMAIN;
131  static const char *QGIS_APPLICATION_NAME;
132 #ifndef SIP_RUN
133  QgsApplication( int &argc, char **argv, bool GUIenabled, const QString &profileFolder = QString(), const QString &platformName = "desktop" );
134 #else
135  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" )];
136  % MethodCode
137  // The Python interface is a list of argument strings that is modified.
138 
139  int argc;
140  char **argv;
141 
142  // Convert the list.
143  if ( ( argv = qtgui_ArgvToC( a0, argc ) ) == NULL )
144  sipIsErr = 1;
145  else
146  {
147  // Create it now the arguments are right.
148  static int nargc = argc;
149 
150  sipCpp = new sipQgsApplication( nargc, argv, a1, *a2, *a3 );
151 
152  // Now modify the original list.
153  qtgui_UpdatePyArgv( a0, argc, argv );
154  }
155  % End
156 #endif
157 
158  ~QgsApplication() override;
159 
165  static QgsApplication *instance();
166 
174  static void init( QString profileFolder = QString() ) SIP_SKIP;
175 
177  bool event( QEvent *event ) override;
178 
180  bool notify( QObject *receiver, QEvent *event ) override;
181 
183  static void setFileOpenEventReceiver( QObject *receiver );
184 
195  static void setThemeName( const QString &themeName );
196 
201  static QString resolvePkgPath();
202 
210  static QString themeName();
211 
219  static void setUITheme( const QString &themeName );
220 
227  static QHash<QString, QString> uiThemes();
228 
230  static QString authorsFilePath();
231 
236  static QString contributorsFilePath();
237 
243  static QString developersMapFilePath();
244 
246  static QString sponsorsFilePath();
247 
249  static QString donorsFilePath();
250 
252  static QString serverResourcesPath();
253 
257  static QString translatorsFilePath();
258 
262  static QString licenceFilePath();
263 
265  static QString i18nPath();
266 
271  static QString metadataPath();
272 
274  static QString qgisMasterDatabaseFilePath();
275 
277  static QString qgisSettingsDirPath();
278 
280  static QString qgisUserDatabaseFilePath();
281 
283  static QString qgisAuthDatabaseFilePath();
284 
286  static QString splashPath();
287 
289  static QString iconsPath();
290 
292  static QString srsDatabaseFilePath();
293 
295  static QStringList svgPaths();
296 
301  static QStringList layoutTemplatePaths();
302 
304  static QMap<QString, QString> systemEnvVars() { return ABISYM( mSystemEnvVars ); }
305 
307  static QString prefixPath();
308 
310  static QString pluginPath();
311 
313  static QString pkgDataPath();
314 
316  static QString activeThemePath();
317 
319  static QString defaultThemePath();
320 
325  static QString iconPath( const QString &iconFile );
326 
331  static QIcon getThemeIcon( const QString &name );
332 
337  enum Cursor
338  {
346  };
347 
354  static QCursor getThemeCursor( Cursor cursor );
355 
360  static QPixmap getThemePixmap( const QString &name );
361 
363  static QString userStylePath();
364 
366  static QRegExp shortNameRegExp();
367 
373  static QString userLoginName();
374 
380  static QString userFullName();
381 
387  static QString osName();
388 
394  static QString platform();
395 
400  static QString locale();
401 
403  static QString userThemesFolder();
404 
406  static QString defaultStylePath();
407 
409  static QString defaultThemesFolder();
410 
412  static QString libraryPath();
413 
415  static QString libexecPath();
416 
423  static QString qmlImportPath();
424 
426  static void setPrefixPath( const QString &prefixPath, bool useDefaultPaths = false );
427 
429  static void setPluginPath( const QString &pluginPath );
430 
432  static void setPkgDataPath( const QString &pkgDataPath );
433 
435  static void setDefaultSvgPaths( const QStringList &pathList );
436 
438  static void setAuthDatabaseDirPath( const QString &authDbDirPath );
439 
441  static void initQgis();
442 
444  static bool createDatabase( QString *errorMessage = nullptr );
445 
447  static bool createThemeFolder();
448 
450  static void exitQgis();
451 
453  static QString appIconPath();
454 
456  enum endian_t
457  {
458  XDR = 0, // network, or big-endian, byte order
459  NDR = 1 // little-endian byte order
460  };
461 
463  static endian_t endian();
464 
476  static QString reportStyleSheet();
477 
481  static QString showSettings();
482 
490  static void registerOgrDrivers();
491 
493  static QString absolutePathToRelativePath( const QString &apath, const QString &targetPath );
495  static QString relativePathToAbsolutePath( const QString &rpath, const QString &targetPath );
496 
498  static bool isRunningFromBuildDir() { return ABISYM( mRunningFromBuildDir ); }
499 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
500  static QString cfgIntDir() { return ABISYM( mCfgIntDir ); } SIP_SKIP
501 #endif
502  static QString buildSourcePath() { return ABISYM( mBuildSourcePath ); }
505  static QString buildOutputPath() { return ABISYM( mBuildOutputPath ); }
506 
512  static void skipGdalDriver( const QString &driver );
513 
519  static void restoreGdalDriver( const QString &driver );
520 
525  static QStringList skippedGdalDrivers() { return ABISYM( mGdalSkipList ); }
526 
533  static void applyGdalSkippedDrivers();
534 
539  static void registerGdalDriversFromSettings();
540 
547  static QStringList deferredSkippedGdalDrivers() { return sDeferredSkippedGdalDrivers; }
548 
555  static void setSkippedGdalDrivers( const QStringList &skippedGdalDrivers,
556  const QStringList &deferredSkippedGdalDrivers );
557 
561  static int maxThreads() { return ABISYM( mMaxThreads ); }
562 
567  static void setMaxThreads( int maxThreads );
568 
574  static QgsTaskManager *taskManager();
575 
580  static QgsColorSchemeRegistry *colorSchemeRegistry() SIP_KEEPREFERENCE;
581 
586  static QgsPaintEffectRegistry *paintEffectRegistry() SIP_KEEPREFERENCE;
587 
592  static QgsRendererRegistry *rendererRegistry() SIP_KEEPREFERENCE;
593 
599  static QgsRasterRendererRegistry *rasterRendererRegistry() SIP_SKIP;
600 
606  static QgsDataItemProviderRegistry *dataItemProviderRegistry() SIP_KEEPREFERENCE;
607 
615  static QgsSvgCache *svgCache();
616 
623  static QgsImageCache *imageCache();
624 
629  static QgsNetworkContentFetcherRegistry *networkContentFetcherRegistry() SIP_KEEPREFERENCE;
630 
635  static QgsValidityCheckRegistry *validityCheckRegistry() SIP_KEEPREFERENCE;
636 
641  static QgsSymbolLayerRegistry *symbolLayerRegistry() SIP_KEEPREFERENCE;
642 
647  static QgsCalloutRegistry *calloutRegistry() SIP_KEEPREFERENCE;
648 
653  static QgsLayoutItemRegistry *layoutItemRegistry() SIP_KEEPREFERENCE;
654 
659  static QgsGpsConnectionRegistry *gpsConnectionRegistry() SIP_KEEPREFERENCE;
660 
665  static QgsPluginLayerRegistry *pluginLayerRegistry() SIP_KEEPREFERENCE;
666 
671  static QgsClassificationMethodRegistry *classificationMethodRegistry() SIP_KEEPREFERENCE;
672 
677  static QgsBookmarkManager *bookmarkManager();
678 
686  static QgsStyleModel *defaultStyleModel();
687 
692  static QgsMessageLog *messageLog();
693 
700  static QgsAuthManager *authManager();
701 
707  static QgsProcessingRegistry *processingRegistry();
708 
713  static QgsPageSizeRegistry *pageSizeRegistry() SIP_KEEPREFERENCE;
714 
720  static QgsAnnotationRegistry *annotationRegistry() SIP_SKIP;
721 
727  static QgsActionScopeRegistry *actionScopeRegistry() SIP_KEEPREFERENCE;
728 
733  static QgsRuntimeProfiler *profiler();
734 
738  static QgsFieldFormatterRegistry *fieldFormatterRegistry() SIP_KEEPREFERENCE;
739 
744  static Qgs3DRendererRegistry *renderer3DRegistry() SIP_KEEPREFERENCE;
745 
750  static QgsProjectStorageRegistry *projectStorageRegistry() SIP_KEEPREFERENCE;
751 
760  static QString nullRepresentation();
761 
765  static void setNullRepresentation( const QString &nullRepresentation );
766 
774  static QVariantMap customVariables();
775 
783  static void setCustomVariables( const QVariantMap &customVariables );
784 
790  static void setCustomVariable( const QString &name, const QVariant &value );
791 
800  int maxConcurrentConnectionsPerPool() const;
801 
807  static void setTranslation( const QString &translation ) { sTranslation = translation; }
808 
814  void collectTranslatableObjects( QgsTranslationContext *translationContext );
815 
816 #ifdef SIP_RUN
817  SIP_IF_FEATURE( ANDROID )
818  //dummy method to workaround sip generation issue
819  bool x11EventFilter( XEvent *event );
820  SIP_END
821 #endif
822 
823  signals:
825  void preNotify( QObject *receiver, QEvent *event, bool *done ) SIP_SKIP;
826 
831  void customVariablesChanged();
832 
833 
837  void nullRepresentationChanged();
838 
845  void requestForTranslatableObjects( QgsTranslationContext *translationContext );
846 
847  private:
848 
849  static void copyPath( const QString &src, const QString &dst );
850  static QObject *ABISYM( mFileOpenEventReceiver );
851  static QStringList ABISYM( mFileOpenEventList );
852 
853  static QString ABISYM( mProfilePath );
854  static QString ABISYM( mUIThemeName );
855  static QString ABISYM( mPrefixPath );
856  static QString ABISYM( mPluginPath );
857  static QString ABISYM( mPkgDataPath );
858  static QString ABISYM( mLibraryPath );
859  static QString ABISYM( mLibexecPath );
860  static QString ABISYM( mQmlImportPath );
861  static QString ABISYM( mThemeName );
862  static QStringList ABISYM( mDefaultSvgPaths );
863  static QMap<QString, QString> ABISYM( mSystemEnvVars );
864 
865  static QString ABISYM( mConfigPath );
866 
867  static bool ABISYM( mInitialized );
868 
870  static bool ABISYM( mRunningFromBuildDir );
872  static QString ABISYM( mBuildSourcePath );
873 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
874  static QString ABISYM( mCfgIntDir );
876 #endif
877  static QString ABISYM( mBuildOutputPath );
879 
883  static QStringList ABISYM( mGdalSkipList );
884 
889  static QStringList sDeferredSkippedGdalDrivers;
890 
893  static int ABISYM( mMaxThreads );
894 
897  static QString ABISYM( mAuthDbDirPath );
898 
899  static QString sUserName;
900  static QString sUserFullName;
901  static QString sPlatformName;
902  static QString sTranslation;
903 
904  QMap<QString, QIcon> mIconCache;
905  QMap<Cursor, QCursor> mCursorCache;
906 
907  QTranslator *mQgisTranslator = nullptr;
908  QTranslator *mQtTranslator = nullptr;
909 
910  QgsDataItemProviderRegistry *mDataItemProviderRegistry = nullptr;
911  QgsAuthManager *mAuthManager = nullptr;
912 
913  struct ApplicationMembers
914  {
915  Qgs3DRendererRegistry *m3DRendererRegistry = nullptr;
916  QgsActionScopeRegistry *mActionScopeRegistry = nullptr;
917  QgsAnnotationRegistry *mAnnotationRegistry = nullptr;
918  QgsColorSchemeRegistry *mColorSchemeRegistry = nullptr;
919  QgsFieldFormatterRegistry *mFieldFormatterRegistry = nullptr;
920  QgsGpsConnectionRegistry *mGpsConnectionRegistry = nullptr;
921  QgsNetworkContentFetcherRegistry *mNetworkContentFetcherRegistry = nullptr;
922  QgsValidityCheckRegistry *mValidityCheckRegistry = nullptr;
923  QgsMessageLog *mMessageLog = nullptr;
924  QgsPaintEffectRegistry *mPaintEffectRegistry = nullptr;
925  QgsPluginLayerRegistry *mPluginLayerRegistry = nullptr;
926  QgsClassificationMethodRegistry *mClassificationMethodRegistry = nullptr;
927  QgsProcessingRegistry *mProcessingRegistry = nullptr;
928  QgsProjectStorageRegistry *mProjectStorageRegistry = nullptr;
929  QgsPageSizeRegistry *mPageSizeRegistry = nullptr;
930  QgsRasterRendererRegistry *mRasterRendererRegistry = nullptr;
931  QgsRendererRegistry *mRendererRegistry = nullptr;
932  QgsRuntimeProfiler *mProfiler = nullptr;
933  QgsSvgCache *mSvgCache = nullptr;
934  QgsImageCache *mImageCache = nullptr;
935  QgsSymbolLayerRegistry *mSymbolLayerRegistry = nullptr;
936  QgsCalloutRegistry *mCalloutRegistry = nullptr;
937  QgsTaskManager *mTaskManager = nullptr;
938  QgsLayoutItemRegistry *mLayoutItemRegistry = nullptr;
939  QgsUserProfileManager *mUserConfigManager = nullptr;
940  QgsBookmarkManager *mBookmarkManager = nullptr;
941  QgsStyleModel *mStyleModel = nullptr;
942  QString mNullRepresentation;
943 
944  ApplicationMembers();
945  ~ApplicationMembers();
946  };
947 
948  // Applications members which belong to an instance of QgsApplication
949  ApplicationMembers *mApplicationMembers = nullptr;
950  // ... but in case QgsApplication is never instantiated (eg with custom designer widgets), we fall back to static members
951  static ApplicationMembers *sApplicationMembers;
952 
953  static QgsAuthManager *sAuthManager;
954 
955  static ApplicationMembers *members();
956 
957  static void invalidateCaches();
958 };
959 
960 // clazy:excludeall=qstring-allocations
961 
962 #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 cache for images / pictures derived from svg files.
Definition: qgssvgcache.h:100
Registry of renderers.
Registry for raster renderers.
User profile contains information about the user profile folders on the machine.
Precisely identify a point on the canvas.
static QStringList skippedGdalDrivers()
Returns the list of gdal drivers that should be skipped (based on GDAL_SKIP environment variable) ...
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.
static int maxThreads()
Gets maximum concurrent thread count.
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.
static QStringList deferredSkippedGdalDrivers()
Returns the list of gdal drivers that have been disabled in the current session, and thus...
static QString buildOutputPath()
Returns path to the build output directory. Valid only when running from build directory.
#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.
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.
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:89
Registry of storage backends that QgsProject may use.
The action scope registry is an application wide registry that contains a list of available action sc...
static const char * QGIS_APPLICATION_NAME
static void setTranslation(const QString &translation)
Set translation.
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.