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