@@ -51,6 +51,8 @@ class QgsFeatureRendererV2
51
51
sipClass = sipClass_QgsCategorizedSymbolRendererV2;
52
52
else if (sipCpp->type() == "graduatedSymbol")
53
53
sipClass = sipClass_QgsGraduatedSymbolRendererV2;
54
+ else if (sipCpp->type() == "RuleRenderer")
55
+ sipClass = sipClass_QgsRuleBasedRendererV2;
54
56
else
55
57
sipClass = 0;
56
58
%End
@@ -350,6 +352,101 @@ protected:
350
352
QgsSymbolV2* symbolForValue(double value);
351
353
};
352
354
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
+
353
450
//////////
354
451
355
452
class QgsSymbolLayerV2
@@ -663,6 +760,8 @@ public:
663
760
664
761
typedef QMap<QString, QString> QgsStringMap;
665
762
763
+ typedef QMap<int, QgsField> QgsFieldMap;
764
+
666
765
//////////
667
766
668
767
class QgsSymbolLayerV2Widget /External/;
0 commit comments