26 #include "qgsexpression.h" 57 #include <QFileOpenEvent> 58 #include <QMessageBox> 63 #include <QThreadPool> 67 #include <netinet/in.h> 73 #define SECURITY_WIN32 75 #pragma comment( lib, "Secur32.lib" ) 78 #include "qgsconfig.h" 85 QObject *
ABISYM( QgsApplication::mFileOpenEventReceiver );
86 QStringList
ABISYM( QgsApplication::mFileOpenEventList );
87 QString
ABISYM( QgsApplication::mPrefixPath );
88 QString
ABISYM( QgsApplication::mPluginPath );
89 QString
ABISYM( QgsApplication::mPkgDataPath );
90 QString
ABISYM( QgsApplication::mLibraryPath );
91 QString
ABISYM( QgsApplication::mLibexecPath );
92 QString
ABISYM( QgsApplication::mThemeName );
93 QString
ABISYM( QgsApplication::mUIThemeName );
94 QString
ABISYM( QgsApplication::mProfilePath );
96 QStringList
ABISYM( QgsApplication::mDefaultSvgPaths );
97 QMap<QString, QString>
ABISYM( QgsApplication::mSystemEnvVars );
98 QString
ABISYM( QgsApplication::mConfigPath );
100 bool ABISYM( QgsApplication::mInitialized ) =
false;
101 bool ABISYM( QgsApplication::mRunningFromBuildDir ) =
false;
102 QString
ABISYM( QgsApplication::mBuildSourcePath );
104 QString
ABISYM( QgsApplication::mCfgIntDir );
106 QString
ABISYM( QgsApplication::mBuildOutputPath );
107 QStringList
ABISYM( QgsApplication::mGdalSkipList );
108 int ABISYM( QgsApplication::mMaxThreads );
109 QString
ABISYM( QgsApplication::mAuthDbDirPath );
111 QString QgsApplication::sUserName;
112 QString QgsApplication::sUserFullName;
113 QString QgsApplication::sPlatformName = QStringLiteral(
"desktop" );
119 QgsApplication::ApplicationMembers *QgsApplication::sApplicationMembers =
nullptr;
122 : QApplication( argc, argv, GUIenabled )
124 sPlatformName = platformName;
126 mApplicationMembers =
new ApplicationMembers();
128 ABISYM( mProfilePath ) = profileFolder;
133 if ( profileFolder.isEmpty() )
135 if ( getenv(
"QGIS_CUSTOM_CONFIG_PATH" ) )
137 QString envProfileFolder = getenv(
"QGIS_CUSTOM_CONFIG_PATH" );
138 profileFolder = envProfileFolder + QDir::separator() +
"profiles";
142 profileFolder = QStandardPaths::standardLocations( QStandardPaths::AppDataLocation ).value( 0 );
149 profileFolder = profile->
folder();
153 ABISYM( mProfilePath ) = profileFolder;
155 qRegisterMetaType<QgsGeometry::Error>(
"QgsGeometry::Error" );
156 qRegisterMetaType<QgsProcessingFeatureSourceDefinition>(
"QgsProcessingFeatureSourceDefinition" );
157 qRegisterMetaType<QgsProcessingOutputLayerDefinition>(
"QgsProcessingOutputLayerDefinition" );
158 qRegisterMetaType<QgsUnitTypes::LayoutUnit>(
"QgsUnitTypes::LayoutUnit" );
159 qRegisterMetaType<QgsFeatureIds>(
"QgsFeatureIds" );
160 qRegisterMetaType<Qgis::MessageLevel>(
"Qgis::MessageLevel" );
161 qRegisterMetaType<QgsReferencedRectangle>(
"QgsReferencedRectangle" );
162 qRegisterMetaType<QgsReferencedPointXY>(
"QgsReferencedPointXY" );
163 qRegisterMetaType<QgsLayoutRenderContext::Flags>(
"QgsLayoutRenderContext::Flags" );
165 QString
prefixPath( getenv(
"QGIS_PREFIX_PATH" ) ? getenv(
"QGIS_PREFIX_PATH" ) : applicationDirPath() );
171 Q_FOREACH (
const QString &path, QStringList() <<
"" <<
"/.." <<
"/bin" <<
"/../../.." )
173 f.setFileName( prefixPath + path +
"/qgisbuildpath.txt" );
177 if ( f.exists() && f.open( QIODevice::ReadOnly ) )
179 ABISYM( mRunningFromBuildDir ) =
true;
180 ABISYM( mBuildSourcePath ) = f.readLine().trimmed();
181 ABISYM( mBuildOutputPath ) = f.readLine().trimmed();
183 QgsDebugMsgLevel( QStringLiteral(
"- source directory: %1" ).arg( ABISYM( mBuildSourcePath ).toUtf8().data() ), 4 );
184 QgsDebugMsgLevel( QStringLiteral(
"- output directory of the build: %1" ).arg( ABISYM( mBuildOutputPath ).toUtf8().data() ), 4 );
186 ABISYM( mCfgIntDir ) = prefixPath.split(
'/', QString::SkipEmptyParts ).last();
187 qDebug(
"- cfg: %s", ABISYM( mCfgIntDir ).toUtf8().data() );
191 if ( ABISYM( mRunningFromBuildDir ) )
194 ABISYM( mPrefixPath ) = QString();
195 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA) 196 setPluginPath( ABISYM( mBuildOutputPath ) +
'/' + QString( QGIS_PLUGIN_SUBDIR ) +
'/' + ABISYM( mCfgIntDir ) );
198 setPluginPath( ABISYM( mBuildOutputPath ) +
'/' + QStringLiteral( QGIS_PLUGIN_SUBDIR ) );
201 ABISYM( mLibraryPath ) = ABISYM( mBuildOutputPath ) +
'/' + QGIS_LIB_SUBDIR +
'/';
202 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA) 203 ABISYM( mLibexecPath ) = ABISYM( mBuildOutputPath ) +
'/' + QGIS_LIBEXEC_SUBDIR +
'/' + ABISYM( mCfgIntDir ) +
'/';
205 ABISYM( mLibexecPath ) = ABISYM( mBuildOutputPath ) +
'/' + QGIS_LIBEXEC_SUBDIR +
'/';
210 char *prefixPath = getenv(
"QGIS_PREFIX_PATH" );
213 #if defined(Q_OS_MACX) || defined(Q_OS_WIN) 215 #elif defined(ANDROID) 217 QDir
myDir( QDir::homePath() );
219 QString myPrefix = myDir.absolutePath();
222 QDir
myDir( applicationDirPath() );
224 QString myPrefix = myDir.absolutePath();
234 ABISYM( mConfigPath ) = profileFolder +
'/';
238 if ( getenv(
"QGIS_AUTH_DB_DIR_PATH" ) )
245 QMap<QString, QString> systemEnvVarMap;
246 QString passfile( QStringLiteral(
"QGIS_AUTH_PASSWORD_FILE" ) );
247 Q_FOREACH (
const QString &varStr, QProcess::systemEnvironment() )
249 int pos = varStr.indexOf( QLatin1Char(
'=' ) );
252 QString varStrName = varStr.left( pos );
253 QString varStrValue = varStr.mid( pos + 1 );
254 if ( varStrName != passfile )
256 systemEnvVarMap.insert( varStrName, varStrValue );
259 ABISYM( mSystemEnvVars ) = systemEnvVarMap;
262 QCoreApplication::addLibraryPath(
pluginPath() );
267 ABISYM( mMaxThreads ) = -1;
269 ABISYM( mInitialized ) =
true;
274 delete mDataItemProviderRegistry;
275 delete mApplicationMembers;
280 return qobject_cast<
QgsApplication *>( QCoreApplication::instance() );
286 if ( event->type() == QEvent::FileOpen )
289 if ( ABISYM( mFileOpenEventReceiver ) )
292 done =
notify( ABISYM( mFileOpenEventReceiver ), event );
299 ABISYM( mFileOpenEventList ).append( static_cast<QFileOpenEvent *>( event )->file() );
306 done = QApplication::event( event );
315 if ( thread() == receiver->thread() )
316 emit
preNotify( receiver, event, &done );
325 done = QApplication::notify( receiver, event );
330 if ( qApp->thread() == QThread::currentThread() )
331 QMessageBox::critical( activeWindow(), tr(
"Exception" ), e.
what() );
333 catch ( std::exception &e )
335 QgsDebugMsg(
"Caught unhandled std::exception: " + QString::fromLatin1( e.what() ) );
336 if ( qApp->thread() == QThread::currentThread() )
337 QMessageBox::critical( activeWindow(), tr(
"Exception" ), e.what() );
341 QgsDebugMsg(
"Caught unhandled unknown exception" );
342 if ( qApp->thread() == QThread::currentThread() )
343 QMessageBox::critical( activeWindow(), tr(
"Exception" ), tr(
"unknown exception" ) );
351 return members()->mProfiler;
357 ABISYM( mFileOpenEventReceiver ) = receiver;
359 if ( ABISYM( mFileOpenEventList ).count() > 0 )
361 QStringListIterator i( ABISYM( mFileOpenEventList ) );
362 while ( i.hasNext() )
364 QFileOpenEvent foe( i.next() );
365 QgsApplication::sendEvent( ABISYM( mFileOpenEventReceiver ), &foe );
367 ABISYM( mFileOpenEventList ).clear();
374 #if defined(_MSC_VER) 375 if ( ABISYM( mPrefixPath ).endsWith(
"/bin" ) )
377 ABISYM( mPrefixPath ).chop( 4 );
380 if ( useDefaultPaths && !ABISYM( mRunningFromBuildDir ) )
382 setPluginPath( ABISYM( mPrefixPath ) +
'/' + QStringLiteral( QGIS_PLUGIN_SUBDIR ) );
383 setPkgDataPath( ABISYM( mPrefixPath ) +
'/' + QStringLiteral( QGIS_DATA_SUBDIR ) );
385 ABISYM( mLibraryPath ) = ABISYM( mPrefixPath ) +
'/' + QGIS_LIB_SUBDIR +
'/';
386 ABISYM( mLibexecPath ) = ABISYM( mPrefixPath ) +
'/' + QGIS_LIBEXEC_SUBDIR +
'/';
397 QString mySvgPath = pkgDataPath + ( ABISYM( mRunningFromBuildDir ) ?
"/images/svg/" :
"/svg/" );
399 if ( !ABISYM( mDefaultSvgPaths ).contains( mySvgPath ) )
400 ABISYM( mDefaultSvgPaths ) << mySvgPath;
405 ABISYM( mDefaultSvgPaths ) = pathList;
410 QFileInfo fi( authDbDirPath );
411 if ( fi.exists() && fi.isDir() && fi.isWritable() )
413 ABISYM( mAuthDbDirPath ) = fi.canonicalFilePath() + QDir::separator();
419 if ( ABISYM( mRunningFromBuildDir ) )
421 static bool sOnce =
true;
423 qWarning(
"!!! prefix path was requested, but it is not valid - we do not run from installed path !!!" );
427 return ABISYM( mPrefixPath );
431 return ABISYM( mPluginPath );
435 return ABISYM( mPkgDataPath );
439 return QStringLiteral(
":/images/themes/default/" );
444 QDir dir( usersThemes );
452 return defaultThemes;
458 return iconsPath() + QStringLiteral(
"qgis-icon-60x60.png" );
465 if ( QFile::exists( path + iconFile ) )
466 return path + iconFile;
475 if ( app && app->mIconCache.contains( name ) )
476 return app->mIconCache.value( name );
480 QString myPreferredPath =
activeThemePath() + QDir::separator() + name;
482 if ( QFile::exists( myPreferredPath ) )
484 icon = QIcon( myPreferredPath );
486 else if ( QFile::exists( myDefaultPath ) )
490 icon = QIcon( myDefaultPath );
498 app->mIconCache.insert( name, icon );
505 if ( app && app->mCursorCache.contains( cursor ) )
506 return app->mCursorCache.value( cursor );
517 name = QStringLiteral(
"mZoomIn.svg" );
522 name = QStringLiteral(
"mZoomOut.svg" );
529 name = QStringLiteral(
"mIdentify.svg" );
532 name = QStringLiteral(
"mCrossHair.svg" );
535 name = QStringLiteral(
"mCapturePoint.svg" );
538 name = QStringLiteral(
"mSelect.svg" );
545 name = QStringLiteral(
"mSampler.svg" );
550 Q_ASSERT( ! name.isEmpty( ) );
552 QIcon icon =
getThemeIcon( QStringLiteral(
"cursors" ) + QDir::separator() + name );
555 if ( ! icon.isNull( ) )
560 if ( app->devicePixelRatio() >= 2 )
562 scale *= app->devicePixelRatio();
563 activeX = activeY = 5;
566 cursorIcon = QCursor( icon.pixmap( std::ceil( scale * 32 ), std::ceil( scale * 32 ) ), std::ceil( scale * activeX ), std::ceil( scale * activeY ) );
569 app->mCursorCache.insert( cursor, cursorIcon );
576 QString myPreferredPath =
activeThemePath() + QDir::separator() + name;
578 if ( QFile::exists( myPreferredPath ) )
580 return QPixmap( myPreferredPath );
586 return QPixmap( myDefaultPath );
598 QString
prefixPath( getenv(
"QGIS_PREFIX_PATH" ) ? getenv(
"QGIS_PREFIX_PATH" ) : QDir::homePath() );
600 QString
prefixPath( getenv(
"QGIS_PREFIX_PATH" ) ? getenv(
"QGIS_PREFIX_PATH" ) : applicationDirPath() );
604 const QStringList pathPrefixes = QStringList() <<
"" <<
"/.." <<
"/bin" <<
"/../../..";
605 for (
const QString &path : pathPrefixes )
607 f.setFileName( prefixPath + path +
"/qgisbuildpath.txt" );
613 if ( f.exists() && f.open( QIODevice::ReadOnly ) )
616 return f.readLine().trimmed();
620 return prefixPath +
'/' + QStringLiteral( QGIS_DATA_SUBDIR );
627 return ABISYM( mThemeName );
634 if ( themeName == QStringLiteral(
"default" ) || !themes.contains( themeName ) )
637 qApp->setStyleSheet( QString() );
641 QString path = themes.value( themeName );
642 QString stylesheetname = path +
"/style.qss";
643 QString autostylesheet = stylesheetname +
".auto";
645 QFile file( stylesheetname );
646 QFile variablesfile( path +
"/variables.qss" );
647 QFile fileout( autostylesheet );
649 QFileInfo variableInfo( variablesfile );
651 if ( variableInfo.exists() && variablesfile.open( QIODevice::ReadOnly ) )
653 if ( !file.open( QIODevice::ReadOnly ) || !fileout.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
658 QString styledata = file.readAll();
659 QTextStream in( &variablesfile );
660 while ( !in.atEnd() )
662 QString line = in.readLine();
664 if ( line.startsWith(
'@' ) )
666 int index = line.indexOf(
':' );
667 QString name = line.mid( 0, index );
668 QString value = line.mid( index + 1, line.length() );
669 styledata.replace( name, value );
672 variablesfile.close();
673 QTextStream out( &fileout );
677 stylesheetname = autostylesheet;
680 QString styleSheet = QStringLiteral(
"file:///" );
681 styleSheet.append( stylesheetname );
682 qApp->setStyleSheet( styleSheet );
689 QHash<QString, QString> mapping;
690 mapping.insert( QStringLiteral(
"default" ), QLatin1String(
"" ) );
691 Q_FOREACH (
const QString &path, paths )
694 QFileInfoList styleFiles = folder.entryInfoList( QDir::Dirs | QDir::NoDotAndDotDot );
695 Q_FOREACH (
const QFileInfo &info, styleFiles )
697 QFileInfo styleFile( info.absoluteFilePath() +
"/style.qss" );
698 if ( !styleFile.exists() )
701 QString name = info.baseName();
702 QString path = info.absoluteFilePath();
703 mapping.insert( name, path );
711 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/doc/AUTHORS" );
716 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/doc/CONTRIBUTORS" );
720 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/doc/developersmap.html" );
725 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/doc/SPONSORS" );
730 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/doc/DONORS" );
735 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/doc/TRANSLATORS" );
740 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/doc/LICENSE" );
745 if ( ABISYM( mRunningFromBuildDir ) )
746 return ABISYM( mBuildOutputPath ) + QStringLiteral(
"/i18n" );
748 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/i18n/" );
753 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/resources/metadata-ISO/" );
758 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/resources/qgis.db" );
763 return ABISYM( mConfigPath );
773 return ABISYM( mAuthDbDirPath ) + QStringLiteral(
"qgis-auth.db" );
778 return QStringLiteral(
":/images/splash/" );
783 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/images/icons/" );
788 if ( ABISYM( mRunningFromBuildDir ) )
790 QString tempCopy = QDir::tempPath() +
"/srs.db";
792 if ( !QFile( tempCopy ).exists() )
794 QFile
f( ABISYM( mPkgDataPath ) +
"/resources/srs.db" );
795 if ( !f.copy( tempCopy ) )
797 qFatal(
"Could not create temporary copy" );
805 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/resources/srs.db" );
814 QStringList pathList = settings.
value( QStringLiteral(
"svg/searchPathsForSVG" ) ).toStringList();
818 Q_FOREACH (
const QString &path, pathList )
820 if ( !paths.contains( path ) )
821 paths.append( path );
823 Q_FOREACH (
const QString &path, ABISYM( mDefaultSvgPaths ) )
825 if ( !paths.contains( path ) )
826 paths.append( path );
837 QStringList pathList = settings.
value( QStringLiteral(
"Layout/searchPathsForTemplates" ), QVariant(),
QgsSettings::Core ).toStringList();
849 return QRegExp(
"^[A-Za-z_][A-Za-z0-9\\._-]*" );
854 if ( !sUserName.isEmpty() )
858 TCHAR name [ UNLEN + 1 ];
859 DWORD size = UNLEN + 1;
861 if ( GetUserName( ( TCHAR * )name, &size ) )
863 sUserName = QString( name );
869 process.start( QStringLiteral(
"whoami" ) );
870 process.waitForFinished();
871 sUserName = process.readAllStandardOutput().trimmed();
874 if ( !sUserName.isEmpty() )
878 sUserName = qgetenv(
"USER" );
879 if ( !sUserName.isEmpty() )
883 sUserName = qgetenv(
"USERNAME" );
889 if ( !sUserFullName.isEmpty() )
890 return sUserFullName;
893 TCHAR name [ UNLEN + 1 ];
894 DWORD size = UNLEN + 1;
897 if ( GetUserNameEx( NameDisplay, ( TCHAR * )name, &size ) )
899 sUserFullName = QString( name );
903 if ( sUserFullName.isEmpty() )
905 #elif defined(Q_OS_ANDROID) || defined(__MINGW32__) 906 sUserFullName =
"Not available";
908 struct passwd *p = getpwuid( getuid() );
912 QString gecosName = QString( p->pw_gecos );
913 sUserFullName = gecosName.left( gecosName.indexOf(
',', 0 ) );
918 return sUserFullName;
923 #if defined(Q_OS_ANDROID) 924 return QLatin1String(
"android" );
925 #elif defined(Q_OS_MAC) 926 return QLatin1String(
"osx" );
927 #elif defined(Q_OS_WIN) 928 return QLatin1String(
"windows" );
929 #elif defined(Q_OS_LINUX) 930 return QStringLiteral(
"linux" );
932 return QLatin1String(
"unknown" );
938 return sPlatformName;
944 bool overrideLocale = settings.
value( QStringLiteral(
"locale/overrideFlag" ),
false ).toBool();
945 if ( overrideLocale )
947 QString
locale = settings.
value( QStringLiteral(
"locale/userLocale" ), QString() ).toString();
949 if ( locale.startsWith( QStringLiteral(
"en" ), Qt::CaseInsensitive ) )
951 return locale.left( 2 );
958 return QLocale::system().name().left( 2 );
969 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/resources/symbology-style.xml" );
974 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/resources/themes" );
979 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/resources/server/" );
984 return ABISYM( mLibraryPath );
989 return ABISYM( mLibexecPath );
994 return ( htonl( 1 ) == 1 ) ?
XDR :
NDR;
1039 if ( !sAuthManager )
1041 return sAuthManager;
1053 QgsApplication::sendPostedEvents(
nullptr, QEvent::DeferredDelete );
1056 QgsExpression::cleanRegisteredFunctions();
1064 GDALDestroyDriverManager();
1069 QString myEnvironmentVar( getenv(
"QGIS_PREFIX_PATH" ) );
1070 QString myState = tr(
"Application state:\n" 1071 "QGIS_PREFIX_PATH env var:\t\t%1\n" 1073 "Plugin Path:\t\t%3\n" 1074 "Package Data Path:\t%4\n" 1075 "Active Theme Name:\t%5\n" 1076 "Active Theme Path:\t%6\n" 1077 "Default Theme Path:\t%7\n" 1078 "SVG Search Paths:\t%8\n" 1079 "User DB Path:\t%9\n" 1080 "Auth DB Path:\t%10\n" )
1081 .arg( myEnvironmentVar,
1088 svgPaths().join( tr(
"\n\t\t",
"match indentation of application state" ) ),
1101 QColor myColor1( Qt::lightGray );
1102 QColor myColor2 = myColor1;
1103 myColor2 = myColor2.lighter( 110 );
1105 myStyle =
".overview{" 1107 " font-weight: bold;" 1110 " background: white;" 1112 " font-family: 'Lato', 'Ubuntu', 'Lucida Grande', 'Segoe UI', 'Arial', sans-serif;" 1115 "h1{ background-color: #F6F6F6;" 1117 " font-size: x-large; " 1118 " font-weight: normal;" 1119 " background: none;" 1120 " padding: 0.75em 0 0;" 1122 " line-height: 3em;" 1124 "h2{ background-color: #F6F6F6;" 1126 " font-size: medium; " 1127 " font-weight: normal;" 1128 " background: none;" 1129 " padding: 0.75em 0 0;" 1131 " line-height: 1.1em;" 1133 "h3{ background-color: #F6F6F6;" 1135 " font-weight: bold;" 1136 " font-size: large;" 1137 " text-align: right;" 1138 " border-bottom: 5px solid #DCEB5C;" 1140 "h4{ background-color: #F6F6F6;" 1142 " font-weight: bold;" 1143 " font-size: medium;" 1144 " text-align: right;" 1146 "h5{ background-color: #F6F6F6;" 1148 " font-weight: bold;" 1149 " font-size: small;" 1150 " text-align: right;" 1152 "a{ color: #729FCF;" 1153 " font-family: arial,sans-serif;" 1154 " font-size: small;" 1156 "label{ background-color: #FFFFCC;" 1157 " border: 1px solid black;" 1159 " padding: 0px 3px; " 1160 " font-size: small;" 1163 " font-weight: bold;" 1164 " padding-top:25px;" 1166 ".list-view .highlight {" 1167 " text-align: right;" 1170 " padding-right: 15px;" 1171 " padding-left: 20px;" 1172 " font-weight: bold;" 1175 " font-weight: bold;" 1178 " border-collapse: collapse;" 1181 ".tabular-view th, .tabular-view td { " 1182 " border:10px solid black;" 1184 ".tabular-view .odd-row{" 1185 " background-color: #f9f9f9;" 1190 " border-top: 1px solid black;" 1197 if ( 0 >= OGRGetDriverCount() )
1205 QString aPathUrl = aPath;
1206 QString tPathUrl = targetPath;
1207 #if defined( Q_OS_WIN ) 1208 const Qt::CaseSensitivity cs = Qt::CaseInsensitive;
1210 aPathUrl.replace(
'\\',
'/' );
1211 if ( aPathUrl.startsWith(
"//" ) )
1214 aPathUrl =
"\\\\" + aPathUrl.mid( 2 );
1217 tPathUrl.replace(
'\\',
'/' );
1218 if ( tPathUrl.startsWith(
"//" ) )
1221 tPathUrl =
"\\\\" + tPathUrl.mid( 2 );
1224 const Qt::CaseSensitivity cs = Qt::CaseSensitive;
1227 QStringList targetElems = tPathUrl.split(
'/', QString::SkipEmptyParts );
1228 QStringList aPathElems = aPathUrl.split(
'/', QString::SkipEmptyParts );
1230 targetElems.removeAll( QStringLiteral(
"." ) );
1231 aPathElems.removeAll( QStringLiteral(
"." ) );
1235 while ( !aPathElems.isEmpty() &&
1236 !targetElems.isEmpty() &&
1237 aPathElems[0].compare( targetElems[0], cs ) == 0 )
1239 aPathElems.removeFirst();
1240 targetElems.removeFirst();
1250 if ( !targetElems.isEmpty() )
1253 for (
int i = 0; i < targetElems.size(); i++ )
1255 aPathElems.insert( 0, QStringLiteral(
".." ) );
1262 aPathElems.insert( 0, QStringLiteral(
"." ) );
1265 return aPathElems.join( QStringLiteral(
"/" ) );
1271 if ( !rpath.startsWith( QLatin1String(
"./" ) ) && !rpath.startsWith( QLatin1String(
"../" ) ) )
1276 QString rPathUrl = rpath;
1277 QString targetPathUrl = targetPath;
1279 #if defined(Q_OS_WIN) 1280 rPathUrl.replace(
'\\',
'/' );
1281 targetPathUrl.replace(
'\\',
'/' );
1283 bool uncPath = targetPathUrl.startsWith(
"//" );
1286 QStringList srcElems = rPathUrl.split(
'/', QString::SkipEmptyParts );
1287 QStringList targetElems = targetPathUrl.split(
'/', QString::SkipEmptyParts );
1289 #if defined(Q_OS_WIN) 1292 targetElems.insert( 0,
"" );
1293 targetElems.insert( 0,
"" );
1298 targetElems << srcElems;
1299 targetElems.removeAll( QStringLiteral(
"." ) );
1303 while ( ( pos = targetElems.indexOf( QStringLiteral(
".." ) ) ) > 0 )
1306 targetElems.removeAt( pos - 1 );
1307 targetElems.removeAt( pos - 1 );
1310 #if !defined(Q_OS_WIN) 1312 targetElems.prepend( QLatin1String(
"" ) );
1315 return targetElems.join( QStringLiteral(
"/" ) );
1320 if (
ABISYM( mGdalSkipList ).contains( driver ) || driver.isEmpty() )
1324 ABISYM( mGdalSkipList ) << driver;
1330 if ( !
ABISYM( mGdalSkipList ).contains( driver ) )
1334 int myPos =
ABISYM( mGdalSkipList ).indexOf( driver );
1337 ABISYM( mGdalSkipList ).removeAt( myPos );
1344 ABISYM( mGdalSkipList ).removeDuplicates();
1345 QString myDriverList =
ABISYM( mGdalSkipList ).join( QStringLiteral(
" " ) );
1346 QgsDebugMsg(
"Gdal Skipped driver list set to:" );
1348 CPLSetConfigOption(
"GDAL_SKIP", myDriverList.toUtf8() );
1355 QDir
myDir( folder );
1356 if ( !myDir.exists() )
1358 myDir.mkpath( folder );
1364 void QgsApplication::copyPath(
const QString &src,
const QString &dst )
1367 if ( ! dir.exists() )
1370 Q_FOREACH (
const QString &d, dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
1372 QString dst_path = dst + QDir::separator() + d;
1373 dir.mkpath( dst_path );
1374 copyPath( src + QDir::separator() + d, dst_path );
1377 Q_FOREACH (
const QString &
f, dir.entryList( QDir::Files ) )
1379 QFile::copy( src + QDir::separator() + f, dst + QDir::separator() + f );
1388 QVariantMap variables;
1392 QStringList childKeys = settings.
childKeys();
1393 for ( QStringList::const_iterator it = childKeys.constBegin(); it != childKeys.constEnd(); ++it )
1396 variables.insert( name, settings.
value( name ) );
1406 QVariantMap::const_iterator it = variables.constBegin();
1409 for ( ; it != variables.constEnd(); ++it )
1411 settings.
setValue( it.key(), it.value() );
1422 settings.
setValue( QStringLiteral(
"variables/" ) + name, value );
1430 ApplicationMembers *appMembers = members();
1431 if ( appMembers->mNullRepresentation.isNull() )
1433 appMembers->mNullRepresentation =
QgsSettings().
value( QStringLiteral(
"qgis/nullValue" ), QStringLiteral(
"NULL" ) ).toString();
1435 return appMembers->mNullRepresentation;
1440 ApplicationMembers *appMembers = members();
1441 if ( !appMembers || appMembers->mNullRepresentation == nullRepresentation )
1454 return members()->mActionScopeRegistry;
1463 QDir
myDir( myPamPath );
1464 if ( !myDir.exists() )
1466 myDir.mkpath( myPamPath );
1469 #if defined(Q_OS_WIN) 1470 CPLSetConfigOption(
"GDAL_PAM_PROXY_DIR", myPamPath.toUtf8() );
1474 int myChangeFlag = 0;
1475 setenv(
"GDAL_PAM_PROXY_DIR", myPamPath.toUtf8(), myChangeFlag );
1482 if ( !qgisPrivateDbFile.exists() )
1486 QFile masterFile( qgisMasterDbFileName );
1492 bool isDbFileCopied = masterFile.copy( qgisPrivateDbFile.fileName() );
1494 if ( !isDbFileCopied )
1498 *errorMessage = tr(
"[ERROR] Can not make qgis.db private copy" );
1511 *errorMessage = tr(
"Could not open qgis.db" );
1516 char *errmsg =
nullptr;
1517 int res = sqlite3_exec( database.get(),
"SELECT epsg FROM tbl_srs LIMIT 0",
nullptr,
nullptr, &errmsg );
1518 if ( res == SQLITE_OK )
1521 if ( sqlite3_exec( database.get(),
1522 "ALTER TABLE tbl_srs RENAME TO tbl_srs_bak;" 1523 "CREATE TABLE tbl_srs (" 1524 "srs_id INTEGER PRIMARY KEY," 1525 "description text NOT NULL," 1526 "projection_acronym text NOT NULL," 1527 "ellipsoid_acronym NOT NULL," 1528 "parameters text NOT NULL," 1530 "auth_name varchar," 1532 "is_geo integer NOT NULL," 1533 "deprecated boolean);" 1534 "CREATE INDEX idx_srsauthid on tbl_srs(auth_name,auth_id);" 1535 "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;" 1536 "DROP TABLE tbl_srs_bak",
nullptr,
nullptr, &errmsg ) != SQLITE_OK
1541 *errorMessage = tr(
"Migration of private qgis.db failed.\n%1" ).arg( QString::fromUtf8( errmsg ) );
1543 sqlite3_free( errmsg );
1549 sqlite3_free( errmsg );
1552 if ( sqlite3_exec( database.get(),
"DROP VIEW vw_srs",
nullptr,
nullptr, &errmsg ) != SQLITE_OK )
1554 QgsDebugMsg( QString(
"vw_srs didn't exists in private qgis.db: %1" ).arg( errmsg ) );
1557 if ( sqlite3_exec( database.get(),
1558 "CREATE VIEW vw_srs AS" 1560 " a.description AS description" 1561 ",a.srs_id AS srs_id" 1562 ",a.is_geo AS is_geo" 1563 ",coalesce(b.name,a.projection_acronym) AS name" 1564 ",a.parameters AS parameters" 1565 ",a.auth_name AS auth_name" 1566 ",a.auth_id AS auth_id" 1567 ",a.deprecated AS deprecated" 1569 " LEFT OUTER JOIN tbl_projection b ON a.projection_acronym=b.acronym" 1570 " ORDER BY coalesce(b.name,a.projection_acronym),a.description",
nullptr,
nullptr, &errmsg ) != SQLITE_OK
1575 *errorMessage = tr(
"Update of view in private qgis.db failed.\n%1" ).arg( QString::fromUtf8( errmsg ) );
1577 sqlite3_free( errmsg );
1586 QgsDebugMsg( QString(
"maxThreads: %1" ).arg( maxThreads ) );
1590 if ( maxThreads < 1 || maxThreads > QThread::idealThreadCount() )
1597 if ( maxThreads == -1 )
1598 maxThreads = QThread::idealThreadCount();
1601 QThreadPool::globalInstance()->setMaxThreadCount( maxThreads );
1602 QgsDebugMsg( QString(
"set QThreadPool max thread count to %1" ).arg( QThreadPool::globalInstance()->maxThreadCount() ) );
1607 return members()->mTaskManager;
1612 return members()->mColorSchemeRegistry;
1617 return members()->mPaintEffectRegistry;
1622 return members()->mRendererRegistry;
1627 return members()->mRasterRendererRegistry;
1634 if ( !
instance()->mDataItemProviderRegistry )
1638 return instance()->mDataItemProviderRegistry;
1644 if ( !sDataItemProviderRegistry )
1646 return sDataItemProviderRegistry;
1652 return members()->mSvgCache;
1657 return members()->mSymbolLayerRegistry;
1662 return members()->mLayoutItemRegistry;
1667 return members()->mGpsConnectionRegistry;
1672 return members()->mPluginLayerRegistry;
1677 return members()->mMessageLog;
1682 return members()->mProcessingRegistry;
1687 return members()->mPageSizeRegistry;
1692 return members()->mAnnotationRegistry;
1697 return members()->mFieldFormatterRegistry;
1702 return members()->m3DRendererRegistry;
1705 QgsApplication::ApplicationMembers::ApplicationMembers()
1716 mColorSchemeRegistry->addDefaultSchemes();
1726 mLayoutItemRegistry->populate();
1727 mAnnotationRegistry =
new QgsAnnotationRegistry();
1731 QgsApplication::ApplicationMembers::~ApplicationMembers()
1733 delete mActionScopeRegistry;
1734 delete m3DRendererRegistry;
1735 delete mAnnotationRegistry;
1736 delete mColorSchemeRegistry;
1737 delete mFieldFormatterRegistry;
1738 delete mGpsConnectionRegistry;
1740 delete mPaintEffectRegistry;
1741 delete mPluginLayerRegistry;
1742 delete mProcessingRegistry;
1743 delete mPageSizeRegistry;
1744 delete mLayoutItemRegistry;
1746 delete mRasterRendererRegistry;
1747 delete mRendererRegistry;
1749 delete mSymbolLayerRegistry;
1750 delete mTaskManager;
1753 QgsApplication::ApplicationMembers *QgsApplication::members()
1757 return instance()->mApplicationMembers;
1761 static QMutex sMemberMutex( QMutex::Recursive );
1762 QMutexLocker lock( &sMemberMutex );
1763 if ( !sApplicationMembers )
1764 sApplicationMembers =
new ApplicationMembers();
1765 return sApplicationMembers;
static QStringList layoutTemplatePaths()
Returns the paths to layout template directories.
Singleton offering an interface to manage the authentication configuration database and to utilize co...
void remove(const QString &key, const QgsSettings::Section section=QgsSettings::NoSection)
Removes the setting key and any sub-settings of key in a section.
QgsApplication(int &argc, char **argv, bool GUIenabled, const QString &profileFolder=QString(), const QString &platformName="desktop")
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 void setThemeName(const QString &themeName)
Set the active theme to the specified theme.
static Qgs3DRendererRegistry * renderer3DRegistry()
Returns registry of available 3D renderers.
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.
Extends QApplication to provide access to QGIS specific resources such as theme paths, database paths etc.
static QgsFieldFormatterRegistry * fieldFormatterRegistry()
Get the registry of available field formatters.
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.
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.
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.
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.
void nullRepresentationChanged()
This string is used to represent the value NULL throughout QGIS.
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).
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...
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
A cache for images / pictures derived from svg files.
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 QVariantMap customVariables()
Custom expression variables for this application.
static void setFileOpenEventReceiver(QObject *receiver)
Set the FileOpen event receiver.
static QString reportStyleSheet()
get a standard css style sheet for reports.
static int maxThreads()
Get maximum concurrent thread count.
static endian_t endian()
Returns whether this machine uses big or little endian.
static QPixmap getThemePixmap(const QString &name)
Helper to get a theme icon as a pixmap.
static QString userFullName()
Returns the user's operating system login account full display name.
static QgsPaintEffectRegistry * paintEffectRegistry()
Returns the application's paint effect registry, used for managing paint effects. ...
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...
void beginGroup(const QString &prefix, const QgsSettings::Section section=QgsSettings::NoSection)
Appends prefix to the current group.
static QgsMessageLog * messageLog()
Returns the application's message log.
static void applyGdalSkippedDrivers()
Apply the skipped drivers list to gdal.
void setValue(const QString &key, const QVariant &value, const QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
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.
Keeps track of available 3D renderers.
#define QgsDebugMsgLevel(str, level)
Registry of available symbol layer classes.
static bool createThemeFolder()
Create the users theme folder.
static bool createDatabase(QString *errorMessage=nullptr)
initialize qgis.db
static QString i18nPath()
Returns the path to the translation directory.
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 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
int open(const QString &path)
Opens the database at the specified file path.
Task manager for managing a set of long-running QgsTask tasks.
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 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.
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 QgsAuthManager * authManager()
Returns the application's authentication manager instance.
static QRegExp shortNameRegExp()
Returns the short name regular expression for line edit validator.
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()
get 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 QString contributorsFilePath()
Returns the path to the contributors file.
static QString activeThemePath()
Returns the path to the currently active theme directory.
static QgsNetworkAccessManager * instance()
returns a pointer to the single instance
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.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), const Section section=NoSection) const
Returns the value for setting key.
QgsUserProfile * getProfile(const QString &defaultProfile="default", bool createNew=true, bool initSettings=true)
Return the profile from the given root profile location.
static QgsProject * instance()
Returns the QgsProject singleton instance.
A class to register / unregister existing GPS connections such that the information is available to a...
bool init(const QString &pluginPath=QString(), const QString &authDatabasePath=QString())
init initialize QCA, prioritize qca-ossl plugin and optionally set up the authentication database ...
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 void exitQgis()
deletes provider registry and map layer registry
static QStringList svgPaths()
Returns the paths to svg directories.
static QString sponsorsFilePath()
Returns the path to the sponsors file.
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.
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
~QgsApplication() override
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 QgsRendererRegistry * rendererRegistry()
Returns the application's renderer registry, used for managing vector layer renderers.
Interface for logging messages from QGIS in GUI independent way.
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 QString licenceFilePath()
Returns the path to the licence file.
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.