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