Skip to content

Commit

Permalink
feature renderers: don't display not rendered class in catch-all clas…
Browse files Browse the repository at this point in the history
…s and fix class counting (followup d4b8c40 and 4867b7f)

Funded-By: norBIT
  • Loading branch information
jef-n committed Jul 7, 2014
1 parent 0954ec3 commit 136cd5c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp
Expand Up @@ -169,7 +169,7 @@ void QgsCategorizedSymbolRendererV2::rebuildHash()
for ( int i = 0; i < mCategories.count(); ++i )
{
QgsRendererCategoryV2& cat = mCategories[i];
mSymbolHash.insert( cat.value().toString(), cat.renderState() ? cat.symbol() : 0 );
mSymbolHash.insert( cat.value().toString(), ( cat.renderState() || mCounting ) ? cat.symbol() : &sSkipRender );
}
}

Expand Down Expand Up @@ -208,7 +208,10 @@ QgsSymbolV2* QgsCategorizedSymbolRendererV2::symbolForFeature( QgsFeature& featu
}

// find the right symbol for the category
QgsSymbolV2* symbol = symbolForValue( value );
QgsSymbolV2 *symbol = symbolForValue( value );
if ( symbol == &sSkipRender )
return 0;

if ( !symbol )
{
// if no symbol found use default one
Expand Down Expand Up @@ -376,6 +379,8 @@ void QgsCategorizedSymbolRendererV2::sortByLabel( Qt::SortOrder order )

void QgsCategorizedSymbolRendererV2::startRender( QgsRenderContext& context, const QgsFields& fields )
{
mCounting = context.rendererScale() == 0.0;

// make sure that the hash table is up to date
rebuildHash();

Expand All @@ -401,7 +406,6 @@ void QgsCategorizedSymbolRendererV2::startRender( QgsRenderContext& context, con
mTempSymbols[ it->value().toString()] = tempSymbol;
}
}

}

void QgsCategorizedSymbolRendererV2::stopRender( QgsRenderContext& context )
Expand Down Expand Up @@ -752,7 +756,7 @@ bool QgsCategorizedSymbolRendererV2::legendSymbolItemsCheckable() const

bool QgsCategorizedSymbolRendererV2::legendSymbolItemChecked( int index )
{
if( index >= 0 && index < mCategories.size() )
if ( index >= 0 && index < mCategories.size() )
return mCategories[ index ].renderState();
else
return true;
Expand All @@ -762,3 +766,5 @@ void QgsCategorizedSymbolRendererV2::checkLegendSymbolItem( int index, bool stat
{
updateCategoryRenderState( index, state );
}

QgsMarkerSymbolV2 QgsCategorizedSymbolRendererV2::sSkipRender;
3 changes: 3 additions & 0 deletions src/core/symbology-ng/qgscategorizedsymbolrendererv2.h
Expand Up @@ -193,13 +193,16 @@ class CORE_EXPORT QgsCategorizedSymbolRendererV2 : public QgsFeatureRendererV2

//! hashtable for faster access to symbols
QHash<QString, QgsSymbolV2*> mSymbolHash;
bool mCounting;

//! temporary symbols, used for data-defined rotation and scaling
QHash<QString, QgsSymbolV2*> mTempSymbols;

void rebuildHash();

QgsSymbolV2* symbolForValue( QVariant value );

static QgsMarkerSymbolV2 sSkipRender;
};


Expand Down
4 changes: 3 additions & 1 deletion src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp
Expand Up @@ -177,7 +177,7 @@ QgsSymbolV2* QgsGraduatedSymbolRendererV2::symbolForValue( double value )
{
if ( it->lowerValue() <= value && it->upperValue() >= value )
{
if ( it->renderState() )
if ( it->renderState() || mCounting )
return it->symbol();
else
return NULL;
Expand Down Expand Up @@ -237,6 +237,8 @@ QgsSymbolV2* QgsGraduatedSymbolRendererV2::symbolForFeature( QgsFeature& feature

void QgsGraduatedSymbolRendererV2::startRender( QgsRenderContext& context, const QgsFields& fields )
{
mCounting = context.rendererScale() == 0.0;

// find out classification attribute index from name
mAttrNum = fields.fieldNameIndex( mAttrName );

Expand Down
1 change: 1 addition & 0 deletions src/core/symbology-ng/qgsgraduatedsymbolrendererv2.h
Expand Up @@ -211,6 +211,7 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2
QScopedPointer<QgsExpression> mExpression;
//! attribute index (derived from attribute name in startRender)
int mAttrNum;
bool mCounting;

//! temporary symbols, used for data-defined rotation and scaling
QHash<QgsSymbolV2*, QgsSymbolV2*> mTempSymbols;
Expand Down

0 comments on commit 136cd5c

Please sign in to comment.