Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE] Merge branch 'rules' - new rule-based rendering
Conflicts:
	src/gui/symbology-ng/qgsgraduatedsymbolrendererv2widget.cpp
  • Loading branch information
wonder-sk committed Jan 24, 2012
2 parents 0b1fd34 + 1c3c02f commit a7cf5e4
Show file tree
Hide file tree
Showing 41 changed files with 2,849 additions and 969 deletions.
28 changes: 10 additions & 18 deletions python/core/symbology-ng-core.sip
Expand Up @@ -390,6 +390,8 @@ class QgsRuleBasedRendererV2 : QgsFeatureRendererV2

public:

//typedef QList<QgsRuleBasedRendererV2::Rule*> RuleList;

/**
This class keeps data about a rules for rule-based renderer.
A rule consists of a symbol, filter expression and range of scales.
Expand All @@ -403,10 +405,10 @@ class QgsRuleBasedRendererV2 : QgsFeatureRendererV2
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( const QgsRuleBasedRendererV2::Rule& other );
~Rule();
QString dump() const;
QStringList needsFields() const;
//QStringList needsFields() const;
bool isFilterOK( QgsFeature& f ) const;
bool isScaleOK( double scale ) const;

Expand All @@ -428,7 +430,9 @@ class QgsRuleBasedRendererV2 : QgsFeatureRendererV2

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

//! Constructor. Takes ownership of the defult symbol.
//! Constructs the renderer from given tree of rules
QgsRuleBasedRendererV2( QgsRuleBasedRendererV2::Rule* root /Transfer/ );
//! Constructor for convenience. Creates a root rule and adds a default rule with symbol
QgsRuleBasedRendererV2( QgsSymbolV2* defaultSymbol /Transfer/ );

//! return symbol for current feature. Should not be used individually: there could be more symbols for a feature
Expand All @@ -454,27 +458,15 @@ class QgsRuleBasedRendererV2 : QgsFeatureRendererV2

/////

//! 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 );
//static QgsRuleBasedRendererV2::RuleList 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 );
//static QgsRuleBasedRendererV2::RuleList 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 );
//static QgsRuleBasedRendererV2::RuleList refineRuleScales( QgsRuleBasedRendererV2::Rule* initialRule, QList<int> scales );

};

Expand Down
2 changes: 0 additions & 2 deletions python/gui/symbology-ng-gui.sip
Expand Up @@ -42,8 +42,6 @@ public slots:
void apply();
void onOK();

void showSymbolLevels();

protected:

//! Reimplements dialog keyPress event so we can ignore it
Expand Down
5 changes: 4 additions & 1 deletion src/core/qgsvectorlayer.cpp
Expand Up @@ -776,6 +776,8 @@ void QgsVectorLayer::drawRendererV2( QgsRenderContext& rendererContext, bool lab
#endif //Q_WS_MAC
}

stopRendererV2( rendererContext, NULL );

#ifndef Q_WS_MAC
QgsDebugMsg( QString( "Total features processed %1" ).arg( featureCount ) );
#endif
Expand Down Expand Up @@ -977,7 +979,8 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )

select( attributes, rendererContext.extent() );

if ( mRendererV2->usingSymbolLevels() )
if ( ( mRendererV2->capabilities() & QgsFeatureRendererV2::SymbolLevels )
&& mRendererV2->usingSymbolLevels() )
drawRendererV2Levels( rendererContext, labeling );
else
drawRendererV2( rendererContext, labeling );
Expand Down
4 changes: 4 additions & 0 deletions src/core/symbology-ng/qgscategorizedsymbolrendererv2.h
Expand Up @@ -60,6 +60,10 @@ class CORE_EXPORT QgsCategorizedSymbolRendererV2 : public QgsFeatureRendererV2

virtual QgsFeatureRendererV2* clone();

//! returns bitwise OR-ed capabilities of the renderer
//! \note added in 2.0
virtual int capabilities() { return SymbolLevels; }

virtual QgsSymbolV2List symbols();

const QgsCategoryList& categories() { return mCategories; }
Expand Down
4 changes: 4 additions & 0 deletions src/core/symbology-ng/qgsgraduatedsymbolrendererv2.h
Expand Up @@ -55,6 +55,10 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2

virtual QgsFeatureRendererV2* clone();

//! returns bitwise OR-ed capabilities of the renderer
//! \note added in 2.0
virtual int capabilities() { return SymbolLevels; }

virtual QgsSymbolV2List symbols();

QString classAttribute() const { return mAttrName; }
Expand Down
6 changes: 5 additions & 1 deletion src/core/symbology-ng/qgsrendererv2.cpp
Expand Up @@ -194,6 +194,11 @@ void QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext&
if ( symbol == NULL )
return;

renderFeatureWithSymbol( feature, symbol, context, layer, selected, drawVertexMarker );
}

void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymbolV2* symbol, QgsRenderContext& context, int layer, bool selected, bool drawVertexMarker )
{
QgsSymbolV2::SymbolType symbolType = symbol->type();

QgsGeometry* geom = feature.geometry();
Expand Down Expand Up @@ -356,7 +361,6 @@ QgsFeatureRendererV2* QgsFeatureRendererV2::load( QDomElement& element )
if ( r )
{
r->setUsingSymbolLevels( element.attribute( "symbollevels", "0" ).toInt() );
r->setUsingFirstRule( element.attribute( "firstrule", "0" ).toInt() );
}
return r;
}
Expand Down
20 changes: 15 additions & 5 deletions src/core/symbology-ng/qgsrendererv2.h
Expand Up @@ -78,16 +78,20 @@ class CORE_EXPORT QgsFeatureRendererV2
//! for debugging
virtual QString dump();

enum Capabilities {
SymbolLevels = 1 // rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
};

//! returns bitwise OR-ed capabilities of the renderer
//! \note added in 2.0
virtual int capabilities() { return 0; }

//! for symbol levels
virtual QgsSymbolV2List symbols() = 0;

bool usingSymbolLevels() const { return mUsingSymbolLevels; }
void setUsingSymbolLevels( bool usingSymbolLevels ) { mUsingSymbolLevels = usingSymbolLevels; }

bool usingFirstRule() const { return mUsingFirstRule; }
void setUsingFirstRule( bool usingFirstRule ) { mUsingFirstRule = usingFirstRule; }


//! create a renderer from XML element
static QgsFeatureRendererV2* load( QDomElement& symbologyElem );

Expand All @@ -107,6 +111,13 @@ class CORE_EXPORT QgsFeatureRendererV2
protected:
QgsFeatureRendererV2( QString type );

void renderFeatureWithSymbol( QgsFeature& feature,
QgsSymbolV2* symbol,
QgsRenderContext& context,
int layer,
bool selected,
bool drawVertexMarker );

//! render editing vertex marker at specified point
void renderVertexMarker( QPointF& pt, QgsRenderContext& context );
//! render editing vertex marker for a polyline
Expand All @@ -121,7 +132,6 @@ class CORE_EXPORT QgsFeatureRendererV2
QString mType;

bool mUsingSymbolLevels;
bool mUsingFirstRule;

/** The current type of editing marker */
int mCurrentVertexMarkerType;
Expand Down

0 comments on commit a7cf5e4

Please sign in to comment.