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 (t == QtWarningMsg) {
69 if (!Platform_qt::isGammaray() && !qEnvironmentVariableIsSet(
"NO_FATAL")) {
87template<
typename Func>
88static bool waitFor(Func func,
int timeout)
106class EventFilter :
public QObject
113 ~EventFilter()
override;
116 if (e->
type() == m_type)
126EventFilter::~EventFilter() =
default;
130bool Platform_qt::tests_waitForWindowActive(Core::Window::Ptr window,
int timeout)
const
133 auto windowqt =
static_cast<Window *
>(window.get());
134 QWindow *qwindow = windowqt->qtWindow();
137 return qwindow && qwindow->
isActive();
142bool Platform_qt::tests_waitForEvent(Core::Object *w,
QEvent::Type type,
int timeout)
const
144 Tests::EventFilter filter(type);
145 w->installEventFilter(&filter);
149 while (!filter.m_got && time.
elapsed() < timeout) {
150 qGuiApp->processEvents();
162bool Platform_qt::tests_waitForResize(
Core::View *view,
int timeout)
const
167bool Platform_qt::tests_waitForResize(
Core::Controller *c,
int timeout)
const
169 return tests_waitForResize(c->
view(), timeout);
172bool Platform_qt::tests_waitForEvent(std::shared_ptr<Core::Window> window,
QEvent::Type type,
175 auto windowqt =
static_cast<Window *
>(window.get());
176 return tests_waitForEvent(windowqt->qtWindow(), type, timeout);
179bool Platform_qt::tests_waitForDeleted(
Core::View *view,
int timeout)
const
189 while (ptr && time.
elapsed() < timeout) {
190 qGuiApp->processEvents();
194 const bool wasDeleted = !ptr;
199bool Platform_qt::tests_waitForDeleted(
Core::Controller *o,
int timeout)
const
208 while (ptr && time.
elapsed() < timeout) {
209 qGuiApp->processEvents();
213 const bool wasDeleted = !ptr;
217void Platform_qt::tests_doubleClickOn(
QPoint globalPos,
Core::View *receiver)
220 tests_pressOn(globalPos, receiver);
222 MouseEvent ev(Event::MouseButtonDblClick, receiver->
mapFromGlobal(globalPos),
229 qGuiApp->sendEvent(actualReceiver, &ev);
232 Platform::instance()->sendEvent(receiver, &ev);
236void Platform_qt::installMessageHandler()
241void Platform_qt::uninstallMessageHandler()
244 qWarning() << Q_FUNC_INFO
245 <<
"No message handler was installed or the fatalWarningsMessageHandler was "
246 "already uninstalled!";
251void Platform_qt::tests_initPlatform_impl()
253 qGuiApp->setOrganizationName(QStringLiteral(
"KDAB"));
254 qGuiApp->setApplicationName(QStringLiteral(
"dockwidgets-unit-tests"));
257void Platform_qt::tests_deinitPlatform_impl()
266bool Platform_qt::isGammaray()
272bool Platform_qt::tests_wait(
int ms)
const
278void Platform_qt::maybeSetOffscreenQPA(
int argc,
char **argv)
280 bool qpaPassed =
false;
282 for (
int i = 1; i < argc; ++i) {
283 if (qstrcmp(argv[i],
"-platform") == 0) {
289 if (!qpaPassed && !qEnvironmentVariableIsSet(
"KDDW_NO_OFFSCREEN")) {
291 qputenv(
"QT_QPA_PLATFORM",
"offscreen");
298 MouseEvent ev(Event::MouseButtonPress, receiver->
mapFromGlobal(globalPos),
304void Platform_qt::tests_pressOn(
QPoint globalPos, std::shared_ptr<Core::Window> receiver)
306 Platform::instance()->setCursorPos(globalPos);
307 MouseEvent ev(Event::MouseButtonPress, receiver->mapFromGlobal(globalPos),
310 qGuiApp->sendEvent(
static_cast<Window *
>(receiver.get())->qtWindow(), &ev);
315 MouseEvent ev(Event::MouseButtonRelease, receiver->
mapFromGlobal(globalPos),
318 Platform::instance()->sendEvent(receiver, &ev);
323void Platform_qt::tests_doubleClickOn(
QPoint globalPos, std::shared_ptr<Core::Window> receiver)
325 Platform::instance()->setCursorPos(globalPos);
326 MouseEvent ev(Event::MouseButtonDblClick, receiver->mapFromGlobal(globalPos),
330 tests_pressOn(globalPos, receiver);
331 qGuiApp->sendEvent(
static_cast<Window *
>(receiver.get())->qtWindow(), &ev);
337 Platform::instance()->setCursorPos(globalPos);
338 MouseEvent ev(Event::MouseMove, receiver->
mapFromGlobal(globalPos),
343 qWarning() <<
"Receiver was deleted";
346 Platform::instance()->sendEvent(receiver, &ev);
347 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