Skip to content

Commit 136cd5c

Browse files
committed
feature renderers: don't display not rendered class in catch-all class and fix class counting (followup d4b8c40 and 4867b7f)
Funded-By: norBIT
1 parent 0954ec3 commit 136cd5c

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ void QgsCategorizedSymbolRendererV2::rebuildHash()
169169
for ( int i = 0; i < mCategories.count(); ++i )
170170
{
171171
QgsRendererCategoryV2& cat = mCategories[i];
172-
mSymbolHash.insert( cat.value().toString(), cat.renderState() ? cat.symbol() : 0 );
172+
mSymbolHash.insert( cat.value().toString(), ( cat.renderState() || mCounting ) ? cat.symbol() : &sSkipRender );
173173
}
174174
}
175175

@@ -208,7 +208,10 @@ QgsSymbolV2* QgsCategorizedSymbolRendererV2::symbolForFeature( QgsFeature& featu
208208
}
209209

210210
// find the right symbol for the category
211-
QgsSymbolV2* symbol = symbolForValue( value );
211+
QgsSymbolV2 *symbol = symbolForValue( value );
212+
if ( symbol == &sSkipRender )
213+
return 0;
214+
212215
if ( !symbol )
213216
{
214217
// if no symbol found use default one
@@ -376,6 +379,8 @@ void QgsCategorizedSymbolRendererV2::sortByLabel( Qt::SortOrder order )
376379

377380
void QgsCategorizedSymbolRendererV2::startRender( QgsRenderContext& context, const QgsFields& fields )
378381
{
382+
mCounting = context.rendererScale() == 0.0;
383+
379384
// make sure that the hash table is up to date
380385
rebuildHash();
381386

@@ -401,7 +406,6 @@ void QgsCategorizedSymbolRendererV2::startRender( QgsRenderContext& context, con
401406
mTempSymbols[ it->value().toString()] = tempSymbol;
402407
}
403408
}
404-
405409
}
406410

407411
void QgsCategorizedSymbolRendererV2::stopRender( QgsRenderContext& context )
@@ -752,7 +756,7 @@ bool QgsCategorizedSymbolRendererV2::legendSymbolItemsCheckable() const
752756

753757
bool QgsCategorizedSymbolRendererV2::legendSymbolItemChecked( int index )
754758
{
755-
if( index >= 0 && index < mCategories.size() )
759+
if ( index >= 0 && index < mCategories.size() )
756760
return mCategories[ index ].renderState();
757761
else
758762
return true;
@@ -762,3 +766,5 @@ void QgsCategorizedSymbolRendererV2::checkLegendSymbolItem( int index, bool stat
762766
{
763767
updateCategoryRenderState( index, state );
764768
}
769+
770+
QgsMarkerSymbolV2 QgsCategorizedSymbolRendererV2::sSkipRender;

src/core/symbology-ng/qgscategorizedsymbolrendererv2.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,16 @@ class CORE_EXPORT QgsCategorizedSymbolRendererV2 : public QgsFeatureRendererV2
193193

194194
//! hashtable for faster access to symbols
195195
QHash<QString, QgsSymbolV2*> mSymbolHash;
196+
bool mCounting;
196197

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

200201
void rebuildHash();
201202

202203
QgsSymbolV2* symbolForValue( QVariant value );
204+
205+
static QgsMarkerSymbolV2 sSkipRender;
203206
};
204207

205208

src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ QgsSymbolV2* QgsGraduatedSymbolRendererV2::symbolForValue( double value )
177177
{
178178
if ( it->lowerValue() <= value && it->upperValue() >= value )
179179
{
180-
if ( it->renderState() )
180+
if ( it->renderState() || mCounting )
181181
return it->symbol();
182182
else
183183
return NULL;
@@ -237,6 +237,8 @@ QgsSymbolV2* QgsGraduatedSymbolRendererV2::symbolForFeature( QgsFeature& feature
237237

238238
void QgsGraduatedSymbolRendererV2::startRender( QgsRenderContext& context, const QgsFields& fields )
239239
{
240+
mCounting = context.rendererScale() == 0.0;
241+
240242
// find out classification attribute index from name
241243
mAttrNum = fields.fieldNameIndex( mAttrName );
242244

src/core/symbology-ng/qgsgraduatedsymbolrendererv2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2
211211
QScopedPointer<QgsExpression> mExpression;
212212
//! attribute index (derived from attribute name in startRender)
213213
int mAttrNum;
214+
bool mCounting;
214215

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

0 commit comments

Comments
 (0)