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