From ff06a409c2ce42f50967a540f2c9296a4d36f971 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Wed, 23 Sep 2020 10:48:29 +0200 Subject: [PATCH] AutoTest: Immediately update checkstate cache ...as soon a modification of the check states happens instead of waiting for the next parsing to update. Otherwise we might lose all changes that have been made without a parse. Change-Id: I33a92786742eb2b58c1cfcdb438412a2c5bbaed8 Reviewed-by: David Schulz --- src/plugins/autotest/testtreemodel.cpp | 22 +++++++++++++++++++--- src/plugins/autotest/testtreemodel.h | 2 ++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/plugins/autotest/testtreemodel.cpp b/src/plugins/autotest/testtreemodel.cpp index 9a7fd99d043..c538b5ff873 100644 --- a/src/plugins/autotest/testtreemodel.cpp +++ b/src/plugins/autotest/testtreemodel.cpp @@ -65,7 +65,8 @@ TestTreeModel::TestTreeModel(TestCodeParser *parser) : this, &TestTreeModel::markAllForRemoval); connect(m_parser, &TestCodeParser::requestRemoval, this, &TestTreeModel::markForRemoval); - + connect(this, &QAbstractItemModel::dataChanged, + this, &TestTreeModel::onDataChanged); setupParsingConnections(); } @@ -119,7 +120,7 @@ bool TestTreeModel::setData(const QModelIndex &index, const QVariant &value, int TestTreeItem *item = static_cast(index.internalPointer()); if (item && item->setData(index.column(), value, role)) { - emit dataChanged(index, index); + emit dataChanged(index, index, {role}); if (role == Qt::CheckStateRole) { Qt::CheckState checked = item->checked(); if (item->hasChildren() && checked != Qt::PartiallyChecked) { @@ -505,7 +506,7 @@ void TestTreeModel::revalidateCheckState(TestTreeItem *item) newState = foundUnchecked ? Qt::Unchecked : Qt::Checked; if (oldState != newState) { item->setData(0, newState, Qt::CheckStateRole); - emit dataChanged(item->index(), item->index()); + emit dataChanged(item->index(), item->index(), {Qt::CheckStateRole}); if (item->parent() != rootItem() && item->parentItem()->checked() != newState) revalidateCheckState(item->parentItem()); } @@ -518,6 +519,21 @@ void TestTreeModel::onParseResultReady(const TestParseResultPtr result) handleParseResult(result.data(), rootNode); } +void Autotest::TestTreeModel::onDataChanged(const QModelIndex &topLeft, + const QModelIndex &bottomRight, + const QVector &roles) +{ + const QModelIndex parent = topLeft.parent(); + QTC_ASSERT(parent == bottomRight.parent(), return); + if (!roles.isEmpty() && !roles.contains(Qt::CheckStateRole)) + return; + + for (int row = topLeft.row(), endRow = bottomRight.row(); row <= endRow; ++row) { + if (auto item = static_cast(itemForIndex(index(row, 0, parent)))) + m_checkStateCache->insert(item, item->checked()); + } +} + void TestTreeModel::handleParseResult(const TestParseResult *result, TestTreeItem *parentNode) { const bool groupingEnabled = result->framework->grouping(); diff --git a/src/plugins/autotest/testtreemodel.h b/src/plugins/autotest/testtreemodel.h index cdc697b6eda..1ce10d29811 100644 --- a/src/plugins/autotest/testtreemodel.h +++ b/src/plugins/autotest/testtreemodel.h @@ -98,6 +98,8 @@ signals: private: void onParseResultReady(const TestParseResultPtr result); + void onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, + const QVector &roles); void handleParseResult(const TestParseResult *result, TestTreeItem *rootNode); void removeAllTestItems(); void removeFiles(const QStringList &files);