diff options
author | Martin Jones <martin.jones@nokia.com> | 2010-03-09 06:37:59 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2010-03-09 06:37:59 (GMT) |
commit | 262c7eb1e93e8cafe8de8e49b53c218deb23639e (patch) | |
tree | de760fd8a9d4e54fd7d65391a0469ce6275c5fae | |
parent | 16a4138a74a1965ecb04fdf1957273f6e8c22071 (diff) | |
download | Qt-262c7eb1e93e8cafe8de8e49b53c218deb23639e.zip Qt-262c7eb1e93e8cafe8de8e49b53c218deb23639e.tar.gz Qt-262c7eb1e93e8cafe8de8e49b53c218deb23639e.tar.bz2 |
Handle itemsInserted/Removed/Moved() correctly for repeater.
Also make positioners react correctly to item moves.
Task-number: QT-745
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativepositioners.cpp | 7 | ||||
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativerepeater.cpp | 56 |
2 files changed, 55 insertions, 8 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativepositioners.cpp b/src/declarative/graphicsitems/qdeclarativepositioners.cpp index 1212e89..0f59a70 100644 --- a/src/declarative/graphicsitems/qdeclarativepositioners.cpp +++ b/src/declarative/graphicsitems/qdeclarativepositioners.cpp @@ -212,19 +212,22 @@ void QDeclarativeBasePositioner::prePositioning() QList<QGraphicsItem *> children = d->QGraphicsItemPrivate::children; qSort(children.begin(), children.end(), d->insertionOrder); + QPODVector<PositionedItem,8> oldItems; + positionedItems.copyAndClear(oldItems); for (int ii = 0; ii < children.count(); ++ii) { QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(ii)); if (!child) continue; PositionedItem *item = 0; PositionedItem posItem(child); - int wIdx = positionedItems.find(posItem); + int wIdx = oldItems.find(posItem); if (wIdx < 0) { d->watchChanges(child); positionedItems.append(posItem); item = &positionedItems[positionedItems.count()-1]; } else { - item = &positionedItems[wIdx]; + item = &oldItems[wIdx]; + positionedItems.append(*item); } if (child->opacity() <= 0.0 || !child->isVisible()) { item->isVisible = false; diff --git a/src/declarative/graphicsitems/qdeclarativerepeater.cpp b/src/declarative/graphicsitems/qdeclarativerepeater.cpp index e4cd499..b9696c8 100644 --- a/src/declarative/graphicsitems/qdeclarativerepeater.cpp +++ b/src/declarative/graphicsitems/qdeclarativerepeater.cpp @@ -296,6 +296,8 @@ void QDeclarativeRepeater::clear() void QDeclarativeRepeater::regenerate() { Q_D(QDeclarativeRepeater); + if (!isComponentComplete()) + return; clear(); @@ -312,23 +314,65 @@ void QDeclarativeRepeater::regenerate() } } -void QDeclarativeRepeater::itemsInserted(int, int) +void QDeclarativeRepeater::itemsInserted(int index, int count) { - regenerate(); + Q_D(QDeclarativeRepeater); + if (!isComponentComplete()) + return; + for (int i = 0; i < count; ++i) { + int modelIndex = index + i; + QDeclarativeItem *item = d->model->item(modelIndex); + if (item) { + item->setParent(parentItem()); + if (modelIndex < d->deletables.count()) + item->stackBefore(d->deletables.at(modelIndex)); + else + item->stackBefore(this); + d->deletables.insert(modelIndex, item); + } + } } -void QDeclarativeRepeater::itemsRemoved(int, int) +void QDeclarativeRepeater::itemsRemoved(int index, int count) { - regenerate(); + Q_D(QDeclarativeRepeater); + if (!isComponentComplete()) + return; + while (count--) { + QDeclarativeItem *item = d->deletables.takeAt(index); + if (item) { + item->setParentItem(this); + d->model->release(item); + } + } } -void QDeclarativeRepeater::itemsMoved(int,int,int) +void QDeclarativeRepeater::itemsMoved(int from, int to, int count) { - regenerate(); + Q_D(QDeclarativeRepeater); + if (!isComponentComplete()) + return; + QList<QDeclarativeItem*> removed; + int removedCount = count; + while (removedCount--) + removed << d->deletables.takeAt(from); + for (int i = 0; i < count; ++i) + d->deletables.insert(to + i, removed.at(i)); + for (int i = 0; i < d->model->count(); ++i) { + if (i < from && i < to) + continue; + QDeclarativeItem *item = d->deletables.at(i); + if (i < d->deletables.count()-1) + item->stackBefore(d->deletables.at(i+1)); + else + item->stackBefore(this); + } } void QDeclarativeRepeater::modelReset() { + if (!isComponentComplete()) + return; regenerate(); } |