Skip to content
Permalink
Browse files

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)
  • Loading branch information
alexbruy committed Jan 10, 2012
1 parent 302c1a7 commit 9035cf7a7e31921a84b5d8281cf9e845293d65c1
@@ -143,7 +143,10 @@ QgsSymbolV2* QgsCategorizedSymbolRendererV2::symbolForFeature( QgsFeature& featu
// find the right symbol for the category
QgsSymbolV2* symbol = symbolForValue( *ita );
if ( symbol == NULL )
return NULL;
{
// if no symbol found use default one
return symbolForValue( QVariant( "" ) );
}

if ( mRotationFieldIdx == -1 && mSizeScaleFieldIdx == -1 )
return symbol; // no data-defined rotation/scaling - just return the symbol
@@ -228,16 +228,29 @@ static void _createCategories( QgsCategoryList& cats, QList<QVariant>& values, Q

int num = values.count();

bool hasNull = false;

for ( int i = 0; i < num; i++ )
{
QVariant value = values[i];
if ( value.toString().isNull() )
{
hasNull = true;
}
double x = i / ( double ) num;
QgsSymbolV2* newSymbol = symbol->clone();
newSymbol->setColor( ramp->color( x ) );

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

// add null (default) value if not exists
if ( !hasNull )
{
QgsSymbolV2* newSymbol = symbol->clone();
newSymbol->setColor( ramp->color( 1 ) );
cats.append( QgsRendererCategoryV2( QVariant( "" ), newSymbol, QString() ) );
}
}

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

bool deleteExisting = false;

if ( !mOldClassificationAttribute.isEmpty() &&
attrName != mOldClassificationAttribute &&
mRenderer->categories().count() > 0 )
@@ -276,28 +291,33 @@ void QgsCategorizedSymbolRendererV2Widget::addCategories()
.arg( mOldClassificationAttribute ).arg( attrName ),
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel );
if ( res == QMessageBox::Cancel )
{
return;
}

deleteExisting = ( res == QMessageBox::Yes );
}

bool deleteExisting = ( res == QMessageBox::Yes );
if ( !deleteExisting )
if ( !deleteExisting )
{
QgsCategoryList prevCats = mRenderer->categories();
for ( int i = 0; i < cats.size(); ++i )
{
QgsCategoryList prevCats = mRenderer->categories();
for ( int i = 0; i < cats.size(); ++i )
bool contains = false;
QVariant value = cats.at( i ).value();
for ( int j = 0; j < prevCats.size() && !contains; ++j )
{
bool contains = false;
QVariant value = cats.at( i ).value();
for ( int j = 0; j < prevCats.size() && !contains; ++j )
if ( prevCats.at( j ).value() == value )
{
if ( prevCats.at( j ).value() == value )
contains = true;
contains = true;
break;
}

if ( !contains )
prevCats.append( cats.at( i ) );
}
cats = prevCats;
}

if ( !contains )
prevCats.append( cats.at( i ) );
}
cats = prevCats;
}

mOldClassificationAttribute = attrName;

0 comments on commit 9035cf7

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