Skip to content
Permalink
Browse files

[FEATURE][layouts] Add actions in map item properties to set map item

scale to match main canvas scale, and to set main canvas scale to
match map's scale

These mirror the existing settings for setting the extent from
the canvas and pushing the extent TO the canvas.
  • Loading branch information
nyalldawson committed Dec 13, 2018
1 parent cdd23e6 commit 75b7d141eaecf4b655df95a8266bed2bb47087ea
@@ -44,6 +44,8 @@ QgsLayoutMapWidget::QgsLayoutMapWidget( QgsLayoutItemMap *item )
connect( mScaleLineEdit, &QLineEdit::editingFinished, this, &QgsLayoutMapWidget::mScaleLineEdit_editingFinished );
connect( mActionSetToCanvasExtent, &QAction::triggered, this, &QgsLayoutMapWidget::setToMapCanvasExtent );
connect( mActionViewExtentInCanvas, &QAction::triggered, this, &QgsLayoutMapWidget::viewExtentInCanvas );
connect( mActionSetToCanvasScale, &QAction::triggered, this, &QgsLayoutMapWidget::setToMapCanvasScale );
connect( mActionViewScaleInCanvas, &QAction::triggered, this, &QgsLayoutMapWidget::viewScaleInCanvas );
connect( mActionUpdatePreview, &QAction::triggered, this, &QgsLayoutMapWidget::updatePreview );
connect( mFollowVisibilityPresetCheckBox, &QCheckBox::stateChanged, this, &QgsLayoutMapWidget::mFollowVisibilityPresetCheckBox_stateChanged );
connect( mKeepLayerListCheckBox, &QCheckBox::stateChanged, this, &QgsLayoutMapWidget::mKeepLayerListCheckBox_stateChanged );
@@ -558,6 +560,20 @@ void QgsLayoutMapWidget::setToMapCanvasExtent()
mMapItem->layout()->undoStack()->endCommand();
}

void QgsLayoutMapWidget::setToMapCanvasScale()
{
if ( !mMapItem )
{
return;
}

const double newScale = QgisApp::instance()->mapCanvas()->scale();

mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr( "Change Map Scale" ) );
mMapItem->setScale( newScale );
mMapItem->layout()->undoStack()->endCommand();
}

void QgsLayoutMapWidget::viewExtentInCanvas()
{
if ( !mMapItem )
@@ -591,6 +607,17 @@ void QgsLayoutMapWidget::viewExtentInCanvas()
}
}

void QgsLayoutMapWidget::viewScaleInCanvas()
{
if ( !mMapItem )
{
return;
}

const double currentScale = mMapItem->scale();
QgisApp::instance()->mapCanvas()->zoomScale( currentScale );
}

void QgsLayoutMapWidget::mXMinLineEdit_editingFinished()
{
updateComposerExtentFromGui();
@@ -44,7 +44,9 @@ class QgsLayoutMapWidget: public QgsLayoutItemBaseWidget, private Ui::QgsLayoutM
public slots:
void mScaleLineEdit_editingFinished();
void setToMapCanvasExtent();
void setToMapCanvasScale();
void viewExtentInCanvas();
void viewScaleInCanvas();
void updatePreview();
void mFollowVisibilityPresetCheckBox_stateChanged( int state );
void mKeepLayerListCheckBox_stateChanged( int state );
@@ -67,6 +67,9 @@
<addaction name="mActionSetToCanvasExtent"/>
<addaction name="mActionViewExtentInCanvas"/>
<addaction name="separator"/>
<addaction name="mActionSetToCanvasScale"/>
<addaction name="mActionViewScaleInCanvas"/>
<addaction name="separator"/>
<addaction name="mActionMoveContent"/>
</widget>
</item>
@@ -850,6 +853,30 @@
<string>Interactively Edit Map Extent</string>
</property>
</action>
<action name="mActionViewScaleInCanvas">
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mActionScaleHighlightFeature.svg</normaloff>:/images/themes/default/mActionScaleHighlightFeature.svg</iconset>
</property>
<property name="text">
<string>View Scale in Map Canvas</string>
</property>
<property name="toolTip">
<string>Set Main Canvas to Match Current Map Scale</string>
</property>
</action>
<action name="mActionSetToCanvasScale">
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mActionZoomToBookmark.svg</normaloff>:/images/themes/default/mActionZoomToBookmark.svg</iconset>
</property>
<property name="text">
<string>Set to Map Canvas Scale</string>
</property>
<property name="toolTip">
<string>Set Map Scale to Match Main Canvas Scale</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>

2 comments on commit 75b7d14

@lajunek

This comment has been minimized.

Copy link

@lajunek lajunek replied Mar 8, 2019

@nyalldawson for documentation 3.4: is this feature only available in 3.6? when I lock the legend item this have the effect that it doesn't the main canvas scale doesn't match the map canvas scale anymore?

@lajunek

This comment has been minimized.

Copy link

@lajunek lajunek replied Mar 8, 2019

@nyalldawson for documentation 3.4: is this feature only available in 3.6? when I lock the legend item, does this have the effect that the main canvas scale doesn't match the map canvas scale anymore?

Please sign in to comment.
You can’t perform that action at this time.