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>
This commit is contained in:
parent
ef60ed1c9d
commit
2bbf9befd8
12
dist/changes-5.0.0
vendored
12
dist/changes-5.0.0
vendored
@ -123,6 +123,18 @@ information about a particular change.
|
||||
- The previously exported function qt_translateRawTouchEvent() has been removed.
|
||||
Use QWindowSystemInterface::handleTouchEvent() instead.
|
||||
|
||||
- QAbstractEventDispatcher
|
||||
|
||||
* The signature for the pure-virtual registerTimer() has changed. Subclasses
|
||||
of QAbstractEventDispatcher will need to be updated to reimplement the new
|
||||
pure-virtual 'virtual void registerTimer(int timerId, int interval,
|
||||
Qt::TimerType timerType, QObject *object) = 0;'
|
||||
|
||||
* QAbstractEventDispatcher::TimerInfo is no longer a QPair<int, int>. It is
|
||||
now a struct with 3 members: struct TimerInfo { int timerId; int interval;
|
||||
Qt::TimerType timerType; }; Reimplementations of
|
||||
QAbstractEventDispatcher::registeredTimers() will need to be updated to pass
|
||||
3 arguments to the TimerInfo constructor (instead of 2).
|
||||
|
||||
****************************************************************************
|
||||
* General *
|
||||
|
@ -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.
|
||||
*/
|
||||
int QAbstractEventDispatcher::registerTimer(int interval, QObject *object)
|
||||
|
||||
/*!
|
||||
\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, 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()
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
};
|
||||
|
@ -121,7 +121,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;
|
||||
@ -137,6 +137,7 @@ private:
|
||||
struct MacTimerInfo {
|
||||
int id;
|
||||
int interval;
|
||||
Qt::TimerType timerType;
|
||||
QObject *obj;
|
||||
bool pending;
|
||||
CFRunLoopTimerRef runLoopTimer;
|
||||
|
@ -139,7 +139,7 @@ void QCocoaEventDispatcherPrivate::activateTimer(CFRunLoopTimerRef, void *info)
|
||||
|
||||
}
|
||||
|
||||
void QCocoaEventDispatcher::registerTimer(int timerId, int interval, QObject *obj)
|
||||
void QCocoaEventDispatcher::registerTimer(int timerId, int interval, Qt::TimerType timerType, QObject *obj)
|
||||
{
|
||||
#ifndef QT_NO_DEBUG
|
||||
if (timerId < 1 || interval < 0 || !obj) {
|
||||
@ -154,6 +154,7 @@ void QCocoaEventDispatcher::registerTimer(int timerId, int interval, QObject *ob
|
||||
MacTimerInfo *t = new MacTimerInfo();
|
||||
t->id = timerId;
|
||||
t->interval = interval;
|
||||
t->timerType = timerType;
|
||||
t->obj = obj;
|
||||
t->runLoopTimer = 0;
|
||||
t->pending = false;
|
||||
@ -241,7 +242,7 @@ QCocoaEventDispatcher::registeredTimers(QObject *object) const
|
||||
while (it != QCocoaEventDispatcherPrivate::macTimerHash.constEnd()) {
|
||||
MacTimerInfo *t = it.value();
|
||||
if (t->obj == object)
|
||||
list << TimerInfo(t->id, t->interval);
|
||||
list << TimerInfo(t->id, t->interval, t->timerType);
|
||||
++it;
|
||||
}
|
||||
return list;
|
||||
|
@ -601,7 +601,7 @@ public:
|
||||
}
|
||||
void registerSocketNotifier(QSocketNotifier *) {}
|
||||
void unregisterSocketNotifier(QSocketNotifier *) {}
|
||||
void registerTimer(int , int , QObject *) {}
|
||||
void registerTimer(int , int , Qt::TimerType, QObject *) {}
|
||||
bool unregisterTimer(int ) { return false; }
|
||||
bool unregisterTimers(QObject *) { return false; }
|
||||
QList<TimerInfo> registeredTimers(QObject *) const { return QList<TimerInfo>(); }
|
||||
|
@ -1228,7 +1228,7 @@ public:
|
||||
}
|
||||
void registerSocketNotifier(QSocketNotifier *) {}
|
||||
void unregisterSocketNotifier(QSocketNotifier *) {}
|
||||
void registerTimer(int , int , QObject *) {}
|
||||
void registerTimer(int, int, Qt::TimerType, QObject *) {}
|
||||
bool unregisterTimer(int ) { return false; }
|
||||
bool unregisterTimers(QObject *) { return false; }
|
||||
QList<TimerInfo> registeredTimers(QObject *) const { return QList<TimerInfo>(); }
|
||||
|
@ -57,8 +57,7 @@ public:
|
||||
void interrupt() {}
|
||||
bool processEvents(QEventLoop::ProcessEventsFlags) { return false; }
|
||||
void registerSocketNotifier(QSocketNotifier*) {}
|
||||
int registerTimer(int,QObject*) { return -1; }
|
||||
void registerTimer(int,int,QObject*) {}
|
||||
void registerTimer(int,int,Qt::TimerType,QObject*) {}
|
||||
QList<TimerInfo> registeredTimers(QObject*) const { return QList<TimerInfo>(); }
|
||||
void unregisterSocketNotifier(QSocketNotifier*) {}
|
||||
bool unregisterTimer(int) { return false; }
|
||||
|
@ -57,8 +57,7 @@ public:
|
||||
void interrupt() {}
|
||||
bool processEvents(QEventLoop::ProcessEventsFlags) { return false; }
|
||||
void registerSocketNotifier(QSocketNotifier*) {}
|
||||
int registerTimer(int,QObject*) { return -1; }
|
||||
void registerTimer(int,int,QObject*) {}
|
||||
void registerTimer(int,int,Qt::TimerType,QObject*) {}
|
||||
QList<TimerInfo> registeredTimers(QObject*) const { return QList<TimerInfo>(); }
|
||||
void unregisterSocketNotifier(QSocketNotifier*) {}
|
||||
bool unregisterTimer(int) { return false; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user