Skip to content

Commit

Permalink
[FEATURE] Added rule-based renderer for symbology-ng.
Browse files Browse the repository at this point in the history
Developed for Faunalia (http://www.faunalia.it) with funding from Regione Toscana -
Sistema Informativo per la Gestione del Territorio e dell' Ambiente [RT-SIGTA]".
For the project: "Sviluppo di prodotti software GIS open-source basati sui prodotti QuantumGIS e Postgis (CIG 037728516E)



git-svn-id: http://svn.osgeo.org/qgis/trunk@13710 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jun 12, 2010
1 parent 65b1cc2 commit 0a4f1c5
Show file tree
Hide file tree
Showing 12 changed files with 1,522 additions and 8 deletions.
2 changes: 0 additions & 2 deletions python/analysis/qgsoverlayanalyzer.sip
@@ -1,5 +1,3 @@
/** polyline is just a list of points */
typedef QMap<int, QgsField> QgsFieldMap;

/** \ingroup analysis
* The QGis class provides vector geometry analysis functions
Expand Down
99 changes: 99 additions & 0 deletions python/core/symbology-ng-core.sip
Expand Up @@ -51,6 +51,8 @@ class QgsFeatureRendererV2
sipClass = sipClass_QgsCategorizedSymbolRendererV2;
else if (sipCpp->type() == "graduatedSymbol")
sipClass = sipClass_QgsGraduatedSymbolRendererV2;
else if (sipCpp->type() == "RuleRenderer")
sipClass = sipClass_QgsRuleBasedRendererV2;
else
sipClass = 0;
%End
Expand Down Expand Up @@ -350,6 +352,101 @@ protected:
QgsSymbolV2* symbolForValue(double value);
};

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

class QgsRuleBasedRendererV2 : QgsFeatureRendererV2
{
%TypeHeaderCode
#include <qgsrulebasedrendererv2.h>
%End

public:

/**
This class keeps data about a rules for rule-based renderer.
A rule consists of a symbol, filter expression and range of scales.
If filter is empty, it matches all features.
If scale range has both values zero, it matches all scales.
If one of the min/max scale denominators is zero, there is no lower/upper bound for scales.
A rule matches if both filter and scale range match.
*/
class Rule
{
public:
//! Constructor takes ownership of the symbol
Rule( QgsSymbolV2* symbol /Transfer/, int scaleMinDenom = 0, int scaleMaxDenom = 0, QString filterExp = QString() );
Rule( const QgsRuleBasedRendererV2::Rule& other );
~Rule();
QString dump() const;
QStringList needsFields() const;
bool isFilterOK( const QgsFieldMap& fields, QgsFeature& f ) const;
bool isScaleOK( double scale ) const;

QgsSymbolV2* symbol();
bool dependsOnScale() const;
int scaleMinDenom() const;
int scaleMaxDenom() const;
QString filterExpression() const;

void setScaleMinDenom( int scaleMinDenom );
void setScaleMaxDenom( int scaleMaxDenom );
void setFilterExpression( QString filterExp );

//Rule& operator=( const Rule& other );
};

/////

static QgsFeatureRendererV2* create( QDomElement& element ) /Factory/;

//! Constructor. Takes ownership of the defult symbol.
QgsRuleBasedRendererV2( QgsSymbolV2* defaultSymbol /Transfer/ );

//! return symbol for current feature. Should not be used individually: there could be more symbols for a feature
virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );

virtual void renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );

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

virtual void stopRender( QgsRenderContext& context );

virtual QList<QString> usedAttributes();

virtual QgsFeatureRendererV2* clone() /Factory/;

virtual QgsSymbolV2List symbols();

//! store renderer info to XML element
virtual QDomElement save( QDomDocument& doc );

/////

//! return the total number of rules
int ruleCount();
//! get reference to rule at index (valid indexes: 0...count-1)
QgsRuleBasedRendererV2::Rule& ruleAt( int index );
//! add rule to the end of the list of rules
void addRule( const QgsRuleBasedRendererV2::Rule& rule );
//! insert rule to a specific position of the list of rules
void insertRule( int index, const QgsRuleBasedRendererV2::Rule& rule );
//! modify the rule at a specific position of the list of rules
void updateRuleAt( int index, const QgsRuleBasedRendererV2::Rule& rule );
//! remove the rule at the specified index
void removeRuleAt( int index );

//////

//! take a rule and create a list of new rules based on the categories from categorized symbol renderer
static QList<QgsRuleBasedRendererV2::Rule> refineRuleCategories( QgsRuleBasedRendererV2::Rule& initialRule, QgsCategorizedSymbolRendererV2* r );
//! take a rule and create a list of new rules based on the ranges from graduated symbol renderer
static QList<QgsRuleBasedRendererV2::Rule> refineRuleRanges( QgsRuleBasedRendererV2::Rule& initialRule, QgsGraduatedSymbolRendererV2* r );
//! take a rule and create a list of new rules with intervals of scales given by the passed scale denominators
static QList<QgsRuleBasedRendererV2::Rule> refineRuleScales( QgsRuleBasedRendererV2::Rule& initialRule, QList<int> scales );

};


//////////

class QgsSymbolLayerV2
Expand Down Expand Up @@ -663,6 +760,8 @@ public:

typedef QMap<QString, QString> QgsStringMap;

typedef QMap<int, QgsField> QgsFieldMap;

//////////

class QgsSymbolLayerV2Widget /External/;
Expand Down
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -32,6 +32,7 @@ SET(QGIS_CORE_SRCS
symbology-ng/qgssinglesymbolrendererv2.cpp
symbology-ng/qgscategorizedsymbolrendererv2.cpp
symbology-ng/qgsgraduatedsymbolrendererv2.cpp
symbology-ng/qgsrulebasedrendererv2.cpp
symbology-ng/qgsvectorcolorrampv2.cpp
symbology-ng/qgsstylev2.cpp
symbology-ng/qgssymbologyv2conversion.cpp
Expand Down
6 changes: 5 additions & 1 deletion src/core/symbology-ng/qgsrendererv2registry.cpp
Expand Up @@ -4,7 +4,7 @@
#include "qgssinglesymbolrendererv2.h"
#include "qgscategorizedsymbolrendererv2.h"
#include "qgsgraduatedsymbolrendererv2.h"

#include "qgsrulebasedrendererv2.h"

QgsRendererV2Registry* QgsRendererV2Registry::mInstance = NULL;

Expand All @@ -20,6 +20,10 @@ QgsRendererV2Registry::QgsRendererV2Registry()
addRenderer( new QgsRendererV2Metadata( "graduatedSymbol",
QObject::tr( "Graduated" ),
QgsGraduatedSymbolRendererV2::create ) );

addRenderer( new QgsRendererV2Metadata( "RuleRenderer",
QObject::tr( "Rule-based" ),
QgsRuleBasedRendererV2::create ) );
}

QgsRendererV2Registry::~QgsRendererV2Registry()
Expand Down

0 comments on commit 0a4f1c5

Please sign in to comment.