Skip to content
Permalink
Browse files

Fix legend text not customisable for QgsSimpleLegendNode items

cherry-picked from 4a9a936
  • Loading branch information
nyalldawson committed May 4, 2015
1 parent 86d447b commit 7c6f01d1af0c97adab8426215c28657d2c8f3f19
@@ -148,7 +148,7 @@ class QgsSimpleLegendNode : QgsLayerTreeModelLegendNode
#include <qgslayertreemodellegendnode.h>
%End
public:
QgsSimpleLegendNode( QgsLayerTreeLayer* nodeLayer, const QString& label, const QIcon& icon = QIcon(), QObject* parent /TransferThis/ = 0 );
QgsSimpleLegendNode( QgsLayerTreeLayer* nodeLayer, const QString& label, const QIcon& icon = QIcon(), QObject* parent /TransferThis/ = 0, const QString& key = QString() );

virtual QVariant data( int role ) const;
};
@@ -392,19 +392,22 @@ void QgsSymbolV2LegendNode::updateLabel()
// -------------------------------------------------------------------------


QgsSimpleLegendNode::QgsSimpleLegendNode( QgsLayerTreeLayer* nodeLayer, const QString& label, const QIcon& icon, QObject* parent )
QgsSimpleLegendNode::QgsSimpleLegendNode( QgsLayerTreeLayer* nodeLayer, const QString& label, const QIcon& icon, QObject* parent, const QString& key )
: QgsLayerTreeModelLegendNode( nodeLayer, parent )
, mLabel( label )
, mIcon( icon )
, mKey( key )
{
}

QVariant QgsSimpleLegendNode::data( int role ) const
{
if ( role == Qt::DisplayRole || role == Qt::EditRole )
return mLabel;
return mUserLabel.isEmpty() ? mLabel : mUserLabel;
else if ( role == Qt::DecorationRole )
return mIcon;
else if ( role == RuleKeyRole && !mKey.isEmpty() )
return mKey;
else
return QVariant();
}
@@ -181,14 +181,15 @@ class CORE_EXPORT QgsSymbolV2LegendNode : public QgsLayerTreeModelLegendNode
class CORE_EXPORT QgsSimpleLegendNode : public QgsLayerTreeModelLegendNode
{
public:
QgsSimpleLegendNode( QgsLayerTreeLayer* nodeLayer, const QString& label, const QIcon& icon = QIcon(), QObject* parent = 0 );
QgsSimpleLegendNode( QgsLayerTreeLayer* nodeLayer, const QString& label, const QIcon& icon = QIcon(), QObject* parent = 0, const QString& key = QString() );

virtual QVariant data( int role ) const override;

private:
QString mLabel;
QString mId;
QIcon mIcon;
QString mKey;
};


0 comments on commit 7c6f01d

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