/
qgsmapcanvasdockwidget.cpp
77 lines (66 loc) · 2.52 KB
/
qgsmapcanvasdockwidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/***************************************************************************
qgsmapcanvasdockwidget.cpp
--------------------------
begin : February 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#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 );
static_cast< QVBoxLayout * >( mContents->layout() )->setSpacing( 0 );
setWindowTitle( name );
mMapCanvas = new QgsMapCanvas( this );
mMainWidget->setLayout( new QVBoxLayout() );
mMainWidget->layout()->setContentsMargins( 0, 0, 0, 0 );
mMainWidget->layout()->setMargin( 0 );
mMainWidget->layout()->addWidget( mMapCanvas );
connect( mActionSetCrs, &QAction::triggered, this, &QgsMapCanvasDockWidget::setMapCrs );
}
QgsMapCanvas *QgsMapCanvasDockWidget::mapCanvas()
{
return mMapCanvas;
}
void QgsMapCanvasDockWidget::closeWithoutWarning()
{
mShowCloseWarning = false;
close();
}
void QgsMapCanvasDockWidget::closeEvent( QCloseEvent *event )
{
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 )
{
event->ignore();
}
else
{
event->accept();
}
}
void QgsMapCanvasDockWidget::setMapCrs()
{
QgsProjectionSelectionDialog dlg;
dlg.setShowNoProjection( true );
dlg.setCrs( mMapCanvas->mapSettings().destinationCrs() );
if ( dlg.exec() )
{
mMapCanvas->setDestinationCrs( dlg.crs() );
}
}