Skip to content
Permalink
Browse files

[FEATURE][layouts] Allow control over stacking position of map overvi…

…ew extents

Allows overview extents to be drawn below map labels (the new default),
but also adds choices for drawing them below all map layers, or
above/below a specific map layer.

This allows users to control exactly where in the map item's layer stack
the overview will be placed, e.g. allowing them to draw a overview
extent below some feature layers such as roads whilst drawing it
above other background layers.
  • Loading branch information
nyalldawson committed Dec 28, 2018
1 parent a441e2b commit 38450f0befdf3cb4fb93bbd7b6bc7b32cb759204
Showing with 131 additions and 35 deletions.
  1. +72 −12 src/app/layout/qgslayoutmapwidget.cpp
  2. +2 −0 src/app/layout/qgslayoutmapwidget.h
  3. +57 −23 src/ui/layout/qgslayoutmapwidgetbase.ui
@@ -54,6 +54,8 @@ QgsLayoutMapWidget::QgsLayoutMapWidget( QgsLayoutItemMap *item )
connect( mOverviewBlendModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapWidget::mOverviewBlendModeComboBox_currentIndexChanged );
connect( mOverviewInvertCheckbox, &QCheckBox::toggled, this, &QgsLayoutMapWidget::mOverviewInvertCheckbox_toggled );
connect( mOverviewCenterCheckbox, &QCheckBox::toggled, this, &QgsLayoutMapWidget::mOverviewCenterCheckbox_toggled );
connect( mOverviewPositionComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapWidget::overviewStackingChanged );
connect( mOverviewStackingLayerComboBox, &QgsMapLayerComboBox::layerChanged, this, &QgsLayoutMapWidget::overviewStackingLayerChanged );
connect( mXMinLineEdit, &QLineEdit::editingFinished, this, &QgsLayoutMapWidget::mXMinLineEdit_editingFinished );
connect( mXMaxLineEdit, &QLineEdit::editingFinished, this, &QgsLayoutMapWidget::mXMaxLineEdit_editingFinished );
connect( mYMinLineEdit, &QLineEdit::editingFinished, this, &QgsLayoutMapWidget::mYMinLineEdit_editingFinished );
@@ -97,6 +99,12 @@ QgsLayoutMapWidget::QgsLayoutMapWidget( QgsLayoutItemMap *item )
mYMinLineEdit->setValidator( new QDoubleValidator( mYMinLineEdit ) );
mYMaxLineEdit->setValidator( new QDoubleValidator( mYMaxLineEdit ) );

mOverviewPositionComboBox->addItem( tr( "Below Map" ), QgsLayoutItemMapItem::StackBelowMap );
mOverviewPositionComboBox->addItem( tr( "Below Map Layer" ), QgsLayoutItemMapItem::StackBelowMapLayer );
mOverviewPositionComboBox->addItem( tr( "Above Map Layer" ), QgsLayoutItemMapItem::StackAboveMapLayer );
mOverviewPositionComboBox->addItem( tr( "Below Map Labels" ), QgsLayoutItemMapItem::StackBelowMapLabels );
mOverviewPositionComboBox->addItem( tr( "Above Map Labels" ), QgsLayoutItemMapItem::StackAboveMapLabels );

blockAllSignals( true );

mCrsSelector->setOptionVisible( QgsProjectionSelectionWidget::CrsNotSet, true );
@@ -356,7 +364,7 @@ void QgsLayoutMapWidget::overviewSymbolChanged()
mMapItem->beginCommand( tr( "Change Overview Style" ), QgsLayoutItem::UndoOverviewStyle );
overview->setFrameSymbol( mOverviewFrameStyleButton->clonedSymbol<QgsFillSymbol>() );
mMapItem->endCommand();
mMapItem->update();
mMapItem->invalidateCache();
}

void QgsLayoutMapWidget::showLabelSettings()
@@ -1201,7 +1209,7 @@ void QgsLayoutMapWidget::mAddOverviewPushButton_clicked()
mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr( "Add Map Overview" ) );
mMapItem->overviews()->addOverview( overview );
mMapItem->layout()->undoStack()->endCommand();
mMapItem->update();
mMapItem->invalidateCache();

addOverviewListItem( overview->id(), overview->name() );

@@ -1220,7 +1228,7 @@ void QgsLayoutMapWidget::mRemoveOverviewPushButton_clicked()
mMapItem->endCommand();
QListWidgetItem *delItem = mOverviewListWidget->takeItem( mOverviewListWidget->row( item ) );
delete delItem;
mMapItem->update();
mMapItem->invalidateCache();
}

void QgsLayoutMapWidget::mOverviewUpButton_clicked()
@@ -1242,7 +1250,7 @@ void QgsLayoutMapWidget::mOverviewUpButton_clicked()
mMapItem->beginCommand( tr( "Move Overview Up" ) );
mMapItem->overviews()->moveOverviewUp( item->data( Qt::UserRole ).toString() );
mMapItem->endCommand();
mMapItem->update();
mMapItem->invalidateCache();
}

void QgsLayoutMapWidget::mOverviewDownButton_clicked()
@@ -1264,7 +1272,7 @@ void QgsLayoutMapWidget::mOverviewDownButton_clicked()
mMapItem->beginCommand( tr( "Move Overview Down" ) );
mMapItem->overviews()->moveOverviewDown( item->data( Qt::UserRole ).toString() );
mMapItem->endCommand();
mMapItem->update();
mMapItem->invalidateCache();
}

QgsLayoutItemMapOverview *QgsLayoutMapWidget::currentOverview()
@@ -1329,16 +1337,21 @@ void QgsLayoutMapWidget::setOverviewItemsEnabled( bool enabled )
mOverviewBlendModeComboBox->setEnabled( enabled );
mOverviewInvertCheckbox->setEnabled( enabled );
mOverviewCenterCheckbox->setEnabled( enabled );
mOverviewPositionComboBox->setEnabled( enabled );

QgsLayoutItemMapItem::StackingPosition currentStackingPos = static_cast< QgsLayoutItemMapItem::StackingPosition >( mOverviewPositionComboBox->currentData().toInt() );
mOverviewStackingLayerComboBox->setEnabled( enabled && ( currentStackingPos == QgsLayoutItemMapItem::StackAboveMapLayer || currentStackingPos == QgsLayoutItemMapItem::StackBelowMapLayer ) );
}

void QgsLayoutMapWidget::blockOverviewItemsSignals( bool block )
void QgsLayoutMapWidget::blockOverviewItemsSignals( const bool block )
{
//grid
mOverviewFrameMapComboBox->blockSignals( block );
mOverviewFrameStyleButton->blockSignals( block );
mOverviewBlendModeComboBox->blockSignals( block );
mOverviewInvertCheckbox->blockSignals( block );
mOverviewCenterCheckbox->blockSignals( block );
mOverviewPositionComboBox->blockSignals( block );
mOverviewStackingLayerComboBox->blockSignals( block );
}

void QgsLayoutMapWidget::setOverviewItems( QgsLayoutItemMapOverview *overview )
@@ -1363,6 +1376,11 @@ void QgsLayoutMapWidget::setOverviewItems( QgsLayoutItemMapOverview *overview )
//center overview
mOverviewCenterCheckbox->setChecked( overview->centered() );

mOverviewPositionComboBox->setCurrentIndex( mOverviewPositionComboBox->findData( overview->stackingPosition() ) );
mOverviewStackingLayerComboBox->setLayer( overview->stackingLayer() );
mOverviewStackingLayerComboBox->setEnabled( mOverviewPositionComboBox->isEnabled() && ( overview->stackingPosition() == QgsLayoutItemMapItem::StackAboveMapLayer
|| overview->stackingPosition() == QgsLayoutItemMapItem::StackBelowMapLayer ) );

mOverviewFrameStyleButton->setSymbol( overview->frameSymbol()->clone() );

blockOverviewItemsSignals( false );
@@ -1451,7 +1469,7 @@ void QgsLayoutMapWidget::mOverviewCheckBox_toggled( bool state )
{
overview->setEnabled( false );
}
mMapItem->update();
mMapItem->invalidateCache();
mMapItem->layout()->undoStack()->endCommand();
}

@@ -1469,7 +1487,7 @@ void QgsLayoutMapWidget::overviewMapChanged( QgsLayoutItem *item )

mMapItem->beginCommand( tr( "Change Overview Map" ) );
overview->setLinkedMap( map );
mMapItem->update();
mMapItem->invalidateCache();
mMapItem->endCommand();
}

@@ -1484,7 +1502,7 @@ void QgsLayoutMapWidget::mOverviewBlendModeComboBox_currentIndexChanged( int ind

mMapItem->beginCommand( tr( "Change Overview Blend Mode" ) );
overview->setBlendMode( mOverviewBlendModeComboBox->blendMode() );
mMapItem->update();
mMapItem->invalidateCache();
mMapItem->endCommand();
}

@@ -1498,7 +1516,7 @@ void QgsLayoutMapWidget::mOverviewInvertCheckbox_toggled( bool state )

mMapItem->beginCommand( tr( "Toggle Overview Inverted" ) );
overview->setInverted( state );
mMapItem->update();
mMapItem->invalidateCache();
mMapItem->endCommand();
}

@@ -1512,7 +1530,49 @@ void QgsLayoutMapWidget::mOverviewCenterCheckbox_toggled( bool state )

mMapItem->beginCommand( tr( "Toggle Overview Centered" ) );
overview->setCentered( state );
mMapItem->update();
mMapItem->invalidateCache();
mMapItem->endCommand();
}

void QgsLayoutMapWidget::overviewStackingChanged( int )
{
QgsLayoutItemMapOverview *overview = currentOverview();
if ( !overview )
{
return;
}

mMapItem->beginCommand( tr( "Change Overview Position" ) );
overview->setStackingPosition( static_cast< QgsLayoutItemMapItem::StackingPosition >( mOverviewPositionComboBox->currentData().toInt() ) );
mMapItem->invalidateCache();
mMapItem->endCommand();

switch ( overview->stackingPosition() )
{
case QgsLayoutItemMapItem::StackAboveMapLabels:
case QgsLayoutItemMapItem::StackBelowMap:
case QgsLayoutItemMapItem::StackBelowMapLabels:
mOverviewStackingLayerComboBox->setEnabled( false );
break;

case QgsLayoutItemMapItem::StackAboveMapLayer:
case QgsLayoutItemMapItem::StackBelowMapLayer:
mOverviewStackingLayerComboBox->setEnabled( true );
break;
}
}

void QgsLayoutMapWidget::overviewStackingLayerChanged( QgsMapLayer *layer )
{
QgsLayoutItemMapOverview *overview = currentOverview();
if ( !overview )
{
return;
}

mMapItem->beginCommand( tr( "Change Overview Position" ) );
overview->setStackingLayer( layer );
mMapItem->invalidateCache();
mMapItem->endCommand();
}

@@ -57,6 +57,8 @@ class QgsLayoutMapWidget: public QgsLayoutItemBaseWidget, private Ui::QgsLayoutM
void mOverviewBlendModeComboBox_currentIndexChanged( int index );
void mOverviewInvertCheckbox_toggled( bool state );
void mOverviewCenterCheckbox_toggled( bool state );
void overviewStackingChanged( int value );
void overviewStackingLayerChanged( QgsMapLayer *layer );

void mXMinLineEdit_editingFinished();
void mXMaxLineEdit_editingFinished();
@@ -87,9 +87,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>368</width>
<height>1253</height>
<y>-257</y>
<width>373</width>
<height>960</height>
</rect>
</property>
<property name="sizePolicy">
@@ -720,21 +720,37 @@
<property name="collapsed" stdset="0">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_8" columnstretch="0,1">
<item row="0" column="0">
<widget class="QLabel" name="mOverviewFrameMapLabel">
<layout class="QGridLayout" name="gridLayout_8" columnstretch="0,0">
<item row="5" column="1">
<widget class="QComboBox" name="mOverviewPositionComboBox"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="mOverviewPositionLabel">
<property name="text">
<string>Map frame</string>
<string>Position</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QgsLayoutItemComboBox" name="mOverviewFrameMapComboBox"/>
<item row="1" column="1">
<widget class="QgsSymbolButton" name="mOverviewFrameStyleButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Change…</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mOverviewFrameStyleLabel">
<item row="2" column="1">
<widget class="QgsBlendModeComboBox" name="mOverviewBlendModeComboBox"/>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="mOverviewInvertCheckbox">
<property name="text">
<string>Frame style</string>
<string>Invert overview</string>
</property>
</widget>
</item>
@@ -745,13 +761,17 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QgsBlendModeComboBox" name="mOverviewBlendModeComboBox"/>
<item row="1" column="0">
<widget class="QLabel" name="mOverviewFrameStyleLabel">
<property name="text">
<string>Frame style</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="mOverviewInvertCheckbox">
<item row="0" column="0">
<widget class="QLabel" name="mOverviewFrameMapLabel">
<property name="text">
<string>Invert overview</string>
<string>Map frame</string>
</property>
</widget>
</item>
@@ -762,16 +782,23 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsSymbolButton" name="mOverviewFrameStyleButton">
<item row="0" column="1">
<widget class="QgsLayoutItemComboBox" name="mOverviewFrameMapComboBox"/>
</item>
<item row="6" column="1">
<widget class="QgsMapLayerComboBox" name="mOverviewStackingLayerComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Change…</string>
<string>Stacking layer</string>
</property>
</widget>
</item>
@@ -921,6 +948,11 @@
<extends>QComboBox</extends>
<header>qgslayoutitemcombobox.h</header>
</customwidget>
<customwidget>
<class>QgsMapLayerComboBox</class>
<extends>QComboBox</extends>
<header location="global">qgsmaplayercombobox.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>scrollArea</tabstop>
@@ -960,6 +992,8 @@
<tabstop>mGridDownButton</tabstop>
<tabstop>mGridListWidget</tabstop>
<tabstop>mDrawGridCheckBox</tabstop>
<tabstop>mDrawGridCheckBox</tabstop>
<tabstop>mGridPropertiesButton</tabstop>
<tabstop>mGridPropertiesButton</tabstop>
<tabstop>mOverviewsGroupBox</tabstop>
<tabstop>mAddOverviewPushButton</tabstop>
@@ -973,8 +1007,8 @@
<tabstop>mOverviewBlendModeComboBox</tabstop>
<tabstop>mOverviewInvertCheckbox</tabstop>
<tabstop>mOverviewCenterCheckbox</tabstop>
<tabstop>mDrawGridCheckBox</tabstop>
<tabstop>mGridPropertiesButton</tabstop>
<tabstop>mOverviewPositionComboBox</tabstop>
<tabstop>mOverviewStackingLayerComboBox</tabstop>
</tabstops>
<resources>
<include location="../../../images/images.qrc"/>

0 comments on commit 38450f0

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