Qt 6.x
The Qt SDK
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
62{
63 return QTest::qWaitFor([&]() { return window->isExposed(); }, timeout);
64}
65
66namespace QTest {
67
69{
72}
74{
75 auto &p = point(touchId);
76 QMutableEventPoint::setGlobalPosition(p, mapToScreen(window, pt));
77 QMutableEventPoint::setState(p, QEventPoint::State::Pressed);
78 return *this;
79}
81{
82 auto &p = point(touchId);
83 QMutableEventPoint::setGlobalPosition(p, mapToScreen(window, pt));
84 QMutableEventPoint::setState(p, QEventPoint::State::Updated);
85 return *this;
86}
88{
89 auto &p = point(touchId);
90 QMutableEventPoint::setGlobalPosition(p, mapToScreen(window, pt));
91 QMutableEventPoint::setState(p, QEventPoint::State::Released);
92 return *this;
93}
95{
96 auto &p = pointOrPreviousPoint(touchId);
97 QMutableEventPoint::setState(p, QEventPoint::State::Stationary);
98 return *this;
99}
100
101bool QTouchEventSequence::commit(bool processEvents)
102{
103 if (points.isEmpty())
104 return false;
105 QThread::sleep(std::chrono::milliseconds{1});
106 bool ret = false;
107 if (targetWindow)
109 if (processEvents)
112 points.clear();
113 return ret;
114}
115
117 : targetWindow(window), device(aDevice), commitWhenDestroyed(autoCommit)
118{
119}
120
122{
123 if (window)
124 return window->mapToGlobal(pt);
125 return targetWindow ? targetWindow->mapToGlobal(pt) : pt;
126}
127
129{
130 if (!points.contains(touchId))
131 points[touchId] = QEventPoint(touchId);
132 return points[touchId];
133}
134
136{
137 if (!points.contains(touchId)) {
138 if (previousPoints.contains(touchId))
139 points[touchId] = previousPoints.value(touchId);
140 else
141 points[touchId] = QEventPoint(touchId);
142 }
143 return points[touchId];
144}
145
146} // namespace QTest
147
IOBluetoothDevice * device
static void processEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
Processes some pending events for the calling thread according to the specified flags.
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:356
bool contains(const Key &key) const
Definition qmap.h:340
void clear()
Definition qmap.h:288
\inmodule QtCore\reentrant
Definition qpoint.h:23
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.
Q_GUI_EXPORT bool qWaitForWindowActive(QWindow *window, int timeout=5000)
Q_GUI_EXPORT bool qWaitForWindowExposed(QWindow *window, int timeout=5000)
static bool qWaitFor(Functor predicate, QDeadlineTimer deadline=QDeadlineTimer(std::chrono::seconds{5}))
#define Q_UNLIKELY(x)
#define qWarning
Definition qlogging.h:162
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]