Skip to content

Commit

Permalink
Scale range supported by symbol in QgsLegendSymbolItemV2
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Sep 1, 2014
1 parent 4fa1f45 commit 54946a4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/core/qgsmaplayerlegend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
19 changes: 17 additions & 2 deletions src/core/symbology-ng/qgslegendsymbolitemv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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 changes: 8 additions & 1 deletion src/core/symbology-ng/qgslegendsymbolitemv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};


Expand Down
7 changes: 7 additions & 0 deletions src/core/symbology-ng/qgssinglesymbolrendererv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 4 additions & 0 deletions src/core/symbology-ng/qgssinglesymbolrendererv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 54946a4

Please sign in to comment.