summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-08-26 09:51:10 +0200
committerLars Knoll <lars.knoll@qt.io>2020-08-29 21:01:10 +0200
commit62c08441099a4e561fe5b4ad644a11c2e1f4d2d8 (patch)
tree9a74e3936419bd83b53a983794008173b3c48e69
parentf098aee532bcaad7889931a53b9ed65650c42728 (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>
-rw-r--r--src/corelib/kernel/qtimer.cpp86
-rw-r--r--src/corelib/kernel/qtimer.h25
2 files changed, 75 insertions, 36 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
diff --git a/src/corelib/kernel/qtimer.h b/src/corelib/kernel/qtimer.h
index 66df5a7d4d..d4da91e172 100644
--- a/src/corelib/kernel/qtimer.h
+++ b/src/corelib/kernel/qtimer.h
@@ -53,7 +53,7 @@
QT_BEGIN_NAMESPACE
-
+class QTimerPrivate;
class Q_CORE_EXPORT QTimer : public QObject
{
Q_OBJECT
@@ -66,19 +66,19 @@ public:
explicit QTimer(QObject *parent = nullptr);
~QTimer();
- inline bool isActive() const { return id >= 0; }
- int timerId() const { return id; }
+ bool isActive() const;
+ int timerId() const;
void setInterval(int msec);
- int interval() const { return inter; }
+ int interval() const;
int remainingTime() const;
- void setTimerType(Qt::TimerType atype) { this->type = atype; }
- Qt::TimerType timerType() const { return Qt::TimerType(type); }
+ void setTimerType(Qt::TimerType atype);
+ Qt::TimerType timerType() const;
- inline void setSingleShot(bool singleShot);
- inline bool isSingleShot() const { return single; }
+ void setSingleShot(bool singleShot);
+ bool isSingleShot() const;
static void singleShot(int msec, const QObject *receiver, const char *member);
static void singleShot(int msec, Qt::TimerType timerType, const QObject *receiver, const char *member);
@@ -214,6 +214,7 @@ protected:
private:
Q_DISABLE_COPY(QTimer)
+ Q_DECLARE_PRIVATE(QTimer)
inline int startTimer(int){ return -1;}
inline void killTimer(int){}
@@ -234,16 +235,8 @@ private:
timerType, receiver, slotObj);
}
#endif
-
- int id, inter, del;
- uint single : 1;
- uint nulltimer : 1;
- uint type : 2;
- // reserved : 28
};
-inline void QTimer::setSingleShot(bool asingleShot) { single = asingleShot; }
-
QT_END_NAMESPACE
#endif // QT_NO_QOBJECT