Skip to content

Commit bc1bce1

Browse files
committedOct 3, 2012
unify the QGis behavior opening project files (fix #6406) and cleanup
1 parent f2eb092 commit bc1bce1

File tree

1 file changed

+24
-58
lines changed

1 file changed

+24
-58
lines changed
 

‎src/app/qgisapp.cpp

+24-58
Original file line numberDiff line numberDiff line change
@@ -3225,8 +3225,6 @@ void QgisApp::fileOpen()
32253225
return;
32263226
}
32273227

3228-
closeProject();
3229-
32303228
// Fix by Tim - getting the dirPath from the dialog
32313229
// directly truncates the last node in the dir path.
32323230
// This is a workaround for that
@@ -3235,55 +3233,8 @@ void QgisApp::fileOpen()
32353233
// Persist last used project dir
32363234
settings.setValue( "/UI/lastProjectDir", myPath );
32373235

3238-
QgsProject::instance()->setFileName( fullPath );
3239-
3240-
if ( ! QgsProject::instance()->read() )
3241-
{
3242-
QMessageBox::critical( this,
3243-
tr( "QGIS Project Read Error" ),
3244-
QgsProject::instance()->error() );
3245-
mMapCanvas->freeze( false );
3246-
mMapCanvas->refresh();
3247-
return;
3248-
}
3249-
3250-
setTitleBarText_( *this );
3251-
3252-
bool projectScales = QgsProject::instance()->readBoolEntry( "Scales", "/useProjectScales" );
3253-
if ( projectScales )
3254-
{
3255-
mScaleEdit->updateScales( QgsProject::instance()->readListEntry( "Scales", "/ScalesList" ) );
3256-
}
3257-
3258-
// does the project have any macros?
3259-
if ( mPythonUtils && mPythonUtils->isEnabled() )
3260-
{
3261-
if ( !QgsProject::instance()->readEntry( "Macros", "/pythonCode", QString::null ).isEmpty() )
3262-
{
3263-
int enableMacros = settings.value( "/qgis/enableMacros", 1 ).toInt();
3264-
// 0 = never, 1 = ask, 2 = just for this session, 3 = always
3265-
3266-
if ( enableMacros == 3 || enableMacros == 2 )
3267-
{
3268-
enableProjectMacros();
3269-
}
3270-
else if ( enableMacros == 1 ) // ask
3271-
{
3272-
// display the macros notification widget
3273-
mInfoBar->pushWidget( mMacrosWarn, 1 );
3274-
}
3275-
}
3276-
}
3277-
3278-
emit projectRead(); // let plug-ins know that we've read in a new
3279-
// project so that they can check any project
3280-
// specific plug-in state
3281-
3282-
// add this to the list of recently used project files
3283-
saveRecentProjectPath( fullPath, settings );
3284-
3285-
mMapCanvas->freeze( false );
3286-
mMapCanvas->refresh();
3236+
// open the selected project
3237+
addProject( fullPath );
32873238
}
32883239
} // QgisApp::fileOpen
32893240

@@ -3302,15 +3253,10 @@ void QgisApp::enableProjectMacros()
33023253
*/
33033254
bool QgisApp::addProject( QString projectFile )
33043255
{
3305-
mMapCanvas->freeze( true );
3306-
33073256
QApplication::setOverrideCursor( Qt::WaitCursor );
33083257

3309-
deletePrintComposers();
3310-
removeAnnotationItems();
3311-
3312-
// clear the map canvas
3313-
removeAllLayers();
3258+
// close the previous opened project if any
3259+
closeProject();
33143260

33153261
if ( ! QgsProject::instance()->read( projectFile ) )
33163262
{
@@ -3355,6 +3301,26 @@ bool QgisApp::addProject( QString projectFile )
33553301
mMapCanvas->updateScale();
33563302
QgsDebugMsg( "Scale restored..." );
33573303

3304+
// does the project have any macros?
3305+
if ( mPythonUtils && mPythonUtils->isEnabled() )
3306+
{
3307+
if ( !QgsProject::instance()->readEntry( "Macros", "/pythonCode", QString::null ).isEmpty() )
3308+
{
3309+
int enableMacros = settings.value( "/qgis/enableMacros", 1 ).toInt();
3310+
// 0 = never, 1 = ask, 2 = just for this session, 3 = always
3311+
3312+
if ( enableMacros == 3 || enableMacros == 2 )
3313+
{
3314+
enableProjectMacros();
3315+
}
3316+
else if ( enableMacros == 1 ) // ask
3317+
{
3318+
// display the macros notification widget
3319+
mInfoBar->pushWidget( mMacrosWarn, 1 );
3320+
}
3321+
}
3322+
}
3323+
33583324
emit projectRead(); // let plug-ins know that we've read in a new
33593325
// project so that they can check any project
33603326
// specific plug-in state

0 commit comments

Comments
 (0)
Please sign in to comment.