Skip to content

Commit cb43ec3

Browse files
committed
Close extra map views when changing project
1 parent 2c61e4c commit cb43ec3

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

src/app/qgisapp.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -3150,9 +3150,21 @@ QgsMapCanvas *QgisApp::createNewMapCanvas( const QString &name )
31503150

31513151
addDockWidget( Qt::RightDockWidgetArea, mapCanvasWidget );
31523152
mapCanvas->freeze( false );
3153+
markDirty();
3154+
connect( mapCanvasWidget, &QgsMapCanvasDockWidget::closed, this, &QgisApp::markDirty );
31533155
return mapCanvas;
31543156
}
31553157

3158+
void QgisApp::closeAdditionalMapCanvases()
3159+
{
3160+
freezeCanvases( true ); // closing docks may cause canvases to resize, and we don't want a map refresh occurring
3161+
Q_FOREACH ( QgsMapCanvasDockWidget *w, findChildren< QgsMapCanvasDockWidget * >() )
3162+
{
3163+
w->closeWithoutWarning();
3164+
}
3165+
freezeCanvases( false );
3166+
}
3167+
31563168
void QgisApp::freezeCanvases( bool frozen )
31573169
{
31583170
Q_FOREACH ( QgsMapCanvas *canvas, mapCanvases() )
@@ -9794,6 +9806,8 @@ void QgisApp::closeProject()
97949806
mLegendExpressionFilterButton->setChecked( false );
97959807
mActionFilterLegend->setChecked( false );
97969808

9809+
closeAdditionalMapCanvases();
9810+
97979811
deletePrintComposers();
97989812
removeAnnotationItems();
97999813
// clear out any stuff from project

src/app/qgisapp.h

+6
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,12 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
239239
//! Create a new map canvas with the specified unique \a name
240240
QgsMapCanvas *createNewMapCanvas( const QString &name );
241241

242+
/**
243+
* Closes any additional map canvases. The main map canvas will not
244+
* be affected.
245+
*/
246+
void closeAdditionalMapCanvases();
247+
242248
/**
243249
* Freezes all map canvases (or thaws them if the \a frozen argument is false).
244250
*/

src/app/qgsmapcanvasdockwidget.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,15 @@ QgsMapCanvas *QgsMapCanvasDockWidget::mapCanvas()
4444
return mMapCanvas;
4545
}
4646

47+
void QgsMapCanvasDockWidget::closeWithoutWarning()
48+
{
49+
mShowCloseWarning = false;
50+
close();
51+
}
52+
4753
void QgsMapCanvasDockWidget::closeEvent( QCloseEvent *event )
4854
{
49-
if ( mMapCanvas->layerCount() > 0
55+
if ( mShowCloseWarning && mMapCanvas->layerCount() > 0
5056
&& QMessageBox::question( this, tr( "Close map view" ),
5157
tr( "Are you sure you want to close this map view?" ), QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) == QMessageBox::No )
5258
{

src/app/qgsmapcanvasdockwidget.h

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class APP_EXPORT QgsMapCanvasDockWidget : public QgsDockWidget, private Ui::QgsM
3333
*/
3434
QgsMapCanvas *mapCanvas();
3535

36+
/**
37+
* Closes the dock, bypassing the usual warning prompt.
38+
*/
39+
void closeWithoutWarning();
40+
3641
protected:
3742

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

4651
QgsMapCanvas *mMapCanvas = nullptr;
52+
bool mShowCloseWarning = true;
4753

4854

4955
};

0 commit comments

Comments
 (0)