QGIS API Documentation  2.99.0-Master (ef89a62)
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 class QgsUserProfile;
46 
61 class CORE_EXPORT QgsApplication : public QApplication
62 {
63 
64 #ifdef SIP_RUN
65  % TypeCode
66  // Convert a Python argv list to a conventional C argc count and argv array.
67  static char **qtgui_ArgvToC( PyObject *argvlist, int &argc )
68  {
69  char **argv;
70 
71  argc = PyList_GET_SIZE( argvlist );
72 
73  // Allocate space for two copies of the argument pointers, plus the
74  // terminating NULL.
75  if ( ( argv = ( char ** )sipMalloc( 2 * ( argc + 1 ) * sizeof( char * ) ) ) == NULL )
76  return NULL;
77 
78  // Convert the list.
79  for ( int a = 0; a < argc; ++a )
80  {
81  char *arg;
82  // Get the argument and allocate memory for it.
83  if ( ( arg = PyBytes_AsString( PyList_GET_ITEM( argvlist, a ) ) ) == NULL ||
84  ( argv[a] = ( char * )sipMalloc( strlen( arg ) + 1 ) ) == NULL )
85  return NULL;
86  // Copy the argument and save a pointer to it.
87  strcpy( argv[a], arg );
88  argv[a + argc + 1] = argv[a];
89  }
90 
91  argv[argc + argc + 1] = argv[argc] = NULL;
92 
93  return argv;
94  }
95 
96  // Remove arguments from the Python argv list that have been removed from the
97  // C argv array.
98  static void qtgui_UpdatePyArgv( PyObject *argvlist, int argc, char **argv )
99  {
100  for ( int a = 0, na = 0; a < argc; ++a )
101  {
102  // See if it was removed.
103  if ( argv[na] == argv[a + argc + 1] )
104  ++na;
105  else
106  PyList_SetSlice( argvlist, na, na + 1, NULL );
107  }
108  }
109  % End
110 #endif
111 
112  Q_OBJECT
113 
114  public:
115 
116  static const char *QGIS_ORGANIZATION_NAME;
117  static const char *QGIS_ORGANIZATION_DOMAIN;
118  static const char *QGIS_APPLICATION_NAME;
119 #ifndef SIP_RUN
120  QgsApplication( int &argc, char **argv, bool GUIenabled, const QString &profileFolder = QString(), const QString &platformName = "desktop" );
121 #else
122  QgsApplication( SIP_PYLIST argv, bool GUIenabled, QString profileFolder = QString(), QString platformName = "desktop" ) / PostHook = __pyQtQAppHook__ / [( int &argc, char **argv, bool GUIenabled, const QString &profileFolder = QString(), const QString &platformName = "desktop" )];
123  % MethodCode
124  // The Python interface is a list of argument strings that is modified.
125 
126  int argc;
127  char **argv;
128 
129  // Convert the list.
130  if ( ( argv = qtgui_ArgvToC( a0, argc ) ) == NULL )
131  sipIsErr = 1;
132  else
133  {
134  // Create it now the arguments are right.
135  static int nargc = argc;
136 
137  sipCpp = new sipQgsApplication( nargc, argv, a1, *a2, *a3 );
138 
139  // Now modify the original list.
140  qtgui_UpdatePyArgv( a0, argc, argv );
141  }
142  % End
143 #endif
144 
145  virtual ~QgsApplication();
146 
152  static QgsApplication *instance();
153 
160  static void init( QString profileFolder = QString() ) SIP_SKIP;
161 
163  virtual bool event( QEvent *event ) override;
164 
166  virtual bool notify( QObject *receiver, QEvent *event ) override;
167 
169  static void setFileOpenEventReceiver( QObject *receiver );
170 
180  static void setThemeName( const QString &themeName );
181 
188  static QString themeName();
189 
197  static void setUITheme( const QString &themeName );
198 
205  static QHash<QString, QString> uiThemes();
206 
208  static QString authorsFilePath();
209 
213  static QString contributorsFilePath();
214 
219  static QString developersMapFilePath();
220 
222  static QString sponsorsFilePath();
223 
225  static QString donorsFilePath();
226 
230  static QString translatorsFilePath();
231 
235  static QString licenceFilePath();
236 
238  static QString i18nPath();
239 
241  static QString qgisMasterDatabaseFilePath();
242 
244  static QString qgisSettingsDirPath();
245 
247  static QString qgisUserDatabaseFilePath();
248 
250  static QString qgisAuthDatabaseFilePath();
251 
253  static QString splashPath();
254 
256  static QString iconsPath();
257 
259  static QString srsDatabaseFilePath();
260 
262  static QStringList svgPaths();
263 
265  static QStringList composerTemplatePaths();
266 
268  static QMap<QString, QString> systemEnvVars() { return ABISYM( mSystemEnvVars ); }
269 
271  static QString prefixPath();
272 
274  static QString pluginPath();
275 
277  static QString pkgDataPath();
278 
280  static QString activeThemePath();
281 
283  static QString defaultThemePath();
284 
287  static QString iconPath( const QString &iconFile );
288 
291  static QIcon getThemeIcon( const QString &name );
292 
295  static QPixmap getThemePixmap( const QString &name );
296 
298  static QString userStylePath();
299 
301  static QRegExp shortNameRegExp();
302 
307  static QString userLoginName();
308 
313  static QString userFullName();
314 
319  static QString osName();
320 
325  static QString platform();
326 
330  static QString locale();
331 
333  static QString userThemesFolder();
334 
336  static QString defaultStylePath();
337 
339  static QString defaultThemesFolder();
340 
342  static QString libraryPath();
343 
345  static QString libexecPath();
346 
348  static void setPrefixPath( const QString &prefixPath, bool useDefaultPaths = false );
349 
351  static void setPluginPath( const QString &pluginPath );
352 
354  static void setPkgDataPath( const QString &pkgDataPath );
355 
357  static void setDefaultSvgPaths( const QStringList &pathList );
358 
360  static void setAuthDatabaseDirPath( const QString &authDbDirPath );
361 
363  static void initQgis();
364 
366  static bool createDatabase( QString *errorMessage = nullptr );
367 
369  static bool createThemeFolder();
370 
372  static void exitQgis();
373 
375  static QString appIconPath();
376 
378  enum endian_t
379  {
380  XDR = 0, // network, or big-endian, byte order
381  NDR = 1 // little-endian byte order
382  };
383 
385  static endian_t endian();
386 
390 #ifndef SIP_RUN
391  template<typename T>
392  static void endian_swap( T &value )
393  {
394  char *data = reinterpret_cast<char *>( &value );
395  std::size_t n = sizeof( value );
396  for ( std::size_t i = 0, m = n / 2; i < m; ++i )
397  {
398  std::swap( data[i], data[n - 1 - i] );
399  }
400  }
401 #endif
402 
411  static QString reportStyleSheet();
412 
415  static QString showSettings();
416 
423  static void registerOgrDrivers();
424 
426  static QString absolutePathToRelativePath( const QString &apath, const QString &targetPath );
428  static QString relativePathToAbsolutePath( const QString &rpath, const QString &targetPath );
429 
431  static bool isRunningFromBuildDir() { return ABISYM( mRunningFromBuildDir ); }
432 #ifdef _MSC_VER
433  static QString cfgIntDir() { return ABISYM( mCfgIntDir ); } SIP_SKIP
434 #endif
435  static QString buildSourcePath() { return ABISYM( mBuildSourcePath ); }
438  static QString buildOutputPath() { return ABISYM( mBuildOutputPath ); }
439 
444  static void skipGdalDriver( const QString &driver );
445 
450  static void restoreGdalDriver( const QString &driver );
451 
455  static QStringList skippedGdalDrivers() { return ABISYM( mGdalSkipList ); }
456 
461  static void applyGdalSkippedDrivers();
462 
465  static int maxThreads() { return ABISYM( mMaxThreads ); }
466 
470  static void setMaxThreads( int maxThreads );
471 
477  static QgsTaskManager *taskManager();
478 
483  static QgsColorSchemeRegistry *colorSchemeRegistry();
484 
489  static QgsPaintEffectRegistry *paintEffectRegistry();
490 
495  static QgsRendererRegistry *rendererRegistry();
496 
502  static QgsRasterRendererRegistry *rasterRendererRegistry() SIP_SKIP;
503 
509  static QgsDataItemProviderRegistry *dataItemProviderRegistry();
510 
516  static QgsSvgCache *svgCache();
517 
522  static QgsSymbolLayerRegistry *symbolLayerRegistry();
523 
528  static QgsLayoutItemRegistry *layoutItemRegistry();
529 
534  static QgsGPSConnectionRegistry *gpsConnectionRegistry();
535 
540  static QgsPluginLayerRegistry *pluginLayerRegistry();
541 
546  static QgsMessageLog *messageLog();
547 
553  static QgsProcessingRegistry *processingRegistry();
554 
559  static QgsPageSizeRegistry *pageSizeRegistry();
560 
566  static QgsAnnotationRegistry *annotationRegistry() SIP_SKIP;
567 
573  static QgsActionScopeRegistry *actionScopeRegistry();
574 
579  static QgsRuntimeProfiler *profiler();
580 
584  static QgsFieldFormatterRegistry *fieldFormatterRegistry();
585 
594  static QString nullRepresentation();
595 
599  static void setNullRepresentation( const QString &nullRepresentation );
600 
608  static QVariantMap customVariables();
609 
617  static void setCustomVariables( const QVariantMap &customVariables );
618 
619 
625  static void setCustomVariable( const QString &name, const QVariant &value );
626 
627 #ifdef SIP_RUN
628  SIP_IF_FEATURE( ANDROID )
629  //dummy method to workaround sip generation issue
630  bool x11EventFilter( XEvent *event );
631  SIP_END
632 #endif
633 
634  signals:
636  void preNotify( QObject *receiver, QEvent *event, bool *done ) SIP_SKIP;
637 
642  void customVariablesChanged();
643 
644 
648  void nullRepresentationChanged();
649 
650  private:
651 
652  static void copyPath( const QString &src, const QString &dst );
653  static QObject *ABISYM( mFileOpenEventReceiver );
654  static QStringList ABISYM( mFileOpenEventList );
655 
656  static QString ABISYM( mUIThemeName );
657  static QString ABISYM( mPrefixPath );
658  static QString ABISYM( mPluginPath );
659  static QString ABISYM( mPkgDataPath );
660  static QString ABISYM( mLibraryPath );
661  static QString ABISYM( mLibexecPath );
662  static QString ABISYM( mThemeName );
663  static QStringList ABISYM( mDefaultSvgPaths );
664  static QMap<QString, QString> ABISYM( mSystemEnvVars );
665 
666  static QString ABISYM( mConfigPath );
667 
669  static bool ABISYM( mRunningFromBuildDir );
671  static QString ABISYM( mBuildSourcePath );
672 #ifdef _MSC_VER
673  static QString ABISYM( mCfgIntDir );
675 #endif
676  static QString ABISYM( mBuildOutputPath );
678 
681  static QStringList ABISYM( mGdalSkipList );
682 
685  static int ABISYM( mMaxThreads );
686 
689  static QString ABISYM( mAuthDbDirPath );
690 
691  static QString sUserName;
692  static QString sUserFullName;
693  static QString sPlatformName;
694 
695  QMap<QString, QIcon> mIconCache;
696 
697  QgsDataItemProviderRegistry *mDataItemProviderRegistry = nullptr;
698 
699  struct ApplicationMembers
700  {
701  QgsActionScopeRegistry *mActionScopeRegistry = nullptr;
702  QgsAnnotationRegistry *mAnnotationRegistry = nullptr;
703  QgsColorSchemeRegistry *mColorSchemeRegistry = nullptr;
704  QgsFieldFormatterRegistry *mFieldFormatterRegistry = nullptr;
705  QgsGPSConnectionRegistry *mGpsConnectionRegistry = nullptr;
706  QgsMessageLog *mMessageLog = nullptr;
707  QgsPaintEffectRegistry *mPaintEffectRegistry = nullptr;
708  QgsPluginLayerRegistry *mPluginLayerRegistry = nullptr;
709  QgsProcessingRegistry *mProcessingRegistry = nullptr;
710  QgsPageSizeRegistry *mPageSizeRegistry = nullptr;
711  QgsRasterRendererRegistry *mRasterRendererRegistry = nullptr;
712  QgsRendererRegistry *mRendererRegistry = nullptr;
713  QgsRuntimeProfiler *mProfiler = nullptr;
714  QgsSvgCache *mSvgCache = nullptr;
715  QgsSymbolLayerRegistry *mSymbolLayerRegistry = nullptr;
716  QgsTaskManager *mTaskManager = nullptr;
717  QgsLayoutItemRegistry *mLayoutItemRegistry = nullptr;
718  QgsUserProfileManager *mUserConfigManager = nullptr;
719  QString mNullRepresentation;
720 
721  ApplicationMembers();
722  ~ApplicationMembers();
723  };
724 
725  // Applications members which belong to an instance of QgsApplication
726  ApplicationMembers *mApplicationMembers = nullptr;
727  // ... but in case QgsApplication is never instantiated (eg with custom designer widgets), we fall back to static members
728  static ApplicationMembers *sApplicationMembers;
729 
730  static ApplicationMembers *members();
731 };
732 
733 #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:103
Registry of renderers.
Registry for raster renderers.
User profile contains information about the user profile folders on the machine.
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)
endian_t
Constants for endian-ness.
Registry of available symbol layer classes.
#define SIP_SKIP
Definition: qgis_sip.h:119
static QString buildOutputPath()
Returns path to the build output directory. Valid only when running from build directory.
#define SIP_END
Definition: qgis_sip.h:175
A registry for known page sizes.
static const char * QGIS_ORGANIZATION_NAME
Task manager for managing a set of long-running QgsTask tasks.
#define SIP_IF_FEATURE(feature)
Definition: qgis_sip.h:155
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
Registry of available layout item types.
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
User profile manager is used to manager list, and manage user profiles on the users machine...
Interface for logging messages from QGIS in GUI independent way.
Definition: qgsmessagelog.h:36
Registry of available paint effects.