Skip to content
Permalink
Browse files

Don't allow null entry to be merged

  • Loading branch information
nyalldawson committed Jan 7, 2019
1 parent 7b245d1 commit 0259548ac9b2404910f0d631cbe5e3a820ee5679
@@ -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() );
@@ -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 );

0 comments on commit 0259548

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