283 changes: 142 additions & 141 deletions src/core/composer/qgscomposerlegend.cpp

Large diffs are not rendered by default.

56 changes: 18 additions & 38 deletions src/core/composer/qgscomposerlegend.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef QGSCOMPOSERLEGEND_H
#define QGSCOMPOSERLEGEND_H

#include "qgscomposerlegendstyle.h"
#include "qgscomposeritem.h"
#include "qgscomposerlegenditem.h"
#include "qgslegendmodel.h"
Expand All @@ -33,10 +34,9 @@ class QgsComposerMap;
*/
class CORE_EXPORT QgsComposerLegend : public QgsComposerItem
{
Q_OBJECT
Q_OBJECT;

public:

QgsComposerLegend( QgsComposition* composition );
~QgsComposerLegend();

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

QFont titleFont() const;
void setTitleFont( const QFont& f );

QFont groupFont() const;
void setGroupFont( const QFont& f );

QFont layerFont() const;
void setLayerFont( const QFont& f );
/** Returns reference to modifiable style */
QgsComposerLegendStyle & rstyle( QgsComposerLegendStyle::Style s ) { return mStyleMap[s]; }
/** Returns style */
QgsComposerLegendStyle style( QgsComposerLegendStyle::Style s ) const { return mStyleMap.value( s ); }
void setStyle( QgsComposerLegendStyle::Style s, const QgsComposerLegendStyle style ) { mStyleMap[s] = style; }

QFont itemFont() const;
void setItemFont( const QFont& f );
QFont styleFont( QgsComposerLegendStyle::Style s ) const { return style( s ).font(); }
/** Set style font */
void setStyleFont( QgsComposerLegendStyle::Style s, const QFont& f );

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

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

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

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

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

double symbolSpace() const {return mSymbolSpace;}
void setSymbolSpace( double s ) {mSymbolSpace = s;}

double iconLabelSpace() const {return mIconLabelSpace;}
void setIconLabelSpace( double s ) {mIconLabelSpace = s;}
QColor fontColor() const {return mFontColor;}
void setFontColor( const QColor& c ) {mFontColor = c;}

double symbolWidth() const {return mSymbolWidth;}
void setSymbolWidth( double w ) {mSymbolWidth = w;}
Expand Down Expand Up @@ -139,25 +129,13 @@ class CORE_EXPORT QgsComposerLegend : public QgsComposerItem
QString mTitle;
QString mWrapChar;

//different fonts for entries
QFont mTitleFont;
QFont mGroupFont;
QFont mLayerFont;
QFont mItemFont;
QColor mFontColor;

/**Space between item box and contents*/
qreal mBoxSpace;
/**Space between columns*/
double mColumnSpace;
/**Vertical space between group entries*/
double mGroupSpace;
/**Vertical space between layer entries*/
double mLayerSpace;
/**Vertical space between symbol entries*/
double mSymbolSpace;
/**Horizontal space between item icon and label*/
double mIconLabelSpace;

/**Width of symbol icon*/
double mSymbolWidth;
/**Height of symbol icon*/
Expand Down Expand Up @@ -257,6 +235,8 @@ class CORE_EXPORT QgsComposerLegend : public QgsComposerItem
/** Splits a string using the wrap char taking into account handling empty
wrap char which means no wrapping */
QStringList splitStringForWrapping( QString stringToSplt );

QMap<QgsComposerLegendStyle::Style, QgsComposerLegendStyle> mStyleMap;
};

#endif
84 changes: 67 additions & 17 deletions src/core/composer/qgscomposerlegenditem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
* *
***************************************************************************/

#include "qgscomposerlegendstyle.h"
#include "qgscomposerlegenditem.h"
#include "qgscomposerlegend.h"
#include "qgsmaplayerregistry.h"
#include "qgsrasterlayer.h"
#include "qgsrenderer.h"
#include "qgsrendererv2.h"
#include "qgssymbol.h"
#include "qgssymbolv2.h"
#include "qgssymbollayerv2utils.h"
Expand All @@ -26,15 +30,18 @@
#include <QDomDocument>
#include <QDomElement>

QgsComposerLegendItem::QgsComposerLegendItem(): QStandardItem()
QgsComposerLegendItem::QgsComposerLegendItem( QgsComposerLegendStyle::Style s ): QStandardItem()
, mStyle( s )
{
}

QgsComposerLegendItem::QgsComposerLegendItem( const QString& text ): QStandardItem( text )
QgsComposerLegendItem::QgsComposerLegendItem( const QString& text, QgsComposerLegendStyle::Style s ): QStandardItem( text )
, mStyle( s )
{
}

QgsComposerLegendItem::QgsComposerLegendItem( const QIcon& icon, const QString& text ): QStandardItem( icon, text )
QgsComposerLegendItem::QgsComposerLegendItem( const QIcon& icon, const QString& text, QgsComposerLegendStyle::Style s ): QStandardItem( icon, text )
, mStyle( s )
{
}

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

//////////////////////////////QgsComposerSymbolItem

QgsComposerSymbolItem::QgsComposerSymbolItem(): QgsComposerLegendItem(), mSymbol( 0 )
QgsComposerSymbolItem::QgsComposerSymbolItem(): QgsComposerLegendItem( QgsComposerLegendStyle::Symbol ), mSymbol( 0 )
{
}

QgsComposerSymbolItem::QgsComposerSymbolItem( const QString& text ): QgsComposerLegendItem( text ), mSymbol( 0 )
QgsComposerSymbolItem::QgsComposerSymbolItem( const QString& text ): QgsComposerLegendItem( text, QgsComposerLegendStyle::Symbol ), mSymbol( 0 )
{
}

QgsComposerSymbolItem::QgsComposerSymbolItem( const QIcon& icon, const QString& text ): QgsComposerLegendItem( icon, text ), mSymbol( 0 )
QgsComposerSymbolItem::QgsComposerSymbolItem( const QIcon& icon, const QString& text ): QgsComposerLegendItem( icon, text, QgsComposerLegendStyle::Symbol ), mSymbol( 0 )
{
}

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

#include "qgssymbolv2.h"

QgsComposerSymbolV2Item::QgsComposerSymbolV2Item(): QgsComposerLegendItem(), mSymbolV2( 0 )
QgsComposerSymbolV2Item::QgsComposerSymbolV2Item(): QgsComposerLegendItem( QgsComposerLegendStyle::Symbol ), mSymbolV2( 0 )
{
}

QgsComposerSymbolV2Item::QgsComposerSymbolV2Item( const QString& text ): QgsComposerLegendItem( text ), mSymbolV2( 0 )
QgsComposerSymbolV2Item::QgsComposerSymbolV2Item( const QString& text ): QgsComposerLegendItem( text, QgsComposerLegendStyle::Symbol ), mSymbolV2( 0 )
{
}

QgsComposerSymbolV2Item::QgsComposerSymbolV2Item( const QIcon& icon, const QString& text ): QgsComposerLegendItem( icon, text ), mSymbolV2( 0 )
QgsComposerSymbolV2Item::QgsComposerSymbolV2Item( const QIcon& icon, const QString& text ): QgsComposerLegendItem( icon, text, QgsComposerLegendStyle::Symbol ), mSymbolV2( 0 )
{
}

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

////////////////////QgsComposerRasterSymbolItem

QgsComposerRasterSymbolItem::QgsComposerRasterSymbolItem(): QgsComposerLegendItem()
QgsComposerRasterSymbolItem::QgsComposerRasterSymbolItem(): QgsComposerLegendItem( QgsComposerLegendStyle::Symbol )
{
}

QgsComposerRasterSymbolItem::QgsComposerRasterSymbolItem( const QString& text ): QgsComposerLegendItem( text )
QgsComposerRasterSymbolItem::QgsComposerRasterSymbolItem( const QString& text ): QgsComposerLegendItem( text, QgsComposerLegendStyle::Symbol )
{
}

QgsComposerRasterSymbolItem::QgsComposerRasterSymbolItem( const QIcon& icon, const QString& text ): QgsComposerLegendItem( icon, text )
QgsComposerRasterSymbolItem::QgsComposerRasterSymbolItem( const QIcon& icon, const QString& text ): QgsComposerLegendItem( icon, text, QgsComposerLegendStyle::Symbol )
{
}

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

////////////////////QgsComposerLayerItem

QgsComposerLayerItem::QgsComposerLayerItem(): QgsComposerLegendItem()
QgsComposerLayerItem::QgsComposerLayerItem(): QgsComposerLegendItem( QgsComposerLegendStyle::Subgroup )
, mShowFeatureCount( false )
{
}

QgsComposerLayerItem::QgsComposerLayerItem( const QString& text ): QgsComposerLegendItem( text )
QgsComposerLayerItem::QgsComposerLayerItem( const QString& text ): QgsComposerLegendItem( text, QgsComposerLegendStyle::Subgroup )
, mShowFeatureCount( false )
{
}
Expand All @@ -315,6 +322,7 @@ void QgsComposerLayerItem::writeXML( QDomElement& elem, QDomDocument& doc ) cons
layerItemElem.setAttribute( "layerId", mLayerID );
layerItemElem.setAttribute( "text", text() );
layerItemElem.setAttribute( "showFeatureCount", showFeatureCount() );
layerItemElem.setAttribute( "style", QgsComposerLegendStyle::styleName( mStyle ) );
writeXMLChildren( layerItemElem, doc );
elem.appendChild( layerItemElem );
}
Expand All @@ -328,6 +336,7 @@ void QgsComposerLayerItem::readXML( const QDomElement& itemElem, bool xServerAva
setText( itemElem.attribute( "text", "" ) );
setLayerID( itemElem.attribute( "layerId", "" ) );
setShowFeatureCount( itemElem.attribute( "showFeatureCount", "" ) == "1" ? true : false );
setStyle( QgsComposerLegendStyle::styleFromName( itemElem.attribute( "style", "subgroup" ) ) );

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

void QgsComposerLayerItem::setDefaultStyle()
{
// set default style according to number of symbols
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( layerID() ) );
if ( vLayer )
{
QgsFeatureRendererV2* renderer = vLayer->rendererV2();
if ( renderer )
{
if ( renderer->legendSymbolItems().size() > 1 )
{
setStyle( QgsComposerLegendStyle::Subgroup );
}
else
{
// Hide title by default for single symbol
setStyle( QgsComposerLegendStyle::Hidden );
}
}
}
}

////////////////////QgsComposerGroupItem

QgsComposerGroupItem::QgsComposerGroupItem(): QgsComposerLegendItem()
QgsComposerGroupItem::QgsComposerGroupItem(): QgsComposerLegendItem( QgsComposerLegendStyle::Group )
{
}

QgsComposerGroupItem::QgsComposerGroupItem( const QString& text ): QgsComposerLegendItem( text )
QgsComposerGroupItem::QgsComposerGroupItem( const QString& text ): QgsComposerLegendItem( text, QgsComposerLegendStyle::Group )
{
}

Expand All @@ -392,6 +423,7 @@ void QgsComposerGroupItem::writeXML( QDomElement& elem, QDomDocument& doc ) cons
{
QDomElement layerGroupElem = doc.createElement( "GroupItem" );
layerGroupElem.setAttribute( "text", text() );
layerGroupElem.setAttribute( "style", QgsComposerLegendStyle::styleName( mStyle ) );
writeXMLChildren( layerGroupElem, doc );
elem.appendChild( layerGroupElem );
}
Expand All @@ -404,6 +436,8 @@ void QgsComposerGroupItem::readXML( const QDomElement& itemElem, bool xServerAva
}
setText( itemElem.attribute( "text", "" ) );

setStyle( QgsComposerLegendStyle::styleFromName( itemElem.attribute( "style", "group" ) ) );

//now call readXML for all the child items
QDomNodeList childList = itemElem.childNodes();
QDomNode currentNode;
Expand Down Expand Up @@ -435,6 +469,22 @@ void QgsComposerGroupItem::readXML( const QDomElement& itemElem, bool xServerAva
continue; //unsupported child item type
}
currentChildItem->readXML( currentElem, xServerAvailable );
appendRow( currentChildItem );

QList<QStandardItem *> itemsList;
itemsList << currentChildItem << new QgsComposerStyleItem( currentChildItem );
appendRow( itemsList );
}
}

QgsComposerStyleItem::QgsComposerStyleItem(): QStandardItem()
{
}

QgsComposerStyleItem::QgsComposerStyleItem( QgsComposerLegendItem *item ): QStandardItem()
{
setData( QgsComposerLegendStyle::styleLabel( item->style() ) , Qt::DisplayRole );
}

QgsComposerStyleItem::~QgsComposerStyleItem()
{
}
25 changes: 21 additions & 4 deletions src/core/composer/qgscomposerlegenditem.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef QGSCOMPOSERLEGENDITEM_H
#define QGSCOMPOSERLEGENDITEM_H

#include "qgscomposerlegendstyle.h"
#include <QStandardItem>
class QDomDocument;
class QDomElement;
Expand All @@ -26,9 +27,9 @@ class QDomElement;
class CORE_EXPORT QgsComposerLegendItem: public QStandardItem
{
public:
QgsComposerLegendItem();
QgsComposerLegendItem( const QString& text );
QgsComposerLegendItem( const QIcon& icon, const QString& text );
QgsComposerLegendItem( QgsComposerLegendStyle::Style s = QgsComposerLegendStyle::Undefined );
QgsComposerLegendItem( const QString& text, QgsComposerLegendStyle::Style s = QgsComposerLegendStyle::Undefined );
QgsComposerLegendItem( const QIcon& icon, const QString& text, QgsComposerLegendStyle::Style s = QgsComposerLegendStyle::Undefined );
virtual ~QgsComposerLegendItem();

enum ItemType
Expand All @@ -37,7 +38,8 @@ class CORE_EXPORT QgsComposerLegendItem: public QStandardItem
LayerItem,
SymbologyItem,
SymbologyV2Item,
RasterSymbolItem
RasterSymbolItem,
StyleItem
};

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

QgsComposerLegendStyle::Style style() const { return mStyle; }
void setStyle( QgsComposerLegendStyle::Style style ) { mStyle = style; }

protected:
void writeXMLChildren( QDomElement& elem, QDomDocument& doc ) const;

QgsComposerLegendStyle::Style mStyle;
};

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

void setDefaultStyle();

private:
QString mLayerID;
// Show vector feature counts
Expand All @@ -171,4 +180,12 @@ class CORE_EXPORT QgsComposerGroupItem: public QgsComposerLegendItem
ItemType itemType() const { return GroupItem; }
};

class CORE_EXPORT QgsComposerStyleItem: public QStandardItem
{
public:
QgsComposerStyleItem( );
QgsComposerStyleItem( QgsComposerLegendItem *item );
~QgsComposerStyleItem();
};

#endif // QGSCOMPOSERLEGENDITEM_H
126 changes: 126 additions & 0 deletions src/core/composer/qgscomposerlegendstyle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/***************************************************************************
qgscomposerlegendstyle.cpp
---------------------
begin : March 2013
copyright : (C) 2013 by Radim Blazek
email : radim.blazek@gmail.com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgscomposerlegendstyle.h"
#include <QFont>
#include <QMap>
#include <QString>
#include <QDomElement>
#include <QDomDocument>
#include <QDomNode>

QgsComposerLegendStyle::QgsComposerLegendStyle()
{
}

QgsComposerLegendStyle::~QgsComposerLegendStyle()
{
}

void QgsComposerLegendStyle::setMargin( double margin )
{
mMarginMap[Top] = margin;
mMarginMap[Bottom] = margin;
mMarginMap[Left] = margin;
mMarginMap[Right] = margin;
}

void QgsComposerLegendStyle::writeXML( QString name, QDomElement& elem, QDomDocument & doc ) const
{
if ( elem.isNull() ) return;

QDomElement styleElem = doc.createElement( "style" );

styleElem.setAttribute( "name", name );

styleElem.setAttribute( "marginTop", QString::number( mMarginMap[Top] ) );
styleElem.setAttribute( "marginBottom", QString::number( mMarginMap[Bottom] ) );
styleElem.setAttribute( "marginLeft", QString::number( mMarginMap[Left] ) );
styleElem.setAttribute( "marginRight", QString::number( mMarginMap[Right] ) );

styleElem.setAttribute( "font", mFont.toString() );

elem.appendChild( styleElem );
}

void QgsComposerLegendStyle::readXML( const QDomElement& elem, const QDomDocument& doc )
{
Q_UNUSED( doc );
if ( elem.isNull() ) return;

mFont.fromString( elem.attribute( "font" ) );

mMarginMap[Top] = elem.attribute( "marginTop" ).toDouble();
mMarginMap[Bottom] = elem.attribute( "marginBottom" ).toDouble();
mMarginMap[Left] = elem.attribute( "marginLeft" ).toDouble();
mMarginMap[Right] = elem.attribute( "marginRight" ).toDouble();
}

QString QgsComposerLegendStyle::styleName ( Style s )
{
switch ( s )
{
case Undefined:
return "";
case Hidden:
return "hidden";
case Title:
return "title";
case Group:
return "group";
case Subgroup:
return "subgroup";
case Symbol:
return "symbol";
case SymbolLabel:
return "symbolLabel";
}
return "";
}

QgsComposerLegendStyle::Style QgsComposerLegendStyle::styleFromName ( QString styleName )
{
if ( styleName == "hidden" ) return Hidden;
else if ( styleName == "title" ) return Title;
else if ( styleName == "group" ) return Group;
else if ( styleName == "subgroup" ) return Subgroup;
else if ( styleName == "symbol" ) return Symbol;
else if ( styleName == "symbolLabel" ) return SymbolLabel;
return Undefined;
}

QString QgsComposerLegendStyle::styleLabel ( Style s )
{
switch ( s )
{
case Undefined:
return QObject::tr("Undefined");
case Hidden:
return QObject::tr("Hidden");
case Title:
return QObject::tr("Title");
case Group:
return QObject::tr("Group");
case Subgroup:
return QObject::tr("Subgroup");
case Symbol:
return QObject::tr("Symbol");
case SymbolLabel:
return QObject::tr("Symbol label");
}
return "";
}
82 changes: 82 additions & 0 deletions src/core/composer/qgscomposerlegendstyle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/***************************************************************************
qgscomposerlegendstyle.h
-------------------
begin : March 2013
copyright : (C) 2013 by Radim Blazek
email : radim.blazek@gmail.com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSCOMPOSERLEGENDSTYLE_H
#define QGSCOMPOSERLEGENDSTYLE_H

#include <QFont>
#include <QMap>
#include <QString>
#include <QDomElement>
#include <QDomDocument>

/** \ingroup MapComposer
* Composer legend components style
*/
class CORE_EXPORT QgsComposerLegendStyle
{
public:
enum Style
{
Undefined, // should not happen, only if corrupted project file
Hidden, // special style, item is hidden includeing margins around
Title,
Group,
Subgroup, // layer
Symbol, // symbol without label
SymbolLabel
};
enum Side // margin side
{
Top = 0,
Bottom = 1,
Left = 2,
Right = 3
};
QgsComposerLegendStyle();
~QgsComposerLegendStyle();

QFont font() const { return mFont; }
QFont & rfont() { return mFont; }
void setFont( const QFont & font ) { mFont = font; }

double margin( Side side ) { return mMarginMap.value( side ); }
void setMargin( Side side, double margin ) { mMarginMap[side] = margin; }

// set all margins
void setMargin( double margin );

void writeXML( QString name, QDomElement& elem, QDomDocument & doc ) const;

void readXML( const QDomElement& elem, const QDomDocument& doc );

/** Get name for style, used in project file */
static QString styleName ( Style s );

/** Get style from name, used in project file */
static Style styleFromName ( QString styleName );

/** Get style label, translated, used in UI */
static QString styleLabel ( Style s );

private:
QFont mFont;
// Space around element
QMap<Side,double> mMarginMap;
};

#endif
55 changes: 45 additions & 10 deletions src/core/composer/qgslegendmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

QgsLegendModel::QgsLegendModel(): QStandardItemModel(), mAutoUpdate( true )
{
setColumnCount( 2 );

if ( QgsMapLayerRegistry::instance() )
{
connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( removeLayer( const QString& ) ) );
Expand Down Expand Up @@ -82,7 +84,6 @@ void QgsLegendModel::setLayerSetAndGroups( const QStringList& layerIds, const QL
{
return; //should never happen
}
//QString layerID = currentItem->data(Qt::UserRole + 2).toString();
QString layerID = layerItem->layerID();
if ( layerList.contains( layerID ) )
{
Expand Down Expand Up @@ -123,14 +124,15 @@ QStandardItem* QgsLegendModel::addGroup( QString text, int position )
text = tr( "Group" );

QgsComposerGroupItem* groupItem = new QgsComposerGroupItem( text );

if ( position == -1 )
{
invisibleRootItem()->insertRow( invisibleRootItem()->rowCount(), groupItem );
}
else
{
invisibleRootItem()->insertRow( position, groupItem );
position = invisibleRootItem()->rowCount();
}
QList<QStandardItem *> itemsList;
itemsList << groupItem << new QgsComposerStyleItem( groupItem );
invisibleRootItem()->insertRow( position, itemsList );

emit layersChanged();
return groupItem;
}
Expand Down Expand Up @@ -377,9 +379,12 @@ void QgsLegendModel::addLayer( QgsMapLayer* theMapLayer )

QgsComposerLayerItem* layerItem = new QgsComposerLayerItem( theMapLayer->name() );
layerItem->setLayerID( theMapLayer->id() );
layerItem->setDefaultStyle();
layerItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );

invisibleRootItem()->setChild( invisibleRootItem()->rowCount(), layerItem );
QList<QStandardItem *> itemsList;
itemsList << layerItem << new QgsComposerStyleItem( layerItem );
invisibleRootItem()->appendRow( itemsList );

switch ( theMapLayer->type() )
{
Expand Down Expand Up @@ -548,7 +553,10 @@ bool QgsLegendModel::readXML( const QDomElement& legendModelElem, const QDomDocu
currentItem = new QgsComposerGroupItem();
}
currentItem->readXML( currentElem, mHasTopLevelWindow );
appendRow( currentItem );

QList<QStandardItem *> itemsList;
itemsList << currentItem << new QgsComposerStyleItem( currentItem );
appendRow( itemsList );
}

setAutoUpdate( legendModelElem.attribute( "autoUpdate", "1" ).toInt() );
Expand Down Expand Up @@ -585,6 +593,29 @@ Qt::ItemFlags QgsLegendModel::flags( const QModelIndex &index ) const
flags |= Qt::ItemIsDragEnabled;
}
}
if ( index.column() == 1 && item )
{
// Style
QStandardItem* firstColumnItem = 0;
if ( item->parent() )
{
firstColumnItem = item->parent()->child( index.row(), 0 );
}
else
{
firstColumnItem = QgsLegendModel::item( index.row(), 0 );
}
cItem = dynamic_cast<QgsComposerLegendItem*>( firstColumnItem );

if ( cItem )
{
if ( cItem->itemType() == QgsComposerLegendItem::GroupItem ||
cItem->itemType() == QgsComposerLegendItem::LayerItem )
{
flags |= Qt::ItemIsEditable;
}
}
}
return flags;
}

Expand Down Expand Up @@ -706,14 +737,18 @@ bool QgsLegendModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
continue;
}
currentItem->readXML( currentElem );
int index;
if ( row < 0 )
{
dropIntoItem->insertRow( dropIntoItem->rowCount(), currentItem );
index = dropIntoItem->rowCount();
}
else
{
dropIntoItem->insertRow( row + i, currentItem );
index = row + i;
}
QList<QStandardItem *> itemsList;
itemsList << currentItem << new QgsComposerStyleItem( currentItem );
dropIntoItem->insertRow( index, itemsList );
}
emit layersChanged();
return true;
Expand Down
67 changes: 41 additions & 26 deletions src/ui/qgscomposerlegendwidgetbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-150</y>
<width>376</width>
<height>1186</height>
<y>-118</y>
<width>369</width>
<height>1088</height>
</rect>
</property>
<layout class="QVBoxLayout" name="mainLayout">
Expand Down Expand Up @@ -192,10 +192,13 @@
<bool>false</bool>
</property>
<property name="headerHidden">
<bool>true</bool>
<bool>false</bool>
</property>
<attribute name="headerVisible">
<bool>false</bool>
<bool>true</bool>
</attribute>
<attribute name="headerVisible">
<bool>true</bool>
</attribute>
</widget>
</item>
Expand Down Expand Up @@ -377,7 +380,7 @@
<item>
<widget class="QPushButton" name="mLayerFontButton">
<property name="text">
<string>Layer Font...</string>
<string>Subgroup Font...</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -443,14 +446,14 @@
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="mEqualColumnWidthCheckBox">
<property name="text">
<string>Equal column widths</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="mSplitLayerCheckBox">
<property name="toolTip">
<string>Allow to split layer items into multiple columns.</string>
Expand All @@ -460,23 +463,6 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Spacing</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="mColumnSpaceSpinBox">
<property name="prefix">
<string/>
</property>
<property name="suffix">
<string> mm</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -561,6 +547,9 @@
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="toolTip">
<string>Space above text using group style.</string>
</property>
<property name="text">
<string>Group Space</string>
</property>
Expand All @@ -581,8 +570,11 @@
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<property name="toolTip">
<string>Space above text using subgroup style.</string>
</property>
<property name="text">
<string>Layer space</string>
<string>Subgroup space</string>
</property>
<property name="wordWrap">
<bool>true</bool>
Expand All @@ -601,6 +593,9 @@
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_7">
<property name="toolTip">
<string>Space above symbol and symbol label.</string>
</property>
<property name="text">
<string>Symbol space</string>
</property>
Expand All @@ -621,6 +616,9 @@
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_8">
<property name="toolTip">
<string>Space between symbol icon and symbol label (symbol label left margin).</string>
</property>
<property name="text">
<string>Icon label space</string>
</property>
Expand Down Expand Up @@ -659,6 +657,23 @@
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Column space</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QDoubleSpinBox" name="mColumnSpaceSpinBox">
<property name="prefix">
<string/>
</property>
<property name="suffix">
<string> mm</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down