1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QDECLARATIVECHANGESET_P_H
43 #define QDECLARATIVECHANGESET_P_H
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
56 #include <QtCore/qdebug.h>
57 #include <QtCore/qvector.h>
61 class Q_AUTOTEST_EXPORT QDeclarativeChangeSet
66 MoveKey() : moveId(-1), offset(0) {}
67 MoveKey(int moveId, int offset) : moveId(moveId), offset(offset) {}
74 Change() : index(0), count(0), moveId(-1) {}
75 Change(int index, int count) : index(index), count(count), moveId(-1) {}
76 Change(int index, int count, int moveId) : index(index), count(count), moveId(moveId) {}
82 bool isMove() const { return moveId >= 0; }
84 MoveKey moveKey(int index) const { return MoveKey(moveId, index - Change::index); }
86 int start() const { return index; }
87 int end() const { return index + count; }
91 struct Insert : public Change
94 Insert(int index, int count) : Change(index, count) {}
95 Insert(int index, int count, int moveId) : Change(index, count, moveId) {}
98 struct Remove : public Change
101 Remove(int index, int count) : Change(index, count) {}
102 Remove(int index, int count, int moveId) : Change(index, count, moveId) {}
105 QDeclarativeChangeSet();
106 QDeclarativeChangeSet(const QDeclarativeChangeSet &changeSet);
107 ~QDeclarativeChangeSet();
109 QDeclarativeChangeSet &operator =(const QDeclarativeChangeSet &changeSet);
111 const QVector<Remove> &removes() const { return m_removes; }
112 const QVector<Insert> &inserts() const { return m_inserts; }
113 const QVector<Change> &changes() const {return m_changes; }
115 void insert(int index, int count);
116 void remove(int index, int count);
117 void move(int from, int to, int count);
118 void change(int index, int count);
120 void apply(const QDeclarativeChangeSet &changeSet);
121 void apply(const QVector<Remove> &removals);
122 void apply(const QVector<Insert> &insertions);
123 void apply(const QVector<Change> &changes);
125 const QVector<Remove> &removals,
126 const QVector<Insert> &insertions,
127 const QVector<Change> &changes = QVector<Change>());
129 bool isEmpty() const { return m_removes.empty() && m_inserts.empty() && m_changes.empty(); }
140 int moveCounter() const { return m_moveCounter; }
141 int difference() const { return m_difference; }
144 void applyRemovals(QVector<Remove> &removals, QVector<Insert> &insertions);
145 void applyInsertions(QVector<Insert> &insertions);
146 void applyChanges(QVector<Change> &changes);
148 QVector<Remove> m_removes;
149 QVector<Insert> m_inserts;
150 QVector<Change> m_changes;
155 inline uint qHash(const QDeclarativeChangeSet::MoveKey &key) { return qHash(qMakePair(key.moveId, key.offset)); }
156 inline bool operator ==(const QDeclarativeChangeSet::MoveKey &l, const QDeclarativeChangeSet::MoveKey &r) {
157 return l.moveId == r.moveId && l.offset == r.offset; }
159 Q_AUTOTEST_EXPORT QDebug operator <<(QDebug debug, const QDeclarativeChangeSet &change);
160 Q_AUTOTEST_EXPORT QDebug operator <<(QDebug debug, const QDeclarativeChangeSet::Remove &remove);
161 Q_AUTOTEST_EXPORT QDebug operator <<(QDebug debug, const QDeclarativeChangeSet::Insert &insert);
162 Q_AUTOTEST_EXPORT QDebug operator <<(QDebug debug, const QDeclarativeChangeSet::Change &change);