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