Fix bug where index is wrong when a group is moved to the end from the same parent.
This triggered the bug: group->setParent(group->parentGroup()); Then index was group->parentGroup()->children().size() instead of size()-1.
This commit is contained in:
@@ -264,6 +264,10 @@ void Group::setParent(Group* parent, int index)
|
||||
|
||||
if (index == -1) {
|
||||
index = parent->children().size();
|
||||
|
||||
if (parentGroup() == parent) {
|
||||
index--;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_parent == parent && parent->children().indexOf(this) == index) {
|
||||
@@ -279,6 +283,7 @@ void Group::setParent(Group* parent, int index)
|
||||
}
|
||||
QObject::setParent(parent);
|
||||
Q_EMIT aboutToAdd(this, index);
|
||||
Q_ASSERT(index <= parent->m_children.size());
|
||||
parent->m_children.insert(index, this);
|
||||
}
|
||||
else {
|
||||
@@ -286,6 +291,7 @@ void Group::setParent(Group* parent, int index)
|
||||
m_parent->m_children.removeAll(this);
|
||||
m_parent = parent;
|
||||
QObject::setParent(parent);
|
||||
Q_ASSERT(index <= parent->m_children.size());
|
||||
parent->m_children.insert(index, this);
|
||||
}
|
||||
|
||||
|
||||
@@ -135,6 +135,14 @@ void TestGroup::testSignals()
|
||||
QCOMPARE(spyAboutToMove.count(), 0);
|
||||
QCOMPARE(spyMoved.count(), 0);
|
||||
|
||||
g2->setParent(root);
|
||||
QCOMPARE(spyAboutToAdd.count(), 2);
|
||||
QCOMPARE(spyAdded.count(), 2);
|
||||
QCOMPARE(spyAboutToRemove.count(), 0);
|
||||
QCOMPARE(spyRemoved.count(), 0);
|
||||
QCOMPARE(spyAboutToMove.count(), 0);
|
||||
QCOMPARE(spyMoved.count(), 0);
|
||||
|
||||
g2->setParent(root, 0);
|
||||
QCOMPARE(spyAboutToAdd.count(), 2);
|
||||
QCOMPARE(spyAdded.count(), 2);
|
||||
|
||||
Reference in New Issue
Block a user