Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Composer Legend: Add spacing for groups. Fixes #4247 Patch by Anna
Kratochvilova. Thanks!
  • Loading branch information
NathanW2 committed Feb 7, 2012
1 parent c2fee79 commit c5f7f1e
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 11 deletions.
14 changes: 14 additions & 0 deletions src/app/composer/qgscomposerlegendwidget.cpp
Expand Up @@ -81,6 +81,7 @@ void QgsComposerLegendWidget::setGuiElements()
mTitleLineEdit->setText( mLegend->title() );
mSymbolWidthSpinBox->setValue( mLegend->symbolWidth() );
mSymbolHeightSpinBox->setValue( mLegend->symbolHeight() );
mGroupSpaceSpinBox->setValue( mLegend->groupSpace() );
mLayerSpaceSpinBox->setValue( mLegend->layerSpace() );
mSymbolSpaceSpinBox->setValue( mLegend->symbolSpace() );
mIconLabelSpaceSpinBox->setValue( mLegend->iconLabelSpace() );
Expand Down Expand Up @@ -140,6 +141,18 @@ void QgsComposerLegendWidget::on_mSymbolHeightSpinBox_valueChanged( double d )
}
}

void QgsComposerLegendWidget::on_mGroupSpaceSpinBox_valueChanged( double d )
{
if ( mLegend )
{
mLegend->beginCommand( tr( "Legend group space" ), QgsComposerMergeCommand::LegendGroupSpace );
mLegend->setGroupSpace( d );
mLegend->adjustBoxSize();
mLegend->update();
mLegend->endCommand();
}
}

void QgsComposerLegendWidget::on_mLayerSpaceSpinBox_valueChanged( double d )
{
if ( mLegend )
Expand Down Expand Up @@ -641,6 +654,7 @@ void QgsComposerLegendWidget::blockAllSignals( bool b )
mMapComboBox->blockSignals( b );
mSymbolWidthSpinBox->blockSignals( b );
mSymbolHeightSpinBox->blockSignals( b );
mGroupSpaceSpinBox->blockSignals( b );
mLayerSpaceSpinBox->blockSignals( b );
mSymbolSpaceSpinBox->blockSignals( b );
mIconLabelSpaceSpinBox->blockSignals( b );
Expand Down
1 change: 1 addition & 0 deletions src/app/composer/qgscomposerlegendwidget.h
Expand Up @@ -42,6 +42,7 @@ class QgsComposerLegendWidget: public QWidget, private Ui::QgsComposerLegendWidg
void on_mTitleLineEdit_textChanged( const QString& text );
void on_mSymbolWidthSpinBox_valueChanged( double d );
void on_mSymbolHeightSpinBox_valueChanged( double d );
void on_mGroupSpaceSpinBox_valueChanged( double d );
void on_mLayerSpaceSpinBox_valueChanged( double d );
void on_mSymbolSpaceSpinBox_valueChanged( double d );
void on_mIconLabelSpaceSpinBox_valueChanged( double d );
Expand Down
1 change: 1 addition & 0 deletions src/core/composer/qgscomposeritemcommand.h
Expand Up @@ -79,6 +79,7 @@ class CORE_EXPORT QgsComposerMergeCommand: public QgsComposerItemCommand
ComposerLegendText,
LegendSymbolWidth,
LegendSymbolHeight,
LegendGroupSpace,
LegendLayerSpace,
LegendSymbolSpace,
LegendIconSymbolSpace,
Expand Down
5 changes: 4 additions & 1 deletion src/core/composer/qgscomposerlegend.cpp
Expand Up @@ -32,6 +32,7 @@ QgsComposerLegend::QgsComposerLegend( QgsComposition* composition )
: QgsComposerItem( composition )
, mTitle( tr( "Legend" ) )
, mBoxSpace( 2 )
, mGroupSpace( 2 )
, mLayerSpace( 2 )
, mSymbolSpace( 2 )
, mIconLabelSpace( 2 ), mComposerMap( 0 )
Expand Down Expand Up @@ -165,7 +166,7 @@ void QgsComposerLegend::drawGroupItem( QPainter* p, QgsComposerGroupItem* groupI
return;
}

currentYCoord += mLayerSpace;
currentYCoord += mGroupSpace;
currentYCoord += fontAscentMillimeters( mGroupFont );

p->setPen( QColor( 0, 0, 0 ) );
Expand Down Expand Up @@ -642,6 +643,7 @@ bool QgsComposerLegend::writeXML( QDomElement& elem, QDomDocument & doc ) const
composerLegendElem.setAttribute( "layerFont", mLayerFont.toString() );
composerLegendElem.setAttribute( "itemFont", mItemFont.toString() );
composerLegendElem.setAttribute( "boxSpace", QString::number( mBoxSpace ) );
composerLegendElem.setAttribute( "groupSpace", QString::number( mGroupSpace ) );
composerLegendElem.setAttribute( "layerSpace", QString::number( mLayerSpace ) );
composerLegendElem.setAttribute( "symbolSpace", QString::number( mSymbolSpace ) );
composerLegendElem.setAttribute( "iconLabelSpace", QString::number( mIconLabelSpace ) );
Expand Down Expand Up @@ -697,6 +699,7 @@ bool QgsComposerLegend::readXML( const QDomElement& itemElem, const QDomDocument

//spaces
mBoxSpace = itemElem.attribute( "boxSpace", "2.0" ).toDouble();
mGroupSpace = itemElem.attribute( "groupSpace", "3.0" ).toDouble();
mLayerSpace = itemElem.attribute( "layerSpace", "3.0" ).toDouble();
mSymbolSpace = itemElem.attribute( "symbolSpace", "2.0" ).toDouble();
mIconLabelSpace = itemElem.attribute( "iconLabelSpace", "2.0" ).toDouble();
Expand Down
5 changes: 5 additions & 0 deletions src/core/composer/qgscomposerlegend.h
Expand Up @@ -72,6 +72,9 @@ class CORE_EXPORT QgsComposerLegend: public QgsComposerItem
double boxSpace() const {return mBoxSpace;}
void setBoxSpace( double s ) {mBoxSpace = s;}

double groupSpace() const {return mGroupSpace;}
void setGroupSpace( double s ) {mGroupSpace = s;}

double layerSpace() const {return mLayerSpace;}
void setLayerSpace( double s ) {mLayerSpace = s;}

Expand Down Expand Up @@ -122,6 +125,8 @@ class CORE_EXPORT QgsComposerLegend: public QgsComposerItem

/**Space between item box and contents*/
double mBoxSpace;
/**Vertical space between group entries*/
double mGroupSpace;
/**Vertical space between layer entries*/
double mLayerSpace;
/**Vertical space between symbol entries*/
Expand Down
30 changes: 20 additions & 10 deletions src/ui/qgscomposerlegendwidgetbase.ui
Expand Up @@ -44,15 +44,15 @@
<item row="0" column="0">
<widget class="QToolBox" name="toolBox">
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="page">
<property name="geometry">
<rect>
<x>0</x>
<y>-26</y>
<y>0</y>
<width>370</width>
<height>440</height>
<height>471</height>
</rect>
</property>
<attribute name="label">
Expand Down Expand Up @@ -116,7 +116,7 @@
</property>
</widget>
</item>
<item row="9" column="0">
<item row="10" column="0">
<widget class="QDoubleSpinBox" name="mLayerSpaceSpinBox">
<property name="prefix">
<string>Layer space </string>
Expand All @@ -126,7 +126,7 @@
</property>
</widget>
</item>
<item row="10" column="0">
<item row="12" column="0">
<widget class="QDoubleSpinBox" name="mSymbolSpaceSpinBox">
<property name="prefix">
<string>Symbol space </string>
Expand All @@ -136,7 +136,7 @@
</property>
</widget>
</item>
<item row="11" column="0">
<item row="13" column="0">
<widget class="QDoubleSpinBox" name="mIconLabelSpaceSpinBox">
<property name="prefix">
<string>Icon label space </string>
Expand All @@ -146,7 +146,7 @@
</property>
</widget>
</item>
<item row="12" column="0">
<item row="14" column="0">
<widget class="QDoubleSpinBox" name="mBoxSpaceSpinBox">
<property name="prefix">
<string>Box space </string>
Expand All @@ -156,7 +156,7 @@
</property>
</widget>
</item>
<item row="15" column="0">
<item row="17" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand All @@ -169,10 +169,10 @@
</property>
</spacer>
</item>
<item row="14" column="0">
<item row="16" column="0">
<widget class="QComboBox" name="mMapComboBox"/>
</item>
<item row="13" column="0">
<item row="15" column="0">
<widget class="QLabel" name="mMapLabel">
<property name="text">
<string>Map</string>
Expand All @@ -189,6 +189,16 @@
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QDoubleSpinBox" name="mGroupSpaceSpinBox">
<property name="prefix">
<string>Group Space </string>
</property>
<property name="suffix">
<string> mm</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_2">
Expand Down

0 comments on commit c5f7f1e

Please sign in to comment.