QGIS API Documentation  3.2.0-Bonn (bc43194)
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 
28 class QgsRuntimeProfiler;
29 class QgsTaskManager;
35 class QgsSvgCache;
41 class QgsMessageLog;
43 class QgsAnnotationRegistry;
44 class QgsUserProfile;
48 class QgsAuthManager;
50 
66 class CORE_EXPORT QgsApplication : public QApplication
67 {
68 
69 #ifdef SIP_RUN
70  % TypeCode
71  // Convert a Python argv list to a conventional C argc count and argv array.
72  static char **qtgui_ArgvToC( PyObject *argvlist, int &argc )
73  {
74  char **argv;
75 
76  argc = PyList_GET_SIZE( argvlist );
77 
78  // Allocate space for two copies of the argument pointers, plus the
79  // terminating NULL.
80  if ( ( argv = ( char ** )sipMalloc( 2 * ( argc + 1 ) * sizeof( char * ) ) ) == NULL )
81  return NULL;
82 
83  // Convert the list.
84  for ( int a = 0; a < argc; ++a )
85  {
86  char *arg;
87  // Get the argument and allocate memory for it.
88  if ( ( arg = PyBytes_AsString( PyList_GET_ITEM( argvlist, a ) ) ) == NULL ||
89  ( argv[a] = ( char * )sipMalloc( strlen( arg ) + 1 ) ) == NULL )
90  return NULL;
91  // Copy the argument and save a pointer to it.
92  strcpy( argv[a], arg );
93  argv[a + argc + 1] = argv[a];
94  }
95 
96  argv[argc + argc + 1] = argv[argc] = NULL;
97 
98  return argv;
99  }
100 
101  // Remove arguments from the Python argv list that have been removed from the
102  // C argv array.
103  static void qtgui_UpdatePyArgv( PyObject *argvlist, int argc, char **argv )
104  {
105  for ( int a = 0, na = 0; a < argc; ++a )
106  {
107  // See if it was removed.
108  if ( argv[na] == argv[a + argc + 1] )
109  ++na;
110  else
111  PyList_SetSlice( argvlist, na, na + 1, NULL );
112  }
113  }
114  % End
115 #endif
116 
117  Q_OBJECT
118 
119  public:
120 
121  static const char *QGIS_ORGANIZATION_NAME;
122  static const char *QGIS_ORGANIZATION_DOMAIN;
123  static const char *QGIS_APPLICATION_NAME;
124 #ifndef SIP_RUN
125  QgsApplication( int &argc, char **argv, bool GUIenabled, const QString &profileFolder = QString(), const QString &platformName = "desktop" );
126 #else
127  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" )];
128  % MethodCode
129  // The Python interface is a list of argument strings that is modified.
130 
131  int argc;
132  char **argv;
133 
134  // Convert the list.
135  if ( ( argv = qtgui_ArgvToC( a0, argc ) ) == NULL )
136  sipIsErr = 1;
137  else
138  {
139  // Create it now the arguments are right.
140  static int nargc = argc;
141 
142  sipCpp = new sipQgsApplication( nargc, argv, a1, *a2, *a3 );
143 
144  // Now modify the original list.
145  qtgui_UpdatePyArgv( a0, argc, argv );
146  }
147  % End
148 #endif
149 
150  ~QgsApplication() override;
151 
157  static QgsApplication *instance();
158 
166  static void init( QString profileFolder = QString() ) SIP_SKIP;
167 
169  bool event( QEvent *event ) override;
170 
172  bool notify( QObject *receiver, QEvent *event ) override;
173 
175  static void setFileOpenEventReceiver( QObject *receiver );
176 
187  static void setThemeName( const QString &themeName );
188 
193  static QString resolvePkgPath( );
194 
202  static QString themeName();
203 
211  static void setUITheme( const QString &themeName );
212 
219  static QHash<QString, QString> uiThemes();
220 
222  static QString authorsFilePath();
223 
228  static QString contributorsFilePath();
229 
235  static QString developersMapFilePath();
236 
238  static QString sponsorsFilePath();
239 
241  static QString donorsFilePath();
242 
244  static QString serverResourcesPath();
245 
249  static QString translatorsFilePath();
250 
254  static QString licenceFilePath();
255 
257  static QString i18nPath();
258 
263  static QString metadataPath();
264 
266  static QString qgisMasterDatabaseFilePath();
267 
269  static QString qgisSettingsDirPath();
270 
272  static QString qgisUserDatabaseFilePath();
273 
275  static QString qgisAuthDatabaseFilePath();
276 
278  static QString splashPath();
279 
281  static QString iconsPath();
282 
284  static QString srsDatabaseFilePath();
285 
287  static QStringList svgPaths();
288 
293  static QStringList layoutTemplatePaths();
294 
296  static QMap<QString, QString> systemEnvVars() { return ABISYM( mSystemEnvVars ); }
297 
299  static QString prefixPath();
300 
302  static QString pluginPath();
303 
305  static QString pkgDataPath();
306 
308  static QString activeThemePath();
309 
311  static QString defaultThemePath();
312 
317  static QString iconPath( const QString &iconFile );
318 
323  static QIcon getThemeIcon( const QString &name );
324 
329  enum Cursor
330  {
338  };
339 
346  static QCursor getThemeCursor( Cursor cursor );
347 
352  static QPixmap getThemePixmap( const QString &name );
353 
355  static QString userStylePath();
356 
358  static QRegExp shortNameRegExp();
359 
365  static QString userLoginName();
366 
372  static QString userFullName();
373 
379  static QString osName();
380 
386  static QString platform();
387 
392  static QString locale();
393 
395  static QString userThemesFolder();
396 
398  static QString defaultStylePath();
399 
401  static QString defaultThemesFolder();
402 
404  static QString libraryPath();
405 
407  static QString libexecPath();
408 
415  static QString qmlImportPath();
416 
418  static void setPrefixPath( const QString &prefixPath, bool useDefaultPaths = false );
419 
421  static void setPluginPath( const QString &pluginPath );
422 
424  static void setPkgDataPath( const QString &pkgDataPath );
425 
427  static void setDefaultSvgPaths( const QStringList &pathList );
428 
430  static void setAuthDatabaseDirPath( const QString &authDbDirPath );
431 
433  static void initQgis();
434 
436  static bool createDatabase( QString *errorMessage = nullptr );
437 
439  static bool createThemeFolder();
440 
442  static void exitQgis();
443 
445  static QString appIconPath();
446 
448  enum endian_t
449  {
450  XDR = 0, // network, or big-endian, byte order
451  NDR = 1 // little-endian byte order
452  };
453 
455  static endian_t endian();
456 
461 #ifndef SIP_RUN
462  template<typename T>
463  static void endian_swap( T &value )
464  {
465  char *data = reinterpret_cast<char *>( &value );
466  std::size_t n = sizeof( value );
467  for ( std::size_t i = 0, m = n / 2; i < m; ++i )
468  {
469  std::swap( data[i], data[n - 1 - i] );
470  }
471  }
472 #endif
473 
485  static QString reportStyleSheet();
486 
490  static QString showSettings();
491 
499  static void registerOgrDrivers();
500 
502  static QString absolutePathToRelativePath( const QString &apath, const QString &targetPath );
504  static QString relativePathToAbsolutePath( const QString &rpath, const QString &targetPath );
505 
507  static bool isRunningFromBuildDir() { return ABISYM( mRunningFromBuildDir ); }
508 #ifdef _MSC_VER
509  static QString cfgIntDir() { return ABISYM( mCfgIntDir ); } SIP_SKIP
510 #endif
511  static QString buildSourcePath() { return ABISYM( mBuildSourcePath ); }
514  static QString buildOutputPath() { return ABISYM( mBuildOutputPath ); }
515 
521  static void skipGdalDriver( const QString &driver );
522 
528  static void restoreGdalDriver( const QString &driver );
529 
534  static QStringList skippedGdalDrivers() { return ABISYM( mGdalSkipList ); }
535 
541  static void applyGdalSkippedDrivers();
542 
546  static int maxThreads() { return ABISYM( mMaxThreads ); }
547 
552  static void setMaxThreads( int maxThreads );
553 
559  static QgsTaskManager *taskManager();
560 
565  static QgsColorSchemeRegistry *colorSchemeRegistry();
566 
571  static QgsPaintEffectRegistry *paintEffectRegistry();
572 
577  static QgsRendererRegistry *rendererRegistry();
578 
584  static QgsRasterRendererRegistry *rasterRendererRegistry() SIP_SKIP;
585 
591  static QgsDataItemProviderRegistry *dataItemProviderRegistry();
592 
598  static QgsSvgCache *svgCache();
599 
604  static QgsNetworkContentFetcherRegistry *networkContentFetcherRegistry();
605 
610  static QgsSymbolLayerRegistry *symbolLayerRegistry();
611 
616  static QgsLayoutItemRegistry *layoutItemRegistry();
617 
622  static QgsGpsConnectionRegistry *gpsConnectionRegistry();
623 
628  static QgsPluginLayerRegistry *pluginLayerRegistry();
629 
634  static QgsMessageLog *messageLog();
635 
642  static QgsAuthManager *authManager();
643 
649  static QgsProcessingRegistry *processingRegistry();
650 
655  static QgsPageSizeRegistry *pageSizeRegistry();
656 
662  static QgsAnnotationRegistry *annotationRegistry() SIP_SKIP;
663 
669  static QgsActionScopeRegistry *actionScopeRegistry();
670 
675  static QgsRuntimeProfiler *profiler();
676 
680  static QgsFieldFormatterRegistry *fieldFormatterRegistry();
681 
686  static Qgs3DRendererRegistry *renderer3DRegistry();
687 
692  static QgsProjectStorageRegistry *projectStorageRegistry();
693 
702  static QString nullRepresentation();
703 
707  static void setNullRepresentation( const QString &nullRepresentation );
708 
716  static QVariantMap customVariables();
717 
725  static void setCustomVariables( const QVariantMap &customVariables );
726 
727 
733  static void setCustomVariable( const QString &name, const QVariant &value );
734 
735 #ifdef SIP_RUN
736  SIP_IF_FEATURE( ANDROID )
737  //dummy method to workaround sip generation issue
738  bool x11EventFilter( XEvent *event );
739  SIP_END
740 #endif
741 
742  signals:
744  void preNotify( QObject *receiver, QEvent *event, bool *done ) SIP_SKIP;
745 
750  void customVariablesChanged();
751 
752 
756  void nullRepresentationChanged();
757 
758  private:
759 
760  static void copyPath( const QString &src, const QString &dst );
761  static QObject *ABISYM( mFileOpenEventReceiver );
762  static QStringList ABISYM( mFileOpenEventList );
763 
764  static QString ABISYM( mProfilePath );
765  static QString ABISYM( mUIThemeName );
766  static QString ABISYM( mPrefixPath );
767  static QString ABISYM( mPluginPath );
768  static QString ABISYM( mPkgDataPath );
769  static QString ABISYM( mLibraryPath );
770  static QString ABISYM( mLibexecPath );
771  static QString ABISYM( mQmlImportPath );
772  static QString ABISYM( mThemeName );
773  static QStringList ABISYM( mDefaultSvgPaths );
774  static QMap<QString, QString> ABISYM( mSystemEnvVars );
775 
776  static QString ABISYM( mConfigPath );
777 
778  static bool ABISYM( mInitialized );
779 
781  static bool ABISYM( mRunningFromBuildDir );
783  static QString ABISYM( mBuildSourcePath );
784 #ifdef _MSC_VER
785  static QString ABISYM( mCfgIntDir );
787 #endif
788  static QString ABISYM( mBuildOutputPath );
790 
794  static QStringList ABISYM( mGdalSkipList );
795 
798  static int ABISYM( mMaxThreads );
799 
802  static QString ABISYM( mAuthDbDirPath );
803 
804  static QString sUserName;
805  static QString sUserFullName;
806  static QString sPlatformName;
807 
808  QMap<QString, QIcon> mIconCache;
809  QMap<Cursor, QCursor> mCursorCache;
810 
811  QgsDataItemProviderRegistry *mDataItemProviderRegistry = nullptr;
812  QgsAuthManager *mAuthManager = nullptr;
813 
814  struct ApplicationMembers
815  {
816  Qgs3DRendererRegistry *m3DRendererRegistry = nullptr;
817  QgsActionScopeRegistry *mActionScopeRegistry = nullptr;
818  QgsAnnotationRegistry *mAnnotationRegistry = nullptr;
819  QgsColorSchemeRegistry *mColorSchemeRegistry = nullptr;
820  QgsFieldFormatterRegistry *mFieldFormatterRegistry = nullptr;
821  QgsGpsConnectionRegistry *mGpsConnectionRegistry = nullptr;
822  QgsNetworkContentFetcherRegistry *mNetworkContentFetcherRegistry = nullptr;
823  QgsMessageLog *mMessageLog = nullptr;
824  QgsPaintEffectRegistry *mPaintEffectRegistry = nullptr;
825  QgsPluginLayerRegistry *mPluginLayerRegistry = nullptr;
826  QgsProcessingRegistry *mProcessingRegistry = nullptr;
827  QgsProjectStorageRegistry *mProjectStorageRegistry = nullptr;
828  QgsPageSizeRegistry *mPageSizeRegistry = nullptr;
829  QgsRasterRendererRegistry *mRasterRendererRegistry = nullptr;
830  QgsRendererRegistry *mRendererRegistry = nullptr;
831  QgsRuntimeProfiler *mProfiler = nullptr;
832  QgsSvgCache *mSvgCache = nullptr;
833  QgsSymbolLayerRegistry *mSymbolLayerRegistry = nullptr;
834  QgsTaskManager *mTaskManager = nullptr;
835  QgsLayoutItemRegistry *mLayoutItemRegistry = nullptr;
836  QgsUserProfileManager *mUserConfigManager = nullptr;
837  QString mNullRepresentation;
838 
839  ApplicationMembers();
840  ~ApplicationMembers();
841  };
842 
843  // Applications members which belong to an instance of QgsApplication
844  ApplicationMembers *mApplicationMembers = nullptr;
845  // ... but in case QgsApplication is never instantiated (eg with custom designer widgets), we fall back to static members
846  static ApplicationMembers *sApplicationMembers;
847 
848  static ApplicationMembers *members();
849 };
850 
851 // clazy:excludeall=qstring-allocations
852 
853 #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.
QString iconPath(const QString &iconFile)
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.
#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
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.