diff options
| author | Ahmad Samir <a.samirh78@gmail.com> | 2023-11-18 20:09:49 +0200 |
|---|---|---|
| committer | Ahmad Samir <a.samirh78@gmail.com> | 2024-03-03 19:56:55 +0200 |
| commit | 577a3dba521f7f69bf6129fcd28184ae288182d9 (patch) | |
| tree | 5e28ffe662343604cac580188ed2b55fe0b78e0d /src/corelib/kernel/qtimer.cpp | |
| parent | bd764cc1ca578759f16fbe292fbe14a243b7d263 (diff) | |
Q{Chrono}Timer: de-duplicate some code
Q{Chrono}Timer::isActive() has to use isActiveData so that the bindable
property is correctly queried. However in other places in the code we
can take a shortcut by checking id > 0.
So rename QTimerPrivate::isActiveActualCalculation() to make it more
palatable and use it throughout the code.
Change-Id: I3378233e553fd860d9f105bba013dc9ffc31a2ba
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qtimer.cpp')
| -rw-r--r-- | src/corelib/kernel/qtimer.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/corelib/kernel/qtimer.cpp b/src/corelib/kernel/qtimer.cpp index cbeeb979343..e235e30a2d4 100644 --- a/src/corelib/kernel/qtimer.cpp +++ b/src/corelib/kernel/qtimer.cpp @@ -130,7 +130,7 @@ QTimer::QTimer(QObject *parent) QTimer::~QTimer() { - if (d_func()->id != QTimerPrivate::INV_TIMER) // stop running timer + if (d_func()->isActive()) // stop running timer stop(); } @@ -191,7 +191,7 @@ int QTimer::timerId() const void QTimer::start() { Q_D(QTimer); - if (d->id != QTimerPrivate::INV_TIMER) // stop running timer + if (d->isActive()) // stop running timer stop(); const int id = QObject::startTimer(std::chrono::milliseconds{d->inter}, d->type); if (id > 0) { @@ -247,7 +247,7 @@ void QTimer::start(std::chrono::milliseconds interval) void QTimer::stop() { Q_D(QTimer); - if (d->id != QTimerPrivate::INV_TIMER) { + if (d->isActive()) { QObject::killTimer(d->id); d->id = QTimerPrivate::INV_TIMER; d->isActiveData.notify(); @@ -570,7 +570,7 @@ void QTimer::setInterval(std::chrono::milliseconds interval) d->inter.removeBindingUnlessInWrapper(); const bool intervalChanged = msec != d->inter.valueBypassingBindings(); d->inter.setValueBypassingBindings(msec); - if (d->id != QTimerPrivate::INV_TIMER) { // create new timer + if (d->isActive()) { // create new timer QObject::killTimer(d->id); // restart timer const int id = QObject::startTimer(std::chrono::milliseconds{msec}, d->type); if (id > 0) { @@ -611,7 +611,7 @@ QBindable<int> QTimer::bindableInterval() int QTimer::remainingTime() const { Q_D(const QTimer); - if (d->id != QTimerPrivate::INV_TIMER) { + if (d->isActive()) { return QAbstractEventDispatcher::instance()->remainingTime(d->id); } |
