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