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