QGIS API Documentation  2.99.0-Master (19b062c)
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;
34 class QgsSvgCache;
40 class QgsMessageLog;
42 class QgsAnnotationRegistry;
43 class QgsUserProfile;
47 class QgsAuthManager;
48 
64 class CORE_EXPORT QgsApplication : public QApplication
65 {
66 
67 #ifdef SIP_RUN
68  % TypeCode
69  // Convert a Python argv list to a conventional C argc count and argv array.
70  static char **qtgui_ArgvToC( PyObject *argvlist, int &argc )
71  {
72  char **argv;
73 
74  argc = PyList_GET_SIZE( argvlist );
75 
76  // Allocate space for two copies of the argument pointers, plus the
77  // terminating NULL.
78  if ( ( argv = ( char ** )sipMalloc( 2 * ( argc + 1 ) * sizeof( char * ) ) ) == NULL )
79  return NULL;
80 
81  // Convert the list.
82  for ( int a = 0; a < argc; ++a )
83  {
84  char *arg;
85  // Get the argument and allocate memory for it.
86  if ( ( arg = PyBytes_AsString( PyList_GET_ITEM( argvlist, a ) ) ) == NULL ||
87  ( argv[a] = ( char * )sipMalloc( strlen( arg ) + 1 ) ) == NULL )
88  return NULL;
89  // Copy the argument and save a pointer to it.
90  strcpy( argv[a], arg );
91  argv[a + argc + 1] = argv[a];
92  }
93 
94  argv[argc + argc + 1] = argv[argc] = NULL;
95 
96  return argv;
97  }
98 
99  // Remove arguments from the Python argv list that have been removed from the
100  // C argv array.
101  static void qtgui_UpdatePyArgv( PyObject *argvlist, int argc, char **argv )
102  {
103  for ( int a = 0, na = 0; a < argc; ++a )
104  {
105  // See if it was removed.
106  if ( argv[na] == argv[a + argc + 1] )
107  ++na;
108  else
109  PyList_SetSlice( argvlist, na, na + 1, NULL );
110  }
111  }
112  % End
113 #endif
114 
115  Q_OBJECT
116 
117  public:
118 
119  static const char *QGIS_ORGANIZATION_NAME;
120  static const char *QGIS_ORGANIZATION_DOMAIN;
121  static const char *QGIS_APPLICATION_NAME;
122 #ifndef SIP_RUN
123  QgsApplication( int &argc, char **argv, bool GUIenabled, const QString &profileFolder = QString(), const QString &platformName = "desktop" );
124 #else
125  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" )];
126  % MethodCode
127  // The Python interface is a list of argument strings that is modified.
128 
129  int argc;
130  char **argv;
131 
132  // Convert the list.
133  if ( ( argv = qtgui_ArgvToC( a0, argc ) ) == NULL )
134  sipIsErr = 1;
135  else
136  {
137  // Create it now the arguments are right.
138  static int nargc = argc;
139 
140  sipCpp = new sipQgsApplication( nargc, argv, a1, *a2, *a3 );
141 
142  // Now modify the original list.
143  qtgui_UpdatePyArgv( a0, argc, argv );
144  }
145  % End
146 #endif
147 
148  virtual ~QgsApplication();
149 
155  static QgsApplication *instance();
156 
164  static void init( QString profileFolder = QString() ) SIP_SKIP;
165 
167  virtual bool event( QEvent *event ) override;
168 
170  virtual bool notify( QObject *receiver, QEvent *event ) override;
171 
173  static void setFileOpenEventReceiver( QObject *receiver );
174 
185  static void setThemeName( const QString &themeName );
186 
194  static QString themeName();
195 
203  static void setUITheme( const QString &themeName );
204 
211  static QHash<QString, QString> uiThemes();
212 
214  static QString authorsFilePath();
215 
220  static QString contributorsFilePath();
221 
227  static QString developersMapFilePath();
228 
230  static QString sponsorsFilePath();
231 
233  static QString donorsFilePath();
234 
236  static QString serverResourcesPath();
237 
241  static QString translatorsFilePath();
242 
246  static QString licenceFilePath();
247 
249  static QString i18nPath();
250 
255  static QString metadataPath();
256 
258  static QString qgisMasterDatabaseFilePath();
259 
261  static QString qgisSettingsDirPath();
262 
264  static QString qgisUserDatabaseFilePath();
265 
267  static QString qgisAuthDatabaseFilePath();
268 
270  static QString splashPath();
271 
273  static QString iconsPath();
274 
276  static QString srsDatabaseFilePath();
277 
279  static QStringList svgPaths();
280 
282  static QStringList composerTemplatePaths();
283 
285  static QMap<QString, QString> systemEnvVars() { return ABISYM( mSystemEnvVars ); }
286 
288  static QString prefixPath();
289 
291  static QString pluginPath();
292 
294  static QString pkgDataPath();
295 
297  static QString activeThemePath();
298 
300  static QString defaultThemePath();
301 
306  static QString iconPath( const QString &iconFile );
307 
312  static QIcon getThemeIcon( const QString &name );
313 
318  enum Cursor
319  {
327  };
328 
335  static QCursor getThemeCursor( const Cursor &cursor );
336 
341  static QPixmap getThemePixmap( const QString &name );
342 
344  static QString userStylePath();
345 
347  static QRegExp shortNameRegExp();
348 
354  static QString userLoginName();
355 
361  static QString userFullName();
362 
368  static QString osName();
369 
375  static QString platform();
376 
381  static QString locale();
382 
384  static QString userThemesFolder();
385 
387  static QString defaultStylePath();
388 
390  static QString defaultThemesFolder();
391 
393  static QString libraryPath();
394 
396  static QString libexecPath();
397 
399  static void setPrefixPath( const QString &prefixPath, bool useDefaultPaths = false );
400 
402  static void setPluginPath( const QString &pluginPath );
403 
405  static void setPkgDataPath( const QString &pkgDataPath );
406 
408  static void setDefaultSvgPaths( const QStringList &pathList );
409 
411  static void setAuthDatabaseDirPath( const QString &authDbDirPath );
412 
414  static void initQgis();
415 
417  static bool createDatabase( QString *errorMessage = nullptr );
418 
420  static bool createThemeFolder();
421 
423  static void exitQgis();
424 
426  static QString appIconPath();
427 
429  enum endian_t
430  {
431  XDR = 0, // network, or big-endian, byte order
432  NDR = 1 // little-endian byte order
433  };
434 
436  static endian_t endian();
437 
442 #ifndef SIP_RUN
443  template<typename T>
444  static void endian_swap( T &value )
445  {
446  char *data = reinterpret_cast<char *>( &value );
447  std::size_t n = sizeof( value );
448  for ( std::size_t i = 0, m = n / 2; i < m; ++i )
449  {
450  std::swap( data[i], data[n - 1 - i] );
451  }
452  }
453 #endif
454 
464  static QString reportStyleSheet();
465 
469  static QString showSettings();
470 
478  static void registerOgrDrivers();
479 
481  static QString absolutePathToRelativePath( const QString &apath, const QString &targetPath );
483  static QString relativePathToAbsolutePath( const QString &rpath, const QString &targetPath );
484 
486  static bool isRunningFromBuildDir() { return ABISYM( mRunningFromBuildDir ); }
487 #ifdef _MSC_VER
488  static QString cfgIntDir() { return ABISYM( mCfgIntDir ); } SIP_SKIP
489 #endif
490  static QString buildSourcePath() { return ABISYM( mBuildSourcePath ); }
493  static QString buildOutputPath() { return ABISYM( mBuildOutputPath ); }
494 
500  static void skipGdalDriver( const QString &driver );
501 
507  static void restoreGdalDriver( const QString &driver );
508 
513  static QStringList skippedGdalDrivers() { return ABISYM( mGdalSkipList ); }
514 
520  static void applyGdalSkippedDrivers();
521 
525  static int maxThreads() { return ABISYM( mMaxThreads ); }
526 
531  static void setMaxThreads( int maxThreads );
532 
538  static QgsTaskManager *taskManager();
539 
544  static QgsColorSchemeRegistry *colorSchemeRegistry();
545 
550  static QgsPaintEffectRegistry *paintEffectRegistry();
551 
556  static QgsRendererRegistry *rendererRegistry();
557 
563  static QgsRasterRendererRegistry *rasterRendererRegistry() SIP_SKIP;
564 
570  static QgsDataItemProviderRegistry *dataItemProviderRegistry();
571 
577  static QgsSvgCache *svgCache();
578 
583  static QgsSymbolLayerRegistry *symbolLayerRegistry();
584 
589  static QgsLayoutItemRegistry *layoutItemRegistry();
590 
595  static QgsGPSConnectionRegistry *gpsConnectionRegistry();
596 
601  static QgsPluginLayerRegistry *pluginLayerRegistry();
602 
607  static QgsMessageLog *messageLog();
608 
615  static QgsAuthManager *authManager();
616 
622  static QgsProcessingRegistry *processingRegistry();
623 
628  static QgsPageSizeRegistry *pageSizeRegistry();
629 
635  static QgsAnnotationRegistry *annotationRegistry() SIP_SKIP;
636 
642  static QgsActionScopeRegistry *actionScopeRegistry();
643 
648  static QgsRuntimeProfiler *profiler();
649 
653  static QgsFieldFormatterRegistry *fieldFormatterRegistry();
654 
660  static Qgs3DRendererRegistry *renderer3DRegistry();
661 
670  static QString nullRepresentation();
671 
675  static void setNullRepresentation( const QString &nullRepresentation );
676 
684  static QVariantMap customVariables();
685 
693  static void setCustomVariables( const QVariantMap &customVariables );
694 
695 
701  static void setCustomVariable( const QString &name, const QVariant &value );
702 
703 #ifdef SIP_RUN
704  SIP_IF_FEATURE( ANDROID )
705  //dummy method to workaround sip generation issue
706  bool x11EventFilter( XEvent *event );
707  SIP_END
708 #endif
709 
710  signals:
712  void preNotify( QObject *receiver, QEvent *event, bool *done ) SIP_SKIP;
713 
718  void customVariablesChanged();
719 
720 
724  void nullRepresentationChanged();
725 
726  private:
727 
728  static void copyPath( const QString &src, const QString &dst );
729  static QObject *ABISYM( mFileOpenEventReceiver );
730  static QStringList ABISYM( mFileOpenEventList );
731 
732  static QString ABISYM( mUIThemeName );
733  static QString ABISYM( mPrefixPath );
734  static QString ABISYM( mPluginPath );
735  static QString ABISYM( mPkgDataPath );
736  static QString ABISYM( mLibraryPath );
737  static QString ABISYM( mLibexecPath );
738  static QString ABISYM( mThemeName );
739  static QStringList ABISYM( mDefaultSvgPaths );
740  static QMap<QString, QString> ABISYM( mSystemEnvVars );
741 
742  static QString ABISYM( mConfigPath );
743 
745  static bool ABISYM( mRunningFromBuildDir );
747  static QString ABISYM( mBuildSourcePath );
748 #ifdef _MSC_VER
749  static QString ABISYM( mCfgIntDir );
751 #endif
752  static QString ABISYM( mBuildOutputPath );
754 
758  static QStringList ABISYM( mGdalSkipList );
759 
762  static int ABISYM( mMaxThreads );
763 
766  static QString ABISYM( mAuthDbDirPath );
767 
768  static QString sUserName;
769  static QString sUserFullName;
770  static QString sPlatformName;
771 
772  QMap<QString, QIcon> mIconCache;
773  QMap<Cursor, QCursor> mCursorCache;
774 
775  QgsDataItemProviderRegistry *mDataItemProviderRegistry = nullptr;
776  QgsAuthManager *mAuthManager = nullptr;
777 
778  struct ApplicationMembers
779  {
780  Qgs3DRendererRegistry *m3DRendererRegistry = nullptr;
781  QgsActionScopeRegistry *mActionScopeRegistry = nullptr;
782  QgsAnnotationRegistry *mAnnotationRegistry = nullptr;
783  QgsColorSchemeRegistry *mColorSchemeRegistry = nullptr;
784  QgsFieldFormatterRegistry *mFieldFormatterRegistry = nullptr;
785  QgsGPSConnectionRegistry *mGpsConnectionRegistry = nullptr;
786  QgsMessageLog *mMessageLog = nullptr;
787  QgsPaintEffectRegistry *mPaintEffectRegistry = nullptr;
788  QgsPluginLayerRegistry *mPluginLayerRegistry = nullptr;
789  QgsProcessingRegistry *mProcessingRegistry = nullptr;
790  QgsPageSizeRegistry *mPageSizeRegistry = nullptr;
791  QgsRasterRendererRegistry *mRasterRendererRegistry = nullptr;
792  QgsRendererRegistry *mRendererRegistry = nullptr;
793  QgsRuntimeProfiler *mProfiler = nullptr;
794  QgsSvgCache *mSvgCache = nullptr;
795  QgsSymbolLayerRegistry *mSymbolLayerRegistry = nullptr;
796  QgsTaskManager *mTaskManager = nullptr;
797  QgsLayoutItemRegistry *mLayoutItemRegistry = nullptr;
798  QgsUserProfileManager *mUserConfigManager = nullptr;
799  QString mNullRepresentation;
800 
801  ApplicationMembers();
802  ~ApplicationMembers();
803  };
804 
805  // Applications members which belong to an instance of QgsApplication
806  ApplicationMembers *mApplicationMembers = nullptr;
807  // ... but in case QgsApplication is never instantiated (eg with custom designer widgets), we fall back to static members
808  static ApplicationMembers *sApplicationMembers;
809 
810  static ApplicationMembers *members();
811 };
812 
813 // clazy:excludeall=qstring-allocations
814 
815 #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:128
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()
Get 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
static QString buildOutputPath()
Returns path to the build output directory. Valid only when running from build directory.
#define SIP_END
Definition: qgis_sip.h:175
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.
A class to register / unregister existing GPS connections such that the information is available to a...
Registry for various processing components, including providers, algorithms and various parameters an...
static const char * QGIS_ORGANIZATION_DOMAIN
Registry of available layout item types.
QObject * ABISYM(QgsApplication::mFileOpenEventReceiver)
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:37
Select and capture a point or a feature.
Registry of available paint effects.