summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2009-09-11 00:08:06 (GMT)
committerMartin Jones <martin.jones@nokia.com>2009-09-11 00:08:06 (GMT)
commit804c9ef64085fafe6f12b92e5dd40e595ed3460f (patch)
tree0c922afabe851018cb51e226f8a2583c13da6480
parentff9d5102534416945b7884ad735a732eac741802 (diff)
downloadQt-804c9ef64085fafe6f12b92e5dd40e595ed3460f.zip
Qt-804c9ef64085fafe6f12b92e5dd40e595ed3460f.tar.gz
Qt-804c9ef64085fafe6f12b92e5dd40e595ed3460f.tar.bz2
Handle itemsMoved() in GridView.
-rw-r--r--src/declarative/fx/qfxgridview.cpp63
-rw-r--r--src/declarative/fx/qfxgridview.h1
2 files changed, 64 insertions, 0 deletions
diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp
index dfb04ad..f49375a 100644
--- a/src/declarative/fx/qfxgridview.cpp
+++ b/src/declarative/fx/qfxgridview.cpp
@@ -723,6 +723,7 @@ void QFxGridView::setModel(const QVariant &model)
if (d->model) {
disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int)));
disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int)));
+ disconnect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int)));
disconnect(d->model, SIGNAL(createdItem(int, QFxItem*)), this, SLOT(createdItem(int,QFxItem*)));
disconnect(d->model, SIGNAL(destroyingItem(QFxItem*)), this, SLOT(destroyingItem(QFxItem*)));
}
@@ -751,6 +752,7 @@ void QFxGridView::setModel(const QVariant &model)
d->updateCurrent(d->currentIndex);
connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int)));
connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int)));
+ connect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int)));
connect(d->model, SIGNAL(createdItem(int, QFxItem*)), this, SLOT(createdItem(int,QFxItem*)));
connect(d->model, SIGNAL(destroyingItem(QFxItem*)), this, SLOT(destroyingItem(QFxItem*)));
refill();
@@ -1356,6 +1358,67 @@ void QFxGridView::destroyRemoved()
d->layout();
}
+void QFxGridView::itemsMoved(int from, int to, int count)
+{
+ Q_D(QFxGridView);
+ QHash<int,FxGridItem*> moved;
+
+ QList<FxGridItem*>::Iterator it = d->visibleItems.begin();
+ while (it != d->visibleItems.end()) {
+ FxGridItem *item = *it;
+ if (item->index >= from && item->index < from + count) {
+ // take the items that are moving
+ item->index += (to-from);
+ moved.insert(item->index, item);
+ it = d->visibleItems.erase(it);
+ } else {
+ if (item->index > from && item->index != -1) {
+ // move everything after the moved items.
+ item->index -= count;
+ }
+ ++it;
+ }
+ }
+
+ int remaining = count;
+ int endIndex = d->visibleIndex;
+ it = d->visibleItems.begin();
+ while (it != d->visibleItems.end()) {
+ FxGridItem *item = *it;
+ if (remaining && item->index >= to && item->index < to + count) {
+ // place items in the target position, reusing any existing items
+ FxGridItem *movedItem = moved.take(item->index);
+ if (!movedItem)
+ movedItem = d->createItem(item->index);
+ it = d->visibleItems.insert(it, movedItem);
+ ++it;
+ --remaining;
+ } else {
+ if (item->index != -1) {
+ if (item->index >= to) {
+ // update everything after the moved items.
+ item->index += count;
+ }
+ endIndex = item->index;
+ }
+ ++it;
+ }
+ }
+
+ // If we have moved items to the end of the visible items
+ // then add any existing moved items that we have
+ while (FxGridItem *item = moved.take(endIndex+1)) {
+ d->visibleItems.append(item);
+ ++endIndex;
+ }
+
+ // Whatever moved items remain are no longer visible items.
+ while (moved.count())
+ d->releaseItem(moved.take(moved.begin().key()));
+
+ d->layout();
+}
+
void QFxGridView::createdItem(int index, QFxItem *item)
{
Q_D(QFxGridView);
diff --git a/src/declarative/fx/qfxgridview.h b/src/declarative/fx/qfxgridview.h
index 954f9fe..734039c 100644
--- a/src/declarative/fx/qfxgridview.h
+++ b/src/declarative/fx/qfxgridview.h
@@ -130,6 +130,7 @@ private Q_SLOTS:
void trackedPositionChanged();
void itemsInserted(int index, int count);
void itemsRemoved(int index, int count);
+ void itemsMoved(int from, int to, int count);
void destroyRemoved();
void createdItem(int index, QFxItem *item);
void destroyingItem(QFxItem *item);