Skip to content
Permalink
Browse files

Close extra map views when changing project

  • Loading branch information
nyalldawson committed Mar 13, 2017
1 parent 2c61e4c commit cb43ec3de5af8f1e7e8a3b3b053a76bcd678db59
Showing with 33 additions and 1 deletion.
  1. +14 −0 src/app/qgisapp.cpp
  2. +6 −0 src/app/qgisapp.h
  3. +7 −1 src/app/qgsmapcanvasdockwidget.cpp
  4. +6 −0 src/app/qgsmapcanvasdockwidget.h
@@ -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() )
@@ -9794,6 +9806,8 @@ void QgisApp::closeProject()
mLegendExpressionFilterButton->setChecked( false );
mActionFilterLegend->setChecked( false );

closeAdditionalMapCanvases();

deletePrintComposers();
removeAnnotationItems();
// clear out any stuff from project
@@ -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).
*/
@@ -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 )
{
@@ -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;
@@ -44,6 +49,7 @@ class APP_EXPORT QgsMapCanvasDockWidget : public QgsDockWidget, private Ui::QgsM
private:

QgsMapCanvas *mMapCanvas = nullptr;
bool mShowCloseWarning = true;


};

0 comments on commit cb43ec3

Please sign in to comment.
You can’t perform that action at this time.