13#include "qtcommon/Window_p.h"
16#include "core/Utils_p.h"
23#include <QGuiApplication>
24#include <QElapsedTimer>
44 QLatin1String(
"There's multiple MainWindows, not sure what to do about parenting"))
64#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
71 if (t == QtWarningMsg) {
76 if (!Platform_qt::isGammaray() && !qEnvironmentVariableIsSet(
"NO_FATAL")) {
94template<
typename Func>
95static bool waitFor(Func func,
int timeout)
102 if (timer.
elapsed() >= timeout)
113class EventFilter :
public QObject
120 ~EventFilter()
override;
123 if (e->
type() == m_type)
133EventFilter::~EventFilter() =
default;
137bool Platform_qt::tests_waitForWindowActive(Core::Window::Ptr window,
int timeout)
const
140 auto windowqt =
static_cast<Window *
>(window.get());
141 QWindow *qwindow = windowqt->qtWindow();
144 return qwindow && qwindow->
isActive();
149bool Platform_qt::tests_waitForEvent(Core::Object *w,
QEvent::Type type,
int timeout)
const
151 Tests::EventFilter filter(type);
152 w->installEventFilter(&filter);
156 while (!filter.m_got && time.
elapsed() < timeout) {
157 qGuiApp->processEvents();
169bool Platform_qt::tests_waitForResize(
Core::View *view,
int timeout)
const
174bool Platform_qt::tests_waitForResize(
Core::Controller *c,
int timeout)
const
176 return tests_waitForResize(c->
view(), timeout);
179bool Platform_qt::tests_waitForEvent(std::shared_ptr<Core::Window> window,
QEvent::Type type,
182 auto windowqt =
static_cast<Window *
>(window.get());
183 return tests_waitForEvent(windowqt->qtWindow(), type, timeout);
186bool Platform_qt::tests_waitForDeleted(
Core::View *view,
int timeout)
const
196 while (ptr && time.
elapsed() < timeout) {
197 qGuiApp->processEvents();
201 const bool wasDeleted = !ptr;
206bool Platform_qt::tests_waitForDeleted(
Core::Controller *o,
int timeout)
const
215 while (ptr && time.
elapsed() < timeout) {
216 qGuiApp->processEvents();
220 const bool wasDeleted = !ptr;
224void Platform_qt::tests_doubleClickOn(
QPoint globalPos,
Core::View *receiver)
227 tests_pressOn(globalPos, receiver);
229 MouseEvent ev(Event::MouseButtonDblClick, receiver->
mapFromGlobal(globalPos),
236 qGuiApp->sendEvent(actualReceiver, &ev);
239 Platform::instance()->sendEvent(receiver, &ev);
243void Platform_qt::installMessageHandler()
248void Platform_qt::uninstallMessageHandler()
251 qWarning() << Q_FUNC_INFO
252 <<
"No message handler was installed or the fatalWarningsMessageHandler was "
253 "already uninstalled!";
258void Platform_qt::tests_initPlatform_impl()
260 qGuiApp->setOrganizationName(QStringLiteral(
"KDAB"));
261 qGuiApp->setApplicationName(QStringLiteral(
"dockwidgets-unit-tests"));
264void Platform_qt::tests_deinitPlatform_impl()
273bool Platform_qt::isGammaray()
279bool Platform_qt::tests_wait(
int ms)
const
285void Platform_qt::maybeSetOffscreenQPA(
int argc,
char **argv)
287 bool qpaPassed =
false;
289 for (
int i = 1; i < argc; ++i) {
290 if (qstrcmp(argv[i],
"-platform") == 0) {
296 if (!qpaPassed && !qEnvironmentVariableIsSet(
"KDDW_NO_OFFSCREEN")) {
298 qputenv(
"QT_QPA_PLATFORM",
"offscreen");
305 MouseEvent ev(Event::MouseButtonPress, receiver->
mapFromGlobal(globalPos),
311void Platform_qt::tests_pressOn(
QPoint globalPos, std::shared_ptr<Core::Window> receiver)
313 Platform::instance()->setCursorPos(globalPos);
314 MouseEvent ev(Event::MouseButtonPress, receiver->mapFromGlobal(globalPos),
317 qGuiApp->sendEvent(
static_cast<Window *
>(receiver.get())->qtWindow(), &ev);
322 MouseEvent ev(Event::MouseButtonRelease, receiver->
mapFromGlobal(globalPos),
325 Platform::instance()->sendEvent(receiver, &ev);
330void Platform_qt::tests_doubleClickOn(
QPoint globalPos, std::shared_ptr<Core::Window> receiver)
332 Platform::instance()->setCursorPos(globalPos);
333 MouseEvent ev(Event::MouseButtonDblClick, receiver->mapFromGlobal(globalPos),
337 tests_pressOn(globalPos, receiver);
338 qGuiApp->sendEvent(
static_cast<Window *
>(receiver.get())->qtWindow(), &ev);
344 Platform::instance()->setCursorPos(globalPos);
345 MouseEvent ev(Event::MouseMove, receiver->
mapFromGlobal(globalPos),
350 qWarning() <<
"Receiver was deleted";
353 Platform::instance()->sendEvent(receiver, &ev);
354 Platform::instance()->tests_wait(2);
QT_BEGIN_NAMESPACE quintptr Q_CORE_EXPORT qtHookData[]
void setPos(int x, int y)
qint64 elapsed() const const
QEvent::Type type() const const
int exec(QEventLoop::ProcessEventsFlags flags)
void exit(int returnCode)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
QString fromStdString(const std::string &str)
bool isActive() const const