QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsapplication.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsapplication.cpp - 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 
16 #include "qgsapplication.h"
17 #include "qgsauthmanager.h"
20 #include "qgsexception.h"
21 #include "qgsgeometry.h"
23 #include "qgslayout.h"
24 #include "qgslayoutitemregistry.h"
25 #include "qgslogger.h"
26 #include "qgsproject.h"
29 #include "qgsnetworkreply.h"
30 #include "qgsproviderregistry.h"
31 #include "qgsexpression.h"
32 #include "qgsactionscoperegistry.h"
33 #include "qgsruntimeprofiler.h"
34 #include "qgstaskmanager.h"
38 #include "qgssvgcache.h"
39 #include "qgsimagecache.h"
40 #include "qgssourcecache.h"
41 #include "qgscolorschemeregistry.h"
42 #include "qgspainteffectregistry.h"
46 #include "qgsrendererregistry.h"
49 #include "qgssymbollayerregistry.h"
50 #include "qgssymbollayerutils.h"
51 #include "qgscalloutsregistry.h"
52 #include "qgspluginlayerregistry.h"
54 #include "qgsmessagelog.h"
55 #include "qgsannotationregistry.h"
56 #include "qgssettings.h"
58 #include "qgstiledownloadmanager.h"
59 #include "qgsunittypes.h"
60 #include "qgsuserprofile.h"
61 #include "qgsuserprofilemanager.h"
62 #include "qgsreferencedgeometry.h"
63 #include "qgs3drendererregistry.h"
64 #include "qgs3dsymbolregistry.h"
65 #include "qgslayoutrendercontext.h"
66 #include "qgssqliteutils.h"
67 #include "qgsstyle.h"
68 #include "qgsprojutils.h"
70 #include "qgsnewsfeedparser.h"
71 #include "qgsbookmarkmanager.h"
72 #include "qgsstylemodel.h"
73 #include "qgsconnectionregistry.h"
75 #include "qgsmeshlayer.h"
76 #include "qgsfeaturestore.h"
77 #include "qgslocator.h"
78 #include "qgsreadwritelocker.h"
79 #include "qgsbabelformatregistry.h"
80 #include "qgsdbquerylog.h"
81 
86 
88 #include "qgsrecentstylehandler.h"
90 
91 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
92 #include <QDesktopWidget>
93 #endif
94 #include <QDir>
95 #include <QFile>
96 #include <QFileInfo>
97 #include <QFileOpenEvent>
98 #include <QMessageBox>
99 #include <QPalette>
100 #include <QProcess>
101 #include <QProcessEnvironment>
102 #include <QIcon>
103 #include <QPixmap>
104 #include <QThreadPool>
105 #include <QLocale>
106 #include <QStyle>
107 #include <QLibraryInfo>
108 #include <QStandardPaths>
109 #include <QRegularExpression>
110 #include <QTextStream>
111 #include <QScreen>
112 #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
113 #include <QRecursiveMutex>
114 #endif
115 
116 #ifndef Q_OS_WIN
117 #include <netinet/in.h>
118 #include <pwd.h>
119 #else
120 #include <winsock.h>
121 #include <windows.h>
122 #include <lmcons.h>
123 #define SECURITY_WIN32
124 #include <security.h>
125 #ifdef _MSC_VER
126 #pragma comment( lib, "Secur32.lib" )
127 #endif
128 #endif
129 
130 #include "qgsconfig.h"
131 
132 #include <gdal.h>
133 #include <ogr_api.h>
134 #include <cpl_conv.h> // for setting gdal options
135 #include <sqlite3.h>
136 #include <mutex>
137 
138 #include <proj.h>
139 
140 #if defined(Q_OS_LINUX)
141 #include <sys/sysinfo.h>
142 #endif
143 
144 #define CONN_POOL_MAX_CONCURRENT_CONNS 4
145 
146 QObject *ABISYM( QgsApplication::mFileOpenEventReceiver ) = nullptr;
147 bool ABISYM( QgsApplication::mInitialized ) = false;
148 bool ABISYM( QgsApplication::mRunningFromBuildDir ) = false;
149 const char *QgsApplication::QGIS_ORGANIZATION_NAME = "QGIS";
150 const char *QgsApplication::QGIS_ORGANIZATION_DOMAIN = "qgis.org";
151 const char *QgsApplication::QGIS_APPLICATION_NAME = "QGIS3";
152 QgsApplication::ApplicationMembers *QgsApplication::sApplicationMembers = nullptr;
153 QgsAuthManager *QgsApplication::sAuthManager = nullptr;
154 int ABISYM( QgsApplication::sMaxThreads ) = -1;
155 
156 Q_GLOBAL_STATIC( QStringList, sFileOpenEventList )
157 Q_GLOBAL_STATIC( QString, sPrefixPath )
158 Q_GLOBAL_STATIC( QString, sPluginPath )
159 Q_GLOBAL_STATIC( QString, sPkgDataPath )
160 Q_GLOBAL_STATIC( QString, sLibraryPath )
161 Q_GLOBAL_STATIC( QString, sLibexecPath )
162 Q_GLOBAL_STATIC( QString, sQmlImportPath )
163 Q_GLOBAL_STATIC( QString, sThemeName )
164 Q_GLOBAL_STATIC( QString, sProfilePath )
165 
166 Q_GLOBAL_STATIC( QStringList, sDefaultSvgPaths )
167 Q_GLOBAL_STATIC( QgsStringMap, sSystemEnvVars )
168 Q_GLOBAL_STATIC( QString, sConfigPath )
169 
170 Q_GLOBAL_STATIC( QString, sBuildSourcePath )
171 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
172 Q_GLOBAL_STATIC( QString, sCfgIntDir )
173 #endif
174 Q_GLOBAL_STATIC( QString, sBuildOutputPath )
175 Q_GLOBAL_STATIC( QStringList, sGdalSkipList )
176 Q_GLOBAL_STATIC( QStringList, sDeferredSkippedGdalDrivers )
177 Q_GLOBAL_STATIC( QString, sAuthDbDirPath )
178 
179 Q_GLOBAL_STATIC( QString, sUserName )
180 Q_GLOBAL_STATIC( QString, sUserFullName )
181 Q_GLOBAL_STATIC_WITH_ARGS( QString, sPlatformName, ( "external" ) )
182 Q_GLOBAL_STATIC( QString, sTranslation )
183 
184 Q_GLOBAL_STATIC( QTemporaryDir, sIconCacheDir )
185 
186 QgsApplication::QgsApplication( int &argc, char **argv, bool GUIenabled, const QString &profileFolder, const QString &platformName )
187  : QApplication( argc, argv, GUIenabled )
188 {
189  *sPlatformName() = platformName;
190 
191  if ( *sTranslation() != QLatin1String( "C" ) )
192  {
193  mQgisTranslator = new QTranslator();
194  if ( mQgisTranslator->load( QStringLiteral( "qgis_" ) + *sTranslation(), i18nPath() ) )
195  {
196  installTranslator( mQgisTranslator );
197  }
198  else
199  {
200  QgsDebugMsgLevel( QStringLiteral( "loading of qgis translation failed %1/qgis_%2" ).arg( i18nPath(), *sTranslation() ), 2 );
201  }
202 
203  /* Translation file for Qt.
204  * The strings from the QMenuBar context section are used by Qt/Mac to shift
205  * the About, Preferences and Quit items to the Mac Application menu.
206  * These items must be translated identically in both qt_ and qgis_ files.
207  */
208  QString qtTranslationsPath = QLibraryInfo::location( QLibraryInfo::TranslationsPath );
209 #ifdef __MINGW32__
210  QString prefix = QDir( QString( "%1/../" ).arg( QApplication::applicationDirPath() ) ).absolutePath();
211  qtTranslationsPath = prefix + qtTranslationsPath.mid( QLibraryInfo::location( QLibraryInfo::PrefixPath ).length() );
212 #endif
213 
214  mQtTranslator = new QTranslator();
215  if ( mQtTranslator->load( QStringLiteral( "qt_" ) + *sTranslation(), qtTranslationsPath ) )
216  {
217  installTranslator( mQtTranslator );
218  }
219  else
220  {
221  QgsDebugMsgLevel( QStringLiteral( "loading of qt translation failed %1/qt_%2" ).arg( qtTranslationsPath, *sTranslation() ), 2 );
222  }
223 
224  mQtBaseTranslator = new QTranslator();
225  if ( mQtBaseTranslator->load( QStringLiteral( "qtbase_" ) + *sTranslation(), qtTranslationsPath ) )
226  {
227  installTranslator( mQtBaseTranslator );
228  }
229  else
230  {
231  QgsDebugMsgLevel( QStringLiteral( "loading of qtbase translation failed %1/qt_%2" ).arg( qtTranslationsPath, *sTranslation() ), 2 );
232  }
233  }
234 
235  mApplicationMembers = new ApplicationMembers();
236 
237  *sProfilePath() = profileFolder;
238 
240 }
241 
242 void QgsApplication::init( QString profileFolder )
243 {
244  if ( profileFolder.isEmpty() )
245  {
246  if ( getenv( "QGIS_CUSTOM_CONFIG_PATH" ) )
247  {
248  profileFolder = getenv( "QGIS_CUSTOM_CONFIG_PATH" );
249  }
250  else
251  {
252  profileFolder = QStandardPaths::standardLocations( QStandardPaths::AppDataLocation ).value( 0 );
253  }
254  // This will normally get here for custom scripts that use QgsApplication.
255  // This doesn't get this hit for QGIS Desktop because we setup the profile via main
256  QString rootProfileFolder = QgsUserProfileManager::resolveProfilesFolder( profileFolder );
257  QgsUserProfileManager manager( rootProfileFolder );
258  QgsUserProfile *profile = manager.getProfile();
259  profileFolder = profile->folder();
260  delete profile;
261  }
262 
263  *sProfilePath() = profileFolder;
264 
265  static std::once_flag sMetaTypesRegistered;
266  std::call_once( sMetaTypesRegistered, []
267  {
268  qRegisterMetaType<QgsGeometry::Error>( "QgsGeometry::Error" );
269  qRegisterMetaType<QgsDatabaseQueryLogEntry>( "QgsDatabaseQueryLogEntry" );
270  qRegisterMetaType<QgsProcessingFeatureSourceDefinition>( "QgsProcessingFeatureSourceDefinition" );
271  qRegisterMetaType<QgsProcessingOutputLayerDefinition>( "QgsProcessingOutputLayerDefinition" );
272  qRegisterMetaType<QgsUnitTypes::LayoutUnit>( "QgsUnitTypes::LayoutUnit" );
273  qRegisterMetaType<QgsFeatureId>( "QgsFeatureId" );
274  qRegisterMetaType<QgsFields>( "QgsFields" );
275  qRegisterMetaType<QgsFeatureIds>( "QgsFeatureIds" );
276  qRegisterMetaType<QgsProperty>( "QgsProperty" );
277  qRegisterMetaType<QgsFeatureStoreList>( "QgsFeatureStoreList" );
278  qRegisterMetaType<Qgis::MessageLevel>( "Qgis::MessageLevel" );
279  qRegisterMetaType<Qgis::BrowserItemState>( "Qgis::BrowserItemState" );
280  qRegisterMetaType<QgsReferencedRectangle>( "QgsReferencedRectangle" );
281  qRegisterMetaType<QgsReferencedPointXY>( "QgsReferencedPointXY" );
282  qRegisterMetaType<QgsReferencedGeometry>( "QgsReferencedGeometry" );
283  qRegisterMetaType<QgsLayoutRenderContext::Flags>( "QgsLayoutRenderContext::Flags" );
284  qRegisterMetaType<QgsStyle::StyleEntity>( "QgsStyle::StyleEntity" );
285  qRegisterMetaType<QgsCoordinateReferenceSystem>( "QgsCoordinateReferenceSystem" );
286  qRegisterMetaType<QgsAuthManager::MessageLevel>( "QgsAuthManager::MessageLevel" );
287  qRegisterMetaType<QgsNetworkRequestParameters>( "QgsNetworkRequestParameters" );
288  qRegisterMetaType<QgsNetworkReplyContent>( "QgsNetworkReplyContent" );
289  qRegisterMetaType<QgsGeometry>( "QgsGeometry" );
290  qRegisterMetaType<QgsDatumTransform::GridDetails>( "QgsDatumTransform::GridDetails" );
291  qRegisterMetaType<QgsDatumTransform::TransformDetails>( "QgsDatumTransform::TransformDetails" );
292  qRegisterMetaType<QgsNewsFeedParser::Entry>( "QgsNewsFeedParser::Entry" );
293  qRegisterMetaType<QgsRectangle>( "QgsRectangle" );
294  qRegisterMetaType<QgsLocatorResult>( "QgsLocatorResult" );
295  qRegisterMetaType<QgsProcessingModelChildParameterSource>( "QgsProcessingModelChildParameterSource" );
296 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
297  // Qt6 documentation says these are not needed anymore (https://www.qt.io/blog/whats-new-in-qmetatype-qvariant) #spellok
298  // TODO: when tests can run against Qt6 builds, check for any regressions
299  qRegisterMetaTypeStreamOperators<QgsProcessingModelChildParameterSource>( "QgsProcessingModelChildParameterSource" );
300 #endif
301  qRegisterMetaType<QgsRemappingSinkDefinition>( "QgsRemappingSinkDefinition" );
302  qRegisterMetaType<QgsProcessingModelChildDependency>( "QgsProcessingModelChildDependency" );
303  qRegisterMetaType<QgsTextFormat>( "QgsTextFormat" );
304 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
305  QMetaType::registerComparators<QgsProcessingModelChildDependency>();
306  QMetaType::registerEqualsComparator<QgsProcessingFeatureSourceDefinition>();
307  QMetaType::registerEqualsComparator<QgsProperty>();
308  QMetaType::registerEqualsComparator<QgsDateTimeRange>();
309  QMetaType::registerEqualsComparator<QgsDateRange>();
310 #endif
311  qRegisterMetaType<QPainter::CompositionMode>( "QPainter::CompositionMode" );
312  qRegisterMetaType<QgsDateTimeRange>( "QgsDateTimeRange" );
313  qRegisterMetaType<QList<QgsMapLayer *>>( "QList<QgsMapLayer*>" );
314  qRegisterMetaType<QMap<QNetworkRequest::Attribute, QVariant>>( "QMap<QNetworkRequest::Attribute,QVariant>" );
315  qRegisterMetaType<QMap<QNetworkRequest::KnownHeaders, QVariant>>( "QMap<QNetworkRequest::KnownHeaders,QVariant>" );
316  qRegisterMetaType<QList<QNetworkReply::RawHeaderPair>>( "QList<QNetworkReply::RawHeaderPair>" );
317  } );
318 
319  ( void ) resolvePkgPath();
320 
321  if ( ABISYM( mRunningFromBuildDir ) )
322  {
323  // we run from source directory - not installed to destination (specified prefix)
324  *sPrefixPath() = QString(); // set invalid path
325 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
326  setPluginPath( *sBuildOutputPath() + '/' + QString( QGIS_PLUGIN_SUBDIR ) + '/' + *sCfgIntDir() );
327 #else
328  setPluginPath( *sBuildOutputPath() + '/' + QStringLiteral( QGIS_PLUGIN_SUBDIR ) );
329 #endif
330  setPkgDataPath( *sBuildOutputPath() + QStringLiteral( "/data" ) ); // in buildDir/data - used for: doc, resources, svg
331  *sLibraryPath() = *sBuildOutputPath() + '/' + QGIS_LIB_SUBDIR + '/';
332 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
333  *sLibexecPath() = *sBuildOutputPath() + '/' + QGIS_LIBEXEC_SUBDIR + '/' + *sCfgIntDir() + '/';
334 #else
335  *sLibexecPath() = *sBuildOutputPath() + '/' + QGIS_LIBEXEC_SUBDIR + '/';
336 #endif
337 #if defined( HAVE_QUICK )
338  *sQmlImportPath() = *sBuildOutputPath() + '/' + QGIS_QML_SUBDIR + '/';
339 #endif
340  }
341  else
342  {
343  char *prefixPath = getenv( "QGIS_PREFIX_PATH" );
344  if ( !prefixPath )
345  {
346  if ( sPrefixPath()->isNull() )
347  {
348 #if defined(Q_OS_MACX) || defined(Q_OS_WIN)
349  setPrefixPath( applicationDirPath(), true );
350 #elif defined(ANDROID)
351  // this is "/data/data/org.qgis.qgis" in android
352  QDir myDir( QDir::homePath() );
353  myDir.cdUp();
354  QString myPrefix = myDir.absolutePath();
355  setPrefixPath( myPrefix, true );
356 #else
357  QDir myDir( applicationDirPath() );
358  // Fix for server which is one level deeper in /usr/lib/cgi-bin
359  if ( applicationDirPath().contains( QStringLiteral( "cgi-bin" ) ) )
360  {
361  myDir.cdUp();
362  }
363  myDir.cdUp(); // Go from /usr/bin or /usr/lib (for server) to /usr
364  QString myPrefix = myDir.absolutePath();
365  setPrefixPath( myPrefix, true );
366 #endif
367  }
368  }
369  else
370  {
371  setPrefixPath( prefixPath, true );
372  }
373  }
374 
375  *sConfigPath() = profileFolder + '/'; // make sure trailing slash is included
376  *sDefaultSvgPaths() << qgisSettingsDirPath() + QStringLiteral( "svg/" );
377 
378  *sAuthDbDirPath() = qgisSettingsDirPath();
379  if ( getenv( "QGIS_AUTH_DB_DIR_PATH" ) )
380  {
381  setAuthDatabaseDirPath( getenv( "QGIS_AUTH_DB_DIR_PATH" ) );
382  }
383 
384  // store system environment variables passed to application, before they are adjusted
385  QMap<QString, QString> systemEnvVarMap;
386  QString passfile( QStringLiteral( "QGIS_AUTH_PASSWORD_FILE" ) ); // QString, for comparison
387 
388  const auto systemEnvironment = QProcessEnvironment::systemEnvironment().toStringList();
389  for ( const QString &varStr : systemEnvironment )
390  {
391  int pos = varStr.indexOf( QLatin1Char( '=' ) );
392  if ( pos == -1 )
393  continue;
394  QString varStrName = varStr.left( pos );
395  QString varStrValue = varStr.mid( pos + 1 );
396  if ( varStrName != passfile )
397  {
398  systemEnvVarMap.insert( varStrName, varStrValue );
399  }
400  }
401  *sSystemEnvVars() = systemEnvVarMap;
402 
403  // append local user-writable folder as a proj search path
404  QStringList currentProjSearchPaths = QgsProjUtils::searchPaths();
405  currentProjSearchPaths.append( qgisSettingsDirPath() + QStringLiteral( "proj" ) );
406 #ifdef Q_OS_MACX
407  // append bundled proj lib for MacOS
408  QString projLib( QDir::cleanPath( pkgDataPath().append( "/proj" ) ) );
409  if ( QFile::exists( projLib ) )
410  {
411  currentProjSearchPaths.append( projLib );
412  }
413 #endif // Q_OS_MACX
414 
415  char **newPaths = new char *[currentProjSearchPaths.length()];
416  for ( int i = 0; i < currentProjSearchPaths.count(); ++i )
417  {
418  newPaths[i] = CPLStrdup( currentProjSearchPaths.at( i ).toUtf8().constData() );
419  }
420  proj_context_set_search_paths( nullptr, currentProjSearchPaths.count(), newPaths );
421  for ( int i = 0; i < currentProjSearchPaths.count(); ++i )
422  {
423  CPLFree( newPaths[i] );
424  }
425  delete [] newPaths;
426 
427  // allow Qt to search for Qt plugins (e.g. sqldrivers) in our plugin directory
428  QCoreApplication::addLibraryPath( pluginPath() );
429 
430  // set max. thread count to -1
431  // this should be read from QgsSettings but we don't know where they are at this point
432  // so we read actual value in main.cpp
433  ABISYM( sMaxThreads ) = -1;
434 
435  {
436  QgsScopedRuntimeProfile profile( tr( "Load color schemes" ) );
439  }
440 
441  {
442  QgsScopedRuntimeProfile profile( tr( "Load bookmarks" ) );
444  }
445 
446  // trigger creation of default style
447  QgsStyle *defaultStyle = QgsStyle::defaultStyle();
448  if ( !members()->mStyleModel )
449  members()->mStyleModel = new QgsStyleModel( defaultStyle );
450 
451  ABISYM( mInitialized ) = true;
452 }
453 
455 {
456  delete mDataItemProviderRegistry;
457  delete mApplicationMembers;
458  delete mQgisTranslator;
459  delete mQtTranslator;
460  delete mQtBaseTranslator;
461 
462  // we do this here as well as in exitQgis() -- it's safe to call as often as we want,
463  // and there's just a *chance* that someone hasn't properly called exitQgis prior to
464  // this destructor...
465  invalidateCaches();
466 }
467 
468 void QgsApplication::invalidateCaches()
469 {
470  // invalidate coordinate cache while the PROJ context held by the thread-locale
471  // QgsProjContextStore object is still alive. Otherwise if this later object
472  // is destroyed before the static variables of the cache, we might use freed memory.
476 }
477 
479 {
480  return qobject_cast<QgsApplication *>( QCoreApplication::instance() );
481 }
482 
483 bool QgsApplication::event( QEvent *event )
484 {
485  bool done = false;
486  if ( event->type() == QEvent::FileOpen )
487  {
488  // handle FileOpen event (double clicking a file icon in Mac OS X Finder)
489  if ( ABISYM( mFileOpenEventReceiver ) )
490  {
491  // Forward event to main window.
492  done = notify( ABISYM( mFileOpenEventReceiver ), event );
493  }
494  else
495  {
496  // Store filename because receiver has not registered yet.
497  // If QGIS has been launched by double clicking a file icon, FileOpen will be
498  // the first event; the main window is not yet ready to handle the event.
499  sFileOpenEventList()->append( static_cast<QFileOpenEvent *>( event )->file() );
500  done = true;
501  }
502  }
503  else
504  {
505  // pass other events to base class
506  done = QApplication::event( event );
507  }
508  return done;
509 }
510 
511 bool QgsApplication::notify( QObject *receiver, QEvent *event )
512 {
513  bool done = false;
514  // Crashes in customization (especially on Mac), if we're not in the main/UI thread, see #5597
515  if ( thread() == receiver->thread() )
516  emit preNotify( receiver, event, &done );
517 
518  if ( done )
519  return true;
520 
521  // Send event to receiver and catch unhandled exceptions
522  done = true;
523  try
524  {
525  done = QApplication::notify( receiver, event );
526  }
527  catch ( QgsException &e )
528  {
529  qCritical() << "Caught unhandled QgsException: " << e.what();
530  if ( qApp->thread() == QThread::currentThread() )
531  QMessageBox::critical( activeWindow(), tr( "Exception" ), e.what() );
532  }
533  catch ( std::exception &e )
534  {
535  qCritical() << "Caught unhandled std::exception: " << e.what();
536  if ( qApp->thread() == QThread::currentThread() )
537  QMessageBox::critical( activeWindow(), tr( "Exception" ), e.what() );
538  }
539  catch ( ... )
540  {
541  qCritical() << "Caught unhandled unknown exception";
542  if ( qApp->thread() == QThread::currentThread() )
543  QMessageBox::critical( activeWindow(), tr( "Exception" ), tr( "unknown exception" ) );
544  }
545 
546  return done;
547 }
548 
550 {
551  return QgsRuntimeProfiler::threadLocalInstance();
552 }
553 
555 {
556  // Set receiver for FileOpen events
557  ABISYM( mFileOpenEventReceiver ) = receiver;
558  // Propagate any events collected before the receiver has registered.
559  if ( sFileOpenEventList()->count() > 0 )
560  {
561  const QStringList fileOpenEventList = *sFileOpenEventList();
562  for ( const QString &file : fileOpenEventList )
563  {
564  QFileOpenEvent foe( file );
565  QgsApplication::sendEvent( ABISYM( mFileOpenEventReceiver ), &foe );
566  }
567  sFileOpenEventList()->clear();
568  }
569 }
570 
571 void QgsApplication::setPrefixPath( const QString &prefixPath, bool useDefaultPaths )
572 {
573  *sPrefixPath() = prefixPath;
574 #if defined(Q_OS_WIN)
575  if ( sPrefixPath()->endsWith( "/bin" ) )
576  {
577  sPrefixPath()->chop( 4 );
578  }
579 #endif
580  if ( useDefaultPaths && !ABISYM( mRunningFromBuildDir ) )
581  {
582  setPluginPath( *sPrefixPath() + '/' + QStringLiteral( QGIS_PLUGIN_SUBDIR ) );
583  setPkgDataPath( *sPrefixPath() + '/' + QStringLiteral( QGIS_DATA_SUBDIR ) );
584  }
585  *sLibraryPath() = *sPrefixPath() + '/' + QGIS_LIB_SUBDIR + '/';
586  *sLibexecPath() = *sPrefixPath() + '/' + QGIS_LIBEXEC_SUBDIR + '/';
587 #if defined( HAVE_QUICK )
588  *sQmlImportPath() = *sPrefixPath() + '/' + QGIS_QML_SUBDIR + '/';
589 #endif
590 }
591 
592 void QgsApplication::setPluginPath( const QString &pluginPath )
593 {
594  *sPluginPath() = pluginPath;
595 }
596 
597 void QgsApplication::setPkgDataPath( const QString &pkgDataPath )
598 {
599  *sPkgDataPath() = pkgDataPath;
600 
601  QString mySvgPath = pkgDataPath + QStringLiteral( "/svg/" );
602 
603  // avoid duplicate entries
604  if ( !sDefaultSvgPaths()->contains( mySvgPath ) )
605  *sDefaultSvgPaths() << mySvgPath;
606 }
607 
608 void QgsApplication::setDefaultSvgPaths( const QStringList &pathList )
609 {
610  *sDefaultSvgPaths() = pathList;
611 }
612 
613 void QgsApplication::setAuthDatabaseDirPath( const QString &authDbDirPath )
614 {
615  QFileInfo fi( authDbDirPath );
616  if ( fi.exists() && fi.isDir() && fi.isWritable() )
617  {
618  *sAuthDbDirPath() = fi.canonicalFilePath() + QDir::separator();
619  }
620 }
621 
623 {
624 #if 0
625  if ( ABISYM( mRunningFromBuildDir ) )
626  {
627  static bool sOnce = true;
628  if ( sOnce )
629  {
630  QgsMessageLogNotifyBlocker blockNotifications;
631  ( void ) blockNotifications;
632  qWarning( "!!! prefix path was requested, but it is not valid - we do not run from installed path !!!" );
633  }
634  sOnce = false;
635  }
636 #endif
637 
638  return *sPrefixPath();
639 }
641 {
642  return *sPluginPath();
643 }
644 
646 {
647  if ( sPkgDataPath()->isNull() )
648  return resolvePkgPath();
649  else
650  return *sPkgDataPath();
651 }
652 
654 {
655  return QStringLiteral( ":/images/themes/default/" );
656 }
658 {
659  QString usersThemes = userThemesFolder() + QDir::separator() + themeName() + QDir::separator() + "icons/";
660  QDir dir( usersThemes );
661  if ( dir.exists() )
662  {
663  return usersThemes;
664  }
665  else
666  {
667  QString defaultThemes = defaultThemesFolder() + QDir::separator() + themeName() + QDir::separator() + "icons/";
668  return defaultThemes;
669  }
670 }
671 
673 {
674  return iconsPath() + QStringLiteral( "qgis-icon-60x60.png" );
675 }
676 
678 {
679  return ABISYM( sMaxThreads );
680 }
681 
682 QString QgsApplication::iconPath( const QString &iconFile )
683 {
684  // try active theme
685  QString path = activeThemePath();
686  if ( QFile::exists( path + iconFile ) )
687  return path + iconFile;
688 
689  // use default theme
690  return defaultThemePath() + iconFile;
691 }
692 
693 QIcon QgsApplication::getThemeIcon( const QString &name, const QColor &fillColor, const QColor &strokeColor )
694 {
695  const QString cacheKey = ( name.startsWith( '/' ) ? name.mid( 1 ) : name )
696  + ( fillColor.isValid() ? QStringLiteral( "_%1" ).arg( fillColor.name( QColor::HexArgb ).mid( 1 ) ) : QString() )
697  + ( strokeColor.isValid() ? QStringLiteral( "_%1" ).arg( strokeColor.name( QColor::HexArgb ).mid( 1 ) ) : QString() );
698  QgsApplication *app = instance();
699  if ( app && app->mIconCache.contains( cacheKey ) )
700  return app->mIconCache.value( cacheKey );
701 
702  QIcon icon;
703  const bool colorBased = fillColor.isValid() || strokeColor.isValid();
704 
705  auto iconFromColoredSvg = [ = ]( const QString & path ) -> QIcon
706  {
707  // sizes are unused here!
708  const QByteArray svgContent = QgsApplication::svgCache()->svgContent( path, 16, fillColor, strokeColor, 1, 1 );
709 
710  const QString iconPath = sIconCacheDir()->filePath( cacheKey + QStringLiteral( ".svg" ) );
711  QFile f( iconPath );
712  if ( f.open( QFile::WriteOnly | QFile::Truncate ) )
713  {
714  f.write( svgContent );
715  f.close();
716  }
717  else
718  {
719  QgsDebugMsg( QStringLiteral( "Could not create colorized icon svg at %1" ).arg( iconPath ) );
720  return QIcon();
721  }
722 
723  return QIcon( f.fileName() );
724  };
725 
726  QString preferredPath = activeThemePath() + QDir::separator() + name;
727  QString defaultPath = defaultThemePath() + QDir::separator() + name;
728  if ( QFile::exists( preferredPath ) )
729  {
730  if ( colorBased )
731  {
732  icon = iconFromColoredSvg( preferredPath );
733  }
734  else
735  {
736  icon = QIcon( preferredPath );
737  }
738  }
739  else if ( QFile::exists( defaultPath ) )
740  {
741  //could still return an empty icon if it
742  //doesn't exist in the default theme either!
743  if ( colorBased )
744  {
745  icon = iconFromColoredSvg( defaultPath );
746  }
747  else
748  {
749  icon = QIcon( defaultPath );
750  }
751  }
752  else
753  {
754  icon = QIcon();
755  }
756 
757  if ( app )
758  app->mIconCache.insert( cacheKey, icon );
759  return icon;
760 }
761 
763 {
764  QgsApplication *app = instance();
765  if ( app && app->mCursorCache.contains( cursor ) )
766  return app->mCursorCache.value( cursor );
767 
768  // All calculations are done on 32x32 icons
769  // Defaults to center, individual cursors may override
770  int activeX = 16;
771  int activeY = 16;
772 
773  QString name;
774  switch ( cursor )
775  {
776  case ZoomIn:
777  name = QStringLiteral( "mZoomIn.svg" );
778  activeX = 13;
779  activeY = 13;
780  break;
781  case ZoomOut:
782  name = QStringLiteral( "mZoomOut.svg" );
783  activeX = 13;
784  activeY = 13;
785  break;
786  case Identify:
787  activeX = 3;
788  activeY = 6;
789  name = QStringLiteral( "mIdentify.svg" );
790  break;
791  case CrossHair:
792  name = QStringLiteral( "mCrossHair.svg" );
793  break;
794  case CapturePoint:
795  name = QStringLiteral( "mCapturePoint.svg" );
796  break;
797  case Select:
798  name = QStringLiteral( "mSelect.svg" );
799  activeX = 6;
800  activeY = 6;
801  break;
802  case Sampler:
803  activeX = 5;
804  activeY = 5;
805  name = QStringLiteral( "mSampler.svg" );
806  break;
807  // No default
808  }
809  // It should never get here!
810  Q_ASSERT( ! name.isEmpty( ) );
811 
812  QIcon icon = getThemeIcon( QStringLiteral( "cursors" ) + QDir::separator() + name );
813  QCursor cursorIcon;
814  // Check if an icon exists for this cursor (the O.S. default cursor will be used if it does not)
815  if ( ! icon.isNull( ) )
816  {
817  // Apply scaling
818  float scale = Qgis::UI_SCALE_FACTOR * QgsApplication::fontMetrics().height() / 32.0;
819  cursorIcon = QCursor( icon.pixmap( std::ceil( scale * 32 ), std::ceil( scale * 32 ) ), std::ceil( scale * activeX ), std::ceil( scale * activeY ) );
820  }
821  if ( app )
822  app->mCursorCache.insert( cursor, cursorIcon );
823  return cursorIcon;
824 }
825 
826 // TODO: add some caching mechanism ?
827 QPixmap QgsApplication::getThemePixmap( const QString &name, const QColor &foreColor, const QColor &backColor, const int size )
828 {
829  const QString preferredPath = activeThemePath() + QDir::separator() + name;
830  const QString defaultPath = defaultThemePath() + QDir::separator() + name;
831  const QString path = QFile::exists( preferredPath ) ? preferredPath : defaultPath;
832  if ( foreColor.isValid() || backColor.isValid() )
833  {
834  bool fitsInCache = false;
835  const QImage image = svgCache()->svgAsImage( path, size, backColor, foreColor, 1, 1, fitsInCache );
836  return QPixmap::fromImage( image );
837  }
838 
839  return QPixmap( path );
840 }
841 
842 void QgsApplication::setThemeName( const QString &themeName )
843 {
844  *sThemeName() = themeName;
845 }
846 
848 {
849  static QString appPath;
850  if ( appPath.isNull() )
851  {
852  if ( QCoreApplication::instance() )
853  {
854  appPath = applicationDirPath();
855  }
856  else
857  {
858  qWarning( "Application path not initialized" );
859  }
860  }
861 
862  if ( !appPath.isNull() || getenv( "QGIS_PREFIX_PATH" ) )
863  {
864  QString prefix = getenv( "QGIS_PREFIX_PATH" ) ? getenv( "QGIS_PREFIX_PATH" ) : appPath;
865 
866  // check if QGIS is run from build directory (not the install directory)
867  QFile f;
868  // "/../../.." is for Mac bundled app in build directory
869  static const QStringList paths { QStringList() << QString() << QStringLiteral( "/.." ) << QStringLiteral( "/bin" ) << QStringLiteral( "/../../.." ) };
870  for ( const QString &path : paths )
871  {
872  f.setFileName( prefix + path + "/qgisbuildpath.txt" );
873  if ( f.exists() )
874  break;
875  }
876  if ( f.exists() && f.open( QIODevice::ReadOnly ) )
877  {
878  ABISYM( mRunningFromBuildDir ) = true;
879  *sBuildSourcePath() = f.readLine().trimmed();
880  *sBuildOutputPath() = f.readLine().trimmed();
881  QgsDebugMsgLevel( QStringLiteral( "Running from build directory!" ), 4 );
882  QgsDebugMsgLevel( QStringLiteral( "- source directory: %1" ).arg( sBuildSourcePath()->toUtf8().constData() ), 4 );
883  QgsDebugMsgLevel( QStringLiteral( "- output directory of the build: %1" ).arg( sBuildOutputPath()->toUtf8().constData() ), 4 );
884 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
885  *sCfgIntDir() = prefix.split( '/', QString::SkipEmptyParts ).last();
886  qDebug( "- cfg: %s", sCfgIntDir()->toUtf8().constData() );
887 #endif
888  }
889  }
890 
891  QString prefixPath;
892  if ( getenv( "QGIS_PREFIX_PATH" ) )
893  prefixPath = getenv( "QGIS_PREFIX_PATH" );
894  else
895  {
896 #if defined(ANDROID)
897  // this is "/data/data/org.qgis.qgis" in android
898  QDir dir( QDir::homePath() );
899  dir.cdUp();
900  prefixPath = dir.absolutePath();
901 #else
902 
903 #if defined(Q_OS_MACX)
904  prefixPath = appPath;
905 #elif defined(Q_OS_WIN)
906  prefixPath = appPath;
907  if ( prefixPath.endsWith( "/bin" ) )
908  prefixPath.chop( 4 );
909 #else
910  QDir dir( appPath );
911  // Fix for server which is one level deeper in /usr/lib/cgi-bin
912  if ( appPath.contains( QStringLiteral( "cgi-bin" ) ) )
913  {
914  dir.cdUp();
915  }
916  dir.cdUp(); // Go from /usr/bin or /usr/lib (for server) to /usr
917  prefixPath = dir.absolutePath();
918 #endif
919 #endif
920  }
921 
922  if ( ABISYM( mRunningFromBuildDir ) )
923  return *sBuildOutputPath() + QStringLiteral( "/data" );
924  else
925  return prefixPath + '/' + QStringLiteral( QGIS_DATA_SUBDIR );
926 }
927 
929 {
930  return *sThemeName();
931 }
932 
933 void QgsApplication::setUITheme( const QString &themeName )
934 {
935  // Loop all style sheets, find matching name, load it.
936  QHash<QString, QString> themes = QgsApplication::uiThemes();
937  if ( themeName == QLatin1String( "default" ) || !themes.contains( themeName ) )
938  {
939  setThemeName( QStringLiteral( "default" ) );
940  qApp->setStyleSheet( QString() );
941  return;
942  }
943 
944  QString path = themes.value( themeName );
945  QString stylesheetname = path + "/style.qss";
946 
947  QFile file( stylesheetname );
948  QFile variablesfile( path + "/variables.qss" );
949 
950  QFileInfo variableInfo( variablesfile );
951 
952  if ( !file.open( QIODevice::ReadOnly ) || ( variableInfo.exists() && !variablesfile.open( QIODevice::ReadOnly ) ) )
953  {
954  return;
955  }
956 
957  QString styledata = file.readAll();
958  styledata.replace( QLatin1String( "@theme_path" ), path );
959 
960  if ( variableInfo.exists() )
961  {
962  QTextStream in( &variablesfile );
963  while ( !in.atEnd() )
964  {
965  QString line = in.readLine();
966  // This is a variable
967  if ( line.startsWith( '@' ) )
968  {
969  int index = line.indexOf( ':' );
970  QString name = line.mid( 0, index );
971  QString value = line.mid( index + 1, line.length() );
972  styledata.replace( name, value );
973  }
974  }
975  variablesfile.close();
976  }
977  file.close();
978 
979  if ( Qgis::UI_SCALE_FACTOR != 1.0 )
980  {
981  // apply OS-specific UI scale factor to stylesheet's em values
982  int index = 0;
983  const static QRegularExpression regex( QStringLiteral( "(?<=[\\s:])([0-9\\.]+)(?=em)" ) );
984  QRegularExpressionMatch match = regex.match( styledata, index );
985  while ( match.hasMatch() )
986  {
987  index = match.capturedStart();
988  styledata.remove( index, match.captured( 0 ).length() );
989  QString number = QString::number( match.captured( 0 ).toDouble() * Qgis::UI_SCALE_FACTOR );
990  styledata.insert( index, number );
991  index += number.length();
992  match = regex.match( styledata, index );
993  }
994  }
995 
996  qApp->setStyleSheet( styledata );
997 
998  QFile palettefile( path + "/palette.txt" );
999  QFileInfo paletteInfo( palettefile );
1000  if ( paletteInfo.exists() && palettefile.open( QIODevice::ReadOnly ) )
1001  {
1002  QPalette pal = qApp->palette();
1003  QTextStream in( &palettefile );
1004  while ( !in.atEnd() )
1005  {
1006  QString line = in.readLine();
1007  QStringList parts = line.split( ':' );
1008  if ( parts.count() == 2 )
1009  {
1010  int role = parts.at( 0 ).trimmed().toInt();
1011  QColor color = QgsSymbolLayerUtils::decodeColor( parts.at( 1 ).trimmed() );
1012  pal.setColor( static_cast< QPalette::ColorRole >( role ), color );
1013  }
1014  }
1015  palettefile.close();
1016  qApp->setPalette( pal );
1017  }
1018 
1020 }
1021 
1022 QHash<QString, QString> QgsApplication::uiThemes()
1023 {
1024  QStringList paths = QStringList() << userThemesFolder() << defaultThemesFolder();
1025  QHash<QString, QString> mapping;
1026  mapping.insert( QStringLiteral( "default" ), QString() );
1027  const auto constPaths = paths;
1028  for ( const QString &path : constPaths )
1029  {
1030  QDir folder( path );
1031  QFileInfoList styleFiles = folder.entryInfoList( QDir::Dirs | QDir::NoDotAndDotDot );
1032  const auto constStyleFiles = styleFiles;
1033  for ( const QFileInfo &info : constStyleFiles )
1034  {
1035  QFileInfo styleFile( info.absoluteFilePath() + "/style.qss" );
1036  if ( !styleFile.exists() )
1037  continue;
1038 
1039  QString name = info.baseName();
1040  QString path = info.absoluteFilePath();
1041  mapping.insert( name, path );
1042  }
1043  }
1044  return mapping;
1045 }
1046 
1048 {
1049  return pkgDataPath() + QStringLiteral( "/doc/AUTHORS" );
1050 }
1051 
1053 {
1054  return pkgDataPath() + QStringLiteral( "/doc/CONTRIBUTORS" );
1055 }
1057 {
1058  return pkgDataPath() + QStringLiteral( "/doc/developersmap.html" );
1059 }
1060 
1062 {
1063  return pkgDataPath() + QStringLiteral( "/doc/SPONSORS" );
1064 }
1065 
1067 {
1068  return pkgDataPath() + QStringLiteral( "/doc/DONORS" );
1069 }
1070 
1072 {
1073  return pkgDataPath() + QStringLiteral( "/doc/TRANSLATORS" );
1074 }
1075 
1077 {
1078  return pkgDataPath() + QStringLiteral( "/doc/LICENSE" );
1079 }
1080 
1082 {
1083  if ( ABISYM( mRunningFromBuildDir ) )
1084  return *sBuildOutputPath() + QStringLiteral( "/i18n/" );
1085  else
1086  return pkgDataPath() + QStringLiteral( "/i18n/" );
1087 }
1088 
1090 {
1091  return pkgDataPath() + QStringLiteral( "/resources/metadata-ISO/" );
1092 }
1093 
1095 {
1096  return pkgDataPath() + QStringLiteral( "/resources/qgis.db" );
1097 }
1098 
1100 {
1101  return *sConfigPath();
1102 }
1103 
1105 {
1106  return qgisSettingsDirPath() + QStringLiteral( "qgis.db" );
1107 }
1108 
1110 {
1111  return *sAuthDbDirPath() + QStringLiteral( "qgis-auth.db" );
1112 }
1113 
1115 {
1116  return QStringLiteral( ":/images/splash/" );
1117 }
1118 
1120 {
1121  return pkgDataPath() + QStringLiteral( "/images/icons/" );
1122 }
1123 
1125 {
1126  if ( ABISYM( mRunningFromBuildDir ) )
1127  {
1128  QString tempCopy = QDir::tempPath() + "/srs6.db";
1129 
1130  if ( !QFile( tempCopy ).exists() )
1131  {
1132  QFile f( buildSourcePath() + "/resources/srs6.db" );
1133  if ( !f.copy( tempCopy ) )
1134  {
1135  qFatal( "Could not create temporary copy" );
1136  }
1137  }
1138 
1139  return tempCopy;
1140  }
1141  else
1142  {
1143  return pkgDataPath() + QStringLiteral( "/resources/srs.db" );
1144  }
1145 }
1146 
1147 void QgsApplication::setSvgPaths( const QStringList &svgPaths )
1148 {
1150  members()->mSvgPathCacheValid = false;
1151 }
1152 
1154 {
1155  static QReadWriteLock lock;
1156 
1158 
1159  if ( members()->mSvgPathCacheValid )
1160  {
1161  return members()->mSvgPathCache;
1162  }
1163  else
1164  {
1166  //local directories to search when looking for an SVG with a given basename
1167  //defined by user in options dialog
1168  const QStringList pathList = settingsSearchPathsForSVG.value();
1169 
1170  // maintain user set order while stripping duplicates
1171  QStringList paths;
1172  for ( const QString &path : pathList )
1173  {
1174  if ( !paths.contains( path ) )
1175  paths.append( path );
1176  }
1177  for ( const QString &path : std::as_const( *sDefaultSvgPaths() ) )
1178  {
1179  if ( !paths.contains( path ) )
1180  paths.append( path );
1181  }
1182  members()->mSvgPathCache = paths;
1183 
1184  return paths;
1185  }
1186 }
1187 
1189 {
1190  //local directories to search when looking for an template with a given basename
1191  //defined by user in options dialog
1193 }
1194 
1195 QMap<QString, QString> QgsApplication::systemEnvVars()
1196 {
1197  return *sSystemEnvVars();
1198 }
1199 
1201 {
1202  return qgisSettingsDirPath() + QStringLiteral( "symbology-style.db" );
1203 }
1204 
1206 {
1207  const thread_local QRegularExpression regexp( QRegularExpression::anchoredPattern( QStringLiteral( "^[A-Za-z][A-Za-z0-9\\._-]*" ) ) );
1208  return regexp;
1209 }
1210 
1212 {
1213  if ( !sUserName()->isEmpty() )
1214  return *sUserName();
1215 
1216 #ifdef _MSC_VER
1217  TCHAR name [ UNLEN + 1 ];
1218  DWORD size = UNLEN + 1;
1219 
1220  if ( GetUserName( ( TCHAR * )name, &size ) )
1221  {
1222  *sUserName() = QString::fromLocal8Bit( name );
1223  }
1224 
1225 #elif QT_CONFIG(process)
1226  QProcess process;
1227 
1228  process.start( QStringLiteral( "whoami" ), QStringList() );
1229  process.waitForFinished();
1230  *sUserName() = process.readAllStandardOutput().trimmed();
1231 #endif
1232 
1233  if ( !sUserName()->isEmpty() )
1234  return *sUserName();
1235 
1236  //backup plan - use environment variables
1237  *sUserName() = qgetenv( "USER" );
1238  if ( !sUserName()->isEmpty() )
1239  return *sUserName();
1240 
1241  //last resort
1242  *sUserName() = qgetenv( "USERNAME" );
1243  return *sUserName();
1244 }
1245 
1247 {
1248  if ( !sUserFullName()->isEmpty() )
1249  return *sUserFullName();
1250 
1251 #ifdef _MSC_VER
1252  TCHAR name [ UNLEN + 1 ];
1253  DWORD size = UNLEN + 1;
1254 
1255  //note - this only works for accounts connected to domain
1256  if ( GetUserNameEx( NameDisplay, ( TCHAR * )name, &size ) )
1257  {
1258  *sUserFullName() = QString::fromLocal8Bit( name );
1259  }
1260 
1261  //fall back to login name
1262  if ( sUserFullName()->isEmpty() )
1263  *sUserFullName() = userLoginName();
1264 #elif defined(Q_OS_ANDROID) || defined(__MINGW32__)
1265  *sUserFullName() = QStringLiteral( "Not available" );
1266 #else
1267  struct passwd *p = getpwuid( getuid() );
1268 
1269  if ( p )
1270  {
1271  QString gecosName = QString( p->pw_gecos );
1272  *sUserFullName() = gecosName.left( gecosName.indexOf( ',', 0 ) );
1273  }
1274 
1275 #endif
1276 
1277  return *sUserFullName();
1278 }
1279 
1281 {
1282 #if defined(Q_OS_ANDROID)
1283  return QLatin1String( "android" );
1284 #elif defined(Q_OS_MAC)
1285  return QLatin1String( "osx" );
1286 #elif defined(Q_OS_WIN)
1287  return QLatin1String( "windows" );
1288 #elif defined(Q_OS_LINUX)
1289  return QStringLiteral( "linux" );
1290 #elif defined(Q_OS_FREEBSD)
1291  return QStringLiteral( "freebsd" );
1292 #elif defined(Q_OS_OPENBSD)
1293  return QStringLiteral( "openbsd" );
1294 #elif defined(Q_OS_NETBSD)
1295  return QStringLiteral( "netbsd" );
1296 #elif defined(Q_OS_UNIX)
1297  return QLatin1String( "unix" );
1298 #else
1299  return QLatin1String( "unknown" );
1300 #endif
1301 }
1302 
1304 {
1305 #if defined(Q_OS_ANDROID)
1306  return -1;
1307 #elif defined(Q_OS_MAC)
1308  return -1;
1309 #elif defined(Q_OS_WIN)
1310  MEMORYSTATUSEX memoryStatus;
1311  ZeroMemory( &memoryStatus, sizeof( MEMORYSTATUSEX ) );
1312  memoryStatus.dwLength = sizeof( MEMORYSTATUSEX );
1313  if ( GlobalMemoryStatusEx( &memoryStatus ) )
1314  {
1315  return memoryStatus.ullTotalPhys / ( 1024 * 1024 );
1316  }
1317  else
1318  {
1319  return -1;
1320  }
1321 #elif defined(Q_OS_LINUX)
1322  constexpr int megabyte = 1024 * 1024;
1323  struct sysinfo si;
1324  sysinfo( &si );
1325  return si.totalram / megabyte;
1326 #elif defined(Q_OS_FREEBSD)
1327  return -1;
1328 #elif defined(Q_OS_OPENBSD)
1329  return -1;
1330 #elif defined(Q_OS_NETBSD)
1331  return -1;
1332 #elif defined(Q_OS_UNIX)
1333  return -1;
1334 #else
1335  return -1;
1336 #endif
1337 }
1338 
1340 {
1341  return *sPlatformName();
1342 }
1343 
1345 {
1347  {
1349  // don't differentiate en_US and en_GB
1350  if ( locale.startsWith( QLatin1String( "en" ), Qt::CaseInsensitive ) )
1351  {
1352  return locale.left( 2 );
1353  }
1354 
1355  return locale;
1356  }
1357  else
1358  {
1359  return QLocale().name().left( 2 );
1360  }
1361 }
1362 
1363 void QgsApplication::setLocale( const QLocale &locale )
1364 {
1365  QLocale::setDefault( locale );
1366  emit instance()->localeChanged();
1367 }
1368 
1370 {
1371  return qgisSettingsDirPath() + QStringLiteral( "/themes" );
1372 }
1373 
1375 {
1376  return pkgDataPath() + QStringLiteral( "/resources/symbology-style.xml" );
1377 }
1378 
1380 {
1381  return pkgDataPath() + QStringLiteral( "/resources/themes" );
1382 }
1383 
1385 {
1386  return pkgDataPath() + QStringLiteral( "/resources/server/" );
1387 }
1388 
1390 {
1391  return *sLibraryPath();
1392 }
1393 
1395 {
1396  return *sLibexecPath();
1397 }
1398 
1400 {
1401  return *sQmlImportPath();
1402 }
1403 
1405 {
1406  return ( htonl( 1 ) == 1 ) ? XDR : NDR;
1407 }
1408 
1410 {
1411  if ( !ABISYM( mInitialized ) && QgsApplication::instance() )
1412  {
1413  init( *sProfilePath() );
1414  }
1415 
1416  // set the provider plugin path (this creates provider registry)
1418 
1419  // create data item provider registry
1421 
1422  // create project instance if doesn't exist
1424 
1425  // Initialize authentication manager and connect to database
1427 
1428  // Make sure we have a NAM created on the main thread.
1429  // Note that this might call QgsApplication::authManager to
1430  // setup the proxy configuration that's why it needs to be
1431  // called after the QgsAuthManager instance has been created
1433 
1434 }
1435 
1437 {
1438  if ( auto *lInstance = instance() )
1439  {
1440  if ( !lInstance->mAuthManager )
1441  {
1442  lInstance->mAuthManager = QgsAuthManager::instance();
1443  }
1444  return lInstance->mAuthManager;
1445  }
1446  else
1447  {
1448  // no QgsApplication instance
1449  if ( !sAuthManager )
1450  sAuthManager = QgsAuthManager::instance();
1451  return sAuthManager;
1452  }
1453 }
1454 
1455 
1457 {
1458  // make sure all threads are done before exiting
1459  QThreadPool::globalInstance()->waitForDone();
1460 
1461  // don't create to delete
1462  if ( auto *lInstance = instance() )
1463  delete lInstance->mAuthManager;
1464  else
1465  delete sAuthManager;
1466 
1467  //Ensure that all remaining deleteLater QObjects are actually deleted before we exit.
1468  //This isn't strictly necessary (since we're exiting anyway) but doing so prevents a lot of
1469  //LeakSanitiser noise which hides real issues
1470  QgsApplication::sendPostedEvents( nullptr, QEvent::DeferredDelete );
1471 
1472  //delete all registered functions from expression engine (see above comment)
1474 
1475  delete QgsProject::instance();
1476 
1477  // avoid creating instance just to delete it!
1478  if ( QgsProviderRegistry::exists() )
1480 
1481  invalidateCaches();
1482 
1484 
1485  // tear-down GDAL/OGR
1486  OGRCleanupAll();
1487  GDALDestroyDriverManager();
1488 }
1489 
1491 {
1492  QString myEnvironmentVar( getenv( "QGIS_PREFIX_PATH" ) );
1493  QString myState = tr( "Application state:\n"
1494  "QGIS_PREFIX_PATH env var:\t\t%1\n"
1495  "Prefix:\t\t%2\n"
1496  "Plugin Path:\t\t%3\n"
1497  "Package Data Path:\t%4\n"
1498  "Active Theme Name:\t%5\n"
1499  "Active Theme Path:\t%6\n"
1500  "Default Theme Path:\t%7\n"
1501  "SVG Search Paths:\t%8\n"
1502  "User DB Path:\t%9\n"
1503  "Auth DB Path:\t%10\n" )
1504  .arg( myEnvironmentVar,
1505  prefixPath(),
1506  pluginPath(),
1507  pkgDataPath(),
1508  themeName(),
1509  activeThemePath(),
1510  defaultThemePath(),
1511  svgPaths().join( tr( "\n\t\t", "match indentation of application state" ) ),
1513  .arg( qgisAuthDatabaseFilePath() );
1514  return myState;
1515 }
1516 
1518 {
1519  //
1520  // Make the style sheet desktop preferences aware by using qapplication
1521  // palette as a basis for colors where appropriate
1522  //
1523  // QColor myColor1 = palette().highlight().color();
1524  QColor myColor1( Qt::lightGray );
1525  QColor myColor2 = myColor1;
1526  myColor2 = myColor2.lighter( 110 ); //10% lighter
1527  QString myStyle;
1528  myStyle = QStringLiteral( ".overview{"
1529  " font: 1.82em;"
1530  " font-weight: bold;"
1531  "}"
1532  "body{"
1533  " background: white;"
1534  " color: black;"
1535  " font-family: 'Lato', 'Open Sans', 'Lucida Grande', 'Segoe UI', 'Arial', sans-serif;"
1536  " width: 100%;"
1537  "}"
1538  "h1{ background-color: #F6F6F6;"
1539  " color: #589632; " // from http://qgis.org/en/site/getinvolved/styleguide.html
1540  " font-size: x-large; "
1541  " font-weight: normal;"
1542  " background: none;"
1543  " padding: 0.75em 0 0;"
1544  " margin: 0;"
1545  " line-height: 3em;"
1546  "}"
1547  "h2{ background-color: #F6F6F6;"
1548  " color: #589632; " // from http://qgis.org/en/site/getinvolved/styleguide.html
1549  " font-size: medium; "
1550  " font-weight: normal;"
1551  " background: none;"
1552  " padding: 0.75em 0 0;"
1553  " margin: 0;"
1554  " line-height: 1.1em;"
1555  "}"
1556  "h3{ background-color: #F6F6F6;"
1557  " color: #93b023;" // from http://qgis.org/en/site/getinvolved/styleguide.html
1558  " font-weight: bold;"
1559  " font-size: large;"
1560  " text-align: left;"
1561  " border-bottom: 5px solid #DCEB5C;"
1562  "}"
1563  "h4{ background-color: #F6F6F6;"
1564  " color: #93b023;" // from http://qgis.org/en/site/getinvolved/styleguide.html
1565  " font-weight: bold;"
1566  " font-size: medium;"
1567  " text-align: left;"
1568  "}"
1569  "h5{ background-color: #F6F6F6;"
1570  " color: #93b023;" // from http://qgis.org/en/site/getinvolved/styleguide.html
1571  " font-weight: bold;"
1572  " font-size: small;"
1573  " text-align: left;"
1574  "}"
1575  "a{ color: #729FCF;"
1576  " font-family: arial,sans-serif;"
1577  "}"
1578  "label{ background-color: #FFFFCC;"
1579  " border: 1px solid black;"
1580  " margin: 1px;"
1581  " padding: 0px 3px; "
1582  " font-size: small;"
1583  "}"
1584  "th .strong {"
1585  " font-weight: bold;"
1586  "}"
1587  "hr {"
1588  " border: 0;"
1589  " height: 0;"
1590  " border-top: 1px solid black;"
1591  "}"
1592  ".list-view .highlight {"
1593  " text-align: left;"
1594  " border: 0px;"
1595  " width: 20%;"
1596  " padding-right: 15px;"
1597  " padding-left: 20px;"
1598  " font-weight: bold;"
1599  "}"
1600  ".tabular-view .odd-row {"
1601  " background-color: #f9f9f9;"
1602  "}"
1603  ".section {"
1604  " font-weight: bold;"
1605  " padding-top:25px;"
1606  "}" );
1607 
1608  // We have some subtle differences between Qt based style and QWebKit style
1609  switch ( styleSheetType )
1610  {
1611  case StyleSheetType::Qt:
1612  myStyle += QStringLiteral(
1613  ".tabular-view{ "
1614  " border-collapse: collapse;"
1615  " width: 95%;"
1616  "}"
1617  ".tabular-view th, .tabular-view td { "
1618  " border:1px solid black;"
1619  "}" );
1620  break;
1621 
1622  case StyleSheetType::WebBrowser:
1623  myStyle += QStringLiteral(
1624  "body { "
1625  " margin: auto;"
1626  " width: 97%;"
1627  "}"
1628  "table.tabular-view, table.list-view { "
1629  " border-collapse: collapse;"
1630  " table-layout:fixed;"
1631  " width: 100% !important;"
1632  " font-size: 90%;"
1633  "}"
1634  // Override
1635  "h1 { "
1636  " line-height: inherit;"
1637  "}"
1638  "td, th {"
1639  " word-wrap: break-word; "
1640  " vertical-align: top;"
1641  "}"
1642  // Set first column width
1643  ".list-view th:first-child, .list-view td:first-child {"
1644  " width: 20%;"
1645  "}"
1646  ".list-view.highlight { "
1647  " padding-left: inherit; "
1648  "}"
1649  // Set first column width for inner tables
1650  ".tabular-view th:first-child, .tabular-view td:first-child { "
1651  " width: 20%; "
1652  "}"
1653  // Makes titles bg stand up
1654  ".tabular-view th.strong { "
1655  " background-color: #eee; "
1656  "}"
1657  // Give some visual appearance to those ugly nested tables
1658  ".tabular-view th, .tabular-view td { "
1659  " border: 1px solid #eee;"
1660  "}"
1661  );
1662  break;
1663  }
1664 
1665  return myStyle;
1666 }
1667 
1669 {
1670  if ( 0 >= OGRGetDriverCount() )
1671  {
1672  OGRRegisterAll();
1673  }
1674 }
1675 
1676 QString QgsApplication::absolutePathToRelativePath( const QString &aPath, const QString &targetPath )
1677 {
1678  QString aPathUrl = aPath;
1679  QString tPathUrl = targetPath;
1680 #if defined( Q_OS_WIN )
1681  const Qt::CaseSensitivity cs = Qt::CaseInsensitive;
1682 
1683  aPathUrl.replace( '\\', '/' );
1684  if ( aPathUrl.startsWith( "//" ) )
1685  {
1686  // keep UNC prefix
1687  aPathUrl = "\\\\" + aPathUrl.mid( 2 );
1688  }
1689 
1690  tPathUrl.replace( '\\', '/' );
1691  if ( tPathUrl.startsWith( "//" ) )
1692  {
1693  // keep UNC prefix
1694  tPathUrl = "\\\\" + tPathUrl.mid( 2 );
1695  }
1696 #else
1697  const Qt::CaseSensitivity cs = Qt::CaseSensitive;
1698 #endif
1699 
1700 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
1701  QStringList targetElems = tPathUrl.split( '/', QString::SkipEmptyParts );
1702  QStringList aPathElems = aPathUrl.split( '/', QString::SkipEmptyParts );
1703 #else
1704  QStringList targetElems = tPathUrl.split( '/', Qt::SkipEmptyParts );
1705  QStringList aPathElems = aPathUrl.split( '/', Qt::SkipEmptyParts );
1706 #endif
1707 
1708  targetElems.removeAll( QStringLiteral( "." ) );
1709  aPathElems.removeAll( QStringLiteral( "." ) );
1710 
1711  // remove common part
1712  int n = 0;
1713  while ( !aPathElems.isEmpty() &&
1714  !targetElems.isEmpty() &&
1715  aPathElems[0].compare( targetElems[0], cs ) == 0 )
1716  {
1717  aPathElems.removeFirst();
1718  targetElems.removeFirst();
1719  n++;
1720  }
1721 
1722  if ( n == 0 )
1723  {
1724  // no common parts; might not even be a file
1725  return aPathUrl;
1726  }
1727 
1728  if ( !targetElems.isEmpty() )
1729  {
1730  // go up to the common directory
1731  for ( int i = 0; i < targetElems.size(); i++ )
1732  {
1733  aPathElems.insert( 0, QStringLiteral( ".." ) );
1734  }
1735  }
1736  else
1737  {
1738  // let it start with . nevertheless,
1739  // so relative path always start with either ./ or ../
1740  aPathElems.insert( 0, QStringLiteral( "." ) );
1741  }
1742 
1743  return aPathElems.join( QLatin1Char( '/' ) );
1744 }
1745 
1746 QString QgsApplication::relativePathToAbsolutePath( const QString &rpath, const QString &targetPath )
1747 {
1748  // relative path should always start with ./ or ../
1749  if ( !rpath.startsWith( QLatin1String( "./" ) ) && !rpath.startsWith( QLatin1String( "../" ) ) )
1750  {
1751  return rpath;
1752  }
1753 
1754  QString rPathUrl = rpath;
1755  QString targetPathUrl = targetPath;
1756 
1757 #if defined(Q_OS_WIN)
1758  rPathUrl.replace( '\\', '/' );
1759  targetPathUrl.replace( '\\', '/' );
1760 
1761  bool uncPath = targetPathUrl.startsWith( "//" );
1762 #endif
1763 
1764 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
1765  QStringList srcElems = rPathUrl.split( '/', QString::SkipEmptyParts );
1766  QStringList targetElems = targetPathUrl.split( '/', QString::SkipEmptyParts );
1767 #else
1768  QStringList srcElems = rPathUrl.split( '/', Qt::SkipEmptyParts );
1769  QStringList targetElems = targetPathUrl.split( '/', Qt::SkipEmptyParts );
1770 #endif
1771 
1772 #if defined(Q_OS_WIN)
1773  if ( uncPath )
1774  {
1775  targetElems.insert( 0, "" );
1776  targetElems.insert( 0, "" );
1777  }
1778 #endif
1779 
1780  // append source path elements
1781  targetElems << srcElems;
1782  targetElems.removeAll( QStringLiteral( "." ) );
1783 
1784  // resolve ..
1785  int pos;
1786  while ( ( pos = targetElems.indexOf( QLatin1String( ".." ) ) ) > 0 )
1787  {
1788  // remove preceding element and ..
1789  targetElems.removeAt( pos - 1 );
1790  targetElems.removeAt( pos - 1 );
1791  }
1792 
1793 #if !defined(Q_OS_WIN)
1794  // make path absolute
1795  targetElems.prepend( QString() );
1796 #endif
1797 
1798  return targetElems.join( QLatin1Char( '/' ) );
1799 }
1800 
1802 {
1803  return *sBuildSourcePath();
1804 }
1805 
1807 {
1808  return *sBuildOutputPath();
1809 }
1810 
1811 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
1812 QString QgsApplication::cfgIntDir()
1813 {
1814  return *sCfgIntDir();
1815 }
1816 #endif
1817 
1818 void QgsApplication::skipGdalDriver( const QString &driver )
1819 {
1820  if ( sGdalSkipList()->contains( driver ) || driver.isEmpty() )
1821  {
1822  return;
1823  }
1824  *sGdalSkipList() << driver;
1826 }
1827 
1828 void QgsApplication::restoreGdalDriver( const QString &driver )
1829 {
1830  if ( !sGdalSkipList()->contains( driver ) )
1831  {
1832  return;
1833  }
1834  int myPos = sGdalSkipList()->indexOf( driver );
1835  if ( myPos >= 0 )
1836  {
1837  sGdalSkipList()->removeAt( myPos );
1838  }
1840 }
1841 
1843 {
1844  return *sGdalSkipList();
1845 }
1846 
1847 void QgsApplication::setSkippedGdalDrivers( const QStringList &skippedGdalDrivers,
1848  const QStringList &deferredSkippedGdalDrivers )
1849 {
1850  *sGdalSkipList() = skippedGdalDrivers;
1851  *sDeferredSkippedGdalDrivers() = deferredSkippedGdalDrivers;
1852 
1853  QgsSettings settings;
1854  settings.setValue( QStringLiteral( "gdal/skipDrivers" ), skippedGdalDrivers.join( QLatin1Char( ',' ) ) );
1855 
1857 }
1858 
1860 {
1861  QgsSettings settings;
1862  QString joinedList, delimiter;
1863  if ( settings.contains( QStringLiteral( "gdal/skipDrivers" ) ) )
1864  {
1865  joinedList = settings.value( QStringLiteral( "gdal/skipDrivers" ), QString() ).toString();
1866  delimiter = QStringLiteral( "," );
1867  }
1868  else
1869  {
1870  joinedList = settings.value( QStringLiteral( "gdal/skipList" ), QString() ).toString();
1871  delimiter = QStringLiteral( " " );
1872  }
1873  QStringList myList;
1874  if ( !joinedList.isEmpty() )
1875  {
1876  myList = joinedList.split( delimiter );
1877  }
1878  *sGdalSkipList() = myList;
1880 }
1881 
1883 {
1884  return *sDeferredSkippedGdalDrivers();
1885 }
1886 
1888 {
1889  sGdalSkipList()->removeDuplicates();
1890  QStringList realDisabledDriverList;
1891  for ( const auto &driverName : *sGdalSkipList() )
1892  {
1893  if ( !sDeferredSkippedGdalDrivers()->contains( driverName ) )
1894  realDisabledDriverList << driverName;
1895  }
1896  QString myDriverList = realDisabledDriverList.join( ',' );
1897  QgsDebugMsgLevel( QStringLiteral( "Gdal Skipped driver list set to:" ), 2 );
1898  QgsDebugMsgLevel( myDriverList, 2 );
1899  CPLSetConfigOption( "GDAL_SKIP", myDriverList.toUtf8() );
1900  GDALAllRegister(); //to update driver list and skip missing ones
1901 }
1902 
1904 {
1905  QString folder = userThemesFolder();
1906  QDir myDir( folder );
1907  if ( !myDir.exists() )
1908  {
1909  myDir.mkpath( folder );
1910  }
1911 
1912  return true;
1913 }
1914 
1915 void QgsApplication::copyPath( const QString &src, const QString &dst )
1916 {
1917  QDir dir( src );
1918  if ( ! dir.exists() )
1919  return;
1920 
1921  const auto subDirectories = dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot );
1922  for ( const QString &d : subDirectories )
1923  {
1924  QString dst_path = dst + QDir::separator() + d;
1925  dir.mkpath( dst_path );
1926  copyPath( src + QDir::separator() + d, dst_path );
1927  }
1928 
1929  const auto files = dir.entryList( QDir::Files );
1930  for ( const QString &f : files )
1931  {
1932  QFile::copy( src + QDir::separator() + f, dst + QDir::separator() + f );
1933  }
1934 }
1935 
1937 {
1938  //read values from QgsSettings
1939  QgsSettings settings;
1940 
1941  QVariantMap variables;
1942 
1943  //check if settings contains any variables
1944  settings.beginGroup( "variables" );
1945  QStringList childKeys = settings.childKeys();
1946  for ( QStringList::const_iterator it = childKeys.constBegin(); it != childKeys.constEnd(); ++it )
1947  {
1948  QString name = *it;
1949  variables.insert( name, settings.value( name ) );
1950  }
1951 
1952  return variables;
1953 }
1954 
1955 void QgsApplication::setCustomVariables( const QVariantMap &variables )
1956 {
1957  QgsSettings settings;
1958 
1959  QVariantMap::const_iterator it = variables.constBegin();
1960  settings.beginGroup( "variables" );
1961  settings.remove( "" );
1962  for ( ; it != variables.constEnd(); ++it )
1963  {
1964  settings.setValue( it.key(), it.value() );
1965  }
1966 
1967  emit instance()->customVariablesChanged();
1968 }
1969 
1970 void QgsApplication::setCustomVariable( const QString &name, const QVariant &value )
1971 {
1972  // save variable to settings
1973  QgsSettings settings;
1974 
1975  settings.setValue( QStringLiteral( "variables/" ) + name, value );
1976 
1977  emit instance()->customVariablesChanged();
1978 }
1979 
1980 int QgsApplication::scaleIconSize( int standardSize, bool applyDevicePixelRatio )
1981 {
1982  QFontMetrics fm( ( QFont() ) );
1983  const double scale = 1.1 * standardSize / 24;
1984  int scaledIconSize = static_cast< int >( std::floor( std::max( Qgis::UI_SCALE_FACTOR * fm.height() * scale, static_cast< double >( standardSize ) ) ) );
1985 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
1986  if ( applyDevicePixelRatio && QApplication::desktop() )
1987  scaledIconSize *= QApplication::desktop()->devicePixelRatio();
1988 #else
1989  if ( applyDevicePixelRatio )
1990  {
1991  if ( QWidget *activeWindow = QApplication::activeWindow() )
1992  scaledIconSize *= ( activeWindow->screen() ? QApplication::activeWindow()->screen()->devicePixelRatio() : 1 );
1993  }
1994 #endif
1995  return scaledIconSize;
1996 }
1997 
1999 {
2001 }
2002 
2003 void QgsApplication::setTranslation( const QString &translation )
2004 {
2005  *sTranslation() = translation;
2006 }
2007 
2009 {
2010  return *sTranslation();
2011 }
2012 
2014 {
2015  emit requestForTranslatableObjects( translationContext );
2016 }
2017 
2019 {
2020  ApplicationMembers *appMembers = members();
2021  if ( appMembers->mNullRepresentation.isNull() )
2022  {
2023  appMembers->mNullRepresentation = QgsSettings().value( QStringLiteral( "qgis/nullValue" ), QStringLiteral( "NULL" ) ).toString();
2024  }
2025  return appMembers->mNullRepresentation;
2026 }
2027 
2028 void QgsApplication::setNullRepresentation( const QString &nullRepresentation )
2029 {
2030  ApplicationMembers *appMembers = members();
2031  if ( !appMembers || appMembers->mNullRepresentation == nullRepresentation )
2032  return;
2033 
2034  appMembers->mNullRepresentation = nullRepresentation;
2035  QgsSettings().setValue( QStringLiteral( "qgis/nullValue" ), nullRepresentation );
2036 
2037  QgsApplication *app = instance();
2038  if ( app )
2039  emit app->nullRepresentationChanged();
2040 }
2041 
2043 {
2044  return members()->mActionScopeRegistry;
2045 }
2046 
2047 bool QgsApplication::createDatabase( QString *errorMessage )
2048 {
2049  // set a working directory up for gdal to write .aux.xml files into
2050  // for cases where the raster dir is read only to the user
2051  // if the env var is already set it will be used preferentially
2052  QString myPamPath = qgisSettingsDirPath() + QStringLiteral( "gdal_pam/" );
2053  QDir myDir( myPamPath );
2054  if ( !myDir.exists() )
2055  {
2056  myDir.mkpath( myPamPath ); //fail silently
2057  }
2058 
2059 #if defined(Q_OS_WIN)
2060  CPLSetConfigOption( "GDAL_PAM_PROXY_DIR", myPamPath.toUtf8() );
2061 #else
2062  //under other OS's we use an environment var so the user can
2063  //override the path if he likes
2064  int myChangeFlag = 0; //whether we want to force the env var to change
2065  setenv( "GDAL_PAM_PROXY_DIR", myPamPath.toUtf8(), myChangeFlag );
2066 #endif
2067 
2068  // Check qgis.db and make private copy if necessary
2069  QFile qgisPrivateDbFile( QgsApplication::qgisUserDatabaseFilePath() );
2070 
2071  // first we look for ~/.qgis/qgis.db
2072  if ( !qgisPrivateDbFile.exists() )
2073  {
2074  // if it doesn't exist we copy it in from the global resources dir
2075  QString qgisMasterDbFileName = QgsApplication::qgisMasterDatabaseFilePath();
2076  QFile masterFile( qgisMasterDbFileName );
2077 
2078  // Must be sure there is destination directory ~/.qgis
2079  QDir().mkpath( QgsApplication::qgisSettingsDirPath() );
2080 
2081  //now copy the master file into the users .qgis dir
2082  bool isDbFileCopied = masterFile.copy( qgisPrivateDbFile.fileName() );
2083 
2084  if ( !isDbFileCopied )
2085  {
2086  if ( errorMessage )
2087  {
2088  *errorMessage = tr( "[ERROR] Can not make qgis.db private copy" );
2089  }
2090  return false;
2091  }
2092 
2093  QFile::Permissions perms = QFile( qgisPrivateDbFile.fileName() ).permissions();
2094  if ( !( perms & QFile::WriteOwner ) )
2095  {
2096  if ( !qgisPrivateDbFile.setPermissions( perms | QFile::WriteOwner ) )
2097  {
2098  if ( errorMessage )
2099  {
2100  *errorMessage = tr( "Can not make '%1' user writable" ).arg( qgisPrivateDbFile.fileName() );
2101  }
2102  return false;
2103  }
2104  }
2105  }
2106  else
2107  {
2108  // migrate if necessary
2109  sqlite3_database_unique_ptr database;
2110  if ( database.open( QgsApplication::qgisUserDatabaseFilePath() ) != SQLITE_OK )
2111  {
2112  if ( errorMessage )
2113  {
2114  *errorMessage = tr( "Could not open qgis.db" );
2115  }
2116  return false;
2117  }
2118 
2119  char *errmsg = nullptr;
2120  int res = sqlite3_exec( database.get(), "SELECT srs_id FROM tbl_srs LIMIT 0", nullptr, nullptr, &errmsg );
2121  if ( res != SQLITE_OK )
2122  {
2123  sqlite3_free( errmsg );
2124 
2125  // qgis.db is missing tbl_srs, create it
2126  if ( sqlite3_exec( database.get(),
2127  "DROP INDEX IF EXISTS idx_srsauthid;"
2128  "CREATE TABLE tbl_srs ("
2129  "srs_id INTEGER PRIMARY KEY,"
2130  "description text NOT NULL,"
2131  "projection_acronym text NOT NULL,"
2132  "ellipsoid_acronym NOT NULL,"
2133  "parameters text NOT NULL,"
2134  "srid integer,"
2135  "auth_name varchar,"
2136  "auth_id varchar,"
2137  "is_geo integer NOT NULL,"
2138  "deprecated boolean,"
2139  "wkt text);"
2140  "CREATE INDEX idx_srsauthid on tbl_srs(auth_name,auth_id);", nullptr, nullptr, &errmsg ) != SQLITE_OK )
2141  {
2142  if ( errorMessage )
2143  {
2144  *errorMessage = tr( "Creation of missing tbl_srs in the private qgis.db failed.\n%1" ).arg( QString::fromUtf8( errmsg ) );
2145  }
2146  sqlite3_free( errmsg );
2147  return false;
2148  }
2149  }
2150  else
2151  {
2152  // test if wkt column exists in database
2153  res = sqlite3_exec( database.get(), "SELECT wkt FROM tbl_srs LIMIT 0", nullptr, nullptr, &errmsg );
2154  if ( res != SQLITE_OK )
2155  {
2156  // need to add wkt column
2157  sqlite3_free( errmsg );
2158  if ( sqlite3_exec( database.get(),
2159  "DROP INDEX IF EXISTS idx_srsauthid;"
2160  "DROP TABLE IF EXISTS tbl_srs_bak;"
2161  "ALTER TABLE tbl_srs RENAME TO tbl_srs_bak;"
2162  "CREATE TABLE tbl_srs ("
2163  "srs_id INTEGER PRIMARY KEY,"
2164  "description text NOT NULL,"
2165  "projection_acronym text NOT NULL,"
2166  "ellipsoid_acronym NOT NULL,"
2167  "parameters text NOT NULL,"
2168  "srid integer,"
2169  "auth_name varchar,"
2170  "auth_id varchar,"
2171  "is_geo integer NOT NULL,"
2172  "deprecated boolean,"
2173  "wkt text);"
2174  "CREATE INDEX idx_srsauthid on tbl_srs(auth_name,auth_id);"
2175  "INSERT INTO tbl_srs(srs_id,description,projection_acronym,ellipsoid_acronym,parameters,srid,auth_name,auth_id,is_geo,deprecated) SELECT srs_id,description,projection_acronym,ellipsoid_acronym,parameters,srid,'','',is_geo,0 FROM tbl_srs_bak;"
2176  "DROP TABLE tbl_srs_bak", nullptr, nullptr, &errmsg ) != SQLITE_OK )
2177  {
2178  if ( errorMessage )
2179  {
2180  *errorMessage = tr( "Migration of private qgis.db failed.\n%1" ).arg( QString::fromUtf8( errmsg ) );
2181  }
2182  sqlite3_free( errmsg );
2183  return false;
2184  }
2185  }
2186  }
2187 
2188  res = sqlite3_exec( database.get(), "SELECT acronym FROM tbl_projection LIMIT 0", nullptr, nullptr, &errmsg );
2189  if ( res != SQLITE_OK )
2190  {
2191  sqlite3_free( errmsg );
2192 
2193  // qgis.db is missing tbl_projection, create it
2194  if ( sqlite3_exec( database.get(),
2195  "CREATE TABLE tbl_projection ("
2196  "acronym varchar(20) NOT NULL PRIMARY KEY,"
2197  "name varchar(255) NOT NULL default '',"
2198  "notes varchar(255) NOT NULL default '',"
2199  "parameters varchar(255) NOT NULL default ''"
2200  ")", nullptr, nullptr, &errmsg ) != SQLITE_OK )
2201  {
2202  if ( errorMessage )
2203  {
2204  *errorMessage = tr( "Creation of missing tbl_projection in the private qgis.db failed.\n%1" ).arg( QString::fromUtf8( errmsg ) );
2205  }
2206  sqlite3_free( errmsg );
2207  return false;
2208  }
2209  }
2210 
2211  res = sqlite3_exec( database.get(), "SELECT epsg FROM tbl_srs LIMIT 0", nullptr, nullptr, &errmsg );
2212  if ( res == SQLITE_OK )
2213  {
2214  // epsg column exists => need migration
2215  if ( sqlite3_exec( database.get(),
2216  "DROP INDEX IF EXISTS idx_srsauthid;"
2217  "DROP TABLE IF EXISTS tbl_srs_bak;"
2218  "ALTER TABLE tbl_srs RENAME TO tbl_srs_bak;"
2219  "CREATE TABLE tbl_srs ("
2220  "srs_id INTEGER PRIMARY KEY,"
2221  "description text NOT NULL,"
2222  "projection_acronym text NOT NULL,"
2223  "ellipsoid_acronym NOT NULL,"
2224  "parameters text NOT NULL,"
2225  "srid integer,"
2226  "auth_name varchar,"
2227  "auth_id varchar,"
2228  "is_geo integer NOT NULL,"
2229  "deprecated boolean,"
2230  "wkt text);"
2231  "CREATE INDEX idx_srsauthid on tbl_srs(auth_name,auth_id);"
2232  "INSERT INTO tbl_srs(srs_id,description,projection_acronym,ellipsoid_acronym,parameters,srid,auth_name,auth_id,is_geo,deprecated) SELECT srs_id,description,projection_acronym,ellipsoid_acronym,parameters,srid,'','',is_geo,0 FROM tbl_srs_bak;"
2233  "DROP TABLE tbl_srs_bak", nullptr, nullptr, &errmsg ) != SQLITE_OK )
2234  {
2235  if ( errorMessage )
2236  {
2237  *errorMessage = tr( "Migration of private qgis.db failed.\n%1" ).arg( QString::fromUtf8( errmsg ) );
2238  }
2239  sqlite3_free( errmsg );
2240  return false;
2241  }
2242  }
2243  else
2244  {
2245  sqlite3_free( errmsg );
2246  }
2247 
2248  if ( sqlite3_exec( database.get(), "DROP VIEW vw_srs", nullptr, nullptr, &errmsg ) != SQLITE_OK )
2249  {
2250  QgsDebugMsg( QStringLiteral( "vw_srs didn't exists in private qgis.db: %1" ).arg( errmsg ) );
2251  }
2252 
2253  if ( sqlite3_exec( database.get(),
2254  "CREATE VIEW vw_srs AS"
2255  " SELECT"
2256  " a.description AS description"
2257  ",a.srs_id AS srs_id"
2258  ",a.is_geo AS is_geo"
2259  ",coalesce(b.name,a.projection_acronym) AS name"
2260  ",a.parameters AS parameters"
2261  ",a.auth_name AS auth_name"
2262  ",a.auth_id AS auth_id"
2263  ",a.deprecated AS deprecated"
2264  " FROM tbl_srs a"
2265  " LEFT OUTER JOIN tbl_projection b ON a.projection_acronym=b.acronym"
2266  " ORDER BY coalesce(b.name,a.projection_acronym),a.description", nullptr, nullptr, &errmsg ) != SQLITE_OK )
2267  {
2268  if ( errorMessage )
2269  {
2270  *errorMessage = tr( "Update of view in private qgis.db failed.\n%1" ).arg( QString::fromUtf8( errmsg ) );
2271  }
2272  sqlite3_free( errmsg );
2273  return false;
2274  }
2275  }
2276  return true;
2277 }
2278 
2279 void QgsApplication::setMaxThreads( int maxThreads )
2280 {
2281  QgsDebugMsgLevel( QStringLiteral( "maxThreads: %1" ).arg( maxThreads ), 2 );
2282 
2283  // make sure value is between 1 and #cores, if not set to -1 (use #cores)
2284  // 0 could be used to disable any parallel processing
2285  if ( maxThreads < 1 || maxThreads > QThread::idealThreadCount() )
2286  maxThreads = -1;
2287 
2288  // save value
2289  ABISYM( sMaxThreads ) = maxThreads;
2290 
2291  // if -1 use #cores
2292  if ( maxThreads == -1 )
2293  maxThreads = QThread::idealThreadCount();
2294 
2295  // set max thread count in QThreadPool
2296  QThreadPool::globalInstance()->setMaxThreadCount( maxThreads );
2297  QgsDebugMsgLevel( QStringLiteral( "set QThreadPool max thread count to %1" ).arg( QThreadPool::globalInstance()->maxThreadCount() ), 2 );
2298 }
2299 
2301 {
2302  return members()->mTaskManager;
2303 }
2304 
2306 {
2307  return members()->mSettingsRegistryCore;
2308 }
2309 
2311 {
2312  return members()->mColorSchemeRegistry;
2313 }
2314 
2316 {
2317  return members()->mPaintEffectRegistry;
2318 }
2319 
2321 {
2322  return members()->mRendererRegistry;
2323 }
2324 
2326 {
2327  return members()->mRasterRendererRegistry;
2328 }
2329 
2331 {
2332  return members()->mPointCloudRendererRegistry;
2333 }
2334 
2336 {
2337  if ( auto *lInstance = instance() )
2338  {
2339  if ( !instance()->mDataItemProviderRegistry )
2340  {
2341  lInstance->mDataItemProviderRegistry = new QgsDataItemProviderRegistry();
2342  }
2343  return lInstance->mDataItemProviderRegistry;
2344  }
2345  else
2346  {
2347  // no QgsApplication instance
2348  static QgsDataItemProviderRegistry *sDataItemProviderRegistry = nullptr;
2349  if ( !sDataItemProviderRegistry )
2350  sDataItemProviderRegistry = new QgsDataItemProviderRegistry();
2351  return sDataItemProviderRegistry;
2352  }
2353 }
2354 
2356 {
2357  return members()->mCrsRegistry;
2358 }
2359 
2361 {
2362  return members()->mSvgCache;
2363 }
2364 
2366 {
2367  return members()->mImageCache;
2368 }
2369 
2371 {
2372  return members()->mSourceCache;
2373 }
2374 
2376 {
2377  return members()->mNetworkContentFetcherRegistry;
2378 }
2379 
2381 {
2382  return members()->mValidityCheckRegistry;
2383 }
2384 
2386 {
2387  return members()->mSymbolLayerRegistry;
2388 }
2389 
2391 {
2392  return members()->mCalloutRegistry;
2393 }
2394 
2396 {
2397  return members()->mLayoutItemRegistry;
2398 }
2399 
2401 {
2402  return members()->mAnnotationItemRegistry;
2403 }
2404 
2406 {
2407  return members()->mGpsConnectionRegistry;
2408 }
2409 
2411 {
2412  return members()->mGpsBabelFormatRegistry;
2413 }
2414 
2416 {
2417  return members()->mPluginLayerRegistry;
2418 }
2419 
2421 {
2422  return members()->mClassificationMethodRegistry;
2423 }
2424 
2426 {
2427  return members()->mBookmarkManager;
2428 }
2429 
2431 {
2432  return members()->mTileDownloadManager;
2433 }
2434 
2436 {
2437  return members()->mRecentStyleHandler;
2438 }
2439 
2441 {
2442  return members()->mQueryLogger;
2443 }
2444 
2446 {
2447  return members()->mStyleModel;
2448 }
2449 
2451 {
2452  return members()->mMessageLog;
2453 }
2454 
2456 {
2457  return members()->mProcessingRegistry;
2458 }
2459 
2461 {
2462  return members()->mConnectionRegistry;
2463 }
2464 
2466 {
2467  return members()->mPageSizeRegistry;
2468 }
2469 
2470 QgsAnnotationRegistry *QgsApplication::annotationRegistry()
2471 {
2472  return members()->mAnnotationRegistry;
2473 }
2474 
2476 {
2477  return members()->mNumericFormatRegistry;
2478 }
2479 
2481 {
2482  return members()->mFieldFormatterRegistry;
2483 }
2484 
2486 {
2487  return members()->m3DRendererRegistry;
2488 }
2489 
2491 {
2492  return members()->m3DSymbolRegistry;
2493 }
2494 
2496 {
2497  return members()->mScaleBarRendererRegistry;
2498 }
2499 
2501 {
2502  return members()->mProjectStorageRegistry.get();
2503 }
2504 
2506 {
2507  return members()->mExternalStorageRegistry;
2508 }
2509 
2511 {
2512  return members()->mLocalizedDataPathRegistry;
2513 }
2514 
2515 QgsApplication::ApplicationMembers::ApplicationMembers()
2516 {
2517  // don't use initializer lists or scoped pointers - as more objects are added here we
2518  // will need to be careful with the order of creation/destruction
2519  mSettingsRegistryCore = new QgsSettingsRegistryCore();
2520  mLocalizedDataPathRegistry = new QgsLocalizedDataPathRegistry();
2521  mMessageLog = new QgsMessageLog();
2522  QgsRuntimeProfiler *profiler = QgsRuntimeProfiler::threadLocalInstance();
2523 
2524  {
2525  profiler->start( tr( "Create query logger" ) );
2526  mQueryLogger = new QgsDatabaseQueryLog();
2527  profiler->end();
2528  }
2529  {
2530  profiler->start( tr( "Setup coordinate reference system registry" ) );
2531  mCrsRegistry = new QgsCoordinateReferenceSystemRegistry();
2532  profiler->end();
2533  }
2534  {
2535  profiler->start( tr( "Create connection registry" ) );
2536  mConnectionRegistry = new QgsConnectionRegistry();
2537  profiler->end();
2538  }
2539  {
2540  profiler->start( tr( "Setup task manager" ) );
2541  mTaskManager = new QgsTaskManager();
2542  profiler->end();
2543  }
2544  {
2545  profiler->start( tr( "Setup action scope registry" ) );
2546  mActionScopeRegistry = new QgsActionScopeRegistry();
2547  profiler->end();
2548  }
2549  {
2550  profiler->start( tr( "Setup numeric formats" ) );
2551  mNumericFormatRegistry = new QgsNumericFormatRegistry();
2552  profiler->end();
2553  }
2554  {
2555  profiler->start( tr( "Setup field formats" ) );
2556  mFieldFormatterRegistry = new QgsFieldFormatterRegistry();
2557  profiler->end();
2558  }
2559  {
2560  profiler->start( tr( "Setup SVG cache" ) );
2561  mSvgCache = new QgsSvgCache();
2562  profiler->end();
2563  }
2564  {
2565  profiler->start( tr( "Setup image cache" ) );
2566  mImageCache = new QgsImageCache();
2567  profiler->end();
2568  }
2569  {
2570  profiler->start( tr( "Setup source cache" ) );
2571  mSourceCache = new QgsSourceCache();
2572  profiler->end();
2573  }
2574  {
2575  profiler->start( tr( "Setup color scheme registry" ) );
2576  mColorSchemeRegistry = new QgsColorSchemeRegistry();
2577  profiler->end();
2578  }
2579  {
2580  profiler->start( tr( "Setup paint effect" ) );
2581  mPaintEffectRegistry = new QgsPaintEffectRegistry();
2582  profiler->end();
2583  }
2584  {
2585  profiler->start( tr( "Setup symbol layer registry" ) );
2586  mSymbolLayerRegistry = new QgsSymbolLayerRegistry();
2587  profiler->end();
2588  }
2589  {
2590  profiler->start( tr( "Recent style handler" ) );
2591  mRecentStyleHandler = new QgsRecentStyleHandler();
2592  profiler->end();
2593  }
2594  {
2595  profiler->start( tr( "Setup callout registry" ) );
2596  mCalloutRegistry = new QgsCalloutRegistry();
2597  profiler->end();
2598  }
2599  {
2600  profiler->start( tr( "Setup renderer registry" ) );
2601  mRendererRegistry = new QgsRendererRegistry();
2602  profiler->end();
2603  }
2604  {
2605  profiler->start( tr( "Setup raster renderer registry" ) );
2606  mRasterRendererRegistry = new QgsRasterRendererRegistry();
2607  profiler->end();
2608  }
2609  {
2610  profiler->start( tr( "Setup point cloud renderer registry" ) );
2611  mPointCloudRendererRegistry = new QgsPointCloudRendererRegistry();
2612  profiler->end();
2613  }
2614  {
2615  profiler->start( tr( "Setup GPS registry" ) );
2616  mGpsConnectionRegistry = new QgsGpsConnectionRegistry();
2617  profiler->end();
2618  }
2619  {
2620  profiler->start( tr( "Setup GPSBabel format registry" ) );
2621  mGpsBabelFormatRegistry = new QgsBabelFormatRegistry();
2622  profiler->end();
2623  }
2624  {
2625  profiler->start( tr( "Setup plugin layer registry" ) );
2626  mPluginLayerRegistry = new QgsPluginLayerRegistry();
2627  profiler->end();
2628  }
2629  {
2630  profiler->start( tr( "Setup Processing registry" ) );
2631  mProcessingRegistry = new QgsProcessingRegistry();
2632  profiler->end();
2633  }
2634  mPageSizeRegistry = new QgsPageSizeRegistry();
2635  {
2636  profiler->start( tr( "Setup layout item registry" ) );
2637  mLayoutItemRegistry = new QgsLayoutItemRegistry();
2638  mLayoutItemRegistry->populate();
2639  profiler->end();
2640  }
2641  {
2642  profiler->start( tr( "Setup annotation registry" ) );
2643  mAnnotationRegistry = new QgsAnnotationRegistry();
2644  profiler->end();
2645  }
2646  {
2647  profiler->start( tr( "Setup annotation item registry" ) );
2648  mAnnotationItemRegistry = new QgsAnnotationItemRegistry();
2649  mAnnotationItemRegistry->populate();
2650  profiler->end();
2651  }
2652  {
2653  profiler->start( tr( "Setup 3D symbol registry" ) );
2654  m3DSymbolRegistry = new Qgs3DSymbolRegistry();
2655  profiler->end();
2656  }
2657  {
2658  profiler->start( tr( "Setup 3D renderer registry" ) );
2659  m3DRendererRegistry = new Qgs3DRendererRegistry();
2660  profiler->end();
2661  }
2662  {
2663  profiler->start( tr( "Setup project storage registry" ) );
2664  mProjectStorageRegistry.reset( new QgsProjectStorageRegistry() );
2665  profiler->end();
2666  }
2667  {
2668  profiler->start( tr( "Setup external storage registry" ) );
2669  mExternalStorageRegistry = new QgsExternalStorageRegistry();
2670  profiler->end();
2671  }
2672  {
2673  profiler->start( tr( "Setup network content cache" ) );
2674  mNetworkContentFetcherRegistry = new QgsNetworkContentFetcherRegistry();
2675  profiler->end();
2676  }
2677  {
2678  profiler->start( tr( "Setup layout check registry" ) );
2679  mValidityCheckRegistry = new QgsValidityCheckRegistry();
2680  profiler->end();
2681  }
2682  {
2683  profiler->start( tr( "Setup classification registry" ) );
2684  mClassificationMethodRegistry = new QgsClassificationMethodRegistry();
2685  profiler->end();
2686  }
2687  {
2688  profiler->start( tr( "Setup bookmark manager" ) );
2689  mBookmarkManager = new QgsBookmarkManager( nullptr );
2690  profiler->end();
2691  }
2692  {
2693  profiler->start( tr( "Setup tile download manager" ) );
2694  mTileDownloadManager = new QgsTileDownloadManager();
2695  profiler->end();
2696  }
2697  {
2698  profiler->start( tr( "Setup scalebar registry" ) );
2699  mScaleBarRendererRegistry = new QgsScaleBarRendererRegistry();
2700  profiler->end();
2701  }
2702 }
2703 
2704 QgsApplication::ApplicationMembers::~ApplicationMembers()
2705 {
2706  delete mStyleModel;
2707  delete mTileDownloadManager;
2708  delete mScaleBarRendererRegistry;
2709  delete mValidityCheckRegistry;
2710  delete mActionScopeRegistry;
2711  delete m3DRendererRegistry;
2712  delete m3DSymbolRegistry;
2713  delete mAnnotationRegistry;
2714  delete mColorSchemeRegistry;
2715  delete mFieldFormatterRegistry;
2716  delete mGpsConnectionRegistry;
2717  delete mGpsBabelFormatRegistry;
2718  delete mMessageLog;
2719  delete mPaintEffectRegistry;
2720  delete mPluginLayerRegistry;
2721  delete mProcessingRegistry;
2722  delete mPageSizeRegistry;
2723  delete mAnnotationItemRegistry;
2724  delete mLayoutItemRegistry;
2725  delete mPointCloudRendererRegistry;
2726  delete mRasterRendererRegistry;
2727  delete mRendererRegistry;
2728  delete mSvgCache;
2729  delete mImageCache;
2730  delete mSourceCache;
2731  delete mCalloutRegistry;
2732  delete mRecentStyleHandler;
2733  delete mSymbolLayerRegistry;
2734  delete mExternalStorageRegistry;
2735  delete mTaskManager;
2736  delete mNetworkContentFetcherRegistry;
2737  delete mClassificationMethodRegistry;
2738  delete mNumericFormatRegistry;
2739  delete mBookmarkManager;
2740  delete mConnectionRegistry;
2741  delete mLocalizedDataPathRegistry;
2742  delete mCrsRegistry;
2743  delete mQueryLogger;
2744  delete mSettingsRegistryCore;
2745 }
2746 
2747 QgsApplication::ApplicationMembers *QgsApplication::members()
2748 {
2749  if ( auto *lInstance = instance() )
2750  {
2751  return lInstance->mApplicationMembers;
2752  }
2753  else
2754  {
2755 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
2756  static QMutex sMemberMutex( QMutex::Recursive );
2757 #else
2758  static QRecursiveMutex sMemberMutex;
2759 #endif
2760  QMutexLocker lock( &sMemberMutex );
2761  if ( !sApplicationMembers )
2762  sApplicationMembers = new ApplicationMembers();
2763  return sApplicationMembers;
2764  }
2765 }
qgssourcecache.h
QgsApplication::QGIS_ORGANIZATION_NAME
static const char * QGIS_ORGANIZATION_NAME
Definition: qgsapplication.h:160
QgsReadWriteLocker::changeMode
void changeMode(Mode mode)
Change the mode of the lock to mode.
Definition: qgsreadwritelocker.cpp:30
QgsApplication::setPkgDataPath
static void setPkgDataPath(const QString &pkgDataPath)
Alters pkg data path - used by 3rd party apps.
Definition: qgsapplication.cpp:597
QgsConnectionRegistry
A registry for saved data provider connections, allowing retrieval of saved connections by name and p...
Definition: qgsconnectionregistry.h:38
QgsApplication::rasterRendererRegistry
static QgsRasterRendererRegistry * rasterRendererRegistry()
Returns the application's raster renderer registry, used for managing raster layer renderers.
Definition: qgsapplication.cpp:2325
QgsApplication::osName
static QString osName()
Returns a string name of the operating system QGIS is running on.
Definition: qgsapplication.cpp:1280
QgsGpsConnectionRegistry
A class to register / unregister existing GPS connections such that the information is available to a...
Definition: qgsgpsconnectionregistry.h:36
qgsreadwritelocker.h
QgsApplication::processingRegistry
static QgsProcessingRegistry * processingRegistry()
Returns the application's processing registry, used for managing processing providers,...
Definition: qgsapplication.cpp:2455
QgsReadWriteLocker::Read
@ Read
Lock for read.
Definition: qgsreadwritelocker.h:75
qgsscalebarrendererregistry.h
QgsSettings::childKeys
QStringList childKeys() const
Returns a list of all top-level keys that can be read using the QSettings object.
Definition: qgssettings.cpp:125
qgssettingsregistrycore.h
QgsApplication::rendererRegistry
static QgsRendererRegistry * rendererRegistry()
Returns the application's renderer registry, used for managing vector layer renderers.
Definition: qgsapplication.cpp:2320
qgssvgcache.h
QgsApplication::Cursor
Cursor
The Cursor enum defines constants for QGIS custom cursors.
Definition: qgsapplication.h:399
qgsnumericformatregistry.h
QgsApplication::setMaxThreads
static void setMaxThreads(int maxThreads)
Set maximum concurrent thread count.
Definition: qgsapplication.cpp:2279
QgsSettings::remove
void remove(const QString &key, QgsSettings::Section section=QgsSettings::NoSection)
Removes the setting key and any sub-settings of key in a section.
Definition: qgssettings.cpp:192
QgsException
Defines a QGIS exception class.
Definition: qgsexception.h:34
sqlite3_database_unique_ptr::open
int open(const QString &path)
Opens the database at the specified file path.
Definition: qgssqliteutils.cpp:78
Q_GLOBAL_STATIC_WITH_ARGS
Q_GLOBAL_STATIC_WITH_ARGS(PalPropertyList, palHiddenProperties,({ QgsPalLayerSettings::PositionX, QgsPalLayerSettings::PositionY, QgsPalLayerSettings::Show, QgsPalLayerSettings::LabelRotation, QgsPalLayerSettings::Family, QgsPalLayerSettings::FontStyle, QgsPalLayerSettings::Size, QgsPalLayerSettings::Bold, QgsPalLayerSettings::Italic, QgsPalLayerSettings::Underline, QgsPalLayerSettings::Color, QgsPalLayerSettings::Strikeout, QgsPalLayerSettings::MultiLineAlignment, QgsPalLayerSettings::BufferSize, QgsPalLayerSettings::BufferDraw, QgsPalLayerSettings::BufferColor, QgsPalLayerSettings::LabelDistance, QgsPalLayerSettings::Hali, QgsPalLayerSettings::Vali, QgsPalLayerSettings::ScaleVisibility, QgsPalLayerSettings::MinScale, QgsPalLayerSettings::MaxScale, QgsPalLayerSettings::AlwaysShow, QgsPalLayerSettings::CalloutDraw, QgsPalLayerSettings::LabelAllParts })) QgsAuxiliaryLayer
Definition: qgsauxiliarystorage.cpp:34
QgsApplication::libraryPath
static QString libraryPath()
Returns the path containing qgis_core, qgis_gui, qgispython (and other) libraries.
Definition: qgsapplication.cpp:1389
qgsruntimeprofiler.h
QgsApplication::~QgsApplication
~QgsApplication() override
Definition: qgsapplication.cpp:454
QgsApplication::pageSizeRegistry
static QgsPageSizeRegistry * pageSizeRegistry()
Returns the application's page size registry, used for managing layout page sizes.
Definition: qgsapplication.cpp:2465
QgsRuntimeProfiler
Provides a method of recording run time profiles of operations, allowing easy recording of their over...
Definition: qgsruntimeprofiler.h:173
QgsStyleModel
A QAbstractItemModel subclass for showing symbol and color ramp entities contained within a QgsStyle ...
Definition: qgsstylemodel.h:107
QgsApplication::CrossHair
@ CrossHair
Precisely identify a point on the canvas.
Definition: qgsapplication.h:404
QgsApplication::buildOutputPath
static QString buildOutputPath()
Returns path to the build output directory. Valid only when running from build directory.
Definition: qgsapplication.cpp:1806
QgsApplication::recentStyleHandler
static QgsRecentStyleHandler * recentStyleHandler()
Returns the handler for recently used style items.
Definition: qgsapplication.cpp:2435
qgsdataitemproviderregistry.h
QgsApplication::maxThreads
static int maxThreads()
Gets maximum concurrent thread count.
Definition: qgsapplication.cpp:677
QgsSettings::value
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
Definition: qgssettings.cpp:161
QgsNumericFormatRegistry
The QgsNumericFormatRegistry manages registered classes of QgsNumericFormat.
Definition: qgsnumericformatregistry.h:38
QgsTileDownloadManager
Tile download manager handles downloads of map tiles for the purpose of map rendering....
Definition: qgstiledownloadmanager.h:202
QgsRuntimeProfiler::end
void end(const QString &group="startup")
End the current profile event.
Definition: qgsruntimeprofiler.cpp:238
qgslocalizeddatapathregistry.h
QgsApplication::nullRepresentationChanged
void nullRepresentationChanged()
This string is used to represent the value NULL throughout QGIS.
QgsDebugMsgLevel
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
QgsUserProfile::folder
const QString folder() const
The base folder for the user profile.
Definition: qgsuserprofile.cpp:30
qgstaskmanager.h
qgstiledownloadmanager.h
qgspluginlayerregistry.h
qgsexpression.h
qgsauthmanager.h
QgsAuthManager::instance
static QgsAuthManager * instance()
Enforce singleton pattern.
Definition: qgsauthmanager.cpp:92
QgsApplication::tileDownloadManager
static QgsTileDownloadManager * tileDownloadManager()
Returns the application's tile download manager, used for download of map tiles when rendering.
Definition: qgsapplication.cpp:2430
QgsApplication::authorsFilePath
static QString authorsFilePath()
Returns the path to the authors file.
Definition: qgsapplication.cpp:1047
QgsApplication::Sampler
@ Sampler
Color/Value picker.
Definition: qgsapplication.h:407
qgsconnectionregistry.h
QgsApplication::annotationRegistry
static QgsAnnotationRegistry * annotationRegistry()
Returns the application's annotation registry, used for managing annotation types.
Definition: qgsapplication.cpp:2470
QgsApplication::pointCloudRendererRegistry
static QgsPointCloudRendererRegistry * pointCloudRendererRegistry()
Returns the application's point cloud renderer registry, used for managing point cloud layer 2D rende...
Definition: qgsapplication.cpp:2330
QgsApplication::notify
bool notify(QObject *receiver, QEvent *event) override
Catch exceptions when sending event to receiver.
Definition: qgsapplication.cpp:511
QgsApplication::i18nPath
static QString i18nPath()
Returns the path to the translation directory.
Definition: qgsapplication.cpp:1081
QgsApplication::connectionRegistry
static QgsConnectionRegistry * connectionRegistry()
Returns the application's connection registry, used for managing saved data provider connections.
Definition: qgsapplication.cpp:2460
QgsApplication::createThemeFolder
static bool createThemeFolder()
Create the users theme folder.
Definition: qgsapplication.cpp:1903
QgsApplication::getThemeCursor
static QCursor getThemeCursor(Cursor cursor)
Helper to get a theme cursor.
Definition: qgsapplication.cpp:762
QgsSvgCache::svgContent
QByteArray svgContent(const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth, double widthScaleFactor, double fixedAspectRatio=0, bool blocking=false, const QMap< QString, QString > &parameters=QMap< QString, QString >(), bool *isMissingImage=nullptr)
Gets the SVG content corresponding to the given path.
Definition: qgssvgcache.cpp:209
qgsuserprofile.h
QgsApplication::setCustomVariables
static void setCustomVariables(const QVariantMap &customVariables)
Custom expression variables for this application.
Definition: qgsapplication.cpp:1955
qgssymbollayerutils.h
QgsApplication::prefixPath
static QString prefixPath()
Returns the path to the application prefix directory.
Definition: qgsapplication.cpp:622
qgsprojectstorageregistry.h
QgsUserProfileManager::resolveProfilesFolder
static QString resolveProfilesFolder(const QString &basePath=QString())
Resolves the profiles folder for the given path.
Definition: qgsuserprofilemanager.cpp:35
QgsDataItemProviderRegistry
This class keeps a list of data item providers that may add items to the browser tree....
Definition: qgsdataitemproviderregistry.h:39
QgsMessageLogNotifyBlocker
Temporarily blocks the application QgsMessageLog (see QgsApplication::messageLog()) from emitting the...
Definition: qgsmessagelog.h:104
QgsApplication::shortNameRegularExpression
static QRegularExpression shortNameRegularExpression()
Returns the short name regular expression for line edit validator.
Definition: qgsapplication.cpp:1205
QgsApplication::defaultStylePath
static QString defaultStylePath()
Returns the path to default style (works as a starting point).
Definition: qgsapplication.cpp:1374
QgsApplication::symbol3DRegistry
static Qgs3DSymbolRegistry * symbol3DRegistry()
Returns registry of available 3D symbols.
Definition: qgsapplication.cpp:2490
QgsApplication::init
static void init(QString profileFolder=QString())
This method initializes paths etc for QGIS.
Definition: qgsapplication.cpp:242
qgsfieldformatterregistry.h
QgsActionScopeRegistry
The action scope registry is an application wide registry that contains a list of available action sc...
Definition: qgsactionscoperegistry.h:44
QgsApplication::qgisAuthDatabaseFilePath
static QString qgisAuthDatabaseFilePath()
Returns the path to the user authentication database file: qgis-auth.db.
Definition: qgsapplication.cpp:1109
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:480
qgslocator.h
QgsApplication::setFileOpenEventReceiver
static void setFileOpenEventReceiver(QObject *receiver)
Sets the FileOpen event receiver.
Definition: qgsapplication.cpp:554
QgsApplication::gpsConnectionRegistry
static QgsGpsConnectionRegistry * gpsConnectionRegistry()
Returns the application's GPS connection registry, used for managing GPS connections.
Definition: qgsapplication.cpp:2405
QgsApplication::svgPaths
static QStringList svgPaths()
Returns the paths to svg directories.
Definition: qgsapplication.cpp:1153
QgsApplication::colorSchemeRegistry
static QgsColorSchemeRegistry * colorSchemeRegistry()
Returns the application's color scheme registry, used for managing color schemes.
Definition: qgsapplication.cpp:2310
qgsunittypes.h
QgsBookmarkManager
Manages storage of a set of bookmarks.
Definition: qgsbookmarkmanager.h:145
QgsSymbolLayerRegistry
Registry of available symbol layer classes.
Definition: qgssymbollayerregistry.h:183
QgsSettings
This class is a composition of two QSettings instances:
Definition: qgssettings.h:61
QgsApplication::setNullRepresentation
static void setNullRepresentation(const QString &nullRepresentation)
This string is used to represent the value NULL throughout QGIS.
Definition: qgsapplication.cpp:2028
qgspainteffectregistry.h
QgsPageSizeRegistry
A registry for known page sizes.
Definition: qgspagesizeregistry.h:73
qgsrasterrendererregistry.h
QgsExternalStorageRegistry
Registry of external storage backends used by QgsExternalResourceWidget.
Definition: qgsexternalstorageregistry.h:36
qgsactionscoperegistry.h
qgsgpsconnectionregistry.h
QgsCoordinateReferenceSystemRegistry
A registry for known coordinate reference system (CRS) definitions, including any user-defined CRSes.
Definition: qgscoordinatereferencesystemregistry.h:39
qgsprocessingmodelchilddependency.h
QgsApplication::instance
static QgsApplication * instance()
Returns the singleton instance of the QgsApplication.
Definition: qgsapplication.cpp:478
QgsApplication::projectStorageRegistry
static QgsProjectStorageRegistry * projectStorageRegistry()
Returns registry of available project storage implementations.
Definition: qgsapplication.cpp:2500
QgsApplication::appIconPath
static QString appIconPath()
Gets application icon.
Definition: qgsapplication.cpp:672
QgsApplication::sponsorsFilePath
static QString sponsorsFilePath()
Returns the path to the sponsors file.
Definition: qgsapplication.cpp:1061
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QgsApplication::actionScopeRegistry
static QgsActionScopeRegistry * actionScopeRegistry()
Returns the action scope registry.
Definition: qgsapplication.cpp:2042
QgsApplication::iconPath
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
Definition: qgsapplication.cpp:682
QgsApplication::registerOgrDrivers
static void registerOgrDrivers()
Register OGR drivers ensuring this only happens once.
Definition: qgsapplication.cpp:1668
QgsApplication::settingsSearchPathsForSVG
static const QgsSettingsEntryStringList settingsSearchPathsForSVG
Settings entry search path for SVG.
Definition: qgsapplication.h:1037
QgsApplication::preNotify
void preNotify(QObject *receiver, QEvent *event, bool *done)
QgsSymbolLayerUtils::decodeColor
static QColor decodeColor(const QString &str)
Definition: qgssymbollayerutils.cpp:69
qgsnewsfeedparser.h
qgs3dsymbolregistry.h
Q_GLOBAL_STATIC
Q_GLOBAL_STATIC(QReadWriteLock, sDefinitionCacheLock)
QgsCoordinateTransform::invalidateCache
static void invalidateCache(bool disableCache=false)
Clears the internal cache used to initialize QgsCoordinateTransform objects.
Definition: qgscoordinatetransform.cpp:1061
pal
Definition: qgsdiagramrenderer.h:50
QgsReadWriteLocker
The QgsReadWriteLocker class is a convenience class that simplifies locking and unlocking QReadWriteL...
Definition: qgsreadwritelocker.h:40
qgsannotationregistry.h
QgsApplication::platform
static QString platform()
Returns the QGIS platform name, e.g., "desktop", "server", "qgis_process" or "external" (for external...
Definition: qgsapplication.cpp:1339
QgsApplication::symbolLayerRegistry
static QgsSymbolLayerRegistry * symbolLayerRegistry()
Returns the application's symbol layer registry, used for managing symbol layers.
Definition: qgsapplication.cpp:2385
QgsApplication::skipGdalDriver
static void skipGdalDriver(const QString &driver)
Sets the GDAL_SKIP environment variable to include the specified driver and then calls GDALDriverMana...
Definition: qgsapplication.cpp:1818
QgsApplication::authManager
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
Definition: qgsapplication.cpp:1436
QgsDatabaseQueryLog
Handles logging of database queries.
Definition: qgsdbquerylog.h:131
QgsBabelFormatRegistry
A registry for QgsAbstractBabelFormat GPSBabel formats.
Definition: qgsbabelformatregistry.h:35
QgsApplication::requestForTranslatableObjects
void requestForTranslatableObjects(QgsTranslationContext *translationContext)
Emitted when project strings which require translation are being collected for inclusion in a ....
QgsStyle::defaultStyle
static QgsStyle * defaultStyle()
Returns default application-wide style.
Definition: qgsstyle.cpp:145
QgsApplication::getThemePixmap
static QPixmap getThemePixmap(const QString &name, const QColor &foreColor=QColor(), const QColor &backColor=QColor(), int size=16)
Helper to get a theme icon as a pixmap.
Definition: qgsapplication.cpp:827
QgsApplication::locale
static QString locale()
Returns the QGIS locale.
Definition: qgsapplication.cpp:1344
QgsCalloutRegistry
Registry of available callout classes.
Definition: qgscalloutsregistry.h:155
qgsapplication.h
qgsexternalstorageregistry.h
QgsApplication::srsDatabaseFilePath
static QString srsDatabaseFilePath()
Returns the path to the srs.db file.
Definition: qgsapplication.cpp:1124
qgsnetworkcontentfetcherregistry.h
QgsApplication::initQgis
static void initQgis()
loads providers
Definition: qgsapplication.cpp:1409
Qgs3DRendererRegistry
Keeps track of available 3D renderers.
Definition: qgs3drendererregistry.h:69
QgsApplication::qgisSettingsDirPath
static QString qgisSettingsDirPath()
Returns the path to the settings directory in user's home dir.
Definition: qgsapplication.cpp:1099
QgsApplication::messageLog
static QgsMessageLog * messageLog()
Returns the application's message log.
Definition: qgsapplication.cpp:2450
QgsApplication::databaseQueryLog
static QgsDatabaseQueryLog * databaseQueryLog()
Returns the database query log.
Definition: qgsapplication.cpp:2440
QgsApplication::relativePathToAbsolutePath
static QString relativePathToAbsolutePath(const QString &rpath, const QString &targetPath)
Converts path relative to target to an absolute path.
Definition: qgsapplication.cpp:1746
qgsproviderregistry.h
QgsApplication::XDR
@ XDR
Definition: qgsapplication.h:545
QgsUserProfileManager::getProfile
QgsUserProfile * getProfile(const QString &defaultProfile="default", bool createNew=true, bool initSettings=true)
Returns the profile from the given root profile location.
Definition: qgsuserprofilemanager.cpp:40
QgsApplication::qgisMasterDatabaseFilePath
static QString qgisMasterDatabaseFilePath()
Returns the path to the master qgis.db file.
Definition: qgsapplication.cpp:1094
QgsApplication::iconsPath
static QString iconsPath()
Returns the path to the icons image directory.
Definition: qgsapplication.cpp:1119
QgsMessageLog
Interface for logging messages from QGIS in GUI independent way.
Definition: qgsmessagelog.h:39
QgsAuthManager
Singleton offering an interface to manage the authentication configuration database and to utilize co...
Definition: qgsauthmanager.h:69
QgsApplication::metadataPath
static QString metadataPath()
Returns the path to the metadata directory.
Definition: qgsapplication.cpp:1089
QgsApplication::nullRepresentation
static QString nullRepresentation()
This string is used to represent the value NULL throughout QGIS.
Definition: qgsapplication.cpp:2018
QgsClassificationMethodRegistry
This class manages all known classification methods.
Definition: qgsclassificationmethodregistry.h:38
QgsApplication::exitQgis
static void exitQgis()
deletes provider registry and map layer registry
Definition: qgsapplication.cpp:1456
QgsApplication::contributorsFilePath
static QString contributorsFilePath()
Returns the path to the contributors file.
Definition: qgsapplication.cpp:1052
qgscalloutsregistry.h
QgsApplication::layoutTemplatePaths
static QStringList layoutTemplatePaths()
Returns the paths to layout template directories.
Definition: qgsapplication.cpp:1188
QgsApplication::developersMapFilePath
static QString developersMapFilePath()
Returns the path to the developers map file.
Definition: qgsapplication.cpp:1056
qgsnetworkaccessmanager.h
QgsApplication::coordinateReferenceSystemRegistry
static QgsCoordinateReferenceSystemRegistry * coordinateReferenceSystemRegistry()
Returns the application's coordinate reference system (CRS) registry, which handles known CRS definit...
Definition: qgsapplication.cpp:2355
QgsSvgCache
A cache for images / pictures derived from SVG files.
Definition: qgssvgcache.h:122
QgsDateTimeFieldFormatter::applyLocaleChange
static void applyLocaleChange()
Adjusts the date time formats according to locale.
Definition: qgsdatetimefieldformatter.cpp:119
QgsException::what
QString what() const
Definition: qgsexception.h:48
QgsColorSchemeRegistry::addDefaultSchemes
void addDefaultSchemes()
Adds all default color schemes to this color scheme.
Definition: qgscolorschemeregistry.cpp:45
qgssymbollayerregistry.h
QgsApplication::setUITheme
static void setUITheme(const QString &themeName)
Set the current UI theme used to style the interface.
Definition: qgsapplication.cpp:933
QgsApplication::defaultStyleModel
static QgsStyleModel * defaultStyleModel()
Returns a shared QgsStyleModel containing the default style library (see QgsStyle::defaultStyle()).
Definition: qgsapplication.cpp:2445
QgsApplication::dataItemProviderRegistry
static QgsDataItemProviderRegistry * dataItemProviderRegistry()
Returns the application's data item provider registry, which keeps a list of data item providers that...
Definition: qgsapplication.cpp:2335
qgsrendererregistry.h
QgsTaskManager
Task manager for managing a set of long-running QgsTask tasks. This class can be created directly,...
Definition: qgstaskmanager.h:392
QgsApplication::taskManager
static QgsTaskManager * taskManager()
Returns the application's task manager, used for managing application wide background task handling.
Definition: qgsapplication.cpp:2300
QgsReadWriteLocker::Write
@ Write
Lock for write.
Definition: qgsreadwritelocker.h:76
QgsApplication::setSvgPaths
static void setSvgPaths(const QStringList &svgPaths)
Sets the paths to svg directories and invalidates the svg path list cache.
Definition: qgsapplication.cpp:1147
QgsApplication::imageCache
static QgsImageCache * imageCache()
Returns the application's image cache, used for caching resampled versions of raster images.
Definition: qgsapplication.cpp:2365
qgspointcloudrendererregistry.h
qgsdbquerylog.h
CONN_POOL_MAX_CONCURRENT_CONNS
#define CONN_POOL_MAX_CONCURRENT_CONNS
Definition: qgsapplication.cpp:144
QgsApplication::createDatabase
static bool createDatabase(QString *errorMessage=nullptr)
initialize qgis.db
Definition: qgsapplication.cpp:2047
QgsApplication::collectTranslatableObjects
void collectTranslatableObjects(QgsTranslationContext *translationContext)
Emits the signal to collect all the strings of .qgs to be included in ts file.
Definition: qgsapplication.cpp:2013
QgsStyle::cleanDefaultStyle
static void cleanDefaultStyle()
Deletes the default style. Only to be used by QgsApplication::exitQgis()
Definition: qgsstyle.cpp:176
QgsApplication::profiler
static QgsRuntimeProfiler * profiler()
Returns the application runtime profiler.
Definition: qgsapplication.cpp:549
QgsApplication::endian
static endian_t endian()
Returns whether this machine uses big or little endian.
Definition: qgsapplication.cpp:1404
QgsApplication::endian_t
endian_t
Constants for endian-ness.
Definition: qgsapplication.h:543
QgsApplication::customVariablesChanged
void customVariablesChanged()
Emitted whenever a custom global variable changes.
QgsPaintEffectRegistry
Registry of available paint effects.
Definition: qgspainteffectregistry.h:175
Qgis::UI_SCALE_FACTOR
static const double UI_SCALE_FACTOR
UI scaling factor.
Definition: qgis.h:2043
QgsSourceCache
A cache for source strings that returns a local file path containing the source content.
Definition: qgssourcecache.h:72
QgsApplication::validityCheckRegistry
static QgsValidityCheckRegistry * validityCheckRegistry()
Returns the application's validity check registry, used for managing validity checks.
Definition: qgsapplication.cpp:2380
QgsApplication::sourceCache
static QgsSourceCache * sourceCache()
Returns the application's source cache, used for caching embedded and remote source strings as local ...
Definition: qgsapplication.cpp:2370
QgsApplication::setCustomVariable
static void setCustomVariable(const QString &name, const QVariant &value)
Set a single custom expression variable.
Definition: qgsapplication.cpp:1970
QgsApplication::setAuthDatabaseDirPath
static void setAuthDatabaseDirPath(const QString &authDbDirPath)
Alters authentication data base directory path - used by 3rd party apps.
Definition: qgsapplication.cpp:613
QgsTranslationContext
Used for the collecting of strings from projects for translation and creation of ts files.
Definition: qgstranslationcontext.h:35
qgsstylemodel.h
QgsApplication::setThemeName
static void setThemeName(const QString &themeName)
Set the active theme to the specified theme.
Definition: qgsapplication.cpp:842
QgsApplication::QGIS_APPLICATION_NAME
static const char * QGIS_APPLICATION_NAME
Definition: qgsapplication.h:162
QgsApplication::event
bool event(QEvent *event) override
Watch for QFileOpenEvent.
Definition: qgsapplication.cpp:483
QgsApplication::settingsLocaleUserLocale
static const QgsSettingsEntryString settingsLocaleUserLocale
Settings entry locale user locale.
Definition: qgsapplication.h:1029
QgsScaleBarRendererRegistry
The QgsScaleBarRendererRegistry manages registered scalebar renderers.
Definition: qgsscalebarrendererregistry.h:33
QgsApplication::Select
@ Select
Select a rectangle.
Definition: qgsapplication.h:406
QgsApplication::pkgDataPath
static QString pkgDataPath()
Returns the common root path of all application data directories.
Definition: qgsapplication.cpp:645
QgsSettings::setValue
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
Definition: qgssettings.cpp:279
QgsApplication::buildSourcePath
static QString buildSourcePath()
Returns path to the source directory. Valid only when running from build directory.
Definition: qgsapplication.cpp:1801
QgsApplication::classificationMethodRegistry
static QgsClassificationMethodRegistry * classificationMethodRegistry()
Returns the application's classification methods registry, used in graduated renderer.
Definition: qgsapplication.cpp:2420
QgsApplication::bookmarkManager
static QgsBookmarkManager * bookmarkManager()
Returns the application's bookmark manager, used for storing installation-wide bookmarks.
Definition: qgsapplication.cpp:2425
QgsRuntimeProfiler::start
void start(const QString &name, const QString &group="startup")
Start a profile event with the given name.
Definition: qgsruntimeprofiler.cpp:206
QgsAnnotationItemRegistry
Registry of available annotation item types.
Definition: qgsannotationitemregistry.h:142
QgsApplication::StyleSheetType
StyleSheetType
The StyleSheetType enum represents the stylesheet type that a widget supports.
Definition: qgsapplication.h:154
qgs3drendererregistry.h
QgsApplication::userStylePath
static QString userStylePath()
Returns the path to user's style.
Definition: qgsapplication.cpp:1200
qgslayout.h
QgsApplication
Extends QApplication to provide access to QGIS specific resources such as theme paths,...
Definition: qgsapplication.h:91
QgsNetworkAccessManager::instance
static QgsNetworkAccessManager * instance(Qt::ConnectionType connectionType=Qt::BlockingQueuedConnection)
Returns a pointer to the active QgsNetworkAccessManager for the current thread.
Definition: qgsnetworkaccessmanager.cpp:202
qgspagesizeregistry.h
qgsdatetimefieldformatter.h
QgsApplication::settingsLocaleOverrideFlag
static const QgsSettingsEntryBool settingsLocaleOverrideFlag
Settings entry locale override flag.
Definition: qgsapplication.h:1031
QgsApplication::svgCache
static QgsSvgCache * svgCache()
Returns the application's SVG cache, used for caching SVG images and handling parameter replacement w...
Definition: qgsapplication.cpp:2360
QgsApplication::fieldFormatterRegistry
static QgsFieldFormatterRegistry * fieldFormatterRegistry()
Gets the registry of available field formatters.
Definition: qgsapplication.cpp:2480
qgsstyle.h
QgsApplication::themeName
static QString themeName()
Set the active theme to the specified theme.
Definition: qgsapplication.cpp:928
qgsmeshlayer.h
QgsSettingsRegistryCore
QgsSettingsRegistryCore is used for settings introspection and collects all QgsSettingsEntry instance...
Definition: qgssettingsregistrycore.h:39
QgsApplication::registerGdalDriversFromSettings
static void registerGdalDriversFromSettings()
Register gdal drivers, excluding the ones mentioned in "gdal/skipList" setting.
Definition: qgsapplication.cpp:1859
QgsCoordinateReferenceSystem::invalidateCache
static void invalidateCache(bool disableCache=false)
Clears the internal cache used to initialize QgsCoordinateReferenceSystem objects.
Definition: qgscoordinatereferencesystem.cpp:2921
QgsColorSchemeRegistry
Registry of color schemes.
Definition: qgscolorschemeregistry.h:34
QgsApplication::gpsBabelFormatRegistry
static QgsBabelFormatRegistry * gpsBabelFormatRegistry()
Returns the application's GPSBabel format registry, used for managing GPSBabel formats.
Definition: qgsapplication.cpp:2410
QgsApplication::setDefaultSvgPaths
static void setDefaultSvgPaths(const QStringList &pathList)
Alters default svg paths - used by 3rd party apps.
Definition: qgsapplication.cpp:608
QgsRecentStyleHandler
Handles and tracks style items recently used in the QGIS GUI.
Definition: qgsrecentstylehandler.h:38
QgsApplication::setSkippedGdalDrivers
static void setSkippedGdalDrivers(const QStringList &skippedGdalDrivers, const QStringList &deferredSkippedGdalDrivers)
Sets the list of gdal drivers that should be disabled (skippedGdalDrivers), but excludes for now the ...
Definition: qgsapplication.cpp:1847
qgsreferencedgeometry.h
QgsApplication::userLoginName
static QString userLoginName()
Returns the user's operating system login account name.
Definition: qgsapplication.cpp:1211
QgsLocalizedDataPathRegistry
A registry class to hold localized data paths which can be used for basemaps, logos,...
Definition: qgslocalizeddatapathregistry.h:42
QgsApplication::localeChanged
void localeChanged()
Emitted when project locale has been changed.
QgsApplication::layoutItemRegistry
static QgsLayoutItemRegistry * layoutItemRegistry()
Returns the application's layout item registry, used for layout item types.
Definition: qgsapplication.cpp:2395
QgsStringMap
QMap< QString, QString > QgsStringMap
Definition: qgis.h:2781
qgslayoutrendercontext.h
QgsLayout::settingsSearchPathForTemplates
static const QgsSettingsEntryStringList settingsSearchPathForTemplates
Settings entry search path for templates.
Definition: qgslayout.h:663
qgsgeometry.h
QgsSettings::beginGroup
void beginGroup(const QString &prefix, QgsSettings::Section section=QgsSettings::NoSection)
Appends prefix to the current group.
Definition: qgssettings.cpp:89
QgsApplication::paintEffectRegistry
static QgsPaintEffectRegistry * paintEffectRegistry()
Returns the application's paint effect registry, used for managing paint effects.
Definition: qgsapplication.cpp:2315
QgsProjectStorageRegistry
Registry of storage backends that QgsProject may use.
Definition: qgsprojectstorageregistry.h:34
QgsApplication::renderer3DRegistry
static Qgs3DRendererRegistry * renderer3DRegistry()
Returns registry of available 3D renderers.
Definition: qgsapplication.cpp:2485
qgsuserprofilemanager.h
QgsRasterRendererRegistry
Registry for raster renderers.
Definition: qgsrasterrendererregistry.h:69
QgsApplication::maxConcurrentConnectionsPerPool
int maxConcurrentConnectionsPerPool() const
The maximum number of concurrent connections per connections pool.
Definition: qgsapplication.cpp:1998
QgsSettingsEntryByReference::value
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
Definition: qgssettingsentry.h:379
qgsrecentstylehandler.h
QgsApplication::libexecPath
static QString libexecPath()
Returns the path with utility executables (help viewer, crssync, ...)
Definition: qgsapplication.cpp:1394
QgsStyle
Definition: qgsstyle.h:159
Qgs3DSymbolRegistry
Registry of available 3D symbol classes.
Definition: qgs3dsymbolregistry.h:183
QgsApplication::licenceFilePath
static QString licenceFilePath()
Returns the path to the licence file.
Definition: qgsapplication.cpp:1076
QgsApplication::ZoomIn
@ ZoomIn
Zoom in.
Definition: qgsapplication.h:401
QgsApplication::deferredSkippedGdalDrivers
static QStringList deferredSkippedGdalDrivers()
Returns the list of gdal drivers that have been disabled in the current session, and thus,...
Definition: qgsapplication.cpp:1882
qgsimagecache.h
qgsprojutils.h
QgsApplication::Identify
@ Identify
Identify: obtain information about the object.
Definition: qgsapplication.h:403
qgsnetworkreply.h
QgsApplication::resolvePkgPath
static QString resolvePkgPath()
Calculate the application pkg path.
Definition: qgsapplication.cpp:847
QgsApplication::NDR
@ NDR
Definition: qgsapplication.h:546
QgsApplication::scaleIconSize
static int scaleIconSize(int standardSize, bool applyDevicePixelRatio=false)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly,...
Definition: qgsapplication.cpp:1980
QgsApplication::externalStorageRegistry
static QgsExternalStorageRegistry * externalStorageRegistry()
Returns registry of available external storage implementations.
Definition: qgsapplication.cpp:2505
QgsApplication::translation
QString translation() const
Returns the current application translation locale code.
Definition: qgsapplication.cpp:2008
QgsScopedRuntimeProfile
Scoped object for logging of the runtime for a single operation or group of operations.
Definition: qgsruntimeprofiler.h:327
qgssettings.h
QgsApplication::systemEnvVars
static QMap< QString, QString > systemEnvVars()
Returns the system environment variables passed to application.
Definition: qgsapplication.cpp:1195
qgscolorschemeregistry.h
QgsUserProfile
User profile contains information about the user profile folders on the machine. In QGIS 3 all settin...
Definition: qgsuserprofile.h:34
qgsvaliditycheckregistry.h
QgsApplication::setPluginPath
static void setPluginPath(const QString &pluginPath)
Alters plugin path - used by 3rd party apps.
Definition: qgsapplication.cpp:592
QgsApplication::qgisUserDatabaseFilePath
static QString qgisUserDatabaseFilePath()
Returns the path to the user qgis.db file.
Definition: qgsapplication.cpp:1104
ABISYM
QObject * ABISYM(QgsApplication::mFileOpenEventReceiver)
QgsApplication::CapturePoint
@ CapturePoint
Select and capture a point or a feature.
Definition: qgsapplication.h:405
QgsApplication::numericFormatRegistry
static QgsNumericFormatRegistry * numericFormatRegistry()
Gets the registry of available numeric formats.
Definition: qgsapplication.cpp:2475
QgsApplication::calloutRegistry
static QgsCalloutRegistry * calloutRegistry()
Returns the application's callout registry, used for managing callout types.
Definition: qgsapplication.cpp:2390
QgsApplication::activeThemePath
static QString activeThemePath()
Returns the path to the currently active theme directory.
Definition: qgsapplication.cpp:657
QgsBookmarkManager::initialize
void initialize(const QString &filePath)
Initializes the bookmark manager.
Definition: qgsbookmarkmanager.cpp:499
QgsSettingsEntryByReference::setValue
bool setValue(const T &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
Definition: qgssettingsentry.h:424
QgsApplication::userThemesFolder
static QString userThemesFolder()
Returns the path to user's themes folder.
Definition: qgsapplication.cpp:1369
qgssqliteutils.h
QgsApplication::customVariables
static QVariantMap customVariables()
Custom expression variables for this application.
Definition: qgsapplication.cpp:1936
QgsApplication::localizedDataPathRegistry
static QgsLocalizedDataPathRegistry * localizedDataPathRegistry()
Returns the registry of data repositories These are used as paths for basemaps, logos,...
Definition: qgsapplication.cpp:2510
qgsprocessingmodelchildparametersource.h
QgsApplication::defaultThemesFolder
static QString defaultThemesFolder()
Returns the path to default themes folder from install (works as a starting point).
Definition: qgsapplication.cpp:1379
QgsProcessingRegistry
Registry for various processing components, including providers, algorithms and various parameters an...
Definition: qgsprocessingregistry.h:39
QgsColorSchemeRegistry::initStyleScheme
void initStyleScheme()
Initializes the default random style color scheme for the user.
Definition: qgscolorschemeregistry.cpp:54
qgsannotationitemregistry.h
QgsApplication::splashPath
static QString splashPath()
Returns the path to the splash screen image directory.
Definition: qgsapplication.cpp:1114
qgsexception.h
qgsremappingproxyfeaturesink.h
QgsApplication::systemMemorySizeMb
static int systemMemorySizeMb()
Returns the size of the system memory (RAM) in megabytes.
Definition: qgsapplication.cpp:1303
QgsSettings::contains
bool contains(const QString &key, QgsSettings::Section section=QgsSettings::NoSection) const
Returns true if there exists a setting called key; returns false otherwise.
Definition: qgssettings.cpp:175
qgsbookmarkmanager.h
QgsApplication::setPrefixPath
static void setPrefixPath(const QString &prefixPath, bool useDefaultPaths=false)
Alters prefix path - used by 3rd party apps.
Definition: qgsapplication.cpp:571
QgsApplication::translatorsFilePath
static QString translatorsFilePath()
Returns the path to the sponsors file.
Definition: qgsapplication.cpp:1071
QgsApplication::getThemeIcon
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Definition: qgsapplication.cpp:693
QgsProjUtils::searchPaths
static QStringList searchPaths()
Returns the current list of Proj file search paths.
Definition: qgsprojutils.cpp:409
QgsLayoutItemRegistry
Registry of available layout item types.
Definition: qgslayoutitemregistry.h:329
qgslogger.h
QgsApplication::donorsFilePath
static QString donorsFilePath()
Returns the path to the donors file.
Definition: qgsapplication.cpp:1066
QgsAuthManager::init
bool init(const QString &pluginPath=QString(), const QString &authDatabasePath=QString())
init initialize QCA, prioritize qca-ossl plugin and optionally set up the authentication database
Definition: qgsauthmanager.cpp:180
QgsApplication::qmlImportPath
static QString qmlImportPath()
Returns the path where QML components are installed for QGIS Quick library.
Definition: qgsapplication.cpp:1399
qgsfeaturestore.h
qgsbabelformatregistry.h
QgsPointCloudRendererRegistry
Registry of 2D renderers for point clouds.
Definition: qgspointcloudrendererregistry.h:184
QgsImageCache
A cache for images derived from raster files.
Definition: qgsimagecache.h:131
QgsExpression::cleanRegisteredFunctions
static void cleanRegisteredFunctions()
Deletes all registered functions whose ownership have been transferred to the expression engine.
Definition: qgsexpressionfunction.cpp:8456
QgsApplication::skippedGdalDrivers
static QStringList skippedGdalDrivers()
Returns the list of gdal drivers that should be skipped (based on GDAL_SKIP environment variable)
Definition: qgsapplication.cpp:1842
QgsRendererRegistry
Registry of renderers.
Definition: qgsrendererregistry.h:224
sqlite3_database_unique_ptr
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
Definition: qgssqliteutils.h:118
qgslayoutitemregistry.h
QgsApplication::pluginLayerRegistry
static QgsPluginLayerRegistry * pluginLayerRegistry()
Returns the application's plugin layer registry, used for managing plugin layer types.
Definition: qgsapplication.cpp:2415
qgsclassificationmethodregistry.h
QgsEllipsoidUtils::invalidateCache
static void invalidateCache(bool disableCache=false)
Clears the internal cache used.
Definition: qgsellipsoidutils.cpp:346
QgsProviderRegistry::instance
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
Definition: qgsproviderregistry.cpp:73
QgsApplication::setLocale
static void setLocale(const QLocale &locale)
Sets the QGIS locale - used mainly by 3rd party apps and tests.
Definition: qgsapplication.cpp:1363
QgsValidityCheckRegistry
This class keeps a list of QgsAbstractValidityCheck checks which can be used when performing validity...
Definition: qgsvaliditycheckregistry.h:36
QgsApplication::applyGdalSkippedDrivers
static void applyGdalSkippedDrivers()
Apply the skipped drivers list to gdal.
Definition: qgsapplication.cpp:1887
QgsApplication::QGIS_ORGANIZATION_DOMAIN
static const char * QGIS_ORGANIZATION_DOMAIN
Definition: qgsapplication.h:161
qgsprocessingregistry.h
QgsApplication::reportStyleSheet
static QString reportStyleSheet(QgsApplication::StyleSheetType styleSheetType=QgsApplication::StyleSheetType::Qt)
Returns a css style sheet for reports, the styleSheetType argument determines what type of stylesheet...
Definition: qgsapplication.cpp:1517
qgscoordinatereferencesystemregistry.h
QgsApplication::defaultThemePath
static QString defaultThemePath()
Returns the path to the default theme directory.
Definition: qgsapplication.cpp:653
QgsPluginLayerRegistry
A registry of plugin layers types.
Definition: qgspluginlayerregistry.h:68
QgsApplication::networkContentFetcherRegistry
static QgsNetworkContentFetcherRegistry * networkContentFetcherRegistry()
Returns the application's network content registry used for fetching temporary files during QGIS sess...
Definition: qgsapplication.cpp:2375
QgsSvgCache::svgAsImage
QImage svgAsImage(const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth, double widthScaleFactor, bool &fitsInCache, double fixedAspectRatio=0, bool blocking=false, const QMap< QString, QString > &parameters=QMap< QString, QString >())
Returns an SVG drawing as a QImage.
Definition: qgssvgcache.cpp:125
qgsproject.h
QgsFieldFormatterRegistry
The QgsFieldFormatterRegistry manages registered classes of QgsFieldFormatter.
Definition: qgsfieldformatterregistry.h:40
QgsApplication::uiThemes
static QHash< QString, QString > uiThemes()
All themes found in ~/.qgis3/themes folder.
Definition: qgsapplication.cpp:1022
QgsUserProfileManager
User profile manager is used to manager list, and manage user profiles on the users machine.
Definition: qgsuserprofilemanager.h:41
QgsApplication::restoreGdalDriver
static void restoreGdalDriver(const QString &driver)
Sets the GDAL_SKIP environment variable to exclude the specified driver and then calls GDALDriverMana...
Definition: qgsapplication.cpp:1828
QgsApplication::ZoomOut
@ ZoomOut
Zoom out.
Definition: qgsapplication.h:402
QgsApplication::absolutePathToRelativePath
static QString absolutePathToRelativePath(const QString &apath, const QString &targetPath)
Converts absolute path to path relative to target.
Definition: qgsapplication.cpp:1676
QgsApplication::pluginPath
static QString pluginPath()
Returns the path to the application plugin directory.
Definition: qgsapplication.cpp:640
QgsApplication::serverResourcesPath
static QString serverResourcesPath()
Returns the path to the server resources directory.
Definition: qgsapplication.cpp:1384
QgsApplication::annotationItemRegistry
static QgsAnnotationItemRegistry * annotationItemRegistry()
Returns the application's annotation item registry, used for annotation item types.
Definition: qgsapplication.cpp:2400
QgsApplication::settingsRegistryCore
static QgsSettingsRegistryCore * settingsRegistryCore()
Returns the application's settings registry, used for managing application settings.
Definition: qgsapplication.cpp:2305
QgsApplication::userFullName
static QString userFullName()
Returns the user's operating system login account full display name.
Definition: qgsapplication.cpp:1246
QgsSettingsEntryByValue::value
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
Definition: qgssettingsentry.h:520
QgsApplication::setTranslation
static void setTranslation(const QString &translation)
Set translation locale code.
Definition: qgsapplication.cpp:2003
qgsmessagelog.h
QgsNetworkContentFetcherRegistry
Registry for temporary fetched files.
Definition: qgsnetworkcontentfetcherregistry.h:139
QgsApplication::scaleBarRendererRegistry
static QgsScaleBarRendererRegistry * scaleBarRendererRegistry()
Gets the registry of available scalebar renderers.
Definition: qgsapplication.cpp:2495
QgsApplication::showSettings
static QString showSettings()
Convenience function to get a summary of the paths used in this application instance useful for debug...
Definition: qgsapplication.cpp:1490