@@ -3225,8 +3225,6 @@ void QgisApp::fileOpen()
3225
3225
return ;
3226
3226
}
3227
3227
3228
- closeProject ();
3229
-
3230
3228
// Fix by Tim - getting the dirPath from the dialog
3231
3229
// directly truncates the last node in the dir path.
3232
3230
// This is a workaround for that
@@ -3235,55 +3233,8 @@ void QgisApp::fileOpen()
3235
3233
// Persist last used project dir
3236
3234
settings.setValue ( " /UI/lastProjectDir" , myPath );
3237
3235
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 );
3287
3238
}
3288
3239
} // QgisApp::fileOpen
3289
3240
@@ -3302,15 +3253,10 @@ void QgisApp::enableProjectMacros()
3302
3253
*/
3303
3254
bool QgisApp::addProject ( QString projectFile )
3304
3255
{
3305
- mMapCanvas ->freeze ( true );
3306
-
3307
3256
QApplication::setOverrideCursor ( Qt::WaitCursor );
3308
3257
3309
- deletePrintComposers ();
3310
- removeAnnotationItems ();
3311
-
3312
- // clear the map canvas
3313
- removeAllLayers ();
3258
+ // close the previous opened project if any
3259
+ closeProject ();
3314
3260
3315
3261
if ( ! QgsProject::instance ()->read ( projectFile ) )
3316
3262
{
@@ -3355,6 +3301,26 @@ bool QgisApp::addProject( QString projectFile )
3355
3301
mMapCanvas ->updateScale ();
3356
3302
QgsDebugMsg ( " Scale restored..." );
3357
3303
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
+
3358
3324
emit projectRead (); // let plug-ins know that we've read in a new
3359
3325
// project so that they can check any project
3360
3326
// specific plug-in state
0 commit comments