Skip to content

Commit

Permalink
Ported single and graduated symbol renderer to use usedAttributes() f…
Browse files Browse the repository at this point in the history
…unctions of symbol
  • Loading branch information
mhugent committed Jun 9, 2011
1 parent 066a0ea commit b76da25
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 12 deletions.
30 changes: 23 additions & 7 deletions src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp
Expand Up @@ -218,13 +218,29 @@ void QgsGraduatedSymbolRendererV2::stopRender( QgsRenderContext& context )

QList<QString> QgsGraduatedSymbolRendererV2::usedAttributes()
{
QList<QString> lst;
lst.append( mAttrName );
if ( !mRotationField.isEmpty() )
lst.append( mRotationField );
if ( !mSizeScaleField.isEmpty() )
lst.append( mSizeScaleField );
return lst;
QSet<QString> attributes;

QgsSymbolV2* symbol = 0;
QgsRangeList::const_iterator range_it = mRanges.constBegin();
for(; range_it != mRanges.constEnd(); ++range_it )
{
symbol = range_it->symbol();
if ( symbol )
{
attributes.unite( symbol->usedAttributes() );
}
}

if ( !mRotationField.isEmpty() )
{
attributes.insert( mRotationField );
}
if ( !mSizeScaleField.isEmpty() )
{
attributes.insert( mSizeScaleField );
}

return attributes.toList();
}

bool QgsGraduatedSymbolRendererV2::updateRangeSymbol( int rangeIndex, QgsSymbolV2* symbol )
Expand Down
16 changes: 12 additions & 4 deletions src/core/symbology-ng/qgssinglesymbolrendererv2.cpp
Expand Up @@ -122,12 +122,20 @@ void QgsSingleSymbolRendererV2::stopRender( QgsRenderContext& context )

QList<QString> QgsSingleSymbolRendererV2::usedAttributes()
{
QList<QString> lst;
QSet<QString> attributes;
if( mSymbol )
{
attributes.unite( mSymbol->usedAttributes() );
}
if ( !mRotationField.isEmpty() )
lst.append( mRotationField );
{
attributes.insert( mRotationField );
}
if ( !mSizeScaleField.isEmpty() )
lst.append( mSizeScaleField );
return lst;
{
attributes.insert( mSizeScaleField );
}
return attributes.toList();
}

QgsSymbolV2* QgsSingleSymbolRendererV2::symbol() const
Expand Down
7 changes: 6 additions & 1 deletion src/core/symbology-ng/qgssymbollayerv2.h
@@ -1,10 +1,12 @@
#ifndef QGSSYMBOLLAYERV2_H
#define QGSSYMBOLLAYERV2_H

#include <QMap>


#include <QColor>
#include <QMap>
#include <QPointF>
#include <QSet>

#include "qgssymbolv2.h"

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

// symbol layers normally only use additional attributes to provide data defined settings
virtual QSet<QString> usedAttributes() const { return QSet<QString>(); }

protected:
QgsSymbolLayerV2( QgsSymbolV2::SymbolType type, bool locked = false )
: mType( type ), mLocked( locked ), mRenderingPass( 0 ) {}
Expand Down
14 changes: 14 additions & 0 deletions src/core/symbology-ng/qgssymbolv2.cpp
Expand Up @@ -265,6 +265,20 @@ QgsSymbolLayerV2List QgsSymbolV2::cloneLayers() const
return lst;
}

QSet<QString> QgsSymbolV2::usedAttributes() const
{
QSet<QString> attributes;
QgsSymbolLayerV2List::const_iterator sIt = mLayers.constBegin();
for(; sIt != mLayers.constEnd(); ++sIt )
{
if( *sIt )
{
attributes.unite( (*sIt)->usedAttributes() );
}
}
return attributes;
}

////////////////////

QgsSymbolV2RenderContext::QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u, qreal alpha, bool selected, int renderHints, const QgsFeature* f )
Expand Down
2 changes: 2 additions & 0 deletions src/core/symbology-ng/qgssymbolv2.h
Expand Up @@ -99,6 +99,8 @@ class CORE_EXPORT QgsSymbolV2
//! @note added in 1.5
int renderHints() { return mRenderHints; }

QSet<QString> usedAttributes() const;

protected:
QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers ); // can't be instantiated

Expand Down

0 comments on commit b76da25

Please sign in to comment.