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>
bb10
parent
bd764cc1ca
commit
577a3dba52
|
|
@ -133,7 +133,7 @@ QChronoTimer::QChronoTimer(std::chrono::nanoseconds nsec, QObject *parent)
|
|||
*/
|
||||
QChronoTimer::~QChronoTimer()
|
||||
{
|
||||
if (d_func()->id != QTimerPrivate::INV_TIMER) // stop running timer
|
||||
if (d_func()->isActive()) // stop running timer
|
||||
stop();
|
||||
}
|
||||
|
||||
|
|
@ -187,7 +187,7 @@ int QChronoTimer::id() const
|
|||
void QChronoTimer::start()
|
||||
{
|
||||
auto *d = d_func();
|
||||
if (d->id != QTimerPrivate::INV_TIMER) // stop running timer
|
||||
if (d->isActive()) // stop running timer
|
||||
stop();
|
||||
const auto id = QObject::startTimer(d->intervalDuration, d->type);
|
||||
if (id > 0) {
|
||||
|
|
@ -204,7 +204,7 @@ void QChronoTimer::start()
|
|||
void QChronoTimer::stop()
|
||||
{
|
||||
auto *d = d_func();
|
||||
if (d->id != QTimerPrivate::INV_TIMER) {
|
||||
if (d->isActive()) {
|
||||
QObject::killTimer(d->id);
|
||||
d->id = QTimerPrivate::INV_TIMER;
|
||||
d->isActiveData.notify();
|
||||
|
|
@ -286,7 +286,7 @@ void QChronoTimer::setInterval(std::chrono::nanoseconds nsec)
|
|||
d->intervalDuration.removeBindingUnlessInWrapper();
|
||||
const bool intervalChanged = nsec != d->intervalDuration.valueBypassingBindings();
|
||||
d->intervalDuration.setValueBypassingBindings(nsec);
|
||||
if (d->id != QTimerPrivate::INV_TIMER) { // Create new timer
|
||||
if (d->isActive()) { // Create new timer
|
||||
QObject::killTimer(d->id); // Restart timer
|
||||
const auto id = QObject::startTimer(nsec, d->type);
|
||||
if (id > 0) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public:
|
|||
static_cast<QTimer *>(q)->setInterval(msec);
|
||||
}
|
||||
|
||||
bool isActiveActualCalculation() const { return id > 0; }
|
||||
bool isActive() const { return id > 0; }
|
||||
|
||||
int id = INV_TIMER;
|
||||
Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QTimerPrivate, int, inter, &QTimerPrivate::setInterval, 0)
|
||||
|
|
@ -61,8 +61,7 @@ public:
|
|||
std::chrono::nanoseconds{0})
|
||||
Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(QTimerPrivate, bool, single, false)
|
||||
Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(QTimerPrivate, Qt::TimerType, type, Qt::CoarseTimer)
|
||||
Q_OBJECT_COMPUTED_PROPERTY(QTimerPrivate, bool, isActiveData,
|
||||
&QTimerPrivate::isActiveActualCalculation)
|
||||
Q_OBJECT_COMPUTED_PROPERTY(QTimerPrivate, bool, isActiveData, &QTimerPrivate::isActive)
|
||||
|
||||
QObject *q;
|
||||
// true if q is a QTimer*, false otherwise
|
||||
|
|
|
|||
Loading…
Reference in New Issue