Skip to content
Permalink
Browse files

composer legend spacing corrected, fixes #7994

  • Loading branch information
blazek committed Jun 10, 2013
1 parent f54d979 commit 499db4ecc8d91343f16c73da3575ff478303dde3
@@ -168,6 +168,7 @@ void QgsComposerLegendWidget::setGuiElements()
mEqualColumnWidthCheckBox->setChecked( mLegend->equalColumnWidth() );
mSymbolWidthSpinBox->setValue( mLegend->symbolWidth() );
mSymbolHeightSpinBox->setValue( mLegend->symbolHeight() );
mTitleSpaceBottomSpinBox->setValue( mLegend->style( QgsComposerLegendStyle::Title ).margin( QgsComposerLegendStyle::Bottom ) );
mGroupSpaceSpinBox->setValue( mLegend->style( QgsComposerLegendStyle::Group ).margin( QgsComposerLegendStyle::Top ) );
mLayerSpaceSpinBox->setValue( mLegend->style( QgsComposerLegendStyle::Subgroup ).margin( QgsComposerLegendStyle::Top ) );
// We keep Symbol and SymbolLabel Top in sync for now
@@ -279,6 +280,18 @@ void QgsComposerLegendWidget::on_mSymbolHeightSpinBox_valueChanged( double d )
}
}

void QgsComposerLegendWidget::on_mTitleSpaceBottomSpinBox_valueChanged( double d )
{
if ( mLegend )
{
mLegend->beginCommand( tr( "Legend title space bottom" ), QgsComposerMergeCommand::LegendTitleSpaceBottom );
mLegend->rstyle( QgsComposerLegendStyle::Title ).setMargin( QgsComposerLegendStyle::Bottom, d );
mLegend->adjustBoxSize();
mLegend->update();
mLegend->endCommand();
}
}

void QgsComposerLegendWidget::on_mGroupSpaceSpinBox_valueChanged( double d )
{
if ( mLegend )
@@ -59,6 +59,7 @@ class QgsComposerLegendWidget: public QWidget, private Ui::QgsComposerLegendWidg
void on_mEqualColumnWidthCheckBox_toggled( bool checked );
void on_mSymbolWidthSpinBox_valueChanged( double d );
void on_mSymbolHeightSpinBox_valueChanged( double d );
void on_mTitleSpaceBottomSpinBox_valueChanged( double d );
void on_mGroupSpaceSpinBox_valueChanged( double d );
void on_mLayerSpaceSpinBox_valueChanged( double d );
void on_mSymbolSpaceSpinBox_valueChanged( double d );
@@ -85,6 +85,7 @@ class CORE_EXPORT QgsComposerMergeCommand: public QgsComposerItemCommand
LegendEqualColumnWidth,
LegendSymbolWidth,
LegendSymbolHeight,
LegendTitleSpaceBottom,
LegendGroupSpace,
LegendLayerSpace,
LegendSymbolSpace,
@@ -41,6 +41,7 @@ QgsComposerLegend::QgsComposerLegend( QgsComposition* composition )
, mSplitLayer( false )
, mEqualColumnWidth( false )
{
setStyleMargin( QgsComposerLegendStyle::Title, QgsComposerLegendStyle::Bottom, 2 );
setStyleMargin( QgsComposerLegendStyle::Group, QgsComposerLegendStyle::Top, 2 );
setStyleMargin( QgsComposerLegendStyle::Subgroup, QgsComposerLegendStyle::Top, 2 );
setStyleMargin( QgsComposerLegendStyle::Symbol, QgsComposerLegendStyle::Top, 2 );
@@ -104,13 +105,10 @@ QSizeF QgsComposerLegend::paintAndDetermineSize( QPainter* painter )
}

QSizeF titleSize = drawTitle();
// Using mGroupSpace as space between legend title and first atom in column
//double columnTop = mBoxSpace + titleSize.height() + mGroupSpace;
// TODO: use margin of first used style
double columnTop = mBoxSpace + titleSize.height() + style( QgsComposerLegendStyle::Group ).margin( QgsComposerLegendStyle::Top );
double columnTop = mBoxSpace + titleSize.height() + style( QgsComposerLegendStyle::Title ).margin( QgsComposerLegendStyle::Bottom );

QPointF point( mBoxSpace, columnTop );
// bool firstInColumn = true;
bool firstInColumn = true;
double columnMaxHeight = 0;
qreal columnWidth = 0;
int column = 0;
@@ -130,21 +128,20 @@ QSizeF QgsComposerLegend::paintAndDetermineSize( QPainter* painter )
point.ry() = columnTop;
columnWidth = 0;
column++;
// firstInColumn = true;
firstInColumn = true;
}
if ( !firstInColumn )
{
point.ry() += spaceAboveAtom( atom );
}
// Add space if necessary, unfortunately it depends on first nucleon
//if ( !firstInColumn )
//{
point.ry() += spaceAboveAtom( atom );
//}

QSizeF atomSize = drawAtom( atom, painter, point );
columnWidth = qMax( atomSize.width(), columnWidth );

point.ry() += atom.size.height();
columnMaxHeight = qMax( point.y() - columnTop, columnMaxHeight );

// firstInColumn = false;
firstInColumn = false;
}
point.rx() += columnWidth + mBoxSpace;

@@ -833,7 +830,7 @@ QList<QgsComposerLegend::Atom> QgsComposerLegend::createAtomList( QStandardItem*
// Draw atom and expand its size (using actual nucleons labelXOffset)
QSizeF QgsComposerLegend::drawAtom( Atom atom, QPainter* painter, QPointF point )
{
// bool first = true;
bool first = true;
QSizeF size = QSizeF( atom.size );
foreach ( Nucleon nucleon, atom.nucleons )
{
@@ -845,38 +842,42 @@ QSizeF QgsComposerLegend::drawAtom( Atom atom, QPainter* painter, QPointF point
{
QgsComposerGroupItem* groupItem = dynamic_cast<QgsComposerGroupItem*>( item );
if ( !groupItem ) continue;
// TODO: is it better to avoid marginand align all types of items to the same top like it was before?
//if ( !first ) point.ry() += style(groupItem->style()).margin(QgsComposerLegendStyle::Top);
if ( groupItem->style() != QgsComposerLegendStyle::Hidden )
{
point.ry() += style( groupItem->style() ).margin( QgsComposerLegendStyle::Top );
if ( !first )
{
point.ry() += style( groupItem->style() ).margin( QgsComposerLegendStyle::Top );
}
drawGroupItemTitle( groupItem, painter, point );
}
}
else if ( type == QgsComposerLegendItem::LayerItem )
{
QgsComposerLayerItem* layerItem = dynamic_cast<QgsComposerLayerItem*>( item );
if ( !layerItem ) continue;
//if ( !first ) point.ry() += style(layerItem->style()).margin(QgsComposerLegendStyle::Top);
if ( layerItem->style() != QgsComposerLegendStyle::Hidden )
{
point.ry() += style( layerItem->style() ).margin( QgsComposerLegendStyle::Top );
if ( !first )
{
point.ry() += style( layerItem->style() ).margin( QgsComposerLegendStyle::Top );
}
drawLayerItemTitle( layerItem, painter, point );
}
}
else if ( type == QgsComposerLegendItem::SymbologyV2Item ||
type == QgsComposerLegendItem::RasterSymbolItem )
{
//if ( !first )
point.ry() += style( QgsComposerLegendStyle::Symbol ).margin( QgsComposerLegendStyle::Top );
//}
if ( !first )
{
point.ry() += style( QgsComposerLegendStyle::Symbol ).margin( QgsComposerLegendStyle::Top );
}
double labelXOffset = nucleon.labelXOffset;
Nucleon symbolNucleon = drawSymbolItem( item, painter, point, labelXOffset );
// expand width, it may be wider because of labelXOffset
size.rwidth() = qMax( symbolNucleon.size.width(), size.width() );
}
point.ry() += nucleon.size.height();
// first = false;
first = false;
}
return size;
}
@@ -219,7 +219,9 @@ class CORE_EXPORT QgsComposerLegend : public QgsComposerItem
it is possible that it differs from mSymbolHeight*/
void drawSymbolV2( QPainter* p, QgsSymbolV2* s, double currentYCoord, double& currentXPosition, double& symbolHeight ) const;

/** Draw atom and return its actual size */
/** Draw atom and return its actual size, the atom is drawn with the space above it
* so that first atoms in column are all aligned to the same line regardles their
* style top space */
QSizeF drawAtom( Atom atom, QPainter* painter = 0, QPointF point = QPointF() );

double spaceAboveAtom( Atom atom );
@@ -54,9 +54,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>369</width>
<height>1088</height>
<y>-141</y>
<width>373</width>
<height>1141</height>
</rect>
</property>
<layout class="QVBoxLayout" name="mainLayout">
@@ -558,7 +558,7 @@
<property name="labelAlignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<item row="0" column="0">
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="toolTip">
<string>Space above text using group style.</string>
@@ -571,7 +571,7 @@
</property>
</widget>
</item>
<item row="0" column="1">
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="mGroupSpaceSpinBox">
<property name="prefix">
<string/>
@@ -581,7 +581,7 @@
</property>
</widget>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="label_6">
<property name="toolTip">
<string>Space above text using subgroup style.</string>
@@ -594,7 +594,7 @@
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="mLayerSpaceSpinBox">
<property name="prefix">
<string/>
@@ -604,7 +604,7 @@
</property>
</widget>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QLabel" name="label_7">
<property name="toolTip">
<string>Space above symbol and symbol label.</string>
@@ -617,7 +617,7 @@
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="mSymbolSpaceSpinBox">
<property name="prefix">
<string/>
@@ -627,7 +627,7 @@
</property>
</widget>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label_8">
<property name="toolTip">
<string>Space between symbol icon and symbol label (symbol label left margin).</string>
@@ -640,7 +640,7 @@
</property>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="1">
<widget class="QDoubleSpinBox" name="mIconLabelSpaceSpinBox">
<property name="prefix">
<string/>
@@ -650,7 +650,7 @@
</property>
</widget>
</item>
<item row="4" column="0">
<item row="5" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Box space</string>
@@ -660,7 +660,7 @@
</property>
</widget>
</item>
<item row="4" column="1">
<item row="5" column="1">
<widget class="QDoubleSpinBox" name="mBoxSpaceSpinBox">
<property name="prefix">
<string/>
@@ -670,14 +670,14 @@
</property>
</widget>
</item>
<item row="5" column="0">
<item row="6" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Column space</string>
</property>
</widget>
</item>
<item row="5" column="1">
<item row="6" column="1">
<widget class="QDoubleSpinBox" name="mColumnSpaceSpinBox">
<property name="prefix">
<string/>
@@ -687,6 +687,26 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_10">
<property name="toolTip">
<string>Space below title.</string>
</property>
<property name="text">
<string>Title space</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="mTitleSpaceBottomSpinBox">
<property name="toolTip">
<string>Space below title.</string>
</property>
<property name="suffix">
<string>mm</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

0 comments on commit 499db4e

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