QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
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;
59 
75 class CORE_EXPORT QgsApplication : public QApplication
76 {
77 
78 #ifdef SIP_RUN
79  % TypeCode
80  // Convert a Python argv list to a conventional C argc count and argv array.
81  static char **qtgui_ArgvToC( PyObject *argvlist, int &argc )
82  {
83  char **argv;
84 
85  argc = PyList_GET_SIZE( argvlist );
86 
87  // Allocate space for two copies of the argument pointers, plus the
88  // terminating NULL.
89  if ( ( argv = ( char ** )sipMalloc( 2 * ( argc + 1 ) * sizeof( char * ) ) ) == NULL )
90  return NULL;
91 
92  // Convert the list.
93  for ( int a = 0; a < argc; ++a )
94  {
95  char *arg;
96  // Get the argument and allocate memory for it.
97  if ( ( arg = PyBytes_AsString( PyList_GET_ITEM( argvlist, a ) ) ) == NULL ||
98  ( argv[a] = ( char * )sipMalloc( strlen( arg ) + 1 ) ) == NULL )
99  return NULL;
100  // Copy the argument and save a pointer to it.
101  strcpy( argv[a], arg );
102  argv[a + argc + 1] = argv[a];
103  }
104 
105  argv[argc + argc + 1] = argv[argc] = NULL;
106 
107  return argv;
108  }
109 
110  // Remove arguments from the Python argv list that have been removed from the
111  // C argv array.
112  static void qtgui_UpdatePyArgv( PyObject *argvlist, int argc, char **argv )
113  {
114  for ( int a = 0, na = 0; a < argc; ++a )
115  {
116  // See if it was removed.
117  if ( argv[na] == argv[a + argc + 1] )
118  ++na;
119  else
120  PyList_SetSlice( argvlist, na, na + 1, NULL );
121  }
122  }
123  % End
124 #endif
125 
126  Q_OBJECT
127 
128  public:
129 
139  {
140  Qt,
142  };
143 
144  static const char *QGIS_ORGANIZATION_NAME;
145  static const char *QGIS_ORGANIZATION_DOMAIN;
146  static const char *QGIS_APPLICATION_NAME;
147 #ifndef SIP_RUN
148  QgsApplication( int &argc, char **argv, bool GUIenabled, const QString &profileFolder = QString(), const QString &platformName = "desktop" );
149 #else
150  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" )];
151  % MethodCode
152  // The Python interface is a list of argument strings that is modified.
153 
154  int argc;
155  char **argv;
156 
157  // Convert the list.
158  if ( ( argv = qtgui_ArgvToC( a0, argc ) ) == NULL )
159  sipIsErr = 1;
160  else
161  {
162  // Create it now the arguments are right.
163  static int nargc = argc;
164 
165  sipCpp = new sipQgsApplication( nargc, argv, a1, *a2, *a3 );
166 
167  // Now modify the original list.
168  qtgui_UpdatePyArgv( a0, argc, argv );
169  }
170  % End
171 #endif
172 
173  ~QgsApplication() override;
174 
180  static QgsApplication *instance();
181 
189  static void init( QString profileFolder = QString() ) SIP_SKIP;
190 
192  bool event( QEvent *event ) override;
193 
195  bool notify( QObject *receiver, QEvent *event ) override;
196 
198  static void setFileOpenEventReceiver( QObject *receiver );
199 
210  static void setThemeName( const QString &themeName );
211 
216  static QString resolvePkgPath();
217 
225  static QString themeName();
226 
234  static void setUITheme( const QString &themeName );
235 
242  static QHash<QString, QString> uiThemes();
243 
245  static QString authorsFilePath();
246 
251  static QString contributorsFilePath();
252 
258  static QString developersMapFilePath();
259 
261  static QString sponsorsFilePath();
262 
264  static QString donorsFilePath();
265 
267  static QString serverResourcesPath();
268 
272  static QString translatorsFilePath();
273 
277  static QString licenceFilePath();
278 
280  static QString i18nPath();
281 
286  static QString metadataPath();
287 
289  static QString qgisMasterDatabaseFilePath();
290 
292  static QString qgisSettingsDirPath();
293 
295  static QString qgisUserDatabaseFilePath();
296 
298  static QString qgisAuthDatabaseFilePath();
299 
301  static QString splashPath();
302 
304  static QString iconsPath();
305 
307  static QString srsDatabaseFilePath();
308 
310  static QStringList svgPaths();
311 
316  static QStringList layoutTemplatePaths();
317 
319  static QMap<QString, QString> systemEnvVars();
320 
322  static QString prefixPath();
323 
325  static QString pluginPath();
326 
328  static QString pkgDataPath();
329 
331  static QString activeThemePath();
332 
334  static QString defaultThemePath();
335 
340  static QString iconPath( const QString &iconFile );
341 
346  static QIcon getThemeIcon( const QString &name );
347 
352  enum Cursor
353  {
361  };
362 
369  static QCursor getThemeCursor( Cursor cursor );
370 
375  static QPixmap getThemePixmap( const QString &name );
376 
378  static QString userStylePath();
379 
381  static QRegExp shortNameRegExp();
382 
388  static QString userLoginName();
389 
395  static QString userFullName();
396 
402  static QString osName();
403 
409  static QString platform();
410 
415  static QString locale();
416 
418  static QString userThemesFolder();
419 
421  static QString defaultStylePath();
422 
424  static QString defaultThemesFolder();
425 
427  static QString libraryPath();
428 
430  static QString libexecPath();
431 
438  static QString qmlImportPath();
439 
441  static void setPrefixPath( const QString &prefixPath, bool useDefaultPaths = false );
442 
444  static void setPluginPath( const QString &pluginPath );
445 
447  static void setPkgDataPath( const QString &pkgDataPath );
448 
450  static void setDefaultSvgPaths( const QStringList &pathList );
451 
453  static void setAuthDatabaseDirPath( const QString &authDbDirPath );
454 
456  static void initQgis();
457 
459  static bool createDatabase( QString *errorMessage = nullptr );
460 
462  static bool createThemeFolder();
463 
465  static void exitQgis();
466 
468  static QString appIconPath();
469 
471  enum endian_t
472  {
473  XDR = 0, // network, or big-endian, byte order
474  NDR = 1 // little-endian byte order
475  };
476 
478  static endian_t endian();
479 
494  static QString reportStyleSheet( QgsApplication::StyleSheetType styleSheetType = QgsApplication::StyleSheetType::Qt );
495 
499  static QString showSettings();
500 
508  static void registerOgrDrivers();
509 
511  static QString absolutePathToRelativePath( const QString &apath, const QString &targetPath );
513  static QString relativePathToAbsolutePath( const QString &rpath, const QString &targetPath );
514 
516  static bool isRunningFromBuildDir() { return ABISYM( mRunningFromBuildDir ); }
517 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
518  static QString cfgIntDir() SIP_SKIP;
519 #endif
520  static QString buildSourcePath();
523  static QString buildOutputPath();
524 
530  static void skipGdalDriver( const QString &driver );
531 
537  static void restoreGdalDriver( const QString &driver );
538 
543  static QStringList skippedGdalDrivers();
544 
551  static void applyGdalSkippedDrivers();
552 
557  static void registerGdalDriversFromSettings();
558 
565  static QStringList deferredSkippedGdalDrivers();
566 
573  static void setSkippedGdalDrivers( const QStringList &skippedGdalDrivers,
574  const QStringList &deferredSkippedGdalDrivers );
575 
579  static int maxThreads();
580 
585  static void setMaxThreads( int maxThreads );
586 
592  static QgsTaskManager *taskManager();
593 
598  static QgsColorSchemeRegistry *colorSchemeRegistry() SIP_KEEPREFERENCE;
599 
604  static QgsPaintEffectRegistry *paintEffectRegistry() SIP_KEEPREFERENCE;
605 
610  static QgsRendererRegistry *rendererRegistry() SIP_KEEPREFERENCE;
611 
617  static QgsRasterRendererRegistry *rasterRendererRegistry() SIP_SKIP;
618 
624  static QgsDataItemProviderRegistry *dataItemProviderRegistry() SIP_KEEPREFERENCE;
625 
633  static QgsSvgCache *svgCache();
634 
641  static QgsImageCache *imageCache();
642 
647  static QgsNetworkContentFetcherRegistry *networkContentFetcherRegistry() SIP_KEEPREFERENCE;
648 
653  static QgsValidityCheckRegistry *validityCheckRegistry() SIP_KEEPREFERENCE;
654 
659  static QgsSymbolLayerRegistry *symbolLayerRegistry() SIP_KEEPREFERENCE;
660 
665  static QgsCalloutRegistry *calloutRegistry() SIP_KEEPREFERENCE;
666 
671  static QgsLayoutItemRegistry *layoutItemRegistry() SIP_KEEPREFERENCE;
672 
677  static QgsGpsConnectionRegistry *gpsConnectionRegistry() SIP_KEEPREFERENCE;
678 
683  static QgsPluginLayerRegistry *pluginLayerRegistry() SIP_KEEPREFERENCE;
684 
689  static QgsClassificationMethodRegistry *classificationMethodRegistry() SIP_KEEPREFERENCE;
690 
695  static QgsBookmarkManager *bookmarkManager();
696 
704  static QgsStyleModel *defaultStyleModel();
705 
710  static QgsMessageLog *messageLog();
711 
718  static QgsAuthManager *authManager();
719 
725  static QgsProcessingRegistry *processingRegistry();
726 
731  static QgsPageSizeRegistry *pageSizeRegistry() SIP_KEEPREFERENCE;
732 
738  static QgsAnnotationRegistry *annotationRegistry() SIP_SKIP;
739 
745  static QgsActionScopeRegistry *actionScopeRegistry() SIP_KEEPREFERENCE;
746 
751  static QgsRuntimeProfiler *profiler();
752 
758  static QgsNumericFormatRegistry *numericFormatRegistry() SIP_KEEPREFERENCE;
759 
763  static QgsFieldFormatterRegistry *fieldFormatterRegistry() SIP_KEEPREFERENCE;
764 
769  static Qgs3DRendererRegistry *renderer3DRegistry() SIP_KEEPREFERENCE;
770 
775  static QgsProjectStorageRegistry *projectStorageRegistry() SIP_KEEPREFERENCE;
776 
785  static QString nullRepresentation();
786 
790  static void setNullRepresentation( const QString &nullRepresentation );
791 
799  static QVariantMap customVariables();
800 
808  static void setCustomVariables( const QVariantMap &customVariables );
809 
815  static void setCustomVariable( const QString &name, const QVariant &value );
816 
825  int maxConcurrentConnectionsPerPool() const;
826 
832  static void setTranslation( const QString &translation );
833 
839  void collectTranslatableObjects( QgsTranslationContext *translationContext );
840 
841 #ifdef SIP_RUN
842  SIP_IF_FEATURE( ANDROID )
843  //dummy method to workaround sip generation issue
844  bool x11EventFilter( XEvent *event );
845  SIP_END
846 #endif
847 
848  signals:
850  void preNotify( QObject *receiver, QEvent *event, bool *done ) SIP_SKIP;
851 
856  void customVariablesChanged();
857 
858 
862  void nullRepresentationChanged();
863 
870  void requestForTranslatableObjects( QgsTranslationContext *translationContext );
871 
872  private:
873 
874  static void copyPath( const QString &src, const QString &dst );
875  static QObject *ABISYM( mFileOpenEventReceiver );
876 
877  static bool ABISYM( mInitialized );
878 
880  static bool ABISYM( mRunningFromBuildDir );
881 
884  static int ABISYM( sMaxThreads );
885 
886  QMap<QString, QIcon> mIconCache;
887  QMap<Cursor, QCursor> mCursorCache;
888 
889  QTranslator *mQgisTranslator = nullptr;
890  QTranslator *mQtTranslator = nullptr;
891 
892  QgsDataItemProviderRegistry *mDataItemProviderRegistry = nullptr;
893  QgsAuthManager *mAuthManager = nullptr;
894 
895  struct ApplicationMembers
896  {
897  Qgs3DRendererRegistry *m3DRendererRegistry = nullptr;
898  QgsActionScopeRegistry *mActionScopeRegistry = nullptr;
899  QgsAnnotationRegistry *mAnnotationRegistry = nullptr;
900  QgsColorSchemeRegistry *mColorSchemeRegistry = nullptr;
901  QgsNumericFormatRegistry *mNumericFormatRegistry = nullptr;
902  QgsFieldFormatterRegistry *mFieldFormatterRegistry = nullptr;
903  QgsGpsConnectionRegistry *mGpsConnectionRegistry = nullptr;
904  QgsNetworkContentFetcherRegistry *mNetworkContentFetcherRegistry = nullptr;
905  QgsValidityCheckRegistry *mValidityCheckRegistry = nullptr;
906  QgsMessageLog *mMessageLog = nullptr;
907  QgsPaintEffectRegistry *mPaintEffectRegistry = nullptr;
908  QgsPluginLayerRegistry *mPluginLayerRegistry = nullptr;
909  QgsClassificationMethodRegistry *mClassificationMethodRegistry = nullptr;
910  QgsProcessingRegistry *mProcessingRegistry = nullptr;
911  QgsProjectStorageRegistry *mProjectStorageRegistry = nullptr;
912  QgsPageSizeRegistry *mPageSizeRegistry = nullptr;
913  QgsRasterRendererRegistry *mRasterRendererRegistry = nullptr;
914  QgsRendererRegistry *mRendererRegistry = nullptr;
915  QgsRuntimeProfiler *mProfiler = nullptr;
916  QgsSvgCache *mSvgCache = nullptr;
917  QgsImageCache *mImageCache = nullptr;
918  QgsSymbolLayerRegistry *mSymbolLayerRegistry = nullptr;
919  QgsCalloutRegistry *mCalloutRegistry = nullptr;
920  QgsTaskManager *mTaskManager = nullptr;
921  QgsLayoutItemRegistry *mLayoutItemRegistry = nullptr;
922  QgsUserProfileManager *mUserConfigManager = nullptr;
923  QgsBookmarkManager *mBookmarkManager = nullptr;
924  QgsStyleModel *mStyleModel = nullptr;
925  QString mNullRepresentation;
926 
927  ApplicationMembers();
928  ~ApplicationMembers();
929  };
930 
931  // Applications members which belong to an instance of QgsApplication
932  ApplicationMembers *mApplicationMembers = nullptr;
933  // ... but in case QgsApplication is never instantiated (eg with custom designer widgets), we fall back to static members
934  static ApplicationMembers *sApplicationMembers;
935 
936  static QgsAuthManager *sAuthManager;
937 
938  static ApplicationMembers *members();
939 
940  static void invalidateCaches();
941 };
942 
943 // clazy:excludeall=qstring-allocations
944 
945 #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.
StyleSheet for Qt GUI widgets (based on QLabel or QTextBrowser), supports basic CSS and Qt extensions...
User profile contains information about the user profile folders on the machine.
Precisely identify a point on the canvas.
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.
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.
#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.
StyleSheetType
The StyleSheetType enum represents the stylesheet type that a widget supports.
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.
The QgsNumericFormatRegistry manages registered classes of QgsNumericFormat.
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
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.