QGIS API Documentation  2.99.0-Master (75367e4)
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  static const char* QGIS_ORGANIZATION_NAME;
58  static const char* QGIS_ORGANIZATION_DOMAIN;
59  static const char* QGIS_APPLICATION_NAME;
60  QgsApplication( int & argc, char ** argv, bool GUIenabled, const QString& customConfigPath = QString(), const QString& platformName = "desktop" );
61  virtual ~QgsApplication();
62 
68  static QgsApplication* instance();
69 
76  static void init( QString customConfigPath = QString() );
77 
79  virtual bool event( QEvent * event ) override;
80 
82  virtual bool notify( QObject * receiver, QEvent * event ) override;
83 
85  static void setFileOpenEventReceiver( QObject * receiver );
86 
96  static void setThemeName( const QString &theThemeName );
97 
104  static QString themeName();
105 
113  static void setUITheme( const QString &themeName );
114 
121  static QHash<QString, QString> uiThemes();
122 
124  static QString authorsFilePath();
125 
129  static QString contributorsFilePath();
130 
135  static QString developersMapFilePath();
136 
138  static QString sponsorsFilePath();
139 
141  static QString donorsFilePath();
142 
146  static QString translatorsFilePath();
147 
151  static QString licenceFilePath();
152 
154  static QString helpAppPath();
155 
157  static QString i18nPath();
158 
160  static QString qgisMasterDatabaseFilePath();
161 
163  static QString qgisSettingsDirPath();
164 
166  static QString qgisUserDatabaseFilePath();
167 
169  static QString qgisAuthDatabaseFilePath();
170 
172  static QString splashPath();
173 
175  static QString iconsPath();
176 
178  static QString srsDatabaseFilePath();
179 
181  static QStringList svgPaths();
182 
184  static QStringList composerTemplatePaths();
185 
187  static QMap<QString, QString> systemEnvVars() { return ABISYM( mSystemEnvVars ); }
188 
190  static QString prefixPath();
191 
193  static QString pluginPath();
194 
196  static QString pkgDataPath();
197 
199  static QString activeThemePath();
200 
202  static QString defaultThemePath();
203 
206  static QString iconPath( const QString& iconFile );
207 
210  static QIcon getThemeIcon( const QString &theName );
211 
214  static QPixmap getThemePixmap( const QString &theName );
215 
217  static QString userStylePath();
218 
220  static QRegExp shortNameRegExp();
221 
226  static QString userLoginName();
227 
232  static QString userFullName();
233 
238  static QString osName();
239 
244  static QString platform();
245 
249  static QString locale();
250 
252  static QString userThemesFolder();
253 
255  static QString defaultStylePath();
256 
258  static QString defaultThemesFolder();
259 
261  static QString libraryPath();
262 
264  static QString libexecPath();
265 
267  static void setPrefixPath( const QString &thePrefixPath, bool useDefaultPaths = false );
268 
270  static void setPluginPath( const QString &thePluginPath );
271 
273  static void setPkgDataPath( const QString &thePkgDataPath );
274 
276  static void setDefaultSvgPaths( const QStringList& pathList );
277 
279  static void setAuthDatabaseDirPath( const QString& theAuthDbDirPath );
280 
282  static void initQgis();
283 
285  static bool createDatabase( QString* errorMessage = nullptr );
286 
288  static bool createThemeFolder();
289 
291  static void exitQgis();
292 
294  static QString appIconPath();
295 
297  enum endian_t
298  {
299  XDR = 0, // network, or big-endian, byte order
300  NDR = 1 // little-endian byte order
301  };
302 
304  static endian_t endian();
305 
309  template<typename T>
310  static void endian_swap( T& value )
311  {
312  char* data = reinterpret_cast<char*>( &value );
313  std::size_t n = sizeof( value );
314  for ( std::size_t i = 0, m = n / 2; i < m; ++i )
315  {
316  std::swap( data[i], data[n - 1 - i] );
317  }
318  }
319 
328  static QString reportStyleSheet();
329 
332  static QString showSettings();
333 
340  static void registerOgrDrivers();
341 
343  static QString absolutePathToRelativePath( const QString& apath, const QString& targetPath );
345  static QString relativePathToAbsolutePath( const QString& rpath, const QString& targetPath );
346 
348  static bool isRunningFromBuildDir() { return ABISYM( mRunningFromBuildDir ); }
349 #ifdef _MSC_VER
350  static QString cfgIntDir() { return ABISYM( mCfgIntDir ); }
351 #endif
352  static QString buildSourcePath() { return ABISYM( mBuildSourcePath ); }
355  static QString buildOutputPath() { return ABISYM( mBuildOutputPath ); }
356 
361  static void skipGdalDriver( const QString& theDriver );
362 
367  static void restoreGdalDriver( const QString& theDriver );
368 
372  static QStringList skippedGdalDrivers() { return ABISYM( mGdalSkipList ); }
373 
378  static void applyGdalSkippedDrivers();
379 
382  static int maxThreads() { return ABISYM( mMaxThreads ); }
383 
387  static void setMaxThreads( int maxThreads );
388 
394  static QgsTaskManager* taskManager();
395 
400  static QgsColorSchemeRegistry* colorSchemeRegistry();
401 
406  static QgsPaintEffectRegistry* paintEffectRegistry();
407 
412  static QgsRendererRegistry* rendererRegistry();
413 
419  static QgsRasterRendererRegistry* rasterRendererRegistry();
420 
426  static QgsDataItemProviderRegistry* dataItemProviderRegistry();
427 
433  static QgsSvgCache* svgCache();
434 
439  static QgsSymbolLayerRegistry* symbolLayerRegistry();
440 
445  static QgsGPSConnectionRegistry* gpsConnectionRegistry();
446 
451  static QgsPluginLayerRegistry* pluginLayerRegistry();
452 
457  static QgsMessageLog* messageLog();
458 
464  static QgsProcessingRegistry* processingRegistry();
465 
471  static QgsAnnotationRegistry* annotationRegistry();
472 
473 #ifdef ANDROID
474  //dummy method to workaround sip generation issue issue
475  bool x11EventFilter( XEvent * event )
476  {
477  Q_UNUSED( event );
478  return 0;
479  }
480 #endif
481 
487  static QgsActionScopeRegistry* actionScopeRegistry();
488 
493  static QgsRuntimeProfiler* profiler();
494 
498  static QgsFieldFormatterRegistry* fieldFormatterRegistry();
499 
508  static QString nullRepresentation();
509 
513  static void setNullRepresentation( const QString& nullRepresentation );
514 
522  static QVariantMap customVariables();
523 
531  static void setCustomVariables( const QVariantMap& customVariables );
532 
533 
539  static void setCustomVariable( const QString& name, const QVariant& value );
540 
541  signals:
543  void preNotify( QObject * receiver, QEvent * event, bool * done );
544 
549  void customVariablesChanged();
550 
551 
555  void nullRepresentationChanged();
556 
557  private:
558  static void copyPath( const QString& src, const QString& dst );
559  static QObject* ABISYM( mFileOpenEventReceiver );
560  static QStringList ABISYM( mFileOpenEventList );
561 
562  static QString ABISYM( mUIThemeName );
563  static QString ABISYM( mPrefixPath );
564  static QString ABISYM( mPluginPath );
565  static QString ABISYM( mPkgDataPath );
566  static QString ABISYM( mLibraryPath );
567  static QString ABISYM( mLibexecPath );
568  static QString ABISYM( mThemeName );
569  static QStringList ABISYM( mDefaultSvgPaths );
570  static QMap<QString, QString> ABISYM( mSystemEnvVars );
571 
572  static QString ABISYM( mConfigPath );
573 
575  static bool ABISYM( mRunningFromBuildDir );
577  static QString ABISYM( mBuildSourcePath );
578 #ifdef _MSC_VER
579  static QString ABISYM( mCfgIntDir );
581 #endif
582  static QString ABISYM( mBuildOutputPath );
584 
587  static QStringList ABISYM( mGdalSkipList );
588 
591  static int ABISYM( mMaxThreads );
592 
595  static QString ABISYM( mAuthDbDirPath );
596 
597  static QString sUserName;
598  static QString sUserFullName;
599  static QString sPlatformName;
600 
601  QMap<QString, QIcon> mIconCache;
602 
603  QgsActionScopeRegistry* mActionScopeRegistry = nullptr;
604  QgsRuntimeProfiler* mProfiler = nullptr;
605  QgsTaskManager* mTaskManager = nullptr;
606  QgsFieldFormatterRegistry* mFieldFormatterRegistry = nullptr;
607  QgsColorSchemeRegistry* mColorSchemeRegistry = nullptr;
608  QgsPaintEffectRegistry* mPaintEffectRegistry = nullptr;
609  QgsRendererRegistry* mRendererRegistry = nullptr;
610  QgsSvgCache* mSvgCache = nullptr;
611  QgsSymbolLayerRegistry* mSymbolLayerRegistry = nullptr;
612  QgsRasterRendererRegistry* mRasterRendererRegistry = nullptr;
613  QgsGPSConnectionRegistry* mGpsConnectionRegistry = nullptr;
614  QgsDataItemProviderRegistry* mDataItemProviderRegistry = nullptr;
615  QgsPluginLayerRegistry* mPluginLayerRegistry = nullptr;
616  QgsMessageLog* mMessageLog = nullptr;
617  QgsProcessingRegistry* mProcessingRegistry = nullptr;
618  QgsAnnotationRegistry* mAnnotationRegistry = nullptr;
619  QString mNullRepresentation;
620 };
621 
622 #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.