Skip to content
Permalink
Browse files

Scale range supported by symbol in QgsLegendSymbolItemV2

  • Loading branch information
wonder-sk committed Sep 1, 2014
1 parent 4fa1f45 commit 54946a44e2ee0ab44df517f39b861438edec52cd
@@ -185,11 +185,10 @@ QList<QgsLayerTreeModelLegendNode*> QgsDefaultVectorLayerLegend::createLayerTree

nodeLayer->setChildrenCheckable( r->legendSymbolItemsCheckable() );

typedef QPair<QString, QgsSymbolV2*> QgsLegendSymbolItem;
int k = 0;
foreach ( const QgsLegendSymbolItem& i, r->legendSymbolItems() )
foreach ( const QgsLegendSymbolItemV2& i, r->legendSymbolItemsV2() )
{
nodes.append( new QgsSymbolV2LegendNode( nodeLayer, i.second, i.first, k++ ) );
nodes.append( new QgsSymbolV2LegendNode( nodeLayer, i.symbol, i.label, k++ ) );
}
return nodes;
}
@@ -5,21 +5,34 @@
QgsLegendSymbolItemV2::QgsLegendSymbolItemV2()
: symbol( 0 )
, index( -1 )
, scaleDenomMin( -1 )
, scaleDenomMax( -1 )
{
}

QgsLegendSymbolItemV2::~QgsLegendSymbolItemV2()
QgsLegendSymbolItemV2::QgsLegendSymbolItemV2( QgsSymbolV2* s, const QString& lbl, int idx )
: symbol( s )
, label( lbl )
, index( idx )
, scaleDenomMin( -1 )
, scaleDenomMax( -1 )
{
delete symbol;
}

QgsLegendSymbolItemV2::QgsLegendSymbolItemV2( const QgsLegendSymbolItemV2& other )
: symbol( 0 )
, index( -1 )
, scaleDenomMin( -1 )
, scaleDenomMax( -1 )
{
*this = other;
}

QgsLegendSymbolItemV2::~QgsLegendSymbolItemV2()
{
delete symbol;
}

QgsLegendSymbolItemV2& QgsLegendSymbolItemV2::operator=( const QgsLegendSymbolItemV2& other )
{
if ( this == &other )
@@ -29,6 +42,8 @@ QgsLegendSymbolItemV2& QgsLegendSymbolItemV2::operator=( const QgsLegendSymbolIt
symbol = other.symbol ? other.symbol->clone() : 0;
label = other.label;
index = other.index;
scaleDenomMin = other.scaleDenomMin;
scaleDenomMax = other.scaleDenomMax;

return *this;
}
@@ -9,14 +9,21 @@ class QgsLegendSymbolItemV2
{
public:
QgsLegendSymbolItemV2();
//! construct item, takes ownership of symbol
QgsLegendSymbolItemV2( QgsSymbolV2* s, const QString& lbl, int idx );
~QgsLegendSymbolItemV2();
QgsLegendSymbolItemV2( const QgsLegendSymbolItemV2& other );
QgsLegendSymbolItemV2& operator=( const QgsLegendSymbolItemV2& other );

QgsSymbolV2* symbol; //!< owned by the struct
QString label;
int index; //!< identifier of the symbol item (within renderer)
// TODO: scale range, rule

// additional data that may be used for filtering

int scaleDenomMin;
int scaleDenomMax;
// TODO: QString rule;
};


@@ -366,3 +366,10 @@ QgsLegendSymbolList QgsSingleSymbolRendererV2::legendSymbolItems( double scaleDe
lst << qMakePair( QString(), mSymbol.data() );
return lst;
}

QgsLegendSymbolListV2 QgsSingleSymbolRendererV2::legendSymbolItemsV2() const
{
QgsLegendSymbolListV2 lst;
lst << QgsLegendSymbolItemV2( mSymbol.data() ? mSymbol->clone() : 0, QString(), 0 );
return lst;
}
@@ -82,6 +82,10 @@ class CORE_EXPORT QgsSingleSymbolRendererV2 : public QgsFeatureRendererV2
//! @note not available in python bindings
virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, QString rule = QString() );

//! Return a list of symbology items for the legend. Better choice than legendSymbolItems().
//! @node added in 2.6
virtual QgsLegendSymbolListV2 legendSymbolItemsV2() const;

protected:
QScopedPointer<QgsSymbolV2> mSymbol;
QScopedPointer<QgsExpression> mRotation;

0 comments on commit 54946a4

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