QGIS API Documentation  2.99.0-Master (b698612)
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 
27 class QgsRuntimeProfiler;
28 class QgsTaskManager;
33 class QgsSvgCache;
39 class QgsMessageLog;
41 class QgsAnnotationRegistry;
42 
43 
44 SIP_FEATURE( ANDROID )
45 
46 
60 class CORE_EXPORT QgsApplication : public QApplication
61 {
62 
63 #ifdef SIP_RUN
64  % TypeCode
65  // Convert a Python argv list to a conventional C argc count and argv array.
66  static char **qtgui_ArgvToC( PyObject *argvlist, int &argc )
67  {
68  char **argv;
69 
70  argc = PyList_GET_SIZE( argvlist );
71 
72  // Allocate space for two copies of the argument pointers, plus the
73  // terminating NULL.
74  if ( ( argv = ( char ** )sipMalloc( 2 * ( argc + 1 ) * sizeof( char * ) ) ) == NULL )
75  return NULL;
76 
77  // Convert the list.
78  for ( int a = 0; a < argc; ++a )
79  {
80  char *arg;
81  // Get the argument and allocate memory for it.
82  if ( ( arg = PyBytes_AsString( PyList_GET_ITEM( argvlist, a ) ) ) == NULL ||
83  ( argv[a] = ( char * )sipMalloc( strlen( arg ) + 1 ) ) == NULL )
84  return NULL;
85  // Copy the argument and save a pointer to it.
86  strcpy( argv[a], arg );
87  argv[a + argc + 1] = argv[a];
88  }
89 
90  argv[argc + argc + 1] = argv[argc] = NULL;
91 
92  return argv;
93  }
94 
95  // Remove arguments from the Python argv list that have been removed from the
96  // C argv array.
97  static void qtgui_UpdatePyArgv( PyObject *argvlist, int argc, char **argv )
98  {
99  for ( int a = 0, na = 0; a < argc; ++a )
100  {
101  // See if it was removed.
102  if ( argv[na] == argv[a + argc + 1] )
103  ++na;
104  else
105  PyList_SetSlice( argvlist, na, na + 1, NULL );
106  }
107  }
108  % End
109 #endif
110 
111  Q_OBJECT
112 
113  public:
114 
115  static const char *QGIS_ORGANIZATION_NAME;
116  static const char *QGIS_ORGANIZATION_DOMAIN;
117  static const char *QGIS_APPLICATION_NAME;
118 #ifndef SIP_RUN
119  QgsApplication( int &argc, char **argv, bool GUIenabled, const QString &customConfigPath = QString(), const QString &platformName = "desktop" );
120 #else
121  QgsApplication( SIP_PYLIST argv, bool GUIenabled, QString customConfigPath = QString() ) / PostHook = __pyQtQAppHook__ / [( int &argc, char **argv, bool GUIenabled, const QString &customConfigPath = QString() )];
122  % MethodCode
123  // The Python interface is a list of argument strings that is modified.
124 
125  int argc;
126  char **argv;
127 
128  // Convert the list.
129  if ( ( argv = qtgui_ArgvToC( a0, argc ) ) == NULL )
130  sipIsErr = 1;
131  else
132  {
133  // Create it now the arguments are right.
134  static int nargc = argc;
135 
136  sipCpp = new sipQgsApplication( nargc, argv, a1, *a2 );
137 
138  // Now modify the original list.
139  qtgui_UpdatePyArgv( a0, argc, argv );
140  }
141  % End
142 #endif
143 
144  virtual ~QgsApplication();
145 
151  static QgsApplication *instance();
152 
159  static void init( QString customConfigPath = QString() ) SIP_SKIP;
160 
162  virtual bool event( QEvent *event ) override;
163 
165  virtual bool notify( QObject *receiver, QEvent *event ) override;
166 
168  static void setFileOpenEventReceiver( QObject *receiver );
169 
179  static void setThemeName( const QString &themeName );
180 
187  static QString themeName();
188 
196  static void setUITheme( const QString &themeName );
197 
204  static QHash<QString, QString> uiThemes();
205 
207  static QString authorsFilePath();
208 
212  static QString contributorsFilePath();
213 
218  static QString developersMapFilePath();
219 
221  static QString sponsorsFilePath();
222 
224  static QString donorsFilePath();
225 
229  static QString translatorsFilePath();
230 
234  static QString licenceFilePath();
235 
237  static QString helpAppPath();
238 
240  static QString i18nPath();
241 
243  static QString qgisMasterDatabaseFilePath();
244 
246  static QString qgisSettingsDirPath();
247 
249  static QString qgisUserDatabaseFilePath();
250 
252  static QString qgisAuthDatabaseFilePath();
253 
255  static QString splashPath();
256 
258  static QString iconsPath();
259 
261  static QString srsDatabaseFilePath();
262 
264  static QStringList svgPaths();
265 
267  static QStringList composerTemplatePaths();
268 
270  static QMap<QString, QString> systemEnvVars() { return ABISYM( mSystemEnvVars ); }
271 
273  static QString prefixPath();
274 
276  static QString pluginPath();
277 
279  static QString pkgDataPath();
280 
282  static QString activeThemePath();
283 
285  static QString defaultThemePath();
286 
289  static QString iconPath( const QString &iconFile );
290 
293  static QIcon getThemeIcon( const QString &name );
294 
297  static QPixmap getThemePixmap( const QString &name );
298 
300  static QString userStylePath();
301 
303  static QRegExp shortNameRegExp();
304 
309  static QString userLoginName();
310 
315  static QString userFullName();
316 
321  static QString osName();
322 
327  static QString platform();
328 
332  static QString locale();
333 
335  static QString userThemesFolder();
336 
338  static QString defaultStylePath();
339 
341  static QString defaultThemesFolder();
342 
344  static QString libraryPath();
345 
347  static QString libexecPath();
348 
350  static void setPrefixPath( const QString &prefixPath, bool useDefaultPaths = false );
351 
353  static void setPluginPath( const QString &pluginPath );
354 
356  static void setPkgDataPath( const QString &pkgDataPath );
357 
359  static void setDefaultSvgPaths( const QStringList &pathList );
360 
362  static void setAuthDatabaseDirPath( const QString &authDbDirPath );
363 
365  static void initQgis();
366 
368  static bool createDatabase( QString *errorMessage = nullptr );
369 
371  static bool createThemeFolder();
372 
374  static void exitQgis();
375 
377  static QString appIconPath();
378 
380  enum endian_t
381  {
382  XDR = 0, // network, or big-endian, byte order
383  NDR = 1 // little-endian byte order
384  };
385 
387  static endian_t endian();
388 
392 #ifndef SIP_RUN
393  template<typename T>
394  static void endian_swap( T &value )
395  {
396  char *data = reinterpret_cast<char *>( &value );
397  std::size_t n = sizeof( value );
398  for ( std::size_t i = 0, m = n / 2; i < m; ++i )
399  {
400  std::swap( data[i], data[n - 1 - i] );
401  }
402  }
403 #endif
404 
413  static QString reportStyleSheet();
414 
417  static QString showSettings();
418 
425  static void registerOgrDrivers();
426 
428  static QString absolutePathToRelativePath( const QString &apath, const QString &targetPath );
430  static QString relativePathToAbsolutePath( const QString &rpath, const QString &targetPath );
431 
433  static bool isRunningFromBuildDir() { return ABISYM( mRunningFromBuildDir ); }
434 #ifdef _MSC_VER
435  static QString cfgIntDir() { return ABISYM( mCfgIntDir ); } SIP_SKIP
436 #endif
437  static QString buildSourcePath() { return ABISYM( mBuildSourcePath ); }
440  static QString buildOutputPath() { return ABISYM( mBuildOutputPath ); }
441 
446  static void skipGdalDriver( const QString &driver );
447 
452  static void restoreGdalDriver( const QString &driver );
453 
457  static QStringList skippedGdalDrivers() { return ABISYM( mGdalSkipList ); }
458 
463  static void applyGdalSkippedDrivers();
464 
467  static int maxThreads() { return ABISYM( mMaxThreads ); }
468 
472  static void setMaxThreads( int maxThreads );
473 
479  static QgsTaskManager *taskManager();
480 
485  static QgsColorSchemeRegistry *colorSchemeRegistry();
486 
491  static QgsPaintEffectRegistry *paintEffectRegistry();
492 
497  static QgsRendererRegistry *rendererRegistry();
498 
504  static QgsRasterRendererRegistry *rasterRendererRegistry() SIP_SKIP;
505 
511  static QgsDataItemProviderRegistry *dataItemProviderRegistry();
512 
518  static QgsSvgCache *svgCache();
519 
524  static QgsSymbolLayerRegistry *symbolLayerRegistry();
525 
530  static QgsGPSConnectionRegistry *gpsConnectionRegistry();
531 
536  static QgsPluginLayerRegistry *pluginLayerRegistry();
537 
542  static QgsMessageLog *messageLog();
543 
549  static QgsProcessingRegistry *processingRegistry();
550 
556  static QgsAnnotationRegistry *annotationRegistry() SIP_SKIP;
557 
563  static QgsActionScopeRegistry *actionScopeRegistry();
564 
569  static QgsRuntimeProfiler *profiler();
570 
574  static QgsFieldFormatterRegistry *fieldFormatterRegistry();
575 
584  static QString nullRepresentation();
585 
589  static void setNullRepresentation( const QString &nullRepresentation );
590 
598  static QVariantMap customVariables();
599 
607  static void setCustomVariables( const QVariantMap &customVariables );
608 
609 
615  static void setCustomVariable( const QString &name, const QVariant &value );
616 
617 #ifdef SIP_RUN
618  SIP_IF_FEATURE( ANDROID )
619  //dummy method to workaround sip generation issue
620  bool x11EventFilter( XEvent *event );
621  SIP_END
622 #endif
623 
624  signals:
626  void preNotify( QObject *receiver, QEvent *event, bool *done ) SIP_SKIP;
627 
632  void customVariablesChanged();
633 
634 
638  void nullRepresentationChanged();
639 
640  private:
641 
642  static void copyPath( const QString &src, const QString &dst );
643  static QObject *ABISYM( mFileOpenEventReceiver );
644  static QStringList ABISYM( mFileOpenEventList );
645 
646  static QString ABISYM( mUIThemeName );
647  static QString ABISYM( mPrefixPath );
648  static QString ABISYM( mPluginPath );
649  static QString ABISYM( mPkgDataPath );
650  static QString ABISYM( mLibraryPath );
651  static QString ABISYM( mLibexecPath );
652  static QString ABISYM( mThemeName );
653  static QStringList ABISYM( mDefaultSvgPaths );
654  static QMap<QString, QString> ABISYM( mSystemEnvVars );
655 
656  static QString ABISYM( mConfigPath );
657 
659  static bool ABISYM( mRunningFromBuildDir );
661  static QString ABISYM( mBuildSourcePath );
662 #ifdef _MSC_VER
663  static QString ABISYM( mCfgIntDir );
665 #endif
666  static QString ABISYM( mBuildOutputPath );
668 
671  static QStringList ABISYM( mGdalSkipList );
672 
675  static int ABISYM( mMaxThreads );
676 
679  static QString ABISYM( mAuthDbDirPath );
680 
681  static QString sUserName;
682  static QString sUserFullName;
683  static QString sPlatformName;
684 
685  QMap<QString, QIcon> mIconCache;
686 
687  QgsDataItemProviderRegistry *mDataItemProviderRegistry = nullptr;
688 
689  struct ApplicationMembers
690  {
691  QgsActionScopeRegistry *mActionScopeRegistry = nullptr;
692  QgsAnnotationRegistry *mAnnotationRegistry = nullptr;
693  QgsColorSchemeRegistry *mColorSchemeRegistry = nullptr;
694  QgsFieldFormatterRegistry *mFieldFormatterRegistry = nullptr;
695  QgsGPSConnectionRegistry *mGpsConnectionRegistry = nullptr;
696  QgsMessageLog *mMessageLog = nullptr;
697  QgsPaintEffectRegistry *mPaintEffectRegistry = nullptr;
698  QgsPluginLayerRegistry *mPluginLayerRegistry = nullptr;
699  QgsProcessingRegistry *mProcessingRegistry = nullptr;
700  QgsRasterRendererRegistry *mRasterRendererRegistry = nullptr;
701  QgsRendererRegistry *mRendererRegistry = nullptr;
702  QgsRuntimeProfiler *mProfiler = nullptr;
703  QgsSvgCache *mSvgCache = nullptr;
704  QgsSymbolLayerRegistry *mSymbolLayerRegistry = nullptr;
705  QgsTaskManager *mTaskManager = nullptr;
706  QString mNullRepresentation;
707 
708  ApplicationMembers();
709  ~ApplicationMembers();
710  };
711 
712  // Applications members which belong to an instance of QgsApplication
713  ApplicationMembers *mApplicationMembers = nullptr;
714  // ... but in case QgsApplication is never instantiated (eg with custom designer widgets), we fall back to static members
715  static ApplicationMembers *sApplicationMembers;
716 
717  static ApplicationMembers *members();
718 };
719 
720 #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:103
Registry of renderers.
Registry for raster renderers.
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.
Registry of available symbol layer classes.
#define SIP_SKIP
Definition: qgis_sip.h:107
static QString buildOutputPath()
Returns path to the build output directory. Valid only when running from build directory.
#define SIP_END
Definition: qgis_sip.h:158
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:143
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
#define SIP_FEATURE(feature)
Definition: qgis_sip.h:138
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
Interface for logging messages from QGIS in GUI independent way.
Definition: qgsmessagelog.h:36
Registry of available paint effects.