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