60 #include <QFileOpenEvent> 61 #include <QMessageBox> 66 #include <QThreadPool> 70 #include <netinet/in.h> 76 #define SECURITY_WIN32 78 #pragma comment( lib, "Secur32.lib" ) 81 #include "qgsconfig.h" 88 QObject *
ABISYM( QgsApplication::mFileOpenEventReceiver );
89 QStringList
ABISYM( QgsApplication::mFileOpenEventList );
90 QString
ABISYM( QgsApplication::mPrefixPath );
91 QString
ABISYM( QgsApplication::mPluginPath );
92 QString
ABISYM( QgsApplication::mPkgDataPath );
93 QString
ABISYM( QgsApplication::mLibraryPath );
94 QString
ABISYM( QgsApplication::mLibexecPath );
95 QString
ABISYM( QgsApplication::mQmlImportPath );
96 QString
ABISYM( QgsApplication::mThemeName );
97 QString
ABISYM( QgsApplication::mUIThemeName );
98 QString
ABISYM( QgsApplication::mProfilePath );
100 QStringList
ABISYM( QgsApplication::mDefaultSvgPaths );
101 QMap<QString, QString>
ABISYM( QgsApplication::mSystemEnvVars );
102 QString
ABISYM( QgsApplication::mConfigPath );
104 bool ABISYM( QgsApplication::mInitialized ) =
false;
105 bool ABISYM( QgsApplication::mRunningFromBuildDir ) =
false;
106 QString
ABISYM( QgsApplication::mBuildSourcePath );
108 QString
ABISYM( QgsApplication::mCfgIntDir );
110 QString
ABISYM( QgsApplication::mBuildOutputPath );
111 QStringList
ABISYM( QgsApplication::mGdalSkipList );
112 int ABISYM( QgsApplication::mMaxThreads );
113 QString
ABISYM( QgsApplication::mAuthDbDirPath );
115 QString QgsApplication::sUserName;
116 QString QgsApplication::sUserFullName;
117 QString QgsApplication::sPlatformName = QStringLiteral(
"desktop" );
123 QgsApplication::ApplicationMembers *QgsApplication::sApplicationMembers =
nullptr;
126 : QApplication( argc, argv, GUIenabled )
128 sPlatformName = platformName;
130 mApplicationMembers =
new ApplicationMembers();
132 ABISYM( mProfilePath ) = profileFolder;
137 if ( profileFolder.isEmpty() )
139 if ( getenv(
"QGIS_CUSTOM_CONFIG_PATH" ) )
141 QString envProfileFolder = getenv(
"QGIS_CUSTOM_CONFIG_PATH" );
142 profileFolder = envProfileFolder + QDir::separator() +
"profiles";
146 profileFolder = QStandardPaths::standardLocations( QStandardPaths::AppDataLocation ).value( 0 );
153 profileFolder = profile->
folder();
157 ABISYM( mProfilePath ) = profileFolder;
159 qRegisterMetaType<QgsGeometry::Error>(
"QgsGeometry::Error" );
160 qRegisterMetaType<QgsProcessingFeatureSourceDefinition>(
"QgsProcessingFeatureSourceDefinition" );
161 qRegisterMetaType<QgsProcessingOutputLayerDefinition>(
"QgsProcessingOutputLayerDefinition" );
162 qRegisterMetaType<QgsUnitTypes::LayoutUnit>(
"QgsUnitTypes::LayoutUnit" );
163 qRegisterMetaType<QgsFeatureIds>(
"QgsFeatureIds" );
164 qRegisterMetaType<Qgis::MessageLevel>(
"Qgis::MessageLevel" );
165 qRegisterMetaType<QgsReferencedRectangle>(
"QgsReferencedRectangle" );
166 qRegisterMetaType<QgsReferencedPointXY>(
"QgsReferencedPointXY" );
167 qRegisterMetaType<QgsLayoutRenderContext::Flags>(
"QgsLayoutRenderContext::Flags" );
169 QString
prefixPath( getenv(
"QGIS_PREFIX_PATH" ) ? getenv(
"QGIS_PREFIX_PATH" ) : applicationDirPath() );
175 Q_FOREACH (
const QString &path, QStringList() <<
"" <<
"/.." <<
"/bin" <<
"/../../.." )
177 f.setFileName( prefixPath + path +
"/qgisbuildpath.txt" );
181 if ( f.exists() && f.open( QIODevice::ReadOnly ) )
183 ABISYM( mRunningFromBuildDir ) =
true;
184 ABISYM( mBuildSourcePath ) = f.readLine().trimmed();
185 ABISYM( mBuildOutputPath ) = f.readLine().trimmed();
187 QgsDebugMsgLevel( QStringLiteral(
"- source directory: %1" ).arg( ABISYM( mBuildSourcePath ).toUtf8().data() ), 4 );
188 QgsDebugMsgLevel( QStringLiteral(
"- output directory of the build: %1" ).arg( ABISYM( mBuildOutputPath ).toUtf8().data() ), 4 );
190 ABISYM( mCfgIntDir ) = prefixPath.split(
'/', QString::SkipEmptyParts ).last();
191 qDebug(
"- cfg: %s", ABISYM( mCfgIntDir ).toUtf8().data() );
195 if ( ABISYM( mRunningFromBuildDir ) )
198 ABISYM( mPrefixPath ) = QString();
199 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA) 200 setPluginPath( ABISYM( mBuildOutputPath ) +
'/' + QString( QGIS_PLUGIN_SUBDIR ) +
'/' + ABISYM( mCfgIntDir ) );
202 setPluginPath( ABISYM( mBuildOutputPath ) +
'/' + QStringLiteral( QGIS_PLUGIN_SUBDIR ) );
205 ABISYM( mLibraryPath ) = ABISYM( mBuildOutputPath ) +
'/' + QGIS_LIB_SUBDIR +
'/';
206 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA) 207 ABISYM( mLibexecPath ) = ABISYM( mBuildOutputPath ) +
'/' + QGIS_LIBEXEC_SUBDIR +
'/' + ABISYM( mCfgIntDir ) +
'/';
209 ABISYM( mLibexecPath ) = ABISYM( mBuildOutputPath ) +
'/' + QGIS_LIBEXEC_SUBDIR +
'/';
211 #if defined( HAVE_QUICK ) 212 ABISYM( mQmlImportPath ) = ABISYM( mBuildOutputPath ) +
'/' + QGIS_QML_SUBDIR +
'/';
217 char *prefixPath = getenv(
"QGIS_PREFIX_PATH" );
220 if ( ABISYM( mPrefixPath ).isNull() )
222 #if defined(Q_OS_MACX) || defined(Q_OS_WIN) 224 #elif defined(ANDROID) 226 QDir myDir( QDir::homePath() );
228 QString myPrefix = myDir.absolutePath();
231 QDir myDir( applicationDirPath() );
233 if ( applicationDirPath().contains( QStringLiteral(
"cgi-bin" ) ) )
238 QString myPrefix = myDir.absolutePath();
249 ABISYM( mConfigPath ) = profileFolder +
'/';
253 if ( getenv(
"QGIS_AUTH_DB_DIR_PATH" ) )
260 QMap<QString, QString> systemEnvVarMap;
261 QString passfile( QStringLiteral(
"QGIS_AUTH_PASSWORD_FILE" ) );
262 Q_FOREACH (
const QString &varStr, QProcess::systemEnvironment() )
264 int pos = varStr.indexOf( QLatin1Char(
'=' ) );
267 QString varStrName = varStr.left( pos );
268 QString varStrValue = varStr.mid( pos + 1 );
269 if ( varStrName != passfile )
271 systemEnvVarMap.insert( varStrName, varStrValue );
274 ABISYM( mSystemEnvVars ) = systemEnvVarMap;
277 QCoreApplication::addLibraryPath(
pluginPath() );
282 ABISYM( mMaxThreads ) = -1;
287 ABISYM( mInitialized ) =
true;
292 delete mDataItemProviderRegistry;
293 delete mApplicationMembers;
298 return qobject_cast<
QgsApplication *>( QCoreApplication::instance() );
304 if ( event->type() == QEvent::FileOpen )
307 if ( ABISYM( mFileOpenEventReceiver ) )
310 done =
notify( ABISYM( mFileOpenEventReceiver ), event );
317 ABISYM( mFileOpenEventList ).append( static_cast<QFileOpenEvent *>( event )->file() );
324 done = QApplication::event( event );
333 if ( thread() == receiver->thread() )
334 emit
preNotify( receiver, event, &done );
343 done = QApplication::notify( receiver, event );
348 if ( qApp->thread() == QThread::currentThread() )
349 QMessageBox::critical( activeWindow(), tr(
"Exception" ), e.
what() );
351 catch ( std::exception &e )
353 QgsDebugMsg(
"Caught unhandled std::exception: " + QString::fromLatin1( e.what() ) );
354 if ( qApp->thread() == QThread::currentThread() )
355 QMessageBox::critical( activeWindow(), tr(
"Exception" ), e.what() );
359 QgsDebugMsg(
"Caught unhandled unknown exception" );
360 if ( qApp->thread() == QThread::currentThread() )
361 QMessageBox::critical( activeWindow(), tr(
"Exception" ), tr(
"unknown exception" ) );
369 return members()->mProfiler;
375 ABISYM( mFileOpenEventReceiver ) = receiver;
377 if ( ABISYM( mFileOpenEventList ).count() > 0 )
379 QStringListIterator i( ABISYM( mFileOpenEventList ) );
380 while ( i.hasNext() )
382 QFileOpenEvent foe( i.next() );
383 QgsApplication::sendEvent( ABISYM( mFileOpenEventReceiver ), &foe );
385 ABISYM( mFileOpenEventList ).clear();
392 #if defined(_MSC_VER) 393 if ( ABISYM( mPrefixPath ).endsWith(
"/bin" ) )
395 ABISYM( mPrefixPath ).chop( 4 );
398 if ( useDefaultPaths && !ABISYM( mRunningFromBuildDir ) )
400 setPluginPath( ABISYM( mPrefixPath ) +
'/' + QStringLiteral( QGIS_PLUGIN_SUBDIR ) );
401 setPkgDataPath( ABISYM( mPrefixPath ) +
'/' + QStringLiteral( QGIS_DATA_SUBDIR ) );
403 ABISYM( mLibraryPath ) = ABISYM( mPrefixPath ) +
'/' + QGIS_LIB_SUBDIR +
'/';
404 ABISYM( mLibexecPath ) = ABISYM( mPrefixPath ) +
'/' + QGIS_LIBEXEC_SUBDIR +
'/';
405 #if defined( HAVE_QUICK ) 406 ABISYM( mQmlImportPath ) = ABISYM( mPrefixPath ) +
'/' + QGIS_QML_SUBDIR +
'/';
418 QString mySvgPath = pkgDataPath + ( ABISYM( mRunningFromBuildDir ) ?
"/images/svg/" :
"/svg/" );
420 if ( !ABISYM( mDefaultSvgPaths ).contains( mySvgPath ) )
421 ABISYM( mDefaultSvgPaths ) << mySvgPath;
426 ABISYM( mDefaultSvgPaths ) = pathList;
431 QFileInfo fi( authDbDirPath );
432 if ( fi.exists() && fi.isDir() && fi.isWritable() )
434 ABISYM( mAuthDbDirPath ) = fi.canonicalFilePath() + QDir::separator();
440 if ( ABISYM( mRunningFromBuildDir ) )
442 static bool sOnce =
true;
446 ( void ) blockNotifications;
447 qWarning(
"!!! prefix path was requested, but it is not valid - we do not run from installed path !!!" );
452 return ABISYM( mPrefixPath );
456 return ABISYM( mPluginPath );
460 return ABISYM( mPkgDataPath );
464 return QStringLiteral(
":/images/themes/default/" );
469 QDir dir( usersThemes );
477 return defaultThemes;
483 return iconsPath() + QStringLiteral(
"qgis-icon-60x60.png" );
490 if ( QFile::exists( path + iconFile ) )
491 return path + iconFile;
500 if ( app && app->mIconCache.contains( name ) )
501 return app->mIconCache.value( name );
505 QString myPreferredPath =
activeThemePath() + QDir::separator() + name;
507 if ( QFile::exists( myPreferredPath ) )
509 icon = QIcon( myPreferredPath );
511 else if ( QFile::exists( myDefaultPath ) )
515 icon = QIcon( myDefaultPath );
523 app->mIconCache.insert( name, icon );
530 if ( app && app->mCursorCache.contains( cursor ) )
531 return app->mCursorCache.value( cursor );
542 name = QStringLiteral(
"mZoomIn.svg" );
547 name = QStringLiteral(
"mZoomOut.svg" );
554 name = QStringLiteral(
"mIdentify.svg" );
557 name = QStringLiteral(
"mCrossHair.svg" );
560 name = QStringLiteral(
"mCapturePoint.svg" );
563 name = QStringLiteral(
"mSelect.svg" );
570 name = QStringLiteral(
"mSampler.svg" );
575 Q_ASSERT( ! name.isEmpty( ) );
577 QIcon icon =
getThemeIcon( QStringLiteral(
"cursors" ) + QDir::separator() + name );
580 if ( ! icon.isNull( ) )
585 if ( app->devicePixelRatio() >= 2 )
587 scale *= app->devicePixelRatio();
588 activeX = activeY = 8;
591 cursorIcon = QCursor( icon.pixmap( std::ceil( scale * 32 ), std::ceil( scale * 32 ) ), std::ceil( scale * activeX ), std::ceil( scale * activeY ) );
594 app->mCursorCache.insert( cursor, cursorIcon );
601 QString myPreferredPath =
activeThemePath() + QDir::separator() + name;
603 if ( QFile::exists( myPreferredPath ) )
605 return QPixmap( myPreferredPath );
611 return QPixmap( myDefaultPath );
623 QString
prefixPath( getenv(
"QGIS_PREFIX_PATH" ) ? getenv(
"QGIS_PREFIX_PATH" ) : QDir::homePath() );
625 QString
prefixPath( getenv(
"QGIS_PREFIX_PATH" ) ? getenv(
"QGIS_PREFIX_PATH" ) : applicationDirPath() );
629 const QStringList pathPrefixes = QStringList() <<
"" <<
"/.." <<
"/bin" <<
"/../../..";
630 for (
const QString &path : pathPrefixes )
632 f.setFileName( prefixPath + path +
"/qgisbuildpath.txt" );
638 if ( f.exists() && f.open( QIODevice::ReadOnly ) )
641 return f.readLine().trimmed();
645 return prefixPath +
'/' + QStringLiteral( QGIS_DATA_SUBDIR );
652 return ABISYM( mThemeName );
659 if ( themeName == QStringLiteral(
"default" ) || !themes.contains( themeName ) )
662 qApp->setStyleSheet( QString() );
666 QString path = themes.value( themeName );
667 QString stylesheetname = path +
"/style.qss";
668 QString autostylesheet = stylesheetname +
".auto";
670 QFile file( stylesheetname );
671 QFile variablesfile( path +
"/variables.qss" );
672 QFile fileout( autostylesheet );
674 QFileInfo variableInfo( variablesfile );
676 if ( variableInfo.exists() && variablesfile.open( QIODevice::ReadOnly ) )
678 if ( !file.open( QIODevice::ReadOnly ) || !fileout.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
683 QString styledata = file.readAll();
684 QTextStream in( &variablesfile );
685 while ( !in.atEnd() )
687 QString line = in.readLine();
689 if ( line.startsWith(
'@' ) )
691 int index = line.indexOf(
':' );
692 QString name = line.mid( 0, index );
693 QString value = line.mid( index + 1, line.length() );
694 styledata.replace( name, value );
697 variablesfile.close();
698 QTextStream out( &fileout );
702 stylesheetname = autostylesheet;
705 QString styleSheet = QStringLiteral(
"file:///" );
706 styleSheet.append( stylesheetname );
707 qApp->setStyleSheet( styleSheet );
714 QHash<QString, QString> mapping;
715 mapping.insert( QStringLiteral(
"default" ), QLatin1String(
"" ) );
716 Q_FOREACH (
const QString &path, paths )
719 QFileInfoList styleFiles = folder.entryInfoList( QDir::Dirs | QDir::NoDotAndDotDot );
720 Q_FOREACH (
const QFileInfo &info, styleFiles )
722 QFileInfo styleFile( info.absoluteFilePath() +
"/style.qss" );
723 if ( !styleFile.exists() )
726 QString name = info.baseName();
727 QString path = info.absoluteFilePath();
728 mapping.insert( name, path );
736 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/doc/AUTHORS" );
741 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/doc/CONTRIBUTORS" );
745 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/doc/developersmap.html" );
750 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/doc/SPONSORS" );
755 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/doc/DONORS" );
760 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/doc/TRANSLATORS" );
765 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/doc/LICENSE" );
770 if ( ABISYM( mRunningFromBuildDir ) )
771 return ABISYM( mBuildOutputPath ) + QStringLiteral(
"/i18n" );
773 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/i18n/" );
778 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/resources/metadata-ISO/" );
783 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/resources/qgis.db" );
788 return ABISYM( mConfigPath );
798 return ABISYM( mAuthDbDirPath ) + QStringLiteral(
"qgis-auth.db" );
803 return QStringLiteral(
":/images/splash/" );
808 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/images/icons/" );
813 if ( ABISYM( mRunningFromBuildDir ) )
815 QString tempCopy = QDir::tempPath() +
"/srs.db";
817 if ( !QFile( tempCopy ).exists() )
819 QFile f( ABISYM( mPkgDataPath ) +
"/resources/srs.db" );
820 if ( !f.copy( tempCopy ) )
822 qFatal(
"Could not create temporary copy" );
830 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/resources/srs.db" );
839 QStringList pathList = settings.
value( QStringLiteral(
"svg/searchPathsForSVG" ) ).toStringList();
843 Q_FOREACH (
const QString &path, pathList )
845 if ( !paths.contains( path ) )
846 paths.append( path );
848 Q_FOREACH (
const QString &path, ABISYM( mDefaultSvgPaths ) )
850 if ( !paths.contains( path ) )
851 paths.append( path );
862 QStringList pathList = settings.
value( QStringLiteral(
"Layout/searchPathsForTemplates" ), QVariant(),
QgsSettings::Core ).toStringList();
874 return QRegExp(
"^[A-Za-z][A-Za-z0-9\\._-]*" );
879 if ( !sUserName.isEmpty() )
883 TCHAR name [ UNLEN + 1 ];
884 DWORD size = UNLEN + 1;
886 if ( GetUserName( ( TCHAR * )name, &size ) )
888 sUserName = QString( name );
894 process.start( QStringLiteral(
"whoami" ) );
895 process.waitForFinished();
896 sUserName = process.readAllStandardOutput().trimmed();
899 if ( !sUserName.isEmpty() )
903 sUserName = qgetenv(
"USER" );
904 if ( !sUserName.isEmpty() )
908 sUserName = qgetenv(
"USERNAME" );
914 if ( !sUserFullName.isEmpty() )
915 return sUserFullName;
918 TCHAR name [ UNLEN + 1 ];
919 DWORD size = UNLEN + 1;
922 if ( GetUserNameEx( NameDisplay, ( TCHAR * )name, &size ) )
924 sUserFullName = QString( name );
928 if ( sUserFullName.isEmpty() )
930 #elif defined(Q_OS_ANDROID) || defined(__MINGW32__) 931 sUserFullName =
"Not available";
933 struct passwd *p = getpwuid( getuid() );
937 QString gecosName = QString( p->pw_gecos );
938 sUserFullName = gecosName.left( gecosName.indexOf(
',', 0 ) );
943 return sUserFullName;
948 #if defined(Q_OS_ANDROID) 949 return QLatin1String(
"android" );
950 #elif defined(Q_OS_MAC) 951 return QLatin1String(
"osx" );
952 #elif defined(Q_OS_WIN) 953 return QLatin1String(
"windows" );
954 #elif defined(Q_OS_LINUX) 955 return QStringLiteral(
"linux" );
957 return QLatin1String(
"unknown" );
963 return sPlatformName;
969 bool overrideLocale = settings.
value( QStringLiteral(
"locale/overrideFlag" ),
false ).toBool();
970 if ( overrideLocale )
972 QString
locale = settings.
value( QStringLiteral(
"locale/userLocale" ), QString() ).toString();
974 if ( locale.startsWith( QStringLiteral(
"en" ), Qt::CaseInsensitive ) )
976 return locale.left( 2 );
983 return QLocale().name().left( 2 );
994 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/resources/symbology-style.xml" );
999 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/resources/themes" );
1004 return ABISYM( mPkgDataPath ) + QStringLiteral(
"/resources/server/" );
1009 return ABISYM( mLibraryPath );
1014 return ABISYM( mLibexecPath );
1019 return ABISYM( mQmlImportPath );
1024 return ( htonl( 1 ) == 1 ) ?
XDR :
NDR;
1069 if ( !sAuthManager )
1071 return sAuthManager;
1083 QgsApplication::sendPostedEvents(
nullptr, QEvent::DeferredDelete );
1101 GDALDestroyDriverManager();
1106 QString myEnvironmentVar( getenv(
"QGIS_PREFIX_PATH" ) );
1107 QString myState = tr(
"Application state:\n" 1108 "QGIS_PREFIX_PATH env var:\t\t%1\n" 1110 "Plugin Path:\t\t%3\n" 1111 "Package Data Path:\t%4\n" 1112 "Active Theme Name:\t%5\n" 1113 "Active Theme Path:\t%6\n" 1114 "Default Theme Path:\t%7\n" 1115 "SVG Search Paths:\t%8\n" 1116 "User DB Path:\t%9\n" 1117 "Auth DB Path:\t%10\n" )
1118 .arg( myEnvironmentVar,
1125 svgPaths().join( tr(
"\n\t\t",
"match indentation of application state" ) ),
1138 QColor myColor1( Qt::lightGray );
1139 QColor myColor2 = myColor1;
1140 myColor2 = myColor2.lighter( 110 );
1142 myStyle =
".overview{" 1144 " font-weight: bold;" 1147 " background: white;" 1149 " font-family: 'Lato', 'Ubuntu', 'Lucida Grande', 'Segoe UI', 'Arial', sans-serif;" 1152 "h1{ background-color: #F6F6F6;" 1154 " font-size: x-large; " 1155 " font-weight: normal;" 1156 " background: none;" 1157 " padding: 0.75em 0 0;" 1159 " line-height: 3em;" 1161 "h2{ background-color: #F6F6F6;" 1163 " font-size: medium; " 1164 " font-weight: normal;" 1165 " background: none;" 1166 " padding: 0.75em 0 0;" 1168 " line-height: 1.1em;" 1170 "h3{ background-color: #F6F6F6;" 1172 " font-weight: bold;" 1173 " font-size: large;" 1174 " text-align: right;" 1175 " border-bottom: 5px solid #DCEB5C;" 1177 "h4{ background-color: #F6F6F6;" 1179 " font-weight: bold;" 1180 " font-size: medium;" 1181 " text-align: right;" 1183 "h5{ background-color: #F6F6F6;" 1185 " font-weight: bold;" 1186 " font-size: small;" 1187 " text-align: right;" 1189 "a{ color: #729FCF;" 1190 " font-family: arial,sans-serif;" 1191 " font-size: small;" 1193 "label{ background-color: #FFFFCC;" 1194 " border: 1px solid black;" 1196 " padding: 0px 3px; " 1197 " font-size: small;" 1200 " font-weight: bold;" 1201 " padding-top:25px;" 1203 ".list-view .highlight {" 1204 " text-align: right;" 1207 " padding-right: 15px;" 1208 " padding-left: 20px;" 1209 " font-weight: bold;" 1212 " font-weight: bold;" 1215 " border-collapse: collapse;" 1218 ".tabular-view th, .tabular-view td { " 1219 " border:10px solid black;" 1221 ".tabular-view .odd-row{" 1222 " background-color: #f9f9f9;" 1227 " border-top: 1px solid black;" 1234 if ( 0 >= OGRGetDriverCount() )
1242 QString aPathUrl = aPath;
1243 QString tPathUrl = targetPath;
1244 #if defined( Q_OS_WIN ) 1245 const Qt::CaseSensitivity cs = Qt::CaseInsensitive;
1247 aPathUrl.replace(
'\\',
'/' );
1248 if ( aPathUrl.startsWith(
"//" ) )
1251 aPathUrl =
"\\\\" + aPathUrl.mid( 2 );
1254 tPathUrl.replace(
'\\',
'/' );
1255 if ( tPathUrl.startsWith(
"//" ) )
1258 tPathUrl =
"\\\\" + tPathUrl.mid( 2 );
1261 const Qt::CaseSensitivity cs = Qt::CaseSensitive;
1264 QStringList targetElems = tPathUrl.split(
'/', QString::SkipEmptyParts );
1265 QStringList aPathElems = aPathUrl.split(
'/', QString::SkipEmptyParts );
1267 targetElems.removeAll( QStringLiteral(
"." ) );
1268 aPathElems.removeAll( QStringLiteral(
"." ) );
1272 while ( !aPathElems.isEmpty() &&
1273 !targetElems.isEmpty() &&
1274 aPathElems[0].compare( targetElems[0], cs ) == 0 )
1276 aPathElems.removeFirst();
1277 targetElems.removeFirst();
1287 if ( !targetElems.isEmpty() )
1290 for (
int i = 0; i < targetElems.size(); i++ )
1292 aPathElems.insert( 0, QStringLiteral(
".." ) );
1299 aPathElems.insert( 0, QStringLiteral(
"." ) );
1302 return aPathElems.join( QStringLiteral(
"/" ) );
1308 if ( !rpath.startsWith( QLatin1String(
"./" ) ) && !rpath.startsWith( QLatin1String(
"../" ) ) )
1313 QString rPathUrl = rpath;
1314 QString targetPathUrl = targetPath;
1316 #if defined(Q_OS_WIN) 1317 rPathUrl.replace(
'\\',
'/' );
1318 targetPathUrl.replace(
'\\',
'/' );
1320 bool uncPath = targetPathUrl.startsWith(
"//" );
1323 QStringList srcElems = rPathUrl.split(
'/', QString::SkipEmptyParts );
1324 QStringList targetElems = targetPathUrl.split(
'/', QString::SkipEmptyParts );
1326 #if defined(Q_OS_WIN) 1329 targetElems.insert( 0,
"" );
1330 targetElems.insert( 0,
"" );
1335 targetElems << srcElems;
1336 targetElems.removeAll( QStringLiteral(
"." ) );
1340 while ( ( pos = targetElems.indexOf( QStringLiteral(
".." ) ) ) > 0 )
1343 targetElems.removeAt( pos - 1 );
1344 targetElems.removeAt( pos - 1 );
1347 #if !defined(Q_OS_WIN) 1349 targetElems.prepend( QLatin1String(
"" ) );
1352 return targetElems.join( QStringLiteral(
"/" ) );
1357 if (
ABISYM( mGdalSkipList ).contains( driver ) || driver.isEmpty() )
1361 ABISYM( mGdalSkipList ) << driver;
1367 if ( !
ABISYM( mGdalSkipList ).contains( driver ) )
1371 int myPos =
ABISYM( mGdalSkipList ).indexOf( driver );
1374 ABISYM( mGdalSkipList ).removeAt( myPos );
1381 ABISYM( mGdalSkipList ).removeDuplicates();
1382 QString myDriverList =
ABISYM( mGdalSkipList ).join( QStringLiteral(
" " ) );
1383 QgsDebugMsg(
"Gdal Skipped driver list set to:" );
1385 CPLSetConfigOption(
"GDAL_SKIP", myDriverList.toUtf8() );
1392 QDir myDir( folder );
1393 if ( !myDir.exists() )
1395 myDir.mkpath( folder );
1401 void QgsApplication::copyPath(
const QString &src,
const QString &dst )
1404 if ( ! dir.exists() )
1407 Q_FOREACH (
const QString &d, dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
1409 QString dst_path = dst + QDir::separator() + d;
1410 dir.mkpath( dst_path );
1411 copyPath( src + QDir::separator() + d, dst_path );
1414 Q_FOREACH (
const QString &f, dir.entryList( QDir::Files ) )
1416 QFile::copy( src + QDir::separator() + f, dst + QDir::separator() + f );
1425 QVariantMap variables;
1429 QStringList childKeys = settings.
childKeys();
1430 for ( QStringList::const_iterator it = childKeys.constBegin(); it != childKeys.constEnd(); ++it )
1433 variables.insert( name, settings.
value( name ) );
1443 QVariantMap::const_iterator it = variables.constBegin();
1446 for ( ; it != variables.constEnd(); ++it )
1448 settings.
setValue( it.key(), it.value() );
1459 settings.
setValue( QStringLiteral(
"variables/" ) + name, value );
1467 ApplicationMembers *appMembers = members();
1468 if ( appMembers->mNullRepresentation.isNull() )
1470 appMembers->mNullRepresentation =
QgsSettings().
value( QStringLiteral(
"qgis/nullValue" ), QStringLiteral(
"NULL" ) ).toString();
1472 return appMembers->mNullRepresentation;
1477 ApplicationMembers *appMembers = members();
1478 if ( !appMembers || appMembers->mNullRepresentation == nullRepresentation )
1491 return members()->mActionScopeRegistry;
1500 QDir myDir( myPamPath );
1501 if ( !myDir.exists() )
1503 myDir.mkpath( myPamPath );
1506 #if defined(Q_OS_WIN) 1507 CPLSetConfigOption(
"GDAL_PAM_PROXY_DIR", myPamPath.toUtf8() );
1511 int myChangeFlag = 0;
1512 setenv(
"GDAL_PAM_PROXY_DIR", myPamPath.toUtf8(), myChangeFlag );
1519 if ( !qgisPrivateDbFile.exists() )
1523 QFile masterFile( qgisMasterDbFileName );
1529 bool isDbFileCopied = masterFile.copy( qgisPrivateDbFile.fileName() );
1531 if ( !isDbFileCopied )
1535 *errorMessage = tr(
"[ERROR] Can not make qgis.db private copy" );
1540 QFile::Permissions perms = QFile( qgisPrivateDbFile.fileName() ).permissions();
1541 if ( !( perms & QFile::WriteOwner ) )
1543 if ( !qgisPrivateDbFile.setPermissions( perms | QFile::WriteOwner ) )
1547 *errorMessage = tr(
"Can not make '%1' user writable" ).arg( qgisPrivateDbFile.fileName() );
1561 *errorMessage = tr(
"Could not open qgis.db" );
1566 char *errmsg =
nullptr;
1567 int res = sqlite3_exec( database.get(),
"SELECT epsg FROM tbl_srs LIMIT 0",
nullptr,
nullptr, &errmsg );
1568 if ( res == SQLITE_OK )
1571 if ( sqlite3_exec( database.get(),
1572 "ALTER TABLE tbl_srs RENAME TO tbl_srs_bak;" 1573 "CREATE TABLE tbl_srs (" 1574 "srs_id INTEGER PRIMARY KEY," 1575 "description text NOT NULL," 1576 "projection_acronym text NOT NULL," 1577 "ellipsoid_acronym NOT NULL," 1578 "parameters text NOT NULL," 1580 "auth_name varchar," 1582 "is_geo integer NOT NULL," 1583 "deprecated boolean);" 1584 "CREATE INDEX idx_srsauthid on tbl_srs(auth_name,auth_id);" 1585 "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;" 1586 "DROP TABLE tbl_srs_bak",
nullptr,
nullptr, &errmsg ) != SQLITE_OK
1591 *errorMessage = tr(
"Migration of private qgis.db failed.\n%1" ).arg( QString::fromUtf8( errmsg ) );
1593 sqlite3_free( errmsg );
1599 sqlite3_free( errmsg );
1602 if ( sqlite3_exec( database.get(),
"DROP VIEW vw_srs",
nullptr,
nullptr, &errmsg ) != SQLITE_OK )
1604 QgsDebugMsg( QString(
"vw_srs didn't exists in private qgis.db: %1" ).arg( errmsg ) );
1607 if ( sqlite3_exec( database.get(),
1608 "CREATE VIEW vw_srs AS" 1610 " a.description AS description" 1611 ",a.srs_id AS srs_id" 1612 ",a.is_geo AS is_geo" 1613 ",coalesce(b.name,a.projection_acronym) AS name" 1614 ",a.parameters AS parameters" 1615 ",a.auth_name AS auth_name" 1616 ",a.auth_id AS auth_id" 1617 ",a.deprecated AS deprecated" 1619 " LEFT OUTER JOIN tbl_projection b ON a.projection_acronym=b.acronym" 1620 " ORDER BY coalesce(b.name,a.projection_acronym),a.description",
nullptr,
nullptr, &errmsg ) != SQLITE_OK
1625 *errorMessage = tr(
"Update of view in private qgis.db failed.\n%1" ).arg( QString::fromUtf8( errmsg ) );
1627 sqlite3_free( errmsg );
1636 QgsDebugMsg( QString(
"maxThreads: %1" ).arg( maxThreads ) );
1640 if ( maxThreads < 1 || maxThreads > QThread::idealThreadCount() )
1647 if ( maxThreads == -1 )
1648 maxThreads = QThread::idealThreadCount();
1651 QThreadPool::globalInstance()->setMaxThreadCount( maxThreads );
1652 QgsDebugMsg( QString(
"set QThreadPool max thread count to %1" ).arg( QThreadPool::globalInstance()->maxThreadCount() ) );
1657 return members()->mTaskManager;
1662 return members()->mColorSchemeRegistry;
1667 return members()->mPaintEffectRegistry;
1672 return members()->mRendererRegistry;
1677 return members()->mRasterRendererRegistry;
1684 if ( !
instance()->mDataItemProviderRegistry )
1688 return instance()->mDataItemProviderRegistry;
1694 if ( !sDataItemProviderRegistry )
1696 return sDataItemProviderRegistry;
1702 return members()->mSvgCache;
1707 return members()->mNetworkContentFetcherRegistry;
1712 return members()->mSymbolLayerRegistry;
1717 return members()->mLayoutItemRegistry;
1722 return members()->mGpsConnectionRegistry;
1727 return members()->mPluginLayerRegistry;
1732 return members()->mMessageLog;
1737 return members()->mProcessingRegistry;
1742 return members()->mPageSizeRegistry;
1747 return members()->mAnnotationRegistry;
1752 return members()->mFieldFormatterRegistry;
1757 return members()->m3DRendererRegistry;
1762 return members()->mProjectStorageRegistry;
1765 QgsApplication::ApplicationMembers::ApplicationMembers()
1785 mLayoutItemRegistry->populate();
1786 mAnnotationRegistry =
new QgsAnnotationRegistry();
1792 QgsApplication::ApplicationMembers::~ApplicationMembers()
1794 delete mActionScopeRegistry;
1795 delete m3DRendererRegistry;
1796 delete mAnnotationRegistry;
1797 delete mColorSchemeRegistry;
1798 delete mFieldFormatterRegistry;
1799 delete mGpsConnectionRegistry;
1801 delete mPaintEffectRegistry;
1802 delete mPluginLayerRegistry;
1803 delete mProcessingRegistry;
1804 delete mProjectStorageRegistry;
1805 delete mPageSizeRegistry;
1806 delete mLayoutItemRegistry;
1808 delete mRasterRendererRegistry;
1809 delete mRendererRegistry;
1811 delete mSymbolLayerRegistry;
1812 delete mTaskManager;
1813 delete mNetworkContentFetcherRegistry;
1816 QgsApplication::ApplicationMembers *QgsApplication::members()
1820 return instance()->mApplicationMembers;
1824 static QMutex sMemberMutex( QMutex::Recursive );
1825 QMutexLocker lock( &sMemberMutex );
1826 if ( !sApplicationMembers )
1827 sApplicationMembers =
new ApplicationMembers();
1828 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...
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.
void addDefaultSchemes()
Adds all default color schemes to this color scheme.
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()
Gets 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.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
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).
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...
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
A cache for images / pictures derived from svg files.
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 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)
Sets the FileOpen event receiver.
static QString reportStyleSheet()
Returns a standard css style sheet for reports.
static int maxThreads()
Gets 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...
static QgsMessageLog * messageLog()
Returns the application's message log.
static void applyGdalSkippedDrivers()
Apply the skipped drivers list to gdal.
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.
Registry for temporary fetched files.
static bool createThemeFolder()
Create the users theme folder.
static bool createDatabase(QString *errorMessage=nullptr)
initialize qgis.db
static void cleanRegisteredFunctions()
Deletes all registered functions whose ownership have been transferred to the expression engine...
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 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.
static QgsProjectStorageRegistry * projectStorageRegistry()
Returns registry of available project storage implementations.
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...
void beginGroup(const QString &prefix, QgsSettings::Section section=QgsSettings::NoSection)
Appends prefix to the current group.
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 QString contributorsFilePath()
Returns the path to the contributors file.
static QString activeThemePath()
Returns the path to the currently active theme directory.
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 QgsProject * instance()
Returns the QgsProject singleton instance.
A class to register / unregister existing GPS connections such that the information is available to a...
static QgsNetworkContentFetcherRegistry * networkContentFetcherRegistry()
Returns the application's network content registry used for fetching temporary files during QGIS sess...
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
Temporarily blocks the application QgsMessageLog (see QgsApplication::messageLog()) from emitting the...
static QStringList svgPaths()
Returns the paths to svg directories.
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.
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 QString qmlImportPath()
Returns the path where QML components are installed for QGIS Quick library.
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.