QGIS API Documentation  3.0.2-Girona (307d082)
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 
28 class QgsRuntimeProfiler;
29 class QgsTaskManager;
34 class QgsSvgCache;
40 class QgsMessageLog;
42 class QgsAnnotationRegistry;
43 class QgsUserProfile;
47 class QgsAuthManager;
48 
64 class CORE_EXPORT QgsApplication : public QApplication
65 {
66 
67 #ifdef SIP_RUN
68  % TypeCode
69  // Convert a Python argv list to a conventional C argc count and argv array.
70  static char **qtgui_ArgvToC( PyObject *argvlist, int &argc )
71  {
72  char **argv;
73 
74  argc = PyList_GET_SIZE( argvlist );
75 
76  // Allocate space for two copies of the argument pointers, plus the
77  // terminating NULL.
78  if ( ( argv = ( char ** )sipMalloc( 2 * ( argc + 1 ) * sizeof( char * ) ) ) == NULL )
79  return NULL;
80 
81  // Convert the list.
82  for ( int a = 0; a < argc; ++a )
83  {
84  char *arg;
85  // Get the argument and allocate memory for it.
86  if ( ( arg = PyBytes_AsString( PyList_GET_ITEM( argvlist, a ) ) ) == NULL ||
87  ( argv[a] = ( char * )sipMalloc( strlen( arg ) + 1 ) ) == NULL )
88  return NULL;
89  // Copy the argument and save a pointer to it.
90  strcpy( argv[a], arg );
91  argv[a + argc + 1] = argv[a];
92  }
93 
94  argv[argc + argc + 1] = argv[argc] = NULL;
95 
96  return argv;
97  }
98 
99  // Remove arguments from the Python argv list that have been removed from the
100  // C argv array.
101  static void qtgui_UpdatePyArgv( PyObject *argvlist, int argc, char **argv )
102  {
103  for ( int a = 0, na = 0; a < argc; ++a )
104  {
105  // See if it was removed.
106  if ( argv[na] == argv[a + argc + 1] )
107  ++na;
108  else
109  PyList_SetSlice( argvlist, na, na + 1, NULL );
110  }
111  }
112  % End
113 #endif
114 
115  Q_OBJECT
116 
117  public:
118 
119  static const char *QGIS_ORGANIZATION_NAME;
120  static const char *QGIS_ORGANIZATION_DOMAIN;
121  static const char *QGIS_APPLICATION_NAME;
122 #ifndef SIP_RUN
123  QgsApplication( int &argc, char **argv, bool GUIenabled, const QString &profileFolder = QString(), const QString &platformName = "desktop" );
124 #else
125  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" )];
126  % MethodCode
127  // The Python interface is a list of argument strings that is modified.
128 
129  int argc;
130  char **argv;
131 
132  // Convert the list.
133  if ( ( argv = qtgui_ArgvToC( a0, argc ) ) == NULL )
134  sipIsErr = 1;
135  else
136  {
137  // Create it now the arguments are right.
138  static int nargc = argc;
139 
140  sipCpp = new sipQgsApplication( nargc, argv, a1, *a2, *a3 );
141 
142  // Now modify the original list.
143  qtgui_UpdatePyArgv( a0, argc, argv );
144  }
145  % End
146 #endif
147 
148  ~QgsApplication() override;
149 
155  static QgsApplication *instance();
156 
164  static void init( QString profileFolder = QString() ) SIP_SKIP;
165 
167  bool event( QEvent *event ) override;
168 
170  bool notify( QObject *receiver, QEvent *event ) override;
171 
173  static void setFileOpenEventReceiver( QObject *receiver );
174 
185  static void setThemeName( const QString &themeName );
186 
191  static QString resolvePkgPath( );
192 
200  static QString themeName();
201 
209  static void setUITheme( const QString &themeName );
210 
217  static QHash<QString, QString> uiThemes();
218 
220  static QString authorsFilePath();
221 
226  static QString contributorsFilePath();
227 
233  static QString developersMapFilePath();
234 
236  static QString sponsorsFilePath();
237 
239  static QString donorsFilePath();
240 
242  static QString serverResourcesPath();
243 
247  static QString translatorsFilePath();
248 
252  static QString licenceFilePath();
253 
255  static QString i18nPath();
256 
261  static QString metadataPath();
262 
264  static QString qgisMasterDatabaseFilePath();
265 
267  static QString qgisSettingsDirPath();
268 
270  static QString qgisUserDatabaseFilePath();
271 
273  static QString qgisAuthDatabaseFilePath();
274 
276  static QString splashPath();
277 
279  static QString iconsPath();
280 
282  static QString srsDatabaseFilePath();
283 
285  static QStringList svgPaths();
286 
291  static QStringList layoutTemplatePaths();
292 
294  static QMap<QString, QString> systemEnvVars() { return ABISYM( mSystemEnvVars ); }
295 
297  static QString prefixPath();
298 
300  static QString pluginPath();
301 
303  static QString pkgDataPath();
304 
306  static QString activeThemePath();
307 
309  static QString defaultThemePath();
310 
315  static QString iconPath( const QString &iconFile );
316 
321  static QIcon getThemeIcon( const QString &name );
322 
327  enum Cursor
328  {
336  };
337 
344  static QCursor getThemeCursor( Cursor cursor );
345 
350  static QPixmap getThemePixmap( const QString &name );
351 
353  static QString userStylePath();
354 
356  static QRegExp shortNameRegExp();
357 
363  static QString userLoginName();
364 
370  static QString userFullName();
371 
377  static QString osName();
378 
384  static QString platform();
385 
390  static QString locale();
391 
393  static QString userThemesFolder();
394 
396  static QString defaultStylePath();
397 
399  static QString defaultThemesFolder();
400 
402  static QString libraryPath();
403 
405  static QString libexecPath();
406 
408  static void setPrefixPath( const QString &prefixPath, bool useDefaultPaths = false );
409 
411  static void setPluginPath( const QString &pluginPath );
412 
414  static void setPkgDataPath( const QString &pkgDataPath );
415 
417  static void setDefaultSvgPaths( const QStringList &pathList );
418 
420  static void setAuthDatabaseDirPath( const QString &authDbDirPath );
421 
423  static void initQgis();
424 
426  static bool createDatabase( QString *errorMessage = nullptr );
427 
429  static bool createThemeFolder();
430 
432  static void exitQgis();
433 
435  static QString appIconPath();
436 
438  enum endian_t
439  {
440  XDR = 0, // network, or big-endian, byte order
441  NDR = 1 // little-endian byte order
442  };
443 
445  static endian_t endian();
446 
451 #ifndef SIP_RUN
452  template<typename T>
453  static void endian_swap( T &value )
454  {
455  char *data = reinterpret_cast<char *>( &value );
456  std::size_t n = sizeof( value );
457  for ( std::size_t i = 0, m = n / 2; i < m; ++i )
458  {
459  std::swap( data[i], data[n - 1 - i] );
460  }
461  }
462 #endif
463 
473  static QString reportStyleSheet();
474 
478  static QString showSettings();
479 
487  static void registerOgrDrivers();
488 
490  static QString absolutePathToRelativePath( const QString &apath, const QString &targetPath );
492  static QString relativePathToAbsolutePath( const QString &rpath, const QString &targetPath );
493 
495  static bool isRunningFromBuildDir() { return ABISYM( mRunningFromBuildDir ); }
496 #ifdef _MSC_VER
497  static QString cfgIntDir() { return ABISYM( mCfgIntDir ); } SIP_SKIP
498 #endif
499  static QString buildSourcePath() { return ABISYM( mBuildSourcePath ); }
502  static QString buildOutputPath() { return ABISYM( mBuildOutputPath ); }
503 
509  static void skipGdalDriver( const QString &driver );
510 
516  static void restoreGdalDriver( const QString &driver );
517 
522  static QStringList skippedGdalDrivers() { return ABISYM( mGdalSkipList ); }
523 
529  static void applyGdalSkippedDrivers();
530 
534  static int maxThreads() { return ABISYM( mMaxThreads ); }
535 
540  static void setMaxThreads( int maxThreads );
541 
547  static QgsTaskManager *taskManager();
548 
553  static QgsColorSchemeRegistry *colorSchemeRegistry();
554 
559  static QgsPaintEffectRegistry *paintEffectRegistry();
560 
565  static QgsRendererRegistry *rendererRegistry();
566 
572  static QgsRasterRendererRegistry *rasterRendererRegistry() SIP_SKIP;
573 
579  static QgsDataItemProviderRegistry *dataItemProviderRegistry();
580 
586  static QgsSvgCache *svgCache();
587 
592  static QgsSymbolLayerRegistry *symbolLayerRegistry();
593 
598  static QgsLayoutItemRegistry *layoutItemRegistry();
599 
604  static QgsGpsConnectionRegistry *gpsConnectionRegistry();
605 
610  static QgsPluginLayerRegistry *pluginLayerRegistry();
611 
616  static QgsMessageLog *messageLog();
617 
624  static QgsAuthManager *authManager();
625 
631  static QgsProcessingRegistry *processingRegistry();
632 
637  static QgsPageSizeRegistry *pageSizeRegistry();
638 
644  static QgsAnnotationRegistry *annotationRegistry() SIP_SKIP;
645 
651  static QgsActionScopeRegistry *actionScopeRegistry();
652 
657  static QgsRuntimeProfiler *profiler();
658 
662  static QgsFieldFormatterRegistry *fieldFormatterRegistry();
663 
669  static Qgs3DRendererRegistry *renderer3DRegistry();
670 
679  static QString nullRepresentation();
680 
684  static void setNullRepresentation( const QString &nullRepresentation );
685 
693  static QVariantMap customVariables();
694 
702  static void setCustomVariables( const QVariantMap &customVariables );
703 
704 
710  static void setCustomVariable( const QString &name, const QVariant &value );
711 
712 #ifdef SIP_RUN
713  SIP_IF_FEATURE( ANDROID )
714  //dummy method to workaround sip generation issue
715  bool x11EventFilter( XEvent *event );
716  SIP_END
717 #endif
718 
719  signals:
721  void preNotify( QObject *receiver, QEvent *event, bool *done ) SIP_SKIP;
722 
727  void customVariablesChanged();
728 
729 
733  void nullRepresentationChanged();
734 
735  private:
736 
737  static void copyPath( const QString &src, const QString &dst );
738  static QObject *ABISYM( mFileOpenEventReceiver );
739  static QStringList ABISYM( mFileOpenEventList );
740 
741  static QString ABISYM( mProfilePath );
742  static QString ABISYM( mUIThemeName );
743  static QString ABISYM( mPrefixPath );
744  static QString ABISYM( mPluginPath );
745  static QString ABISYM( mPkgDataPath );
746  static QString ABISYM( mLibraryPath );
747  static QString ABISYM( mLibexecPath );
748  static QString ABISYM( mThemeName );
749  static QStringList ABISYM( mDefaultSvgPaths );
750  static QMap<QString, QString> ABISYM( mSystemEnvVars );
751 
752  static QString ABISYM( mConfigPath );
753 
754  static bool ABISYM( mInitialized );
755 
757  static bool ABISYM( mRunningFromBuildDir );
759  static QString ABISYM( mBuildSourcePath );
760 #ifdef _MSC_VER
761  static QString ABISYM( mCfgIntDir );
763 #endif
764  static QString ABISYM( mBuildOutputPath );
766 
770  static QStringList ABISYM( mGdalSkipList );
771 
774  static int ABISYM( mMaxThreads );
775 
778  static QString ABISYM( mAuthDbDirPath );
779 
780  static QString sUserName;
781  static QString sUserFullName;
782  static QString sPlatformName;
783 
784  QMap<QString, QIcon> mIconCache;
785  QMap<Cursor, QCursor> mCursorCache;
786 
787  QgsDataItemProviderRegistry *mDataItemProviderRegistry = nullptr;
788  QgsAuthManager *mAuthManager = nullptr;
789 
790  struct ApplicationMembers
791  {
792  Qgs3DRendererRegistry *m3DRendererRegistry = nullptr;
793  QgsActionScopeRegistry *mActionScopeRegistry = nullptr;
794  QgsAnnotationRegistry *mAnnotationRegistry = nullptr;
795  QgsColorSchemeRegistry *mColorSchemeRegistry = nullptr;
796  QgsFieldFormatterRegistry *mFieldFormatterRegistry = nullptr;
797  QgsGpsConnectionRegistry *mGpsConnectionRegistry = nullptr;
798  QgsMessageLog *mMessageLog = nullptr;
799  QgsPaintEffectRegistry *mPaintEffectRegistry = nullptr;
800  QgsPluginLayerRegistry *mPluginLayerRegistry = nullptr;
801  QgsProcessingRegistry *mProcessingRegistry = nullptr;
802  QgsPageSizeRegistry *mPageSizeRegistry = nullptr;
803  QgsRasterRendererRegistry *mRasterRendererRegistry = nullptr;
804  QgsRendererRegistry *mRendererRegistry = nullptr;
805  QgsRuntimeProfiler *mProfiler = nullptr;
806  QgsSvgCache *mSvgCache = nullptr;
807  QgsSymbolLayerRegistry *mSymbolLayerRegistry = nullptr;
808  QgsTaskManager *mTaskManager = nullptr;
809  QgsLayoutItemRegistry *mLayoutItemRegistry = nullptr;
810  QgsUserProfileManager *mUserConfigManager = nullptr;
811  QString mNullRepresentation;
812 
813  ApplicationMembers();
814  ~ApplicationMembers();
815  };
816 
817  // Applications members which belong to an instance of QgsApplication
818  ApplicationMembers *mApplicationMembers = nullptr;
819  // ... but in case QgsApplication is never instantiated (eg with custom designer widgets), we fall back to static members
820  static ApplicationMembers *sApplicationMembers;
821 
822  static ApplicationMembers *members();
823 };
824 
825 // clazy:excludeall=qstring-allocations
826 
827 #endif
Singleton offering an interface to manage the authentication configuration database and to utilize co...
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.
Cursor
The Cursor enum defines constants for QGIS custom cursors.
Registry of color schemes.
A registry of plugin layers types.
A cache for images / pictures derived from svg files.
Definition: qgssvgcache.h:130
Registry of renderers.
Registry for raster renderers.
User profile contains information about the user profile folders on the machine.
Precisely identify a point on the canvas.
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)
Color/Value picker.
static int maxThreads()
Get maximum concurrent thread count.
QString iconPath(const QString &iconFile)
endian_t
Constants for endian-ness.
Keeps track of available 3D renderers.
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
Select a rectangle.
Identify: obtain information about the object.
Registry for various processing components, including providers, algorithms and various parameters an...
static const char * QGIS_ORGANIZATION_DOMAIN
Registry of available layout item types.
A class to register / unregister existing GPS connections such that the information is available to a...
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:38
Select and capture a point or a feature.
Registry of available paint effects.