QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
30 #ifdef ANDROID
31 typedef void XEvent;
32 #endif
33 
34 class CORE_EXPORT QgsApplication : public QApplication
35 {
36  Q_OBJECT
37  public:
38  static const char* QGIS_ORGANIZATION_NAME;
39  static const char* QGIS_ORGANIZATION_DOMAIN;
40  static const char* QGIS_APPLICATION_NAME;
41  QgsApplication( int & argc, char ** argv, bool GUIenabled, const QString& customConfigPath = QString(), const QString& platformName = "desktop" );
42  virtual ~QgsApplication();
43 
50  static void init( QString customConfigPath = QString() );
51 
53  virtual bool event( QEvent * event ) override;
54 
56  virtual bool notify( QObject * receiver, QEvent * event ) override;
57 
59  static void setFileOpenEventReceiver( QObject * receiver );
60 
70  static void setThemeName( const QString &theThemeName );
71 
78  static QString themeName();
79 
87  static void setUITheme( const QString &themeName );
88 
95  static QHash<QString, QString> uiThemes();
96 
98  static QString authorsFilePath();
99 
103  static QString contributorsFilePath();
104 
109  static QString developersMapFilePath();
110 
112  static QString sponsorsFilePath();
113 
115  static QString donorsFilePath();
116 
120  static QString translatorsFilePath();
121 
125  static QString licenceFilePath();
126 
128  static QString helpAppPath();
129 
131  static QString i18nPath();
132 
134  static QString qgisMasterDbFilePath();
135 
137  static QString qgisSettingsDirPath();
138 
140  static QString qgisUserDbFilePath();
141 
143  static QString qgisAuthDbFilePath();
144 
146  static QString splashPath();
147 
149  static QString iconsPath();
150 
152  static QString srsDbFilePath();
153 
155  static QStringList svgPaths();
156 
158  static QStringList composerTemplatePaths();
159 
161  static QMap<QString, QString> systemEnvVars() { return ABISYM( mSystemEnvVars ); }
162 
164  static QString prefixPath();
165 
167  static QString pluginPath();
168 
170  static QString pkgDataPath();
171 
173  static QString activeThemePath();
174 
176  static QString defaultThemePath();
177 
180  static QString iconPath( const QString& iconFile );
181 
184  static QIcon getThemeIcon( const QString &theName );
185 
188  static QPixmap getThemePixmap( const QString &theName );
189 
191  static QString userStyleV2Path();
192 
194  static QRegExp shortNameRegExp();
195 
200  static QString userLoginName();
201 
206  static QString userFullName();
207 
212  static QString osName();
213 
218  static QString platform();
219 
221  static QString userThemesFolder();
222 
224  static QString defaultStyleV2Path();
225 
227  static QString defaultThemesFolder();
228 
230  static QString libraryPath();
231 
233  static QString libexecPath();
234 
236  static void setPrefixPath( const QString &thePrefixPath, bool useDefaultPaths = false );
237 
239  static void setPluginPath( const QString &thePluginPath );
240 
242  static void setPkgDataPath( const QString &thePkgDataPath );
243 
245  static void setDefaultSvgPaths( const QStringList& pathList );
246 
248  static void setAuthDbDirPath( const QString& theAuthDbDirPath );
249 
251  static void initQgis();
252 
254  static bool createDB( QString* errorMessage = nullptr );
255 
257  static bool createThemeFolder();
258 
260  static void exitQgis();
261 
263  static QString appIconPath();
264 
266  enum endian_t
267  {
268  XDR = 0, // network, or big-endian, byte order
269  NDR = 1 // little-endian byte order
270  };
271 
273  static endian_t endian();
274 
278  template<typename T>
279  static void endian_swap( T& value )
280  {
281  char* data = reinterpret_cast<char*>( &value );
282  std::size_t n = sizeof( value );
283  for ( std::size_t i = 0, m = n / 2; i < m; ++i )
284  {
285  std::swap( data[i], data[n - 1 - i] );
286  }
287  }
288 
297  static QString reportStyleSheet();
298 
301  static QString showSettings();
302 
309  static void registerOgrDrivers();
310 
312  static QString absolutePathToRelativePath( const QString& apath, const QString& targetPath );
314  static QString relativePathToAbsolutePath( const QString& rpath, const QString& targetPath );
315 
317  static bool isRunningFromBuildDir() { return ABISYM( mRunningFromBuildDir ); }
318 #ifdef _MSC_VER
319  static QString cfgIntDir() { return ABISYM( mCfgIntDir ); }
320 #endif
321 
322  static QString buildSourcePath() { return ABISYM( mBuildSourcePath ); }
324  static QString buildOutputPath() { return ABISYM( mBuildOutputPath ); }
325 
330  static void skipGdalDriver( const QString& theDriver );
331 
336  static void restoreGdalDriver( const QString& theDriver );
337 
341  static QStringList skippedGdalDrivers() { return ABISYM( mGdalSkipList ); }
342 
347  static void applyGdalSkippedDrivers();
348 
351  static int maxThreads() { return ABISYM( mMaxThreads ); }
352 
356  static void setMaxThreads( int maxThreads );
357 
358 #ifdef ANDROID
359  //dummy method to workaround sip generation issue issue
360  bool x11EventFilter( XEvent * event )
361  {
362  Q_UNUSED( event );
363  return 0;
364  }
365 #endif
366 
367  public slots:
368 
375  void emitSettingsChanged();
376 
377  signals:
379  void preNotify( QObject * receiver, QEvent * event, bool * done );
380 
385  void settingsChanged();
386 
387  private:
388  static void copyPath( const QString& src, const QString& dst );
389  static QObject* ABISYM( mFileOpenEventReceiver );
390  static QStringList ABISYM( mFileOpenEventList );
391 
392  static QString ABISYM( mUIThemeName );
393  static QString ABISYM( mPrefixPath );
394  static QString ABISYM( mPluginPath );
395  static QString ABISYM( mPkgDataPath );
396  static QString ABISYM( mLibraryPath );
397  static QString ABISYM( mLibexecPath );
398  static QString ABISYM( mThemeName );
399  static QStringList ABISYM( mDefaultSvgPaths );
400  static QMap<QString, QString> ABISYM( mSystemEnvVars );
401 
402  static QString ABISYM( mConfigPath );
403 
405  static bool ABISYM( mRunningFromBuildDir );
407  static QString ABISYM( mBuildSourcePath );
408 #ifdef _MSC_VER
409 
410  static QString ABISYM( mCfgIntDir );
411 #endif
412 
413  static QString ABISYM( mBuildOutputPath );
416  static QStringList ABISYM( mGdalSkipList );
419  static int ABISYM( mMaxThreads );
422  static QString ABISYM( mAuthDbDirPath );
423 
424  static QString sUserName;
425  static QString sUserFullName;
426  static QString sPlatformName;
427 
428  QMap<QString, QIcon> mIconCache;
429 };
430 
431 #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.
QStringList ABISYM(QgsApplication::mFileOpenEventList)
static const char * QGIS_ORGANIZATION_NAME
virtual bool x11EventFilter(XEvent *event)
static QString buildSourcePath()
Returns path to the source directory.
static const char * QGIS_ORGANIZATION_DOMAIN
virtual bool event(QEvent *e)
static const char * QGIS_APPLICATION_NAME
virtual bool notify(QObject *receiver, QEvent *e)