QGIS API Documentation  2.99.0-Master (6a61179)
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 
33 #ifdef ANDROID
34 typedef void XEvent;
35 #endif
36 
37 class CORE_EXPORT QgsApplication : public QApplication
38 {
39  Q_OBJECT
40 
41  public:
42  static const char* QGIS_ORGANIZATION_NAME;
43  static const char* QGIS_ORGANIZATION_DOMAIN;
44  static const char* QGIS_APPLICATION_NAME;
45  QgsApplication( int & argc, char ** argv, bool GUIenabled, const QString& customConfigPath = QString(), const QString& platformName = "desktop" );
46  virtual ~QgsApplication();
47 
53  static QgsApplication* instance();
54 
61  static void init( QString customConfigPath = QString() );
62 
64  virtual bool event( QEvent * event ) override;
65 
67  virtual bool notify( QObject * receiver, QEvent * event ) override;
68 
70  static void setFileOpenEventReceiver( QObject * receiver );
71 
81  static void setThemeName( const QString &theThemeName );
82 
89  static QString themeName();
90 
98  static void setUITheme( const QString &themeName );
99 
106  static QHash<QString, QString> uiThemes();
107 
109  static QString authorsFilePath();
110 
114  static QString contributorsFilePath();
115 
120  static QString developersMapFilePath();
121 
123  static QString sponsorsFilePath();
124 
126  static QString donorsFilePath();
127 
131  static QString translatorsFilePath();
132 
136  static QString licenceFilePath();
137 
139  static QString helpAppPath();
140 
142  static QString i18nPath();
143 
145  static QString qgisMasterDbFilePath();
146 
148  static QString qgisSettingsDirPath();
149 
151  static QString qgisUserDbFilePath();
152 
154  static QString qgisAuthDbFilePath();
155 
157  static QString splashPath();
158 
160  static QString iconsPath();
161 
163  static QString srsDbFilePath();
164 
166  static QStringList svgPaths();
167 
169  static QStringList composerTemplatePaths();
170 
172  static QMap<QString, QString> systemEnvVars() { return ABISYM( mSystemEnvVars ); }
173 
175  static QString prefixPath();
176 
178  static QString pluginPath();
179 
181  static QString pkgDataPath();
182 
184  static QString activeThemePath();
185 
187  static QString defaultThemePath();
188 
191  static QString iconPath( const QString& iconFile );
192 
195  static QIcon getThemeIcon( const QString &theName );
196 
199  static QPixmap getThemePixmap( const QString &theName );
200 
202  static QString userStylePath();
203 
205  static QRegExp shortNameRegExp();
206 
211  static QString userLoginName();
212 
217  static QString userFullName();
218 
223  static QString osName();
224 
229  static QString platform();
230 
232  static QString userThemesFolder();
233 
235  static QString defaultStylePath();
236 
238  static QString defaultThemesFolder();
239 
241  static QString libraryPath();
242 
244  static QString libexecPath();
245 
247  static void setPrefixPath( const QString &thePrefixPath, bool useDefaultPaths = false );
248 
250  static void setPluginPath( const QString &thePluginPath );
251 
253  static void setPkgDataPath( const QString &thePkgDataPath );
254 
256  static void setDefaultSvgPaths( const QStringList& pathList );
257 
259  static void setAuthDbDirPath( const QString& theAuthDbDirPath );
260 
262  static void initQgis();
263 
265  static bool createDB( QString* errorMessage = nullptr );
266 
268  static bool createThemeFolder();
269 
271  static void exitQgis();
272 
274  static QString appIconPath();
275 
277  enum endian_t
278  {
279  XDR = 0, // network, or big-endian, byte order
280  NDR = 1 // little-endian byte order
281  };
282 
284  static endian_t endian();
285 
289  template<typename T>
290  static void endian_swap( T& value )
291  {
292  char* data = reinterpret_cast<char*>( &value );
293  std::size_t n = sizeof( value );
294  for ( std::size_t i = 0, m = n / 2; i < m; ++i )
295  {
296  std::swap( data[i], data[n - 1 - i] );
297  }
298  }
299 
308  static QString reportStyleSheet();
309 
312  static QString showSettings();
313 
320  static void registerOgrDrivers();
321 
323  static QString absolutePathToRelativePath( const QString& apath, const QString& targetPath );
325  static QString relativePathToAbsolutePath( const QString& rpath, const QString& targetPath );
326 
328  static bool isRunningFromBuildDir() { return ABISYM( mRunningFromBuildDir ); }
329 #ifdef _MSC_VER
330  static QString cfgIntDir() { return ABISYM( mCfgIntDir ); }
331 #endif
332  static QString buildSourcePath() { return ABISYM( mBuildSourcePath ); }
335  static QString buildOutputPath() { return ABISYM( mBuildOutputPath ); }
336 
341  static void skipGdalDriver( const QString& theDriver );
342 
347  static void restoreGdalDriver( const QString& theDriver );
348 
352  static QStringList skippedGdalDrivers() { return ABISYM( mGdalSkipList ); }
353 
358  static void applyGdalSkippedDrivers();
359 
362  static int maxThreads() { return ABISYM( mMaxThreads ); }
363 
367  static void setMaxThreads( int maxThreads );
368 
369 #ifdef ANDROID
370  //dummy method to workaround sip generation issue issue
371  bool x11EventFilter( XEvent * event )
372  {
373  Q_UNUSED( event );
374  return 0;
375  }
376 #endif
377 
383  static QgsActionScopeRegistry* actionScopeRegistry();
384 
389  static QgsRuntimeProfiler* profiler();
390 
391  public slots:
392 
399  void emitSettingsChanged();
400 
401  signals:
403  void preNotify( QObject * receiver, QEvent * event, bool * done );
404 
409  void settingsChanged();
410 
411  private:
412  static void copyPath( const QString& src, const QString& dst );
413  static QObject* ABISYM( mFileOpenEventReceiver );
414  static QStringList ABISYM( mFileOpenEventList );
415 
416  static QString ABISYM( mUIThemeName );
417  static QString ABISYM( mPrefixPath );
418  static QString ABISYM( mPluginPath );
419  static QString ABISYM( mPkgDataPath );
420  static QString ABISYM( mLibraryPath );
421  static QString ABISYM( mLibexecPath );
422  static QString ABISYM( mThemeName );
423  static QStringList ABISYM( mDefaultSvgPaths );
424  static QMap<QString, QString> ABISYM( mSystemEnvVars );
425 
426  static QString ABISYM( mConfigPath );
427 
429  static bool ABISYM( mRunningFromBuildDir );
431  static QString ABISYM( mBuildSourcePath );
432 #ifdef _MSC_VER
433  static QString ABISYM( mCfgIntDir );
435 #endif
436  static QString ABISYM( mBuildOutputPath );
438 
441  static QStringList ABISYM( mGdalSkipList );
442 
445  static int ABISYM( mMaxThreads );
446 
449  static QString ABISYM( mAuthDbDirPath );
450 
451  static QString sUserName;
452  static QString sUserFullName;
453  static QString sPlatformName;
454 
455  QMap<QString, QIcon> mIconCache;
456 
457  QgsActionScopeRegistry* mActionScopeRegistry;
458  QgsRuntimeProfiler* mProfiler;
459 };
460 
461 #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
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