Skip to content

Commit ee84bb1

Browse files
committedMar 26, 2013
composer legend styles, fixes partialy #6960
1 parent 53c47dd commit ee84bb1

12 files changed

+664
-279
lines changed
 

‎python/core/composer/qgscomposerlegend.sip

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class QgsComposerLegend : QgsComposerItem
55
{
66
%TypeHeaderCode
77
#include <qgscomposerlegend.h>
8+
#include <qgscomposerlegendstyle.h>
89
%End
910

1011
public:
@@ -30,33 +31,18 @@ class QgsComposerLegend : QgsComposerItem
3031
void setTitle( const QString& t );
3132
QString title() const;
3233

33-
QFont titleFont() const;
34-
void setTitleFont( const QFont& f );
35-
36-
QFont groupFont() const;
37-
void setGroupFont( const QFont& f );
38-
39-
QFont layerFont() const;
40-
void setLayerFont( const QFont& f );
41-
42-
QFont itemFont() const;
43-
void setItemFont( const QFont& f );
34+
/*
35+
QgsComposerLegendStyle style(QgsComposerLegendStyle::Style s) const;
36+
void setStyle(QgsComposerLegendStyle::Style s, const QgsComposerLegendStyle style);
37+
QFont styleFont( QgsComposerLegendStyle::Style s ) const;
38+
void setStyleFont( QgsComposerLegendStyle::Style s, const QFont& f );
39+
void setStyleMargin( QgsComposerLegendStyle::Style s, double margin );
40+
void setStyleMargin( QgsComposerLegendStyle::Style s, QgsComposerLegendStyle::Side side, double margin );
41+
*/
4442

4543
double boxSpace() const;
4644
void setBoxSpace( double s );
4745

48-
double groupSpace() const;
49-
void setGroupSpace( double s );
50-
51-
double layerSpace() const;
52-
void setLayerSpace( double s );
53-
54-
double symbolSpace() const;
55-
void setSymbolSpace( double s );
56-
57-
double iconLabelSpace() const;
58-
void setIconLabelSpace( double s );
59-
6046
double symbolWidth() const;
6147
void setSymbolWidth( double w );
6248

‎src/app/composer/qgscomposerlegendwidget.cpp

Lines changed: 98 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,75 @@
3636

3737
#include <QMessageBox>
3838

39+
QgsComposerLegendWidgetStyleDelegate::QgsComposerLegendWidgetStyleDelegate( QObject *parent ): QItemDelegate( parent )
40+
{
41+
}
42+
43+
QWidget *QgsComposerLegendWidgetStyleDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem & item, const QModelIndex & index ) const
44+
{
45+
Q_UNUSED( item );
46+
Q_UNUSED( index );
47+
QgsDebugMsg( "Entered" );
48+
49+
QComboBox *editor = new QComboBox( parent );
50+
QList<QgsComposerLegendStyle::Style> list;
51+
list << QgsComposerLegendStyle::Group << QgsComposerLegendStyle::Subgroup << QgsComposerLegendStyle::Hidden;
52+
foreach ( QgsComposerLegendStyle::Style s, list )
53+
{
54+
editor->addItem( QgsComposerLegendStyle::styleLabel( s ), s );
55+
}
56+
57+
return editor;
58+
}
59+
60+
void QgsComposerLegendWidgetStyleDelegate::setEditorData( QWidget *editor, const QModelIndex &index ) const
61+
{
62+
QgsDebugMsg( "Entered" );
63+
//int s = index.model()->data(index, Qt::UserRole).toInt();
64+
QComboBox *comboBox = static_cast<QComboBox*>( editor );
65+
66+
const QStandardItemModel * standardModel = dynamic_cast<const QStandardItemModel*>( index.model() );
67+
if ( standardModel )
68+
{
69+
QModelIndex firstColumnIndex = standardModel->index( index.row(), 0, index.parent() );
70+
QStandardItem* firstColumnItem = standardModel->itemFromIndex( firstColumnIndex );
71+
72+
QgsComposerLegendItem* cItem = dynamic_cast<QgsComposerLegendItem*>( firstColumnItem );
73+
if ( cItem )
74+
{
75+
comboBox->setCurrentIndex( comboBox->findData( cItem->style() ) );
76+
}
77+
}
78+
}
79+
80+
void QgsComposerLegendWidgetStyleDelegate::setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const
81+
{
82+
QgsDebugMsg( "Entered" );
83+
QComboBox *comboBox = static_cast<QComboBox*>( editor );
84+
QgsComposerLegendStyle::Style s = ( QgsComposerLegendStyle::Style ) comboBox->itemData( comboBox->currentIndex() ).toInt();
85+
model->setData( index, s, Qt::UserRole );
86+
model->setData( index, QgsComposerLegendStyle::styleLabel( s ), Qt::DisplayRole );
87+
QStandardItemModel * standardModel = dynamic_cast<QStandardItemModel*>( model );
88+
if ( standardModel )
89+
{
90+
QModelIndex firstColumnIndex = standardModel->index( index.row(), 0, index.parent() );
91+
QStandardItem* firstColumnItem = standardModel->itemFromIndex( firstColumnIndex );
92+
93+
QgsComposerLegendItem* cItem = dynamic_cast<QgsComposerLegendItem*>( firstColumnItem );
94+
if ( cItem )
95+
{
96+
cItem->setStyle( s );
97+
}
98+
}
99+
}
100+
101+
void QgsComposerLegendWidgetStyleDelegate::updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex & index ) const
102+
{
103+
Q_UNUSED( index );
104+
editor->setGeometry( option.rect );
105+
}
106+
107+
39108
QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend* legend ): mLegend( legend )
40109
{
41110
setupUi( this );
@@ -54,9 +123,15 @@ QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend* legend ): m
54123

55124
if ( legend )
56125
{
126+
legend->model()->setHorizontalHeaderLabels( QStringList() << tr( "Item" ) << tr( "Style" ) );
57127
mItemTreeView->setModel( legend->model() );
58128
}
59129

130+
QgsComposerLegendWidgetStyleDelegate* styleDelegate = new QgsComposerLegendWidgetStyleDelegate();
131+
mItemTreeView->setItemDelegateForColumn( 0, styleDelegate );
132+
mItemTreeView->setItemDelegateForColumn( 1, styleDelegate );
133+
mItemTreeView->setEditTriggers( QAbstractItemView::AllEditTriggers );
134+
60135
mItemTreeView->setDragEnabled( true );
61136
mItemTreeView->setAcceptDrops( true );
62137
mItemTreeView->setDropIndicatorShown( true );
@@ -93,10 +168,11 @@ void QgsComposerLegendWidget::setGuiElements()
93168
mEqualColumnWidthCheckBox->setChecked( mLegend->equalColumnWidth() );
94169
mSymbolWidthSpinBox->setValue( mLegend->symbolWidth() );
95170
mSymbolHeightSpinBox->setValue( mLegend->symbolHeight() );
96-
mGroupSpaceSpinBox->setValue( mLegend->groupSpace() );
97-
mLayerSpaceSpinBox->setValue( mLegend->layerSpace() );
98-
mSymbolSpaceSpinBox->setValue( mLegend->symbolSpace() );
99-
mIconLabelSpaceSpinBox->setValue( mLegend->iconLabelSpace() );
171+
mGroupSpaceSpinBox->setValue( mLegend->style( QgsComposerLegendStyle::Group ).margin( QgsComposerLegendStyle::Top ) );
172+
mLayerSpaceSpinBox->setValue( mLegend->style( QgsComposerLegendStyle::Subgroup ).margin( QgsComposerLegendStyle::Top ) );
173+
// We keep Symbol and SymbolLabel Top in sync for now
174+
mSymbolSpaceSpinBox->setValue( mLegend->style( QgsComposerLegendStyle::Symbol ).margin( QgsComposerLegendStyle::Top ) );
175+
mIconLabelSpaceSpinBox->setValue( mLegend->style( QgsComposerLegendStyle::SymbolLabel ).margin( QgsComposerLegendStyle::Left ) );
100176
mBoxSpaceSpinBox->setValue( mLegend->boxSpace() );
101177
mColumnSpaceSpinBox->setValue( mLegend->columnSpace() );
102178
if ( mLegend->model() )
@@ -208,7 +284,7 @@ void QgsComposerLegendWidget::on_mGroupSpaceSpinBox_valueChanged( double d )
208284
if ( mLegend )
209285
{
210286
mLegend->beginCommand( tr( "Legend group space" ), QgsComposerMergeCommand::LegendGroupSpace );
211-
mLegend->setGroupSpace( d );
287+
mLegend->rstyle( QgsComposerLegendStyle::Group ).setMargin( QgsComposerLegendStyle::Top, d );
212288
mLegend->adjustBoxSize();
213289
mLegend->update();
214290
mLegend->endCommand();
@@ -220,7 +296,7 @@ void QgsComposerLegendWidget::on_mLayerSpaceSpinBox_valueChanged( double d )
220296
if ( mLegend )
221297
{
222298
mLegend->beginCommand( tr( "Legend layer space" ), QgsComposerMergeCommand::LegendLayerSpace );
223-
mLegend->setLayerSpace( d );
299+
mLegend->rstyle( QgsComposerLegendStyle::Subgroup ).setMargin( QgsComposerLegendStyle::Top, d );
224300
mLegend->adjustBoxSize();
225301
mLegend->update();
226302
mLegend->endCommand();
@@ -232,7 +308,9 @@ void QgsComposerLegendWidget::on_mSymbolSpaceSpinBox_valueChanged( double d )
232308
if ( mLegend )
233309
{
234310
mLegend->beginCommand( tr( "Legend symbol space" ), QgsComposerMergeCommand::LegendSymbolSpace );
235-
mLegend->setSymbolSpace( d );
311+
// We keep Symbol and SymbolLabel Top in sync for now
312+
mLegend->rstyle( QgsComposerLegendStyle::Symbol ).setMargin( QgsComposerLegendStyle::Top, d );
313+
mLegend->rstyle( QgsComposerLegendStyle::SymbolLabel ).setMargin( QgsComposerLegendStyle::Top, d );
236314
mLegend->adjustBoxSize();
237315
mLegend->update();
238316
mLegend->endCommand();
@@ -244,7 +322,7 @@ void QgsComposerLegendWidget::on_mIconLabelSpaceSpinBox_valueChanged( double d )
244322
if ( mLegend )
245323
{
246324
mLegend->beginCommand( tr( "Legend icon label space" ), QgsComposerMergeCommand::LegendIconSymbolSpace );
247-
mLegend->setIconLabelSpace( d );
325+
mLegend->rstyle( QgsComposerLegendStyle::SymbolLabel ).setMargin( QgsComposerLegendStyle::Left, d );
248326
mLegend->adjustBoxSize();
249327
mLegend->update();
250328
mLegend->endCommand();
@@ -258,14 +336,14 @@ void QgsComposerLegendWidget::on_mTitleFontButton_clicked()
258336
bool ok;
259337
#if defined(Q_WS_MAC) && QT_VERSION >= 0x040500 && defined(QT_MAC_USE_COCOA)
260338
// Native Mac dialog works only for Qt Carbon
261-
QFont newFont = QFontDialog::getFont( &ok, mLegend->titleFont(), 0, QString(), QFontDialog::DontUseNativeDialog );
339+
QFont newFont = QFontDialog::getFont( &ok, mLegend->style( QgsComposerLegendStyle::Title ).font(), 0, QString(), QFontDialog::DontUseNativeDialog );
262340
#else
263-
QFont newFont = QFontDialog::getFont( &ok, mLegend->titleFont() );
341+
QFont newFont = QFontDialog::getFont( &ok, mLegend->style( QgsComposerLegendStyle::Title ).font() );
264342
#endif
265343
if ( ok )
266344
{
267345
mLegend->beginCommand( tr( "Title font changed" ) );
268-
mLegend->setTitleFont( newFont );
346+
mLegend->setStyleFont( QgsComposerLegendStyle::Title, newFont );
269347
mLegend->adjustBoxSize();
270348
mLegend->update();
271349
mLegend->endCommand();
@@ -280,14 +358,14 @@ void QgsComposerLegendWidget::on_mGroupFontButton_clicked()
280358
bool ok;
281359
#if defined(Q_WS_MAC) && QT_VERSION >= 0x040500 && defined(QT_MAC_USE_COCOA)
282360
// Native Mac dialog works only for Qt Carbon
283-
QFont newFont = QFontDialog::getFont( &ok, mLegend->groupFont(), 0, QString(), QFontDialog::DontUseNativeDialog );
361+
QFont newFont = QFontDialog::getFont( &ok, mLegend->style( QgsComposerLegendStyle::Group ).font(), 0, QString(), QFontDialog::DontUseNativeDialog );
284362
#else
285-
QFont newFont = QFontDialog::getFont( &ok, mLegend->groupFont() );
363+
QFont newFont = QFontDialog::getFont( &ok, mLegend->style( QgsComposerLegendStyle::Group ).font() );
286364
#endif
287365
if ( ok )
288366
{
289367
mLegend->beginCommand( tr( "Legend group font changed" ) );
290-
mLegend->setGroupFont( newFont );
368+
mLegend->setStyleFont( QgsComposerLegendStyle::Group, newFont );
291369
mLegend->adjustBoxSize();
292370
mLegend->update();
293371
mLegend->endCommand();
@@ -302,14 +380,14 @@ void QgsComposerLegendWidget::on_mLayerFontButton_clicked()
302380
bool ok;
303381
#if defined(Q_WS_MAC) && QT_VERSION >= 0x040500 && defined(QT_MAC_USE_COCOA)
304382
// Native Mac dialog works only for Qt Carbon
305-
QFont newFont = QFontDialog::getFont( &ok, mLegend->layerFont(), 0, QString(), QFontDialog::DontUseNativeDialog );
383+
QFont newFont = QFontDialog::getFont( &ok, mLegend->style( QgsComposerLegendStyle::Subgroup ).font(), 0, QString(), QFontDialog::DontUseNativeDialog );
306384
#else
307-
QFont newFont = QFontDialog::getFont( &ok, mLegend->layerFont() );
385+
QFont newFont = QFontDialog::getFont( &ok, mLegend->style( QgsComposerLegendStyle::Subgroup ).font() );
308386
#endif
309387
if ( ok )
310388
{
311389
mLegend->beginCommand( tr( "Legend layer font changed" ) );
312-
mLegend->setLayerFont( newFont );
390+
mLegend->setStyleFont( QgsComposerLegendStyle::Subgroup, newFont );
313391
mLegend->adjustBoxSize();
314392
mLegend->update();
315393
mLegend->endCommand();
@@ -324,14 +402,14 @@ void QgsComposerLegendWidget::on_mItemFontButton_clicked()
324402
bool ok;
325403
#if defined(Q_WS_MAC) && QT_VERSION >= 0x040500 && defined(QT_MAC_USE_COCOA)
326404
// Native Mac dialog works only for Qt Carbon
327-
QFont newFont = QFontDialog::getFont( &ok, mLegend->itemFont(), 0, QString(), QFontDialog::DontUseNativeDialog );
405+
QFont newFont = QFontDialog::getFont( &ok, mLegend->style( QgsComposerLegendStyle::SymbolLabel ).font(), 0, QString(), QFontDialog::DontUseNativeDialog );
328406
#else
329-
QFont newFont = QFontDialog::getFont( &ok, mLegend->itemFont() );
407+
QFont newFont = QFontDialog::getFont( &ok, mLegend->style( QgsComposerLegendStyle::SymbolLabel ).font() );
330408
#endif
331409
if ( ok )
332410
{
333411
mLegend->beginCommand( tr( "Legend item font changed" ) );
334-
mLegend->setItemFont( newFont );
412+
mLegend->setStyleFont( QgsComposerLegendStyle::SymbolLabel, newFont );
335413
mLegend->adjustBoxSize();
336414
mLegend->update();
337415
mLegend->endCommand();

‎src/app/composer/qgscomposerlegendwidget.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,22 @@
2020

2121
#include "ui_qgscomposerlegendwidgetbase.h"
2222
#include <QWidget>
23+
#include <QItemDelegate>
2324

2425
class QgsComposerLegend;
2526

27+
class QgsComposerLegendWidgetStyleDelegate : public QItemDelegate
28+
{
29+
Q_OBJECT
30+
31+
public:
32+
QgsComposerLegendWidgetStyleDelegate( QObject *parent = 0 );
33+
QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const;
34+
void setEditorData( QWidget *editor, const QModelIndex &index ) const;
35+
void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const;
36+
void updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index ) const;
37+
};
38+
2639
/** \ingroup MapComposer
2740
* A widget for setting properties relating to a composer legend.
2841
*/

‎src/core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ SET(QGIS_CORE_SRCS
146146
composer/qgsatlascomposition.cpp
147147
composer/qgslegendmodel.cpp
148148
composer/qgscomposerlegend.cpp
149+
composer/qgscomposerlegendstyle.cpp
149150
composer/qgspaperitem.cpp
150151
composer/qgsscalebarstyle.cpp
151152
composer/qgsdoubleboxscalebarstyle.cpp
@@ -321,6 +322,7 @@ SET(QGIS_CORE_MOC_HDRS
321322

322323
composer/qgsaddremoveitemcommand.h
323324
composer/qgscomposerlegend.h
325+
composer/qgscomposerlegendstyle.h
324326
composer/qgscomposermap.h
325327
composer/qgscomposerpicture.h
326328
composer/qgscomposerscalebar.h

‎src/core/composer/qgscomposerlegend.cpp

Lines changed: 142 additions & 141 deletions
Large diffs are not rendered by default.

‎src/core/composer/qgscomposerlegend.h

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#ifndef QGSCOMPOSERLEGEND_H
1919
#define QGSCOMPOSERLEGEND_H
2020

21+
#include "qgscomposerlegendstyle.h"
2122
#include "qgscomposeritem.h"
2223
#include "qgscomposerlegenditem.h"
2324
#include "qgslegendmodel.h"
@@ -33,10 +34,9 @@ class QgsComposerMap;
3334
*/
3435
class CORE_EXPORT QgsComposerLegend : public QgsComposerItem
3536
{
36-
Q_OBJECT
37+
Q_OBJECT;
3738

3839
public:
39-
4040
QgsComposerLegend( QgsComposition* composition );
4141
~QgsComposerLegend();
4242

@@ -60,38 +60,28 @@ class CORE_EXPORT QgsComposerLegend : public QgsComposerItem
6060
void setTitle( const QString& t ) {mTitle = t;}
6161
QString title() const {return mTitle;}
6262

63-
QFont titleFont() const;
64-
void setTitleFont( const QFont& f );
65-
66-
QFont groupFont() const;
67-
void setGroupFont( const QFont& f );
68-
69-
QFont layerFont() const;
70-
void setLayerFont( const QFont& f );
63+
/** Returns reference to modifiable style */
64+
QgsComposerLegendStyle & rstyle( QgsComposerLegendStyle::Style s ) { return mStyleMap[s]; }
65+
/** Returns style */
66+
QgsComposerLegendStyle style( QgsComposerLegendStyle::Style s ) const { return mStyleMap.value( s ); }
67+
void setStyle( QgsComposerLegendStyle::Style s, const QgsComposerLegendStyle style ) { mStyleMap[s] = style; }
7168

72-
QFont itemFont() const;
73-
void setItemFont( const QFont& f );
69+
QFont styleFont( QgsComposerLegendStyle::Style s ) const { return style( s ).font(); }
70+
/** Set style font */
71+
void setStyleFont( QgsComposerLegendStyle::Style s, const QFont& f );
7472

75-
QColor fontColor() const {return mFontColor;}
76-
void setFontColor( const QColor& c ) {mFontColor = c;}
73+
/** Set style margin*/
74+
void setStyleMargin( QgsComposerLegendStyle::Style s, double margin );
75+
void setStyleMargin( QgsComposerLegendStyle::Style s, QgsComposerLegendStyle::Side side, double margin );
7776

7877
double boxSpace() const {return mBoxSpace;}
7978
void setBoxSpace( double s ) {mBoxSpace = s;}
8079

8180
double columnSpace() const {return mColumnSpace;}
8281
void setColumnSpace( double s ) { mColumnSpace = s;}
8382

84-
double groupSpace() const {return mGroupSpace;}
85-
void setGroupSpace( double s ) {mGroupSpace = s;}
86-
87-
double layerSpace() const {return mLayerSpace;}
88-
void setLayerSpace( double s ) {mLayerSpace = s;}
89-
90-
double symbolSpace() const {return mSymbolSpace;}
91-
void setSymbolSpace( double s ) {mSymbolSpace = s;}
92-
93-
double iconLabelSpace() const {return mIconLabelSpace;}
94-
void setIconLabelSpace( double s ) {mIconLabelSpace = s;}
83+
QColor fontColor() const {return mFontColor;}
84+
void setFontColor( const QColor& c ) {mFontColor = c;}
9585

9686
double symbolWidth() const {return mSymbolWidth;}
9787
void setSymbolWidth( double w ) {mSymbolWidth = w;}
@@ -139,25 +129,13 @@ class CORE_EXPORT QgsComposerLegend : public QgsComposerItem
139129
QString mTitle;
140130
QString mWrapChar;
141131

142-
//different fonts for entries
143-
QFont mTitleFont;
144-
QFont mGroupFont;
145-
QFont mLayerFont;
146-
QFont mItemFont;
147132
QColor mFontColor;
148133

149134
/**Space between item box and contents*/
150135
qreal mBoxSpace;
151136
/**Space between columns*/
152137
double mColumnSpace;
153-
/**Vertical space between group entries*/
154-
double mGroupSpace;
155-
/**Vertical space between layer entries*/
156-
double mLayerSpace;
157-
/**Vertical space between symbol entries*/
158-
double mSymbolSpace;
159-
/**Horizontal space between item icon and label*/
160-
double mIconLabelSpace;
138+
161139
/**Width of symbol icon*/
162140
double mSymbolWidth;
163141
/**Height of symbol icon*/
@@ -257,6 +235,8 @@ class CORE_EXPORT QgsComposerLegend : public QgsComposerItem
257235
/** Splits a string using the wrap char taking into account handling empty
258236
wrap char which means no wrapping */
259237
QStringList splitStringForWrapping( QString stringToSplt );
238+
239+
QMap<QgsComposerLegendStyle::Style, QgsComposerLegendStyle> mStyleMap;
260240
};
261241

262242
#endif

‎src/core/composer/qgscomposerlegenditem.cpp

Lines changed: 67 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@
1515
* *
1616
***************************************************************************/
1717

18+
#include "qgscomposerlegendstyle.h"
1819
#include "qgscomposerlegenditem.h"
20+
#include "qgscomposerlegend.h"
1921
#include "qgsmaplayerregistry.h"
2022
#include "qgsrasterlayer.h"
23+
#include "qgsrenderer.h"
24+
#include "qgsrendererv2.h"
2125
#include "qgssymbol.h"
2226
#include "qgssymbolv2.h"
2327
#include "qgssymbollayerv2utils.h"
@@ -26,15 +30,18 @@
2630
#include <QDomDocument>
2731
#include <QDomElement>
2832

29-
QgsComposerLegendItem::QgsComposerLegendItem(): QStandardItem()
33+
QgsComposerLegendItem::QgsComposerLegendItem( QgsComposerLegendStyle::Style s ): QStandardItem()
34+
, mStyle( s )
3035
{
3136
}
3237

33-
QgsComposerLegendItem::QgsComposerLegendItem( const QString& text ): QStandardItem( text )
38+
QgsComposerLegendItem::QgsComposerLegendItem( const QString& text, QgsComposerLegendStyle::Style s ): QStandardItem( text )
39+
, mStyle( s )
3440
{
3541
}
3642

37-
QgsComposerLegendItem::QgsComposerLegendItem( const QIcon& icon, const QString& text ): QStandardItem( icon, text )
43+
QgsComposerLegendItem::QgsComposerLegendItem( const QIcon& icon, const QString& text, QgsComposerLegendStyle::Style s ): QStandardItem( icon, text )
44+
, mStyle( s )
3845
{
3946
}
4047

@@ -58,15 +65,15 @@ void QgsComposerLegendItem::writeXMLChildren( QDomElement& elem, QDomDocument& d
5865

5966
//////////////////////////////QgsComposerSymbolItem
6067

61-
QgsComposerSymbolItem::QgsComposerSymbolItem(): QgsComposerLegendItem(), mSymbol( 0 )
68+
QgsComposerSymbolItem::QgsComposerSymbolItem(): QgsComposerLegendItem( QgsComposerLegendStyle::Symbol ), mSymbol( 0 )
6269
{
6370
}
6471

65-
QgsComposerSymbolItem::QgsComposerSymbolItem( const QString& text ): QgsComposerLegendItem( text ), mSymbol( 0 )
72+
QgsComposerSymbolItem::QgsComposerSymbolItem( const QString& text ): QgsComposerLegendItem( text, QgsComposerLegendStyle::Symbol ), mSymbol( 0 )
6673
{
6774
}
6875

69-
QgsComposerSymbolItem::QgsComposerSymbolItem( const QIcon& icon, const QString& text ): QgsComposerLegendItem( icon, text ), mSymbol( 0 )
76+
QgsComposerSymbolItem::QgsComposerSymbolItem( const QIcon& icon, const QString& text ): QgsComposerLegendItem( icon, text, QgsComposerLegendStyle::Symbol ), mSymbol( 0 )
7077
{
7178
}
7279

@@ -155,15 +162,15 @@ void QgsComposerSymbolItem::readXML( const QDomElement& itemElem, bool xServerAv
155162

156163
#include "qgssymbolv2.h"
157164

158-
QgsComposerSymbolV2Item::QgsComposerSymbolV2Item(): QgsComposerLegendItem(), mSymbolV2( 0 )
165+
QgsComposerSymbolV2Item::QgsComposerSymbolV2Item(): QgsComposerLegendItem( QgsComposerLegendStyle::Symbol ), mSymbolV2( 0 )
159166
{
160167
}
161168

162-
QgsComposerSymbolV2Item::QgsComposerSymbolV2Item( const QString& text ): QgsComposerLegendItem( text ), mSymbolV2( 0 )
169+
QgsComposerSymbolV2Item::QgsComposerSymbolV2Item( const QString& text ): QgsComposerLegendItem( text, QgsComposerLegendStyle::Symbol ), mSymbolV2( 0 )
163170
{
164171
}
165172

166-
QgsComposerSymbolV2Item::QgsComposerSymbolV2Item( const QIcon& icon, const QString& text ): QgsComposerLegendItem( icon, text ), mSymbolV2( 0 )
173+
QgsComposerSymbolV2Item::QgsComposerSymbolV2Item( const QIcon& icon, const QString& text ): QgsComposerLegendItem( icon, text, QgsComposerLegendStyle::Symbol ), mSymbolV2( 0 )
167174
{
168175
}
169176

@@ -234,15 +241,15 @@ void QgsComposerSymbolV2Item::setSymbolV2( QgsSymbolV2* s )
234241

235242
////////////////////QgsComposerRasterSymbolItem
236243

237-
QgsComposerRasterSymbolItem::QgsComposerRasterSymbolItem(): QgsComposerLegendItem()
244+
QgsComposerRasterSymbolItem::QgsComposerRasterSymbolItem(): QgsComposerLegendItem( QgsComposerLegendStyle::Symbol )
238245
{
239246
}
240247

241-
QgsComposerRasterSymbolItem::QgsComposerRasterSymbolItem( const QString& text ): QgsComposerLegendItem( text )
248+
QgsComposerRasterSymbolItem::QgsComposerRasterSymbolItem( const QString& text ): QgsComposerLegendItem( text, QgsComposerLegendStyle::Symbol )
242249
{
243250
}
244251

245-
QgsComposerRasterSymbolItem::QgsComposerRasterSymbolItem( const QIcon& icon, const QString& text ): QgsComposerLegendItem( icon, text )
252+
QgsComposerRasterSymbolItem::QgsComposerRasterSymbolItem( const QIcon& icon, const QString& text ): QgsComposerLegendItem( icon, text, QgsComposerLegendStyle::Symbol )
246253
{
247254
}
248255

@@ -287,12 +294,12 @@ void QgsComposerRasterSymbolItem::readXML( const QDomElement& itemElem, bool xSe
287294

288295
////////////////////QgsComposerLayerItem
289296

290-
QgsComposerLayerItem::QgsComposerLayerItem(): QgsComposerLegendItem()
297+
QgsComposerLayerItem::QgsComposerLayerItem(): QgsComposerLegendItem( QgsComposerLegendStyle::Subgroup )
291298
, mShowFeatureCount( false )
292299
{
293300
}
294301

295-
QgsComposerLayerItem::QgsComposerLayerItem( const QString& text ): QgsComposerLegendItem( text )
302+
QgsComposerLayerItem::QgsComposerLayerItem( const QString& text ): QgsComposerLegendItem( text, QgsComposerLegendStyle::Subgroup )
296303
, mShowFeatureCount( false )
297304
{
298305
}
@@ -315,6 +322,7 @@ void QgsComposerLayerItem::writeXML( QDomElement& elem, QDomDocument& doc ) cons
315322
layerItemElem.setAttribute( "layerId", mLayerID );
316323
layerItemElem.setAttribute( "text", text() );
317324
layerItemElem.setAttribute( "showFeatureCount", showFeatureCount() );
325+
layerItemElem.setAttribute( "style", QgsComposerLegendStyle::styleName( mStyle ) );
318326
writeXMLChildren( layerItemElem, doc );
319327
elem.appendChild( layerItemElem );
320328
}
@@ -328,6 +336,7 @@ void QgsComposerLayerItem::readXML( const QDomElement& itemElem, bool xServerAva
328336
setText( itemElem.attribute( "text", "" ) );
329337
setLayerID( itemElem.attribute( "layerId", "" ) );
330338
setShowFeatureCount( itemElem.attribute( "showFeatureCount", "" ) == "1" ? true : false );
339+
setStyle( QgsComposerLegendStyle::styleFromName( itemElem.attribute( "style", "subgroup" ) ) );
331340

332341
//now call readXML for all the child items
333342
QDomNodeList childList = itemElem.childNodes();
@@ -367,13 +376,35 @@ void QgsComposerLayerItem::readXML( const QDomElement& itemElem, bool xServerAva
367376
}
368377
}
369378

379+
void QgsComposerLayerItem::setDefaultStyle()
380+
{
381+
// set default style according to number of symbols
382+
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( layerID() ) );
383+
if ( vLayer )
384+
{
385+
QgsFeatureRendererV2* renderer = vLayer->rendererV2();
386+
if ( renderer )
387+
{
388+
if ( renderer->legendSymbolItems().size() > 1 )
389+
{
390+
setStyle( QgsComposerLegendStyle::Subgroup );
391+
}
392+
else
393+
{
394+
// Hide title by default for single symbol
395+
setStyle( QgsComposerLegendStyle::Hidden );
396+
}
397+
}
398+
}
399+
}
400+
370401
////////////////////QgsComposerGroupItem
371402

372-
QgsComposerGroupItem::QgsComposerGroupItem(): QgsComposerLegendItem()
403+
QgsComposerGroupItem::QgsComposerGroupItem(): QgsComposerLegendItem( QgsComposerLegendStyle::Group )
373404
{
374405
}
375406

376-
QgsComposerGroupItem::QgsComposerGroupItem( const QString& text ): QgsComposerLegendItem( text )
407+
QgsComposerGroupItem::QgsComposerGroupItem( const QString& text ): QgsComposerLegendItem( text, QgsComposerLegendStyle::Group )
377408
{
378409
}
379410

@@ -392,6 +423,7 @@ void QgsComposerGroupItem::writeXML( QDomElement& elem, QDomDocument& doc ) cons
392423
{
393424
QDomElement layerGroupElem = doc.createElement( "GroupItem" );
394425
layerGroupElem.setAttribute( "text", text() );
426+
layerGroupElem.setAttribute( "style", QgsComposerLegendStyle::styleName( mStyle ) );
395427
writeXMLChildren( layerGroupElem, doc );
396428
elem.appendChild( layerGroupElem );
397429
}
@@ -404,6 +436,8 @@ void QgsComposerGroupItem::readXML( const QDomElement& itemElem, bool xServerAva
404436
}
405437
setText( itemElem.attribute( "text", "" ) );
406438

439+
setStyle( QgsComposerLegendStyle::styleFromName( itemElem.attribute( "style", "group" ) ) );
440+
407441
//now call readXML for all the child items
408442
QDomNodeList childList = itemElem.childNodes();
409443
QDomNode currentNode;
@@ -435,6 +469,22 @@ void QgsComposerGroupItem::readXML( const QDomElement& itemElem, bool xServerAva
435469
continue; //unsupported child item type
436470
}
437471
currentChildItem->readXML( currentElem, xServerAvailable );
438-
appendRow( currentChildItem );
472+
473+
QList<QStandardItem *> itemsList;
474+
itemsList << currentChildItem << new QgsComposerStyleItem( currentChildItem );
475+
appendRow( itemsList );
439476
}
440477
}
478+
479+
QgsComposerStyleItem::QgsComposerStyleItem(): QStandardItem()
480+
{
481+
}
482+
483+
QgsComposerStyleItem::QgsComposerStyleItem( QgsComposerLegendItem *item ): QStandardItem()
484+
{
485+
setData( QgsComposerLegendStyle::styleLabel( item->style() ) , Qt::DisplayRole );
486+
}
487+
488+
QgsComposerStyleItem::~QgsComposerStyleItem()
489+
{
490+
}

‎src/core/composer/qgscomposerlegenditem.h

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#ifndef QGSCOMPOSERLEGENDITEM_H
1919
#define QGSCOMPOSERLEGENDITEM_H
2020

21+
#include "qgscomposerlegendstyle.h"
2122
#include <QStandardItem>
2223
class QDomDocument;
2324
class QDomElement;
@@ -26,9 +27,9 @@ class QDomElement;
2627
class CORE_EXPORT QgsComposerLegendItem: public QStandardItem
2728
{
2829
public:
29-
QgsComposerLegendItem();
30-
QgsComposerLegendItem( const QString& text );
31-
QgsComposerLegendItem( const QIcon& icon, const QString& text );
30+
QgsComposerLegendItem( QgsComposerLegendStyle::Style s = QgsComposerLegendStyle::Undefined );
31+
QgsComposerLegendItem( const QString& text, QgsComposerLegendStyle::Style s = QgsComposerLegendStyle::Undefined );
32+
QgsComposerLegendItem( const QIcon& icon, const QString& text, QgsComposerLegendStyle::Style s = QgsComposerLegendStyle::Undefined );
3233
virtual ~QgsComposerLegendItem();
3334

3435
enum ItemType
@@ -37,7 +38,8 @@ class CORE_EXPORT QgsComposerLegendItem: public QStandardItem
3738
LayerItem,
3839
SymbologyItem,
3940
SymbologyV2Item,
40-
RasterSymbolItem
41+
RasterSymbolItem,
42+
StyleItem
4143
};
4244

4345
virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const = 0;
@@ -49,8 +51,13 @@ class CORE_EXPORT QgsComposerLegendItem: public QStandardItem
4951
virtual ItemType itemType() const = 0;
5052
virtual QStandardItem* clone() const = 0;
5153

54+
QgsComposerLegendStyle::Style style() const { return mStyle; }
55+
void setStyle( QgsComposerLegendStyle::Style style ) { mStyle = style; }
56+
5257
protected:
5358
void writeXMLChildren( QDomElement& elem, QDomDocument& doc ) const;
59+
60+
QgsComposerLegendStyle::Style mStyle;
5461
};
5562

5663
class QgsSymbol;
@@ -151,6 +158,8 @@ class CORE_EXPORT QgsComposerLayerItem: public QgsComposerLegendItem
151158
void setShowFeatureCount( bool show ) { mShowFeatureCount = show; }
152159
bool showFeatureCount() const { return mShowFeatureCount; }
153160

161+
void setDefaultStyle();
162+
154163
private:
155164
QString mLayerID;
156165
// Show vector feature counts
@@ -171,4 +180,12 @@ class CORE_EXPORT QgsComposerGroupItem: public QgsComposerLegendItem
171180
ItemType itemType() const { return GroupItem; }
172181
};
173182

183+
class CORE_EXPORT QgsComposerStyleItem: public QStandardItem
184+
{
185+
public:
186+
QgsComposerStyleItem( );
187+
QgsComposerStyleItem( QgsComposerLegendItem *item );
188+
~QgsComposerStyleItem();
189+
};
190+
174191
#endif // QGSCOMPOSERLEGENDITEM_H
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/***************************************************************************
2+
qgscomposerlegendstyle.cpp
3+
---------------------
4+
begin : March 2013
5+
copyright : (C) 2013 by Radim Blazek
6+
email : radim.blazek@gmail.com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgscomposerlegendstyle.h"
19+
#include <QFont>
20+
#include <QMap>
21+
#include <QString>
22+
#include <QDomElement>
23+
#include <QDomDocument>
24+
#include <QDomNode>
25+
26+
QgsComposerLegendStyle::QgsComposerLegendStyle()
27+
{
28+
}
29+
30+
QgsComposerLegendStyle::~QgsComposerLegendStyle()
31+
{
32+
}
33+
34+
void QgsComposerLegendStyle::setMargin( double margin )
35+
{
36+
mMarginMap[Top] = margin;
37+
mMarginMap[Bottom] = margin;
38+
mMarginMap[Left] = margin;
39+
mMarginMap[Right] = margin;
40+
}
41+
42+
void QgsComposerLegendStyle::writeXML( QString name, QDomElement& elem, QDomDocument & doc ) const
43+
{
44+
if ( elem.isNull() ) return;
45+
46+
QDomElement styleElem = doc.createElement( "style" );
47+
48+
styleElem.setAttribute( "name", name );
49+
50+
styleElem.setAttribute( "marginTop", QString::number( mMarginMap[Top] ) );
51+
styleElem.setAttribute( "marginBottom", QString::number( mMarginMap[Bottom] ) );
52+
styleElem.setAttribute( "marginLeft", QString::number( mMarginMap[Left] ) );
53+
styleElem.setAttribute( "marginRight", QString::number( mMarginMap[Right] ) );
54+
55+
styleElem.setAttribute( "font", mFont.toString() );
56+
57+
elem.appendChild( styleElem );
58+
}
59+
60+
void QgsComposerLegendStyle::readXML( const QDomElement& elem, const QDomDocument& doc )
61+
{
62+
Q_UNUSED( doc );
63+
if ( elem.isNull() ) return;
64+
65+
mFont.fromString( elem.attribute( "font" ) );
66+
67+
mMarginMap[Top] = elem.attribute( "marginTop" ).toDouble();
68+
mMarginMap[Bottom] = elem.attribute( "marginBottom" ).toDouble();
69+
mMarginMap[Left] = elem.attribute( "marginLeft" ).toDouble();
70+
mMarginMap[Right] = elem.attribute( "marginRight" ).toDouble();
71+
}
72+
73+
QString QgsComposerLegendStyle::styleName ( Style s )
74+
{
75+
switch ( s )
76+
{
77+
case Undefined:
78+
return "";
79+
case Hidden:
80+
return "hidden";
81+
case Title:
82+
return "title";
83+
case Group:
84+
return "group";
85+
case Subgroup:
86+
return "subgroup";
87+
case Symbol:
88+
return "symbol";
89+
case SymbolLabel:
90+
return "symbolLabel";
91+
}
92+
return "";
93+
}
94+
95+
QgsComposerLegendStyle::Style QgsComposerLegendStyle::styleFromName ( QString styleName )
96+
{
97+
if ( styleName == "hidden" ) return Hidden;
98+
else if ( styleName == "title" ) return Title;
99+
else if ( styleName == "group" ) return Group;
100+
else if ( styleName == "subgroup" ) return Subgroup;
101+
else if ( styleName == "symbol" ) return Symbol;
102+
else if ( styleName == "symbolLabel" ) return SymbolLabel;
103+
return Undefined;
104+
}
105+
106+
QString QgsComposerLegendStyle::styleLabel ( Style s )
107+
{
108+
switch ( s )
109+
{
110+
case Undefined:
111+
return QObject::tr("Undefined");
112+
case Hidden:
113+
return QObject::tr("Hidden");
114+
case Title:
115+
return QObject::tr("Title");
116+
case Group:
117+
return QObject::tr("Group");
118+
case Subgroup:
119+
return QObject::tr("Subgroup");
120+
case Symbol:
121+
return QObject::tr("Symbol");
122+
case SymbolLabel:
123+
return QObject::tr("Symbol label");
124+
}
125+
return "";
126+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/***************************************************************************
2+
qgscomposerlegendstyle.h
3+
-------------------
4+
begin : March 2013
5+
copyright : (C) 2013 by Radim Blazek
6+
email : radim.blazek@gmail.com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#ifndef QGSCOMPOSERLEGENDSTYLE_H
19+
#define QGSCOMPOSERLEGENDSTYLE_H
20+
21+
#include <QFont>
22+
#include <QMap>
23+
#include <QString>
24+
#include <QDomElement>
25+
#include <QDomDocument>
26+
27+
/** \ingroup MapComposer
28+
* Composer legend components style
29+
*/
30+
class CORE_EXPORT QgsComposerLegendStyle
31+
{
32+
public:
33+
enum Style
34+
{
35+
Undefined, // should not happen, only if corrupted project file
36+
Hidden, // special style, item is hidden includeing margins around
37+
Title,
38+
Group,
39+
Subgroup, // layer
40+
Symbol, // symbol without label
41+
SymbolLabel
42+
};
43+
enum Side // margin side
44+
{
45+
Top = 0,
46+
Bottom = 1,
47+
Left = 2,
48+
Right = 3
49+
};
50+
QgsComposerLegendStyle();
51+
~QgsComposerLegendStyle();
52+
53+
QFont font() const { return mFont; }
54+
QFont & rfont() { return mFont; }
55+
void setFont( const QFont & font ) { mFont = font; }
56+
57+
double margin( Side side ) { return mMarginMap.value( side ); }
58+
void setMargin( Side side, double margin ) { mMarginMap[side] = margin; }
59+
60+
// set all margins
61+
void setMargin( double margin );
62+
63+
void writeXML( QString name, QDomElement& elem, QDomDocument & doc ) const;
64+
65+
void readXML( const QDomElement& elem, const QDomDocument& doc );
66+
67+
/** Get name for style, used in project file */
68+
static QString styleName ( Style s );
69+
70+
/** Get style from name, used in project file */
71+
static Style styleFromName ( QString styleName );
72+
73+
/** Get style label, translated, used in UI */
74+
static QString styleLabel ( Style s );
75+
76+
private:
77+
QFont mFont;
78+
// Space around element
79+
QMap<Side,double> mMarginMap;
80+
};
81+
82+
#endif

‎src/core/composer/qgslegendmodel.cpp

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
QgsLegendModel::QgsLegendModel(): QStandardItemModel(), mAutoUpdate( true )
3838
{
39+
setColumnCount( 2 );
40+
3941
if ( QgsMapLayerRegistry::instance() )
4042
{
4143
connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( removeLayer( const QString& ) ) );
@@ -82,7 +84,6 @@ void QgsLegendModel::setLayerSetAndGroups( const QStringList& layerIds, const QL
8284
{
8385
return; //should never happen
8486
}
85-
//QString layerID = currentItem->data(Qt::UserRole + 2).toString();
8687
QString layerID = layerItem->layerID();
8788
if ( layerList.contains( layerID ) )
8889
{
@@ -123,14 +124,15 @@ QStandardItem* QgsLegendModel::addGroup( QString text, int position )
123124
text = tr( "Group" );
124125

125126
QgsComposerGroupItem* groupItem = new QgsComposerGroupItem( text );
127+
126128
if ( position == -1 )
127129
{
128-
invisibleRootItem()->insertRow( invisibleRootItem()->rowCount(), groupItem );
129-
}
130-
else
131-
{
132-
invisibleRootItem()->insertRow( position, groupItem );
130+
position = invisibleRootItem()->rowCount();
133131
}
132+
QList<QStandardItem *> itemsList;
133+
itemsList << groupItem << new QgsComposerStyleItem( groupItem );
134+
invisibleRootItem()->insertRow( position, itemsList );
135+
134136
emit layersChanged();
135137
return groupItem;
136138
}
@@ -377,9 +379,12 @@ void QgsLegendModel::addLayer( QgsMapLayer* theMapLayer )
377379

378380
QgsComposerLayerItem* layerItem = new QgsComposerLayerItem( theMapLayer->name() );
379381
layerItem->setLayerID( theMapLayer->id() );
382+
layerItem->setDefaultStyle();
380383
layerItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
381384

382-
invisibleRootItem()->setChild( invisibleRootItem()->rowCount(), layerItem );
385+
QList<QStandardItem *> itemsList;
386+
itemsList << layerItem << new QgsComposerStyleItem( layerItem );
387+
invisibleRootItem()->appendRow( itemsList );
383388

384389
switch ( theMapLayer->type() )
385390
{
@@ -548,7 +553,10 @@ bool QgsLegendModel::readXML( const QDomElement& legendModelElem, const QDomDocu
548553
currentItem = new QgsComposerGroupItem();
549554
}
550555
currentItem->readXML( currentElem, mHasTopLevelWindow );
551-
appendRow( currentItem );
556+
557+
QList<QStandardItem *> itemsList;
558+
itemsList << currentItem << new QgsComposerStyleItem( currentItem );
559+
appendRow( itemsList );
552560
}
553561

554562
setAutoUpdate( legendModelElem.attribute( "autoUpdate", "1" ).toInt() );
@@ -585,6 +593,29 @@ Qt::ItemFlags QgsLegendModel::flags( const QModelIndex &index ) const
585593
flags |= Qt::ItemIsDragEnabled;
586594
}
587595
}
596+
if ( index.column() == 1 && item )
597+
{
598+
// Style
599+
QStandardItem* firstColumnItem = 0;
600+
if ( item->parent() )
601+
{
602+
firstColumnItem = item->parent()->child( index.row(), 0 );
603+
}
604+
else
605+
{
606+
firstColumnItem = QgsLegendModel::item( index.row(), 0 );
607+
}
608+
cItem = dynamic_cast<QgsComposerLegendItem*>( firstColumnItem );
609+
610+
if ( cItem )
611+
{
612+
if ( cItem->itemType() == QgsComposerLegendItem::GroupItem ||
613+
cItem->itemType() == QgsComposerLegendItem::LayerItem )
614+
{
615+
flags |= Qt::ItemIsEditable;
616+
}
617+
}
618+
}
588619
return flags;
589620
}
590621

@@ -706,14 +737,18 @@ bool QgsLegendModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
706737
continue;
707738
}
708739
currentItem->readXML( currentElem );
740+
int index;
709741
if ( row < 0 )
710742
{
711-
dropIntoItem->insertRow( dropIntoItem->rowCount(), currentItem );
743+
index = dropIntoItem->rowCount();
712744
}
713745
else
714746
{
715-
dropIntoItem->insertRow( row + i, currentItem );
747+
index = row + i;
716748
}
749+
QList<QStandardItem *> itemsList;
750+
itemsList << currentItem << new QgsComposerStyleItem( currentItem );
751+
dropIntoItem->insertRow( index, itemsList );
717752
}
718753
emit layersChanged();
719754
return true;

‎src/ui/qgscomposerlegendwidgetbase.ui

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@
5454
<property name="geometry">
5555
<rect>
5656
<x>0</x>
57-
<y>-150</y>
58-
<width>376</width>
59-
<height>1186</height>
57+
<y>-118</y>
58+
<width>369</width>
59+
<height>1088</height>
6060
</rect>
6161
</property>
6262
<layout class="QVBoxLayout" name="mainLayout">
@@ -192,10 +192,13 @@
192192
<bool>false</bool>
193193
</property>
194194
<property name="headerHidden">
195-
<bool>true</bool>
195+
<bool>false</bool>
196196
</property>
197197
<attribute name="headerVisible">
198-
<bool>false</bool>
198+
<bool>true</bool>
199+
</attribute>
200+
<attribute name="headerVisible">
201+
<bool>true</bool>
199202
</attribute>
200203
</widget>
201204
</item>
@@ -377,7 +380,7 @@
377380
<item>
378381
<widget class="QPushButton" name="mLayerFontButton">
379382
<property name="text">
380-
<string>Layer Font...</string>
383+
<string>Subgroup Font...</string>
381384
</property>
382385
</widget>
383386
</item>
@@ -443,14 +446,14 @@
443446
</property>
444447
</widget>
445448
</item>
446-
<item row="4" column="0" colspan="2">
449+
<item row="3" column="0" colspan="2">
447450
<widget class="QCheckBox" name="mEqualColumnWidthCheckBox">
448451
<property name="text">
449452
<string>Equal column widths</string>
450453
</property>
451454
</widget>
452455
</item>
453-
<item row="5" column="0" colspan="2">
456+
<item row="4" column="0" colspan="2">
454457
<widget class="QCheckBox" name="mSplitLayerCheckBox">
455458
<property name="toolTip">
456459
<string>Allow to split layer items into multiple columns.</string>
@@ -460,23 +463,6 @@
460463
</property>
461464
</widget>
462465
</item>
463-
<item row="2" column="0">
464-
<widget class="QLabel" name="label_10">
465-
<property name="text">
466-
<string>Spacing</string>
467-
</property>
468-
</widget>
469-
</item>
470-
<item row="2" column="1">
471-
<widget class="QDoubleSpinBox" name="mColumnSpaceSpinBox">
472-
<property name="prefix">
473-
<string/>
474-
</property>
475-
<property name="suffix">
476-
<string> mm</string>
477-
</property>
478-
</widget>
479-
</item>
480466
</layout>
481467
</widget>
482468
</item>
@@ -561,6 +547,9 @@
561547
</property>
562548
<item row="0" column="0">
563549
<widget class="QLabel" name="label_5">
550+
<property name="toolTip">
551+
<string>Space above text using group style.</string>
552+
</property>
564553
<property name="text">
565554
<string>Group Space</string>
566555
</property>
@@ -581,8 +570,11 @@
581570
</item>
582571
<item row="1" column="0">
583572
<widget class="QLabel" name="label_6">
573+
<property name="toolTip">
574+
<string>Space above text using subgroup style.</string>
575+
</property>
584576
<property name="text">
585-
<string>Layer space</string>
577+
<string>Subgroup space</string>
586578
</property>
587579
<property name="wordWrap">
588580
<bool>true</bool>
@@ -601,6 +593,9 @@
601593
</item>
602594
<item row="2" column="0">
603595
<widget class="QLabel" name="label_7">
596+
<property name="toolTip">
597+
<string>Space above symbol and symbol label.</string>
598+
</property>
604599
<property name="text">
605600
<string>Symbol space</string>
606601
</property>
@@ -621,6 +616,9 @@
621616
</item>
622617
<item row="3" column="0">
623618
<widget class="QLabel" name="label_8">
619+
<property name="toolTip">
620+
<string>Space between symbol icon and symbol label (symbol label left margin).</string>
621+
</property>
624622
<property name="text">
625623
<string>Icon label space</string>
626624
</property>
@@ -659,6 +657,23 @@
659657
</property>
660658
</widget>
661659
</item>
660+
<item row="5" column="0">
661+
<widget class="QLabel" name="label_12">
662+
<property name="text">
663+
<string>Column space</string>
664+
</property>
665+
</widget>
666+
</item>
667+
<item row="5" column="1">
668+
<widget class="QDoubleSpinBox" name="mColumnSpaceSpinBox">
669+
<property name="prefix">
670+
<string/>
671+
</property>
672+
<property name="suffix">
673+
<string> mm</string>
674+
</property>
675+
</widget>
676+
</item>
662677
</layout>
663678
</widget>
664679
</item>

0 commit comments

Comments
 (0)
Please sign in to comment.