aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2011-07-27 18:30:05 +1000
committerQt by Nokia <qt-info@nokia.com>2011-07-28 07:12:34 +0200
commite2b5681b1adab83555c7307b05f508d796a1152b (patch)
treec19df1b0e1ab62a3694b53371803ff76a054fd3c /src
parent14496b18a67982ee25ed43aed6b6bcd7d6fa23ee (diff)
Fix moving of multiple items, and moving items backwards
To fix backward movements, all backward movements are now flipped into forward movements (as is done in ListModel implemenation). Movement of multiple items wasn't working as views weren't removing the right indexes in these cases. Task-number: QTBUG-19208 Change-Id: I9866ddabc241c066bb77329a6761d500d79aaf61 Reviewed-on: http://codereview.qt.nokia.com/2262 Reviewed-by: Bea Lam <bea.lam@nokia.com> Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Diffstat (limited to 'src')
-rw-r--r--src/declarative/items/qsggridview.cpp19
-rw-r--r--src/declarative/items/qsgitemview.cpp12
-rw-r--r--src/declarative/items/qsgitemview_p_p.h1
-rw-r--r--src/declarative/items/qsglistview.cpp21
4 files changed, 35 insertions, 18 deletions
diff --git a/src/declarative/items/qsggridview.cpp b/src/declarative/items/qsggridview.cpp
index 5531c153a3..214481a288 100644
--- a/src/declarative/items/qsggridview.cpp
+++ b/src/declarative/items/qsggridview.cpp
@@ -1497,11 +1497,13 @@ void QSGGridView::itemsMoved(int from, int to, int count)
}
d->moveReason = QSGGridViewPrivate::Other;
- FxGridItemSG *firstVisible = static_cast<FxGridItemSG*>(d->firstVisibleItem());
- QHash<int,FxGridItemSG*> moved;
- int moveByCount = 0;
bool movingBackwards = from > to;
+ d->adjustMoveParameters(&from, &to, &count);
+
+ QHash<int,FxGridItemSG*> moved;
+ int moveByCount = 0;
+ FxGridItemSG *firstVisible = static_cast<FxGridItemSG*>(d->firstVisibleItem());
int firstItemIndex = firstVisible ? firstVisible->index : -1;
// if visibleItems.first() is above the content start pos, and the items
@@ -1532,19 +1534,20 @@ void QSGGridView::itemsMoved(int from, int to, int count)
}
}
- int remaining = count;
+ int movedCount = 0;
int endIndex = d->visibleIndex;
it = d->visibleItems.begin();
while (it != d->visibleItems.end()) {
FxViewItem *item = *it;
- if (remaining && item->index >= to && item->index < to + count) {
+ if (movedCount < count && item->index >= to && item->index < to + count) {
// place items in the target position, reusing any existing items
- FxGridItemSG *movedItem = moved.take(item->index);
+ int targetIndex = item->index + movedCount;
+ FxGridItemSG *movedItem = moved.take(targetIndex);
if (!movedItem)
- movedItem = static_cast<FxGridItemSG*>(d->createItem(item->index));
+ movedItem = static_cast<FxGridItemSG*>(d->createItem(targetIndex));
it = d->visibleItems.insert(it, movedItem);
++it;
- --remaining;
+ ++movedCount;
} else {
if (item->index != -1) {
if (item->index >= to) {
diff --git a/src/declarative/items/qsgitemview.cpp b/src/declarative/items/qsgitemview.cpp
index 18015edf44..bcb4a8a97c 100644
--- a/src/declarative/items/qsgitemview.cpp
+++ b/src/declarative/items/qsgitemview.cpp
@@ -1089,6 +1089,18 @@ int QSGItemViewPrivate::mapFromModel(int modelIndex) const
return -1; // Not in visibleList
}
+void QSGItemViewPrivate::adjustMoveParameters(int *from, int *to, int *count) const
+{
+ if (*from > *to) {
+ // Only move forwards - flip if backwards moving
+ int tfrom = *from;
+ int tto = *to;
+ *from = tto;
+ *to = tto + *count;
+ *count = tfrom - tto;
+ }
+}
+
void QSGItemViewPrivate::init()
{
Q_Q(QSGItemView);
diff --git a/src/declarative/items/qsgitemview_p_p.h b/src/declarative/items/qsgitemview_p_p.h
index bc2e45ff88..3113a8b754 100644
--- a/src/declarative/items/qsgitemview_p_p.h
+++ b/src/declarative/items/qsgitemview_p_p.h
@@ -92,6 +92,7 @@ public:
FxViewItem *visibleItem(int modelIndex) const;
FxViewItem *firstVisibleItem() const;
int mapFromModel(int modelIndex) const;
+ void adjustMoveParameters(int *from, int *to, int *count) const;
virtual void init();
virtual void updateCurrent(int modelIndex);
diff --git a/src/declarative/items/qsglistview.cpp b/src/declarative/items/qsglistview.cpp
index 7fbfe3c68d..37b027cd36 100644
--- a/src/declarative/items/qsglistview.cpp
+++ b/src/declarative/items/qsglistview.cpp
@@ -1813,11 +1813,13 @@ void QSGListView::itemsMoved(int from, int to, int count)
}
d->moveReason = QSGListViewPrivate::Other;
- FxViewItem *firstVisible = d->firstVisibleItem();
- QHash<int,FxViewItem*> moved;
- int moveBy = 0;
bool movingBackwards = from > to;
+ d->adjustMoveParameters(&from, &to, &count);
+
+ QHash<int,FxViewItem*> moved;
+ int moveBy = 0;
+ FxViewItem *firstVisible = d->firstVisibleItem();
int firstItemIndex = firstVisible ? firstVisible->index : -1;
// if visibleItems.first() is above the content start pos, and the items
@@ -1845,21 +1847,20 @@ void QSGListView::itemsMoved(int from, int to, int count)
}
}
- int remaining = count;
+ int movedCount = 0;
int endIndex = d->visibleIndex;
it = d->visibleItems.begin();
while (it != d->visibleItems.end()) {
FxViewItem *item = *it;
- if (remaining && item->index >= to && item->index < to + count) {
+ if (movedCount < count && item->index >= to && item->index < to + count) {
// place items in the target position, reusing any existing items
- FxViewItem *movedItem = moved.take(item->index);
+ int targetIndex = item->index + movedCount;
+ FxViewItem *movedItem = moved.take(targetIndex);
if (!movedItem)
- movedItem = d->createItem(item->index);
- if (item->index <= firstVisible->index)
- moveBy -= movedItem->size();
+ movedItem = d->createItem(targetIndex);
it = d->visibleItems.insert(it, movedItem);
++it;
- --remaining;
+ ++movedCount;
} else {
if (item->index != -1) {
if (item->index >= to) {