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