Skip to content

Commit

Permalink
Close extra map views when changing project
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 13, 2017
1 parent 2c61e4c commit cb43ec3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -3150,9 +3150,21 @@ QgsMapCanvas *QgisApp::createNewMapCanvas( const QString &name )

addDockWidget( Qt::RightDockWidgetArea, mapCanvasWidget );
mapCanvas->freeze( false );
markDirty();
connect( mapCanvasWidget, &QgsMapCanvasDockWidget::closed, this, &QgisApp::markDirty );
return mapCanvas;
}

void QgisApp::closeAdditionalMapCanvases()
{
freezeCanvases( true ); // closing docks may cause canvases to resize, and we don't want a map refresh occurring
Q_FOREACH ( QgsMapCanvasDockWidget *w, findChildren< QgsMapCanvasDockWidget * >() )
{
w->closeWithoutWarning();
}
freezeCanvases( false );
}

void QgisApp::freezeCanvases( bool frozen )
{
Q_FOREACH ( QgsMapCanvas *canvas, mapCanvases() )
Expand Down Expand Up @@ -9794,6 +9806,8 @@ void QgisApp::closeProject()
mLegendExpressionFilterButton->setChecked( false );
mActionFilterLegend->setChecked( false );

closeAdditionalMapCanvases();

deletePrintComposers();
removeAnnotationItems();
// clear out any stuff from project
Expand Down
6 changes: 6 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -239,6 +239,12 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! Create a new map canvas with the specified unique \a name
QgsMapCanvas *createNewMapCanvas( const QString &name );

/**
* Closes any additional map canvases. The main map canvas will not
* be affected.
*/
void closeAdditionalMapCanvases();

/**
* Freezes all map canvases (or thaws them if the \a frozen argument is false).
*/
Expand Down
8 changes: 7 additions & 1 deletion src/app/qgsmapcanvasdockwidget.cpp
Expand Up @@ -44,9 +44,15 @@ QgsMapCanvas *QgsMapCanvasDockWidget::mapCanvas()
return mMapCanvas;
}

void QgsMapCanvasDockWidget::closeWithoutWarning()
{
mShowCloseWarning = false;
close();
}

void QgsMapCanvasDockWidget::closeEvent( QCloseEvent *event )
{
if ( mMapCanvas->layerCount() > 0
if ( mShowCloseWarning && mMapCanvas->layerCount() > 0
&& QMessageBox::question( this, tr( "Close map view" ),
tr( "Are you sure you want to close this map view?" ), QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) == QMessageBox::No )
{
Expand Down
6 changes: 6 additions & 0 deletions src/app/qgsmapcanvasdockwidget.h
Expand Up @@ -33,6 +33,11 @@ class APP_EXPORT QgsMapCanvasDockWidget : public QgsDockWidget, private Ui::QgsM
*/
QgsMapCanvas *mapCanvas();

/**
* Closes the dock, bypassing the usual warning prompt.
*/
void closeWithoutWarning();

protected:

virtual void closeEvent( QCloseEvent *event ) override;
Expand All @@ -44,6 +49,7 @@ class APP_EXPORT QgsMapCanvasDockWidget : public QgsDockWidget, private Ui::QgsM
private:

QgsMapCanvas *mMapCanvas = nullptr;
bool mShowCloseWarning = true;


};
Expand Down

0 comments on commit cb43ec3

Please sign in to comment.