Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qtestsupport_gui.cpp
Go to the documentation of this file.
1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <private/qguiapplication_p.h>
5#include <private/qeventpoint_p.h>
6
7#include <qpa/qplatformintegration.h>
8
9#include "qtestsupport_gui.h"
10#include "qwindow.h"
11
12#include <QtCore/qtestsupport_core.h>
13#include <QtCore/qthread.h>
14#include <QtCore/QDebug>
15
17
35{
37 qWarning() << "qWaitForWindowActive was called on a platform that doesn't support window"
38 << "activation. This means there is an error in the test and it should either"
39 << "check for the WindowActivation platform capability before calling"
40 << "qWaitForWindowActivate, use qWaitForWindowExposed instead, or skip the test."
41 << "Falling back to qWaitForWindowExposed.";
43 }
44 return QTest::qWaitFor([&]() { return window->isActive(); }, timeout);
45}
46
64{
65 return QTest::qWaitFor([&]() { return qGuiApp->focusWindow() == window; }, timeout);
66}
67
83{
84 return QTest::qWaitFor([&]() { return window->isExposed(); }, timeout);
85}
86
87namespace QTest {
88
95{
96 auto &p = point(touchId);
97 QMutableEventPoint::setGlobalPosition(p, mapToScreen(window, pt));
98 QMutableEventPoint::setState(p, QEventPoint::State::Pressed);
99 return *this;
100}
102{
103 auto &p = point(touchId);
104 QMutableEventPoint::setGlobalPosition(p, mapToScreen(window, pt));
105 QMutableEventPoint::setState(p, QEventPoint::State::Updated);
106 return *this;
107}
109{
110 auto &p = point(touchId);
111 QMutableEventPoint::setGlobalPosition(p, mapToScreen(window, pt));
112 QMutableEventPoint::setState(p, QEventPoint::State::Released);
113 return *this;
114}
116{
117 auto &p = pointOrPreviousPoint(touchId);
118 QMutableEventPoint::setState(p, QEventPoint::State::Stationary);
119 return *this;
120}
121
122bool QTouchEventSequence::commit(bool processEvents)
123{
124 if (points.isEmpty())
125 return false;
126 QThread::sleep(std::chrono::milliseconds{1});
127 bool ret = false;
128 if (targetWindow)
130 if (processEvents)
133 points.clear();
134 return ret;
135}
136
138 : targetWindow(window), device(aDevice), commitWhenDestroyed(autoCommit)
139{
140}
141
143{
144 if (window)
145 return window->mapToGlobal(pt);
146 return targetWindow ? targetWindow->mapToGlobal(pt) : pt;
147}
148
150{
151 if (!points.contains(touchId))
152 points[touchId] = QEventPoint(touchId);
153 return points[touchId];
154}
155
157{
158 if (!points.contains(touchId)) {
159 if (previousPoints.contains(touchId))
160 points[touchId] = previousPoints.value(touchId);
161 else
162 points[touchId] = QEventPoint(touchId);
163 }
164 return points[touchId];
165}
166
167} // namespace QTest
168
IOBluetoothDevice * device
static void processEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
Processes some pending events for the calling thread according to the specified flags.
\inmodule QtCore
The QEventPoint class provides information about a point in a QPointerEvent.
Definition qeventpoint.h:20
static QPlatformIntegration * platformIntegration()
T value(const Key &key, const T &defaultValue=T()) const
Definition qmap.h:357
bool contains(const Key &key) const
Definition qmap.h:341
void clear()
Definition qmap.h:289
\inmodule QtCore\reentrant
Definition qpoint.h:25
The QPointingDevice class describes a device from which mouse, touch or tablet events originate.
virtual bool commit(bool processEvents=true)
QTouchEventSequence & move(int touchId, const QPoint &pt, QWindow *window=nullptr)
QPoint mapToScreen(QWindow *window, const QPoint &pt)
QMap< int, QEventPoint > previousPoints
QEventPoint & pointOrPreviousPoint(int touchId)
QEventPoint & point(int touchId)
QTouchEventSequence(QWindow *window, QPointingDevice *aDevice, bool autoCommit)
QMap< int, QEventPoint > points
QTouchEventSequence & press(int touchId, const QPoint &pt, QWindow *window=nullptr)
QTouchEventSequence & release(int touchId, const QPoint &pt, QWindow *window=nullptr)
virtual QTouchEventSequence & stationary(int touchId)
static void sleep(unsigned long)
\inmodule QtGui
Definition qwindow.h:63
Combined button and popup list for selecting options.
bool qWaitFor(Functor predicate, QDeadlineTimer deadline=QDeadlineTimer(std::chrono::seconds{5}))
Q_GUI_EXPORT bool qWaitForWindowActive(QWindow *window, int timeout=5000)
Q_GUI_EXPORT bool qWaitForWindowExposed(QWindow *window, int timeout=5000)
Q_GUI_EXPORT bool qWaitForWindowFocused(QWindow *widget, QDeadlineTimer timeout=std::chrono::seconds{5})
#define Q_UNLIKELY(x)
#define qGuiApp
#define qWarning
Definition qlogging.h:166
return ret
GLbitfield GLuint64 timeout
[4]
GLfixed GLfixed GLint GLint GLfixed points
GLfloat GLfloat p
[1]
Q_GUI_EXPORT bool qt_handleTouchEventv2(QWindow *w, const QPointingDevice *device, const QList< QEventPoint > &points, Qt::KeyboardModifiers mods=Qt::NoModifier)
aWidget window() -> setWindowTitle("New Window Title")
[2]