QGIS API Documentation  2.99.0-Master (40f86b2)
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 
48 #ifdef ANDROID
49 typedef void XEvent;
50 #endif
51 
52 class CORE_EXPORT QgsApplication : public QApplication
53 {
54  Q_OBJECT
55 
56  public:
57 
58  static const char *QGIS_ORGANIZATION_NAME;
59  static const char *QGIS_ORGANIZATION_DOMAIN;
60  static const char *QGIS_APPLICATION_NAME;
61  QgsApplication( int &argc, char **argv, bool GUIenabled, const QString &customConfigPath = QString(), const QString &platformName = "desktop" );
62  virtual ~QgsApplication();
63 
69  static QgsApplication *instance();
70 
77  static void init( QString customConfigPath = QString() );
78 
80  virtual bool event( QEvent *event ) override;
81 
83  virtual bool notify( QObject *receiver, QEvent *event ) override;
84 
86  static void setFileOpenEventReceiver( QObject *receiver );
87 
97  static void setThemeName( const QString &themeName );
98 
105  static QString themeName();
106 
114  static void setUITheme( const QString &themeName );
115 
122  static QHash<QString, QString> uiThemes();
123 
125  static QString authorsFilePath();
126 
130  static QString contributorsFilePath();
131 
136  static QString developersMapFilePath();
137 
139  static QString sponsorsFilePath();
140 
142  static QString donorsFilePath();
143 
147  static QString translatorsFilePath();
148 
152  static QString licenceFilePath();
153 
155  static QString helpAppPath();
156 
158  static QString i18nPath();
159 
161  static QString qgisMasterDatabaseFilePath();
162 
164  static QString qgisSettingsDirPath();
165 
167  static QString qgisUserDatabaseFilePath();
168 
170  static QString qgisAuthDatabaseFilePath();
171 
173  static QString splashPath();
174 
176  static QString iconsPath();
177 
179  static QString srsDatabaseFilePath();
180 
182  static QStringList svgPaths();
183 
185  static QStringList composerTemplatePaths();
186 
188  static QMap<QString, QString> systemEnvVars() { return ABISYM( mSystemEnvVars ); }
189 
191  static QString prefixPath();
192 
194  static QString pluginPath();
195 
197  static QString pkgDataPath();
198 
200  static QString activeThemePath();
201 
203  static QString defaultThemePath();
204 
207  static QString iconPath( const QString &iconFile );
208 
211  static QIcon getThemeIcon( const QString &name );
212 
215  static QPixmap getThemePixmap( const QString &name );
216 
218  static QString userStylePath();
219 
221  static QRegExp shortNameRegExp();
222 
227  static QString userLoginName();
228 
233  static QString userFullName();
234 
239  static QString osName();
240 
245  static QString platform();
246 
250  static QString locale();
251 
253  static QString userThemesFolder();
254 
256  static QString defaultStylePath();
257 
259  static QString defaultThemesFolder();
260 
262  static QString libraryPath();
263 
265  static QString libexecPath();
266 
268  static void setPrefixPath( const QString &prefixPath, bool useDefaultPaths = false );
269 
271  static void setPluginPath( const QString &pluginPath );
272 
274  static void setPkgDataPath( const QString &pkgDataPath );
275 
277  static void setDefaultSvgPaths( const QStringList &pathList );
278 
280  static void setAuthDatabaseDirPath( const QString &authDbDirPath );
281 
283  static void initQgis();
284 
286  static bool createDatabase( QString *errorMessage = nullptr );
287 
289  static bool createThemeFolder();
290 
292  static void exitQgis();
293 
295  static QString appIconPath();
296 
298  enum endian_t
299  {
300  XDR = 0, // network, or big-endian, byte order
301  NDR = 1 // little-endian byte order
302  };
303 
305  static endian_t endian();
306 
310  template<typename T>
311  static void endian_swap( T &value )
312  {
313  char *data = reinterpret_cast<char *>( &value );
314  std::size_t n = sizeof( value );
315  for ( std::size_t i = 0, m = n / 2; i < m; ++i )
316  {
317  std::swap( data[i], data[n - 1 - i] );
318  }
319  }
320 
329  static QString reportStyleSheet();
330 
333  static QString showSettings();
334 
341  static void registerOgrDrivers();
342 
344  static QString absolutePathToRelativePath( const QString &apath, const QString &targetPath );
346  static QString relativePathToAbsolutePath( const QString &rpath, const QString &targetPath );
347 
349  static bool isRunningFromBuildDir() { return ABISYM( mRunningFromBuildDir ); }
350 #ifdef _MSC_VER
351  static QString cfgIntDir() { return ABISYM( mCfgIntDir ); }
352 #endif
353  static QString buildSourcePath() { return ABISYM( mBuildSourcePath ); }
356  static QString buildOutputPath() { return ABISYM( mBuildOutputPath ); }
357 
362  static void skipGdalDriver( const QString &driver );
363 
368  static void restoreGdalDriver( const QString &driver );
369 
373  static QStringList skippedGdalDrivers() { return ABISYM( mGdalSkipList ); }
374 
379  static void applyGdalSkippedDrivers();
380 
383  static int maxThreads() { return ABISYM( mMaxThreads ); }
384 
388  static void setMaxThreads( int maxThreads );
389 
395  static QgsTaskManager *taskManager();
396 
401  static QgsColorSchemeRegistry *colorSchemeRegistry();
402 
407  static QgsPaintEffectRegistry *paintEffectRegistry();
408 
413  static QgsRendererRegistry *rendererRegistry();
414 
420  static QgsRasterRendererRegistry *rasterRendererRegistry();
421 
427  static QgsDataItemProviderRegistry *dataItemProviderRegistry();
428 
434  static QgsSvgCache *svgCache();
435 
440  static QgsSymbolLayerRegistry *symbolLayerRegistry();
441 
446  static QgsGPSConnectionRegistry *gpsConnectionRegistry();
447 
452  static QgsPluginLayerRegistry *pluginLayerRegistry();
453 
458  static QgsMessageLog *messageLog();
459 
465  static QgsProcessingRegistry *processingRegistry();
466 
472  static QgsAnnotationRegistry *annotationRegistry();
473 
474 #ifdef ANDROID
475  //dummy method to workaround sip generation issue issue
476  bool x11EventFilter( XEvent *event )
477  {
478  Q_UNUSED( event );
479  return 0;
480  }
481 #endif
482 
488  static QgsActionScopeRegistry *actionScopeRegistry();
489 
494  static QgsRuntimeProfiler *profiler();
495 
499  static QgsFieldFormatterRegistry *fieldFormatterRegistry();
500 
509  static QString nullRepresentation();
510 
514  static void setNullRepresentation( const QString &nullRepresentation );
515 
523  static QVariantMap customVariables();
524 
532  static void setCustomVariables( const QVariantMap &customVariables );
533 
534 
540  static void setCustomVariable( const QString &name, const QVariant &value );
541 
542  signals:
544  void preNotify( QObject *receiver, QEvent *event, bool *done );
545 
550  void customVariablesChanged();
551 
552 
556  void nullRepresentationChanged();
557 
558  private:
559 
560  static void copyPath( const QString &src, const QString &dst );
561  static QObject *ABISYM( mFileOpenEventReceiver );
562  static QStringList ABISYM( mFileOpenEventList );
563 
564  static QString ABISYM( mUIThemeName );
565  static QString ABISYM( mPrefixPath );
566  static QString ABISYM( mPluginPath );
567  static QString ABISYM( mPkgDataPath );
568  static QString ABISYM( mLibraryPath );
569  static QString ABISYM( mLibexecPath );
570  static QString ABISYM( mThemeName );
571  static QStringList ABISYM( mDefaultSvgPaths );
572  static QMap<QString, QString> ABISYM( mSystemEnvVars );
573 
574  static QString ABISYM( mConfigPath );
575 
577  static bool ABISYM( mRunningFromBuildDir );
579  static QString ABISYM( mBuildSourcePath );
580 #ifdef _MSC_VER
581  static QString ABISYM( mCfgIntDir );
583 #endif
584  static QString ABISYM( mBuildOutputPath );
586 
589  static QStringList ABISYM( mGdalSkipList );
590 
593  static int ABISYM( mMaxThreads );
594 
597  static QString ABISYM( mAuthDbDirPath );
598 
599  static QString sUserName;
600  static QString sUserFullName;
601  static QString sPlatformName;
602 
603  QMap<QString, QIcon> mIconCache;
604 
605  QgsDataItemProviderRegistry *mDataItemProviderRegistry = nullptr;
606 
607  struct ApplicationMembers
608  {
609  QgsActionScopeRegistry *mActionScopeRegistry = nullptr;
610  QgsAnnotationRegistry *mAnnotationRegistry = nullptr;
611  QgsColorSchemeRegistry *mColorSchemeRegistry = nullptr;
612  QgsFieldFormatterRegistry *mFieldFormatterRegistry = nullptr;
613  QgsGPSConnectionRegistry *mGpsConnectionRegistry = nullptr;
614  QgsMessageLog *mMessageLog = nullptr;
615  QgsPaintEffectRegistry *mPaintEffectRegistry = nullptr;
616  QgsPluginLayerRegistry *mPluginLayerRegistry = nullptr;
617  QgsProcessingRegistry *mProcessingRegistry = nullptr;
618  QgsRasterRendererRegistry *mRasterRendererRegistry = nullptr;
619  QgsRendererRegistry *mRendererRegistry = nullptr;
620  QgsRuntimeProfiler *mProfiler = nullptr;
621  QgsSvgCache *mSvgCache = nullptr;
622  QgsSymbolLayerRegistry *mSymbolLayerRegistry = nullptr;
623  QgsTaskManager *mTaskManager = nullptr;
624  QString mNullRepresentation;
625 
626  ApplicationMembers();
627  ~ApplicationMembers();
628  };
629 
630  // Applications members which belong to an instance of QgsApplication
631  ApplicationMembers *mApplicationMembers = nullptr;
632  // ... but in case QgsApplication is never instantiated (eg with custom designer widgets), we fall back to static members
633  static ApplicationMembers *sApplicationMembers;
634 
635  static ApplicationMembers *members();
636 };
637 
638 #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:100
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)
static QMap< QString, QString > systemEnvVars()
Returns the system environment variables passed to application.
endian_t
Constants for endian-ness.
Registry of available symbol layer classes.
static QString buildOutputPath()
Returns path to the build output directory. Valid only when running from build directory.
static const char * QGIS_ORGANIZATION_NAME
Task manager for managing a set of long-running QgsTask tasks.
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
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.