Skip to content

Commit 0a4f1c5

Browse files
author
wonder
committed
[FEATURE] Added rule-based renderer for symbology-ng.
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
1 parent 65b1cc2 commit 0a4f1c5

12 files changed

+1522
-8
lines changed

python/analysis/qgsoverlayanalyzer.sip

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/** polyline is just a list of points */
2-
typedef QMap<int, QgsField> QgsFieldMap;
31

42
/** \ingroup analysis
53
* The QGis class provides vector geometry analysis functions

python/core/symbology-ng-core.sip

+99
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class QgsFeatureRendererV2
5151
sipClass = sipClass_QgsCategorizedSymbolRendererV2;
5252
else if (sipCpp->type() == "graduatedSymbol")
5353
sipClass = sipClass_QgsGraduatedSymbolRendererV2;
54+
else if (sipCpp->type() == "RuleRenderer")
55+
sipClass = sipClass_QgsRuleBasedRendererV2;
5456
else
5557
sipClass = 0;
5658
%End
@@ -350,6 +352,101 @@ protected:
350352
QgsSymbolV2* symbolForValue(double value);
351353
};
352354

355+
///////////////
356+
357+
class QgsRuleBasedRendererV2 : QgsFeatureRendererV2
358+
{
359+
%TypeHeaderCode
360+
#include <qgsrulebasedrendererv2.h>
361+
%End
362+
363+
public:
364+
365+
/**
366+
This class keeps data about a rules for rule-based renderer.
367+
A rule consists of a symbol, filter expression and range of scales.
368+
If filter is empty, it matches all features.
369+
If scale range has both values zero, it matches all scales.
370+
If one of the min/max scale denominators is zero, there is no lower/upper bound for scales.
371+
A rule matches if both filter and scale range match.
372+
*/
373+
class Rule
374+
{
375+
public:
376+
//! Constructor takes ownership of the symbol
377+
Rule( QgsSymbolV2* symbol /Transfer/, int scaleMinDenom = 0, int scaleMaxDenom = 0, QString filterExp = QString() );
378+
Rule( const QgsRuleBasedRendererV2::Rule& other );
379+
~Rule();
380+
QString dump() const;
381+
QStringList needsFields() const;
382+
bool isFilterOK( const QgsFieldMap& fields, QgsFeature& f ) const;
383+
bool isScaleOK( double scale ) const;
384+
385+
QgsSymbolV2* symbol();
386+
bool dependsOnScale() const;
387+
int scaleMinDenom() const;
388+
int scaleMaxDenom() const;
389+
QString filterExpression() const;
390+
391+
void setScaleMinDenom( int scaleMinDenom );
392+
void setScaleMaxDenom( int scaleMaxDenom );
393+
void setFilterExpression( QString filterExp );
394+
395+
//Rule& operator=( const Rule& other );
396+
};
397+
398+
/////
399+
400+
static QgsFeatureRendererV2* create( QDomElement& element ) /Factory/;
401+
402+
//! Constructor. Takes ownership of the defult symbol.
403+
QgsRuleBasedRendererV2( QgsSymbolV2* defaultSymbol /Transfer/ );
404+
405+
//! return symbol for current feature. Should not be used individually: there could be more symbols for a feature
406+
virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );
407+
408+
virtual void renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
409+
410+
virtual void startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer );
411+
412+
virtual void stopRender( QgsRenderContext& context );
413+
414+
virtual QList<QString> usedAttributes();
415+
416+
virtual QgsFeatureRendererV2* clone() /Factory/;
417+
418+
virtual QgsSymbolV2List symbols();
419+
420+
//! store renderer info to XML element
421+
virtual QDomElement save( QDomDocument& doc );
422+
423+
/////
424+
425+
//! return the total number of rules
426+
int ruleCount();
427+
//! get reference to rule at index (valid indexes: 0...count-1)
428+
QgsRuleBasedRendererV2::Rule& ruleAt( int index );
429+
//! add rule to the end of the list of rules
430+
void addRule( const QgsRuleBasedRendererV2::Rule& rule );
431+
//! insert rule to a specific position of the list of rules
432+
void insertRule( int index, const QgsRuleBasedRendererV2::Rule& rule );
433+
//! modify the rule at a specific position of the list of rules
434+
void updateRuleAt( int index, const QgsRuleBasedRendererV2::Rule& rule );
435+
//! remove the rule at the specified index
436+
void removeRuleAt( int index );
437+
438+
//////
439+
440+
//! take a rule and create a list of new rules based on the categories from categorized symbol renderer
441+
static QList<QgsRuleBasedRendererV2::Rule> refineRuleCategories( QgsRuleBasedRendererV2::Rule& initialRule, QgsCategorizedSymbolRendererV2* r );
442+
//! take a rule and create a list of new rules based on the ranges from graduated symbol renderer
443+
static QList<QgsRuleBasedRendererV2::Rule> refineRuleRanges( QgsRuleBasedRendererV2::Rule& initialRule, QgsGraduatedSymbolRendererV2* r );
444+
//! take a rule and create a list of new rules with intervals of scales given by the passed scale denominators
445+
static QList<QgsRuleBasedRendererV2::Rule> refineRuleScales( QgsRuleBasedRendererV2::Rule& initialRule, QList<int> scales );
446+
447+
};
448+
449+
353450
//////////
354451

355452
class QgsSymbolLayerV2
@@ -663,6 +760,8 @@ public:
663760

664761
typedef QMap<QString, QString> QgsStringMap;
665762

763+
typedef QMap<int, QgsField> QgsFieldMap;
764+
666765
//////////
667766

668767
class QgsSymbolLayerV2Widget /External/;

src/core/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ SET(QGIS_CORE_SRCS
3232
symbology-ng/qgssinglesymbolrendererv2.cpp
3333
symbology-ng/qgscategorizedsymbolrendererv2.cpp
3434
symbology-ng/qgsgraduatedsymbolrendererv2.cpp
35+
symbology-ng/qgsrulebasedrendererv2.cpp
3536
symbology-ng/qgsvectorcolorrampv2.cpp
3637
symbology-ng/qgsstylev2.cpp
3738
symbology-ng/qgssymbologyv2conversion.cpp

src/core/symbology-ng/qgsrendererv2registry.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "qgssinglesymbolrendererv2.h"
55
#include "qgscategorizedsymbolrendererv2.h"
66
#include "qgsgraduatedsymbolrendererv2.h"
7-
7+
#include "qgsrulebasedrendererv2.h"
88

99
QgsRendererV2Registry* QgsRendererV2Registry::mInstance = NULL;
1010

@@ -20,6 +20,10 @@ QgsRendererV2Registry::QgsRendererV2Registry()
2020
addRenderer( new QgsRendererV2Metadata( "graduatedSymbol",
2121
QObject::tr( "Graduated" ),
2222
QgsGraduatedSymbolRendererV2::create ) );
23+
24+
addRenderer( new QgsRendererV2Metadata( "RuleRenderer",
25+
QObject::tr( "Rule-based" ),
26+
QgsRuleBasedRendererV2::create ) );
2327
}
2428

2529
QgsRendererV2Registry::~QgsRendererV2Registry()

0 commit comments

Comments
 (0)