Skip to content

Commit e029bc7

Browse files
committed
composer legend optional space between columns
1 parent 86c2118 commit e029bc7

6 files changed

+57
-30
lines changed

src/app/composer/qgscomposerlegendwidget.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ void QgsComposerLegendWidget::setGuiElements()
9696
mSymbolSpaceSpinBox->setValue( mLegend->symbolSpace() );
9797
mIconLabelSpaceSpinBox->setValue( mLegend->iconLabelSpace() );
9898
mBoxSpaceSpinBox->setValue( mLegend->boxSpace() );
99+
mColumnSpaceSpinBox->setValue( mLegend->columnSpace() );
99100
if ( mLegend->model() )
100101
{
101102
mCheckBoxAutoUpdate->setChecked( mLegend->model()->autoUpdate() );
@@ -336,7 +337,6 @@ void QgsComposerLegendWidget::on_mItemFontButton_clicked()
336337
}
337338
}
338339

339-
340340
void QgsComposerLegendWidget::on_mBoxSpaceSpinBox_valueChanged( double d )
341341
{
342342
if ( mLegend )
@@ -349,6 +349,18 @@ void QgsComposerLegendWidget::on_mBoxSpaceSpinBox_valueChanged( double d )
349349
}
350350
}
351351

352+
void QgsComposerLegendWidget::on_mColumnSpaceSpinBox_valueChanged( double d )
353+
{
354+
if ( mLegend )
355+
{
356+
mLegend->beginCommand( tr( "Legend box space" ), QgsComposerMergeCommand::LegendColumnSpace );
357+
mLegend->setColumnSpace( d );
358+
mLegend->adjustBoxSize();
359+
mLegend->update();
360+
mLegend->endCommand();
361+
}
362+
}
363+
352364
void QgsComposerLegendWidget::on_mMoveDownToolButton_clicked()
353365
{
354366
if ( !mLegend )
@@ -767,6 +779,7 @@ void QgsComposerLegendWidget::blockAllSignals( bool b )
767779
mSymbolSpaceSpinBox->blockSignals( b );
768780
mIconLabelSpaceSpinBox->blockSignals( b );
769781
mBoxSpaceSpinBox->blockSignals( b );
782+
mColumnSpaceSpinBox->blockSignals( b );
770783
}
771784

772785
void QgsComposerLegendWidget::refreshMapComboBox()

src/app/composer/qgscomposerlegendwidget.h

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class QgsComposerLegendWidget: public QWidget, private Ui::QgsComposerLegendWidg
5555
void on_mLayerFontButton_clicked();
5656
void on_mItemFontButton_clicked();
5757
void on_mBoxSpaceSpinBox_valueChanged( double d );
58+
void on_mColumnSpaceSpinBox_valueChanged( double d );
5859
void on_mCheckBoxAutoUpdate_stateChanged( int state );
5960
void on_mMapComboBox_currentIndexChanged( int index );
6061

src/core/composer/qgscomposeritemcommand.h

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class CORE_EXPORT QgsComposerMergeCommand: public QgsComposerItemCommand
9090
LegendSymbolSpace,
9191
LegendIconSymbolSpace,
9292
LegendBoxSpace,
93+
LegendColumnSpace,
9394
//composer picture
9495
ComposerPictureRotation,
9596
// composer scalebar

src/core/composer/qgscomposerlegend.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ QgsComposerLegend::QgsComposerLegend( QgsComposition* composition )
3434
: QgsComposerItem( composition )
3535
, mTitle( tr( "Legend" ) )
3636
, mBoxSpace( 2 )
37+
, mColumnSpace( 2 )
3738
, mGroupSpace( 2 )
3839
, mLayerSpace( 2 )
3940
, mSymbolSpace( 2 )
@@ -117,14 +118,13 @@ QSizeF QgsComposerLegend::paintAndDetermineSize( QPainter* painter )
117118
if ( atom.column > column )
118119
{
119120
// Switch to next column
120-
// Using mBoxSpace for inter column space
121121
if ( mEqualColumnWidth )
122122
{
123-
point.rx() += mBoxSpace + maxColumnWidth;
123+
point.rx() += mColumnSpace + maxColumnWidth;
124124
}
125125
else
126126
{
127-
point.rx() += mBoxSpace + columnWidth;
127+
point.rx() += mColumnSpace + columnWidth;
128128
}
129129
point.ry() = columnTop;
130130
columnWidth = 0;
@@ -290,7 +290,6 @@ QSizeF QgsComposerLegend::drawLayerItemTitle( QgsComposerLayerItem* layerItem, Q
290290

291291
void QgsComposerLegend::adjustBoxSize()
292292
{
293-
mColumns.clear();
294293
QSizeF size = paintAndDetermineSize( 0 );
295294
QgsDebugMsg( QString( "width = %1 height = %2" ).arg( size.width() ).arg( size.height() ) );
296295
if ( size.isValid() )
@@ -642,7 +641,6 @@ QStringList QgsComposerLegend::layerIdList() const
642641
void QgsComposerLegend::synchronizeWithModel()
643642
{
644643
QgsDebugMsg( "Entered" );
645-
mColumns.clear();
646644
adjustBoxSize();
647645
update();
648646
}
@@ -656,23 +654,20 @@ void QgsComposerLegend::setTitleFont( const QFont& f )
656654

657655
void QgsComposerLegend::setGroupFont( const QFont& f )
658656
{
659-
mColumns.clear();
660657
mGroupFont = f;
661658
adjustBoxSize();
662659
update();
663660
}
664661

665662
void QgsComposerLegend::setLayerFont( const QFont& f )
666663
{
667-
mColumns.clear();
668664
mLayerFont = f;
669665
adjustBoxSize();
670666
update();
671667
}
672668

673669
void QgsComposerLegend::setItemFont( const QFont& f )
674670
{
675-
mColumns.clear();
676671
mItemFont = f;
677672
adjustBoxSize();
678673
update();
@@ -724,6 +719,7 @@ bool QgsComposerLegend::writeXML( QDomElement& elem, QDomDocument & doc ) const
724719
composerLegendElem.setAttribute( "layerFont", mLayerFont.toString() );
725720
composerLegendElem.setAttribute( "itemFont", mItemFont.toString() );
726721
composerLegendElem.setAttribute( "boxSpace", QString::number( mBoxSpace ) );
722+
composerLegendElem.setAttribute( "columnSpace", QString::number( mColumnSpace ) );
727723
composerLegendElem.setAttribute( "groupSpace", QString::number( mGroupSpace ) );
728724
composerLegendElem.setAttribute( "layerSpace", QString::number( mLayerSpace ) );
729725
composerLegendElem.setAttribute( "symbolSpace", QString::number( mSymbolSpace ) );
@@ -785,6 +781,7 @@ bool QgsComposerLegend::readXML( const QDomElement& itemElem, const QDomDocument
785781

786782
//spaces
787783
mBoxSpace = itemElem.attribute( "boxSpace", "2.0" ).toDouble();
784+
mColumnSpace = itemElem.attribute( "columnSpace", "2.0" ).toDouble();
788785
mGroupSpace = itemElem.attribute( "groupSpace", "3.0" ).toDouble();
789786
mLayerSpace = itemElem.attribute( "layerSpace", "3.0" ).toDouble();
790787
mSymbolSpace = itemElem.attribute( "symbolSpace", "2.0" ).toDouble();
@@ -822,7 +819,6 @@ bool QgsComposerLegend::readXML( const QDomElement& itemElem, const QDomDocument
822819

823820
void QgsComposerLegend::setComposerMap( const QgsComposerMap* map )
824821
{
825-
mColumns.clear();
826822
mComposerMap = map;
827823
if ( map )
828824
{
@@ -832,7 +828,10 @@ void QgsComposerLegend::setComposerMap( const QgsComposerMap* map )
832828

833829
void QgsComposerLegend::invalidateCurrentMap()
834830
{
835-
disconnect( mComposerMap, SIGNAL( destroyed( QObject* ) ), this, SLOT( invalidateCurrentMap() ) );
831+
if ( mComposerMap )
832+
{
833+
disconnect( mComposerMap, SIGNAL( destroyed( QObject* ) ), this, SLOT( invalidateCurrentMap() ) );
834+
}
836835
mComposerMap = 0;
837836
}
838837

src/core/composer/qgscomposerlegend.h

+14-11
Original file line numberDiff line numberDiff line change
@@ -73,31 +73,34 @@ class CORE_EXPORT QgsComposerLegend : public QgsComposerItem
7373
void setItemFont( const QFont& f );
7474

7575
double boxSpace() const {return mBoxSpace;}
76-
void setBoxSpace( double s ) {mBoxSpace = s; mColumns.clear();}
76+
void setBoxSpace( double s ) {mBoxSpace = s;}
77+
78+
double columnSpace() const {return mColumnSpace;}
79+
void setColumnSpace( double s ) { mColumnSpace = s;}
7780

7881
double groupSpace() const {return mGroupSpace;}
79-
void setGroupSpace( double s ) {mGroupSpace = s;mColumns.clear();}
82+
void setGroupSpace( double s ) {mGroupSpace = s;}
8083

8184
double layerSpace() const {return mLayerSpace;}
82-
void setLayerSpace( double s ) {mLayerSpace = s;mColumns.clear();}
85+
void setLayerSpace( double s ) {mLayerSpace = s;}
8386

8487
double symbolSpace() const {return mSymbolSpace;}
85-
void setSymbolSpace( double s ) {mSymbolSpace = s;mColumns.clear();}
88+
void setSymbolSpace( double s ) {mSymbolSpace = s;}
8689

8790
double iconLabelSpace() const {return mIconLabelSpace;}
88-
void setIconLabelSpace( double s ) {mIconLabelSpace = s;mColumns.clear();}
91+
void setIconLabelSpace( double s ) {mIconLabelSpace = s;}
8992

9093
double symbolWidth() const {return mSymbolWidth;}
91-
void setSymbolWidth( double w ) {mSymbolWidth = w;mColumns.clear();}
94+
void setSymbolWidth( double w ) {mSymbolWidth = w;}
9295

9396
double symbolHeight() const {return mSymbolHeight;}
94-
void setSymbolHeight( double h ) {mSymbolHeight = h;mColumns.clear();}
97+
void setSymbolHeight( double h ) {mSymbolHeight = h;}
9598

96-
void setWrapChar( const QString& t ) {mWrapChar = t;mColumns.clear();}
99+
void setWrapChar( const QString& t ) {mWrapChar = t;}
97100
QString wrapChar() const {return mWrapChar;}
98101

99102
int columnCount() const { return mColumnCount; }
100-
void setColumnCount( int c ) { mColumnCount = c;mColumns.clear();}
103+
void setColumnCount( int c ) { mColumnCount = c;}
101104

102105
int splitLayer() const { return mSplitLayer; }
103106
void setSplitLayer( bool s ) { mSplitLayer = s;}
@@ -141,6 +144,8 @@ class CORE_EXPORT QgsComposerLegend : public QgsComposerItem
141144

142145
/**Space between item box and contents*/
143146
double mBoxSpace;
147+
/**Space between columns*/
148+
double mColumnSpace;
144149
/**Vertical space between group entries*/
145150
double mGroupSpace;
146151
/**Vertical space between layer entries*/
@@ -159,8 +164,6 @@ class CORE_EXPORT QgsComposerLegend : public QgsComposerItem
159164

160165
/** Number of legend columns */
161166
int mColumnCount;
162-
/** Cached division of items to columns */
163-
QMap<QStandardItem *, int> mColumns;
164167

165168
QgsLegendModel mLegendModel;
166169

src/ui/qgscomposerlegendwidgetbase.ui

+18-8
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@
5050
<property name="geometry">
5151
<rect>
5252
<x>0</x>
53-
<y>0</y>
53+
<y>-115</y>
5454
<width>370</width>
55-
<height>533</height>
55+
<height>562</height>
5656
</rect>
5757
</property>
5858
<attribute name="label">
@@ -153,7 +153,7 @@
153153
</property>
154154
</widget>
155155
</item>
156-
<item row="24" column="1">
156+
<item row="25" column="1">
157157
<spacer name="verticalSpacer">
158158
<property name="orientation">
159159
<enum>Qt::Vertical</enum>
@@ -166,10 +166,10 @@
166166
</property>
167167
</spacer>
168168
</item>
169-
<item row="20" column="1">
169+
<item row="21" column="1">
170170
<widget class="QComboBox" name="mMapComboBox"/>
171171
</item>
172-
<item row="19" column="1">
172+
<item row="20" column="1">
173173
<widget class="QLabel" name="mMapLabel">
174174
<property name="text">
175175
<string>Map</string>
@@ -186,14 +186,14 @@
186186
</property>
187187
</widget>
188188
</item>
189-
<item row="22" column="1">
189+
<item row="23" column="1">
190190
<widget class="QLabel" name="label">
191191
<property name="text">
192192
<string>Wrap text on</string>
193193
</property>
194194
</widget>
195195
</item>
196-
<item row="23" column="1">
196+
<item row="24" column="1">
197197
<widget class="QLineEdit" name="mWrapCharLineEdit">
198198
<property name="frame">
199199
<bool>true</bool>
@@ -247,6 +247,16 @@
247247
</property>
248248
</widget>
249249
</item>
250+
<item row="19" column="1">
251+
<widget class="QDoubleSpinBox" name="mColumnSpaceSpinBox">
252+
<property name="prefix">
253+
<string>Column space </string>
254+
</property>
255+
<property name="suffix">
256+
<string> mm</string>
257+
</property>
258+
</widget>
259+
</item>
250260
</layout>
251261
</widget>
252262
<widget class="QWidget" name="page_2">
@@ -255,7 +265,7 @@
255265
<x>0</x>
256266
<y>0</y>
257267
<width>427</width>
258-
<height>401</height>
268+
<height>139</height>
259269
</rect>
260270
</property>
261271
<attribute name="label">

0 commit comments

Comments
 (0)