Skip to content

Commit

Permalink
Handle deleting map views
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 13, 2017
1 parent 864cae4 commit 2c61e4c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/app/qgsmapcanvasdockwidget.cpp
Expand Up @@ -15,11 +15,13 @@
#include "qgsmapcanvasdockwidget.h"
#include "qgsmapcanvas.h"
#include "qgsprojectionselectiondialog.h"
#include <QMessageBox>

QgsMapCanvasDockWidget::QgsMapCanvasDockWidget( const QString &name, QWidget *parent )
: QgsDockWidget( parent )
{
setupUi( this );
setAttribute( Qt::WA_DeleteOnClose );

mContents->layout()->setContentsMargins( 0, 0, 0, 0 );
mContents->layout()->setMargin( 0 );
Expand All @@ -42,9 +44,24 @@ QgsMapCanvas *QgsMapCanvasDockWidget::mapCanvas()
return mMapCanvas;
}

void QgsMapCanvasDockWidget::closeEvent( QCloseEvent *event )
{
if ( 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 )
{
event->ignore();
}
else
{
event->accept();
}
}

void QgsMapCanvasDockWidget::setMapCrs()
{
QgsProjectionSelectionDialog dlg;
dlg.setShowNoProjection( true );
dlg.setCrs( mMapCanvas->mapSettings().destinationCrs() );

if ( dlg.exec() )
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgsmapcanvasdockwidget.h
Expand Up @@ -33,6 +33,10 @@ class APP_EXPORT QgsMapCanvasDockWidget : public QgsDockWidget, private Ui::QgsM
*/
QgsMapCanvas *mapCanvas();

protected:

virtual void closeEvent( QCloseEvent *event ) override;

private slots:

void setMapCrs();
Expand Down

0 comments on commit 2c61e4c

Please sign in to comment.