Skip to content

Commit 86c2118

Browse files
committed
composer multicolumn legend: division to columns heuristic, optional splitting layers into multiple columns, optional equal column width
1 parent b177abf commit 86c2118

6 files changed

+626
-446
lines changed

src/app/composer/qgscomposerlegendwidget.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend* legend ): m
6262
mWrapCharLineEdit->setText( legend->wrapChar() );
6363

6464
setGuiElements();
65-
connect( mItemTreeView, SIGNAL( itemChanged() ), this, SLOT( setGuiElements() ) );
6665

6766
connect( mItemTreeView->selectionModel(), SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ),
6867
this, SLOT( selectedChanged( const QModelIndex &, const QModelIndex & ) ) );
@@ -88,6 +87,8 @@ void QgsComposerLegendWidget::setGuiElements()
8887
blockAllSignals( true );
8988
mTitleLineEdit->setText( mLegend->title() );
9089
mColumnCountSpinBox->setValue( mLegend->columnCount() );
90+
mSplitLayerCheckBox->setChecked( mLegend->splitLayer() );
91+
mEqualColumnWidthCheckBox->setChecked( mLegend->equalColumnWidth() );
9192
mSymbolWidthSpinBox->setValue( mLegend->symbolWidth() );
9293
mSymbolHeightSpinBox->setValue( mLegend->symbolHeight() );
9394
mGroupSpaceSpinBox->setValue( mLegend->groupSpace() );
@@ -147,6 +148,32 @@ void QgsComposerLegendWidget::on_mColumnCountSpinBox_valueChanged( int c )
147148
mLegend->update();
148149
mLegend->endCommand();
149150
}
151+
mSplitLayerCheckBox->setEnabled( c > 1 );
152+
mEqualColumnWidthCheckBox->setEnabled( c > 1 );
153+
}
154+
155+
void QgsComposerLegendWidget::on_mSplitLayerCheckBox_toggled( bool checked )
156+
{
157+
if ( mLegend )
158+
{
159+
mLegend->beginCommand( tr( "Legend split layers" ), QgsComposerMergeCommand::LegendSplitLayer );
160+
mLegend->setSplitLayer( checked );
161+
mLegend->adjustBoxSize();
162+
mLegend->update();
163+
mLegend->endCommand();
164+
}
165+
}
166+
167+
void QgsComposerLegendWidget::on_mEqualColumnWidthCheckBox_toggled( bool checked )
168+
{
169+
if ( mLegend )
170+
{
171+
mLegend->beginCommand( tr( "Legend equal column width" ), QgsComposerMergeCommand::LegendEqualColumnWidth );
172+
mLegend->setEqualColumnWidth( checked );
173+
mLegend->adjustBoxSize();
174+
mLegend->update();
175+
mLegend->endCommand();
176+
}
150177
}
151178

152179
void QgsComposerLegendWidget::on_mSymbolWidthSpinBox_valueChanged( double d )
@@ -731,6 +758,8 @@ void QgsComposerLegendWidget::blockAllSignals( bool b )
731758
mCheckBoxAutoUpdate->blockSignals( b );
732759
mMapComboBox->blockSignals( b );
733760
mColumnCountSpinBox->blockSignals( b );
761+
mSplitLayerCheckBox->blockSignals( b );
762+
mEqualColumnWidthCheckBox->blockSignals( b );
734763
mSymbolWidthSpinBox->blockSignals( b );
735764
mSymbolHeightSpinBox->blockSignals( b );
736765
mGroupSpaceSpinBox->blockSignals( b );

src/app/composer/qgscomposerlegendwidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class QgsComposerLegendWidget: public QWidget, private Ui::QgsComposerLegendWidg
4242
void on_mWrapCharLineEdit_textChanged( const QString& text );
4343
void on_mTitleLineEdit_textChanged( const QString& text );
4444
void on_mColumnCountSpinBox_valueChanged( int c );
45+
void on_mSplitLayerCheckBox_toggled( bool checked );
46+
void on_mEqualColumnWidthCheckBox_toggled( bool checked );
4547
void on_mSymbolWidthSpinBox_valueChanged( double d );
4648
void on_mSymbolHeightSpinBox_valueChanged( double d );
4749
void on_mGroupSpaceSpinBox_valueChanged( double d );

src/core/composer/qgscomposeritemcommand.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class CORE_EXPORT QgsComposerMergeCommand: public QgsComposerItemCommand
8181
//composer legend
8282
ComposerLegendText,
8383
LegendColumnCount,
84+
LegendSplitLayer,
85+
LegendEqualColumnWidth,
8486
LegendSymbolWidth,
8587
LegendSymbolHeight,
8688
LegendGroupSpace,

0 commit comments

Comments
 (0)