diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2024-02-18 20:31:33 -0800 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2024-03-13 17:29:13 -0800 |
commit | f8da484d5741d1191504eefddf5134fd7009e16a (patch) | |
tree | d9aa03b1c0b73c2f0cd339eb50d23185e4175fd4 /src/corelib/kernel/qeventdispatcher_glib.cpp | |
parent | 9dc2935462ef42a5172b19b2bd4a8b938cf40bee (diff) |
QEventDispatcher*: port the Unix dispatchers to V2
They're all ported in one go because all the changes are the same and
they all rely on QTimerInfoList. The changes are:
- use Qt::TimerId to uniquely identify timer IDs
- use Duration (nanoseconds) to specify the timer interval
- rename registeredTimers() to timersForObject(), which is const
Change-Id: I83dda2d36c904517b3c0fffd17b52958767d8a68
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Diffstat (limited to 'src/corelib/kernel/qeventdispatcher_glib.cpp')
-rw-r--r-- | src/corelib/kernel/qeventdispatcher_glib.cpp | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/src/corelib/kernel/qeventdispatcher_glib.cpp b/src/corelib/kernel/qeventdispatcher_glib.cpp index ba3a1ea988..1e906c4b27 100644 --- a/src/corelib/kernel/qeventdispatcher_glib.cpp +++ b/src/corelib/kernel/qeventdispatcher_glib.cpp @@ -327,12 +327,12 @@ void QEventDispatcherGlibPrivate::runTimersOnceWithNormalPriority() } QEventDispatcherGlib::QEventDispatcherGlib(QObject *parent) - : QAbstractEventDispatcher(*(new QEventDispatcherGlibPrivate), parent) + : QAbstractEventDispatcherV2(*(new QEventDispatcherGlibPrivate), parent) { } QEventDispatcherGlib::QEventDispatcherGlib(GMainContext *mainContext, QObject *parent) - : QAbstractEventDispatcher(*(new QEventDispatcherGlibPrivate(mainContext)), parent) + : QAbstractEventDispatcherV2(*(new QEventDispatcherGlibPrivate(mainContext)), parent) { } QEventDispatcherGlib::~QEventDispatcherGlib() @@ -477,10 +477,11 @@ void QEventDispatcherGlib::unregisterSocketNotifier(QSocketNotifier *notifier) } } -void QEventDispatcherGlib::registerTimer(int timerId, qint64 interval, Qt::TimerType timerType, QObject *object) +void QEventDispatcherGlib::registerTimer(Qt::TimerId timerId, Duration interval, + Qt::TimerType timerType, QObject *object) { #ifndef QT_NO_DEBUG - if (timerId < 1 || interval < 0 || !object) { + if (qToUnderlying(timerId) < 1 || interval < 0ns || !object) { qWarning("QEventDispatcherGlib::registerTimer: invalid arguments"); return; } else if (object->thread() != thread() || thread() != QThread::currentThread()) { @@ -490,14 +491,13 @@ void QEventDispatcherGlib::registerTimer(int timerId, qint64 interval, Qt::Timer #endif Q_D(QEventDispatcherGlib); - d->timerSource->timerList.registerTimer(timerId, std::chrono::milliseconds{ interval }, - timerType, object); + d->timerSource->timerList.registerTimer(timerId, interval, timerType, object); } -bool QEventDispatcherGlib::unregisterTimer(int timerId) +bool QEventDispatcherGlib::unregisterTimer(Qt::TimerId timerId) { #ifndef QT_NO_DEBUG - if (timerId < 1) { + if (qToUnderlying(timerId) < 1) { qWarning("QEventDispatcherGlib::unregisterTimer: invalid argument"); return false; } else if (thread() != QThread::currentThread()) { @@ -526,28 +526,30 @@ bool QEventDispatcherGlib::unregisterTimers(QObject *object) return d->timerSource->timerList.unregisterTimers(object); } -QList<QEventDispatcherGlib::TimerInfo> QEventDispatcherGlib::registeredTimers(QObject *object) const +QList<QEventDispatcherGlib::TimerInfoV2> QEventDispatcherGlib::timersForObject(QObject *object) const { +#ifndef QT_NO_DEBUG if (!object) { - qWarning("QEventDispatcherUNIX:registeredTimers: invalid argument"); - return QList<TimerInfo>(); + qWarning("QEventDispatcherGlib:timersForObject: invalid argument"); + return {}; } +#endif Q_D(const QEventDispatcherGlib); return d->timerSource->timerList.registeredTimers(object); } -int QEventDispatcherGlib::remainingTime(int timerId) +QEventDispatcherGlib::Duration QEventDispatcherGlib::remainingTime(Qt::TimerId timerId) const { #ifndef QT_NO_DEBUG - if (timerId < 1) { + if (qToUnderlying(timerId) < 1) { qWarning("QEventDispatcherGlib::remainingTimeTime: invalid argument"); - return -1; + return Duration::min(); } #endif - Q_D(QEventDispatcherGlib); - return d->timerSource->timerList.timerRemainingTime(timerId); + Q_D(const QEventDispatcherGlib); + return d->timerSource->timerList.remainingDuration(timerId); } void QEventDispatcherGlib::interrupt() @@ -572,7 +574,7 @@ bool QEventDispatcherGlib::versionSupported() } QEventDispatcherGlib::QEventDispatcherGlib(QEventDispatcherGlibPrivate &dd, QObject *parent) - : QAbstractEventDispatcher(dd, parent) + : QAbstractEventDispatcherV2(dd, parent) { } |