diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-08-26 09:51:10 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-08-29 21:01:10 +0200 |
commit | 62c08441099a4e561fe5b4ad644a11c2e1f4d2d8 (patch) | |
tree | 9a74e3936419bd83b53a983794008173b3c48e69 /src/corelib/kernel/qtimer.cpp | |
parent | f098aee532bcaad7889931a53b9ed65650c42728 (diff) |
Move the data for QTimer into the d-pointer
We shouldn't expose it inline in the header file.
Change-Id: I400d805fd0769f788f257bbf78311fe1fb56df79
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/kernel/qtimer.cpp')
-rw-r--r-- | src/corelib/kernel/qtimer.cpp | 86 |
1 files changed, 66 insertions, 20 deletions
diff --git a/src/corelib/kernel/qtimer.cpp b/src/corelib/kernel/qtimer.cpp index 25ce0c032f..6e3d34214f 100644 --- a/src/corelib/kernel/qtimer.cpp +++ b/src/corelib/kernel/qtimer.cpp @@ -47,6 +47,18 @@ QT_BEGIN_NAMESPACE +static constexpr int INV_TIMER = -1; // invalid timer id + +class QTimerPrivate : public QObjectPrivate +{ +public: + int id = INV_TIMER; + int inter = 0; + bool single = false; + bool nulltimer = false; + Qt::TimerType type = Qt::CoarseTimer; +}; + /*! \class QTimer \inmodule QtCore @@ -141,16 +153,13 @@ QT_BEGIN_NAMESPACE {Analog Clock Example}, {Wiggly Example} */ -static const int INV_TIMER = -1; // invalid timer id - /*! Constructs a timer with the given \a parent. */ QTimer::QTimer(QObject *parent) - : QObject(parent), id(INV_TIMER), inter(0), del(0), single(0), nulltimer(0), type(Qt::CoarseTimer) + : QObject(*new QTimerPrivate, parent) { - Q_UNUSED(del); // ### Qt 6: remove field } @@ -160,7 +169,7 @@ QTimer::QTimer(QObject *parent) QTimer::~QTimer() { - if (id != INV_TIMER) // stop running timer + if (d_func()->id != INV_TIMER) // stop running timer stop(); } @@ -187,6 +196,10 @@ QTimer::~QTimer() Returns \c true if the timer is running (pending); otherwise returns false. */ +bool QTimer::isActive() const +{ + return d_func()->id >= 0; +} /*! \fn int QTimer::timerId() const @@ -194,6 +207,10 @@ QTimer::~QTimer() Returns the ID of the timer if the timer is running; otherwise returns -1. */ +int QTimer::timerId() const +{ + return d_func()->id; +} /*! \overload start() @@ -207,10 +224,11 @@ QTimer::~QTimer() */ void QTimer::start() { - if (id != INV_TIMER) // stop running timer + Q_D(QTimer); + if (d->id != INV_TIMER) // stop running timer stop(); - nulltimer = (!inter && single); - id = QObject::startTimer(inter, Qt::TimerType(type)); + d->nulltimer = (!d->inter && d->single); + d->id = QObject::startTimer(d->inter, d->type); } /*! @@ -225,7 +243,8 @@ void QTimer::start() */ void QTimer::start(int msec) { - inter = msec; + Q_D(QTimer); + d->inter = msec; start(); } @@ -239,9 +258,10 @@ void QTimer::start(int msec) void QTimer::stop() { - if (id != INV_TIMER) { - QObject::killTimer(id); - id = INV_TIMER; + Q_D(QTimer); + if (d->id != INV_TIMER) { + QObject::killTimer(d->id); + d->id = INV_TIMER; } } @@ -251,8 +271,9 @@ void QTimer::stop() */ void QTimer::timerEvent(QTimerEvent *e) { - if (e->timerId() == id) { - if (single) + Q_D(QTimer); + if (e->timerId() == d->id) { + if (d->single) stop(); emit timeout(QPrivateSignal()); } @@ -687,6 +708,15 @@ void QTimer::singleShot(int msec, Qt::TimerType timerType, const QObject *receiv \sa interval, singleShot() */ +void QTimer::setSingleShot(bool singleShot) +{ + d_func()->single = singleShot; +} + +bool QTimer::isSingleShot() const +{ + return d_func()->single; +} /*! \property QTimer::interval @@ -702,13 +732,19 @@ void QTimer::singleShot(int msec, Qt::TimerType timerType, const QObject *receiv */ void QTimer::setInterval(int msec) { - inter = msec; - if (id != INV_TIMER) { // create new timer - QObject::killTimer(id); // restart timer - id = QObject::startTimer(msec, Qt::TimerType(type)); + Q_D(QTimer); + d->inter = msec; + if (d->id != INV_TIMER) { // create new timer + QObject::killTimer(d->id); // restart timer + d->id = QObject::startTimer(msec, d->type); } } +int QTimer::interval() const +{ + return d_func()->inter; +} + /*! \property QTimer::remainingTime \since 5.0 @@ -722,8 +758,9 @@ void QTimer::setInterval(int msec) */ int QTimer::remainingTime() const { - if (id != INV_TIMER) { - return QAbstractEventDispatcher::instance()->remainingTime(id); + Q_D(const QTimer); + if (d->id != INV_TIMER) { + return QAbstractEventDispatcher::instance()->remainingTime(d->id); } return -1; @@ -737,6 +774,15 @@ int QTimer::remainingTime() const \sa Qt::TimerType */ +void QTimer::setTimerType(Qt::TimerType atype) +{ + d_func()->type = atype; +} + +Qt::TimerType QTimer::timerType() const +{ + return d_func()->type; +} QT_END_NAMESPACE |