2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2016-08-17 15:29:37 +02:00
|
|
|
|
|
|
|
|
#include "eventspy.h"
|
|
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QEvent>
|
|
|
|
|
|
|
|
|
|
using namespace std::literals::chrono_literals;
|
|
|
|
|
|
|
|
|
|
EventSpy::EventSpy(uint eventType)
|
|
|
|
|
: startTime(std::chrono::steady_clock::now()),
|
|
|
|
|
eventType(eventType)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool EventSpy::waitForEvent()
|
|
|
|
|
{
|
|
|
|
|
while (shouldRun())
|
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
|
|
|
|
|
|
return eventHappened;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool EventSpy::event(QEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (event->type() == eventType) {
|
|
|
|
|
eventHappened = true;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool EventSpy::shouldRun() const
|
|
|
|
|
{
|
|
|
|
|
return !eventHappened
|
|
|
|
|
&& (std::chrono::steady_clock::now() - startTime) < 1s;
|
|
|
|
|
}
|