QGIS API Documentation  3.6.0-Noosa (5873452)
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;
43 class QgsMessageLog;
45 class QgsAnnotationRegistry;
46 class QgsUserProfile;
50 class QgsAuthManager;
53 class QTranslator;
54 
70 class CORE_EXPORT QgsApplication : public QApplication
71 {
72 
73 #ifdef SIP_RUN
74  % TypeCode
75  // Convert a Python argv list to a conventional C argc count and argv array.
76  static char **qtgui_ArgvToC( PyObject *argvlist, int &argc )
77  {
78  char **argv;
79 
80  argc = PyList_GET_SIZE( argvlist );
81 
82  // Allocate space for two copies of the argument pointers, plus the
83  // terminating NULL.
84  if ( ( argv = ( char ** )sipMalloc( 2 * ( argc + 1 ) * sizeof( char * ) ) ) == NULL )
85  return NULL;
86 
87  // Convert the list.
88  for ( int a = 0; a < argc; ++a )
89  {
90  char *arg;
91  // Get the argument and allocate memory for it.
92  if ( ( arg = PyBytes_AsString( PyList_GET_ITEM( argvlist, a ) ) ) == NULL ||
93  ( argv[a] = ( char * )sipMalloc( strlen( arg ) + 1 ) ) == NULL )
94  return NULL;
95  // Copy the argument and save a pointer to it.
96  strcpy( argv[a], arg );
97  argv[a + argc + 1] = argv[a];
98  }
99 
100  argv[argc + argc + 1] = argv[argc] = NULL;
101 
102  return argv;
103  }
104 
105  // Remove arguments from the Python argv list that have been removed from the
106  // C argv array.
107  static void qtgui_UpdatePyArgv( PyObject *argvlist, int argc, char **argv )
108  {
109  for ( int a = 0, na = 0; a < argc; ++a )
110  {
111  // See if it was removed.
112  if ( argv[na] == argv[a + argc + 1] )
113  ++na;
114  else
115  PyList_SetSlice( argvlist, na, na + 1, NULL );
116  }
117  }
118  % End
119 #endif
120 
121  Q_OBJECT
122 
123  public:
124 
125  static const char *QGIS_ORGANIZATION_NAME;
126  static const char *QGIS_ORGANIZATION_DOMAIN;
127  static const char *QGIS_APPLICATION_NAME;
128 #ifndef SIP_RUN
129  QgsApplication( int &argc, char **argv, bool GUIenabled, const QString &profileFolder = QString(), const QString &platformName = "desktop" );
130 #else
131  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" )];
132  % MethodCode
133  // The Python interface is a list of argument strings that is modified.
134 
135  int argc;
136  char **argv;
137 
138  // Convert the list.
139  if ( ( argv = qtgui_ArgvToC( a0, argc ) ) == NULL )
140  sipIsErr = 1;
141  else
142  {
143  // Create it now the arguments are right.
144  static int nargc = argc;
145 
146  sipCpp = new sipQgsApplication( nargc, argv, a1, *a2, *a3 );
147 
148  // Now modify the original list.
149  qtgui_UpdatePyArgv( a0, argc, argv );
150  }
151  % End
152 #endif
153 
154  ~QgsApplication() override;
155 
161  static QgsApplication *instance();
162 
170  static void init( QString profileFolder = QString() ) SIP_SKIP;
171 
173  bool event( QEvent *event ) override;
174 
176  bool notify( QObject *receiver, QEvent *event ) override;
177 
179  static void setFileOpenEventReceiver( QObject *receiver );
180 
191  static void setThemeName( const QString &themeName );
192 
197  static QString resolvePkgPath();
198 
206  static QString themeName();
207 
215  static void setUITheme( const QString &themeName );
216 
223  static QHash<QString, QString> uiThemes();
224 
226  static QString authorsFilePath();
227 
232  static QString contributorsFilePath();
233 
239  static QString developersMapFilePath();
240 
242  static QString sponsorsFilePath();
243 
245  static QString donorsFilePath();
246 
248  static QString serverResourcesPath();
249 
253  static QString translatorsFilePath();
254 
258  static QString licenceFilePath();
259 
261  static QString i18nPath();
262 
267  static QString metadataPath();
268 
270  static QString qgisMasterDatabaseFilePath();
271 
273  static QString qgisSettingsDirPath();
274 
276  static QString qgisUserDatabaseFilePath();
277 
279  static QString qgisAuthDatabaseFilePath();
280 
282  static QString splashPath();
283 
285  static QString iconsPath();
286 
288  static QString srsDatabaseFilePath();
289 
291  static QStringList svgPaths();
292 
297  static QStringList layoutTemplatePaths();
298 
300  static QMap<QString, QString> systemEnvVars() { return ABISYM( mSystemEnvVars ); }
301 
303  static QString prefixPath();
304 
306  static QString pluginPath();
307 
309  static QString pkgDataPath();
310 
312  static QString activeThemePath();
313 
315  static QString defaultThemePath();
316 
321  static QString iconPath( const QString &iconFile );
322 
327  static QIcon getThemeIcon( const QString &name );
328 
333  enum Cursor
334  {
342  };
343 
350  static QCursor getThemeCursor( Cursor cursor );
351 
356  static QPixmap getThemePixmap( const QString &name );
357 
359  static QString userStylePath();
360 
362  static QRegExp shortNameRegExp();
363 
369  static QString userLoginName();
370 
376  static QString userFullName();
377 
383  static QString osName();
384 
390  static QString platform();
391 
396  static QString locale();
397 
399  static QString userThemesFolder();
400 
402  static QString defaultStylePath();
403 
405  static QString defaultThemesFolder();
406 
408  static QString libraryPath();
409 
411  static QString libexecPath();
412 
419  static QString qmlImportPath();
420 
422  static void setPrefixPath( const QString &prefixPath, bool useDefaultPaths = false );
423 
425  static void setPluginPath( const QString &pluginPath );
426 
428  static void setPkgDataPath( const QString &pkgDataPath );
429 
431  static void setDefaultSvgPaths( const QStringList &pathList );
432 
434  static void setAuthDatabaseDirPath( const QString &authDbDirPath );
435 
437  static void initQgis();
438 
440  static bool createDatabase( QString *errorMessage = nullptr );
441 
443  static bool createThemeFolder();
444 
446  static void exitQgis();
447 
449  static QString appIconPath();
450 
452  enum endian_t
453  {
454  XDR = 0, // network, or big-endian, byte order
455  NDR = 1 // little-endian byte order
456  };
457 
459  static endian_t endian();
460 
472  static QString reportStyleSheet();
473 
477  static QString showSettings();
478 
486  static void registerOgrDrivers();
487 
489  static QString absolutePathToRelativePath( const QString &apath, const QString &targetPath );
491  static QString relativePathToAbsolutePath( const QString &rpath, const QString &targetPath );
492 
494  static bool isRunningFromBuildDir() { return ABISYM( mRunningFromBuildDir ); }
495 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
496  static QString cfgIntDir() { return ABISYM( mCfgIntDir ); } SIP_SKIP
497 #endif
498  static QString buildSourcePath() { return ABISYM( mBuildSourcePath ); }
501  static QString buildOutputPath() { return ABISYM( mBuildOutputPath ); }
502 
508  static void skipGdalDriver( const QString &driver );
509 
515  static void restoreGdalDriver( const QString &driver );
516 
521  static QStringList skippedGdalDrivers() { return ABISYM( mGdalSkipList ); }
522 
528  static void applyGdalSkippedDrivers();
529 
533  static int maxThreads() { return ABISYM( mMaxThreads ); }
534 
539  static void setMaxThreads( int maxThreads );
540 
546  static QgsTaskManager *taskManager();
547 
552  static QgsColorSchemeRegistry *colorSchemeRegistry() SIP_KEEPREFERENCE;
553 
558  static QgsPaintEffectRegistry *paintEffectRegistry() SIP_KEEPREFERENCE;
559 
564  static QgsRendererRegistry *rendererRegistry() SIP_KEEPREFERENCE;
565 
571  static QgsRasterRendererRegistry *rasterRendererRegistry() SIP_SKIP;
572 
578  static QgsDataItemProviderRegistry *dataItemProviderRegistry() SIP_KEEPREFERENCE;
579 
587  static QgsSvgCache *svgCache();
588 
595  static QgsImageCache *imageCache();
596 
601  static QgsNetworkContentFetcherRegistry *networkContentFetcherRegistry() SIP_KEEPREFERENCE;
602 
607  static QgsValidityCheckRegistry *validityCheckRegistry() SIP_KEEPREFERENCE;
608 
613  static QgsSymbolLayerRegistry *symbolLayerRegistry();
614 
619  static QgsLayoutItemRegistry *layoutItemRegistry();
620 
625  static QgsGpsConnectionRegistry *gpsConnectionRegistry();
626 
631  static QgsPluginLayerRegistry *pluginLayerRegistry();
632 
637  static QgsMessageLog *messageLog();
638 
645  static QgsAuthManager *authManager();
646 
652  static QgsProcessingRegistry *processingRegistry();
653 
658  static QgsPageSizeRegistry *pageSizeRegistry();
659 
665  static QgsAnnotationRegistry *annotationRegistry() SIP_SKIP;
666 
672  static QgsActionScopeRegistry *actionScopeRegistry() SIP_KEEPREFERENCE;
673 
678  static QgsRuntimeProfiler *profiler();
679 
683  static QgsFieldFormatterRegistry *fieldFormatterRegistry() SIP_KEEPREFERENCE;
684 
689  static Qgs3DRendererRegistry *renderer3DRegistry() SIP_KEEPREFERENCE;
690 
695  static QgsProjectStorageRegistry *projectStorageRegistry() SIP_KEEPREFERENCE;
696 
705  static QString nullRepresentation();
706 
710  static void setNullRepresentation( const QString &nullRepresentation );
711 
719  static QVariantMap customVariables();
720 
728  static void setCustomVariables( const QVariantMap &customVariables );
729 
735  static void setCustomVariable( const QString &name, const QVariant &value );
736 
745  int maxConcurrentConnectionsPerPool() const;
746 
752  static void setTranslation( const QString &translation ) { sTranslation = translation; }
753 
759  void collectTranslatableObjects( QgsTranslationContext *translationContext );
760 
761 #ifdef SIP_RUN
762  SIP_IF_FEATURE( ANDROID )
763  //dummy method to workaround sip generation issue
764  bool x11EventFilter( XEvent *event );
765  SIP_END
766 #endif
767 
768  signals:
770  void preNotify( QObject *receiver, QEvent *event, bool *done ) SIP_SKIP;
771 
776  void customVariablesChanged();
777 
778 
782  void nullRepresentationChanged();
783 
790  void requestForTranslatableObjects( QgsTranslationContext *translationContext );
791 
792  private:
793 
794  static void copyPath( const QString &src, const QString &dst );
795  static QObject *ABISYM( mFileOpenEventReceiver );
796  static QStringList ABISYM( mFileOpenEventList );
797 
798  static QString ABISYM( mProfilePath );
799  static QString ABISYM( mUIThemeName );
800  static QString ABISYM( mPrefixPath );
801  static QString ABISYM( mPluginPath );
802  static QString ABISYM( mPkgDataPath );
803  static QString ABISYM( mLibraryPath );
804  static QString ABISYM( mLibexecPath );
805  static QString ABISYM( mQmlImportPath );
806  static QString ABISYM( mThemeName );
807  static QStringList ABISYM( mDefaultSvgPaths );
808  static QMap<QString, QString> ABISYM( mSystemEnvVars );
809 
810  static QString ABISYM( mConfigPath );
811 
812  static bool ABISYM( mInitialized );
813 
815  static bool ABISYM( mRunningFromBuildDir );
817  static QString ABISYM( mBuildSourcePath );
818 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
819  static QString ABISYM( mCfgIntDir );
821 #endif
822  static QString ABISYM( mBuildOutputPath );
824 
828  static QStringList ABISYM( mGdalSkipList );
829 
832  static int ABISYM( mMaxThreads );
833 
836  static QString ABISYM( mAuthDbDirPath );
837 
838  static QString sUserName;
839  static QString sUserFullName;
840  static QString sPlatformName;
841  static QString sTranslation;
842 
843  QMap<QString, QIcon> mIconCache;
844  QMap<Cursor, QCursor> mCursorCache;
845 
846  QTranslator *mQgisTranslator = nullptr;
847  QTranslator *mQtTranslator = nullptr;
848 
849  QgsDataItemProviderRegistry *mDataItemProviderRegistry = nullptr;
850  QgsAuthManager *mAuthManager = nullptr;
851 
852  struct ApplicationMembers
853  {
854  Qgs3DRendererRegistry *m3DRendererRegistry = nullptr;
855  QgsActionScopeRegistry *mActionScopeRegistry = nullptr;
856  QgsAnnotationRegistry *mAnnotationRegistry = nullptr;
857  QgsColorSchemeRegistry *mColorSchemeRegistry = nullptr;
858  QgsFieldFormatterRegistry *mFieldFormatterRegistry = nullptr;
859  QgsGpsConnectionRegistry *mGpsConnectionRegistry = nullptr;
860  QgsNetworkContentFetcherRegistry *mNetworkContentFetcherRegistry = nullptr;
861  QgsValidityCheckRegistry *mValidityCheckRegistry = nullptr;
862  QgsMessageLog *mMessageLog = nullptr;
863  QgsPaintEffectRegistry *mPaintEffectRegistry = nullptr;
864  QgsPluginLayerRegistry *mPluginLayerRegistry = nullptr;
865  QgsProcessingRegistry *mProcessingRegistry = nullptr;
866  QgsProjectStorageRegistry *mProjectStorageRegistry = nullptr;
867  QgsPageSizeRegistry *mPageSizeRegistry = nullptr;
868  QgsRasterRendererRegistry *mRasterRendererRegistry = nullptr;
869  QgsRendererRegistry *mRendererRegistry = nullptr;
870  QgsRuntimeProfiler *mProfiler = nullptr;
871  QgsSvgCache *mSvgCache = nullptr;
872  QgsImageCache *mImageCache = nullptr;
873  QgsSymbolLayerRegistry *mSymbolLayerRegistry = nullptr;
874  QgsTaskManager *mTaskManager = nullptr;
875  QgsLayoutItemRegistry *mLayoutItemRegistry = nullptr;
876  QgsUserProfileManager *mUserConfigManager = nullptr;
877  QString mNullRepresentation;
878 
879  ApplicationMembers();
880  ~ApplicationMembers();
881  };
882 
883  // Applications members which belong to an instance of QgsApplication
884  ApplicationMembers *mApplicationMembers = nullptr;
885  // ... but in case QgsApplication is never instantiated (eg with custom designer widgets), we fall back to static members
886  static ApplicationMembers *sApplicationMembers;
887 
888  static ApplicationMembers *members();
889 };
890 
891 // clazy:excludeall=qstring-allocations
892 
893 #endif
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) ...
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: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
#define SIP_KEEPREFERENCE
Definition: qgis_sip.h:79
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)
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.