From c4b934602100c1929345847d42f41f9ceae1b342 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 10 Nov 2016 11:15:52 +0200 Subject: [PATCH] Fixed issue #586. Valentina crashes if clear input filter string. --HG-- branch : develop --- .../support/dialogeditwrongformula.cpp | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp b/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp index ea3407582..1a07b83e6 100644 --- a/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp +++ b/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp @@ -561,16 +561,33 @@ void DialogEditWrongFormula::FilterVariablesEdited(const QString &filter) { ui->tableWidget->blockSignals(true); - // hide all rows - for (auto i = 0; i < ui->tableWidget->rowCount(); i++) + // If filter is empty findItems() for unknown reason returns nullptr items. + // See issue #586. https://bitbucket.org/dismine/valentina/issues/586/valentina-crashes-if-clear-input-filter + if (filter.isEmpty()) { - ui->tableWidget->hideRow(i); + // show all rows + for (auto i = 0; i < ui->tableWidget->rowCount(); ++i) + { + ui->tableWidget->showRow(i); + } } - - // show rows with matched filter - for (auto item : ui->tableWidget->findItems(filter, Qt::MatchContains)) + else { - ui->tableWidget->showRow(item->row()); + // hide all rows + for (auto i = 0; i < ui->tableWidget->rowCount(); i++) + { + ui->tableWidget->hideRow(i); + } + + // show rows with matched filter + for (auto item : ui->tableWidget->findItems(filter, Qt::MatchContains)) + { + // If filter is empty findItems() for unknown reason returns nullptr items. + if (item) + { + ui->tableWidget->showRow(item->row()); + } + } } ui->tableWidget->blockSignals(false);