Navigation Menu

Skip to content

Commit

Permalink
don't overwrite existing classes when reclassify in graduated symbol
Browse files Browse the repository at this point in the history
renderer. Also always add default value and use it for all unclassified
values (fixes #2709)
  • Loading branch information
alexbruy committed Jan 16, 2012
1 parent cf41e6c commit 068493d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
5 changes: 4 additions & 1 deletion src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp
Expand Up @@ -139,7 +139,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
Expand Down
48 changes: 34 additions & 14 deletions src/gui/symbology-ng/qgscategorizedsymbolrendererv2widget.cpp
Expand Up @@ -227,16 +227,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()
Expand Down Expand Up @@ -264,6 +277,8 @@ void QgsCategorizedSymbolRendererV2Widget::addCategories()
QgsCategoryList cats;
_createCategories( cats, unique_vals, mCategorizedSymbol, ramp );

bool deleteExisting = false;

if ( !mOldClassificationAttribute.isEmpty() &&
attrName != mOldClassificationAttribute &&
mRenderer->categories().count() > 0 )
Expand All @@ -275,28 +290,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;
Expand Down

0 comments on commit 068493d

Please sign in to comment.