summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2011-12-21 11:33:33 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-02 10:44:00 +0100
commit2bbf9befd8879dcfca9f48ac9ac13daf40f48847 (patch)
tree42457f54a2a25cf2a8de6a9292c60b7513339c4a /src/corelib
parentef60ed1c9dbc87d9f8401036cc254a9c45cd8ca8 (diff)
Add Qt::TimerType argument to QAbstractEventDispatcher::registerTimer()
... and deprecate the old registerTimer() functions. The new pure- virtual registerTimer() breaks source-compatibility. Subclasses cannot be instantiated anymore, since the pure virtual function signature has changed. QAbstractEventDispatcher::TimerInfo is no longer a QPair. It is now a struct with timerId, interval, and timerType members. This is a source incompatibility that should only affect subclasses of QAbstractEventDispatcher, which will need to pass 3 arguments to the TimerInfo constructor instead of 2. If the subclass used QPair<int,int> instead of the TimerInfo typedef, the QPair<int,int> declarations will need to be replaced with TimerInfo. Call the new registerTimer() function with the type from QObject::startTimer(). Change all subclasses of QAbstractEventDispatcher to reimplement the new virtual function. The type argument is unused at the momemnt, except to ensure that registeredTimers() returns the type each timer was registered with. Implementations for the various dispatchers will be done in separate commits. Author: Thiago Macieira <thiago.macieira@nokia.com> Change-Id: Ia22697e0ab0847810c5d162ef473e0e5a17a904b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/kernel/qabstracteventdispatcher.cpp35
-rw-r--r--src/corelib/kernel/qabstracteventdispatcher.h22
-rw-r--r--src/corelib/kernel/qeventdispatcher_glib.cpp4
-rw-r--r--src/corelib/kernel/qeventdispatcher_glib_p.h2
-rw-r--r--src/corelib/kernel/qeventdispatcher_unix.cpp4
-rw-r--r--src/corelib/kernel/qeventdispatcher_unix_p.h2
-rw-r--r--src/corelib/kernel/qeventdispatcher_win.cpp5
-rw-r--r--src/corelib/kernel/qeventdispatcher_win_p.h3
-rw-r--r--src/corelib/kernel/qobject.cpp12
-rw-r--r--src/corelib/kernel/qtimerinfo_unix.cpp9
-rw-r--r--src/corelib/kernel/qtimerinfo_unix_p.h9
11 files changed, 71 insertions, 36 deletions
diff --git a/src/corelib/kernel/qabstracteventdispatcher.cpp b/src/corelib/kernel/qabstracteventdispatcher.cpp
index b936ac4ed2..910b2908f1 100644
--- a/src/corelib/kernel/qabstracteventdispatcher.cpp
+++ b/src/corelib/kernel/qabstracteventdispatcher.cpp
@@ -230,22 +230,39 @@ QAbstractEventDispatcher *QAbstractEventDispatcher::instance(QThread *thread)
*/
/*!
+ \obsolete
+
\fn int QAbstractEventDispatcher::registerTimer(int interval, QObject *object)
- Registers a timer with the specified \a interval for the given \a object.
+ Registers a timer with the specified \a interval for the given \a object
+ and returns the timer id.
+*/
+
+/*!
+ \obsolete
+
+ \fn void QAbstractEventDispatcher::registerTimer(int timerId, int interval, QObject *object)
+
+ Register a timer with the specified \a timerId and \a interval for the
+ given \a object.
+*/
+
+/*!
+ Registers a timer with the specified \a interval and \a timerType for the
+ given \a object and returns the timer id.
*/
-int QAbstractEventDispatcher::registerTimer(int interval, QObject *object)
+int QAbstractEventDispatcher::registerTimer(int interval, Qt::TimerType timerType, QObject *object)
{
int id = QAbstractEventDispatcherPrivate::allocateTimerId();
- registerTimer(id, interval, object);
+ registerTimer(id, interval, timerType, object);
return id;
}
/*!
- \fn void QAbstractEventDispatcher::registerTimer(int timerId, int interval, QObject *object)
+ \fn void QAbstractEventDispatcher::registerTimer(int timerId, int interval, Qt::TimerType timerType, QObject *object)
- Register a timer with the specified \a timerId and \a interval for
- the given \a object.
+ Register a timer with the specified \a timerId, \a interval, and \a
+ timerType for the given \a object.
*/
/*!
@@ -269,8 +286,10 @@ int QAbstractEventDispatcher::registerTimer(int interval, QObject *object)
/*!
\fn QList<TimerInfo> QAbstractEventDispatcher::registeredTimers(QObject *object) const
- Returns a list of registered timers for \a object. The timer ID
- is the first member in each pair; the interval is the second.
+ Returns a list of registered timers for \a object. The TimerInfo struct has
+ \c timerId, \c interval, and \c timerType members.
+
+ \sa Qt::TimerType
*/
/*! \fn void QAbstractEventDispatcher::wakeUp()
diff --git a/src/corelib/kernel/qabstracteventdispatcher.h b/src/corelib/kernel/qabstracteventdispatcher.h
index 36bd1be368..0add7bc71a 100644
--- a/src/corelib/kernel/qabstracteventdispatcher.h
+++ b/src/corelib/kernel/qabstracteventdispatcher.h
@@ -53,7 +53,6 @@ QT_MODULE(Core)
class QAbstractEventDispatcherPrivate;
class QSocketNotifier;
-template <typename T1, typename T2> struct QPair;
class Q_CORE_EXPORT QAbstractEventDispatcher : public QObject
{
@@ -61,7 +60,16 @@ class Q_CORE_EXPORT QAbstractEventDispatcher : public QObject
Q_DECLARE_PRIVATE(QAbstractEventDispatcher)
public:
- typedef QPair<int, int> TimerInfo;
+ struct TimerInfo
+ {
+ int timerId;
+ int interval;
+ Qt::TimerType timerType;
+
+ inline TimerInfo(int id, int i, Qt::TimerType t)
+ : timerId(id), interval(i), timerType(t)
+ { }
+ };
explicit QAbstractEventDispatcher(QObject *parent = 0);
~QAbstractEventDispatcher();
@@ -74,8 +82,14 @@ public:
virtual void registerSocketNotifier(QSocketNotifier *notifier) = 0;
virtual void unregisterSocketNotifier(QSocketNotifier *notifier) = 0;
- int registerTimer(int interval, QObject *object);
- virtual void registerTimer(int timerId, int interval, QObject *object) = 0;
+#if QT_DEPRECATED_SINCE(5,0)
+ QT_DEPRECATED inline int registerTimer(int interval, QObject *object)
+ { return registerTimer(interval, Qt::CoarseTimer, object); }
+ QT_DEPRECATED inline void registerTimer(int timerId, int interval, QObject *object)
+ { registerTimer(timerId, interval, Qt::CoarseTimer, object); }
+#endif
+ int registerTimer(int interval, Qt::TimerType timerType, QObject *object);
+ virtual void registerTimer(int timerId, int interval, Qt::TimerType timerType, QObject *object) = 0;
virtual bool unregisterTimer(int timerId) = 0;
virtual bool unregisterTimers(QObject *object) = 0;
virtual QList<TimerInfo> registeredTimers(QObject *object) const = 0;
diff --git a/src/corelib/kernel/qeventdispatcher_glib.cpp b/src/corelib/kernel/qeventdispatcher_glib.cpp
index 0773915391..261d8d3b4c 100644
--- a/src/corelib/kernel/qeventdispatcher_glib.cpp
+++ b/src/corelib/kernel/qeventdispatcher_glib.cpp
@@ -509,7 +509,7 @@ void QEventDispatcherGlib::unregisterSocketNotifier(QSocketNotifier *notifier)
}
}
-void QEventDispatcherGlib::registerTimer(int timerId, int interval, QObject *object)
+void QEventDispatcherGlib::registerTimer(int timerId, int interval, Qt::TimerType timerType, QObject *object)
{
#ifndef QT_NO_DEBUG
if (timerId < 1 || interval < 0 || !object) {
@@ -522,7 +522,7 @@ void QEventDispatcherGlib::registerTimer(int timerId, int interval, QObject *obj
#endif
Q_D(QEventDispatcherGlib);
- d->timerSource->timerList.registerTimer(timerId, interval, object);
+ d->timerSource->timerList.registerTimer(timerId, interval, timerType, object);
}
bool QEventDispatcherGlib::unregisterTimer(int timerId)
diff --git a/src/corelib/kernel/qeventdispatcher_glib_p.h b/src/corelib/kernel/qeventdispatcher_glib_p.h
index 419f2f3dc0..1c3b7e8645 100644
--- a/src/corelib/kernel/qeventdispatcher_glib_p.h
+++ b/src/corelib/kernel/qeventdispatcher_glib_p.h
@@ -80,7 +80,7 @@ public:
void registerSocketNotifier(QSocketNotifier *socketNotifier);
void unregisterSocketNotifier(QSocketNotifier *socketNotifier);
- void registerTimer(int timerId, int interval, QObject *object);
+ void registerTimer(int timerId, int interval, Qt::TimerType timerType, QObject *object);
bool unregisterTimer(int timerId);
bool unregisterTimers(QObject *object);
QList<TimerInfo> registeredTimers(QObject *object) const;
diff --git a/src/corelib/kernel/qeventdispatcher_unix.cpp b/src/corelib/kernel/qeventdispatcher_unix.cpp
index 3420990969..4b61667710 100644
--- a/src/corelib/kernel/qeventdispatcher_unix.cpp
+++ b/src/corelib/kernel/qeventdispatcher_unix.cpp
@@ -330,7 +330,7 @@ int QEventDispatcherUNIX::select(int nfds, fd_set *readfds, fd_set *writefds, fd
/*!
\internal
*/
-void QEventDispatcherUNIX::registerTimer(int timerId, int interval, QObject *obj)
+void QEventDispatcherUNIX::registerTimer(int timerId, int interval, Qt::TimerType timerType, QObject *obj)
{
#ifndef QT_NO_DEBUG
if (timerId < 1 || interval < 0 || !obj) {
@@ -343,7 +343,7 @@ void QEventDispatcherUNIX::registerTimer(int timerId, int interval, QObject *obj
#endif
Q_D(QEventDispatcherUNIX);
- d->timerList.registerTimer(timerId, interval, obj);
+ d->timerList.registerTimer(timerId, interval, timerType, obj);
}
/*!
diff --git a/src/corelib/kernel/qeventdispatcher_unix_p.h b/src/corelib/kernel/qeventdispatcher_unix_p.h
index e96be68db8..07cbf92d6a 100644
--- a/src/corelib/kernel/qeventdispatcher_unix_p.h
+++ b/src/corelib/kernel/qeventdispatcher_unix_p.h
@@ -111,7 +111,7 @@ public:
void registerSocketNotifier(QSocketNotifier *notifier);
void unregisterSocketNotifier(QSocketNotifier *notifier);
- void registerTimer(int timerId, int interval, QObject *object);
+ void registerTimer(int timerId, int interval, Qt::TimerType timerType, QObject *object);
bool unregisterTimer(int timerId);
bool unregisterTimers(QObject *object);
QList<TimerInfo> registeredTimers(QObject *object) const;
diff --git a/src/corelib/kernel/qeventdispatcher_win.cpp b/src/corelib/kernel/qeventdispatcher_win.cpp
index afee536d02..58a927969c 100644
--- a/src/corelib/kernel/qeventdispatcher_win.cpp
+++ b/src/corelib/kernel/qeventdispatcher_win.cpp
@@ -859,7 +859,7 @@ void QEventDispatcherWin32::unregisterSocketNotifier(QSocketNotifier *notifier)
d->doWsaAsyncSelect(sockfd);
}
-void QEventDispatcherWin32::registerTimer(int timerId, int interval, QObject *object)
+void QEventDispatcherWin32::registerTimer(int timerId, int interval, Qt::TimerType timerType, QObject *object)
{
if (timerId < 1 || interval < 0 || !object) {
qWarning("QEventDispatcherWin32::registerTimer: invalid arguments");
@@ -875,6 +875,7 @@ void QEventDispatcherWin32::registerTimer(int timerId, int interval, QObject *ob
t->dispatcher = this;
t->timerId = timerId;
t->interval = interval;
+ t->timerType = timerType;
t->obj = object;
t->inTimerEvent = false;
t->fastTimerId = 0;
@@ -953,7 +954,7 @@ QEventDispatcherWin32::registeredTimers(QObject *object) const
for (int i = 0; i < d->timerVec.size(); ++i) {
const WinTimerInfo *t = d->timerVec.at(i);
if (t && t->obj == object)
- list << TimerInfo(t->timerId, t->interval);
+ list << TimerInfo(t->timerId, t->interval, t->timerType);
}
return list;
}
diff --git a/src/corelib/kernel/qeventdispatcher_win_p.h b/src/corelib/kernel/qeventdispatcher_win_p.h
index 4a7aac0c04..300449d6cf 100644
--- a/src/corelib/kernel/qeventdispatcher_win_p.h
+++ b/src/corelib/kernel/qeventdispatcher_win_p.h
@@ -84,7 +84,7 @@ public:
void registerSocketNotifier(QSocketNotifier *notifier);
void unregisterSocketNotifier(QSocketNotifier *notifier);
- void registerTimer(int timerId, int interval, QObject *object);
+ void registerTimer(int timerId, int interval, Qt::TimerType timerType, QObject *object);
bool unregisterTimer(int timerId);
bool unregisterTimers(QObject *object);
QList<TimerInfo> registeredTimers(QObject *object) const;
@@ -120,6 +120,7 @@ struct WinTimerInfo { // internal timer info
QObject *dispatcher;
int timerId;
int interval;
+ Qt::TimerType timerType;
QObject *obj; // - object to receive events
bool inTimerEvent;
int fastTimerId;
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index 8db8aceced..db2ab4218d 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -1017,7 +1017,7 @@ bool QObject::event(QEvent *e)
QThreadData *threadData = d->threadData;
QAbstractEventDispatcher *eventDispatcher = threadData->eventDispatcher;
if (eventDispatcher) {
- QList<QPair<int, int> > timers = eventDispatcher->registeredTimers(this);
+ QList<QAbstractEventDispatcher::TimerInfo> timers = eventDispatcher->registeredTimers(this);
if (!timers.isEmpty()) {
// set inThreadChangeEvent to true to tell the dispatcher not to release out timer ids
// back to the pool (since the timer ids are moving to a new thread).
@@ -1025,7 +1025,7 @@ bool QObject::event(QEvent *e)
eventDispatcher->unregisterTimers(this);
d->inThreadChangeEvent = false;
QMetaObject::invokeMethod(this, "_q_reregisterTimers", Qt::QueuedConnection,
- Q_ARG(void*, (new QList<QPair<int, int> >(timers))));
+ Q_ARG(void*, (new QList<QAbstractEventDispatcher::TimerInfo>(timers))));
}
}
break;
@@ -1322,11 +1322,11 @@ void QObjectPrivate::setThreadData_helper(QThreadData *currentData, QThreadData
void QObjectPrivate::_q_reregisterTimers(void *pointer)
{
Q_Q(QObject);
- QList<QPair<int, int> > *timerList = reinterpret_cast<QList<QPair<int, int> > *>(pointer);
+ QList<QAbstractEventDispatcher::TimerInfo> *timerList = reinterpret_cast<QList<QAbstractEventDispatcher::TimerInfo> *>(pointer);
QAbstractEventDispatcher *eventDispatcher = threadData->eventDispatcher;
for (int i = 0; i < timerList->size(); ++i) {
- const QPair<int, int> &pair = timerList->at(i);
- eventDispatcher->registerTimer(pair.first, pair.second, q);
+ const QAbstractEventDispatcher::TimerInfo &ti = timerList->at(i);
+ eventDispatcher->registerTimer(ti.timerId, ti.interval, ti.timerType, q);
}
delete timerList;
}
@@ -1388,7 +1388,7 @@ int QObject::startTimer(int interval, Qt::TimerType timerType)
qWarning("QObject::startTimer: QTimer can only be used with threads started with QThread");
return 0;
}
- return d->threadData->eventDispatcher->registerTimer(interval, this);
+ return d->threadData->eventDispatcher->registerTimer(interval, timerType, this);
}
/*!
diff --git a/src/corelib/kernel/qtimerinfo_unix.cpp b/src/corelib/kernel/qtimerinfo_unix.cpp
index 0bb61de02e..8a0c6c5ac2 100644
--- a/src/corelib/kernel/qtimerinfo_unix.cpp
+++ b/src/corelib/kernel/qtimerinfo_unix.cpp
@@ -228,10 +228,11 @@ bool QTimerInfoList::timerWait(timeval &tm)
return true;
}
-void QTimerInfoList::registerTimer(int timerId, int interval, QObject *object)
+void QTimerInfoList::registerTimer(int timerId, int interval, Qt::TimerType timerType, QObject *object)
{
QTimerInfo *t = new QTimerInfo;
t->id = timerId;
+ t->timerType = timerType;
t->interval.tv_sec = interval / 1000;
t->interval.tv_usec = (interval % 1000) * 1000;
t->timeout = updateCurrentTime() + t->interval;
@@ -292,13 +293,13 @@ bool QTimerInfoList::unregisterTimers(QObject *object)
return true;
}
-QList<QPair<int, int> > QTimerInfoList::registeredTimers(QObject *object) const
+QList<QAbstractEventDispatcher::TimerInfo> QTimerInfoList::registeredTimers(QObject *object) const
{
- QList<QPair<int, int> > list;
+ QList<QAbstractEventDispatcher::TimerInfo> list;
for (int i = 0; i < count(); ++i) {
register const QTimerInfo * const t = at(i);
if (t->obj == object)
- list << QPair<int, int>(t->id, t->interval.tv_sec * 1000 + t->interval.tv_usec / 1000);
+ list << QAbstractEventDispatcher::TimerInfo(t->id, t->interval.tv_sec * 1000 + t->interval.tv_usec / 1000, t->timerType);
}
return list;
}
diff --git a/src/corelib/kernel/qtimerinfo_unix_p.h b/src/corelib/kernel/qtimerinfo_unix_p.h
index d464a146e3..82acb439e7 100644
--- a/src/corelib/kernel/qtimerinfo_unix_p.h
+++ b/src/corelib/kernel/qtimerinfo_unix_p.h
@@ -53,9 +53,7 @@
// We mean it.
//
-#include <qobject.h>
-#include <qlist.h>
-#include <qpair.h>
+#include "qabstracteventdispatcher.h"
#include <sys/time.h> // struct timeval
@@ -64,6 +62,7 @@ QT_BEGIN_NAMESPACE
// internal timer info
struct QTimerInfo {
int id; // - timer identifier
+ Qt::TimerType timerType; // - timer type
timeval interval; // - timer interval
timeval timeout; // - when to sent event
QObject *obj; // - object to receive event
@@ -97,10 +96,10 @@ public:
void timerInsert(QTimerInfo *);
void timerRepair(const timeval &);
- void registerTimer(int timerId, int interval, QObject *object);
+ void registerTimer(int timerId, int interval, Qt::TimerType timerType, QObject *object);
bool unregisterTimer(int timerId);
bool unregisterTimers(QObject *object);
- QList<QPair<int, int> > registeredTimers(QObject *object) const;
+ QList<QAbstractEventDispatcher::TimerInfo> registeredTimers(QObject *object) const;
int activateTimers();
};