@@ -44,6 +44,8 @@ QgsLayoutMapWidget::QgsLayoutMapWidget( QgsLayoutItemMap *item )
44
44
connect ( mScaleLineEdit , &QLineEdit::editingFinished, this , &QgsLayoutMapWidget::mScaleLineEdit_editingFinished );
45
45
connect ( mActionSetToCanvasExtent , &QAction::triggered, this , &QgsLayoutMapWidget::setToMapCanvasExtent );
46
46
connect ( mActionViewExtentInCanvas , &QAction::triggered, this , &QgsLayoutMapWidget::viewExtentInCanvas );
47
+ connect ( mActionSetToCanvasScale , &QAction::triggered, this , &QgsLayoutMapWidget::setToMapCanvasScale );
48
+ connect ( mActionViewScaleInCanvas , &QAction::triggered, this , &QgsLayoutMapWidget::viewScaleInCanvas );
47
49
connect ( mActionUpdatePreview , &QAction::triggered, this , &QgsLayoutMapWidget::updatePreview );
48
50
connect ( mFollowVisibilityPresetCheckBox , &QCheckBox::stateChanged, this , &QgsLayoutMapWidget::mFollowVisibilityPresetCheckBox_stateChanged );
49
51
connect ( mKeepLayerListCheckBox , &QCheckBox::stateChanged, this , &QgsLayoutMapWidget::mKeepLayerListCheckBox_stateChanged );
@@ -558,6 +560,20 @@ void QgsLayoutMapWidget::setToMapCanvasExtent()
558
560
mMapItem ->layout ()->undoStack ()->endCommand ();
559
561
}
560
562
563
+ void QgsLayoutMapWidget::setToMapCanvasScale ()
564
+ {
565
+ if ( !mMapItem )
566
+ {
567
+ return ;
568
+ }
569
+
570
+ const double newScale = QgisApp::instance ()->mapCanvas ()->scale ();
571
+
572
+ mMapItem ->layout ()->undoStack ()->beginCommand ( mMapItem , tr ( " Change Map Scale" ) );
573
+ mMapItem ->setScale ( newScale );
574
+ mMapItem ->layout ()->undoStack ()->endCommand ();
575
+ }
576
+
561
577
void QgsLayoutMapWidget::viewExtentInCanvas ()
562
578
{
563
579
if ( !mMapItem )
@@ -591,6 +607,17 @@ void QgsLayoutMapWidget::viewExtentInCanvas()
591
607
}
592
608
}
593
609
610
+ void QgsLayoutMapWidget::viewScaleInCanvas ()
611
+ {
612
+ if ( !mMapItem )
613
+ {
614
+ return ;
615
+ }
616
+
617
+ const double currentScale = mMapItem ->scale ();
618
+ QgisApp::instance ()->mapCanvas ()->zoomScale ( currentScale );
619
+ }
620
+
594
621
void QgsLayoutMapWidget::mXMinLineEdit_editingFinished ()
595
622
{
596
623
updateComposerExtentFromGui ();
0 commit comments