QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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.h"
24 #include "qgsconfig.h"
25 #include "qgstranslationcontext.h"
26 
29 class QgsRuntimeProfiler;
30 class QgsTaskManager;
36 class QgsSvgCache;
42 class QgsMessageLog;
44 class QgsAnnotationRegistry;
45 class QgsUserProfile;
49 class QgsAuthManager;
51 class QTranslator;
52 
68 class CORE_EXPORT QgsApplication : public QApplication
69 {
70 
71 #ifdef SIP_RUN
72  % TypeCode
73  // Convert a Python argv list to a conventional C argc count and argv array.
74  static char **qtgui_ArgvToC( PyObject *argvlist, int &argc )
75  {
76  char **argv;
77 
78  argc = PyList_GET_SIZE( argvlist );
79 
80  // Allocate space for two copies of the argument pointers, plus the
81  // terminating NULL.
82  if ( ( argv = ( char ** )sipMalloc( 2 * ( argc + 1 ) * sizeof( char * ) ) ) == NULL )
83  return NULL;
84 
85  // Convert the list.
86  for ( int a = 0; a < argc; ++a )
87  {
88  char *arg;
89  // Get the argument and allocate memory for it.
90  if ( ( arg = PyBytes_AsString( PyList_GET_ITEM( argvlist, a ) ) ) == NULL ||
91  ( argv[a] = ( char * )sipMalloc( strlen( arg ) + 1 ) ) == NULL )
92  return NULL;
93  // Copy the argument and save a pointer to it.
94  strcpy( argv[a], arg );
95  argv[a + argc + 1] = argv[a];
96  }
97 
98  argv[argc + argc + 1] = argv[argc] = NULL;
99 
100  return argv;
101  }
102 
103  // Remove arguments from the Python argv list that have been removed from the
104  // C argv array.
105  static void qtgui_UpdatePyArgv( PyObject *argvlist, int argc, char **argv )
106  {
107  for ( int a = 0, na = 0; a < argc; ++a )
108  {
109  // See if it was removed.
110  if ( argv[na] == argv[a + argc + 1] )
111  ++na;
112  else
113  PyList_SetSlice( argvlist, na, na + 1, NULL );
114  }
115  }
116  % End
117 #endif
118 
119  Q_OBJECT
120 
121  public:
122 
123  static const char *QGIS_ORGANIZATION_NAME;
124  static const char *QGIS_ORGANIZATION_DOMAIN;
125  static const char *QGIS_APPLICATION_NAME;
126 #ifndef SIP_RUN
127  QgsApplication( int &argc, char **argv, bool GUIenabled, const QString &profileFolder = QString(), const QString &platformName = "desktop" );
128 #else
129  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" )];
130  % MethodCode
131  // The Python interface is a list of argument strings that is modified.
132 
133  int argc;
134  char **argv;
135 
136  // Convert the list.
137  if ( ( argv = qtgui_ArgvToC( a0, argc ) ) == NULL )
138  sipIsErr = 1;
139  else
140  {
141  // Create it now the arguments are right.
142  static int nargc = argc;
143 
144  sipCpp = new sipQgsApplication( nargc, argv, a1, *a2, *a3 );
145 
146  // Now modify the original list.
147  qtgui_UpdatePyArgv( a0, argc, argv );
148  }
149  % End
150 #endif
151 
152  ~QgsApplication() override;
153 
159  static QgsApplication *instance();
160 
168  static void init( QString profileFolder = QString() ) SIP_SKIP;
169 
171  bool event( QEvent *event ) override;
172 
174  bool notify( QObject *receiver, QEvent *event ) override;
175 
177  static void setFileOpenEventReceiver( QObject *receiver );
178 
189  static void setThemeName( const QString &themeName );
190 
195  static QString resolvePkgPath();
196 
204  static QString themeName();
205 
213  static void setUITheme( const QString &themeName );
214 
221  static QHash<QString, QString> uiThemes();
222 
224  static QString authorsFilePath();
225 
230  static QString contributorsFilePath();
231 
237  static QString developersMapFilePath();
238 
240  static QString sponsorsFilePath();
241 
243  static QString donorsFilePath();
244 
246  static QString serverResourcesPath();
247 
251  static QString translatorsFilePath();
252 
256  static QString licenceFilePath();
257 
259  static QString i18nPath();
260 
265  static QString metadataPath();
266 
268  static QString qgisMasterDatabaseFilePath();
269 
271  static QString qgisSettingsDirPath();
272 
274  static QString qgisUserDatabaseFilePath();
275 
277  static QString qgisAuthDatabaseFilePath();
278 
280  static QString splashPath();
281 
283  static QString iconsPath();
284 
286  static QString srsDatabaseFilePath();
287 
289  static QStringList svgPaths();
290 
295  static QStringList layoutTemplatePaths();
296 
298  static QMap<QString, QString> systemEnvVars() { return ABISYM( mSystemEnvVars ); }
299 
301  static QString prefixPath();
302 
304  static QString pluginPath();
305 
307  static QString pkgDataPath();
308 
310  static QString activeThemePath();
311 
313  static QString defaultThemePath();
314 
319  static QString iconPath( const QString &iconFile );
320 
325  static QIcon getThemeIcon( const QString &name );
326 
331  enum Cursor
332  {
340  };
341 
348  static QCursor getThemeCursor( Cursor cursor );
349 
354  static QPixmap getThemePixmap( const QString &name );
355 
357  static QString userStylePath();
358 
360  static QRegExp shortNameRegExp();
361 
367  static QString userLoginName();
368 
374  static QString userFullName();
375 
381  static QString osName();
382 
388  static QString platform();
389 
394  static QString locale();
395 
397  static QString userThemesFolder();
398 
400  static QString defaultStylePath();
401 
403  static QString defaultThemesFolder();
404 
406  static QString libraryPath();
407 
409  static QString libexecPath();
410 
417  static QString qmlImportPath();
418 
420  static void setPrefixPath( const QString &prefixPath, bool useDefaultPaths = false );
421 
423  static void setPluginPath( const QString &pluginPath );
424 
426  static void setPkgDataPath( const QString &pkgDataPath );
427 
429  static void setDefaultSvgPaths( const QStringList &pathList );
430 
432  static void setAuthDatabaseDirPath( const QString &authDbDirPath );
433 
435  static void initQgis();
436 
438  static bool createDatabase( QString *errorMessage = nullptr );
439 
441  static bool createThemeFolder();
442 
444  static void exitQgis();
445 
447  static QString appIconPath();
448 
450  enum endian_t
451  {
452  XDR = 0, // network, or big-endian, byte order
453  NDR = 1 // little-endian byte order
454  };
455 
457  static endian_t endian();
458 
463 #ifndef SIP_RUN
464  template<typename T>
465  static void endian_swap( T &value )
466  {
467  char *data = reinterpret_cast<char *>( &value );
468  std::size_t n = sizeof( value );
469  for ( std::size_t i = 0, m = n / 2; i < m; ++i )
470  {
471  std::swap( data[i], data[n - 1 - i] );
472  }
473  }
474 #endif
475 
487  static QString reportStyleSheet();
488 
492  static QString showSettings();
493 
501  static void registerOgrDrivers();
502 
504  static QString absolutePathToRelativePath( const QString &apath, const QString &targetPath );
506  static QString relativePathToAbsolutePath( const QString &rpath, const QString &targetPath );
507 
509  static bool isRunningFromBuildDir() { return ABISYM( mRunningFromBuildDir ); }
510 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
511  static QString cfgIntDir() { return ABISYM( mCfgIntDir ); } SIP_SKIP
512 #endif
513  static QString buildSourcePath() { return ABISYM( mBuildSourcePath ); }
516  static QString buildOutputPath() { return ABISYM( mBuildOutputPath ); }
517 
523  static void skipGdalDriver( const QString &driver );
524 
530  static void restoreGdalDriver( const QString &driver );
531 
536  static QStringList skippedGdalDrivers() { return ABISYM( mGdalSkipList ); }
537 
543  static void applyGdalSkippedDrivers();
544 
548  static int maxThreads() { return ABISYM( mMaxThreads ); }
549 
554  static void setMaxThreads( int maxThreads );
555 
561  static QgsTaskManager *taskManager();
562 
567  static QgsColorSchemeRegistry *colorSchemeRegistry();
568 
573  static QgsPaintEffectRegistry *paintEffectRegistry();
574 
579  static QgsRendererRegistry *rendererRegistry();
580 
586  static QgsRasterRendererRegistry *rasterRendererRegistry() SIP_SKIP;
587 
593  static QgsDataItemProviderRegistry *dataItemProviderRegistry();
594 
600  static QgsSvgCache *svgCache();
601 
606  static QgsNetworkContentFetcherRegistry *networkContentFetcherRegistry();
607 
612  static QgsSymbolLayerRegistry *symbolLayerRegistry();
613 
618  static QgsLayoutItemRegistry *layoutItemRegistry();
619 
624  static QgsGpsConnectionRegistry *gpsConnectionRegistry();
625 
630  static QgsPluginLayerRegistry *pluginLayerRegistry();
631 
636  static QgsMessageLog *messageLog();
637 
644  static QgsAuthManager *authManager();
645 
651  static QgsProcessingRegistry *processingRegistry();
652 
657  static QgsPageSizeRegistry *pageSizeRegistry();
658 
664  static QgsAnnotationRegistry *annotationRegistry() SIP_SKIP;
665 
671  static QgsActionScopeRegistry *actionScopeRegistry();
672 
677  static QgsRuntimeProfiler *profiler();
678 
682  static QgsFieldFormatterRegistry *fieldFormatterRegistry();
683 
688  static Qgs3DRendererRegistry *renderer3DRegistry();
689 
694  static QgsProjectStorageRegistry *projectStorageRegistry();
695 
704  static QString nullRepresentation();
705 
709  static void setNullRepresentation( const QString &nullRepresentation );
710 
718  static QVariantMap customVariables();
719 
727  static void setCustomVariables( const QVariantMap &customVariables );
728 
734  static void setCustomVariable( const QString &name, const QVariant &value );
735 
744  int maxConcurrentConnectionsPerPool() const;
745 
751  static void setTranslation( const QString &translation ) { sTranslation = translation; }
752 
758  void collectTranslatableObjects( QgsTranslationContext *translationContext );
759 
760 #ifdef SIP_RUN
761  SIP_IF_FEATURE( ANDROID )
762  //dummy method to workaround sip generation issue
763  bool x11EventFilter( XEvent *event );
764  SIP_END
765 #endif
766 
767  signals:
769  void preNotify( QObject *receiver, QEvent *event, bool *done ) SIP_SKIP;
770 
775  void customVariablesChanged();
776 
777 
781  void nullRepresentationChanged();
782 
789  void requestForTranslatableObjects( QgsTranslationContext *translationContext );
790 
791  private:
792 
793  static void copyPath( const QString &src, const QString &dst );
794  static QObject *ABISYM( mFileOpenEventReceiver );
795  static QStringList ABISYM( mFileOpenEventList );
796 
797  static QString ABISYM( mProfilePath );
798  static QString ABISYM( mUIThemeName );
799  static QString ABISYM( mPrefixPath );
800  static QString ABISYM( mPluginPath );
801  static QString ABISYM( mPkgDataPath );
802  static QString ABISYM( mLibraryPath );
803  static QString ABISYM( mLibexecPath );
804  static QString ABISYM( mQmlImportPath );
805  static QString ABISYM( mThemeName );
806  static QStringList ABISYM( mDefaultSvgPaths );
807  static QMap<QString, QString> ABISYM( mSystemEnvVars );
808 
809  static QString ABISYM( mConfigPath );
810 
811  static bool ABISYM( mInitialized );
812 
814  static bool ABISYM( mRunningFromBuildDir );
816  static QString ABISYM( mBuildSourcePath );
817 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
818  static QString ABISYM( mCfgIntDir );
820 #endif
821  static QString ABISYM( mBuildOutputPath );
823 
827  static QStringList ABISYM( mGdalSkipList );
828 
831  static int ABISYM( mMaxThreads );
832 
835  static QString ABISYM( mAuthDbDirPath );
836 
837  static QString sUserName;
838  static QString sUserFullName;
839  static QString sPlatformName;
840  static QString sTranslation;
841 
842  QMap<QString, QIcon> mIconCache;
843  QMap<Cursor, QCursor> mCursorCache;
844 
845  QTranslator *mQgisTranslator = nullptr;
846  QTranslator *mQtTranslator = nullptr;
847 
848  QgsDataItemProviderRegistry *mDataItemProviderRegistry = nullptr;
849  QgsAuthManager *mAuthManager = nullptr;
850 
851  struct ApplicationMembers
852  {
853  Qgs3DRendererRegistry *m3DRendererRegistry = nullptr;
854  QgsActionScopeRegistry *mActionScopeRegistry = nullptr;
855  QgsAnnotationRegistry *mAnnotationRegistry = nullptr;
856  QgsColorSchemeRegistry *mColorSchemeRegistry = nullptr;
857  QgsFieldFormatterRegistry *mFieldFormatterRegistry = nullptr;
858  QgsGpsConnectionRegistry *mGpsConnectionRegistry = nullptr;
859  QgsNetworkContentFetcherRegistry *mNetworkContentFetcherRegistry = nullptr;
860  QgsMessageLog *mMessageLog = nullptr;
861  QgsPaintEffectRegistry *mPaintEffectRegistry = nullptr;
862  QgsPluginLayerRegistry *mPluginLayerRegistry = nullptr;
863  QgsProcessingRegistry *mProcessingRegistry = nullptr;
864  QgsProjectStorageRegistry *mProjectStorageRegistry = nullptr;
865  QgsPageSizeRegistry *mPageSizeRegistry = nullptr;
866  QgsRasterRendererRegistry *mRasterRendererRegistry = nullptr;
867  QgsRendererRegistry *mRendererRegistry = nullptr;
868  QgsRuntimeProfiler *mProfiler = nullptr;
869  QgsSvgCache *mSvgCache = nullptr;
870  QgsSymbolLayerRegistry *mSymbolLayerRegistry = nullptr;
871  QgsTaskManager *mTaskManager = nullptr;
872  QgsLayoutItemRegistry *mLayoutItemRegistry = nullptr;
873  QgsUserProfileManager *mUserConfigManager = nullptr;
874  QString mNullRepresentation;
875 
876  ApplicationMembers();
877  ~ApplicationMembers();
878  };
879 
880  // Applications members which belong to an instance of QgsApplication
881  ApplicationMembers *mApplicationMembers = nullptr;
882  // ... but in case QgsApplication is never instantiated (eg with custom designer widgets), we fall back to static members
883  static ApplicationMembers *sApplicationMembers;
884 
885  static QgsAuthManager *sAuthManager;
886 
887  static ApplicationMembers *members();
888 
889  static void invalidateCaches();
890 };
891 
892 // clazy:excludeall=qstring-allocations
893 
894 #endif
Singleton offering an interface to manage the authentication configuration database and to utilize co...
static void endian_swap(T &value)
Swap the endianness of the specified value.
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:130
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) ...
The QgsFieldFormatterRegistry manages registered classes of QgsFieldFormatter.
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:119
Registry for temporary fetched files.
static QString buildOutputPath()
Returns path to the build output directory. Valid only when running from build directory.
#define SIP_END
Definition: qgis_sip.h:182
A registry for known page sizes.
static const char * QGIS_ORGANIZATION_NAME
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:155
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...
QObject * ABISYM(QgsApplication::mFileOpenEventReceiver)
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.