summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2024-02-18 20:50:35 -0800
committerThiago Macieira <thiago.macieira@intel.com>2024-03-13 17:29:12 -0800
commit7ce75b1a2bd9f22a7b2b83d48df875c68a47b390 (patch)
tree6db3c9baf09ab90f7f5f5e75fc3da5102f26cbe7 /src/corelib/kernel
parentaf6afad3b390c0ed7de6d3c4314cc394d8f8e2c2 (diff)
QAbstractEventDispatcher: add an adaptation layer to use V2 methods
This way, we can begin using the V2 methods now, regardless of whether the concrete dispatcher class has been ported or not. Change-Id: I83dda2d36c904517b3c0fffd17b52a6256b083af Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r--src/corelib/kernel/qabstracteventdispatcher.cpp44
-rw-r--r--src/corelib/kernel/qabstracteventdispatcher.h5
2 files changed, 49 insertions, 0 deletions
diff --git a/src/corelib/kernel/qabstracteventdispatcher.cpp b/src/corelib/kernel/qabstracteventdispatcher.cpp
index c7cf7fe1e2..f3056a399c 100644
--- a/src/corelib/kernel/qabstracteventdispatcher.cpp
+++ b/src/corelib/kernel/qabstracteventdispatcher.cpp
@@ -69,6 +69,13 @@ static inline QAbstractEventDispatcherV2 *v2(QAbstractEventDispatcher *self)
return static_cast<QAbstractEventDispatcherV2 *>(self);
return nullptr;
}
+
+static inline const QAbstractEventDispatcherV2 *v2(const QAbstractEventDispatcher *self)
+{
+ if (QAbstractEventDispatcherPrivate::get(self)->isV2)
+ return static_cast<const QAbstractEventDispatcherV2 *>(self);
+ return nullptr;
+}
#endif // Qt 7
QAbstractEventDispatcherPrivate::QAbstractEventDispatcherPrivate()
@@ -578,6 +585,43 @@ bool QAbstractEventDispatcher::filterNativeEvent(const QByteArray &eventType, vo
*/
#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
+void QAbstractEventDispatcher::registerTimer(Qt::TimerId timerId, Duration interval,
+ Qt::TimerType timerType, QObject *object)
+{
+ if (QAbstractEventDispatcherV2 *self = v2(this))
+ self->registerTimer(timerId, interval, timerType, object);
+ else
+ registerTimer(int(timerId), fromDuration<qint64>(interval), timerType, object);
+}
+
+bool QAbstractEventDispatcher::unregisterTimer(Qt::TimerId timerId)
+{
+ if (QAbstractEventDispatcherV2 *self = v2(this))
+ return self->unregisterTimer(timerId);
+ return unregisterTimer(int(timerId));
+}
+
+QList<QAbstractEventDispatcher::TimerInfoV2>
+QAbstractEventDispatcher::timersForObject(QObject *object) const
+{
+ if (const QAbstractEventDispatcherV2 *self = v2(this))
+ return self->timersForObject(object);
+ QList<TimerInfo> timers = registeredTimers(object);
+ QList<TimerInfoV2> result;
+ result.reserve(timers.size());
+ for (const TimerInfo &t : timers)
+ result.emplaceBack(TimerInfoV2{ t.interval * 1ms, Qt::TimerId(t.timerId), t.timerType });
+ return result;
+}
+
+QAbstractEventDispatcher::Duration
+QAbstractEventDispatcher::remainingTime(Qt::TimerId timerId) const
+{
+ if (const QAbstractEventDispatcherV2 *self = v2(this))
+ return self->remainingTime(timerId);
+ return const_cast<QAbstractEventDispatcher *>(this)->remainingTime(int(timerId)) * 1ms;
+}
+
/*!
\class QAbstractEventDispatcherV2
\inmodule QtCore
diff --git a/src/corelib/kernel/qabstracteventdispatcher.h b/src/corelib/kernel/qabstracteventdispatcher.h
index 2332292d09..ad97a93ba2 100644
--- a/src/corelib/kernel/qabstracteventdispatcher.h
+++ b/src/corelib/kernel/qabstracteventdispatcher.h
@@ -56,6 +56,11 @@ public:
virtual bool unregisterTimer(int timerId) = 0;
virtual QList<TimerInfo> registeredTimers(QObject *object) const = 0;
virtual int remainingTime(int timerId) = 0;
+
+ void registerTimer(Qt::TimerId timerId, Duration interval, Qt::TimerType timerType, QObject *object);
+ bool unregisterTimer(Qt::TimerId timerId);
+ QList<TimerInfoV2> timersForObject(QObject *object) const;
+ Duration remainingTime(Qt::TimerId timerId) const;
#else
virtual void registerTimer(Qt::TimerId timerId, Duration interval, Qt::TimerType timerType, QObject *object) = 0;
virtual bool unregisterTimer(Qt::TimerId timerId) = 0;