Skip to content

Commit

Permalink
Don't allow null entry to be merged
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 8, 2019
1 parent 7b245d1 commit 0259548
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/gui/symbology/qgscategorizedsymbolrendererwidget.cpp
Expand Up @@ -1155,12 +1155,27 @@ void QgsCategorizedSymbolRendererWidget::dataDefinedSizeLegend()

void QgsCategorizedSymbolRendererWidget::mergeClicked()
{
QList<int> categoryIndexes = selectedCategories();
const QgsCategoryList &categories = mRenderer->categories();

QList<int> selectedCategoryIndexes = selectedCategories();
QList< int > categoryIndexes;

// filter out "" entry
for ( int i : selectedCategoryIndexes )
{
QVariant v = categories.at( i ).value();

if ( !v.isValid() || v == "" )
{
continue;
}

categoryIndexes.append( i );
}

if ( categoryIndexes.count() < 2 )
return;

const QgsCategoryList &categories = mRenderer->categories();

QStringList labels;
QVariantList values;
values.reserve( categoryIndexes.count() );
Expand Down
2 changes: 2 additions & 0 deletions tests/src/gui/testqgscategorizedrendererwidget.cpp
Expand Up @@ -196,6 +196,8 @@ void TestQgsCategorizedRendererWidget::merge()
// merging categories which are already lists
widget->viewCategories->selectionModel()->select( widget->viewCategories->model()->index( 0, 0 ), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows );
widget->viewCategories->selectionModel()->select( widget->viewCategories->model()->index( 1, 0 ), QItemSelectionModel::Select | QItemSelectionModel::Rows );
//"" entry should be ignored
widget->viewCategories->selectionModel()->select( widget->viewCategories->model()->index( 2, 0 ), QItemSelectionModel::Select | QItemSelectionModel::Rows );
widget->mergeClicked();

QCOMPARE( static_cast< QgsCategorizedSymbolRenderer * >( widget->renderer() )->categories().count(), 2 );
Expand Down

0 comments on commit 0259548

Please sign in to comment.