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