QGraphicsScene: stabilize stacking order of toplevel items
Removing and adding toplevel items could result in invalid stacking order (not corresponding to insertion order). Task-number: QTBUG-19316 Change-Id: Ia8646784a2181cfa936b101e2adaf7e7e73bb83d Reviewed-by: Andreas Aardal Hanssen <andreas@hanssen.name>bb10
parent
9911550fa7
commit
6841dd6ecc
|
|
@ -392,7 +392,7 @@ void QGraphicsScenePrivate::_q_emitUpdated()
|
|||
*/
|
||||
void QGraphicsScenePrivate::registerTopLevelItem(QGraphicsItem *item)
|
||||
{
|
||||
item->d_ptr->ensureSequentialSiblingIndex();
|
||||
ensureSequentialTopLevelSiblingIndexes();
|
||||
needSortTopLevelItems = true; // ### maybe false
|
||||
item->d_ptr->siblingIndex = topLevelItems.size();
|
||||
topLevelItems.append(item);
|
||||
|
|
|
|||
|
|
@ -242,6 +242,7 @@ private slots:
|
|||
void style();
|
||||
void sorting_data();
|
||||
void sorting();
|
||||
void insertionOrder();
|
||||
void changedSignal_data();
|
||||
void changedSignal();
|
||||
void stickyFocus_data();
|
||||
|
|
@ -3633,6 +3634,42 @@ void tst_QGraphicsScene::sorting()
|
|||
<< t_1);
|
||||
}
|
||||
|
||||
void tst_QGraphicsScene::insertionOrder()
|
||||
{
|
||||
QGraphicsScene scene;
|
||||
const int numItems = 5;
|
||||
QList<QGraphicsItem*> items;
|
||||
|
||||
for (int i = 0; i < numItems; ++i) {
|
||||
QGraphicsRectItem* item = new QGraphicsRectItem(i * 20, i * 20, 200, 200);
|
||||
item->setData(0, i);
|
||||
items.append(item);
|
||||
scene.addItem(item);
|
||||
}
|
||||
|
||||
{
|
||||
QList<QGraphicsItem*> itemList = scene.items();
|
||||
QCOMPARE(itemList.count(), numItems);
|
||||
for (int i = 0; i < itemList.count(); ++i) {
|
||||
QCOMPARE(numItems-1-i, itemList.at(i)->data(0).toInt());
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < items.size(); ++i)
|
||||
{
|
||||
scene.removeItem(items.at(i));
|
||||
scene.addItem(items.at(i));
|
||||
}
|
||||
|
||||
{
|
||||
QList<QGraphicsItem*> itemList = scene.items();
|
||||
QCOMPARE(itemList.count(), numItems);
|
||||
for (int i = 0; i < itemList.count(); ++i) {
|
||||
QCOMPARE(numItems-1-i, itemList.at(i)->data(0).toInt());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ChangedListener : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
|
|||
Loading…
Reference in New Issue