aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2011-06-20 08:31:50 +1000
committerAndrew den Exter <andrew.den-exter@nokia.com>2011-06-20 08:31:50 +1000
commit7031ca0e1d896336334f5a788baac6c09a9ce703 (patch)
tree49fb1a7386e834e276832e9c665ffe16ec9c694b
parent658ca667ad9a3dca6313886f8d49d254b5161c1b (diff)
Add QDeclarativeChangeSet.
Takes a sequence of model changes and reorders and compresses them so that like changes are grouped together and are ordered from start to end. The order is Removed, Inserted, Moved then Changed.
-rw-r--r--src/declarative/util/qdeclarativechangeset.cpp440
-rw-r--r--src/declarative/util/qdeclarativechangeset_p.h160
-rw-r--r--src/declarative/util/util.pri2
-rw-r--r--tests/auto/declarative/declarative.pro1
-rw-r--r--tests/auto/declarative/qdeclarativechangeset/qdeclarativechangeset.pro17
-rw-r--r--tests/auto/declarative/qdeclarativechangeset/tst_qdeclarativechangeset.cpp614
6 files changed, 1234 insertions, 0 deletions
diff --git a/src/declarative/util/qdeclarativechangeset.cpp b/src/declarative/util/qdeclarativechangeset.cpp
new file mode 100644
index 0000000000..d9a508ba13
--- /dev/null
+++ b/src/declarative/util/qdeclarativechangeset.cpp
@@ -0,0 +1,440 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qdeclarativechangeset_p.h"
+
+void QDeclarativeChangeSet::insertInsert(int start, int end)
+{
+ const int count = end - start;
+
+ // Moved signals.
+ QVector<Move>::iterator move = m_moves.begin();
+ for (; move != m_moves.end() && start >= move->maximum(); ++move) {}
+ for (; move != m_moves.end() && end >= move->minimum(); ++move) {
+ if (start <= move->tstart) {
+ move->tstart += count;
+ move->tend += count;
+ } else if (start < move->tend) {
+ int relativeStart = start - move->tstart;
+
+ move = m_moves.insert(move, Move(
+ move->fstart + count, move->fstart + count + relativeStart, move->tstart));
+ ++move;
+ move->fstart += relativeStart;
+ move->tstart += count + relativeStart;
+ move->tend += count;
+
+ start -= relativeStart;
+ end -= relativeStart;
+ } else {
+ start -= move->count();
+ end -= move->count();
+ }
+
+ if (start <= move->fstart) {
+ move->fstart += count;
+ move->fend += count;
+ } else if (start < move->tstart) {
+ start += move->count();
+ end += move->count();
+ }
+
+ }
+ for (; move != m_moves.end(); ++move) {
+ move->fstart += count;
+ move->fend += count;
+ move->tstart += count;
+ move->tend += count;
+ }
+
+ // Inserted signals.
+ QVector<Insert>::iterator insert = m_inserts.begin();
+ for (; insert != m_inserts.end(); ++insert) {
+ if (start < insert->start) {
+ insert = m_inserts.insert(insert, Insert(start, end));
+ break;
+ } else if (start <= insert->end) {
+ insert->end += count;
+ break;
+ }
+ }
+ if (insert == m_inserts.end()) {
+ m_inserts.append(Insert(start, end));
+ } else for (++insert; insert != m_inserts.end(); ++insert) {
+ insert->start += count;
+ insert->end += count;
+ }
+
+
+ // Changed signals.
+ QVector<Change>::iterator change = m_changes.begin();
+ for (; change != m_changes.end() && start != change->start && start < change->end; ++change) {
+ if (start > change->start) {
+ int relativeStart = start - change->start;
+ change = m_changes.insert(change, Change(change->start, change->start + relativeStart));
+ ++change;
+ change->start += count + relativeStart;
+ change->end += count - relativeStart;
+ break;
+ }
+ }
+ for (; change != m_changes.end(); ++change) {
+ change->start += count;
+ change->end += count;
+ }
+}
+
+void QDeclarativeChangeSet::insertRemove(int start, int end)
+{
+ // Changed Signals.
+ QVector<Change>::iterator change = m_changes.begin();
+ for (; change != m_changes.end() && start >= change->end; ++change) {}
+ for (; change != m_changes.end() && end < change->start; ++change) {
+ const int removeCount = qMin(change->end, end) - qMax(change->start, start);
+ change->end -= removeCount;
+ if (change->start == change->end) {
+ change = m_changes.erase(change);
+ } else if (start < change->start) {
+ change->start = start;
+ }
+ }
+ const int count = end - start;
+ for (; change != m_changes.end(); ++change) {
+ change->start -= count;
+ change->end -= count;
+ }
+
+ QVector<Remove> removeChanges;
+
+ // Moved signals.
+ QVector<Move>::iterator move = m_moves.begin();
+ for (; move != m_moves.end() && start >= move->maximum(); ++move) {}
+ for (; move != m_moves.end() && end >= move->minimum(); ++move) {
+ if (move->fstart < move->tstart) {
+ if (start < move->fstart) {
+ const int difference = move->fstart - start;
+ move->fend -= difference;
+ move->fstart = start;
+ move->tstart -= difference;
+ move->tend -= difference;
+
+ removeChanges.append(Remove(start, start + difference));
+ end -= difference;
+ }
+ if (end < move->tstart) {
+ move->tstart -= end - start;
+ move->tend -= end - start;
+ } else if (start < move->tend) {
+ const int difference = qMin(move->tend, end) - move->tstart;
+ removeChanges.append(Remove(
+ move->fstart , move->fstart + difference));
+ end -= difference;
+
+ move->fend -= difference;
+ move->tstart -= end - start;
+ move->tend -= end - start + difference;
+ }
+ start += move->count();
+ end += move->count();
+ } else {
+ if (start < move->tend) {
+ const int offset = qMax(0, start - move->tstart);
+ const int difference = qMin(move->tend, end) - qMax(move->tstart, start);
+
+ removeChanges.append(Remove(
+ move->fstart + offset, move->fstart + offset + difference));
+ start -= offset;
+ end -= offset + difference;
+
+ move->fend -= difference;
+ move->tstart = start;
+ move->tend = start + move->fend - move->fstart;
+ } else {
+ start -= move->count();
+ end -= move->count();
+ }
+
+ move->fstart -= end - start;
+ move->fend -= end - start;
+
+ if (start > move->fstart) {
+ const int offset = start - move->fstart;
+ const int difference = qMin(move->fend, end) - start;
+ removeChanges.append(Remove(
+ move->fstart + end - start + offset + difference ,
+ move->fend + end - start + offset));
+ end -= offset;
+ move->fstart += offset;
+ move->fend += offset;
+ }
+ }
+
+ if (move->tstart == move->tend || move->fstart == move->tstart) {
+ move = m_moves.erase(move);
+ --move;
+ }
+ }
+ for (; move != m_moves.end(); ++move) {
+ move->fstart -= count;
+ move->fend -= count;
+ move->tstart -= count;
+ move->tend -= count;
+ }
+
+ if (start != end)
+ removeChanges.append(Remove(start, end));
+
+ foreach (const Remove &r, removeChanges) {
+ int start = r.start;
+ int end = r.end;
+
+ QVector<Insert>::iterator insert = m_inserts.end() - 1;
+ for (const int count = end - start; insert != m_inserts.begin() - 1 && insert->start >= end; --insert) {
+ insert->start -= count;
+ insert->end -= count;
+ }
+ for (; insert != m_inserts.begin() - 1 && insert->end > start; --insert) {
+ const int removeCount = qMin(insert->end, end) - qMax(insert->start, start);
+ insert->end -= removeCount;
+ if (insert->start == insert->end) {
+ insert = m_inserts.erase(insert);
+ } else if (start < insert->start) {
+ insert->end -= insert->start - start;
+ insert->start = start;
+ } else {
+ start -= insert->count();
+ end -= insert->count();
+ }
+ end -= removeCount;
+ if (start == end)
+ return;
+ }
+ // Adjust the index to compensate for any inserts prior to the remove position..
+ for (; insert != m_inserts.begin() - 1; --insert) {
+ start -= insert->count();
+ end -= insert->count();
+ }
+
+ // Removed signals.
+ QVector<Remove>::iterator remove = m_removes.begin();
+ for (; remove != m_removes.end(); ++remove) {
+ if (end < remove->start) {
+ remove = m_removes.insert(remove, Remove(start, end));
+ break;
+ } else if (start <= remove->start) {
+ remove->end += end - remove->start;
+ remove->start = start;
+
+ QVector<Remove>::iterator rbegin = remove;
+ QVector<Remove>::iterator rend = ++rbegin;
+ for (; rend != m_removes.end() && rend->start <= remove->end; ++rend)
+ remove->end += rend->count();
+ if (rbegin != rend) {
+ remove = m_removes.erase(rbegin, rend);
+ }
+ break;
+ }
+ }
+ if (remove != m_removes.end()) {
+ const int count = end - start;
+ for (++remove; remove != m_removes.end(); ++remove) {
+ remove->start -= count;
+ remove->end -= count;
+ }
+ } else {
+ m_removes.append(Remove(start, end));
+ }
+ }
+}
+
+void QDeclarativeChangeSet::insertMove(int start, int end, int to)
+{
+ QVector<Insert> insertChanges;
+ QVector<Move> moveChanges;
+
+ int fStart = start;
+ int fTo = to;
+ int fEnd = end;
+ int &bStart = fTo;
+ int bEnd = to + end - start;
+
+ if (start > to) {
+ qSwap(fStart, bStart);
+ qSwap(fEnd, bEnd);
+ }
+
+ // Inserted signals.
+ QVector<Insert>::iterator insert = m_inserts.begin();
+ if (start < to) {
+ for (; insert != m_inserts.end() && fStart >= insert->end; ++insert) {}
+ for (; insert != m_inserts.end() && fEnd > insert->start; ++insert) {
+ const int removeCount = qMin(insert->end, fEnd) - qMax(insert->start, fStart);
+ const int relativeStart = fStart - insert->start;
+ const int relativeEnd = qMax(0, fEnd - insert->end);
+
+ insert->end -= removeCount;
+ if (insert->start == insert->end) {
+ insert = m_inserts.erase(insert);
+ --insert;
+ }
+
+ if (relativeStart < 0) {
+ moveChanges.append(Move(fStart, fStart - relativeStart, fTo + relativeEnd));
+ fTo -= relativeStart;
+ }
+
+ fTo += removeCount;
+ insertChanges.append(Insert(bEnd - removeCount, bEnd));
+ }
+ } else {
+ for (; insert != m_inserts.end() && bStart >= insert->end; ++insert) {}
+ for (; insert != m_inserts.end() && bEnd > insert->start; ++insert) {
+ const int removeCount = qMin(insert->end, bEnd) - qMax(insert->start, bStart);
+ const int relativeStart = bStart - insert->start;
+
+ insert->start += removeCount;
+ if (insert->start == insert->end) {
+ insert->start = fStart;
+ insert->end = insert->start + removeCount;
+ } else {
+ insert = m_inserts.insert(insert, Insert(fStart, fStart + removeCount));
+ ++insert;
+ }
+ if (relativeStart < 0) {
+ moveChanges.append(Move(fStart, fStart - relativeStart, fTo + removeCount));
+ fStart -= relativeStart;
+ fTo -= relativeStart;
+ }
+ fStart += removeCount;
+ fTo += removeCount;
+ }
+ }
+
+ if (fTo != bEnd)
+ moveChanges.append(Move(fStart, fStart + bEnd - fTo, fTo));
+
+ QVector<Insert>::iterator it = insertChanges.begin();
+ for (insert = m_inserts.begin(); it != insertChanges.end() && insert != m_inserts.end();++insert) {
+ if (it->start < insert->start) {
+ insert = m_inserts.insert(insert, *it);
+ ++it;
+ } else if (it->start <= insert->end) {
+ insert->end += it->count();
+ ++it;
+ }
+ }
+ for (; it != insertChanges.end(); ++it)
+ m_inserts.append(*it);
+
+ // Insert queued moved signals ordered by destination position.
+ QVector<Move>::iterator move = m_moves.begin();
+ if (start > to) {
+ for (QVector<Move>::iterator it = moveChanges.begin(); it != moveChanges.end(); ++it) {
+ it->fend += it->tstart - it->fstart;
+ it->tend -=it->tstart - it->fstart;
+ qSwap(it->fstart, it->tstart);
+ for (; move != m_moves.end() && it->to >= qMin(move->fstart, move->tstart); ++move) {}
+ move = m_moves.insert(move, *it);
+ }
+ } else {
+ for (QVector<Move>::iterator it = moveChanges.begin(); it != moveChanges.end(); ++it) {
+ for (; move != m_moves.end() && it->start >= qMin(move->fstart, move->tstart); ++move) {}
+ move = m_moves.insert(move, *it);
+ }
+ }
+}
+
+void QDeclarativeChangeSet::insertChange(int start, int end)
+{
+ QVector<Change> filteredChanges;
+
+ // Inserted signals (don't emit change signals on new items).
+ QVector<Insert>::iterator insert = m_inserts.begin();
+ for (; insert != m_inserts.end() && start >= insert->end; ++insert) {}
+ for (; insert != m_inserts.end() && end > insert->start; ++insert) {
+ if (start < insert->start)
+ filteredChanges.append(Change(start, insert->start));
+ start = insert->end;
+ }
+ if (start < end)
+ filteredChanges.append(Change(start, end));
+
+ // Find the union of the existing and filtered sets of change signals.
+ QVector<Change>::iterator change = m_changes.begin();
+ for (QVector<Change>::iterator it = filteredChanges.begin(); it != filteredChanges.end(); ++it) {
+ for (; change != m_changes.end() && change->end < it->start; ++change) {}
+ if (change == m_changes.end() || change->start > it->end) {
+ change = m_changes.insert(change, *it);
+ } else {
+ if (it->start < change->start)
+ change->start = it->start;
+
+ if (it->end > change->end) {
+ change->end = it->end;
+ QVector<Change>::iterator rbegin = change;
+ QVector<Change>::iterator rend = ++rbegin;
+ for (; rend != m_changes.end() && rend->start <= change->end; ++rend) {
+ if (rend->end > change->end)
+ change->end = rend->end;
+ }
+ if (rbegin != rend) {
+ change = m_changes.erase(rbegin, rend);
+ --change;
+ }
+ }
+ }
+ }
+
+}
+
+QDebug operator <<(QDebug debug, const QDeclarativeChangeSet &set)
+{
+ foreach (const QDeclarativeChangeSet::Remove &remove, set.removes())
+ debug.nospace() << "QDeclarativeChangeSet::Remove(" << remove.start << "," << remove.end << ")";
+ foreach (const QDeclarativeChangeSet::Insert &insert, set.inserts())
+ debug.nospace() << "QDeclarativeChangeSet::Insert(" << insert.start << "," << insert.end << ")";
+ foreach (const QDeclarativeChangeSet::Move &move, set.moves())
+ debug.nospace() << "QDeclarativeChangeSet::Move(" << move.start << "," << move.end << "," << move.to << ")";
+ foreach (const QDeclarativeChangeSet::Change &change, set.changes())
+ debug.nospace() << "QDeclarativeChangeSet::Change(" << change.start << "," << change.end << ")";
+ return debug;
+}
+
diff --git a/src/declarative/util/qdeclarativechangeset_p.h b/src/declarative/util/qdeclarativechangeset_p.h
new file mode 100644
index 0000000000..f911e658ea
--- /dev/null
+++ b/src/declarative/util/qdeclarativechangeset_p.h
@@ -0,0 +1,160 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QDECLARATIVECHANGESET_P_H
+#define QDECLARATIVECHANGESET_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qdebug.h>
+#include <QtCore/qvector.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_AUTOTEST_EXPORT QDeclarativeChangeSet
+{
+public:
+ struct Insert
+ {
+ Insert() {}
+ Insert(int start, int end) : start(start), end(end) {}
+
+ int count() const { return end - start; }
+
+ int start;
+ int end;
+ };
+
+ struct Remove
+ {
+ Remove() {}
+ Remove(int start, int end) : start(start), end(end) {}
+
+ int count() const { return end - start; }
+
+ int start;
+ int end;
+ };
+
+ struct Move
+ {
+ Move() {}
+ Move(int start, int end, int to) : fstart(start), fend(end), tstart(to), tend(to + end - start) {}
+
+ int minimum() const { return qMin(fstart, tstart); }
+ int maximum() const { return qMax(fend, tend); }
+ int count() const { return fend - fstart; }
+
+ union {
+ int start;
+ int fstart;
+ };
+ union {
+ int end;
+ int fend;
+ };
+ union {
+ int to;
+ int tstart;
+ };
+ int tend;
+ };
+
+ struct Change
+ {
+ Change() {}
+ Change(int start, int end) : start(start), end(end) {}
+
+ int count() const { return end - start; }
+
+ int start;
+ int end;
+ };
+
+ const QVector<Remove> &removes() const { return m_removes; }
+ const QVector<Insert> &inserts() const { return m_inserts; }
+ const QVector<Move> &moves() const { return m_moves; }
+ const QVector<Change> &changes() const {return m_changes; }
+
+ void insertInsert(int start, int end);
+ void insertRemove(int start, int end);
+ void insertMove(int start, int end, int to);
+ void insertChange(int start, int end);
+
+ void appendInsert(int start, int end) { m_inserts.append(Insert(start, end)); }
+ void appendRemove(int start, int end) { m_removes.append(Remove(start, end)); }
+ void appendMove(int start, int end, int to) { m_moves.append(Move(start, end, to)); }
+ void appendChange(int start, int end) { m_changes.append(Change(start, end)); }
+
+ void append(const QVector<Insert> &inserts) { m_inserts += inserts; }
+ void append(const QVector<Remove> &removes) { m_removes += removes; }
+ void append(const QVector<Move> &moves) { m_moves += moves; }
+ void append(const QVector<Change> &changes) { m_changes += changes; }
+
+ void clear()
+ {
+ m_removes.clear();
+ m_inserts.clear();
+ m_moves.clear();
+ m_changes.clear();
+ }
+
+private:
+ QVector<Remove> m_removes;
+ QVector<Insert> m_inserts;
+ QVector<Move> m_moves;
+ QVector<Change> m_changes;
+};
+
+Q_AUTOTEST_EXPORT QDebug operator <<(QDebug debug, const QDeclarativeChangeSet &change);
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/declarative/util/util.pri b/src/declarative/util/util.pri
index 5bc8b117c0..4bd1f1bb1b 100644
--- a/src/declarative/util/util.pri
+++ b/src/declarative/util/util.pri
@@ -28,6 +28,7 @@ SOURCES += \
$$PWD/qdeclarativefontloader.cpp \
$$PWD/qdeclarativestyledtext.cpp \
$$PWD/qdeclarativelistmodelworkeragent.cpp \
+ $$PWD/qdeclarativechangeset.cpp \
$$PWD/qlistmodelinterface.cpp
HEADERS += \
@@ -63,6 +64,7 @@ HEADERS += \
$$PWD/qdeclarativefontloader_p.h \
$$PWD/qdeclarativestyledtext_p.h \
$$PWD/qdeclarativelistmodelworkeragent_p.h \
+ $$PWD/qdeclarativechangeset_p.h \
$$PWD/qlistmodelinterface_p.h
contains(QT_CONFIG, xmlpatterns) {
diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro
index 20fa8548fd..9ef9ce8a16 100644
--- a/tests/auto/declarative/declarative.pro
+++ b/tests/auto/declarative/declarative.pro
@@ -34,6 +34,7 @@ contains(QT_CONFIG, private_tests) {
qdeclarativebehaviors \
qdeclarativebinding \
qdeclarativeborderimage \
+ qdeclarativechangeset \
qdeclarativeconnection \
qdeclarativedebug \
qdeclarativedebugclient \
diff --git a/tests/auto/declarative/qdeclarativechangeset/qdeclarativechangeset.pro b/tests/auto/declarative/qdeclarativechangeset/qdeclarativechangeset.pro
new file mode 100644
index 0000000000..1c9a3c00f9
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativechangeset/qdeclarativechangeset.pro
@@ -0,0 +1,17 @@
+load(qttest_p4)
+contains(QT_CONFIG,declarative): QT += declarative gui
+macx:CONFIG -= app_bundle
+
+SOURCES += tst_qdeclarativechangeset.cpp
+
+symbian: {
+ importFiles.files = data
+ importFiles.path = .
+ DEPLOYMENT += importFiles
+} else {
+ DEFINES += SRCDIR=\\\"$$PWD\\\"
+}
+
+CONFIG += parallel_test
+
+QT += core-private gui-private declarative-private
diff --git a/tests/auto/declarative/qdeclarativechangeset/tst_qdeclarativechangeset.cpp b/tests/auto/declarative/qdeclarativechangeset/tst_qdeclarativechangeset.cpp
new file mode 100644
index 0000000000..018711ac64
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativechangeset/tst_qdeclarativechangeset.cpp
@@ -0,0 +1,614 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <qtest.h>
+#include <private/qdeclarativechangeset_p.h>
+
+#define VERIFY_EXPECTED_OUTPUT
+
+
+
+class tst_qdeclarativemodelchange : public QObject
+{
+ Q_OBJECT
+public:
+ struct Signal
+ {
+ int start;
+ int end;
+ int to;
+
+ bool isInsert() const { return to == -1; }
+ bool isRemove() const { return to == -2; }
+ bool isMove() const { return to >= 0; }
+ bool isChange() const { return to == -3; }
+ };
+
+ static Signal Insert(int start, int end) { Signal signal = { start, end, -1 }; return signal; }
+ static Signal Remove(int start, int end) { Signal signal = { start, end, -2 }; return signal; }
+ static Signal Move(int start, int end, int to) { Signal signal = { start, end, to }; return signal; }
+ static Signal Change(int start, int end) { Signal signal = { start, end, -3 }; return signal; }
+
+ typedef QVector<Signal> SignalList;
+
+
+#ifdef VERIFY_EXPECTED_OUTPUT
+
+ template<typename T>
+ void move(int from, int to, int n, T *items)
+ {
+ if (from > to) {
+ // Only move forwards - flip if backwards moving
+ int tfrom = from;
+ int tto = to;
+ from = tto;
+ to = tto+n;
+ n = tfrom-tto;
+ }
+
+ T replaced;
+ int i=0;
+ typename T::ConstIterator it=items->begin(); it += from+n;
+ for (; i<to-from; ++i,++it)
+ replaced.append(*it);
+ i=0;
+ it=items->begin(); it += from;
+ for (; i<n; ++i,++it)
+ replaced.append(*it);
+ typename T::ConstIterator f=replaced.begin();
+ typename T::Iterator t=items->begin(); t += from;
+ for (; f != replaced.end(); ++f, ++t)
+ *t = *f;
+ }
+
+ QVector<int> applyChanges(const QVector<int> &list, const QVector<Signal> &changes)
+ {
+ QVector<int> alteredList = list;
+ foreach (const Signal &signal, changes) {
+ if (signal.isInsert()) {
+ alteredList.insert(signal.start, signal.end - signal.start, 100);
+ } else if (signal.isRemove()) {
+ alteredList.erase(alteredList.begin() + signal.start, alteredList.begin() + signal.end);
+ } else if (signal.isMove()) {
+ move(signal.start, signal.to, signal.end - signal.start, &alteredList);
+ } else if (signal.isChange()) {
+ for (int i = signal.start; i < signal.end; ++i) {
+ if (alteredList[i] < 100)
+ alteredList[i] = 100;
+ }
+ }
+ }
+ return alteredList;
+ }
+
+#endif
+
+private slots:
+ void sequence_data();
+ void sequence();
+};
+
+bool operator ==(const tst_qdeclarativemodelchange::Signal &left, const tst_qdeclarativemodelchange::Signal &right) {
+ return left.start == right.start && left.end == right.end && left.to == right.to; }
+
+
+QDebug operator <<(QDebug debug, const tst_qdeclarativemodelchange::Signal &signal)
+{
+ if (signal.isInsert())
+ debug.nospace() << "Insert(" << signal.start << "," << signal.end << ")";
+ else if (signal.isRemove())
+ debug.nospace() << "Remove(" << signal.start << "," << signal.end << ")";
+ else if (signal.isMove())
+ debug.nospace() << "Move(" << signal.start << "," << signal.end << "," << signal.to << ")";
+ else if (signal.isChange())
+ debug.nospace() << "Change(" << signal.start << "," << signal.end << ")";
+ return debug;
+}
+
+Q_DECLARE_METATYPE(tst_qdeclarativemodelchange::SignalList)
+
+void tst_qdeclarativemodelchange::sequence_data()
+{
+ QTest::addColumn<SignalList>("input");
+ QTest::addColumn<SignalList>("output");
+
+ // Insert
+ QTest::newRow("i(12-17)")
+ << (SignalList() << Insert(12, 17))
+ << (SignalList() << Insert(12, 17));
+ QTest::newRow("i(2-5),i(12-17)")
+ << (SignalList() << Insert(2, 5) << Insert(12, 17))
+ << (SignalList() << Insert(2, 5) << Insert(12, 17));
+ QTest::newRow("i(12-17),i(2-5)")
+ << (SignalList() << Insert(12, 17) << Insert(2, 5))
+ << (SignalList() << Insert(2, 5) << Insert(15, 20));
+ QTest::newRow("i(12-17),i(12-15)")
+ << (SignalList() << Insert(12, 17) << Insert(12, 15))
+ << (SignalList() << Insert(12, 20));
+ QTest::newRow("i(12-17),i(17-20)")
+ << (SignalList() << Insert(12, 17) << Insert(17, 20))
+ << (SignalList() << Insert(12, 20));
+ QTest::newRow("i(12-17),i(15-18)")
+ << (SignalList() << Insert(12, 17) << Insert(15, 18))
+ << (SignalList() << Insert(12, 20));
+
+ // Remove
+ QTest::newRow("r(3-12)")
+ << (SignalList() << Remove(3, 12))
+ << (SignalList() << Remove(3, 12));
+ QTest::newRow("r(3-7),r(3-5)")
+ << (SignalList() << Remove(3, 7) << Remove(3, 5))
+ << (SignalList() << Remove(3, 9));
+ QTest::newRow("r(4-3),r(14-19)")
+ << (SignalList() << Remove(4, 7) << Remove(14, 19))
+ << (SignalList() << Remove(4, 7) << Remove(14, 19));
+ QTest::newRow("r(14-19),r(4-7)")
+ << (SignalList() << Remove(14, 19) << Remove(4, 7))
+ << (SignalList() << Remove(4, 7) << Remove(11, 16));
+ QTest::newRow("r(4-7),r(2-11)")
+ << (SignalList() << Remove(4, 7) << Remove(2, 11))
+ << (SignalList() << Remove(2, 14));
+
+ // Move
+ QTest::newRow("m(8-10,10)")
+ << (SignalList() << Move(8, 10, 10))
+ << (SignalList() << Move(8, 10, 10));
+ // No merging of moves yet.
+// QTest::newRow("m(5-7,13),m(5-8,12)")
+// << (SignalList() << Move(5, 7, 13) << Move(5, 8, 12))
+// << (SignalList() << Move(5, 10, 10));
+
+ // Change
+ QTest::newRow("c(4-9)")
+ << (SignalList() << Change(4, 9))
+ << (SignalList() << Change(4, 9));
+ QTest::newRow("c(4-9),c(12-14)")
+ << (SignalList() << Change(4, 9) << Change(12, 14))
+ << (SignalList() << Change(4, 9) << Change(12, 14));
+ QTest::newRow("c(12-14),c(4-9)")
+ << (SignalList() << Change(12, 14) << Change(4, 9))
+ << (SignalList() << Change(4, 9) << Change(12, 14));
+ QTest::newRow("c(4-9),c(2-4)")
+ << (SignalList() << Change(4, 9) << Change(2, 4))
+ << (SignalList() << Change(2, 9));
+ QTest::newRow("c(4-9),c(9-11)")
+ << (SignalList() << Change(4, 9) << Change(9, 11))
+ << (SignalList() << Change(4, 11));
+ QTest::newRow("c(4-9),c(3-5)")
+ << (SignalList() << Change(4, 9) << Change(3, 5))
+ << (SignalList() << Change(3, 9));
+ QTest::newRow("c(4-9),c(8-10)")
+ << (SignalList() << Change(4, 9) << Change(8, 10))
+ << (SignalList() << Change(4, 10));
+ QTest::newRow("c(4-9),c(3-5)")
+ << (SignalList() << Change(4, 9) << Change(3, 5))
+ << (SignalList() << Change(3, 9));
+ QTest::newRow("c(4-9),c(2,11)")
+ << (SignalList() << Change(4, 9) << Change(2, 11))
+ << (SignalList() << Change(2, 11));
+ QTest::newRow("c(4-9),c(12-15),c(8-14)")
+ << (SignalList() << Change(4, 9) << Change(12, 15) << Change(8, 14))
+ << (SignalList() << Change(4, 15));
+
+ // Insert, then remove.
+ QTest::newRow("i(12-18),r(12-18)")
+ << (SignalList() << Insert(12, 18) << Remove(12, 18))
+ << (SignalList());
+ QTest::newRow("i(12-18),r(10-14)")
+ << (SignalList() << Insert(12, 18) << Remove(10, 14))
+ << (SignalList() << Remove(10, 12) << Insert(10, 14));
+ QTest::newRow("i(12-18),r(16-20)")
+ << (SignalList() << Insert(12, 18) << Remove(16, 20))
+ << (SignalList() << Remove(12, 14) << Insert(12, 16));
+ QTest::newRow("i(12-18),r(13-17)")
+ << (SignalList() << Insert(12, 18) << Remove(13, 17))
+ << (SignalList() << Insert(12, 14));
+ QTest::newRow("i(12-18),r(14,18)")
+ << (SignalList() << Insert(12, 18) << Remove(14, 18))
+ << (SignalList() << Insert(12, 14));
+ QTest::newRow("i(12-18),r(12-16)")
+ << (SignalList() << Insert(12, 18) << Remove(12, 16))
+ << (SignalList() << Insert(12, 14));
+ QTest::newRow("i(12-18),r(11-19)")
+ << (SignalList() << Insert(12, 18) << Remove(11, 19))
+ << (SignalList() << Remove(11, 13));
+ QTest::newRow("i(12-18),r(8-12)")
+ << (SignalList() << Insert(12, 18) << Remove(8, 12))
+ << (SignalList() << Remove(8, 12) << Insert(8, 14));
+ QTest::newRow("i(12-18),r(2-6)")
+ << (SignalList() << Insert(12, 18) << Remove(2, 6))
+ << (SignalList() << Remove(2, 6) << Insert(8, 14));
+ QTest::newRow("i(12-18),r(18-22)")
+ << (SignalList() << Insert(12, 18) << Remove(18, 22))
+ << (SignalList() << Remove(12, 16) << Insert(12, 18));
+ QTest::newRow("i(12-18),r(20-24)")
+ << (SignalList() << Insert(12, 18) << Remove(20, 24))
+ << (SignalList() << Remove(14, 18) << Insert(12, 18));
+
+ // Insert, then move
+ QTest::newRow("i(12-18),m(12-18,5)")
+ << (SignalList() << Insert(12, 18) << Move(12, 18, 5))
+ << (SignalList() << Insert(5, 11));
+ QTest::newRow("i(12-18),m(10-14,5)")
+ << (SignalList() << Insert(12, 18) << Move(10, 14, 5))
+ << (SignalList() << Insert(5, 7) << Insert(14, 18) << Move(12, 14, 5));
+ QTest::newRow("i(12-18),m(16-20,5)")
+ << (SignalList() << Insert(12, 18) << Move(16, 20, 5))
+ << (SignalList() << Insert(5, 7) << Insert(14, 18) << Move(18, 20, 7));
+ QTest::newRow("i(12-18),m(13-17,5)")
+ << (SignalList() << Insert(12, 18) << Move(13, 17, 5))
+ << (SignalList() << Insert(5, 9) << Insert(16, 18));
+ QTest::newRow("i(12-18),m(14-18,5)")
+ << (SignalList() << Insert(12, 18) << Move(14, 18, 5))
+ << (SignalList() << Insert(5, 9) << Insert(16, 18));
+ QTest::newRow("i(12-18),m(12-16,5)")
+ << (SignalList() << Insert(12, 18) << Move(12, 16, 5))
+ << (SignalList() << Insert(5, 9) << Insert(16, 18));
+ QTest::newRow("i(12-18),m(11-19,5)")
+ << (SignalList() << Insert(12, 18) << Move(11, 19, 5))
+ << (SignalList() << Insert(5, 11) << Move(17, 18, 5) << Move(18, 19, 12));
+ QTest::newRow("i(12-18),m(8-12,5)")
+ << (SignalList() << Insert(12, 18) << Move(8, 12, 5))
+ << (SignalList() << Insert(12, 18) << Move(8, 12, 5));
+ QTest::newRow("i(12-18),m(2-6,5)")
+ << (SignalList() << Insert(12, 18) << Move(2, 6, 5))
+ << (SignalList() << Insert(12, 18) << Move(2, 6, 5));
+ QTest::newRow("i(12-18),m(18-22,5)")
+ << (SignalList() << Insert(12, 18) << Move(18, 22, 5))
+ << (SignalList() << Insert(12, 18) << Move(18, 22, 5));
+ QTest::newRow("i(12-18),m(20-24,5)")
+ << (SignalList() << Insert(12, 18) << Move(20, 24, 5))
+ << (SignalList() << Insert(12, 18) << Move(20, 24, 5));
+
+ QTest::newRow("i(12-18),m(5-13,11)")
+ << (SignalList() << Insert(12, 18) << Move(5, 13, 11))
+ << (SignalList() << Insert(12, 17) << Insert(18, 19) << Move(5, 12, 11));
+
+ QTest::newRow("i(12-18),m(12-18,23)")
+ << (SignalList() << Insert(12, 18) << Move(12, 18, 23))
+ << (SignalList() << Insert(23, 29));
+ QTest::newRow("i(12-18),m(10-14,23)")
+ << (SignalList() << Insert(12, 18) << Move(10, 14, 23))
+ << (SignalList() << Insert(12, 16) << Insert(25, 27) << Move(10, 12, 23));
+ QTest::newRow("i(12-18),m(16-20,23)")
+ << (SignalList() << Insert(12, 18) << Move(16, 20, 23))
+ << (SignalList() << Insert(12, 16) << Insert(25, 27) << Move(16, 18, 25));
+ QTest::newRow("i(12-18),m(13-17,23)")
+ << (SignalList() << Insert(12, 18) << Move(13, 17, 23))
+ << (SignalList() << Insert(12, 14) << Insert(23, 27));
+ QTest::newRow("i(12-18),m(14-18,23)")
+ << (SignalList() << Insert(12, 18) << Move(14, 18, 23))
+ << (SignalList() << Insert(12, 14) << Insert(23, 27));
+ QTest::newRow("i(12-18),m(12-16,23)")
+ << (SignalList() << Insert(12, 18) << Move(12, 16, 23))
+ << (SignalList() << Insert(12, 14) << Insert(23, 27));
+ QTest::newRow("i(12-18),m(11-19,23)")
+ << (SignalList() << Insert(12, 18) << Move(11, 19, 23))
+ << (SignalList() << Insert(25, 31) << Move(11, 12, 24) << Move(11, 12, 30));
+ QTest::newRow("i(12-18),m(8-12,23)")
+ << (SignalList() << Insert(12, 18) << Move(8, 12, 23))
+ << (SignalList() << Insert(12, 18) << Move(8, 12, 23));
+ QTest::newRow("i(12-18),m(2-6,23)")
+ << (SignalList() << Insert(12, 18) << Move(2, 6, 23))
+ << (SignalList() << Insert(12, 18) << Move(2, 6, 23));
+ QTest::newRow("i(12-18),m(18-22,23)")
+ << (SignalList() << Insert(12, 18) << Move(18, 22, 23))
+ << (SignalList() << Insert(12, 18) << Move(18, 22, 23));
+ QTest::newRow("i(12-18),m(20-24,23)")
+ << (SignalList() << Insert(12, 18) << Move(20, 24, 23))
+ << (SignalList() << Insert(12, 18) << Move(20, 24, 23));
+
+ QTest::newRow("i(12-18),m(11-21,23)")
+ << (SignalList() << Insert(12, 18) << Move(11, 21, 23))
+ << (SignalList() << Insert(27, 33) << Move(11, 12, 26) << Move(11, 14, 30));
+
+ // Insert, then change
+ QTest::newRow("i(12-18),c(12-16)")
+ << (SignalList() << Insert(12, 18) << Change(12, 6))
+ << (SignalList() << Insert(12, 18));
+ QTest::newRow("i(12-18),c(10-14)")
+ << (SignalList() << Insert(12, 18) << Change(10, 16))
+ << (SignalList() << Insert(12, 18) << Change(10, 12));
+ QTest::newRow("i(12-18),c(16-20)")
+ << (SignalList() << Insert(12, 18) << Change(16, 20))
+ << (SignalList() << Insert(12, 18) << Change(18, 20));
+ QTest::newRow("i(12-18),c(13-17)")
+ << (SignalList() << Insert(12, 18) << Change(13, 17))
+ << (SignalList() << Insert(12, 18));
+ QTest::newRow("i(12-18),c(14-18)")
+ << (SignalList() << Insert(12, 18) << Change(14, 18))
+ << (SignalList() << Insert(12, 18));
+ QTest::newRow("i(12-18),c(12-16)")
+ << (SignalList() << Insert(12, 18) << Change(12, 16))
+ << (SignalList() << Insert(12, 18));
+ QTest::newRow("i(12-18),c(11-19)")
+ << (SignalList() << Insert(12, 18) << Change(11, 19))
+ << (SignalList() << Insert(12, 18) << Change(11, 12) << Change(18, 19));
+ QTest::newRow("i(12-18),c(8-12)")
+ << (SignalList() << Insert(12, 18) << Change(8, 12))
+ << (SignalList() << Insert(12, 18) << Change(8, 12));
+ QTest::newRow("i(12-18),c(2-6)")
+ << (SignalList() << Insert(12, 18) << Change(2, 6))
+ << (SignalList() << Insert(12, 18) << Change(2, 6));
+ QTest::newRow("i(12-18),c(18-22)")
+ << (SignalList() << Insert(12, 18) << Change(18, 22))
+ << (SignalList() << Insert(12, 18) << Change(18, 22));
+ QTest::newRow("i(12-18),c(20-24)")
+ << (SignalList() << Insert(12, 18) << Change(20, 24))
+ << (SignalList() << Insert(12, 18) << Change(20, 24));
+
+ // Remove, then insert
+ QTest::newRow("r(12-18),i(12-18)")
+ << (SignalList() << Remove(12, 18) << Insert(12, 18))
+ << (SignalList() << Remove(12, 18) << Insert(12, 18));
+ QTest::newRow("r(12-18),i(10-14)")
+ << (SignalList() << Remove(12, 18) << Insert(10, 14))
+ << (SignalList() << Remove(12, 18) << Insert(10, 14));
+ QTest::newRow("r(12-18),i(16-20)")
+ << (SignalList() << Remove(12, 18) << Insert(16, 20))
+ << (SignalList() << Remove(12, 18) << Insert(16, 20));
+ QTest::newRow("r(12-18),i(13-17)")
+ << (SignalList() << Remove(12, 18) << Insert(13, 17))
+ << (SignalList() << Remove(12, 18) << Insert(13, 17));
+ QTest::newRow("r(12-18),i(14-18)")
+ << (SignalList() << Remove(12, 18) << Insert(14, 18))
+ << (SignalList() << Remove(12, 18) << Insert(14, 18));
+ QTest::newRow("r(12-18),i(12-16)")
+ << (SignalList() << Remove(12, 18) << Insert(12, 16))
+ << (SignalList() << Remove(12, 18) << Insert(12, 16));
+ QTest::newRow("r(12-18),i(11-19)")
+ << (SignalList() << Remove(12, 18) << Insert(11, 19))
+ << (SignalList() << Remove(12, 18) << Insert(11, 19));
+ QTest::newRow("i(12-18),r(8-12)")
+ << (SignalList() << Remove(12, 18) << Insert(8, 12))
+ << (SignalList() << Remove(12, 18) << Insert(8, 12));
+ QTest::newRow("i(12-18),r(2-6)")
+ << (SignalList() << Remove(12, 18) << Insert(2, 6))
+ << (SignalList() << Remove(12, 18) << Insert(2, 6));
+ QTest::newRow("i(12-18),r(18-22)")
+ << (SignalList() << Remove(12, 18) << Insert(18, 22))
+ << (SignalList() << Remove(12, 18) << Insert(18, 22));
+ QTest::newRow("i(12-18),r(20-24)")
+ << (SignalList() << Remove(12, 18) << Insert(20, 24))
+ << (SignalList() << Remove(12, 18) << Insert(20, 24));
+
+ // Move, then insert
+ QTest::newRow("m(12-18,5),i(12-18)")
+ << (SignalList() << Move(12, 18, 5) << Insert(12, 18))
+ << (SignalList() << Insert(6, 12) << Move(18, 24, 5));
+ QTest::newRow("m(12-18,5),i(10-14)")
+ << (SignalList() << Move(12, 18, 5) << Insert(10, 14))
+ << (SignalList() << Insert(5, 9) << Move(16, 21, 5) << Move(21, 22, 14));
+ QTest::newRow("m(12-18,5),i(16-20)")
+ << (SignalList() << Move(12, 18, 5) << Insert(16, 20))
+ << (SignalList() << Insert(10, 14) << Move(16, 22, 5));
+ QTest::newRow("m(12-18,5),i(13-17)")
+ << (SignalList() << Move(12, 18, 5) << Insert(13, 17))
+ << (SignalList() << Insert(7, 11) << Move(16, 22, 5));
+ QTest::newRow("m(12-18,5),i(14-18)")
+ << (SignalList() << Move(12, 18, 5) << Insert(14, 18))
+ << (SignalList() << Insert(8, 12) << Move(16, 22, 5));
+ QTest::newRow("m(12-18,5),i(12-16)")
+ << (SignalList() << Move(12, 18, 5) << Insert(12, 16))
+ << (SignalList() << Insert(6, 10) << Move(16, 22, 5));
+ QTest::newRow("m(12-18,5),i(11-19)")
+ << (SignalList() << Move(12, 18, 5) << Insert(11, 19))
+ << (SignalList() << Insert(5, 13) << Move(20, 26, 5));
+ QTest::newRow("m(12-18,5),i(8-12)")
+ << (SignalList() << Move(12, 18, 5) << Insert(8, 12))
+ << (SignalList() << Insert(5, 9) << Move(16, 19, 5) << Move(19, 22, 12));
+ QTest::newRow("m(12-18,5),i(2-6)")
+ << (SignalList() << Move(12, 18, 5) << Insert(2, 6))
+ << (SignalList() << Insert(2, 6) << Move(16, 22, 9));
+ QTest::newRow("m(12-18,5),i(18-22)")
+ << (SignalList() << Move(12, 18, 5) << Insert(18, 22))
+ << (SignalList() << Insert(18, 22) << Move(12, 18, 5));
+ QTest::newRow("m(12-18,5),i(20-24)")
+ << (SignalList() << Move(12, 18, 5) << Insert(20, 24))
+ << (SignalList() << Insert(20, 24) << Move(12, 18, 5));
+
+ QTest::newRow("m(12-18,23),i(12-18)")
+ << (SignalList() << Move(12, 18, 23) << Insert(12, 18))
+ << (SignalList() << Insert(12, 18) << Move(18, 24, 29));
+ QTest::newRow("m(12-18,23),i(10-14)")
+ << (SignalList() << Move(12, 18, 23) << Insert(10, 14))
+ << (SignalList() << Insert(10, 14) << Move(16, 22, 27));
+ QTest::newRow("m(12-18,23),i(16-20)")
+ << (SignalList() << Move(12, 18, 23) << Insert(16, 20))
+ << (SignalList() << Insert(22, 26) << Move(12, 18, 27));
+ QTest::newRow("m(12-18,23),i(13-17)")
+ << (SignalList() << Move(12, 18, 23) << Insert(13, 17))
+ << (SignalList() << Insert(19, 23) << Move(12, 18, 27));
+ QTest::newRow("m(12-18,23),i(14-18)")
+ << (SignalList() << Move(12, 18, 23) << Insert(14, 18))
+ << (SignalList() << Insert(20, 24) << Move(12, 18, 27));
+ QTest::newRow("m(12-18,23),i(12-16)")
+ << (SignalList() << Move(12, 18, 23) << Insert(12, 16))
+ << (SignalList() << Insert(12, 16) << Move(16, 22, 27));
+ QTest::newRow("m(12-18,23),i(11-19)")
+ << (SignalList() << Move(12, 18, 23) << Insert(11, 19))
+ << (SignalList() << Insert(11, 19) << Move(20, 26, 31));
+ QTest::newRow("m(12-18,23),i(8-12)")
+ << (SignalList() << Move(12, 18, 23) << Insert(8, 12))
+ << (SignalList() << Insert(8, 12) << Move(16, 22, 27));
+ QTest::newRow("m(12-18,23),i(2-6)")
+ << (SignalList() << Move(12, 18, 23) << Insert(2, 6))
+ << (SignalList() << Insert(2, 6) << Move(16, 22, 27));
+ QTest::newRow("m(12-18,23),i(18-22)")
+ << (SignalList() << Move(12, 18, 23) << Insert(18, 22))
+ << (SignalList() << Insert(24, 28) << Move(12, 18, 27));
+ QTest::newRow("m(12-18,23),i(20-24)")
+ << (SignalList() << Move(12, 18, 23) << Insert(20, 24))
+ << (SignalList() << Insert(26, 30) << Move(12, 18, 27));
+
+ // Move, then remove
+ QTest::newRow("m(12-18,5),r(12-18)")
+ << (SignalList() << Move(12, 18, 5) << Remove(12, 18))
+ << (SignalList() << Remove(6, 12) << Move(6, 12, 5));
+ QTest::newRow("m(12-18,5),r(10-14)")
+ << (SignalList() << Move(12, 18, 5) << Remove(10, 14))
+ << (SignalList() << Remove(5, 8) << Remove(14, 15) << Move(9, 14, 5));
+ QTest::newRow("m(12-18,5),r(16-20)")
+ << (SignalList() << Move(12, 18, 5) << Remove(16, 20))
+ << (SignalList() << Remove(10, 12) << Remove(16, 18) << Move(10, 16, 5));
+ QTest::newRow("m(12-18,5),r(13-17)")
+ << (SignalList() << Move(12, 18, 5) << Remove(13, 17))
+ << (SignalList() << Remove(7, 11) << Move(8, 14, 5));
+ QTest::newRow("m(12-18,5),r(14-18)")
+ << (SignalList() << Move(12, 18, 5) << Remove(14, 18))
+ << (SignalList() << Remove(8, 12) << Move(8, 14, 5));
+ QTest::newRow("m(12-18,5),r(12-16)")
+ << (SignalList() << Move(12, 18, 5) << Remove(12, 16))
+ << (SignalList() << Remove(6, 10) << Move(8, 14, 5));
+ QTest::newRow("m(12-18,5),r(11-19)")
+ << (SignalList() << Move(12, 18, 5) << Remove(11, 19))
+ << (SignalList() << Remove(5, 12) << Remove(11, 12));
+ QTest::newRow("m(12-18,5),r(8-12)")
+ << (SignalList() << Move(12, 18, 5) << Remove(8, 12))
+ << (SignalList() << Remove(5, 6) << Remove(14, 17) << Move(11, 14, 5));
+ QTest::newRow("m(12-18,5),r(2-6)")
+ << (SignalList() << Move(12, 18, 5) << Remove(2, 6))
+ << (SignalList() << Remove(2, 5) << Remove(9, 10) << Move(9, 14, 2));
+ QTest::newRow("m(12-18,5),r(6-10)")
+ << (SignalList() << Move(12, 18, 5) << Remove(6, 10))
+ << (SignalList() << Remove(13, 17) << Move(12, 14, 5));
+ QTest::newRow("m(12-18,5),r(18-22)")
+ << (SignalList() << Move(12, 18, 5) << Remove(18, 22))
+ << (SignalList() << Remove(18, 22) << Move(12, 18, 5));
+ QTest::newRow("m(12-18,5),r(20-24)")
+ << (SignalList() << Move(12, 18, 5) << Remove(20, 24))
+ << (SignalList() << Remove(20, 24) << Move(12, 18, 5));
+
+ QTest::newRow("m(12-18,23),r(12-18)")
+ << (SignalList() << Move(12, 18, 23) << Remove(12, 18))
+ << (SignalList() << Remove(18, 24) << Move(12, 18, 17));
+ QTest::newRow("m(12-18,23),r(10-14)")
+ << (SignalList() << Move(12, 18, 23) << Remove(10, 14))
+ << (SignalList() << Remove(10, 12) << Remove(16, 18) << Move(10, 16, 19));
+ QTest::newRow("m(12-18,23),r(16-20)")
+ << (SignalList() << Move(12, 18, 23) << Remove(16, 20))
+ << (SignalList() << Remove(22, 26) << Move(12, 18, 19));
+ QTest::newRow("m(12-18,23),r(13-17)")
+ << (SignalList() << Move(12, 18, 23) << Remove(13, 17))
+ << (SignalList() << Remove(19, 23) << Move(12, 18, 19));
+ QTest::newRow("m(12-18,23),r(14-18)")
+ << (SignalList() << Move(12, 18, 23) << Remove(14, 18))
+ << (SignalList() << Remove(20, 24) << Move(12, 18, 19));
+ QTest::newRow("m(12-18,23),r(12-16)")
+ << (SignalList() << Move(12, 18, 23) << Remove(12, 16))
+ << (SignalList() << Remove(18, 22) << Move(12, 18, 19));
+ QTest::newRow("m(12-18,23),r(11-19)")
+ << (SignalList() << Move(12, 18, 23) << Remove(11, 19))
+ << (SignalList() << Remove(11, 12) << Remove(17, 24) << Move(11, 17, 15));
+ QTest::newRow("m(12-18,23),r(8-12)")
+ << (SignalList() << Move(12, 18, 23) << Remove(8, 12))
+ << (SignalList() << Remove(8, 12) << Move(8, 14, 19));
+ QTest::newRow("m(12-18,23),r(2-6)")
+ << (SignalList() << Move(12, 18, 23) << Remove(2, 6))
+ << (SignalList() << Remove(2, 6) << Move(8, 14, 19));
+ QTest::newRow("m(12-18,23),r(18-22)")
+ << (SignalList() << Move(12, 18, 23) << Remove(18, 22))
+ << (SignalList() << Remove(24, 28) << Move(12, 18, 19));
+ QTest::newRow("m(12-18,23),r(20-24)")
+ << (SignalList() << Move(12, 18, 23) << Remove(20, 24))
+ << (SignalList() << Remove(12, 13) << Remove(25, 28) << Move(12, 17, 20));
+}
+
+void tst_qdeclarativemodelchange::sequence()
+{
+ QFETCH(SignalList, input);
+ QFETCH(SignalList, output);
+
+ QDeclarativeChangeSet set;
+
+ foreach (const Signal &signal, input) {
+ if (signal.isRemove())
+ set.insertRemove(signal.start, signal.end);
+ else if (signal.isInsert())
+ set.insertInsert(signal.start, signal.end);
+ else if (signal.isMove())
+ set.insertMove(signal.start, signal.end, signal.to);
+ else if (signal.isChange())
+ set.insertChange(signal.start, signal.end);
+ }
+
+ SignalList changes;
+ foreach (const QDeclarativeChangeSet::Remove &remove, set.removes())
+ changes << Remove(remove.start, remove.end);
+ foreach (const QDeclarativeChangeSet::Insert &insert, set.inserts())
+ changes << Insert(insert.start, insert.end);
+ foreach (const QDeclarativeChangeSet::Move &move, set.moves())
+ changes << Move(move.start, move.end, move.to);
+ foreach (const QDeclarativeChangeSet::Change &change, set.changes())
+ changes << Change(change.start, change.end);
+
+#ifdef VERIFY_EXPECTED_OUTPUT
+ QVector<int> list;
+ for (int i = 0; i < 40; ++i)
+ list.append(i);
+ QVector<int> inputList = applyChanges(list, input);
+ QVector<int> outputList = applyChanges(list, output);
+ if (outputList != inputList /* || changes != output*/) {
+ qDebug() << input;
+ qDebug() << output;
+ qDebug() << changes;
+ qDebug() << inputList;
+ qDebug() << outputList;
+ } else if (changes != output) {
+ qDebug() << output;
+ qDebug() << changes;
+ }
+ QCOMPARE(outputList, inputList);
+#else
+
+ if (changes != output) {
+ qDebug() << output;
+ qDebug() << changes;
+ }
+
+#endif
+
+ QCOMPARE(changes, output);
+}
+
+
+QTEST_MAIN(tst_qdeclarativemodelchange)
+
+#include "tst_qdeclarativechangeset.moc"