QGIS API Documentation  3.9.0-Master (224899f119)
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 
73 class CORE_EXPORT QgsApplication : public QApplication
74 {
75 
76 #ifdef SIP_RUN
77  % TypeCode
78  // Convert a Python argv list to a conventional C argc count and argv array.
79  static char **qtgui_ArgvToC( PyObject *argvlist, int &argc )
80  {
81  char **argv;
82 
83  argc = PyList_GET_SIZE( argvlist );
84 
85  // Allocate space for two copies of the argument pointers, plus the
86  // terminating NULL.
87  if ( ( argv = ( char ** )sipMalloc( 2 * ( argc + 1 ) * sizeof( char * ) ) ) == NULL )
88  return NULL;
89 
90  // Convert the list.
91  for ( int a = 0; a < argc; ++a )
92  {
93  char *arg;
94  // Get the argument and allocate memory for it.
95  if ( ( arg = PyBytes_AsString( PyList_GET_ITEM( argvlist, a ) ) ) == NULL ||
96  ( argv[a] = ( char * )sipMalloc( strlen( arg ) + 1 ) ) == NULL )
97  return NULL;
98  // Copy the argument and save a pointer to it.
99  strcpy( argv[a], arg );
100  argv[a + argc + 1] = argv[a];
101  }
102 
103  argv[argc + argc + 1] = argv[argc] = NULL;
104 
105  return argv;
106  }
107 
108  // Remove arguments from the Python argv list that have been removed from the
109  // C argv array.
110  static void qtgui_UpdatePyArgv( PyObject *argvlist, int argc, char **argv )
111  {
112  for ( int a = 0, na = 0; a < argc; ++a )
113  {
114  // See if it was removed.
115  if ( argv[na] == argv[a + argc + 1] )
116  ++na;
117  else
118  PyList_SetSlice( argvlist, na, na + 1, NULL );
119  }
120  }
121  % End
122 #endif
123 
124  Q_OBJECT
125 
126  public:
127 
128  static const char *QGIS_ORGANIZATION_NAME;
129  static const char *QGIS_ORGANIZATION_DOMAIN;
130  static const char *QGIS_APPLICATION_NAME;
131 #ifndef SIP_RUN
132  QgsApplication( int &argc, char **argv, bool GUIenabled, const QString &profileFolder = QString(), const QString &platformName = "desktop" );
133 #else
134  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" )];
135  % MethodCode
136  // The Python interface is a list of argument strings that is modified.
137 
138  int argc;
139  char **argv;
140 
141  // Convert the list.
142  if ( ( argv = qtgui_ArgvToC( a0, argc ) ) == NULL )
143  sipIsErr = 1;
144  else
145  {
146  // Create it now the arguments are right.
147  static int nargc = argc;
148 
149  sipCpp = new sipQgsApplication( nargc, argv, a1, *a2, *a3 );
150 
151  // Now modify the original list.
152  qtgui_UpdatePyArgv( a0, argc, argv );
153  }
154  % End
155 #endif
156 
157  ~QgsApplication() override;
158 
164  static QgsApplication *instance();
165 
173  static void init( QString profileFolder = QString() ) SIP_SKIP;
174 
176  bool event( QEvent *event ) override;
177 
179  bool notify( QObject *receiver, QEvent *event ) override;
180 
182  static void setFileOpenEventReceiver( QObject *receiver );
183 
194  static void setThemeName( const QString &themeName );
195 
200  static QString resolvePkgPath();
201 
209  static QString themeName();
210 
218  static void setUITheme( const QString &themeName );
219 
226  static QHash<QString, QString> uiThemes();
227 
229  static QString authorsFilePath();
230 
235  static QString contributorsFilePath();
236 
242  static QString developersMapFilePath();
243 
245  static QString sponsorsFilePath();
246 
248  static QString donorsFilePath();
249 
251  static QString serverResourcesPath();
252 
256  static QString translatorsFilePath();
257 
261  static QString licenceFilePath();
262 
264  static QString i18nPath();
265 
270  static QString metadataPath();
271 
273  static QString qgisMasterDatabaseFilePath();
274 
276  static QString qgisSettingsDirPath();
277 
279  static QString qgisUserDatabaseFilePath();
280 
282  static QString qgisAuthDatabaseFilePath();
283 
285  static QString splashPath();
286 
288  static QString iconsPath();
289 
291  static QString srsDatabaseFilePath();
292 
294  static QStringList svgPaths();
295 
300  static QStringList layoutTemplatePaths();
301 
303  static QMap<QString, QString> systemEnvVars() { return ABISYM( mSystemEnvVars ); }
304 
306  static QString prefixPath();
307 
309  static QString pluginPath();
310 
312  static QString pkgDataPath();
313 
315  static QString activeThemePath();
316 
318  static QString defaultThemePath();
319 
324  static QString iconPath( const QString &iconFile );
325 
330  static QIcon getThemeIcon( const QString &name );
331 
336  enum Cursor
337  {
345  };
346 
353  static QCursor getThemeCursor( Cursor cursor );
354 
359  static QPixmap getThemePixmap( const QString &name );
360 
362  static QString userStylePath();
363 
365  static QRegExp shortNameRegExp();
366 
372  static QString userLoginName();
373 
379  static QString userFullName();
380 
386  static QString osName();
387 
393  static QString platform();
394 
399  static QString locale();
400 
402  static QString userThemesFolder();
403 
405  static QString defaultStylePath();
406 
408  static QString defaultThemesFolder();
409 
411  static QString libraryPath();
412 
414  static QString libexecPath();
415 
422  static QString qmlImportPath();
423 
425  static void setPrefixPath( const QString &prefixPath, bool useDefaultPaths = false );
426 
428  static void setPluginPath( const QString &pluginPath );
429 
431  static void setPkgDataPath( const QString &pkgDataPath );
432 
434  static void setDefaultSvgPaths( const QStringList &pathList );
435 
437  static void setAuthDatabaseDirPath( const QString &authDbDirPath );
438 
440  static void initQgis();
441 
443  static bool createDatabase( QString *errorMessage = nullptr );
444 
446  static bool createThemeFolder();
447 
449  static void exitQgis();
450 
452  static QString appIconPath();
453 
455  enum endian_t
456  {
457  XDR = 0, // network, or big-endian, byte order
458  NDR = 1 // little-endian byte order
459  };
460 
462  static endian_t endian();
463 
475  static QString reportStyleSheet();
476 
480  static QString showSettings();
481 
489  static void registerOgrDrivers();
490 
492  static QString absolutePathToRelativePath( const QString &apath, const QString &targetPath );
494  static QString relativePathToAbsolutePath( const QString &rpath, const QString &targetPath );
495 
497  static bool isRunningFromBuildDir() { return ABISYM( mRunningFromBuildDir ); }
498 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
499  static QString cfgIntDir() { return ABISYM( mCfgIntDir ); } SIP_SKIP
500 #endif
501  static QString buildSourcePath() { return ABISYM( mBuildSourcePath ); }
504  static QString buildOutputPath() { return ABISYM( mBuildOutputPath ); }
505 
511  static void skipGdalDriver( const QString &driver );
512 
518  static void restoreGdalDriver( const QString &driver );
519 
524  static QStringList skippedGdalDrivers() { return ABISYM( mGdalSkipList ); }
525 
531  static void applyGdalSkippedDrivers();
532 
536  static int maxThreads() { return ABISYM( mMaxThreads ); }
537 
542  static void setMaxThreads( int maxThreads );
543 
549  static QgsTaskManager *taskManager();
550 
555  static QgsColorSchemeRegistry *colorSchemeRegistry() SIP_KEEPREFERENCE;
556 
561  static QgsPaintEffectRegistry *paintEffectRegistry() SIP_KEEPREFERENCE;
562 
567  static QgsRendererRegistry *rendererRegistry() SIP_KEEPREFERENCE;
568 
574  static QgsRasterRendererRegistry *rasterRendererRegistry() SIP_SKIP;
575 
581  static QgsDataItemProviderRegistry *dataItemProviderRegistry() SIP_KEEPREFERENCE;
582 
590  static QgsSvgCache *svgCache();
591 
598  static QgsImageCache *imageCache();
599 
604  static QgsNetworkContentFetcherRegistry *networkContentFetcherRegistry() SIP_KEEPREFERENCE;
605 
610  static QgsValidityCheckRegistry *validityCheckRegistry() SIP_KEEPREFERENCE;
611 
616  static QgsSymbolLayerRegistry *symbolLayerRegistry() SIP_KEEPREFERENCE;
617 
622  static QgsCalloutRegistry *calloutRegistry() SIP_KEEPREFERENCE;
623 
628  static QgsLayoutItemRegistry *layoutItemRegistry() SIP_KEEPREFERENCE;
629 
634  static QgsGpsConnectionRegistry *gpsConnectionRegistry() SIP_KEEPREFERENCE;
635 
640  static QgsPluginLayerRegistry *pluginLayerRegistry() SIP_KEEPREFERENCE;
641 
646  static QgsClassificationMethodRegistry *classificationMethodRegistry() SIP_KEEPREFERENCE;
647 
652  static QgsBookmarkManager *bookmarkManager();
653 
658  static QgsMessageLog *messageLog();
659 
666  static QgsAuthManager *authManager();
667 
673  static QgsProcessingRegistry *processingRegistry();
674 
679  static QgsPageSizeRegistry *pageSizeRegistry() SIP_KEEPREFERENCE;
680 
686  static QgsAnnotationRegistry *annotationRegistry() SIP_SKIP;
687 
693  static QgsActionScopeRegistry *actionScopeRegistry() SIP_KEEPREFERENCE;
694 
699  static QgsRuntimeProfiler *profiler();
700 
704  static QgsFieldFormatterRegistry *fieldFormatterRegistry() SIP_KEEPREFERENCE;
705 
710  static Qgs3DRendererRegistry *renderer3DRegistry() SIP_KEEPREFERENCE;
711 
716  static QgsProjectStorageRegistry *projectStorageRegistry() SIP_KEEPREFERENCE;
717 
726  static QString nullRepresentation();
727 
731  static void setNullRepresentation( const QString &nullRepresentation );
732 
740  static QVariantMap customVariables();
741 
749  static void setCustomVariables( const QVariantMap &customVariables );
750 
756  static void setCustomVariable( const QString &name, const QVariant &value );
757 
766  int maxConcurrentConnectionsPerPool() const;
767 
773  static void setTranslation( const QString &translation ) { sTranslation = translation; }
774 
780  void collectTranslatableObjects( QgsTranslationContext *translationContext );
781 
782 #ifdef SIP_RUN
783  SIP_IF_FEATURE( ANDROID )
784  //dummy method to workaround sip generation issue
785  bool x11EventFilter( XEvent *event );
786  SIP_END
787 #endif
788 
789  signals:
791  void preNotify( QObject *receiver, QEvent *event, bool *done ) SIP_SKIP;
792 
797  void customVariablesChanged();
798 
799 
803  void nullRepresentationChanged();
804 
811  void requestForTranslatableObjects( QgsTranslationContext *translationContext );
812 
813  private:
814 
815  static void copyPath( const QString &src, const QString &dst );
816  static QObject *ABISYM( mFileOpenEventReceiver );
817  static QStringList ABISYM( mFileOpenEventList );
818 
819  static QString ABISYM( mProfilePath );
820  static QString ABISYM( mUIThemeName );
821  static QString ABISYM( mPrefixPath );
822  static QString ABISYM( mPluginPath );
823  static QString ABISYM( mPkgDataPath );
824  static QString ABISYM( mLibraryPath );
825  static QString ABISYM( mLibexecPath );
826  static QString ABISYM( mQmlImportPath );
827  static QString ABISYM( mThemeName );
828  static QStringList ABISYM( mDefaultSvgPaths );
829  static QMap<QString, QString> ABISYM( mSystemEnvVars );
830 
831  static QString ABISYM( mConfigPath );
832 
833  static bool ABISYM( mInitialized );
834 
836  static bool ABISYM( mRunningFromBuildDir );
838  static QString ABISYM( mBuildSourcePath );
839 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
840  static QString ABISYM( mCfgIntDir );
842 #endif
843  static QString ABISYM( mBuildOutputPath );
845 
849  static QStringList ABISYM( mGdalSkipList );
850 
853  static int ABISYM( mMaxThreads );
854 
857  static QString ABISYM( mAuthDbDirPath );
858 
859  static QString sUserName;
860  static QString sUserFullName;
861  static QString sPlatformName;
862  static QString sTranslation;
863 
864  QMap<QString, QIcon> mIconCache;
865  QMap<Cursor, QCursor> mCursorCache;
866 
867  QTranslator *mQgisTranslator = nullptr;
868  QTranslator *mQtTranslator = nullptr;
869 
870  QgsDataItemProviderRegistry *mDataItemProviderRegistry = nullptr;
871  QgsAuthManager *mAuthManager = nullptr;
872 
873  struct ApplicationMembers
874  {
875  Qgs3DRendererRegistry *m3DRendererRegistry = nullptr;
876  QgsActionScopeRegistry *mActionScopeRegistry = nullptr;
877  QgsAnnotationRegistry *mAnnotationRegistry = nullptr;
878  QgsColorSchemeRegistry *mColorSchemeRegistry = nullptr;
879  QgsFieldFormatterRegistry *mFieldFormatterRegistry = nullptr;
880  QgsGpsConnectionRegistry *mGpsConnectionRegistry = nullptr;
881  QgsNetworkContentFetcherRegistry *mNetworkContentFetcherRegistry = nullptr;
882  QgsValidityCheckRegistry *mValidityCheckRegistry = nullptr;
883  QgsMessageLog *mMessageLog = nullptr;
884  QgsPaintEffectRegistry *mPaintEffectRegistry = nullptr;
885  QgsPluginLayerRegistry *mPluginLayerRegistry = nullptr;
886  QgsClassificationMethodRegistry *mClassificationMethodRegistry = nullptr;
887  QgsProcessingRegistry *mProcessingRegistry = nullptr;
888  QgsProjectStorageRegistry *mProjectStorageRegistry = nullptr;
889  QgsPageSizeRegistry *mPageSizeRegistry = nullptr;
890  QgsRasterRendererRegistry *mRasterRendererRegistry = nullptr;
891  QgsRendererRegistry *mRendererRegistry = nullptr;
892  QgsRuntimeProfiler *mProfiler = nullptr;
893  QgsSvgCache *mSvgCache = nullptr;
894  QgsImageCache *mImageCache = nullptr;
895  QgsSymbolLayerRegistry *mSymbolLayerRegistry = nullptr;
896  QgsCalloutRegistry *mCalloutRegistry = nullptr;
897  QgsTaskManager *mTaskManager = nullptr;
898  QgsLayoutItemRegistry *mLayoutItemRegistry = nullptr;
899  QgsUserProfileManager *mUserConfigManager = nullptr;
900  QgsBookmarkManager *mBookmarkManager = nullptr;
901  QString mNullRepresentation;
902 
903  ApplicationMembers();
904  ~ApplicationMembers();
905  };
906 
907  // Applications members which belong to an instance of QgsApplication
908  ApplicationMembers *mApplicationMembers = nullptr;
909  // ... but in case QgsApplication is never instantiated (eg with custom designer widgets), we fall back to static members
910  static ApplicationMembers *sApplicationMembers;
911 
912  static QgsAuthManager *sAuthManager;
913 
914  static ApplicationMembers *members();
915 };
916 
917 // clazy:excludeall=qstring-allocations
918 
919 #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) ...
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 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.