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