QGIS API Documentation  2.99.0-Master (9fdd060)
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 
63 class CORE_EXPORT QgsApplication : public QApplication
64 {
65 
66 #ifdef SIP_RUN
67  % TypeCode
68  // Convert a Python argv list to a conventional C argc count and argv array.
69  static char **qtgui_ArgvToC( PyObject *argvlist, int &argc )
70  {
71  char **argv;
72 
73  argc = PyList_GET_SIZE( argvlist );
74 
75  // Allocate space for two copies of the argument pointers, plus the
76  // terminating NULL.
77  if ( ( argv = ( char ** )sipMalloc( 2 * ( argc + 1 ) * sizeof( char * ) ) ) == NULL )
78  return NULL;
79 
80  // Convert the list.
81  for ( int a = 0; a < argc; ++a )
82  {
83  char *arg;
84  // Get the argument and allocate memory for it.
85  if ( ( arg = PyBytes_AsString( PyList_GET_ITEM( argvlist, a ) ) ) == NULL ||
86  ( argv[a] = ( char * )sipMalloc( strlen( arg ) + 1 ) ) == NULL )
87  return NULL;
88  // Copy the argument and save a pointer to it.
89  strcpy( argv[a], arg );
90  argv[a + argc + 1] = argv[a];
91  }
92 
93  argv[argc + argc + 1] = argv[argc] = NULL;
94 
95  return argv;
96  }
97 
98  // Remove arguments from the Python argv list that have been removed from the
99  // C argv array.
100  static void qtgui_UpdatePyArgv( PyObject *argvlist, int argc, char **argv )
101  {
102  for ( int a = 0, na = 0; a < argc; ++a )
103  {
104  // See if it was removed.
105  if ( argv[na] == argv[a + argc + 1] )
106  ++na;
107  else
108  PyList_SetSlice( argvlist, na, na + 1, NULL );
109  }
110  }
111  % End
112 #endif
113 
114  Q_OBJECT
115 
116  public:
117 
118  static const char *QGIS_ORGANIZATION_NAME;
119  static const char *QGIS_ORGANIZATION_DOMAIN;
120  static const char *QGIS_APPLICATION_NAME;
121 #ifndef SIP_RUN
122  QgsApplication( int &argc, char **argv, bool GUIenabled, const QString &profileFolder = QString(), const QString &platformName = "desktop" );
123 #else
124  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" )];
125  % MethodCode
126  // The Python interface is a list of argument strings that is modified.
127 
128  int argc;
129  char **argv;
130 
131  // Convert the list.
132  if ( ( argv = qtgui_ArgvToC( a0, argc ) ) == NULL )
133  sipIsErr = 1;
134  else
135  {
136  // Create it now the arguments are right.
137  static int nargc = argc;
138 
139  sipCpp = new sipQgsApplication( nargc, argv, a1, *a2, *a3 );
140 
141  // Now modify the original list.
142  qtgui_UpdatePyArgv( a0, argc, argv );
143  }
144  % End
145 #endif
146 
147  virtual ~QgsApplication();
148 
154  static QgsApplication *instance();
155 
163  static void init( QString profileFolder = QString() ) SIP_SKIP;
164 
166  virtual bool event( QEvent *event ) override;
167 
169  virtual bool notify( QObject *receiver, QEvent *event ) override;
170 
172  static void setFileOpenEventReceiver( QObject *receiver );
173 
184  static void setThemeName( const QString &themeName );
185 
193  static QString themeName();
194 
202  static void setUITheme( const QString &themeName );
203 
210  static QHash<QString, QString> uiThemes();
211 
213  static QString authorsFilePath();
214 
219  static QString contributorsFilePath();
220 
226  static QString developersMapFilePath();
227 
229  static QString sponsorsFilePath();
230 
232  static QString donorsFilePath();
233 
235  static QString serverResourcesPath();
236 
240  static QString translatorsFilePath();
241 
245  static QString licenceFilePath();
246 
248  static QString i18nPath();
249 
254  static QString metadataPath();
255 
257  static QString qgisMasterDatabaseFilePath();
258 
260  static QString qgisSettingsDirPath();
261 
263  static QString qgisUserDatabaseFilePath();
264 
266  static QString qgisAuthDatabaseFilePath();
267 
269  static QString splashPath();
270 
272  static QString iconsPath();
273 
275  static QString srsDatabaseFilePath();
276 
278  static QStringList svgPaths();
279 
281  static QStringList composerTemplatePaths();
282 
284  static QMap<QString, QString> systemEnvVars() { return ABISYM( mSystemEnvVars ); }
285 
287  static QString prefixPath();
288 
290  static QString pluginPath();
291 
293  static QString pkgDataPath();
294 
296  static QString activeThemePath();
297 
299  static QString defaultThemePath();
300 
305  static QString iconPath( const QString &iconFile );
306 
311  static QIcon getThemeIcon( const QString &name );
312 
317  static QPixmap getThemePixmap( const QString &name );
318 
320  static QString userStylePath();
321 
323  static QRegExp shortNameRegExp();
324 
330  static QString userLoginName();
331 
337  static QString userFullName();
338 
344  static QString osName();
345 
351  static QString platform();
352 
357  static QString locale();
358 
360  static QString userThemesFolder();
361 
363  static QString defaultStylePath();
364 
366  static QString defaultThemesFolder();
367 
369  static QString libraryPath();
370 
372  static QString libexecPath();
373 
375  static void setPrefixPath( const QString &prefixPath, bool useDefaultPaths = false );
376 
378  static void setPluginPath( const QString &pluginPath );
379 
381  static void setPkgDataPath( const QString &pkgDataPath );
382 
384  static void setDefaultSvgPaths( const QStringList &pathList );
385 
387  static void setAuthDatabaseDirPath( const QString &authDbDirPath );
388 
390  static void initQgis();
391 
393  static bool createDatabase( QString *errorMessage = nullptr );
394 
396  static bool createThemeFolder();
397 
399  static void exitQgis();
400 
402  static QString appIconPath();
403 
405  enum endian_t
406  {
407  XDR = 0, // network, or big-endian, byte order
408  NDR = 1 // little-endian byte order
409  };
410 
412  static endian_t endian();
413 
418 #ifndef SIP_RUN
419  template<typename T>
420  static void endian_swap( T &value )
421  {
422  char *data = reinterpret_cast<char *>( &value );
423  std::size_t n = sizeof( value );
424  for ( std::size_t i = 0, m = n / 2; i < m; ++i )
425  {
426  std::swap( data[i], data[n - 1 - i] );
427  }
428  }
429 #endif
430 
440  static QString reportStyleSheet();
441 
445  static QString showSettings();
446 
454  static void registerOgrDrivers();
455 
457  static QString absolutePathToRelativePath( const QString &apath, const QString &targetPath );
459  static QString relativePathToAbsolutePath( const QString &rpath, const QString &targetPath );
460 
462  static bool isRunningFromBuildDir() { return ABISYM( mRunningFromBuildDir ); }
463 #ifdef _MSC_VER
464  static QString cfgIntDir() { return ABISYM( mCfgIntDir ); } SIP_SKIP
465 #endif
466  static QString buildSourcePath() { return ABISYM( mBuildSourcePath ); }
469  static QString buildOutputPath() { return ABISYM( mBuildOutputPath ); }
470 
476  static void skipGdalDriver( const QString &driver );
477 
483  static void restoreGdalDriver( const QString &driver );
484 
489  static QStringList skippedGdalDrivers() { return ABISYM( mGdalSkipList ); }
490 
496  static void applyGdalSkippedDrivers();
497 
501  static int maxThreads() { return ABISYM( mMaxThreads ); }
502 
507  static void setMaxThreads( int maxThreads );
508 
514  static QgsTaskManager *taskManager();
515 
520  static QgsColorSchemeRegistry *colorSchemeRegistry();
521 
526  static QgsPaintEffectRegistry *paintEffectRegistry();
527 
532  static QgsRendererRegistry *rendererRegistry();
533 
539  static QgsRasterRendererRegistry *rasterRendererRegistry() SIP_SKIP;
540 
546  static QgsDataItemProviderRegistry *dataItemProviderRegistry();
547 
553  static QgsSvgCache *svgCache();
554 
559  static QgsSymbolLayerRegistry *symbolLayerRegistry();
560 
565  static QgsLayoutItemRegistry *layoutItemRegistry();
566 
571  static QgsGPSConnectionRegistry *gpsConnectionRegistry();
572 
577  static QgsPluginLayerRegistry *pluginLayerRegistry();
578 
583  static QgsMessageLog *messageLog();
584 
590  static QgsProcessingRegistry *processingRegistry();
591 
596  static QgsPageSizeRegistry *pageSizeRegistry();
597 
603  static QgsAnnotationRegistry *annotationRegistry() SIP_SKIP;
604 
610  static QgsActionScopeRegistry *actionScopeRegistry();
611 
616  static QgsRuntimeProfiler *profiler();
617 
621  static QgsFieldFormatterRegistry *fieldFormatterRegistry();
622 
628  static Qgs3DRendererRegistry *renderer3DRegistry();
629 
638  static QString nullRepresentation();
639 
643  static void setNullRepresentation( const QString &nullRepresentation );
644 
652  static QVariantMap customVariables();
653 
661  static void setCustomVariables( const QVariantMap &customVariables );
662 
663 
669  static void setCustomVariable( const QString &name, const QVariant &value );
670 
671 #ifdef SIP_RUN
672  SIP_IF_FEATURE( ANDROID )
673  //dummy method to workaround sip generation issue
674  bool x11EventFilter( XEvent *event );
675  SIP_END
676 #endif
677 
678  signals:
680  void preNotify( QObject *receiver, QEvent *event, bool *done ) SIP_SKIP;
681 
686  void customVariablesChanged();
687 
688 
692  void nullRepresentationChanged();
693 
694  private:
695 
696  static void copyPath( const QString &src, const QString &dst );
697  static QObject *ABISYM( mFileOpenEventReceiver );
698  static QStringList ABISYM( mFileOpenEventList );
699 
700  static QString ABISYM( mUIThemeName );
701  static QString ABISYM( mPrefixPath );
702  static QString ABISYM( mPluginPath );
703  static QString ABISYM( mPkgDataPath );
704  static QString ABISYM( mLibraryPath );
705  static QString ABISYM( mLibexecPath );
706  static QString ABISYM( mThemeName );
707  static QStringList ABISYM( mDefaultSvgPaths );
708  static QMap<QString, QString> ABISYM( mSystemEnvVars );
709 
710  static QString ABISYM( mConfigPath );
711 
713  static bool ABISYM( mRunningFromBuildDir );
715  static QString ABISYM( mBuildSourcePath );
716 #ifdef _MSC_VER
717  static QString ABISYM( mCfgIntDir );
719 #endif
720  static QString ABISYM( mBuildOutputPath );
722 
726  static QStringList ABISYM( mGdalSkipList );
727 
730  static int ABISYM( mMaxThreads );
731 
734  static QString ABISYM( mAuthDbDirPath );
735 
736  static QString sUserName;
737  static QString sUserFullName;
738  static QString sPlatformName;
739 
740  QMap<QString, QIcon> mIconCache;
741 
742  QgsDataItemProviderRegistry *mDataItemProviderRegistry = nullptr;
743 
744  struct ApplicationMembers
745  {
746  Qgs3DRendererRegistry *m3DRendererRegistry = nullptr;
747  QgsActionScopeRegistry *mActionScopeRegistry = nullptr;
748  QgsAnnotationRegistry *mAnnotationRegistry = nullptr;
749  QgsColorSchemeRegistry *mColorSchemeRegistry = nullptr;
750  QgsFieldFormatterRegistry *mFieldFormatterRegistry = nullptr;
751  QgsGPSConnectionRegistry *mGpsConnectionRegistry = nullptr;
752  QgsMessageLog *mMessageLog = nullptr;
753  QgsPaintEffectRegistry *mPaintEffectRegistry = nullptr;
754  QgsPluginLayerRegistry *mPluginLayerRegistry = nullptr;
755  QgsProcessingRegistry *mProcessingRegistry = nullptr;
756  QgsPageSizeRegistry *mPageSizeRegistry = nullptr;
757  QgsRasterRendererRegistry *mRasterRendererRegistry = nullptr;
758  QgsRendererRegistry *mRendererRegistry = nullptr;
759  QgsRuntimeProfiler *mProfiler = nullptr;
760  QgsSvgCache *mSvgCache = nullptr;
761  QgsSymbolLayerRegistry *mSymbolLayerRegistry = nullptr;
762  QgsTaskManager *mTaskManager = nullptr;
763  QgsLayoutItemRegistry *mLayoutItemRegistry = nullptr;
764  QgsUserProfileManager *mUserConfigManager = nullptr;
765  QString mNullRepresentation;
766 
767  ApplicationMembers();
768  ~ApplicationMembers();
769  };
770 
771  // Applications members which belong to an instance of QgsApplication
772  ApplicationMembers *mApplicationMembers = nullptr;
773  // ... but in case QgsApplication is never instantiated (eg with custom designer widgets), we fall back to static members
774  static ApplicationMembers *sApplicationMembers;
775 
776  static ApplicationMembers *members();
777 };
778 
779 // clazy:excludeall=qstring-allocations
780 
781 #endif
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.
Registry of color schemes.
A registry of plugin layers types.
A cache for images / pictures derived from svg files.
Definition: qgssvgcache.h:113
Registry of renderers.
Registry for raster renderers.
User profile contains information about the user profile folders on the machine.
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)
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
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
Registry of available paint effects.