QGIS API Documentation  2.99.0-Master (c558d51)
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 <QApplication>
19 #include <QEvent>
20 #include <QStringList>
21 
22 #include <qgis.h>
23 #include <qgsconfig.h>
24 
26 class QgsRuntimeProfiler;
27 class QgsTaskManager;
28 
34 #ifdef ANDROID
35 typedef void XEvent;
36 #endif
37 
38 class CORE_EXPORT QgsApplication : public QApplication
39 {
40  Q_OBJECT
41 
42  public:
43  static const char* QGIS_ORGANIZATION_NAME;
44  static const char* QGIS_ORGANIZATION_DOMAIN;
45  static const char* QGIS_APPLICATION_NAME;
46  QgsApplication( int & argc, char ** argv, bool GUIenabled, const QString& customConfigPath = QString(), const QString& platformName = "desktop" );
47  virtual ~QgsApplication();
48 
54  static QgsApplication* instance();
55 
62  static void init( QString customConfigPath = QString() );
63 
65  virtual bool event( QEvent * event ) override;
66 
68  virtual bool notify( QObject * receiver, QEvent * event ) override;
69 
71  static void setFileOpenEventReceiver( QObject * receiver );
72 
82  static void setThemeName( const QString &theThemeName );
83 
90  static QString themeName();
91 
99  static void setUITheme( const QString &themeName );
100 
107  static QHash<QString, QString> uiThemes();
108 
110  static QString authorsFilePath();
111 
115  static QString contributorsFilePath();
116 
121  static QString developersMapFilePath();
122 
124  static QString sponsorsFilePath();
125 
127  static QString donorsFilePath();
128 
132  static QString translatorsFilePath();
133 
137  static QString licenceFilePath();
138 
140  static QString helpAppPath();
141 
143  static QString i18nPath();
144 
146  static QString qgisMasterDbFilePath();
147 
149  static QString qgisSettingsDirPath();
150 
152  static QString qgisUserDbFilePath();
153 
155  static QString qgisAuthDbFilePath();
156 
158  static QString splashPath();
159 
161  static QString iconsPath();
162 
164  static QString srsDbFilePath();
165 
167  static QStringList svgPaths();
168 
170  static QStringList composerTemplatePaths();
171 
173  static QMap<QString, QString> systemEnvVars() { return ABISYM( mSystemEnvVars ); }
174 
176  static QString prefixPath();
177 
179  static QString pluginPath();
180 
182  static QString pkgDataPath();
183 
185  static QString activeThemePath();
186 
188  static QString defaultThemePath();
189 
192  static QString iconPath( const QString& iconFile );
193 
196  static QIcon getThemeIcon( const QString &theName );
197 
200  static QPixmap getThemePixmap( const QString &theName );
201 
203  static QString userStylePath();
204 
206  static QRegExp shortNameRegExp();
207 
212  static QString userLoginName();
213 
218  static QString userFullName();
219 
224  static QString osName();
225 
230  static QString platform();
231 
233  static QString userThemesFolder();
234 
236  static QString defaultStylePath();
237 
239  static QString defaultThemesFolder();
240 
242  static QString libraryPath();
243 
245  static QString libexecPath();
246 
248  static void setPrefixPath( const QString &thePrefixPath, bool useDefaultPaths = false );
249 
251  static void setPluginPath( const QString &thePluginPath );
252 
254  static void setPkgDataPath( const QString &thePkgDataPath );
255 
257  static void setDefaultSvgPaths( const QStringList& pathList );
258 
260  static void setAuthDbDirPath( const QString& theAuthDbDirPath );
261 
263  static void initQgis();
264 
266  static bool createDB( QString* errorMessage = nullptr );
267 
269  static bool createThemeFolder();
270 
272  static void exitQgis();
273 
275  static QString appIconPath();
276 
278  enum endian_t
279  {
280  XDR = 0, // network, or big-endian, byte order
281  NDR = 1 // little-endian byte order
282  };
283 
285  static endian_t endian();
286 
290  template<typename T>
291  static void endian_swap( T& value )
292  {
293  char* data = reinterpret_cast<char*>( &value );
294  std::size_t n = sizeof( value );
295  for ( std::size_t i = 0, m = n / 2; i < m; ++i )
296  {
297  std::swap( data[i], data[n - 1 - i] );
298  }
299  }
300 
309  static QString reportStyleSheet();
310 
313  static QString showSettings();
314 
321  static void registerOgrDrivers();
322 
324  static QString absolutePathToRelativePath( const QString& apath, const QString& targetPath );
326  static QString relativePathToAbsolutePath( const QString& rpath, const QString& targetPath );
327 
329  static bool isRunningFromBuildDir() { return ABISYM( mRunningFromBuildDir ); }
330 #ifdef _MSC_VER
331  static QString cfgIntDir() { return ABISYM( mCfgIntDir ); }
332 #endif
333  static QString buildSourcePath() { return ABISYM( mBuildSourcePath ); }
336  static QString buildOutputPath() { return ABISYM( mBuildOutputPath ); }
337 
342  static void skipGdalDriver( const QString& theDriver );
343 
348  static void restoreGdalDriver( const QString& theDriver );
349 
353  static QStringList skippedGdalDrivers() { return ABISYM( mGdalSkipList ); }
354 
359  static void applyGdalSkippedDrivers();
360 
363  static int maxThreads() { return ABISYM( mMaxThreads ); }
364 
368  static void setMaxThreads( int maxThreads );
369 
375  static QgsTaskManager* taskManager();
376 
377 #ifdef ANDROID
378  //dummy method to workaround sip generation issue issue
379  bool x11EventFilter( XEvent * event )
380  {
381  Q_UNUSED( event );
382  return 0;
383  }
384 #endif
385 
391  static QgsActionScopeRegistry* actionScopeRegistry();
392 
397  static QgsRuntimeProfiler* profiler();
398 
399  public slots:
400 
407  void emitSettingsChanged();
408 
409  signals:
411  void preNotify( QObject * receiver, QEvent * event, bool * done );
412 
417  void settingsChanged();
418 
419  private:
420  static void copyPath( const QString& src, const QString& dst );
421  static QObject* ABISYM( mFileOpenEventReceiver );
422  static QStringList ABISYM( mFileOpenEventList );
423 
424  static QString ABISYM( mUIThemeName );
425  static QString ABISYM( mPrefixPath );
426  static QString ABISYM( mPluginPath );
427  static QString ABISYM( mPkgDataPath );
428  static QString ABISYM( mLibraryPath );
429  static QString ABISYM( mLibexecPath );
430  static QString ABISYM( mThemeName );
431  static QStringList ABISYM( mDefaultSvgPaths );
432  static QMap<QString, QString> ABISYM( mSystemEnvVars );
433 
434  static QString ABISYM( mConfigPath );
435 
437  static bool ABISYM( mRunningFromBuildDir );
439  static QString ABISYM( mBuildSourcePath );
440 #ifdef _MSC_VER
441  static QString ABISYM( mCfgIntDir );
443 #endif
444  static QString ABISYM( mBuildOutputPath );
446 
449  static QStringList ABISYM( mGdalSkipList );
450 
453  static int ABISYM( mMaxThreads );
454 
457  static QString ABISYM( mAuthDbDirPath );
458 
459  static QString sUserName;
460  static QString sUserFullName;
461  static QString sPlatformName;
462 
463  QMap<QString, QIcon> mIconCache;
464 
465  QgsActionScopeRegistry* mActionScopeRegistry;
466  QgsRuntimeProfiler* mProfiler;
467  QgsTaskManager* mTaskManager;
468 };
469 
470 #endif
static void endian_swap(T &value)
Swap the endianness of the specified value.
Extends QApplication to provide access to QGIS specific resources such as theme paths, database paths etc.
static QStringList skippedGdalDrivers()
Returns the list of gdal drivers that should be skipped (based on GDAL_SKIP environment variable) ...
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.
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.
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