Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9035cf7

Browse files
committedJan 10, 2012
don't overwrite existing classes when reclassify in graduated symbol
renderer. Also always add default value and use it for all unclassified values (fixes #2709)
1 parent 302c1a7 commit 9035cf7

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed
 

‎src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@ QgsSymbolV2* QgsCategorizedSymbolRendererV2::symbolForFeature( QgsFeature& featu
143143
// find the right symbol for the category
144144
QgsSymbolV2* symbol = symbolForValue( *ita );
145145
if ( symbol == NULL )
146-
return NULL;
146+
{
147+
// if no symbol found use default one
148+
return symbolForValue( QVariant( "" ) );
149+
}
147150

148151
if ( mRotationFieldIdx == -1 && mSizeScaleFieldIdx == -1 )
149152
return symbol; // no data-defined rotation/scaling - just return the symbol

‎src/gui/symbology-ng/qgscategorizedsymbolrendererv2widget.cpp

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -228,16 +228,29 @@ static void _createCategories( QgsCategoryList& cats, QList<QVariant>& values, Q
228228

229229
int num = values.count();
230230

231+
bool hasNull = false;
232+
231233
for ( int i = 0; i < num; i++ )
232234
{
233235
QVariant value = values[i];
236+
if ( value.toString().isNull() )
237+
{
238+
hasNull = true;
239+
}
234240
double x = i / ( double ) num;
235241
QgsSymbolV2* newSymbol = symbol->clone();
236242
newSymbol->setColor( ramp->color( x ) );
237243

238244
cats.append( QgsRendererCategoryV2( value, newSymbol, value.toString() ) );
239245
}
240246

247+
// add null (default) value if not exists
248+
if ( !hasNull )
249+
{
250+
QgsSymbolV2* newSymbol = symbol->clone();
251+
newSymbol->setColor( ramp->color( 1 ) );
252+
cats.append( QgsRendererCategoryV2( QVariant( "" ), newSymbol, QString() ) );
253+
}
241254
}
242255

243256
void QgsCategorizedSymbolRendererV2Widget::addCategories()
@@ -265,6 +278,8 @@ void QgsCategorizedSymbolRendererV2Widget::addCategories()
265278
QgsCategoryList cats;
266279
_createCategories( cats, unique_vals, mCategorizedSymbol, ramp );
267280

281+
bool deleteExisting = false;
282+
268283
if ( !mOldClassificationAttribute.isEmpty() &&
269284
attrName != mOldClassificationAttribute &&
270285
mRenderer->categories().count() > 0 )
@@ -276,28 +291,33 @@ void QgsCategorizedSymbolRendererV2Widget::addCategories()
276291
.arg( mOldClassificationAttribute ).arg( attrName ),
277292
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel );
278293
if ( res == QMessageBox::Cancel )
294+
{
279295
return;
296+
}
297+
298+
deleteExisting = ( res == QMessageBox::Yes );
299+
}
280300

281-
bool deleteExisting = ( res == QMessageBox::Yes );
282-
if ( !deleteExisting )
301+
if ( !deleteExisting )
302+
{
303+
QgsCategoryList prevCats = mRenderer->categories();
304+
for ( int i = 0; i < cats.size(); ++i )
283305
{
284-
QgsCategoryList prevCats = mRenderer->categories();
285-
for ( int i = 0; i < cats.size(); ++i )
306+
bool contains = false;
307+
QVariant value = cats.at( i ).value();
308+
for ( int j = 0; j < prevCats.size() && !contains; ++j )
286309
{
287-
bool contains = false;
288-
QVariant value = cats.at( i ).value();
289-
for ( int j = 0; j < prevCats.size() && !contains; ++j )
310+
if ( prevCats.at( j ).value() == value )
290311
{
291-
if ( prevCats.at( j ).value() == value )
292-
contains = true;
312+
contains = true;
313+
break;
293314
}
294-
295-
if ( !contains )
296-
prevCats.append( cats.at( i ) );
297315
}
298-
cats = prevCats;
299-
}
300316

317+
if ( !contains )
318+
prevCats.append( cats.at( i ) );
319+
}
320+
cats = prevCats;
301321
}
302322

303323
mOldClassificationAttribute = attrName;

0 commit comments

Comments
 (0)
Please sign in to comment.