Skip to content

Commit

Permalink
Cleanup project closing
Browse files Browse the repository at this point in the history
- ensure that layers are removed when clearing projects
- ensure that project is cleared before destruction
  • Loading branch information
nyalldawson committed May 5, 2017
1 parent 67e1558 commit fe67704
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 12 deletions.
9 changes: 1 addition & 8 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4768,8 +4768,6 @@ void QgisApp::fileNew( bool promptToSaveFlag, bool forceBlank )
closeProject();

QgsProject *prj = QgsProject::instance();
prj->clear();

prj->layerTreeRegistryBridge()->setNewLayersVisible( settings.value( QStringLiteral( "qgis/new_layers_visible" ), true ).toBool() );

//set the color for selections
Expand Down Expand Up @@ -8737,11 +8735,6 @@ void QgisApp::removingLayers( const QStringList &layers )
}
}

void QgisApp::removeAllLayers()
{
QgsProject::instance()->removeAllMapLayers();
}

void QgisApp::removeLayer()
{
if ( !mLayerTreeView )
Expand Down Expand Up @@ -10032,7 +10025,7 @@ void QgisApp::closeProject()
mMapCanvas->clearCache();
mOverviewCanvas->setLayers( QList<QgsMapLayer *>() );
mMapCanvas->freeze( false );
removeAllLayers();
QgsProject::instance()->clear();
}


Expand Down
2 changes: 0 additions & 2 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

//! Set the extents of the map canvas
void setExtent( const QgsRectangle &rect );
//! Remove all layers from the map and legend - reimplements same method from qgisappbase
void removeAllLayers();

/** Open a raster or vector file; ignore other files.
Used to process a commandline argument, FileOpen or Drop event.
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,11 @@ QgsProject::QgsProject( QObject *parent )

QgsProject::~QgsProject()
{
clear();
delete mBadLayerHandler;
delete mRelationManager;
delete mLayerTreeRegistryBridge;
delete mRootGroup;

removeAllMapLayers();
}


Expand Down Expand Up @@ -487,6 +486,7 @@ void QgsProject::clear()
writeEntry( QStringLiteral( "Measurement" ), QStringLiteral( "/DistanceUnits" ), s.value( QStringLiteral( "/qgis/measure/displayunits" ) ).toString() );
writeEntry( QStringLiteral( "Measurement" ), QStringLiteral( "/AreaUnits" ), s.value( QStringLiteral( "/qgis/measure/areaunits" ) ).toString() );

removeAllMapLayers();
setDirty( false );
}

Expand Down

0 comments on commit fe67704

Please sign in to comment.