From a7e1411ebff9211c364cdf510dfde60025df6427 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Thu, 24 Sep 2020 08:33:51 +0200 Subject: [PATCH] AutoTest: Cache failed states Avoid losing failed states of test while editing files that trigger a re-parse and may drop the original item. Change-Id: Ia66c7f61819d610cced42ff9f86449855b80da2a Reviewed-by: David Schulz --- src/plugins/autotest/testtreemodel.cpp | 13 ++++++++++++- src/plugins/autotest/testtreemodel.h | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/plugins/autotest/testtreemodel.cpp b/src/plugins/autotest/testtreemodel.cpp index 0c32a716a36..9a7fd99d043 100644 --- a/src/plugins/autotest/testtreemodel.cpp +++ b/src/plugins/autotest/testtreemodel.cpp @@ -93,6 +93,7 @@ void TestTreeModel::setupParsingConnections() m_parser->onStartupProjectChanged(project); m_checkStateCache = project ? AutotestPlugin::projectSettings(project)->checkStateCache() : nullptr; + m_failedStateCache.clear(); }); CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance(); @@ -131,6 +132,8 @@ bool TestTreeModel::setData(const QModelIndex &index, const QVariant &value, int if (item->parent() != rootItem() && item->parentItem()->checked() != checked) revalidateCheckState(item->parentItem()); // handle parent too return true; + } else if (role == FailedRole) { + m_failedStateCache.insert(item, true); } } return false; @@ -328,6 +331,7 @@ void TestTreeModel::clearFailedMarks() child->setData(0, false, FailedRole); }); } + m_failedStateCache.clear(); } void TestTreeModel::removeFiles(const QStringList &files) @@ -456,6 +460,10 @@ void TestTreeModel::insertItemInParent(TestTreeItem *item, TestTreeItem *root, b item->setData(0, cached.value(), Qt::CheckStateRole); else applyParentCheckState(parentNode, item); + // ..and the failed state if available + Utils::optional failed = m_failedStateCache.get(item); + if (failed.has_value()) + item->setData(0, *failed, FailedRole); parentNode->appendChild(item); revalidateCheckState(parentNode); } @@ -538,12 +546,15 @@ void TestTreeModel::handleParseResult(const TestParseResult *result, TestTreeIte TestTreeItem *newItem = result->createTestTreeItem(); QTC_ASSERT(newItem, return); - // restore former check state if available + // restore former check state and fail state if available newItem->forAllChildren([this](Utils::TreeItem *child) { auto childItem = static_cast(child); Utils::optional cached = m_checkStateCache->get(childItem); if (cached.has_value()) childItem->setData(0, cached.value(), Qt::CheckStateRole); + Utils::optional failed = m_failedStateCache.get(childItem); + if (failed.has_value()) + childItem->setData(0, *failed, FailedRole); }); // it might be necessary to "split" created item filterAndInsert(newItem, parentNode, groupingEnabled); diff --git a/src/plugins/autotest/testtreemodel.h b/src/plugins/autotest/testtreemodel.h index 9d07705e80b..cdc697b6eda 100644 --- a/src/plugins/autotest/testtreemodel.h +++ b/src/plugins/autotest/testtreemodel.h @@ -110,6 +110,7 @@ private: Internal::TestCodeParser *m_parser = nullptr; Internal::ItemDataCache *m_checkStateCache = nullptr; // not owned + Internal::ItemDataCache m_failedStateCache; }; namespace Internal {