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 <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2020-09-24 08:33:51 +02:00
parent 6269d09763
commit a7e1411ebf
2 changed files with 13 additions and 1 deletions

View File

@@ -93,6 +93,7 @@ void TestTreeModel::setupParsingConnections()
m_parser->onStartupProjectChanged(project); m_parser->onStartupProjectChanged(project);
m_checkStateCache = project ? AutotestPlugin::projectSettings(project)->checkStateCache() m_checkStateCache = project ? AutotestPlugin::projectSettings(project)->checkStateCache()
: nullptr; : nullptr;
m_failedStateCache.clear();
}); });
CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance(); 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) if (item->parent() != rootItem() && item->parentItem()->checked() != checked)
revalidateCheckState(item->parentItem()); // handle parent too revalidateCheckState(item->parentItem()); // handle parent too
return true; return true;
} else if (role == FailedRole) {
m_failedStateCache.insert(item, true);
} }
} }
return false; return false;
@@ -328,6 +331,7 @@ void TestTreeModel::clearFailedMarks()
child->setData(0, false, FailedRole); child->setData(0, false, FailedRole);
}); });
} }
m_failedStateCache.clear();
} }
void TestTreeModel::removeFiles(const QStringList &files) 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); item->setData(0, cached.value(), Qt::CheckStateRole);
else else
applyParentCheckState(parentNode, item); applyParentCheckState(parentNode, item);
// ..and the failed state if available
Utils::optional<bool> failed = m_failedStateCache.get(item);
if (failed.has_value())
item->setData(0, *failed, FailedRole);
parentNode->appendChild(item); parentNode->appendChild(item);
revalidateCheckState(parentNode); revalidateCheckState(parentNode);
} }
@@ -538,12 +546,15 @@ void TestTreeModel::handleParseResult(const TestParseResult *result, TestTreeIte
TestTreeItem *newItem = result->createTestTreeItem(); TestTreeItem *newItem = result->createTestTreeItem();
QTC_ASSERT(newItem, return); 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) { newItem->forAllChildren([this](Utils::TreeItem *child) {
auto childItem = static_cast<TestTreeItem *>(child); auto childItem = static_cast<TestTreeItem *>(child);
Utils::optional<Qt::CheckState> cached = m_checkStateCache->get(childItem); Utils::optional<Qt::CheckState> cached = m_checkStateCache->get(childItem);
if (cached.has_value()) if (cached.has_value())
childItem->setData(0, cached.value(), Qt::CheckStateRole); childItem->setData(0, cached.value(), Qt::CheckStateRole);
Utils::optional<bool> failed = m_failedStateCache.get(childItem);
if (failed.has_value())
childItem->setData(0, *failed, FailedRole);
}); });
// it might be necessary to "split" created item // it might be necessary to "split" created item
filterAndInsert(newItem, parentNode, groupingEnabled); filterAndInsert(newItem, parentNode, groupingEnabled);

View File

@@ -110,6 +110,7 @@ private:
Internal::TestCodeParser *m_parser = nullptr; Internal::TestCodeParser *m_parser = nullptr;
Internal::ItemDataCache<Qt::CheckState> *m_checkStateCache = nullptr; // not owned Internal::ItemDataCache<Qt::CheckState> *m_checkStateCache = nullptr; // not owned
Internal::ItemDataCache<bool> m_failedStateCache;
}; };
namespace Internal { namespace Internal {