Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
viewtestutils_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QQUICKVIEWTESTUTILS_P_H
5#define QQUICKVIEWTESTUTILS_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/QAbstractListModel>
19#include <QtQml/QQmlExpression>
20#include <QtQuick/QQuickItem>
21#include <QtCore/private/qglobal_p.h>
22#include <QtQuick/private/qtquickglobal_p.h>
23
25QT_FORWARD_DECLARE_CLASS(QQuickItemViewPrivate)
26QT_FORWARD_DECLARE_CLASS(FxViewItem)
27QT_FORWARD_DECLARE_CLASS(QPointingDevice)
28
29QT_BEGIN_NAMESPACE
30
32{
34
35 void centerOnScreen(QQuickWindow *window, const QSize &size);
36 void centerOnScreen(QQuickWindow *window);
38
39 QList<int> adjustIndexesForAddDisplaced(const QList<int> &indexes, int index, int count);
40 QList<int> adjustIndexesForMove(const QList<int> &indexes, int from, int to, int count);
41 QList<int> adjustIndexesForRemoveDisplaced(const QList<int> &indexes, int index, int count);
42
43 struct ListChange {
45 int index;
46 int count;
47 int to; // Move
48 qreal pos; // setContentY
49
50 static ListChange insert(int index, int count = 1) { ListChange c = { Inserted, index, count, -1, 0.0 }; return c; }
51 static ListChange remove(int index, int count = 1) { ListChange c = { Removed, index, count, -1, 0.0 }; return c; }
52 static ListChange move(int index, int to, int count) { ListChange c = { Moved, index, count, to, 0.0 }; return c; }
53 static ListChange setCurrent(int index) { ListChange c = { SetCurrent, index, -1, -1, 0.0 }; return c; }
54 static ListChange setContentY(qreal pos) { ListChange c = { SetContentY, -1, -1, -1, pos }; return c; }
55 static ListChange polish() { ListChange c = { Polish, -1, -1, -1, 0.0 }; return c; }
56 };
57
59 {
61 public:
62 enum Roles { Name = Qt::UserRole+1, Number = Qt::UserRole+2 };
63
64 QaimModel(QObject *parent=0);
65
66 int rowCount(const QModelIndex &parent=QModelIndex()) const override;
67 int columnCount(const QModelIndex &parent=QModelIndex()) const override;
68 QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override;
69 QHash<int,QByteArray> roleNames() const override;
70
71 int count() const;
72 QString name(int index) const;
73 QString number(int index) const;
74
75 Q_INVOKABLE void addItem(const QString &name, const QString &number);
76 void addItems(const QList<std::pair<QString, QString> > &items);
77 void insertItem(int index, const QString &name, const QString &number);
78 void insertItems(int index, const QList<std::pair<QString, QString> > &items);
79
80 Q_INVOKABLE void removeItem(int index);
81 void removeItems(int index, int count);
82
83 void moveItem(int from, int to);
84 void moveItems(int from, int to, int count);
85
86 void modifyItem(int idx, const QString &name, const QString &number);
87
88 void clear();
89 void reset();
90 void resetItems(const QList<std::pair<QString, QString> > &items);
91
92 void matchAgainst(const QList<std::pair<QString, QString> > &other, const QString &error1, const QString &error2);
93
95
96 int columns = 1;
97
98 private:
100 };
101
103 {
104 public:
105 ListRange();
106 ListRange(const ListRange &other);
107 ListRange(int start, int end);
108
109 ~ListRange();
110
111 ListRange operator+(const ListRange &other) const;
112 bool operator==(const ListRange &other) const;
113 bool operator!=(const ListRange &other) const;
114
115 bool isValid() const;
116 int count() const;
117
119
121 bool valid;
122 };
123
124 template<typename T>
125 static void qquickmodelviewstestutil_move(int from, int to, int n, T *items)
126 {
127 if (from > to) {
128 // Only move forwards - flip if backwards moving
129 int tfrom = from;
130 int tto = to;
131 from = tto;
132 to = tto+n;
133 n = tfrom-tto;
134 }
135
136 T replaced;
137 int i=0;
138 typename T::ConstIterator it=items->begin(); it += from+n;
139 for (; i<to-from; ++i,++it)
140 replaced.append(*it);
141 i=0;
142 it=items->begin(); it += from;
143 for (; i<n; ++i,++it)
144 replaced.append(*it);
145 typename T::ConstIterator f=replaced.begin();
146 typename T::Iterator t=items->begin(); t += from;
147 for (; f != replaced.end(); ++f, ++t)
148 *t = *f;
149 }
150
152 {
154
155 public:
156
158
159 int rowCount(const QModelIndex &) const override;
160 QVariant data(const QModelIndex &, int) const override;
161
162 public Q_SLOTS:
163 void updateModel();
164
165 private:
166 int m_rowCount;
167 };
168
169#if QT_CONFIG(quick_itemview) && defined(QT_BUILD_INTERNAL)
172#endif
173}
174
175namespace QQuickTouchUtils {
176 void flush(QQuickWindow *window);
177}
178
179namespace QQuickTest {
180 [[nodiscard]] bool initView(QQuickView &v, const QUrl &url,
181 bool moveMouseOut = true, QByteArray *errorMessage = nullptr);
182 [[nodiscard]] bool showView(QQuickView &v, const QUrl &url);
183
184 void pointerPress(const QPointingDevice *dev, QQuickWindow *window,
185 int pointId, const QPoint &p, Qt::MouseButton button = Qt::LeftButton,
186 Qt::KeyboardModifiers modifiers = Qt::NoModifier, int delay = -1);
187
188 void pointerMove(const QPointingDevice *dev, QQuickWindow *window, int pointId,
189 const QPoint &p, int delay = -1);
190
191 void pointerRelease(const QPointingDevice *dev, QQuickWindow *window, int pointId,
192 const QPoint &p, Qt::MouseButton button = Qt::LeftButton,
193 Qt::KeyboardModifiers modifiers = Qt::NoModifier, int delay = -1);
194
195 void pointerMoveAndPress(const QPointingDevice *dev, QQuickWindow *window,
196 int pointId, const QPoint &p, Qt::MouseButton button = Qt::LeftButton,
197 Qt::KeyboardModifiers modifiers = Qt::NoModifier, int delay = -1);
198
199 void pointerMoveAndRelease(const QPointingDevice *dev, QQuickWindow *window,
200 int pointId, const QPoint &p, Qt::MouseButton button = Qt::LeftButton,
201 Qt::KeyboardModifiers modifiers = Qt::NoModifier, int delay = -1);
202
203 void pointerFlick(const QPointingDevice *dev, QQuickWindow *window,
204 int pointId, const QPoint &from, const QPoint &to, int duration,
205 Qt::MouseButton button = Qt::LeftButton,
206 Qt::KeyboardModifiers modifiers = Qt::NoModifier, int delay = -1);
207}
208
209QT_END_NAMESPACE
210
211Q_DECLARE_METATYPE(QQuickViewTestUtils::QaimModel*)
212Q_DECLARE_METATYPE(QQuickViewTestUtils::ListChange)
213Q_DECLARE_METATYPE(QList<QQuickViewTestUtils::ListChange>)
214Q_DECLARE_METATYPE(QQuickViewTestUtils::ListRange)
215
216
217#endif // QQUICKVIEWTESTUTILS_P_H
bool operator==(const ListRange &other) const
ListRange(const ListRange &other)
bool operator!=(const ListRange &other) const
ListRange operator+(const ListRange &other) const
void insertItems(int index, const QList< std::pair< QString, QString > > &items)
void insertItem(int index, const QString &name, const QString &number)
Q_INVOKABLE void addItem(const QString &name, const QString &number)
QString number(int index) const
void resetItems(const QList< std::pair< QString, QString > > &items)
QHash< int, QByteArray > roleNames() const override
Q_INVOKABLE void removeItem(int index)
void removeItems(int index, int count)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of rows under the given parent.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Returns the data stored under the given role for the item referred to by the index.
QString name(int index) const
void modifyItem(int idx, const QString &name, const QString &number)
void moveItems(int from, int to, int count)
void matchAgainst(const QList< std::pair< QString, QString > > &other, const QString &error1, const QString &error2)
void moveItem(int from, int to)
void addItems(const QList< std::pair< QString, QString > > &items)
QVariant data(const QModelIndex &, int) const override
Returns the data stored under the given role for the item referred to by the index.
int rowCount(const QModelIndex &) const override
Returns the number of rows under the given parent.
The QQuickView class provides a window for displaying a Qt Quick user interface.
Definition qquickview.h:21
void pointerPress(const QPointingDevice *dev, QQuickWindow *window, int pointId, const QPoint &p, Qt::MouseButton button, Qt::KeyboardModifiers modifiers, int delay)
void pointerRelease(const QPointingDevice *dev, QQuickWindow *window, int pointId, const QPoint &p, Qt::MouseButton button, Qt::KeyboardModifiers modifiers, int delay)
void pointerMoveAndPress(const QPointingDevice *dev, QQuickWindow *window, int pointId, const QPoint &p, Qt::MouseButton button, Qt::KeyboardModifiers modifiers, int delay)
void pointerFlick(const QPointingDevice *dev, QQuickWindow *window, int pointId, const QPoint &from, const QPoint &to, int duration, Qt::MouseButton button, Qt::KeyboardModifiers modifiers, int delay)
bool initView(QQuickView &view, const QUrl &url, bool moveMouseOut, QByteArray *errorMessage)
void pointerMoveAndRelease(const QPointingDevice *dev, QQuickWindow *window, int pointId, const QPoint &p, Qt::MouseButton button, Qt::KeyboardModifiers modifiers, int delay)
void pointerMove(const QPointingDevice *dev, QQuickWindow *window, int pointId, const QPoint &p, int delay)
bool showView(QQuickView &view, const QUrl &url)
static Qt::KeyboardModifiers pressedTabletModifiers
static Qt::MouseButton pressedTabletButton
void flush(QQuickWindow *window)
QQuickView * createView()
QList< int > adjustIndexesForAddDisplaced(const QList< int > &indexes, int index, int count)
void centerOnScreen(QQuickWindow *window, const QSize &size)
QList< int > adjustIndexesForMove(const QList< int > &indexes, int from, int to, int count)
static void qquickmodelviewstestutil_move(int from, int to, int n, T *items)
QList< int > adjustIndexesForRemoveDisplaced(const QList< int > &indexes, int index, int count)
void moveMouseAway(QQuickView *window)
void centerOnScreen(QQuickWindow *window)
static ListChange remove(int index, int count=1)
static ListChange move(int index, int to, int count)
static ListChange setCurrent(int index)
static ListChange insert(int index, int count=1)
static ListChange setContentY(qreal pos)