QQuickCanvas renames
[profile/ivi/qtdeclarative.git] / tests / auto / quick / shared / viewtestutil.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QQUICKVIEWTESTUTIL_H
43 #define QQUICKVIEWTESTUTIL_H
44
45 #include <QtQuick/QQuickItem>
46 #include <QtQml/QQmlExpression>
47 #include <QtQml/private/qlistmodelinterface_p.h>
48 #include <QtCore/QAbstractListModel>
49
50 QT_FORWARD_DECLARE_CLASS(QQuickView)
51
52 namespace QQuickViewTestUtil
53 {
54     QQuickView *createView();
55
56     void flick(QQuickView *window, const QPoint &from, const QPoint &to, int duration);
57
58     QList<int> adjustIndexesForAddDisplaced(const QList<int> &indexes, int index, int count);
59     QList<int> adjustIndexesForMove(const QList<int> &indexes, int from, int to, int count);
60     QList<int> adjustIndexesForRemoveDisplaced(const QList<int> &indexes, int index, int count);
61
62     struct ListChange {
63         enum { Inserted, Removed, Moved, SetCurrent, SetContentY, Polish } type;
64         int index;
65         int count;
66         int to;     // Move
67         qreal pos;  // setContentY
68
69         static ListChange insert(int index, int count = 1) { ListChange c = { Inserted, index, count, -1, 0.0 }; return c; }
70         static ListChange remove(int index, int count = 1) { ListChange c = { Removed, index, count, -1, 0.0 }; return c; }
71         static ListChange move(int index, int to, int count) { ListChange c = { Moved, index, count, to, 0.0 }; return c; }
72         static ListChange setCurrent(int index) { ListChange c = { SetCurrent, index, -1, -1, 0.0 }; return c; }
73         static ListChange setContentY(qreal pos) { ListChange c = { SetContentY, -1, -1, -1, pos }; return c; }
74         static ListChange polish() { ListChange c = { Polish, -1, -1, -1, 0.0 }; return c; }
75     };
76
77     class QmlListModel : public QListModelInterface
78     {
79         Q_OBJECT
80     public:
81         QmlListModel(QObject *parent = 0);
82         ~QmlListModel();
83
84         enum Roles { Name, Number };
85
86         QString name(int index) const;
87         QString number(int index) const;
88
89         int count() const;
90
91         QList<int> roles() const;
92         QString toString(int role) const;
93
94         QVariant data(int index, int role) const;
95         QHash<int, QVariant> data(int index, const QList<int> &roles) const;
96
97         Q_INVOKABLE void addItem(const QString &name, const QString &number);
98         void insertItem(int index, const QString &name, const QString &number);
99         void insertItems(int index, const QList<QPair<QString, QString> > &items);
100
101         Q_INVOKABLE void removeItem(int index);
102         Q_INVOKABLE void removeItems(int index, int count);
103
104         void moveItem(int from, int to);
105         void moveItems(int from, int to, int count);
106
107         void modifyItem(int index, const QString &name, const QString &number);
108
109         void clear();
110
111         void matchAgainst(const QList<QPair<QString, QString> > &other, const QString &error1, const QString &error2);
112
113     private:
114         QList<QPair<QString,QString> > list;
115     };
116
117     class QaimModel : public QAbstractListModel
118     {
119         Q_OBJECT
120     public:
121         enum Roles { Name = Qt::UserRole+1, Number = Qt::UserRole+2 };
122
123         QaimModel(QObject *parent=0);
124
125         int rowCount(const QModelIndex &parent=QModelIndex()) const;
126         QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const;
127
128         int count() const;
129         QString name(int index) const;
130         QString number(int index) const;
131
132         Q_INVOKABLE void addItem(const QString &name, const QString &number);
133         void addItems(const QList<QPair<QString, QString> > &items);
134         void insertItem(int index, const QString &name, const QString &number);
135         void insertItems(int index, const QList<QPair<QString, QString> > &items);
136
137         void removeItem(int index);
138         void removeItems(int index, int count);
139
140         void moveItem(int from, int to);
141         void moveItems(int from, int to, int count);
142
143         void modifyItem(int idx, const QString &name, const QString &number);
144
145         void clear();
146         void reset();
147
148         void matchAgainst(const QList<QPair<QString, QString> > &other, const QString &error1, const QString &error2);
149
150     private:
151         QList<QPair<QString,QString> > list;
152     };
153
154     class ListRange
155     {
156     public:
157         ListRange();
158         ListRange(const ListRange &other);
159         ListRange(int start, int end);
160
161         ~ListRange();
162
163         ListRange operator+(const ListRange &other) const;
164         bool operator==(const ListRange &other) const;
165         bool operator!=(const ListRange &other) const;
166
167         bool isValid() const;
168         int count() const;
169
170         QList<QPair<QString,QString> > getModelDataValues(const QmlListModel &model);
171         QList<QPair<QString,QString> > getModelDataValues(const QaimModel &model);
172
173         QList<int> indexes;
174         bool valid;
175     };
176 }
177
178 Q_DECLARE_METATYPE(QQuickViewTestUtil::QaimModel*)
179 Q_DECLARE_METATYPE(QQuickViewTestUtil::ListChange)
180 Q_DECLARE_METATYPE(QList<QQuickViewTestUtil::ListChange>)
181 Q_DECLARE_METATYPE(QQuickViewTestUtil::ListRange)
182
183 #endif // QQUICKVIEWTESTUTIL_H