Skip to content
Permalink
Browse files

Rule-based renderer: selection and drawing of markers works again

  • Loading branch information
wonder-sk committed Jan 25, 2012
1 parent 14b718b commit 87ae8a36fcaaa7cd2a86610e97969d8f402e0663
Showing with 24 additions and 28 deletions.
  1. +9 −24 src/core/symbology-ng/qgsrulebasedrendererv2.cpp
  2. +15 −4 src/core/symbology-ng/qgsrulebasedrendererv2.h
@@ -260,9 +260,9 @@ void QgsRuleBasedRendererV2::Rule::setNormZLevels( const QMap<int, int>& zLevels
}


void QgsRuleBasedRendererV2::Rule::renderFeature( QgsFeature* featPtr, QgsRenderContext& context, QgsRuleBasedRendererV2::RenderQueue& renderQueue )
void QgsRuleBasedRendererV2::Rule::renderFeature( QgsRuleBasedRendererV2::FeatureToRender& featToRender, QgsRenderContext& context, QgsRuleBasedRendererV2::RenderQueue& renderQueue )
{
if ( isFilterOK( *featPtr ) )
if ( isFilterOK( featToRender.feat ) )
{
// create job for this feature and this symbol, add to list of jobs
if ( mSymbol )
@@ -271,15 +271,15 @@ void QgsRuleBasedRendererV2::Rule::renderFeature( QgsFeature* featPtr, QgsRender
foreach( int normZLevel, mSymbolNormZLevels )
{
//QgsDebugMsg(QString("add job at level %1").arg(normZLevel));
renderQueue[normZLevel].jobs.append( new RenderJob( featPtr, mSymbol ) );
renderQueue[normZLevel].jobs.append( new RenderJob( featToRender, mSymbol ) );
}
}

// process children
for ( QList<Rule*>::iterator it = mActiveChildren.begin(); it != mActiveChildren.end(); ++it )
{
Rule* rule = *it;
rule->renderFeature( featPtr, context, renderQueue );
rule->renderFeature( featToRender, context, renderQueue );
}
}
}
@@ -371,20 +371,12 @@ void QgsRuleBasedRendererV2::renderFeature( QgsFeature& feature,
bool drawVertexMarker )
{
Q_UNUSED( layer );
Q_UNUSED( selected );
Q_UNUSED( drawVertexMarker );

// TODO: selected features, vertex markers

QgsFeature* featPtr = NULL;
if ( !featPtr )
{
featPtr = new QgsFeature( feature );
mCurrentFeatures.append( featPtr );
}
int flags = ( selected ? FeatIsSelected : 0 ) | ( drawVertexMarker ? FeatDrawMarkers : 0 );
mCurrentFeatures.append( FeatureToRender( feature, flags ) );

// check each active rule
mRootRule->renderFeature( featPtr, context, mRenderQueue );
mRootRule->renderFeature( mCurrentFeatures.last(), context, mRenderQueue );
}


@@ -415,10 +407,6 @@ void QgsRuleBasedRendererV2::stopRender( QgsRenderContext& context )
// do the actual rendering
//

// TODO: selected, markers
bool selected = false;
bool drawVertexMarker = false;

// go through all levels
foreach( const RenderLevel& level, mRenderQueue )
{
@@ -437,17 +425,14 @@ void QgsRuleBasedRendererV2::stopRender( QgsRenderContext& context )
// but there are multiple transforms going on!
if ( s->symbolLayer( i )->renderingPass() == level.zIndex )
{
renderFeatureWithSymbol( *job->f, job->symbol, context, i, selected, drawVertexMarker );
int flags = job->ftr.flags;
renderFeatureWithSymbol( job->ftr.feat, job->symbol, context, i, flags & FeatIsSelected, flags & FeatDrawMarkers );
}
}
}
}

// clean current features
foreach( QgsFeature* f, mCurrentFeatures )
{
delete f;
}
mCurrentFeatures.clear();

// clean render queue
@@ -17,6 +17,7 @@
#define QGSRULEBASEDRENDERERV2_H

#include "qgsfield.h"
#include "qgsfeature.h"

#include "qgsrendererv2.h"

@@ -36,12 +37,22 @@ class CORE_EXPORT QgsRuleBasedRendererV2 : public QgsFeatureRendererV2

// TODO: use QVarLengthArray instead of QList

enum FeatureFlags { FeatIsSelected = 1, FeatDrawMarkers = 2 };

// feature for rendering: QgsFeature and some flags
struct FeatureToRender
{
FeatureToRender( QgsFeature& _f, int _flags ) : feat( _f ), flags( _flags ) {}
QgsFeature feat;
int flags; // selected and/or draw markers
};

// rendering job: a feature to be rendered with a particular symbol
// (both f, symbol are _not_ owned by this class)
struct RenderJob
{
RenderJob( QgsFeature* _f, QgsSymbolV2* _s ) : f( _f ), symbol( _s ) {}
QgsFeature* f;
RenderJob( FeatureToRender& _ftr, QgsSymbolV2* _s ) : ftr( _ftr ), symbol( _s ) {}
FeatureToRender& ftr;
QgsSymbolV2* symbol;
};

@@ -114,7 +125,7 @@ class CORE_EXPORT QgsRuleBasedRendererV2 : public QgsFeatureRendererV2
//! assign normalized z-levels [0..N-1] for this rule's symbol for quick access during rendering
void setNormZLevels( const QMap<int, int>& zLevelsToNormLevels );

void renderFeature( QgsFeature* featPtr, QgsRenderContext& context, RenderQueue& renderQueue );
void renderFeature( FeatureToRender& featToRender, QgsRenderContext& context, RenderQueue& renderQueue );

void stopRender( QgsRenderContext& context );

@@ -212,7 +223,7 @@ class CORE_EXPORT QgsRuleBasedRendererV2 : public QgsFeatureRendererV2

// temporary
RenderQueue mRenderQueue;
QList<QgsFeature*> mCurrentFeatures;
QList<FeatureToRender> mCurrentFeatures;
};

#endif // QGSRULEBASEDRENDERERV2_H

0 comments on commit 87ae8a3

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