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