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