Skip to content
Permalink
Browse files

use QgsVectorLayer::fieldNameIndex() in symbology-ng and add python b…

…inding

git-svn-id: http://svn.osgeo.org/qgis/trunk@12346 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Dec 6, 2009
1 parent 1d5e0ed commit ffd1c32295872714f12f40d14696db473c2820f2
@@ -333,7 +333,7 @@ void QgsVectorLayer::drawLabels( QgsRenderContext& rendererContext )
attributes.append( attrNum );
}
// make sure the renderer is ready for classification ("symbolForFeature")
mRendererV2->startRender( rendererContext, pendingFields() );
mRendererV2->startRender( rendererContext, this );
}

// Add fields required for labels
@@ -686,14 +686,14 @@ unsigned char *QgsVectorLayer::drawPolygon( unsigned char *feature, QgsRenderCon

void QgsVectorLayer::drawRendererV2( QgsRenderContext& rendererContext, bool labeling )
{
mRendererV2->startRender( rendererContext, pendingFields() );
mRendererV2->startRender( rendererContext, this );

QgsSingleSymbolRendererV2* selRenderer = NULL;
if ( !mSelectedFeatureIds.isEmpty() )
{
selRenderer = new QgsSingleSymbolRendererV2( QgsSymbolV2::defaultSymbol( geometryType() ) );
selRenderer->symbol()->setColor( QgsRenderer::selectionColor() );
selRenderer->startRender( rendererContext, pendingFields() );
selRenderer->startRender( rendererContext, this );
}

QgsFeature fet;
@@ -728,14 +728,14 @@ void QgsVectorLayer::drawRendererV2Levels( QgsRenderContext& rendererContext, bo
QHash< QgsSymbolV2*, QList<QgsFeature> > features; // key = symbol, value = array of features

// startRender must be called before symbolForFeature() calls to make sure renderer is ready
mRendererV2->startRender( rendererContext, pendingFields() );
mRendererV2->startRender( rendererContext, this );

QgsSingleSymbolRendererV2* selRenderer = NULL;
if ( !mSelectedFeatureIds.isEmpty() )
{
selRenderer = new QgsSingleSymbolRendererV2( QgsSymbolV2::defaultSymbol( geometryType() ) );
selRenderer->symbol()->setColor( QgsRenderer::selectionColor() );
selRenderer->startRender( rendererContext, pendingFields() );
selRenderer->startRender( rendererContext, this );
}

// 1. fetch features
@@ -6,6 +6,7 @@
#include "qgsvectorcolorrampv2.h"

#include "qgsfeature.h"
#include "qgsvectorlayer.h"
#include "qgslogger.h"

#include <QDomDocument>
@@ -172,13 +173,13 @@ void QgsCategorizedSymbolRendererV2::deleteAllCategories()
mCategories.clear();
}

void QgsCategorizedSymbolRendererV2::startRender( QgsRenderContext& context, const QgsFieldMap& fields )
void QgsCategorizedSymbolRendererV2::startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer )
{
// make sure that the hash table is up to date
rebuildHash();

// find out classification attribute index from name
mAttrNum = fieldNameIndex( fields, mAttrName );
mAttrNum = vlayer ? vlayer->fieldNameIndex( mAttrName ) : -1;

QgsCategoryList::iterator it = mCategories.begin();
for ( ; it != mCategories.end(); ++it )
@@ -6,6 +6,7 @@
#include <QHash>

class QgsVectorColorRampV2;
class QgsVectorLayer;

class CORE_EXPORT QgsRendererCategoryV2
{
@@ -47,7 +48,7 @@ class CORE_EXPORT QgsCategorizedSymbolRendererV2 : public QgsFeatureRendererV2

virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );

virtual void startRender( QgsRenderContext& context, const QgsFieldMap& fields );
virtual void startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer );

virtual void stopRender( QgsRenderContext& context );

@@ -6,6 +6,7 @@
#include "qgsvectorcolorrampv2.h"

#include "qgsfeature.h"
#include "qgsvectorlayer.h"
#include "qgslogger.h"

#include <QDomDocument>
@@ -123,10 +124,10 @@ QgsSymbolV2* QgsGraduatedSymbolRendererV2::symbolForFeature( QgsFeature& feature

}

void QgsGraduatedSymbolRendererV2::startRender( QgsRenderContext& context, const QgsFieldMap& fields )
void QgsGraduatedSymbolRendererV2::startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer )
{
// find out classification attribute index from name
mAttrNum = fieldNameIndex( fields, mAttrName );
mAttrNum = vlayer ? vlayer->fieldNameIndex( mAttrName ) : -1;

QgsRangeList::iterator it = mRanges.begin();
for ( ; it != mRanges.end(); ++it )
@@ -45,7 +45,7 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2

virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );

virtual void startRender( QgsRenderContext& context, const QgsFieldMap& fields );
virtual void startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer );

virtual void stopRender( QgsRenderContext& context );

@@ -304,14 +304,3 @@ QgsLegendSymbologyList QgsFeatureRendererV2::legendSymbologyItems( QSize iconSiz
// empty list by default
return QgsLegendSymbologyList();
}


int QgsFeatureRendererV2::fieldNameIndex( const QgsFieldMap& fields, const QString& fieldName )
{
for ( QgsFieldMap::const_iterator it = fields.constBegin(); it != fields.constEnd(); ++it )
{
if ( it->name() == fieldName )
return it.key();
}
return -1;
}
@@ -3,7 +3,6 @@
#define QGSRENDERERV2_H

#include "qgis.h"
#include "qgsfield.h" // for QgsFieldMap

#include <QList>
#include <QString>
@@ -17,6 +16,7 @@ class QDomElement;
class QgsSymbolV2;
class QgsRenderContext;
class QgsFeature;
class QgsVectorLayer;

typedef QList<QgsSymbolV2*> QgsSymbolV2List;
typedef QMap<QString, QgsSymbolV2* > QgsSymbolV2Map;
@@ -62,7 +62,7 @@ class CORE_EXPORT QgsFeatureRendererV2
// to be overridden
virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature ) = 0;

virtual void startRender( QgsRenderContext& context, const QgsFieldMap& fields ) = 0;
virtual void startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer ) = 0;

virtual void stopRender( QgsRenderContext& context ) = 0;

@@ -92,12 +92,6 @@ class CORE_EXPORT QgsFeatureRendererV2
//! return a list of symbology items for the legend
virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );

/** Returns the index of a field name or -1 if the field does not exist
* copied from QgsVectorDataProvider... d'oh... probably should be elsewhere
*/
static int fieldNameIndex( const QgsFieldMap& fields, const QString& fieldName );


protected:
QgsFeatureRendererV2( QString type );

@@ -23,7 +23,7 @@ QgsSymbolV2* QgsSingleSymbolRendererV2::symbolForFeature( QgsFeature& feature )
return mSymbol;
}

void QgsSingleSymbolRendererV2::startRender( QgsRenderContext& context, const QgsFieldMap& fields )
void QgsSingleSymbolRendererV2::startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer )
{
mSymbol->startRender( context );
}
@@ -13,7 +13,7 @@ class CORE_EXPORT QgsSingleSymbolRendererV2 : public QgsFeatureRendererV2

virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );

virtual void startRender( QgsRenderContext& context, const QgsFieldMap& fields );
virtual void startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer );

virtual void stopRender( QgsRenderContext& context );

0 comments on commit ffd1c32

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