AutoTest: Avoid unneeded duplication on rebuild

When the rebuild of the tree model has been triggered
due to switching between grouping by filter or directory
it could happen that some children did not get merged
into others due to (insignificant) differences.
Avoid this visual duplication by finding items similar
to the one to be added and if there is one re-use this
instead.

Change-Id: Ife49593638e0af23ffc7353e305be4ea25eb2180
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2018-03-13 13:38:43 +01:00
parent db2e962a2f
commit 96ccb95e6f
9 changed files with 108 additions and 1 deletions

View File

@@ -317,6 +317,15 @@ bool TestTreeModel::sweepChildren(TestTreeItem *item)
return hasChanged;
}
static TestTreeItem *fullCopyOf(TestTreeItem *other)
{
QTC_ASSERT(other, return nullptr);
TestTreeItem *result = other->copyWithoutChildren();
for (int row = 0, count = other->childCount(); row < count; ++row)
result->appendChild(fullCopyOf(other->childItem(row)));
return result;
}
void TestTreeModel::insertItemInParent(TestTreeItem *item, TestTreeItem *root, bool groupingEnabled)
{
TestTreeItem *parentNode = root;
@@ -332,7 +341,16 @@ void TestTreeModel::insertItemInParent(TestTreeItem *item, TestTreeItem *root, b
root->appendChild(parentNode);
}
}
parentNode->appendChild(item);
// check if a similar item is already present (can happen for rebuild())
if (auto otherChild = parentNode->findChild(item)) {
// only handle item's children and add them to the already present one
for (int row = 0, count = item->childCount(); row < count; ++row)
otherChild->appendChild(fullCopyOf(item->childItem(row)));
delete item;
item = otherChild; // TODO needed? or early return?
} else {
parentNode->appendChild(item);
}
if (item->checked() != parentNode->checked())
revalidateCheckState(parentNode);
}