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 <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2020-09-23 10:48:29 +02:00
parent a7e1411ebf
commit ff06a409c2
2 changed files with 21 additions and 3 deletions

View File

@@ -65,7 +65,8 @@ TestTreeModel::TestTreeModel(TestCodeParser *parser) :
this, &TestTreeModel::markAllForRemoval); this, &TestTreeModel::markAllForRemoval);
connect(m_parser, &TestCodeParser::requestRemoval, connect(m_parser, &TestCodeParser::requestRemoval,
this, &TestTreeModel::markForRemoval); this, &TestTreeModel::markForRemoval);
connect(this, &QAbstractItemModel::dataChanged,
this, &TestTreeModel::onDataChanged);
setupParsingConnections(); setupParsingConnections();
} }
@@ -119,7 +120,7 @@ bool TestTreeModel::setData(const QModelIndex &index, const QVariant &value, int
TestTreeItem *item = static_cast<TestTreeItem *>(index.internalPointer()); TestTreeItem *item = static_cast<TestTreeItem *>(index.internalPointer());
if (item && item->setData(index.column(), value, role)) { if (item && item->setData(index.column(), value, role)) {
emit dataChanged(index, index); emit dataChanged(index, index, {role});
if (role == Qt::CheckStateRole) { if (role == Qt::CheckStateRole) {
Qt::CheckState checked = item->checked(); Qt::CheckState checked = item->checked();
if (item->hasChildren() && checked != Qt::PartiallyChecked) { if (item->hasChildren() && checked != Qt::PartiallyChecked) {
@@ -505,7 +506,7 @@ void TestTreeModel::revalidateCheckState(TestTreeItem *item)
newState = foundUnchecked ? Qt::Unchecked : Qt::Checked; newState = foundUnchecked ? Qt::Unchecked : Qt::Checked;
if (oldState != newState) { if (oldState != newState) {
item->setData(0, newState, Qt::CheckStateRole); 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) if (item->parent() != rootItem() && item->parentItem()->checked() != newState)
revalidateCheckState(item->parentItem()); revalidateCheckState(item->parentItem());
} }
@@ -518,6 +519,21 @@ void TestTreeModel::onParseResultReady(const TestParseResultPtr result)
handleParseResult(result.data(), rootNode); handleParseResult(result.data(), rootNode);
} }
void Autotest::TestTreeModel::onDataChanged(const QModelIndex &topLeft,
const QModelIndex &bottomRight,
const QVector<int> &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<TestTreeItem *>(itemForIndex(index(row, 0, parent))))
m_checkStateCache->insert(item, item->checked());
}
}
void TestTreeModel::handleParseResult(const TestParseResult *result, TestTreeItem *parentNode) void TestTreeModel::handleParseResult(const TestParseResult *result, TestTreeItem *parentNode)
{ {
const bool groupingEnabled = result->framework->grouping(); const bool groupingEnabled = result->framework->grouping();

View File

@@ -98,6 +98,8 @@ signals:
private: private:
void onParseResultReady(const TestParseResultPtr result); void onParseResultReady(const TestParseResultPtr result);
void onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
const QVector<int> &roles);
void handleParseResult(const TestParseResult *result, TestTreeItem *rootNode); void handleParseResult(const TestParseResult *result, TestTreeItem *rootNode);
void removeAllTestItems(); void removeAllTestItems();
void removeFiles(const QStringList &files); void removeFiles(const QStringList &files);