Skip to content

Commit

Permalink
Don't call init in QgsApplication
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed Feb 12, 2018
1 parent 9198971 commit 3207600
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/app/main.cpp
Expand Up @@ -798,7 +798,8 @@ int main( int argc, char *argv[] )
QCoreApplication::setAttribute( Qt::AA_DisableWindowContextHelpButton, true );
#endif

QApplication *subapp = new QApplication(argc, argv);
QgsApplication myApp( argc, argv, myUseGuiFlag );

// SetUp the QgsSettings Global Settings:
// - use the path specified with --globalsettingsfile path,
// - use the environment if not found
Expand Down Expand Up @@ -851,7 +852,6 @@ int main( int argc, char *argv[] )
}
}
delete globalSettings;
delete subapp;

QgsDebugMsg( "CONFIG LOCAL STORAGE:" + configLocalStorageLocation );

Expand All @@ -872,7 +872,7 @@ int main( int argc, char *argv[] )
QgsDebugMsg( QString( "\t - %1" ).arg( profileFolder ) );
QgsDebugMsg( QString( "\t - %1" ).arg( rootProfileFolder ) );

QgsApplication myApp( argc, argv, myUseGuiFlag, profileFolder );
myApp.init( profileFolder );

// Settings migration is only supported on the default profile for now.
if ( profileName == "default" )
Expand Down
19 changes: 16 additions & 3 deletions src/core/qgsapplication.cpp
Expand Up @@ -91,9 +91,13 @@ QString ABISYM( QgsApplication::mLibraryPath );
QString ABISYM( QgsApplication::mLibexecPath );
QString ABISYM( QgsApplication::mThemeName );
QString ABISYM( QgsApplication::mUIThemeName );
QString ABISYM( QgsApplication::mProfilePath );

QStringList ABISYM( QgsApplication::mDefaultSvgPaths );
QMap<QString, QString> ABISYM( QgsApplication::mSystemEnvVars );
QString ABISYM( QgsApplication::mConfigPath );

bool ABISYM( QgsApplication::mInitialized ) = false;
bool ABISYM( QgsApplication::mRunningFromBuildDir ) = false;
QString ABISYM( QgsApplication::mBuildSourcePath );
#ifdef _MSC_VER
Expand Down Expand Up @@ -121,7 +125,7 @@ QgsApplication::QgsApplication( int &argc, char **argv, bool GUIenabled, const Q

mApplicationMembers = new ApplicationMembers();

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

void QgsApplication::init( QString profileFolder )
Expand All @@ -146,6 +150,8 @@ void QgsApplication::init( QString profileFolder )
delete profile;
}

ABISYM( mProfilePath ) = profileFolder;

qRegisterMetaType<QgsGeometry::Error>( "QgsGeometry::Error" );
qRegisterMetaType<QgsProcessingFeatureSourceDefinition>( "QgsProcessingFeatureSourceDefinition" );
qRegisterMetaType<QgsProcessingOutputLayerDefinition>( "QgsProcessingOutputLayerDefinition" );
Expand Down Expand Up @@ -259,6 +265,8 @@ void QgsApplication::init( QString profileFolder )
// this should be read from QgsSettings but we don't know where they are at this point
// so we read actual value in main.cpp
ABISYM( mMaxThreads ) = -1;

ABISYM( mInitialized ) = true;
}

QgsApplication::~QgsApplication()
Expand Down Expand Up @@ -589,14 +597,14 @@ QString QgsApplication::resolvePkgPath()
Q_FOREACH ( const QString &path, QStringList() << "" << "/.." << "/bin" << "/../../.." )
{
f.setFileName( prefixPath + path + "/qgisbuildpath.txt" );
QgsDebugMsg(f.fileName());
QgsDebugMsg( f.fileName() );
if ( f.exists() )
break;
}

if ( f.exists() && f.open( QIODevice::ReadOnly ) )
{
QgsDebugMsg("Running from build dir!");
QgsDebugMsg( "Running from build dir!" );
return f.readLine().trimmed();
}
else
Expand Down Expand Up @@ -980,6 +988,11 @@ QgsApplication::endian_t QgsApplication::endian()

void QgsApplication::initQgis()
{
if ( !ABISYM( mInitialized ) )
{
init( ABISYM( mProfilePath ) );
}

// set the provider plugin path (this creates provider registry)
QgsProviderRegistry::instance( pluginPath() );

Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsapplication.h
Expand Up @@ -734,6 +734,7 @@ class CORE_EXPORT QgsApplication : public QApplication
static QObject *ABISYM( mFileOpenEventReceiver );
static QStringList ABISYM( mFileOpenEventList );

static QString ABISYM( mProfilePath );
static QString ABISYM( mUIThemeName );
static QString ABISYM( mPrefixPath );
static QString ABISYM( mPluginPath );
Expand All @@ -746,6 +747,8 @@ class CORE_EXPORT QgsApplication : public QApplication

static QString ABISYM( mConfigPath );

static bool ABISYM( mInitialized );

//! True when running from build directory, i.e. without 'make install'
static bool ABISYM( mRunningFromBuildDir );
//! Path to the source directory. valid only when running from build directory.
Expand Down

0 comments on commit 3207600

Please sign in to comment.