Skip to content

Commit 76b9d94

Browse files
committed
Add toolbar buttons for navigating map views
1 parent 95806bb commit 76b9d94

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/app/qgsmapcanvasdockwidget.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#include "qgsmapthemecollection.h"
2525
#include "qgsproject.h"
2626
#include "qgsmapthemes.h"
27+
#include "qgslayertreeview.h"
28+
#include "qgslayertreeviewdefaultactions.h"
29+
#include "qgisapp.h"
2730
#include <QMessageBox>
2831
#include <QMenu>
2932
#include <QToolBar>
@@ -65,14 +68,18 @@ QgsMapCanvasDockWidget::QgsMapCanvasDockWidget( const QString &name, QWidget *pa
6568

6669
QMenu *settingsMenu = new QMenu();
6770
QToolButton *settingsButton = new QToolButton();
68-
btnMapThemes->setAutoRaise( true );
71+
settingsButton->setAutoRaise( true );
72+
settingsButton->setToolTip( tr( "View Settings" ) );
6973
settingsButton->setMenu( settingsMenu );
7074
settingsButton->setPopupMode( QToolButton::InstantPopup );
7175
settingsButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionMapSettings.svg" ) ) );
7276
mToolbar->addWidget( settingsButton );
7377

7478
connect( mActionSetCrs, &QAction::triggered, this, &QgsMapCanvasDockWidget::setMapCrs );
7579
connect( mMapCanvas, &QgsMapCanvas::destinationCrsChanged, this, &QgsMapCanvasDockWidget::mapCrsChanged );
80+
connect( mActionZoomFullExtent, &QAction::triggered, mMapCanvas, &QgsMapCanvas::zoomToFullExtent );
81+
connect( mActionZoomToLayer, &QAction::triggered, mMapCanvas, [ = ] { QgisApp::instance()->layerTreeView()->defaultActions()->zoomToLayer( mMapCanvas ); } );
82+
connect( mActionZoomToSelected, &QAction::triggered, mMapCanvas, [ = ] { mMapCanvas->zoomToSelected(); } );
7683
mapCrsChanged();
7784

7885
QgsMapSettingsAction *settingsAction = new QgsMapSettingsAction( settingsMenu );

src/ui/qgsmapcanvasdockwidgetbase.ui

+30
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
<bool>false</bool>
4343
</property>
4444
<addaction name="mActionSyncView"/>
45+
<addaction name="mActionZoomFullExtent"/>
46+
<addaction name="mActionZoomToSelected"/>
47+
<addaction name="mActionZoomToLayer"/>
4548
</widget>
4649
</item>
4750
<item>
@@ -102,6 +105,33 @@
102105
<string>Rename View</string>
103106
</property>
104107
</action>
108+
<action name="mActionZoomToSelected">
109+
<property name="icon">
110+
<iconset resource="../../images/images.qrc">
111+
<normaloff>:/images/themes/default/mActionZoomToSelected.svg</normaloff>:/images/themes/default/mActionZoomToSelected.svg</iconset>
112+
</property>
113+
<property name="text">
114+
<string>Zoom to &amp;Selection</string>
115+
</property>
116+
</action>
117+
<action name="mActionZoomToLayer">
118+
<property name="icon">
119+
<iconset resource="../../images/images.qrc">
120+
<normaloff>:/images/themes/default/mActionZoomToLayer.svg</normaloff>:/images/themes/default/mActionZoomToLayer.svg</iconset>
121+
</property>
122+
<property name="text">
123+
<string>Zoom to &amp;Layer</string>
124+
</property>
125+
</action>
126+
<action name="mActionZoomFullExtent">
127+
<property name="icon">
128+
<iconset resource="../../images/images.qrc">
129+
<normaloff>:/images/themes/default/mActionZoomFullExtent.svg</normaloff>:/images/themes/default/mActionZoomFullExtent.svg</iconset>
130+
</property>
131+
<property name="text">
132+
<string>Zoom &amp;Full</string>
133+
</property>
134+
</action>
105135
</widget>
106136
<customwidgets>
107137
<customwidget>

0 commit comments

Comments
 (0)