Skip to content

Commit 0310c1d

Browse files
authoredFeb 16, 2018
Merge pull request #6354 from elpaso/NathanW2-settings_17670
Nathan w2 settings 17670
2 parents 14787ff + 26edd8a commit 0310c1d

File tree

8 files changed

+76
-19
lines changed

8 files changed

+76
-19
lines changed
 

‎python/core/qgsapplication.sip.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ for resources in their own datastores e.g. a Qt4 resource bundle.
143143
be reverted to 'default'.
144144
%End
145145

146+
static QString resolvePkgPath( );
147+
%Docstring
148+
Calculate the application pkg path
149+
150+
:return: the resolved pkg path
151+
%End
152+
146153
static QString themeName();
147154
%Docstring
148155
Set the active theme to the specified theme.

‎resources/CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
INSTALL(FILES srs.db qgis.db symbology-style.xml spatialite.db customization.xml 2to3migration.txt
1+
INSTALL(FILES srs.db
2+
qgis.db
3+
symbology-style.xml
4+
spatialite.db
5+
customization.xml
6+
2to3migration.txt
7+
qgis_global_settings.ini
28
DESTINATION ${QGIS_DATA_DIR}/resources)
3-
INSTALL(FILES qgis_global_settings.ini
4-
DESTINATION ${QGIS_DATA_DIR})
59
INSTALL(DIRECTORY cpt-city-qgis-min DESTINATION ${QGIS_DATA_DIR}/resources)
610
INSTALL(DIRECTORY themes DESTINATION ${QGIS_DATA_DIR}/resources)
711
INSTALL(DIRECTORY data DESTINATION ${QGIS_DATA_DIR}/resources)

‎src/app/main.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,8 @@ int main( int argc, char *argv[] )
798798
QCoreApplication::setAttribute( Qt::AA_DisableWindowContextHelpButton, true );
799799
#endif
800800

801+
QgsApplication myApp( argc, argv, myUseGuiFlag );
802+
801803
// SetUp the QgsSettings Global Settings:
802804
// - use the path specified with --globalsettingsfile path,
803805
// - use the environment if not found
@@ -809,7 +811,7 @@ int main( int argc, char *argv[] )
809811

810812
if ( globalsettingsfile.isEmpty() )
811813
{
812-
QString default_globalsettingsfile = QgsApplication::pkgDataPath() + "/qgis_global_settings.ini";
814+
QString default_globalsettingsfile = QgsApplication::resolvePkgPath() + "/resources/qgis_global_settings.ini";
813815
if ( QFile::exists( default_globalsettingsfile ) )
814816
{
815817
globalsettingsfile = default_globalsettingsfile;
@@ -862,12 +864,12 @@ int main( int argc, char *argv[] )
862864
// Should be cleaned up in future to make this cleaner.
863865
QgsSettings settings;
864866

865-
QgsDebugMsg( "User profile details:" );
866-
QgsDebugMsg( QString( "\t - %1" ).arg( profileName ) );
867-
QgsDebugMsg( QString( "\t - %1" ).arg( profileFolder ) );
868-
QgsDebugMsg( QString( "\t - %1" ).arg( rootProfileFolder ) );
867+
QgsDebugMsgLevel( QStringLiteral( "User profile details:" ), 2 );
868+
QgsDebugMsgLevel( QStringLiteral( "\t - %1" ).arg( profileName ), 2 );
869+
QgsDebugMsgLevel( QStringLiteral( "\t - %1" ).arg( profileFolder ), 2 );
870+
QgsDebugMsgLevel( QStringLiteral( "\t - %1" ).arg( rootProfileFolder ), 2 );
869871

870-
QgsApplication myApp( argc, argv, myUseGuiFlag, profileFolder );
872+
myApp.init( profileFolder );
871873

872874
// Settings migration is only supported on the default profile for now.
873875
if ( profileName == "default" )

‎src/core/qgsapplication.cpp

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,13 @@ QString ABISYM( QgsApplication::mLibraryPath );
9191
QString ABISYM( QgsApplication::mLibexecPath );
9292
QString ABISYM( QgsApplication::mThemeName );
9393
QString ABISYM( QgsApplication::mUIThemeName );
94+
QString ABISYM( QgsApplication::mProfilePath );
95+
9496
QStringList ABISYM( QgsApplication::mDefaultSvgPaths );
9597
QMap<QString, QString> ABISYM( QgsApplication::mSystemEnvVars );
9698
QString ABISYM( QgsApplication::mConfigPath );
99+
100+
bool ABISYM( QgsApplication::mInitialized ) = false;
97101
bool ABISYM( QgsApplication::mRunningFromBuildDir ) = false;
98102
QString ABISYM( QgsApplication::mBuildSourcePath );
99103
#ifdef _MSC_VER
@@ -121,7 +125,7 @@ QgsApplication::QgsApplication( int &argc, char **argv, bool GUIenabled, const Q
121125

122126
mApplicationMembers = new ApplicationMembers();
123127

124-
init( profileFolder ); // init can also be called directly by e.g. unit tests that don't inherit QApplication.
128+
ABISYM( mProfilePath ) = profileFolder;
125129
}
126130

127131
void QgsApplication::init( QString profileFolder )
@@ -146,6 +150,8 @@ void QgsApplication::init( QString profileFolder )
146150
delete profile;
147151
}
148152

153+
ABISYM( mProfilePath ) = profileFolder;
154+
149155
qRegisterMetaType<QgsGeometry::Error>( "QgsGeometry::Error" );
150156
qRegisterMetaType<QgsProcessingFeatureSourceDefinition>( "QgsProcessingFeatureSourceDefinition" );
151157
qRegisterMetaType<QgsProcessingOutputLayerDefinition>( "QgsProcessingOutputLayerDefinition" );
@@ -259,6 +265,8 @@ void QgsApplication::init( QString profileFolder )
259265
// this should be read from QgsSettings but we don't know where they are at this point
260266
// so we read actual value in main.cpp
261267
ABISYM( mMaxThreads ) = -1;
268+
269+
ABISYM( mInitialized ) = true;
262270
}
263271

264272
QgsApplication::~QgsApplication()
@@ -577,6 +585,36 @@ void QgsApplication::setThemeName( const QString &themeName )
577585
ABISYM( mThemeName ) = themeName;
578586
}
579587

588+
QString QgsApplication::resolvePkgPath()
589+
{
590+
#if defined(ANDROID)
591+
QString prefixPath( getenv( "QGIS_PREFIX_PATH" ) ? getenv( "QGIS_PREFIX_PATH" ) : QDir::homePath() );
592+
#else
593+
QString prefixPath( getenv( "QGIS_PREFIX_PATH" ) ? getenv( "QGIS_PREFIX_PATH" ) : applicationDirPath() );
594+
#endif
595+
QFile f;
596+
// "/../../.." is for Mac bundled app in build directory
597+
const QStringList pathPrefixes = QStringList() << "" << "/.." << "/bin" << "/../../..";
598+
for ( const QString &path : pathPrefixes )
599+
{
600+
f.setFileName( prefixPath + path + "/qgisbuildpath.txt" );
601+
QgsDebugMsg( f.fileName() );
602+
if ( f.exists() )
603+
break;
604+
}
605+
606+
if ( f.exists() && f.open( QIODevice::ReadOnly ) )
607+
{
608+
QgsDebugMsg( "Running from build dir!" );
609+
return f.readLine().trimmed();
610+
}
611+
else
612+
{
613+
return prefixPath + '/' + QStringLiteral( QGIS_DATA_SUBDIR );
614+
}
615+
616+
}
617+
580618
QString QgsApplication::themeName()
581619
{
582620
return ABISYM( mThemeName );
@@ -951,6 +989,11 @@ QgsApplication::endian_t QgsApplication::endian()
951989

952990
void QgsApplication::initQgis()
953991
{
992+
if ( !ABISYM( mInitialized ) && QgsApplication::instance() )
993+
{
994+
init( ABISYM( mProfilePath ) );
995+
}
996+
954997
// set the provider plugin path (this creates provider registry)
955998
QgsProviderRegistry::instance( pluginPath() );
956999

‎src/core/qgsapplication.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ class CORE_EXPORT QgsApplication : public QApplication
184184
*/
185185
static void setThemeName( const QString &themeName );
186186

187+
/**
188+
* Calculate the application pkg path
189+
* \return the resolved pkg path
190+
*/
191+
static QString resolvePkgPath( );
192+
187193
/**
188194
* Set the active theme to the specified theme.
189195
* The theme name should be a single word e.g. 'default','classic'.
@@ -732,6 +738,7 @@ class CORE_EXPORT QgsApplication : public QApplication
732738
static QObject *ABISYM( mFileOpenEventReceiver );
733739
static QStringList ABISYM( mFileOpenEventList );
734740

741+
static QString ABISYM( mProfilePath );
735742
static QString ABISYM( mUIThemeName );
736743
static QString ABISYM( mPrefixPath );
737744
static QString ABISYM( mPluginPath );
@@ -744,6 +751,8 @@ class CORE_EXPORT QgsApplication : public QApplication
744751

745752
static QString ABISYM( mConfigPath );
746753

754+
static bool ABISYM( mInitialized );
755+
747756
//! True when running from build directory, i.e. without 'make install'
748757
static bool ABISYM( mRunningFromBuildDir );
749758
//! Path to the source directory. valid only when running from build directory.

‎src/server/qgsserver.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,6 @@ bool QgsServer::init()
194194
QCoreApplication::setOrganizationDomain( QgsApplication::QGIS_ORGANIZATION_DOMAIN );
195195
QCoreApplication::setApplicationName( QgsApplication::QGIS_APPLICATION_NAME );
196196

197-
#if !defined(Q_OS_WIN)
198-
// Set the QGIS_PREFIX_PATH environnemnt instead of calling directly
199-
// setPrefixPath: this will allow running server from build directory
200-
// and get the paths accordingly
201-
setenv( "QGIS_PREFIX_PATH", CMAKE_INSTALL_PREFIX, 1 );
202-
#endif
203-
204-
//Default prefix path may be altered by environment variable
205197
QgsApplication::init();
206198

207199
#if defined(SERVER_SKIP_ECW)

‎src/test/qgstest.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
int main(int argc, char *argv[]) \
2727
{ \
2828
QgsApplication app(argc, argv, false); \
29+
app.init(); \
2930
app.setAttribute(Qt::AA_Use96Dpi, true); \
3031
QTEST_DISABLE_KEYPAD_NAVIGATION \
3132
QTEST_ADD_GPU_BLACKLIST_SUPPORT \

‎tests/src/python/test_qgsserver.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,6 @@ def test_wcs_getcapabilities_url(self):
400400
item_found = False
401401
for item in str(r).split("\\n"):
402402
if "OnlineResource" in item:
403-
print("OnlineResource: ", item)
404403
self.assertEqual("\"my_wcs_advertised_url" in item, True)
405404
item_found = True
406405
self.assertTrue(item_found)

0 commit comments

Comments
 (0)
Please sign in to comment.