77 #include "processing/models/qgsprocessingmodelchildparametersource.h" 78 #include "processing/models/qgsprocessingmodelchilddependency.h" 82 #include <QDesktopWidget> 86 #include <QFileOpenEvent> 87 #include <QMessageBox> 90 #include <QProcessEnvironment> 93 #include <QThreadPool> 98 #include <netinet/in.h> 104 #define SECURITY_WIN32 105 #include <security.h> 107 #pragma comment( lib, "Secur32.lib" ) 111 #include "qgsconfig.h" 115 #include <cpl_conv.h> 119 #if PROJ_VERSION_MAJOR>=6 124 #define CONN_POOL_MAX_CONCURRENT_CONNS 4 126 QObject *
ABISYM( QgsApplication::mFileOpenEventReceiver ) =
nullptr;
127 bool ABISYM( QgsApplication::mInitialized ) =
false;
128 bool ABISYM( QgsApplication::mRunningFromBuildDir ) =
false;
132 QgsApplication::ApplicationMembers *QgsApplication::sApplicationMembers =
nullptr;
134 int ABISYM( QgsApplication::sMaxThreads ) = -1;
151 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA) 165 : QApplication( argc, argv, GUIenabled )
167 *sPlatformName() = platformName;
169 if ( *sTranslation() != QLatin1String(
"C" ) )
171 mQgisTranslator =
new QTranslator();
172 if ( mQgisTranslator->load( QStringLiteral(
"qgis_" ) + *sTranslation(), i18nPath() ) )
174 installTranslator( mQgisTranslator );
178 QgsDebugMsgLevel( QStringLiteral(
"loading of qgis translation failed %1/qgis_%2" ).arg( i18nPath(), *sTranslation() ), 2 );
186 mQtTranslator =
new QTranslator();
187 if ( mQtTranslator->load( QStringLiteral(
"qt_" ) + *sTranslation(), QLibraryInfo::location( QLibraryInfo::TranslationsPath ) ) )
189 installTranslator( mQtTranslator );
193 QgsDebugMsgLevel( QStringLiteral(
"loading of qt translation failed %1/qt_%2" ).arg( QLibraryInfo::location( QLibraryInfo::TranslationsPath ), *sTranslation() ), 2 );
197 mApplicationMembers =
new ApplicationMembers();
199 *sProfilePath() = profileFolder;
204 if ( profileFolder.isEmpty() )
206 if ( getenv(
"QGIS_CUSTOM_CONFIG_PATH" ) )
208 profileFolder = getenv(
"QGIS_CUSTOM_CONFIG_PATH" );
212 profileFolder = QStandardPaths::standardLocations( QStandardPaths::AppDataLocation ).value( 0 );
219 profileFolder = profile->
folder();
223 *sProfilePath() = profileFolder;
225 static std::once_flag sMetaTypesRegistered;
226 std::call_once( sMetaTypesRegistered, []
228 qRegisterMetaType<QgsGeometry::Error>(
"QgsGeometry::Error" );
229 qRegisterMetaType<QgsProcessingFeatureSourceDefinition>(
"QgsProcessingFeatureSourceDefinition" );
230 qRegisterMetaType<QgsProcessingOutputLayerDefinition>(
"QgsProcessingOutputLayerDefinition" );
231 qRegisterMetaType<QgsUnitTypes::LayoutUnit>(
"QgsUnitTypes::LayoutUnit" );
232 qRegisterMetaType<QgsFeatureId>(
"QgsFeatureId" );
233 qRegisterMetaType<QgsFeatureIds>(
"QgsFeatureIds" );
234 qRegisterMetaType<QgsProperty>(
"QgsProperty" );
235 qRegisterMetaType<QgsFeatureStoreList>(
"QgsFeatureStoreList" );
236 qRegisterMetaType<Qgis::MessageLevel>(
"Qgis::MessageLevel" );
237 qRegisterMetaType<QgsReferencedRectangle>(
"QgsReferencedRectangle" );
238 qRegisterMetaType<QgsReferencedPointXY>(
"QgsReferencedPointXY" );
239 qRegisterMetaType<QgsReferencedGeometry>(
"QgsReferencedGeometry" );
240 qRegisterMetaType<QgsLayoutRenderContext::Flags>(
"QgsLayoutRenderContext::Flags" );
241 qRegisterMetaType<QgsStyle::StyleEntity>(
"QgsStyle::StyleEntity" );
242 qRegisterMetaType<QgsCoordinateReferenceSystem>(
"QgsCoordinateReferenceSystem" );
243 qRegisterMetaType<QgsAuthManager::MessageLevel>(
"QgsAuthManager::MessageLevel" );
244 qRegisterMetaType<QgsNetworkRequestParameters>(
"QgsNetworkRequestParameters" );
245 qRegisterMetaType<QgsNetworkReplyContent>(
"QgsNetworkReplyContent" );
246 qRegisterMetaType<QgsGeometry>(
"QgsGeometry" );
247 qRegisterMetaType<QgsDatumTransform::GridDetails>(
"QgsDatumTransform::GridDetails" );
248 qRegisterMetaType<QgsDatumTransform::TransformDetails>(
"QgsDatumTransform::TransformDetails" );
249 qRegisterMetaType<QgsNewsFeedParser::Entry>(
"QgsNewsFeedParser::Entry" );
250 qRegisterMetaType<QgsRectangle>(
"QgsRectangle" );
251 qRegisterMetaType<QgsLocatorResult>(
"QgsLocatorResult" );
252 qRegisterMetaType<QgsProcessingModelChildParameterSource>(
"QgsProcessingModelChildParameterSource" );
253 qRegisterMetaTypeStreamOperators<QgsProcessingModelChildParameterSource>(
"QgsProcessingModelChildParameterSource" );
254 qRegisterMetaType<QgsRemappingSinkDefinition>(
"QgsRemappingSinkDefinition" );
255 qRegisterMetaType<QgsProcessingModelChildDependency>(
"QgsProcessingModelChildDependency" );
256 qRegisterMetaType<QgsTextFormat>(
"QgsTextFormat" );
257 QMetaType::registerComparators<QgsProcessingModelChildDependency>();
258 QMetaType::registerEqualsComparator<QgsProcessingFeatureSourceDefinition>();
259 QMetaType::registerEqualsComparator<QgsProperty>();
260 qRegisterMetaType<QPainter::CompositionMode>(
"QPainter::CompositionMode" );
261 qRegisterMetaType<QgsDateTimeRange>(
"QgsDateTimeRange" );
266 if ( ABISYM( mRunningFromBuildDir ) )
269 *sPrefixPath() = QString();
270 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA) 271 setPluginPath( *sBuildOutputPath() +
'/' + QString( QGIS_PLUGIN_SUBDIR ) +
'/' + *sCfgIntDir() );
273 setPluginPath( *sBuildOutputPath() +
'/' + QStringLiteral( QGIS_PLUGIN_SUBDIR ) );
275 setPkgDataPath( *sBuildOutputPath() + QStringLiteral(
"/data" ) );
276 *sLibraryPath() = *sBuildOutputPath() +
'/' + QGIS_LIB_SUBDIR +
'/';
277 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA) 278 *sLibexecPath() = *sBuildOutputPath() +
'/' + QGIS_LIBEXEC_SUBDIR +
'/' + *sCfgIntDir() +
'/';
280 *sLibexecPath() = *sBuildOutputPath() +
'/' + QGIS_LIBEXEC_SUBDIR +
'/';
282 #if defined( HAVE_QUICK ) 283 *sQmlImportPath() = *sBuildOutputPath() +
'/' + QGIS_QML_SUBDIR +
'/';
288 char *
prefixPath = getenv(
"QGIS_PREFIX_PATH" );
291 if ( sPrefixPath()->isNull() )
293 #if defined(Q_OS_MACX) || defined(Q_OS_WIN) 295 #elif defined(ANDROID) 297 QDir myDir( QDir::homePath() );
299 QString myPrefix = myDir.absolutePath();
302 QDir myDir( applicationDirPath() );
304 if ( applicationDirPath().contains( QStringLiteral(
"cgi-bin" ) ) )
309 QString myPrefix = myDir.absolutePath();
320 *sConfigPath() = profileFolder +
'/';
324 if ( getenv(
"QGIS_AUTH_DB_DIR_PATH" ) )
330 QMap<QString, QString> systemEnvVarMap;
331 QString passfile( QStringLiteral(
"QGIS_AUTH_PASSWORD_FILE" ) );
333 const auto systemEnvironment = QProcessEnvironment::systemEnvironment().toStringList();
334 for (
const QString &varStr : systemEnvironment )
336 int pos = varStr.indexOf( QLatin1Char(
'=' ) );
339 QString varStrName = varStr.left( pos );
340 QString varStrValue = varStr.mid( pos + 1 );
341 if ( varStrName != passfile )
343 systemEnvVarMap.insert( varStrName, varStrValue );
346 *sSystemEnvVars() = systemEnvVarMap;
348 #if PROJ_VERSION_MAJOR>=6 354 QString projLib( QDir::cleanPath(
pkgDataPath().append(
"/proj" ) ) );
355 if ( QFile::exists( projLib ) )
357 currentProjSearchPaths.append( projLib );
361 char **newPaths =
new char *[currentProjSearchPaths.length()];
362 for (
int i = 0; i < currentProjSearchPaths.count(); ++i )
364 newPaths[i] = CPLStrdup( currentProjSearchPaths.at( i ).toUtf8().constData() );
366 proj_context_set_search_paths(
nullptr, currentProjSearchPaths.count(), newPaths );
367 for (
int i = 0; i < currentProjSearchPaths.count(); ++i )
369 CPLFree( newPaths[i] );
372 #endif // PROJ_VERSION_MAJOR>=6 375 QCoreApplication::addLibraryPath(
pluginPath() );
380 ABISYM( sMaxThreads ) = -1;
393 if ( !members()->mStyleModel )
396 ABISYM( mInitialized ) =
true;
401 delete mDataItemProviderRegistry;
402 delete mApplicationMembers;
403 delete mQgisTranslator;
404 delete mQtTranslator;
412 void QgsApplication::invalidateCaches()
424 return qobject_cast<
QgsApplication *>( QCoreApplication::instance() );
430 if ( event->type() == QEvent::FileOpen )
433 if ( ABISYM( mFileOpenEventReceiver ) )
436 done =
notify( ABISYM( mFileOpenEventReceiver ), event );
443 sFileOpenEventList()->append( static_cast<QFileOpenEvent *>( event )->file() );
450 done = QApplication::event( event );
459 if ( thread() == receiver->thread() )
460 emit
preNotify( receiver, event, &done );
469 done = QApplication::notify( receiver, event );
473 qCritical() <<
"Caught unhandled QgsException: " << e.
what();
474 if ( qApp->thread() == QThread::currentThread() )
475 QMessageBox::critical( activeWindow(), tr(
"Exception" ), e.
what() );
477 catch ( std::exception &e )
479 qCritical() <<
"Caught unhandled std::exception: " << e.what();
480 if ( qApp->thread() == QThread::currentThread() )
481 QMessageBox::critical( activeWindow(), tr(
"Exception" ), e.what() );
485 qCritical() <<
"Caught unhandled unknown exception";
486 if ( qApp->thread() == QThread::currentThread() )
487 QMessageBox::critical( activeWindow(), tr(
"Exception" ), tr(
"unknown exception" ) );
495 return QgsRuntimeProfiler::threadLocalInstance();
501 ABISYM( mFileOpenEventReceiver ) = receiver;
503 if ( sFileOpenEventList()->count() > 0 )
505 const QStringList fileOpenEventList = *sFileOpenEventList();
506 for (
const QString &file : fileOpenEventList )
508 QFileOpenEvent foe( file );
509 QgsApplication::sendEvent( ABISYM( mFileOpenEventReceiver ), &foe );
511 sFileOpenEventList()->clear();
518 #if defined(Q_OS_WIN) 519 if ( sPrefixPath()->endsWith(
"/bin" ) )
521 sPrefixPath()->chop( 4 );
524 if ( useDefaultPaths && !ABISYM( mRunningFromBuildDir ) )
526 setPluginPath( *sPrefixPath() +
'/' + QStringLiteral( QGIS_PLUGIN_SUBDIR ) );
527 setPkgDataPath( *sPrefixPath() +
'/' + QStringLiteral( QGIS_DATA_SUBDIR ) );
529 *sLibraryPath() = *sPrefixPath() +
'/' + QGIS_LIB_SUBDIR +
'/';
530 *sLibexecPath() = *sPrefixPath() +
'/' + QGIS_LIBEXEC_SUBDIR +
'/';
531 #if defined( HAVE_QUICK ) 532 *sQmlImportPath() = *sPrefixPath() +
'/' + QGIS_QML_SUBDIR +
'/';
545 QString mySvgPath = pkgDataPath + QStringLiteral(
"/svg/" );
548 if ( !sDefaultSvgPaths()->contains( mySvgPath ) )
549 *sDefaultSvgPaths() << mySvgPath;
554 *sDefaultSvgPaths() = pathList;
559 QFileInfo fi( authDbDirPath );
560 if ( fi.exists() && fi.isDir() && fi.isWritable() )
562 *sAuthDbDirPath() = fi.canonicalFilePath() + QDir::separator();
569 if ( ABISYM( mRunningFromBuildDir ) )
571 static bool sOnce =
true;
575 ( void ) blockNotifications;
576 qWarning(
"!!! prefix path was requested, but it is not valid - we do not run from installed path !!!" );
582 return *sPrefixPath();
586 return *sPluginPath();
591 if ( sPkgDataPath()->isNull() )
594 return *sPkgDataPath();
599 return QStringLiteral(
":/images/themes/default/" );
604 QDir dir( usersThemes );
612 return defaultThemes;
618 return iconsPath() + QStringLiteral(
"qgis-icon-60x60.png" );
623 return ABISYM( sMaxThreads );
630 if ( QFile::exists( path + iconFile ) )
631 return path + iconFile;
640 if ( app && app->mIconCache.contains( name ) )
641 return app->mIconCache.value( name );
645 QString myPreferredPath =
activeThemePath() + QDir::separator() + name;
647 if ( QFile::exists( myPreferredPath ) )
649 icon = QIcon( myPreferredPath );
651 else if ( QFile::exists( myDefaultPath ) )
655 icon = QIcon( myDefaultPath );
663 app->mIconCache.insert( name, icon );
670 if ( app && app->mCursorCache.contains( cursor ) )
671 return app->mCursorCache.value( cursor );
682 name = QStringLiteral(
"mZoomIn.svg" );
687 name = QStringLiteral(
"mZoomOut.svg" );
694 name = QStringLiteral(
"mIdentify.svg" );
697 name = QStringLiteral(
"mCrossHair.svg" );
700 name = QStringLiteral(
"mCapturePoint.svg" );
703 name = QStringLiteral(
"mSelect.svg" );
710 name = QStringLiteral(
"mSampler.svg" );
715 Q_ASSERT( ! name.isEmpty( ) );
717 QIcon icon =
getThemeIcon( QStringLiteral(
"cursors" ) + QDir::separator() + name );
720 if ( ! icon.isNull( ) )
724 cursorIcon = QCursor( icon.pixmap( std::ceil( scale * 32 ), std::ceil( scale * 32 ) ), std::ceil( scale * activeX ), std::ceil( scale * activeY ) );
727 app->mCursorCache.insert( cursor, cursorIcon );
734 const QString preferredPath =
activeThemePath() + QDir::separator() + name;
736 const QString path = QFile::exists( preferredPath ) ? preferredPath : defaultPath;
737 if ( foreColor.isValid() || backColor.isValid() )
739 bool fitsInCache =
false;
740 const QImage image =
svgCache()->
svgAsImage( path, size, backColor, foreColor, 1, 1, fitsInCache );
741 return QPixmap::fromImage( image );
744 return QPixmap( path );
754 static QString appPath;
755 if ( appPath.isNull() )
757 if ( QCoreApplication::instance() )
759 appPath = applicationDirPath();
763 qWarning(
"Application path not initialized" );
767 if ( !appPath.isNull() || getenv(
"QGIS_PREFIX_PATH" ) )
769 QString prefix = getenv(
"QGIS_PREFIX_PATH" ) ? getenv(
"QGIS_PREFIX_PATH" ) : appPath;
774 static const QStringList paths { QStringList() << QString() << QStringLiteral(
"/.." ) << QStringLiteral(
"/bin" ) << QStringLiteral(
"/../../.." ) };
775 for (
const QString &path : paths )
777 f.setFileName( prefix + path +
"/qgisbuildpath.txt" );
781 if ( f.exists() && f.open( QIODevice::ReadOnly ) )
783 ABISYM( mRunningFromBuildDir ) =
true;
784 *sBuildSourcePath() = f.readLine().trimmed();
785 *sBuildOutputPath() = f.readLine().trimmed();
787 QgsDebugMsgLevel( QStringLiteral(
"- source directory: %1" ).arg( sBuildSourcePath()->toUtf8().constData() ), 4 );
788 QgsDebugMsgLevel( QStringLiteral(
"- output directory of the build: %1" ).arg( sBuildOutputPath()->toUtf8().constData() ), 4 );
789 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA) 790 *sCfgIntDir() = prefix.split(
'/', QString::SkipEmptyParts ).last();
791 qDebug(
"- cfg: %s", sCfgIntDir()->toUtf8().constData() );
797 if ( getenv(
"QGIS_PREFIX_PATH" ) )
798 prefixPath = getenv(
"QGIS_PREFIX_PATH" );
803 QDir dir( QDir::homePath() );
805 prefixPath = dir.absolutePath();
808 #if defined(Q_OS_MACX) 809 prefixPath = appPath;
810 #elif defined(Q_OS_WIN) 811 prefixPath = appPath;
812 if ( prefixPath.endsWith(
"/bin" ) )
813 prefixPath.chop( 4 );
817 if ( appPath.contains( QStringLiteral(
"cgi-bin" ) ) )
822 prefixPath = dir.absolutePath();
827 if ( ABISYM( mRunningFromBuildDir ) )
828 return *sBuildOutputPath() + QStringLiteral(
"/data" );
830 return prefixPath +
'/' + QStringLiteral( QGIS_DATA_SUBDIR );
835 return *sThemeName();
842 if ( themeName == QLatin1String(
"default" ) || !themes.contains( themeName ) )
845 qApp->setStyleSheet( QString() );
849 QString path = themes.value( themeName );
850 QString stylesheetname = path +
"/style.qss";
852 QFile file( stylesheetname );
853 QFile variablesfile( path +
"/variables.qss" );
855 QFileInfo variableInfo( variablesfile );
857 if ( !file.open( QIODevice::ReadOnly ) || ( variableInfo.exists() && !variablesfile.open( QIODevice::ReadOnly ) ) )
862 QString styledata = file.readAll();
863 styledata.replace( QLatin1String(
"@theme_path" ), path );
865 if ( variableInfo.exists() )
867 QTextStream in( &variablesfile );
868 while ( !in.atEnd() )
870 QString line = in.readLine();
872 if ( line.startsWith(
'@' ) )
874 int index = line.indexOf(
':' );
875 QString name = line.mid( 0, index );
876 QString value = line.mid( index + 1, line.length() );
877 styledata.replace( name, value );
880 variablesfile.close();
888 const static QRegularExpression regex( QStringLiteral(
"(?<=[\\s:])([0-9\\.]+)(?=em)" ) );
889 QRegularExpressionMatch match = regex.match( styledata, index );
890 while ( match.hasMatch() )
892 index = match.capturedStart();
893 styledata.remove( index, match.captured( 0 ).length() );
895 styledata.insert( index, number );
896 index += number.length();
897 match = regex.match( styledata, index );
901 qApp->setStyleSheet( styledata );
903 QFile palettefile( path +
"/palette.txt" );
904 QFileInfo paletteInfo( palettefile );
905 if ( paletteInfo.exists() && palettefile.open( QIODevice::ReadOnly ) )
907 QPalette
pal = qApp->palette();
908 QTextStream in( &palettefile );
909 while ( !in.atEnd() )
911 QString line = in.readLine();
912 QStringList parts = line.split(
':' );
913 if ( parts.count() == 2 )
915 int role = parts.at( 0 ).trimmed().toInt();
917 pal.setColor( static_cast< QPalette::ColorRole >( role ), color );
921 qApp->setPalette( pal );
930 QHash<QString, QString> mapping;
931 mapping.insert( QStringLiteral(
"default" ), QString() );
932 const auto constPaths = paths;
933 for (
const QString &path : constPaths )
936 QFileInfoList styleFiles = folder.entryInfoList( QDir::Dirs | QDir::NoDotAndDotDot );
937 const auto constStyleFiles = styleFiles;
938 for (
const QFileInfo &info : constStyleFiles )
940 QFileInfo styleFile( info.absoluteFilePath() +
"/style.qss" );
941 if ( !styleFile.exists() )
944 QString name = info.baseName();
945 QString path = info.absoluteFilePath();
946 mapping.insert( name, path );
954 return pkgDataPath() + QStringLiteral(
"/doc/AUTHORS" );
959 return pkgDataPath() + QStringLiteral(
"/doc/CONTRIBUTORS" );
963 return pkgDataPath() + QStringLiteral(
"/doc/developersmap.html" );
968 return pkgDataPath() + QStringLiteral(
"/doc/SPONSORS" );
973 return pkgDataPath() + QStringLiteral(
"/doc/DONORS" );
978 return pkgDataPath() + QStringLiteral(
"/doc/TRANSLATORS" );
983 return pkgDataPath() + QStringLiteral(
"/doc/LICENSE" );
988 if ( ABISYM( mRunningFromBuildDir ) )
989 return *sBuildOutputPath() + QStringLiteral(
"/i18n/" );
996 return pkgDataPath() + QStringLiteral(
"/resources/metadata-ISO/" );
1001 return pkgDataPath() + QStringLiteral(
"/resources/qgis.db" );
1006 return *sConfigPath();
1016 return *sAuthDbDirPath() + QStringLiteral(
"qgis-auth.db" );
1021 return QStringLiteral(
":/images/splash/" );
1026 return pkgDataPath() + QStringLiteral(
"/images/icons/" );
1031 if ( ABISYM( mRunningFromBuildDir ) )
1033 #if PROJ_VERSION_MAJOR>=6 1034 QString tempCopy = QDir::tempPath() +
"/srs6.db";
1036 QString tempCopy = QDir::tempPath() +
"/srs.db";
1039 if ( !QFile( tempCopy ).exists() )
1041 #if PROJ_VERSION_MAJOR>=6 1046 if ( !f.copy( tempCopy ) )
1048 qFatal(
"Could not create temporary copy" );
1056 return pkgDataPath() + QStringLiteral(
"/resources/srs.db" );
1063 members()->mSvgPathCacheValid =
false;
1068 static QReadWriteLock lock;
1072 if ( members()->mSvgPathCacheValid )
1074 return members()->mSvgPathCache;
1082 const QStringList pathList = settings.
value( QStringLiteral(
"svg/searchPathsForSVG" ) ).toStringList();
1086 for (
const QString &path : pathList )
1088 if ( !paths.contains( path ) )
1089 paths.append( path );
1091 for (
const QString &path : qgis::as_const( *sDefaultSvgPaths() ) )
1093 if ( !paths.contains( path ) )
1094 paths.append( path );
1096 members()->mSvgPathCache = paths;
1107 QStringList pathList = settings.
value( QStringLiteral(
"Layout/searchPathsForTemplates" ), QVariant(),
QgsSettings::Core ).toStringList();
1114 return *sSystemEnvVars();
1124 const thread_local QRegExp regexp( QStringLiteral(
"^[A-Za-z][A-Za-z0-9\\._-]*" ) );
1130 if ( !sUserName()->isEmpty() )
1131 return *sUserName();
1134 TCHAR name [ UNLEN + 1 ];
1135 DWORD size = UNLEN + 1;
1137 if ( GetUserName( ( TCHAR * )name, &size ) )
1139 *sUserName() = QString::fromLocal8Bit( name );
1142 #elif QT_CONFIG(process) 1145 process.start( QStringLiteral(
"whoami" ), QStringList() );
1146 process.waitForFinished();
1147 *sUserName() = process.readAllStandardOutput().trimmed();
1150 if ( !sUserName()->isEmpty() )
1151 return *sUserName();
1154 *sUserName() = qgetenv(
"USER" );
1155 if ( !sUserName()->isEmpty() )
1156 return *sUserName();
1159 *sUserName() = qgetenv(
"USERNAME" );
1160 return *sUserName();
1165 if ( !sUserFullName()->isEmpty() )
1166 return *sUserFullName();
1169 TCHAR name [ UNLEN + 1 ];
1170 DWORD size = UNLEN + 1;
1173 if ( GetUserNameEx( NameDisplay, ( TCHAR * )name, &size ) )
1175 *sUserFullName() = QString::fromLocal8Bit( name );
1179 if ( sUserFullName()->isEmpty() )
1181 #elif defined(Q_OS_ANDROID) || defined(__MINGW32__) 1182 *sUserFullName() = QStringLiteral(
"Not available" );
1184 struct passwd *p = getpwuid( getuid() );
1188 QString gecosName = QString( p->pw_gecos );
1189 *sUserFullName() = gecosName.left( gecosName.indexOf(
',', 0 ) );
1194 return *sUserFullName();
1199 #if defined(Q_OS_ANDROID) 1200 return QLatin1String(
"android" );
1201 #elif defined(Q_OS_MAC) 1202 return QLatin1String(
"osx" );
1203 #elif defined(Q_OS_WIN) 1204 return QLatin1String(
"windows" );
1205 #elif defined(Q_OS_LINUX) 1206 return QStringLiteral(
"linux" );
1207 #elif defined(Q_OS_FREEBSD) 1208 return QStringLiteral(
"freebsd" );
1209 #elif defined(Q_OS_OPENBSD) 1210 return QStringLiteral(
"openbsd" );
1211 #elif defined(Q_OS_NETBSD) 1212 return QStringLiteral(
"netbsd" );
1213 #elif defined(Q_OS_UNIX) 1214 return QLatin1String(
"unix" );
1216 return QLatin1String(
"unknown" );
1222 return *sPlatformName();
1228 bool overrideLocale = settings.
value( QStringLiteral(
"locale/overrideFlag" ),
false ).toBool();
1229 if ( overrideLocale )
1231 QString
locale = settings.
value( QStringLiteral(
"locale/userLocale" ), QString() ).toString();
1233 if ( locale.startsWith( QLatin1String(
"en" ), Qt::CaseInsensitive ) )
1235 return locale.left( 2 );
1242 return QLocale().name().left( 2 );
1253 return pkgDataPath() + QStringLiteral(
"/resources/symbology-style.xml" );
1258 return pkgDataPath() + QStringLiteral(
"/resources/themes" );
1263 return pkgDataPath() + QStringLiteral(
"/resources/server/" );
1268 return *sLibraryPath();
1273 return *sLibexecPath();
1278 return *sQmlImportPath();
1283 return ( htonl( 1 ) == 1 ) ?
XDR :
NDR;
1290 init( *sProfilePath() );
1315 if (
auto *lInstance =
instance() )
1317 if ( !lInstance->mAuthManager )
1321 return lInstance->mAuthManager;
1326 if ( !sAuthManager )
1328 return sAuthManager;
1336 QThreadPool::globalInstance()->waitForDone();
1339 if (
auto *lInstance =
instance() )
1340 delete lInstance->mAuthManager;
1342 delete sAuthManager;
1347 QgsApplication::sendPostedEvents(
nullptr, QEvent::DeferredDelete );
1355 if ( QgsProviderRegistry::exists() )
1364 GDALDestroyDriverManager();
1369 QString myEnvironmentVar( getenv(
"QGIS_PREFIX_PATH" ) );
1370 QString myState = tr(
"Application state:\n" 1371 "QGIS_PREFIX_PATH env var:\t\t%1\n" 1373 "Plugin Path:\t\t%3\n" 1374 "Package Data Path:\t%4\n" 1375 "Active Theme Name:\t%5\n" 1376 "Active Theme Path:\t%6\n" 1377 "Default Theme Path:\t%7\n" 1378 "SVG Search Paths:\t%8\n" 1379 "User DB Path:\t%9\n" 1380 "Auth DB Path:\t%10\n" )
1381 .arg( myEnvironmentVar,
1388 svgPaths().join( tr(
"\n\t\t",
"match indentation of application state" ) ),
1401 QColor myColor1( Qt::lightGray );
1402 QColor myColor2 = myColor1;
1403 myColor2 = myColor2.lighter( 110 );
1405 myStyle = QStringLiteral(
".overview{" 1407 " font-weight: bold;" 1410 " background: white;" 1412 " font-family: 'Lato', 'Ubuntu', 'Lucida Grande', 'Segoe UI', 'Arial', sans-serif;" 1415 "h1{ background-color: #F6F6F6;" 1417 " font-size: x-large; " 1418 " font-weight: normal;" 1419 " background: none;" 1420 " padding: 0.75em 0 0;" 1422 " line-height: 3em;" 1424 "h2{ background-color: #F6F6F6;" 1426 " font-size: medium; " 1427 " font-weight: normal;" 1428 " background: none;" 1429 " padding: 0.75em 0 0;" 1431 " line-height: 1.1em;" 1433 "h3{ background-color: #F6F6F6;" 1435 " font-weight: bold;" 1436 " font-size: large;" 1437 " text-align: left;" 1438 " border-bottom: 5px solid #DCEB5C;" 1440 "h4{ background-color: #F6F6F6;" 1442 " font-weight: bold;" 1443 " font-size: medium;" 1444 " text-align: left;" 1446 "h5{ background-color: #F6F6F6;" 1448 " font-weight: bold;" 1449 " font-size: small;" 1450 " text-align: left;" 1452 "a{ color: #729FCF;" 1453 " font-family: arial,sans-serif;" 1455 "label{ background-color: #FFFFCC;" 1456 " border: 1px solid black;" 1458 " padding: 0px 3px; " 1459 " font-size: small;" 1462 " font-weight: bold;" 1467 " border-top: 1px solid black;" 1469 ".list-view .highlight {" 1470 " text-align: left;" 1473 " padding-right: 15px;" 1474 " padding-left: 20px;" 1475 " font-weight: bold;" 1477 ".tabular-view .odd-row {" 1478 " background-color: #f9f9f9;" 1481 " font-weight: bold;" 1482 " padding-top:25px;" 1486 switch ( styleSheetType )
1488 case StyleSheetType::Qt:
1489 myStyle += QStringLiteral(
1491 " border-collapse: collapse;" 1494 ".tabular-view th, .tabular-view td { " 1495 " border:1px solid black;" 1499 case StyleSheetType::WebBrowser:
1500 myStyle += QStringLiteral(
1505 "table.tabular-view, table.list-view { " 1506 " border-collapse: collapse;" 1507 " table-layout:fixed;" 1508 " width: 100% !important;" 1513 " line-height: inherit;" 1516 " word-wrap: break-word; " 1517 " vertical-align: top;" 1520 ".list-view th:first-child, .list-view td:first-child {" 1523 ".list-view.highlight { " 1524 " padding-left: inherit; " 1527 ".tabular-view th:first-child, .tabular-view td:first-child { " 1531 ".tabular-view th.strong { " 1532 " background-color: #eee; " 1535 ".tabular-view th, .tabular-view td { " 1536 " border: 1px solid #eee;" 1547 if ( 0 >= OGRGetDriverCount() )
1555 QString aPathUrl = aPath;
1556 QString tPathUrl = targetPath;
1557 #if defined( Q_OS_WIN ) 1558 const Qt::CaseSensitivity cs = Qt::CaseInsensitive;
1560 aPathUrl.replace(
'\\',
'/' );
1561 if ( aPathUrl.startsWith(
"//" ) )
1564 aPathUrl =
"\\\\" + aPathUrl.mid( 2 );
1567 tPathUrl.replace(
'\\',
'/' );
1568 if ( tPathUrl.startsWith(
"//" ) )
1571 tPathUrl =
"\\\\" + tPathUrl.mid( 2 );
1574 const Qt::CaseSensitivity cs = Qt::CaseSensitive;
1577 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) 1578 QStringList targetElems = tPathUrl.split(
'/', QString::SkipEmptyParts );
1579 QStringList aPathElems = aPathUrl.split(
'/', QString::SkipEmptyParts );
1581 QStringList targetElems = tPathUrl.split(
'/', Qt::SkipEmptyParts );
1582 QStringList aPathElems = aPathUrl.split(
'/', Qt::SkipEmptyParts );
1585 targetElems.removeAll( QStringLiteral(
"." ) );
1586 aPathElems.removeAll( QStringLiteral(
"." ) );
1590 while ( !aPathElems.isEmpty() &&
1591 !targetElems.isEmpty() &&
1592 aPathElems[0].compare( targetElems[0], cs ) == 0 )
1594 aPathElems.removeFirst();
1595 targetElems.removeFirst();
1605 if ( !targetElems.isEmpty() )
1608 for (
int i = 0; i < targetElems.size(); i++ )
1610 aPathElems.insert( 0, QStringLiteral(
".." ) );
1617 aPathElems.insert( 0, QStringLiteral(
"." ) );
1620 return aPathElems.join( QLatin1Char(
'/' ) );
1626 if ( !rpath.startsWith( QLatin1String(
"./" ) ) && !rpath.startsWith( QLatin1String(
"../" ) ) )
1631 QString rPathUrl = rpath;
1632 QString targetPathUrl = targetPath;
1634 #if defined(Q_OS_WIN) 1635 rPathUrl.replace(
'\\',
'/' );
1636 targetPathUrl.replace(
'\\',
'/' );
1638 bool uncPath = targetPathUrl.startsWith(
"//" );
1641 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) 1642 QStringList srcElems = rPathUrl.split(
'/', QString::SkipEmptyParts );
1643 QStringList targetElems = targetPathUrl.split(
'/', QString::SkipEmptyParts );
1645 QStringList srcElems = rPathUrl.split(
'/', Qt::SkipEmptyParts );
1646 QStringList targetElems = targetPathUrl.split(
'/', Qt::SkipEmptyParts );
1649 #if defined(Q_OS_WIN) 1652 targetElems.insert( 0,
"" );
1653 targetElems.insert( 0,
"" );
1658 targetElems << srcElems;
1659 targetElems.removeAll( QStringLiteral(
"." ) );
1663 while ( ( pos = targetElems.indexOf( QLatin1String(
".." ) ) ) > 0 )
1666 targetElems.removeAt( pos - 1 );
1667 targetElems.removeAt( pos - 1 );
1670 #if !defined(Q_OS_WIN) 1672 targetElems.prepend( QString() );
1675 return targetElems.join( QLatin1Char(
'/' ) );
1680 return *sBuildSourcePath();
1685 return *sBuildOutputPath();
1688 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA) 1689 QString QgsApplication::cfgIntDir()
1691 return *sCfgIntDir();
1697 if ( sGdalSkipList()->contains( driver ) || driver.isEmpty() )
1701 *sGdalSkipList() << driver;
1707 if ( !sGdalSkipList()->contains( driver ) )
1711 int myPos = sGdalSkipList()->indexOf( driver );
1714 sGdalSkipList()->removeAt( myPos );
1721 return *sGdalSkipList();
1731 settings.
setValue( QStringLiteral(
"gdal/skipDrivers" ), skippedGdalDrivers.join( QLatin1Char(
',' ) ) );
1739 QString joinedList, delimiter;
1740 if ( settings.
contains( QStringLiteral(
"gdal/skipDrivers" ) ) )
1742 joinedList = settings.
value( QStringLiteral(
"gdal/skipDrivers" ), QString() ).toString();
1743 delimiter = QStringLiteral(
"," );
1747 joinedList = settings.
value( QStringLiteral(
"gdal/skipList" ), QString() ).toString();
1748 delimiter = QStringLiteral(
" " );
1751 if ( !joinedList.isEmpty() )
1753 myList = joinedList.split( delimiter );
1755 *sGdalSkipList() = myList;
1761 return *sDeferredSkippedGdalDrivers();
1766 sGdalSkipList()->removeDuplicates();
1767 QStringList realDisabledDriverList;
1768 for (
const auto &driverName : *sGdalSkipList() )
1770 if ( !sDeferredSkippedGdalDrivers()->contains( driverName ) )
1771 realDisabledDriverList << driverName;
1773 QString myDriverList = realDisabledDriverList.join(
',' );
1774 QgsDebugMsgLevel( QStringLiteral(
"Gdal Skipped driver list set to:" ), 2 );
1776 CPLSetConfigOption(
"GDAL_SKIP", myDriverList.toUtf8() );
1783 QDir myDir( folder );
1784 if ( !myDir.exists() )
1786 myDir.mkpath( folder );
1792 void QgsApplication::copyPath(
const QString &src,
const QString &dst )
1795 if ( ! dir.exists() )
1798 const auto subDirectories = dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot );
1799 for (
const QString &d : subDirectories )
1801 QString dst_path = dst + QDir::separator() + d;
1802 dir.mkpath( dst_path );
1803 copyPath( src + QDir::separator() + d, dst_path );
1806 const auto files = dir.entryList( QDir::Files );
1807 for (
const QString &f : files )
1809 QFile::copy( src + QDir::separator() + f, dst + QDir::separator() + f );
1818 QVariantMap variables;
1822 QStringList childKeys = settings.
childKeys();
1823 for ( QStringList::const_iterator it = childKeys.constBegin(); it != childKeys.constEnd(); ++it )
1826 variables.insert( name, settings.
value( name ) );
1836 QVariantMap::const_iterator it = variables.constBegin();
1839 for ( ; it != variables.constEnd(); ++it )
1841 settings.
setValue( it.key(), it.value() );
1852 settings.
setValue( QStringLiteral(
"variables/" ) + name, value );
1859 QFontMetrics fm( ( QFont() ) );
1860 const double scale = 1.1 * standardSize / 24;
1861 int scaledIconSize =
static_cast< int >( std::floor( std::max(
Qgis::UI_SCALE_FACTOR * fm.height() * scale,
static_cast< double >( standardSize ) ) ) );
1862 if ( applyDevicePixelRatio && QApplication::desktop() )
1863 scaledIconSize *= QApplication::desktop()->devicePixelRatio();
1864 return scaledIconSize;
1874 *sTranslation() = translation;
1884 ApplicationMembers *appMembers = members();
1885 if ( appMembers->mNullRepresentation.isNull() )
1887 appMembers->mNullRepresentation =
QgsSettings().
value( QStringLiteral(
"qgis/nullValue" ), QStringLiteral(
"NULL" ) ).toString();
1889 return appMembers->mNullRepresentation;
1894 ApplicationMembers *appMembers = members();
1895 if ( !appMembers || appMembers->mNullRepresentation == nullRepresentation )
1908 return members()->mActionScopeRegistry;
1917 QDir myDir( myPamPath );
1918 if ( !myDir.exists() )
1920 myDir.mkpath( myPamPath );
1923 #if defined(Q_OS_WIN) 1924 CPLSetConfigOption(
"GDAL_PAM_PROXY_DIR", myPamPath.toUtf8() );
1928 int myChangeFlag = 0;
1929 setenv(
"GDAL_PAM_PROXY_DIR", myPamPath.toUtf8(), myChangeFlag );
1936 if ( !qgisPrivateDbFile.exists() )
1940 QFile masterFile( qgisMasterDbFileName );
1946 bool isDbFileCopied = masterFile.copy( qgisPrivateDbFile.fileName() );
1948 if ( !isDbFileCopied )
1952 *errorMessage = tr(
"[ERROR] Can not make qgis.db private copy" );
1957 QFile::Permissions perms = QFile( qgisPrivateDbFile.fileName() ).permissions();
1958 if ( !( perms & QFile::WriteOwner ) )
1960 if ( !qgisPrivateDbFile.setPermissions( perms | QFile::WriteOwner ) )
1964 *errorMessage = tr(
"Can not make '%1' user writable" ).arg( qgisPrivateDbFile.fileName() );
1978 *errorMessage = tr(
"Could not open qgis.db" );
1983 char *errmsg =
nullptr;
1984 int res = sqlite3_exec( database.get(),
"SELECT srs_id FROM tbl_srs LIMIT 0",
nullptr,
nullptr, &errmsg );
1985 if ( res != SQLITE_OK )
1987 sqlite3_free( errmsg );
1990 if ( sqlite3_exec( database.get(),
1991 "DROP INDEX IF EXISTS idx_srsauthid;" 1992 "CREATE TABLE tbl_srs (" 1993 "srs_id INTEGER PRIMARY KEY," 1994 "description text NOT NULL," 1995 "projection_acronym text NOT NULL," 1996 "ellipsoid_acronym NOT NULL," 1997 "parameters text NOT NULL," 1999 "auth_name varchar," 2001 "is_geo integer NOT NULL," 2002 "deprecated boolean," 2004 "CREATE INDEX idx_srsauthid on tbl_srs(auth_name,auth_id);",
nullptr,
nullptr, &errmsg ) != SQLITE_OK )
2008 *errorMessage = tr(
"Creation of missing tbl_srs in the private qgis.db failed.\n%1" ).arg( QString::fromUtf8( errmsg ) );
2010 sqlite3_free( errmsg );
2017 res = sqlite3_exec( database.get(),
"SELECT wkt FROM tbl_srs LIMIT 0",
nullptr,
nullptr, &errmsg );
2018 if ( res != SQLITE_OK )
2021 sqlite3_free( errmsg );
2022 if ( sqlite3_exec( database.get(),
2023 "DROP INDEX IF EXISTS idx_srsauthid;" 2024 "DROP TABLE IF EXISTS tbl_srs_bak;" 2025 "ALTER TABLE tbl_srs RENAME TO tbl_srs_bak;" 2026 "CREATE TABLE tbl_srs (" 2027 "srs_id INTEGER PRIMARY KEY," 2028 "description text NOT NULL," 2029 "projection_acronym text NOT NULL," 2030 "ellipsoid_acronym NOT NULL," 2031 "parameters text NOT NULL," 2033 "auth_name varchar," 2035 "is_geo integer NOT NULL," 2036 "deprecated boolean," 2038 "CREATE INDEX idx_srsauthid on tbl_srs(auth_name,auth_id);" 2039 "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;" 2040 "DROP TABLE tbl_srs_bak",
nullptr,
nullptr, &errmsg ) != SQLITE_OK )
2044 *errorMessage = tr(
"Migration of private qgis.db failed.\n%1" ).arg( QString::fromUtf8( errmsg ) );
2046 sqlite3_free( errmsg );
2052 res = sqlite3_exec( database.get(),
"SELECT acronym FROM tbl_projection LIMIT 0",
nullptr,
nullptr, &errmsg );
2053 if ( res != SQLITE_OK )
2055 sqlite3_free( errmsg );
2058 if ( sqlite3_exec( database.get(),
2059 "CREATE TABLE tbl_projection (" 2060 "acronym varchar(20) NOT NULL PRIMARY KEY," 2061 "name varchar(255) NOT NULL default ''," 2062 "notes varchar(255) NOT NULL default ''," 2063 "parameters varchar(255) NOT NULL default ''" 2064 ")",
nullptr,
nullptr, &errmsg ) != SQLITE_OK )
2068 *errorMessage = tr(
"Creation of missing tbl_projection in the private qgis.db failed.\n%1" ).arg( QString::fromUtf8( errmsg ) );
2070 sqlite3_free( errmsg );
2075 res = sqlite3_exec( database.get(),
"SELECT epsg FROM tbl_srs LIMIT 0",
nullptr,
nullptr, &errmsg );
2076 if ( res == SQLITE_OK )
2079 if ( sqlite3_exec( database.get(),
2080 "DROP INDEX IF EXISTS idx_srsauthid;" 2081 "DROP TABLE IF EXISTS tbl_srs_bak;" 2082 "ALTER TABLE tbl_srs RENAME TO tbl_srs_bak;" 2083 "CREATE TABLE tbl_srs (" 2084 "srs_id INTEGER PRIMARY KEY," 2085 "description text NOT NULL," 2086 "projection_acronym text NOT NULL," 2087 "ellipsoid_acronym NOT NULL," 2088 "parameters text NOT NULL," 2090 "auth_name varchar," 2092 "is_geo integer NOT NULL," 2093 "deprecated boolean," 2095 "CREATE INDEX idx_srsauthid on tbl_srs(auth_name,auth_id);" 2096 "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;" 2097 "DROP TABLE tbl_srs_bak",
nullptr,
nullptr, &errmsg ) != SQLITE_OK )
2101 *errorMessage = tr(
"Migration of private qgis.db failed.\n%1" ).arg( QString::fromUtf8( errmsg ) );
2103 sqlite3_free( errmsg );
2109 sqlite3_free( errmsg );
2112 if ( sqlite3_exec( database.get(),
"DROP VIEW vw_srs",
nullptr,
nullptr, &errmsg ) != SQLITE_OK )
2114 QgsDebugMsg( QStringLiteral(
"vw_srs didn't exists in private qgis.db: %1" ).arg( errmsg ) );
2117 if ( sqlite3_exec( database.get(),
2118 "CREATE VIEW vw_srs AS" 2120 " a.description AS description" 2121 ",a.srs_id AS srs_id" 2122 ",a.is_geo AS is_geo" 2123 ",coalesce(b.name,a.projection_acronym) AS name" 2124 ",a.parameters AS parameters" 2125 ",a.auth_name AS auth_name" 2126 ",a.auth_id AS auth_id" 2127 ",a.deprecated AS deprecated" 2129 " LEFT OUTER JOIN tbl_projection b ON a.projection_acronym=b.acronym" 2130 " ORDER BY coalesce(b.name,a.projection_acronym),a.description",
nullptr,
nullptr, &errmsg ) != SQLITE_OK )
2134 *errorMessage = tr(
"Update of view in private qgis.db failed.\n%1" ).arg( QString::fromUtf8( errmsg ) );
2136 sqlite3_free( errmsg );
2145 QgsDebugMsgLevel( QStringLiteral(
"maxThreads: %1" ).arg( maxThreads ), 2 );
2149 if ( maxThreads < 1 || maxThreads > QThread::idealThreadCount() )
2156 if ( maxThreads == -1 )
2157 maxThreads = QThread::idealThreadCount();
2160 QThreadPool::globalInstance()->setMaxThreadCount( maxThreads );
2161 QgsDebugMsgLevel( QStringLiteral(
"set QThreadPool max thread count to %1" ).arg( QThreadPool::globalInstance()->maxThreadCount() ), 2 );
2166 return members()->mTaskManager;
2171 return members()->mColorSchemeRegistry;
2176 return members()->mPaintEffectRegistry;
2181 return members()->mRendererRegistry;
2186 return members()->mRasterRendererRegistry;
2191 return members()->mPointCloudRendererRegistry;
2196 if (
auto *lInstance =
instance() )
2198 if ( !
instance()->mDataItemProviderRegistry )
2202 return lInstance->mDataItemProviderRegistry;
2208 if ( !sDataItemProviderRegistry )
2210 return sDataItemProviderRegistry;
2216 return members()->mSvgCache;
2221 return members()->mImageCache;
2226 return members()->mSourceCache;
2231 return members()->mNetworkContentFetcherRegistry;
2236 return members()->mValidityCheckRegistry;
2241 return members()->mSymbolLayerRegistry;
2246 return members()->mCalloutRegistry;
2251 return members()->mLayoutItemRegistry;
2256 return members()->mAnnotationItemRegistry;
2261 return members()->mGpsConnectionRegistry;
2266 return members()->mPluginLayerRegistry;
2271 return members()->mClassificationMethodRegistry;
2276 return members()->mBookmarkManager;
2281 return members()->mStyleModel;
2286 return members()->mMessageLog;
2291 return members()->mProcessingRegistry;
2296 return members()->mConnectionRegistry;
2301 return members()->mPageSizeRegistry;
2306 return members()->mAnnotationRegistry;
2311 return members()->mNumericFormatRegistry;
2316 return members()->mFieldFormatterRegistry;
2321 return members()->m3DRendererRegistry;
2326 return members()->m3DSymbolRegistry;
2331 return members()->mScaleBarRendererRegistry;
2336 return members()->mProjectStorageRegistry;
2341 return members()->mLocalizedDataPathRegistry;
2344 QgsApplication::ApplicationMembers::ApplicationMembers()
2353 profiler->
start( tr(
"Create connection registry" ) );
2358 profiler->
start( tr(
"Setup task manager" ) );
2363 profiler->
start( tr(
"Setup action scope registry" ) );
2368 profiler->
start( tr(
"Setup numeric formats" ) );
2373 profiler->
start( tr(
"Setup field formats" ) );
2378 profiler->
start( tr(
"Setup SVG cache" ) );
2383 profiler->
start( tr(
"Setup image cache" ) );
2388 profiler->
start( tr(
"Setup source cache" ) );
2393 profiler->
start( tr(
"Setup color scheme registry" ) );
2398 profiler->
start( tr(
"Setup paint effect" ) );
2403 profiler->
start( tr(
"Setup symbol layer registry" ) );
2408 profiler->
start( tr(
"Setup callout registry" ) );
2413 profiler->
start( tr(
"Setup renderer registry" ) );
2418 profiler->
start( tr(
"Setup raster renderer registry" ) );
2423 profiler->
start( tr(
"Setup point cloud renderer registry" ) );
2428 profiler->
start( tr(
"Setup GPS registry" ) );
2433 profiler->
start( tr(
"Setup plugin layer registry" ) );
2438 profiler->
start( tr(
"Setup Processing registry" ) );
2444 profiler->
start( tr(
"Setup layout item registry" ) );
2446 mLayoutItemRegistry->populate();
2450 profiler->
start( tr(
"Setup annotation registry" ) );
2451 mAnnotationRegistry =
new QgsAnnotationRegistry();
2455 profiler->
start( tr(
"Setup annotation item registry" ) );
2457 mAnnotationItemRegistry->populate();
2461 profiler->
start( tr(
"Setup 3D symbol registry" ) );
2466 profiler->
start( tr(
"Setup 3D renderer registry" ) );
2471 profiler->
start( tr(
"Setup project storage registry" ) );
2476 profiler->
start( tr(
"Setup network content cache" ) );
2481 profiler->
start( tr(
"Setup layout check registry" ) );
2486 profiler->
start( tr(
"Setup classification registry" ) );
2491 profiler->
start( tr(
"Setup bookmark manager" ) );
2496 profiler->
start( tr(
"Setup scalebar registry" ) );
2502 QgsApplication::ApplicationMembers::~ApplicationMembers()
2505 delete mScaleBarRendererRegistry;
2506 delete mValidityCheckRegistry;
2507 delete mActionScopeRegistry;
2508 delete m3DRendererRegistry;
2509 delete m3DSymbolRegistry;
2510 delete mAnnotationRegistry;
2511 delete mColorSchemeRegistry;
2512 delete mFieldFormatterRegistry;
2513 delete mGpsConnectionRegistry;
2515 delete mPaintEffectRegistry;
2516 delete mPluginLayerRegistry;
2517 delete mProcessingRegistry;
2518 delete mProjectStorageRegistry;
2519 delete mPageSizeRegistry;
2520 delete mAnnotationItemRegistry;
2521 delete mLayoutItemRegistry;
2522 delete mPointCloudRendererRegistry;
2523 delete mRasterRendererRegistry;
2524 delete mRendererRegistry;
2527 delete mSourceCache;
2528 delete mCalloutRegistry;
2529 delete mSymbolLayerRegistry;
2530 delete mTaskManager;
2531 delete mNetworkContentFetcherRegistry;
2532 delete mClassificationMethodRegistry;
2533 delete mNumericFormatRegistry;
2534 delete mBookmarkManager;
2535 delete mConnectionRegistry;
2536 delete mLocalizedDataPathRegistry;
2539 QgsApplication::ApplicationMembers *QgsApplication::members()
2541 if (
auto *lInstance =
instance() )
2543 return lInstance->mApplicationMembers;
2547 static QMutex sMemberMutex( QMutex::Recursive );
2548 QMutexLocker lock( &sMemberMutex );
2549 if ( !sApplicationMembers )
2550 sApplicationMembers =
new ApplicationMembers();
2551 return sApplicationMembers;
static QStringList layoutTemplatePaths()
Returns the paths to layout template directories.
A QAbstractItemModel subclass for showing symbol and color ramp entities contained within a QgsStyle ...
Singleton offering an interface to manage the authentication configuration database and to utilize co...
static QString locale()
Returns the QGIS locale.
static QgsSymbolLayerRegistry * symbolLayerRegistry()
Returns the application's symbol layer registry, used for managing symbol layers. ...
static QgsSvgCache * svgCache()
Returns the application's SVG cache, used for caching SVG images and handling parameter replacement w...
This class keeps a list of data item providers that may add items to the browser tree.
static QString buildSourcePath()
Returns path to the source directory. Valid only when running from build directory.
static QgsAnnotationItemRegistry * annotationItemRegistry()
Returns the application's annotation item registry, used for annotation item types.
static void setThemeName(const QString &themeName)
Set the active theme to the specified theme.
void addDefaultSchemes()
Adds all default color schemes to this color scheme.
static Qgs3DRendererRegistry * renderer3DRegistry()
Returns registry of available 3D renderers.
Q_GLOBAL_STATIC_WITH_ARGS(PalPropertyList, palHiddenProperties,({ QgsPalLayerSettings::PositionX, QgsPalLayerSettings::PositionY, QgsPalLayerSettings::Show, QgsPalLayerSettings::LabelRotation, QgsPalLayerSettings::Family, QgsPalLayerSettings::FontStyle, QgsPalLayerSettings::Size, QgsPalLayerSettings::Bold, QgsPalLayerSettings::Italic, QgsPalLayerSettings::Underline, QgsPalLayerSettings::Color, QgsPalLayerSettings::Strikeout, QgsPalLayerSettings::MultiLineAlignment, QgsPalLayerSettings::BufferSize, QgsPalLayerSettings::BufferDraw, QgsPalLayerSettings::BufferColor, QgsPalLayerSettings::LabelDistance, QgsPalLayerSettings::Hali, QgsPalLayerSettings::Vali, QgsPalLayerSettings::ScaleVisibility, QgsPalLayerSettings::MinScale, QgsPalLayerSettings::MaxScale, QgsPalLayerSettings::AlwaysShow, QgsPalLayerSettings::CalloutDraw, QgsPalLayerSettings::LabelAllParts })) QgsAuxiliaryLayer
static QgsCalloutRegistry * calloutRegistry()
Returns the application's callout registry, used for managing callout types.
Provides a method of recording run time profiles of operations, allowing easy recording of their over...
static QString resolveProfilesFolder(const QString &basePath=QString())
Resolves the profiles folder for the given path.
static QgsAnnotationRegistry * annotationRegistry()
Returns the application's annotation registry, used for managing annotation types.
static void invalidateCache(bool disableCache=false)
Clears the internal cache used.
Extends QApplication to provide access to QGIS specific resources such as theme paths, database paths etc.
static QgsFieldFormatterRegistry * fieldFormatterRegistry()
Gets the registry of available field formatters.
Scoped object for logging of the runtime for a single operation or group of operations.
Cursor
The Cursor enum defines constants for QGIS custom cursors.
static QString userStylePath()
Returns the path to user's style.
Registry of color schemes.
static QgsAuthManager * instance()
Enforce singleton pattern.
static QgsApplication * instance()
Returns the singleton instance of the QgsApplication.
static QString authorsFilePath()
Returns the path to the authors file.
static void setPrefixPath(const QString &prefixPath, bool useDefaultPaths=false)
Alters prefix path - used by 3rd party apps.
A registry of plugin layers types.
static QString qgisSettingsDirPath()
Returns the path to the settings directory in user's home dir.
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 > ¶meters=QMap< QString, QString >())
Returns an SVG drawing as a QImage.
static void invalidateCache(bool disableCache=false)
Clears the internal cache used to initialize QgsCoordinateReferenceSystem objects.
Registry of available 3D symbol classes.
static void setCustomVariables(const QVariantMap &customVariables)
Custom expression variables for this application.
static QString libraryPath()
Returns the path containing qgis_core, qgis_gui, qgispython (and other) libraries.
static QgsRuntimeProfiler * profiler()
Returns the application runtime profiler.
static QString defaultThemePath()
Returns the path to the default theme directory.
static const double UI_SCALE_FACTOR
UI scaling factor.
A registry class to hold localized data paths which can be used for basemaps, logos, etc.
A cache for source strings that returns a local file path containing the source content.
void start(const QString &name, const QString &group="startup")
Start a profile event with the given name.
This class is a composition of two QSettings instances:
static QString qgisMasterDatabaseFilePath()
Returns the path to the master qgis.db file.
void customVariablesChanged()
Emitted whenever a custom global variable changes.
static QString qgisUserDatabaseFilePath()
Returns the path to the user qgis.db file.
bool event(QEvent *event) override
Watch for QFileOpenEvent.
void requestForTranslatableObjects(QgsTranslationContext *translationContext)
Emitted when project strings which require translation are being collected for inclusion in a ...
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 donorsFilePath()
Returns the path to the donors file.
static QString relativePathToAbsolutePath(const QString &rpath, const QString &targetPath)
Converts path relative to target to an absolute path.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
int maxConcurrentConnectionsPerPool() const
The maximum number of concurrent connections per connections pool.
void nullRepresentationChanged()
This string is used to represent the value NULL throughout QGIS.
static QgsImageCache * imageCache()
Returns the application's image cache, used for caching resampled versions of raster images...
static QgsValidityCheckRegistry * validityCheckRegistry()
Returns the application's validity check registry, used for managing validity checks.
static QString themeName()
Set the active theme to the specified theme.
static QString defaultThemesFolder()
Returns the path to default themes folder from install (works as a starting point).
void initStyleScheme()
Initializes the default random style color scheme for the user.
QStringList childKeys() const
Returns a list of all top-level keys that can be read using the QSettings object. ...
static void restoreGdalDriver(const QString &driver)
Sets the GDAL_SKIP environment variable to exclude the specified driver and then calls GDALDriverMana...
Registry of 2D renderers for point clouds.
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
A cache for images / pictures derived from SVG files.
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...
void remove(const QString &key, QgsSettings::Section section=QgsSettings::NoSection)
Removes the setting key and any sub-settings of key in a section.
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 resolvePkgPath()
Calculate the application pkg path.
Registry for raster renderers.
static void registerOgrDrivers()
Register OGR drivers ensuring this only happens once.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
User profile contains information about the user profile folders on the machine.
Precisely identify a point on the canvas.
static QgsPluginLayerRegistry * pluginLayerRegistry()
Returns the application's plugin layer registry, used for managing plugin layer types.
static QgsNumericFormatRegistry * numericFormatRegistry()
Gets the registry of available numeric formats.
static QVariantMap customVariables()
Custom expression variables for this application.
Manages storage of a set of bookmarks.
This class keeps a list of QgsAbstractValidityCheck checks which can be used when performing validity...
static void setFileOpenEventReceiver(QObject *receiver)
Sets the FileOpen event receiver.
static endian_t endian()
Returns whether this machine uses big or little endian.
QMap< QString, QString > QgsStringMap
static QStringList deferredSkippedGdalDrivers()
Returns the list of gdal drivers that have been disabled in the current session, and thus...
static QString userFullName()
Returns the user's operating system login account full display name.
void end(const QString &group="startup")
End the current profile event.
static QgsPaintEffectRegistry * paintEffectRegistry()
Returns the application's paint effect registry, used for managing paint effects. ...
static QgsStyle * defaultStyle()
Returns default application-wide style.
static QString developersMapFilePath()
Returns the path to the developers map file.
static QString absolutePathToRelativePath(const QString &apath, const QString &targetPath)
Converts absolute path to path relative to target.
static QString defaultStylePath()
Returns the path to default style (works as a starting point).
static QgsTaskManager * taskManager()
Returns the application's task manager, used for managing application wide background task handling...
static QgsMessageLog * messageLog()
Returns the application's message log.
The QgsReadWriteLocker class is a convenience class that simplifies locking and unlocking QReadWriteL...
static void applyGdalSkippedDrivers()
Apply the skipped drivers list to gdal.
#define CONN_POOL_MAX_CONCURRENT_CONNS
endian_t
Constants for endian-ness.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
static QgsLayoutItemRegistry * layoutItemRegistry()
Returns the application's layout item registry, used for layout item types.
static void setNullRepresentation(const QString &nullRepresentation)
This string is used to represent the value NULL throughout QGIS.
static QString pluginPath()
Returns the path to the application plugin directory.
Q_GLOBAL_STATIC(QReadWriteLock, sDefinitionCacheLock)
Keeps track of available 3D renderers.
#define QgsDebugMsgLevel(str, level)
Registry of available symbol layer classes.
Registry for temporary fetched files.
static bool createThemeFolder()
Create the users theme folder.
static bool createDatabase(QString *errorMessage=nullptr)
initialize qgis.db
static void setTranslation(const QString &translation)
Set translation.
static void cleanRegisteredFunctions()
Deletes all registered functions whose ownership have been transferred to the expression engine...
static QgsLocalizedDataPathRegistry * localizedDataPathRegistry()
Returns the registry of data repositories These are used as paths for basemaps, logos, etc.
static QString i18nPath()
Returns the path to the translation directory.
static void cleanDefaultStyle()
Deletes the default style. Only to be used by QgsApplication::exitQgis()
static QString nullRepresentation()
This string is used to represent the value NULL throughout QGIS.
static QString splashPath()
Returns the path to the splash screen image directory.
static void setCustomVariable(const QString &name, const QVariant &value)
Set a single custom expression variable.
static int maxThreads()
Gets maximum concurrent thread count.
static QgsGpsConnectionRegistry * gpsConnectionRegistry()
Returns the application's GPS connection registry, used for managing GPS connections.
A registry for known page sizes.
static const char * QGIS_ORGANIZATION_NAME
This class manages all known classification methods.
int open(const QString &path)
Opens the database at the specified file path.
static QgsProjectStorageRegistry * projectStorageRegistry()
Returns registry of available project storage implementations.
Task manager for managing a set of long-running QgsTask tasks.
Used for the collecting of strings from projects for translation and creation of ts files...
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 QString userLoginName()
Returns the user's operating system login account name.
static QString pkgDataPath()
Returns the common root path of all application data directories.
static Qgs3DSymbolRegistry * symbol3DRegistry()
Returns registry of available 3D symbols.
static QString osName()
Returns a string name of the operating system QGIS is running on.
static void initQgis()
loads providers
static void setDefaultSvgPaths(const QStringList &pathList)
Alters default svg paths - used by 3rd party apps.
StyleSheetType
The StyleSheetType enum represents the stylesheet type that a widget supports.
static QStringList searchPaths()
Returns the current list of Proj file search paths.
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
static void skipGdalDriver(const QString &driver)
Sets the GDAL_SKIP environment variable to include the specified driver and then calls GDALDriverMana...
static QgsStyleModel * defaultStyleModel()
Returns a shared QgsStyleModel containing the default style library (see QgsStyle::defaultStyle()).
void beginGroup(const QString &prefix, QgsSettings::Section section=QgsSettings::NoSection)
Appends prefix to the current group.
Registry of available annotation item types.
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
static QRegExp shortNameRegExp()
Returns the short name regular expression for line edit validator.
static QgsNetworkAccessManager * instance(Qt::ConnectionType connectionType=Qt::BlockingQueuedConnection)
Returns a pointer to the active QgsNetworkAccessManager for the current thread.
Identify: obtain information about the object.
Registry for various processing components, including providers, algorithms and various parameters an...
static QString showSettings()
Convenience function to get a summary of the paths used in this application instance useful for debug...
static QString appIconPath()
Gets application icon.
static QgsColorSchemeRegistry * colorSchemeRegistry()
Returns the application's color scheme registry, used for managing color schemes. ...
static const char * QGIS_ORGANIZATION_DOMAIN
bool notify(QObject *receiver, QEvent *event) override
Catch exceptions when sending event to receiver.
Registry of available layout item types.
static void setPkgDataPath(const QString &pkgDataPath)
Alters pkg data path - used by 3rd party apps.
static QgsPageSizeRegistry * pageSizeRegistry()
Returns the application's page size registry, used for managing layout page sizes.
static QStringList skippedGdalDrivers()
Returns the list of gdal drivers that should be skipped (based on GDAL_SKIP environment variable) ...
static QString contributorsFilePath()
Returns the path to the contributors file.
static QString activeThemePath()
Returns the path to the currently active theme directory.
static QString buildOutputPath()
Returns path to the build output directory. Valid only when running from build directory.
The QgsScaleBarRendererRegistry manages registered scalebar renderers.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
static void init(QString profileFolder=QString())
This method initializes paths etc for QGIS.
static void setPluginPath(const QString &pluginPath)
Alters plugin path - used by 3rd party apps.
QgsUserProfile * getProfile(const QString &defaultProfile="default", bool createNew=true, bool initSettings=true)
Returns the profile from the given root profile location.
static QgsClassificationMethodRegistry * classificationMethodRegistry()
Returns the application's classification methods registry, used in graduated renderer.
static QgsProject * instance()
Returns the QgsProject singleton instance.
A class to register / unregister existing GPS connections such that the information is available to a...
static QgsSourceCache * sourceCache()
Returns the application's source cache, used for caching embedded and remote source strings as local ...
static QgsNetworkContentFetcherRegistry * networkContentFetcherRegistry()
Returns the application's network content registry used for fetching temporary files during QGIS sess...
Registry of available callout classes.
bool init(const QString &pluginPath=QString(), const QString &authDatabasePath=QString())
init initialize QCA, prioritize qca-ossl plugin and optionally set up the authentication database ...
void changeMode(Mode mode)
Change the mode of the lock to mode.
static QString platform()
Returns the QGIS platform name, e.g., "desktop" or "server".
static QString srsDatabaseFilePath()
Returns the path to the srs.db file.
QObject * ABISYM(QgsApplication::mFileOpenEventReceiver)
static QgsBookmarkManager * bookmarkManager()
Returns the application's bookmark manager, used for storing installation-wide bookmarks.
static void exitQgis()
deletes provider registry and map layer registry
Temporarily blocks the application QgsMessageLog (see QgsApplication::messageLog()) from emitting the...
A cache for images derived from raster files.
static QStringList svgPaths()
Returns the paths to svg directories.
static QgsPointCloudRendererRegistry * pointCloudRendererRegistry()
Returns the application's point cloud renderer registry, used for managing point cloud layer 2D rende...
static QString sponsorsFilePath()
Returns the path to the sponsors file.
Registry of storage backends that QgsProject may use.
static QCursor getThemeCursor(Cursor cursor)
Helper to get a theme cursor.
static QString qgisAuthDatabaseFilePath()
Returns the path to the user authentication database file: qgis-auth.db.
A registry for saved data provider connections, allowing retrieval of saved connections by name and p...
static void setSvgPaths(const QStringList &svgPaths)
Sets the paths to svg directories and invalidates the svg path list cache.
const QString folder() const
The base folder for the user profile.
The action scope registry is an application wide registry that contains a list of available action sc...
static QHash< QString, QString > uiThemes()
All themes found in ~/.qgis3/themes folder.
static QString libexecPath()
Returns the path with utility executables (help viewer, crssync, ...)
static QString prefixPath()
Returns the path to the application prefix directory.
static QString iconsPath()
Returns the path to the icons image directory.
static QString translatorsFilePath()
Returns the path to the sponsors file.
static const char * QGIS_APPLICATION_NAME
bool contains(const QString &key, QgsSettings::Section section=QgsSettings::NoSection) const
Returns true if there exists a setting called key; returns false otherwise.
void collectTranslatableObjects(QgsTranslationContext *translationContext)
Emits the signal to collect all the strings of .qgs to be included in ts file.
~QgsApplication() override
static QgsConnectionRegistry * connectionRegistry()
Returns the application's connection registry, used for managing saved data provider connections...
static QString serverResourcesPath()
Returns the path to the server resources directory.
static QgsActionScopeRegistry * actionScopeRegistry()
Returns the action scope registry.
User profile manager is used to manager list, and manage user profiles on the users machine...
static QString metadataPath()
Returns the path to the metadata directory.
Defines a QGIS exception class.
static QgsRasterRendererRegistry * rasterRendererRegistry()
Returns the application's raster renderer registry, used for managing raster layer renderers...
static QgsDataItemProviderRegistry * dataItemProviderRegistry()
Returns the application's data item provider registry, which keeps a list of data item providers that...
static void registerGdalDriversFromSettings()
Register gdal drivers, excluding the ones mentioned in "gdal/skipList" setting.
static QgsRendererRegistry * rendererRegistry()
Returns the application's renderer registry, used for managing vector layer renderers.
static QgsScaleBarRendererRegistry * scaleBarRendererRegistry()
Gets the registry of available scalebar renderers.
Interface for logging messages from QGIS in GUI independent way.
static QString qmlImportPath()
Returns the path where QML components are installed for QGIS Quick library.
void initialize(const QString &filePath)
Initializes the bookmark manager.
static void setMaxThreads(int maxThreads)
Set maximum concurrent thread count.
Select and capture a point or a feature.
static void setUITheme(const QString &themeName)
Set the current UI theme used to style the interface.
static QColor decodeColor(const QString &str)
static QString licenceFilePath()
Returns the path to the licence file.
static QMap< QString, QString > systemEnvVars()
Returns the system environment variables passed to application.
Registry of available paint effects.
static QgsProcessingRegistry * processingRegistry()
Returns the application's processing registry, used for managing processing providers, algorithms, and various parameters and outputs.
static QString userThemesFolder()
Returns the path to user's themes folder.
void preNotify(QObject *receiver, QEvent *event, bool *done)
static void setAuthDatabaseDirPath(const QString &authDbDirPath)
Alters authentication data base directory path - used by 3rd party apps.