Skip to content

Commit 36339c2

Browse files
committedApr 24, 2020
[FEATURE][layouts] Allow control over the horizontal spacing before
legend group/subgroup/symbols Gives flexibility to allow "nesting" legend groups/subgroups/symbols and much greater control over legend item placement Sponsored by SLYR
1 parent 715f4c7 commit 36339c2

File tree

7 files changed

+277
-91
lines changed

7 files changed

+277
-91
lines changed
 

‎src/core/qgslegendrenderer.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,22 @@ QgsLegendRenderer::LegendComponent QgsLegendRenderer::drawSymbolItemInternal( Qg
653653
Q_NOWARN_DEPRECATED_POP
654654

655655
ctx.top = top;
656+
656657
ctx.columnLeft = columnContext.left;
657658
ctx.columnRight = columnContext.right;
659+
660+
switch ( mSettings.symbolAlignment() )
661+
{
662+
case Qt::AlignLeft:
663+
default:
664+
ctx.columnLeft += mSettings.style( QgsLegendStyle::Symbol ).margin( QgsLegendStyle::Left );
665+
break;
666+
667+
case Qt::AlignRight:
668+
ctx.columnRight -= mSettings.style( QgsLegendStyle::Symbol ).margin( QgsLegendStyle::Left );
669+
break;
670+
}
671+
658672
ctx.maxSiblingSymbolWidth = maxSiblingSymbolWidth;
659673

660674
if ( const QgsSymbolLegendNode *symbolNode = dynamic_cast< const QgsSymbolLegendNode * >( symbolItem ) )
@@ -675,6 +689,7 @@ QgsLegendRenderer::LegendComponent QgsLegendRenderer::drawSymbolItemInternal( Qg
675689
// ideally we could (should?) expose all these margins as settings, and then adapt the below to respect the current symbol/text alignment
676690
// and consider the correct margin sides...
677691
double width = std::max( static_cast< double >( im.symbolSize.width() ), maxSiblingSymbolWidth )
692+
+ mSettings.style( QgsLegendStyle::Symbol ).margin( QgsLegendStyle::Left )
678693
+ mSettings.style( QgsLegendStyle::Symbol ).margin( QgsLegendStyle::Right )
679694
+ mSettings.style( QgsLegendStyle::SymbolLabel ).margin( QgsLegendStyle::Left )
680695
+ im.labelSize.width();
@@ -719,23 +734,26 @@ QSizeF QgsLegendRenderer::drawLayerTitleInternal( QgsLayerTreeLayer *nodeLayer,
719734
const QStringList lines = mSettings.evaluateItemText( titleString,
720735
context ? context->expressionContext() : tempContext );
721736
int i = 0;
737+
738+
const double sideMargin = mSettings.style( nodeLegendStyle( nodeLayer ) ).margin( QgsLegendStyle::Left );
722739
for ( QStringList::ConstIterator layerItemPart = lines.constBegin(); layerItemPart != lines.constEnd(); ++layerItemPart )
723740
{
724741
y += mSettings.fontAscentMillimeters( layerFont );
725742
if ( QPainter *destPainter = context && context->painter() ? context->painter() : painter )
726743
{
727-
double x = columnContext.left;
744+
double x = columnContext.left + sideMargin;
728745
if ( mSettings.style( nodeLegendStyle( nodeLayer ) ).alignment() != Qt::AlignLeft )
729746
{
730747
const double labelWidth = mSettings.textWidthMillimeters( layerFont, *layerItemPart );
731748
if ( mSettings.style( nodeLegendStyle( nodeLayer ) ).alignment() == Qt::AlignRight )
732-
x = columnContext.right - labelWidth;
749+
x = columnContext.right - labelWidth - sideMargin;
733750
else if ( mSettings.style( nodeLegendStyle( nodeLayer ) ).alignment() == Qt::AlignHCenter )
734751
x = columnContext.left + ( columnContext.right - columnContext.left - labelWidth ) / 2;
735752
}
736753
mSettings.drawText( destPainter, x, y, *layerItemPart, layerFont );
737754
}
738-
qreal width = mSettings.textWidthMillimeters( layerFont, *layerItemPart );
755+
qreal width = mSettings.textWidthMillimeters( layerFont, *layerItemPart ) + sideMargin *
756+
( mSettings.style( nodeLegendStyle( nodeLayer ) ).alignment() == Qt::AlignHCenter ? 2 : 1 );
739757
size.rwidth() = std::max( width, size.width() );
740758
if ( layerItemPart != ( lines.end() - 1 ) )
741759
{
@@ -773,6 +791,8 @@ QSizeF QgsLegendRenderer::drawGroupTitleInternal( QgsLayerTreeGroup *nodeGroup,
773791

774792
QgsExpressionContext tempContext;
775793

794+
const double sideMargin = mSettings.style( nodeLegendStyle( nodeGroup ) ).margin( QgsLegendStyle::Left );
795+
776796
const QStringList lines = mSettings.evaluateItemText( mLegendModel->data( idx, Qt::DisplayRole ).toString(),
777797
context ? context->expressionContext() : tempContext );
778798
for ( QStringList::ConstIterator groupPart = lines.constBegin(); groupPart != lines.constEnd(); ++groupPart )
@@ -781,18 +801,18 @@ QSizeF QgsLegendRenderer::drawGroupTitleInternal( QgsLayerTreeGroup *nodeGroup,
781801

782802
if ( QPainter *destPainter = context && context->painter() ? context->painter() : painter )
783803
{
784-
double x = columnContext.left;
804+
double x = columnContext.left + sideMargin;
785805
if ( mSettings.style( nodeLegendStyle( nodeGroup ) ).alignment() != Qt::AlignLeft )
786806
{
787807
const double labelWidth = mSettings.textWidthMillimeters( groupFont, *groupPart );
788808
if ( mSettings.style( nodeLegendStyle( nodeGroup ) ).alignment() == Qt::AlignRight )
789-
x = columnContext.right - labelWidth;
809+
x = columnContext.right - labelWidth - sideMargin;
790810
else if ( mSettings.style( nodeLegendStyle( nodeGroup ) ).alignment() == Qt::AlignHCenter )
791811
x = columnContext.left + ( columnContext.right - columnContext.left - labelWidth ) / 2;
792812
}
793813
mSettings.drawText( destPainter, x, y, *groupPart, groupFont );
794814
}
795-
qreal width = mSettings.textWidthMillimeters( groupFont, *groupPart );
815+
qreal width = mSettings.textWidthMillimeters( groupFont, *groupPart ) + sideMargin * ( mSettings.style( nodeLegendStyle( nodeGroup ) ).alignment() == Qt::AlignHCenter ? 2 : 1 );
796816
size.rwidth() = std::max( width, size.width() );
797817
if ( groupPart != ( lines.end() - 1 ) )
798818
{

‎src/gui/layout/qgslayoutlegendwidget.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,12 @@ QgsLayoutLegendWidget::QgsLayoutLegendWidget( QgsLayoutItemLegend *legend, QgsMa
9191
connect( mTitleSpaceBottomSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutLegendWidget::mTitleSpaceBottomSpinBox_valueChanged );
9292
connect( mGroupSpaceSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutLegendWidget::mGroupSpaceSpinBox_valueChanged );
9393
connect( mSpaceBelowGroupHeadingSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutLegendWidget::spaceBelowGroupHeadingChanged );
94+
connect( mGroupSideSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutLegendWidget::spaceGroupSideChanged );
9495
connect( mLayerSpaceSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutLegendWidget::mLayerSpaceSpinBox_valueChanged );
9596
connect( mSpaceBelowSubgroupHeadingSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutLegendWidget::spaceBelowSubGroupHeadingChanged );
97+
connect( mSubgroupSideSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutLegendWidget::spaceSubGroupSideChanged );
9698
connect( mSymbolSpaceSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutLegendWidget::mSymbolSpaceSpinBox_valueChanged );
99+
connect( mSymbolSideSpaceSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutLegendWidget::spaceSymbolSideChanged );
97100
connect( mIconLabelSpaceSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutLegendWidget::mIconLabelSpaceSpinBox_valueChanged );
98101
connect( mFontColorButton, &QgsColorButton::colorChanged, this, &QgsLayoutLegendWidget::mFontColorButton_colorChanged );
99102
connect( mBoxSpaceSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutLegendWidget::mBoxSpaceSpinBox_valueChanged );
@@ -135,7 +138,10 @@ QgsLayoutLegendWidget::QgsLayoutLegendWidget( QgsLayoutItemLegend *legend, QgsMa
135138
mArrangementCombo->customizeAlignmentDisplay( Qt::AlignRight, tr( "Symbols on Right" ), QgsApplication::getThemeIcon( QStringLiteral( "/mIconArrangeSymbolsRight.svg" ) ) );
136139

137140
mSpaceBelowGroupHeadingSpinBox->setClearValue( 0 );
141+
mGroupSideSpinBox->setClearValue( 0 );
138142
mSpaceBelowSubgroupHeadingSpinBox->setClearValue( 0 );
143+
mSubgroupSideSpinBox->setClearValue( 0 );
144+
mSymbolSideSpaceSpinBox->setClearValue( 0 );
139145

140146
// setup icons
141147
mAddToolButton->setIcon( QIcon( QgsApplication::iconPath( "symbologyAdd.svg" ) ) );
@@ -228,12 +234,15 @@ void QgsLayoutLegendWidget::setGuiElements()
228234
mWmsLegendHeightSpinBox->setValue( mLegend->wmsLegendHeight() );
229235
mTitleSpaceBottomSpinBox->setValue( mLegend->style( QgsLegendStyle::Title ).margin( QgsLegendStyle::Bottom ) );
230236
mGroupSpaceSpinBox->setValue( mLegend->style( QgsLegendStyle::Group ).margin( QgsLegendStyle::Top ) );
237+
mGroupSideSpinBox->setValue( mLegend->style( QgsLegendStyle::Group ).margin( QgsLegendStyle::Left ) );
231238
mSpaceBelowGroupHeadingSpinBox->setValue( mLegend->style( QgsLegendStyle::Group ).margin( QgsLegendStyle::Bottom ) );
232239
mLayerSpaceSpinBox->setValue( mLegend->style( QgsLegendStyle::Subgroup ).margin( QgsLegendStyle::Top ) );
233240
mSpaceBelowSubgroupHeadingSpinBox->setValue( mLegend->style( QgsLegendStyle::Subgroup ).margin( QgsLegendStyle::Bottom ) );
241+
mSubgroupSideSpinBox->setValue( mLegend->style( QgsLegendStyle::Subgroup ).margin( QgsLegendStyle::Left ) );
234242
// We keep Symbol and SymbolLabel Top in sync for now
235243
mSymbolSpaceSpinBox->setValue( mLegend->style( QgsLegendStyle::Symbol ).margin( QgsLegendStyle::Top ) );
236244
mIconLabelSpaceSpinBox->setValue( mLegend->style( QgsLegendStyle::SymbolLabel ).margin( QgsLegendStyle::Left ) );
245+
mSymbolSideSpaceSpinBox->setValue( mLegend->style( QgsLegendStyle::Symbol ).margin( QgsLegendStyle::Left ) );
237246
mBoxSpaceSpinBox->setValue( mLegend->boxSpace() );
238247
mColumnSpaceSpinBox->setValue( mLegend->columnSpace() );
239248
mLineSpacingSpinBox->setValue( mLegend->lineSpacing() );
@@ -466,6 +475,42 @@ void QgsLayoutLegendWidget::spaceBelowGroupHeadingChanged( double space )
466475
}
467476
}
468477

478+
void QgsLayoutLegendWidget::spaceGroupSideChanged( double space )
479+
{
480+
if ( mLegend )
481+
{
482+
mLegend->beginCommand( tr( "Change Side of Group Space" ), QgsLayoutItem::UndoLegendGroupSpace );
483+
mLegend->rstyle( QgsLegendStyle::Group ).setMargin( QgsLegendStyle::Left, space );
484+
mLegend->adjustBoxSize();
485+
mLegend->update();
486+
mLegend->endCommand();
487+
}
488+
}
489+
490+
void QgsLayoutLegendWidget::spaceSubGroupSideChanged( double space )
491+
{
492+
if ( mLegend )
493+
{
494+
mLegend->beginCommand( tr( "Change Side of Subgroup Space" ), QgsLayoutItem::UndoLegendLayerSpace );
495+
mLegend->rstyle( QgsLegendStyle::Subgroup ).setMargin( QgsLegendStyle::Left, space );
496+
mLegend->adjustBoxSize();
497+
mLegend->update();
498+
mLegend->endCommand();
499+
}
500+
}
501+
502+
void QgsLayoutLegendWidget::spaceSymbolSideChanged( double space )
503+
{
504+
if ( mLegend )
505+
{
506+
mLegend->beginCommand( tr( "Change Side of Symbol Space" ), QgsLayoutItem::UndoLegendSymbolSpace );
507+
mLegend->rstyle( QgsLegendStyle::Symbol ).setMargin( QgsLegendStyle::Left, space );
508+
mLegend->adjustBoxSize();
509+
mLegend->update();
510+
mLegend->endCommand();
511+
}
512+
}
513+
469514
void QgsLayoutLegendWidget::mLayerSpaceSpinBox_valueChanged( double d )
470515
{
471516
if ( mLegend )
@@ -1181,9 +1226,12 @@ void QgsLayoutLegendWidget::blockAllSignals( bool b )
11811226
mSymbolHeightSpinBox->blockSignals( b );
11821227
mGroupSpaceSpinBox->blockSignals( b );
11831228
mSpaceBelowGroupHeadingSpinBox->blockSignals( b );
1229+
mGroupSideSpinBox->blockSignals( b );
11841230
mSpaceBelowSubgroupHeadingSpinBox->blockSignals( b );
1231+
mSubgroupSideSpinBox->blockSignals( b );
11851232
mLayerSpaceSpinBox->blockSignals( b );
11861233
mSymbolSpaceSpinBox->blockSignals( b );
1234+
mSymbolSideSpaceSpinBox->blockSignals( b );
11871235
mIconLabelSpaceSpinBox->blockSignals( b );
11881236
mBoxSpaceSpinBox->blockSignals( b );
11891237
mColumnSpaceSpinBox->blockSignals( b );

‎src/gui/layout/qgslayoutlegendwidget.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ class GUI_EXPORT QgsLayoutLegendWidget: public QgsLayoutItemBaseWidget, private
136136
void spaceBelowSubGroupHeadingChanged( double space );
137137
void spaceBelowGroupHeadingChanged( double space );
138138

139+
void spaceGroupSideChanged( double space );
140+
void spaceSubGroupSideChanged( double space );
141+
142+
void spaceSymbolSideChanged( double space );
143+
139144
private:
140145
QgsLayoutLegendWidget() = delete;
141146
void blockAllSignals( bool b );

‎src/ui/layout/qgslayoutlegendwidgetbase.ui

Lines changed: 165 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@
6363
<property name="geometry">
6464
<rect>
6565
<x>0</x>
66-
<y>-1086</y>
67-
<width>359</width>
68-
<height>2056</height>
66+
<y>-1283</y>
67+
<width>367</width>
68+
<height>2239</height>
6969
</rect>
7070
</property>
7171
<layout class="QVBoxLayout" name="mainLayout">
@@ -957,8 +957,8 @@
957957
<bool>true</bool>
958958
</property>
959959
<layout class="QGridLayout" name="gridLayout_5">
960-
<item row="3" column="1">
961-
<widget class="QgsDoubleSpinBox" name="mGroupSpaceSpinBox">
960+
<item row="11" column="1">
961+
<widget class="QgsDoubleSpinBox" name="mSubgroupSideSpinBox">
962962
<property name="prefix">
963963
<string/>
964964
</property>
@@ -967,32 +967,65 @@
967967
</property>
968968
</widget>
969969
</item>
970-
<item row="14" column="0">
971-
<widget class="QLabel" name="label_121">
972-
<property name="text">
973-
<string>Line space</string>
970+
<item row="17" column="1">
971+
<widget class="QgsDoubleSpinBox" name="mBoxSpaceSpinBox">
972+
<property name="prefix">
973+
<string/>
974+
</property>
975+
<property name="suffix">
976+
<string> mm</string>
974977
</property>
975978
</widget>
976979
</item>
977-
<item row="0" column="0" colspan="2">
978-
<widget class="QLabel" name="label_31s">
980+
<item row="12" column="0" colspan="2">
981+
<widget class="QLabel" name="label_34">
979982
<property name="text">
980-
<string>&lt;b&gt;Legend Title&lt;/b&gt;</string>
983+
<string>&lt;b&gt;Legend Items&lt;/b&gt;</string>
981984
</property>
982985
</widget>
983986
</item>
984-
<item row="7" column="0">
985-
<widget class="QLabel" name="label_19">
987+
<item row="10" column="1">
988+
<widget class="QgsDoubleSpinBox" name="mSpaceBelowSubgroupHeadingSpinBox">
989+
<property name="prefix">
990+
<string/>
991+
</property>
992+
<property name="suffix">
993+
<string> mm</string>
994+
</property>
995+
</widget>
996+
</item>
997+
<item row="1" column="1">
998+
<widget class="QgsDoubleSpinBox" name="mTitleSpaceBottomSpinBox">
986999
<property name="toolTip">
987-
<string>Space above text using group style.</string>
1000+
<string>Space below title.</string>
1001+
</property>
1002+
<property name="suffix">
1003+
<string> mm</string>
1004+
</property>
1005+
</widget>
1006+
</item>
1007+
<item row="18" column="1">
1008+
<widget class="QgsDoubleSpinBox" name="mColumnSpaceSpinBox">
1009+
<property name="prefix">
1010+
<string/>
1011+
</property>
1012+
<property name="suffix">
1013+
<string> mm</string>
1014+
</property>
1015+
</widget>
1016+
</item>
1017+
<item row="8" column="0">
1018+
<widget class="QLabel" name="label_6">
1019+
<property name="toolTip">
1020+
<string>Space above text using subgroup style.</string>
9881021
</property>
9891022
<property name="text">
990-
<string>Below subgroup heading</string>
1023+
<string>Above subgroup</string>
9911024
</property>
9921025
</widget>
9931026
</item>
994-
<item row="14" column="1">
995-
<widget class="QgsDoubleSpinBox" name="mLineSpacingSpinBox">
1027+
<item row="15" column="1">
1028+
<widget class="QgsDoubleSpinBox" name="mIconLabelSpaceSpinBox">
9961029
<property name="prefix">
9971030
<string/>
9981031
</property>
@@ -1001,39 +1034,45 @@
10011034
</property>
10021035
</widget>
10031036
</item>
1004-
<item row="4" column="0">
1037+
<item row="5" column="0">
10051038
<widget class="QLabel" name="label_18">
10061039
<property name="toolTip">
10071040
<string>Space above text using group style.</string>
10081041
</property>
10091042
<property name="text">
1010-
<string>Below group heading</string>
1043+
<string>Below heading</string>
10111044
</property>
10121045
</widget>
10131046
</item>
1014-
<item row="5" column="0" colspan="2">
1015-
<widget class="QLabel" name="label_32">
1047+
<item row="6" column="0">
1048+
<widget class="QLabel" name="label_30">
1049+
<property name="toolTip">
1050+
<string>Space above text using group style.</string>
1051+
</property>
10161052
<property name="text">
1017-
<string>&lt;b&gt;Subgroups&lt;/b&gt;</string>
1053+
<string>Side of heading</string>
10181054
</property>
10191055
</widget>
10201056
</item>
1021-
<item row="11" column="0" colspan="2">
1022-
<widget class="QLabel" name="label_33">
1057+
<item row="3" column="0">
1058+
<widget class="QLabel" name="label_5">
1059+
<property name="toolTip">
1060+
<string>Space above text using group style.</string>
1061+
</property>
10231062
<property name="text">
1024-
<string>&lt;b&gt;General&lt;/b&gt;</string>
1063+
<string>Above group</string>
10251064
</property>
10261065
</widget>
10271066
</item>
1028-
<item row="13" column="0">
1029-
<widget class="QLabel" name="label_12">
1067+
<item row="9" column="0" colspan="2">
1068+
<widget class="QLabel" name="label_36">
10301069
<property name="text">
1031-
<string>Column space</string>
1070+
<string>&lt;b&gt;Subgroup Headings&lt;/b&gt;</string>
10321071
</property>
10331072
</widget>
10341073
</item>
1035-
<item row="9" column="1">
1036-
<widget class="QgsDoubleSpinBox" name="mSymbolSpaceSpinBox">
1074+
<item row="19" column="1">
1075+
<widget class="QgsDoubleSpinBox" name="mLineSpacingSpinBox">
10371076
<property name="prefix">
10381077
<string/>
10391078
</property>
@@ -1042,18 +1081,39 @@
10421081
</property>
10431082
</widget>
10441083
</item>
1045-
<item row="6" column="0">
1046-
<widget class="QLabel" name="label_6">
1084+
<item row="15" column="0">
1085+
<widget class="QLabel" name="label_8">
10471086
<property name="toolTip">
1048-
<string>Space above text using subgroup style.</string>
1087+
<string>Space between symbol icon and symbol label (symbol label left margin).</string>
10491088
</property>
10501089
<property name="text">
1051-
<string>Above subgroup</string>
1090+
<string>Symbol label space</string>
10521091
</property>
10531092
</widget>
10541093
</item>
1055-
<item row="7" column="1">
1056-
<widget class="QgsDoubleSpinBox" name="mSpaceBelowSubgroupHeadingSpinBox">
1094+
<item row="16" column="0" colspan="2">
1095+
<widget class="QLabel" name="label_33">
1096+
<property name="text">
1097+
<string>&lt;b&gt;General&lt;/b&gt;</string>
1098+
</property>
1099+
</widget>
1100+
</item>
1101+
<item row="4" column="0" colspan="2">
1102+
<widget class="QLabel" name="label_35">
1103+
<property name="text">
1104+
<string>&lt;b&gt;Group Headings&lt;/b&gt;</string>
1105+
</property>
1106+
</widget>
1107+
</item>
1108+
<item row="7" column="0" colspan="2">
1109+
<widget class="QLabel" name="label_32">
1110+
<property name="text">
1111+
<string>&lt;b&gt;Subgroups&lt;/b&gt;</string>
1112+
</property>
1113+
</widget>
1114+
</item>
1115+
<item row="3" column="1">
1116+
<widget class="QgsDoubleSpinBox" name="mGroupSpaceSpinBox">
10571117
<property name="prefix">
10581118
<string/>
10591119
</property>
@@ -1062,8 +1122,8 @@
10621122
</property>
10631123
</widget>
10641124
</item>
1065-
<item row="10" column="1">
1066-
<widget class="QgsDoubleSpinBox" name="mIconLabelSpaceSpinBox">
1125+
<item row="14" column="1">
1126+
<widget class="QgsDoubleSpinBox" name="mSymbolSpaceSpinBox">
10671127
<property name="prefix">
10681128
<string/>
10691129
</property>
@@ -1072,10 +1132,13 @@
10721132
</property>
10731133
</widget>
10741134
</item>
1075-
<item row="12" column="0">
1076-
<widget class="QLabel" name="label_9">
1135+
<item row="11" column="0">
1136+
<widget class="QLabel" name="label_37">
1137+
<property name="toolTip">
1138+
<string>Space above text using group style.</string>
1139+
</property>
10771140
<property name="text">
1078-
<string>Box space</string>
1141+
<string>Side of heading</string>
10791142
</property>
10801143
</widget>
10811144
</item>
@@ -1086,18 +1149,18 @@
10861149
</property>
10871150
</widget>
10881151
</item>
1089-
<item row="1" column="0">
1090-
<widget class="QLabel" name="label_10">
1091-
<property name="toolTip">
1092-
<string>Space below title.</string>
1152+
<item row="5" column="1">
1153+
<widget class="QgsDoubleSpinBox" name="mSpaceBelowGroupHeadingSpinBox">
1154+
<property name="prefix">
1155+
<string/>
10931156
</property>
1094-
<property name="text">
1095-
<string>Space below</string>
1157+
<property name="suffix">
1158+
<string> mm</string>
10961159
</property>
10971160
</widget>
10981161
</item>
1099-
<item row="13" column="1">
1100-
<widget class="QgsDoubleSpinBox" name="mColumnSpaceSpinBox">
1162+
<item row="8" column="1">
1163+
<widget class="QgsDoubleSpinBox" name="mLayerSpaceSpinBox">
11011164
<property name="prefix">
11021165
<string/>
11031166
</property>
@@ -1106,7 +1169,7 @@
11061169
</property>
11071170
</widget>
11081171
</item>
1109-
<item row="9" column="0">
1172+
<item row="14" column="0">
11101173
<widget class="QLabel" name="label_7">
11111174
<property name="toolTip">
11121175
<string>Space above symbol and symbol label.</string>
@@ -1116,58 +1179,76 @@
11161179
</property>
11171180
</widget>
11181181
</item>
1119-
<item row="10" column="0">
1120-
<widget class="QLabel" name="label_8">
1121-
<property name="toolTip">
1122-
<string>Space between symbol icon and symbol label (symbol label left margin).</string>
1182+
<item row="6" column="1">
1183+
<widget class="QgsDoubleSpinBox" name="mGroupSideSpinBox">
1184+
<property name="prefix">
1185+
<string/>
11231186
</property>
1187+
<property name="suffix">
1188+
<string> mm</string>
1189+
</property>
1190+
</widget>
1191+
</item>
1192+
<item row="19" column="0">
1193+
<widget class="QLabel" name="label_121">
11241194
<property name="text">
1125-
<string>Symbol label space</string>
1195+
<string>Line space</string>
11261196
</property>
11271197
</widget>
11281198
</item>
1129-
<item row="3" column="0">
1130-
<widget class="QLabel" name="label_5">
1199+
<item row="0" column="0" colspan="2">
1200+
<widget class="QLabel" name="label_31s">
1201+
<property name="text">
1202+
<string>&lt;b&gt;Legend Title&lt;/b&gt;</string>
1203+
</property>
1204+
</widget>
1205+
</item>
1206+
<item row="10" column="0">
1207+
<widget class="QLabel" name="label_19">
11311208
<property name="toolTip">
11321209
<string>Space above text using group style.</string>
11331210
</property>
11341211
<property name="text">
1135-
<string>Above group</string>
1212+
<string>Below heading</string>
11361213
</property>
11371214
</widget>
11381215
</item>
1139-
<item row="4" column="1">
1140-
<widget class="QgsDoubleSpinBox" name="mSpaceBelowGroupHeadingSpinBox">
1141-
<property name="prefix">
1142-
<string/>
1216+
<item row="17" column="0">
1217+
<widget class="QLabel" name="label_9">
1218+
<property name="text">
1219+
<string>Box space</string>
11431220
</property>
1144-
<property name="suffix">
1145-
<string> mm</string>
1221+
</widget>
1222+
</item>
1223+
<item row="18" column="0">
1224+
<widget class="QLabel" name="label_12">
1225+
<property name="text">
1226+
<string>Column space</string>
11461227
</property>
11471228
</widget>
11481229
</item>
1149-
<item row="12" column="1">
1150-
<widget class="QgsDoubleSpinBox" name="mBoxSpaceSpinBox">
1151-
<property name="prefix">
1152-
<string/>
1230+
<item row="1" column="0">
1231+
<widget class="QLabel" name="label_10">
1232+
<property name="toolTip">
1233+
<string>Space below title.</string>
11531234
</property>
1154-
<property name="suffix">
1155-
<string> mm</string>
1235+
<property name="text">
1236+
<string>Space below</string>
11561237
</property>
11571238
</widget>
11581239
</item>
1159-
<item row="1" column="1">
1160-
<widget class="QgsDoubleSpinBox" name="mTitleSpaceBottomSpinBox">
1240+
<item row="13" column="0">
1241+
<widget class="QLabel" name="label_38">
11611242
<property name="toolTip">
1162-
<string>Space below title.</string>
1243+
<string>Space above symbol and symbol label.</string>
11631244
</property>
1164-
<property name="suffix">
1165-
<string> mm</string>
1245+
<property name="text">
1246+
<string>Space before side of symbol</string>
11661247
</property>
11671248
</widget>
11681249
</item>
1169-
<item row="6" column="1">
1170-
<widget class="QgsDoubleSpinBox" name="mLayerSpaceSpinBox">
1250+
<item row="13" column="1">
1251+
<widget class="QgsDoubleSpinBox" name="mSymbolSideSpaceSpinBox">
11711252
<property name="prefix">
11721253
<string/>
11731254
</property>
@@ -1176,13 +1257,6 @@
11761257
</property>
11771258
</widget>
11781259
</item>
1179-
<item row="8" column="0" colspan="2">
1180-
<widget class="QLabel" name="label_34">
1181-
<property name="text">
1182-
<string>&lt;b&gt;Legend Items&lt;/b&gt;</string>
1183-
</property>
1184-
</widget>
1185-
</item>
11861260
</layout>
11871261
</widget>
11881262
</item>
@@ -1304,16 +1378,22 @@
13041378
<tabstop>mTitleSpaceBottomSpinBox</tabstop>
13051379
<tabstop>mGroupSpaceSpinBox</tabstop>
13061380
<tabstop>mSpaceBelowGroupHeadingSpinBox</tabstop>
1381+
<tabstop>mGroupSideSpinBox</tabstop>
13071382
<tabstop>mLayerSpaceSpinBox</tabstop>
13081383
<tabstop>mSpaceBelowSubgroupHeadingSpinBox</tabstop>
1384+
<tabstop>mSubgroupSideSpinBox</tabstop>
1385+
<tabstop>mSymbolSideSpaceSpinBox</tabstop>
13091386
<tabstop>mSymbolSpaceSpinBox</tabstop>
13101387
<tabstop>mIconLabelSpaceSpinBox</tabstop>
13111388
<tabstop>mBoxSpaceSpinBox</tabstop>
13121389
<tabstop>mColumnSpaceSpinBox</tabstop>
13131390
<tabstop>mLineSpacingSpinBox</tabstop>
1391+
<tabstop>mLayerExpressionButton</tabstop>
13141392
</tabstops>
13151393
<resources>
13161394
<include location="../../../images/images.qrc"/>
1395+
<include location="../../../images/images.qrc"/>
1396+
<include location="../../../images/images.qrc"/>
13171397
</resources>
13181398
<connections/>
13191399
</ui>

‎tests/src/core/testqgslegendrenderer.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class TestQgsLegendRenderer : public QObject
132132

133133
void testBasic();
134134
void testMultiline();
135+
void testSpacing();
135136
void testEffects();
136137
void testBigMarker();
137138

@@ -339,6 +340,38 @@ void TestQgsLegendRenderer::testMultiline()
339340
QVERIFY( _verifyImage( testName, mReport ) );
340341
}
341342

343+
void TestQgsLegendRenderer::testSpacing()
344+
{
345+
QgsMarkerSymbol *sym = new QgsMarkerSymbol();
346+
sym->setColor( Qt::red );
347+
sym->setSize( sym->size() * 6 );
348+
QgsCategorizedSymbolRenderer *catRenderer = dynamic_cast<QgsCategorizedSymbolRenderer *>( mVL3->renderer() );
349+
QVERIFY( catRenderer );
350+
catRenderer->updateCategorySymbol( 0, sym );
351+
352+
QgsLayerTreeModel legendModel( mRoot );
353+
QgsLegendSettings settings;
354+
355+
settings.rstyle( QgsLegendStyle::Group ).setMargin( QgsLegendStyle::Left, 7 );
356+
settings.rstyle( QgsLegendStyle::Subgroup ).setMargin( QgsLegendStyle::Left, 11 );
357+
settings.rstyle( QgsLegendStyle::Symbol ).setMargin( QgsLegendStyle::Left, 5 );
358+
_setStandardTestFont( settings, QStringLiteral( "Bold" ) );
359+
360+
settings.rstyle( QgsLegendStyle::Group ).setAlignment( Qt::AlignLeft );
361+
settings.rstyle( QgsLegendStyle::Subgroup ).setAlignment( Qt::AlignLeft );
362+
settings.rstyle( QgsLegendStyle::SymbolLabel ).setAlignment( Qt::AlignLeft );
363+
364+
_renderLegend( QStringLiteral( "legend_left_align_side_space" ), &legendModel, settings );
365+
QVERIFY( _verifyImage( QStringLiteral( "legend_left_align_side_space" ), mReport ) );
366+
367+
settings.rstyle( QgsLegendStyle::Group ).setAlignment( Qt::AlignRight );
368+
settings.rstyle( QgsLegendStyle::Subgroup ).setAlignment( Qt::AlignRight );
369+
settings.setSymbolAlignment( Qt::AlignRight );
370+
371+
_renderLegend( QStringLiteral( "legend_right_align_side_space" ), &legendModel, settings );
372+
QVERIFY( _verifyImage( QStringLiteral( "legend_right_align_side_space" ), mReport ) );
373+
}
374+
342375
void TestQgsLegendRenderer::testEffects()
343376
{
344377
QString testName = QStringLiteral( "legend_effects" );

0 commit comments

Comments
 (0)
Please sign in to comment.