Skip to content

Commit b76da25

Browse files
committedJun 9, 2011
Ported single and graduated symbol renderer to use usedAttributes() functions of symbol
1 parent 066a0ea commit b76da25

File tree

5 files changed

+57
-12
lines changed

5 files changed

+57
-12
lines changed
 

‎src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,29 @@ void QgsGraduatedSymbolRendererV2::stopRender( QgsRenderContext& context )
218218

219219
QList<QString> QgsGraduatedSymbolRendererV2::usedAttributes()
220220
{
221-
QList<QString> lst;
222-
lst.append( mAttrName );
223-
if ( !mRotationField.isEmpty() )
224-
lst.append( mRotationField );
225-
if ( !mSizeScaleField.isEmpty() )
226-
lst.append( mSizeScaleField );
227-
return lst;
221+
QSet<QString> attributes;
222+
223+
QgsSymbolV2* symbol = 0;
224+
QgsRangeList::const_iterator range_it = mRanges.constBegin();
225+
for(; range_it != mRanges.constEnd(); ++range_it )
226+
{
227+
symbol = range_it->symbol();
228+
if ( symbol )
229+
{
230+
attributes.unite( symbol->usedAttributes() );
231+
}
232+
}
233+
234+
if ( !mRotationField.isEmpty() )
235+
{
236+
attributes.insert( mRotationField );
237+
}
238+
if ( !mSizeScaleField.isEmpty() )
239+
{
240+
attributes.insert( mSizeScaleField );
241+
}
242+
243+
return attributes.toList();
228244
}
229245

230246
bool QgsGraduatedSymbolRendererV2::updateRangeSymbol( int rangeIndex, QgsSymbolV2* symbol )

‎src/core/symbology-ng/qgssinglesymbolrendererv2.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,20 @@ void QgsSingleSymbolRendererV2::stopRender( QgsRenderContext& context )
122122

123123
QList<QString> QgsSingleSymbolRendererV2::usedAttributes()
124124
{
125-
QList<QString> lst;
125+
QSet<QString> attributes;
126+
if( mSymbol )
127+
{
128+
attributes.unite( mSymbol->usedAttributes() );
129+
}
126130
if ( !mRotationField.isEmpty() )
127-
lst.append( mRotationField );
131+
{
132+
attributes.insert( mRotationField );
133+
}
128134
if ( !mSizeScaleField.isEmpty() )
129-
lst.append( mSizeScaleField );
130-
return lst;
135+
{
136+
attributes.insert( mSizeScaleField );
137+
}
138+
return attributes.toList();
131139
}
132140

133141
QgsSymbolV2* QgsSingleSymbolRendererV2::symbol() const

‎src/core/symbology-ng/qgssymbollayerv2.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#ifndef QGSSYMBOLLAYERV2_H
22
#define QGSSYMBOLLAYERV2_H
33

4-
#include <QMap>
4+
55

66
#include <QColor>
7+
#include <QMap>
78
#include <QPointF>
9+
#include <QSet>
810

911
#include "qgssymbolv2.h"
1012

@@ -52,6 +54,9 @@ class CORE_EXPORT QgsSymbolLayerV2
5254
void setRenderingPass( int renderingPass ) { mRenderingPass = renderingPass; }
5355
int renderingPass() const { return mRenderingPass; }
5456

57+
// symbol layers normally only use additional attributes to provide data defined settings
58+
virtual QSet<QString> usedAttributes() const { return QSet<QString>(); }
59+
5560
protected:
5661
QgsSymbolLayerV2( QgsSymbolV2::SymbolType type, bool locked = false )
5762
: mType( type ), mLocked( locked ), mRenderingPass( 0 ) {}

‎src/core/symbology-ng/qgssymbolv2.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,20 @@ QgsSymbolLayerV2List QgsSymbolV2::cloneLayers() const
265265
return lst;
266266
}
267267

268+
QSet<QString> QgsSymbolV2::usedAttributes() const
269+
{
270+
QSet<QString> attributes;
271+
QgsSymbolLayerV2List::const_iterator sIt = mLayers.constBegin();
272+
for(; sIt != mLayers.constEnd(); ++sIt )
273+
{
274+
if( *sIt )
275+
{
276+
attributes.unite( (*sIt)->usedAttributes() );
277+
}
278+
}
279+
return attributes;
280+
}
281+
268282
////////////////////
269283

270284
QgsSymbolV2RenderContext::QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u, qreal alpha, bool selected, int renderHints, const QgsFeature* f )

‎src/core/symbology-ng/qgssymbolv2.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ class CORE_EXPORT QgsSymbolV2
9999
//! @note added in 1.5
100100
int renderHints() { return mRenderHints; }
101101

102+
QSet<QString> usedAttributes() const;
103+
102104
protected:
103105
QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers ); // can't be instantiated
104106

0 commit comments

Comments
 (0)
Please sign in to comment.