| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/kernel/qabstracteventdispatcher.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||
| 2 | ** | - | ||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||
| 5 | ** | - | ||||||
| 6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||
| 7 | ** | - | ||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||
| 9 | ** Commercial License Usage | - | ||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||
| 16 | ** | - | ||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||
| 19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||
| 25 | ** | - | ||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||
| 29 | ** | - | ||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||
| 31 | ** | - | ||||||
| 32 | ****************************************************************************/ | - | ||||||
| 33 | - | |||||||
| 34 | #include "qabstracteventdispatcher.h" | - | ||||||
| 35 | #include "qabstracteventdispatcher_p.h" | - | ||||||
| 36 | #include "qabstractnativeeventfilter.h" | - | ||||||
| 37 | - | |||||||
| 38 | #include "qthread.h" | - | ||||||
| 39 | #include <private/qthread_p.h> | - | ||||||
| 40 | #include <private/qcoreapplication_p.h> | - | ||||||
| 41 | #include <private/qfreelist_p.h> | - | ||||||
| 42 | - | |||||||
| 43 | QT_BEGIN_NAMESPACE | - | ||||||
| 44 | - | |||||||
| 45 | // we allow for 2^24 = 8^8 = 16777216 simultaneously running timers | - | ||||||
| 46 | struct QtTimerIdFreeListConstants : public QFreeListDefaultConstants | - | ||||||
| 47 | { | - | ||||||
| 48 | enum | - | ||||||
| 49 | { | - | ||||||
| 50 | InitialNextValue = 1, | - | ||||||
| 51 | BlockCount = 6 | - | ||||||
| 52 | }; | - | ||||||
| 53 | - | |||||||
| 54 | static const int Sizes[BlockCount]; | - | ||||||
| 55 | }; | - | ||||||
| 56 | - | |||||||
| 57 | enum { | - | ||||||
| 58 | Offset0 = 0x00000000, | - | ||||||
| 59 | Offset1 = 0x00000040, | - | ||||||
| 60 | Offset2 = 0x00000100, | - | ||||||
| 61 | Offset3 = 0x00001000, | - | ||||||
| 62 | Offset4 = 0x00010000, | - | ||||||
| 63 | Offset5 = 0x00100000, | - | ||||||
| 64 | - | |||||||
| 65 | Size0 = Offset1 - Offset0, | - | ||||||
| 66 | Size1 = Offset2 - Offset1, | - | ||||||
| 67 | Size2 = Offset3 - Offset2, | - | ||||||
| 68 | Size3 = Offset4 - Offset3, | - | ||||||
| 69 | Size4 = Offset5 - Offset4, | - | ||||||
| 70 | Size5 = QtTimerIdFreeListConstants::MaxIndex - Offset5 | - | ||||||
| 71 | }; | - | ||||||
| 72 | - | |||||||
| 73 | const int QtTimerIdFreeListConstants::Sizes[QtTimerIdFreeListConstants::BlockCount] = { | - | ||||||
| 74 | Size0, | - | ||||||
| 75 | Size1, | - | ||||||
| 76 | Size2, | - | ||||||
| 77 | Size3, | - | ||||||
| 78 | Size4, | - | ||||||
| 79 | Size5 | - | ||||||
| 80 | }; | - | ||||||
| 81 | - | |||||||
| 82 | typedef QFreeList<void, QtTimerIdFreeListConstants> QtTimerIdFreeList; | - | ||||||
| 83 | Q_GLOBAL_STATIC(QtTimerIdFreeList, timerIdFreeList) executed 207 times by 200 tests: end of blockExecuted by:
executed 207 times by 200 tests: guard.store(QtGlobalStatic::Destroyed);Executed by:
executed 329093 times by 294 tests: return &holder.value;Executed by:
| 0-329093 | ||||||
| 84 | - | |||||||
| 85 | int QAbstractEventDispatcherPrivate::allocateTimerId() | - | ||||||
| 86 | { | - | ||||||
| 87 | return timerIdFreeList()->next(); executed 165302 times by 206 tests: return timerIdFreeList()->next();Executed by:
| 165302 | ||||||
| 88 | } | - | ||||||
| 89 | - | |||||||
| 90 | void QAbstractEventDispatcherPrivate::releaseTimerId(int timerId) | - | ||||||
| 91 | { | - | ||||||
| 92 | // this function may be called by a global destructor after | - | ||||||
| 93 | // timerIdFreeList() has been destructed | - | ||||||
| 94 | if (QtTimerIdFreeList *fl = timerIdFreeList())
| 16-163791 | ||||||
| 95 | fl->release(timerId); executed 163791 times by 285 tests: fl->release(timerId);Executed by:
| 163791 | ||||||
| 96 | } executed 163807 times by 301 tests: end of blockExecuted by:
| 163807 | ||||||
| 97 | - | |||||||
| 98 | /*! | - | ||||||
| 99 | \class QAbstractEventDispatcher | - | ||||||
| 100 | \inmodule QtCore | - | ||||||
| 101 | \brief The QAbstractEventDispatcher class provides an interface to manage Qt's event queue. | - | ||||||
| 102 | - | |||||||
| 103 | \ingroup events | - | ||||||
| 104 | - | |||||||
| 105 | An event dispatcher receives events from the window system and other | - | ||||||
| 106 | sources. It then sends them to the QCoreApplication or QApplication | - | ||||||
| 107 | instance for processing and delivery. QAbstractEventDispatcher provides | - | ||||||
| 108 | fine-grained control over event delivery. | - | ||||||
| 109 | - | |||||||
| 110 | For simple control of event processing use | - | ||||||
| 111 | QCoreApplication::processEvents(). | - | ||||||
| 112 | - | |||||||
| 113 | For finer control of the application's event loop, call | - | ||||||
| 114 | instance() and call functions on the QAbstractEventDispatcher | - | ||||||
| 115 | object that is returned. If you want to use your own instance of | - | ||||||
| 116 | QAbstractEventDispatcher or of a QAbstractEventDispatcher | - | ||||||
| 117 | subclass, you must install it with QCoreApplication::setEventDispatcher() | - | ||||||
| 118 | or QThread::setEventDispatcher() \e before a default event dispatcher has | - | ||||||
| 119 | been installed. | - | ||||||
| 120 | - | |||||||
| 121 | The main event loop is started by calling | - | ||||||
| 122 | QCoreApplication::exec(), and stopped by calling | - | ||||||
| 123 | QCoreApplication::exit(). Local event loops can be created using | - | ||||||
| 124 | QEventLoop. | - | ||||||
| 125 | - | |||||||
| 126 | Programs that perform long operations can call processEvents() | - | ||||||
| 127 | with a bitwise OR combination of various QEventLoop::ProcessEventsFlag | - | ||||||
| 128 | values to control which events should be delivered. | - | ||||||
| 129 | - | |||||||
| 130 | QAbstractEventDispatcher also allows the integration of an | - | ||||||
| 131 | external event loop with the Qt event loop. | - | ||||||
| 132 | - | |||||||
| 133 | \sa QEventLoop, QCoreApplication, QThread | - | ||||||
| 134 | */ | - | ||||||
| 135 | - | |||||||
| 136 | /*! | - | ||||||
| 137 | Constructs a new event dispatcher with the given \a parent. | - | ||||||
| 138 | */ | - | ||||||
| 139 | QAbstractEventDispatcher::QAbstractEventDispatcher(QObject *parent) | - | ||||||
| 140 | : QObject(*new QAbstractEventDispatcherPrivate, parent) {} executed 30 times by 4 tests: end of blockExecuted by:
| 30 | ||||||
| 141 | - | |||||||
| 142 | /*! | - | ||||||
| 143 | \internal | - | ||||||
| 144 | */ | - | ||||||
| 145 | QAbstractEventDispatcher::QAbstractEventDispatcher(QAbstractEventDispatcherPrivate &dd, | - | ||||||
| 146 | QObject *parent) | - | ||||||
| 147 | : QObject(dd, parent) {} executed 639945 times by 549 tests: end of blockExecuted by:
| 639945 | ||||||
| 148 | - | |||||||
| 149 | /*! | - | ||||||
| 150 | Destroys the event dispatcher. | - | ||||||
| 151 | */ | - | ||||||
| 152 | QAbstractEventDispatcher::~QAbstractEventDispatcher() | - | ||||||
| 153 | { } | - | ||||||
| 154 | - | |||||||
| 155 | /*! | - | ||||||
| 156 | Returns a pointer to the event dispatcher object for the specified | - | ||||||
| 157 | \a thread. If \a thread is zero, the current thread is used. If no | - | ||||||
| 158 | event dispatcher exists for the specified thread, this function | - | ||||||
| 159 | returns 0. | - | ||||||
| 160 | - | |||||||
| 161 | \b{Note:} If Qt is built without thread support, the \a thread | - | ||||||
| 162 | argument is ignored. | - | ||||||
| 163 | */ | - | ||||||
| 164 | QAbstractEventDispatcher *QAbstractEventDispatcher::instance(QThread *thread) | - | ||||||
| 165 | { | - | ||||||
| 166 | QThreadData *data = thread ? QThreadData::get2(thread) : QThreadData::current();
| 3427-641563 | ||||||
| 167 | return data->eventDispatcher.load(); executed 644990 times by 173 tests: return data->eventDispatcher.load();Executed by:
| 644990 | ||||||
| 168 | } | - | ||||||
| 169 | - | |||||||
| 170 | /*! | - | ||||||
| 171 | \fn bool QAbstractEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags) | - | ||||||
| 172 | - | |||||||
| 173 | Processes pending events that match \a flags until there are no | - | ||||||
| 174 | more events to process. Returns \c true if an event was processed; | - | ||||||
| 175 | otherwise returns \c false. | - | ||||||
| 176 | - | |||||||
| 177 | This function is especially useful if you have a long running | - | ||||||
| 178 | operation, and want to show its progress without allowing user | - | ||||||
| 179 | input by using the QEventLoop::ExcludeUserInputEvents flag. | - | ||||||
| 180 | - | |||||||
| 181 | If the QEventLoop::WaitForMoreEvents flag is set in \a flags, the | - | ||||||
| 182 | behavior of this function is as follows: | - | ||||||
| 183 | - | |||||||
| 184 | \list | - | ||||||
| 185 | - | |||||||
| 186 | \li If events are available, this function returns after processing | - | ||||||
| 187 | them. | - | ||||||
| 188 | - | |||||||
| 189 | \li If no events are available, this function will wait until more | - | ||||||
| 190 | are available and return after processing newly available events. | - | ||||||
| 191 | - | |||||||
| 192 | \endlist | - | ||||||
| 193 | - | |||||||
| 194 | If the QEventLoop::WaitForMoreEvents flag is not set in \a flags, | - | ||||||
| 195 | and no events are available, this function will return | - | ||||||
| 196 | immediately. | - | ||||||
| 197 | - | |||||||
| 198 | \b{Note:} This function does not process events continuously; it | - | ||||||
| 199 | returns after all available events are processed. | - | ||||||
| 200 | - | |||||||
| 201 | \sa hasPendingEvents() | - | ||||||
| 202 | */ | - | ||||||
| 203 | - | |||||||
| 204 | /*! \fn bool QAbstractEventDispatcher::hasPendingEvents() | - | ||||||
| 205 | \deprecated | - | ||||||
| 206 | - | |||||||
| 207 | Returns \c true if there is an event waiting; otherwise returns false. This | - | ||||||
| 208 | function is an implementation detail for | - | ||||||
| 209 | QCoreApplication::hasPendingEvents() and must not be called directly. | - | ||||||
| 210 | */ | - | ||||||
| 211 | - | |||||||
| 212 | /*! | - | ||||||
| 213 | \fn void QAbstractEventDispatcher::registerSocketNotifier(QSocketNotifier *notifier) | - | ||||||
| 214 | - | |||||||
| 215 | Registers \a notifier with the event loop. Subclasses must | - | ||||||
| 216 | implement this method to tie a socket notifier into another | - | ||||||
| 217 | event loop. | - | ||||||
| 218 | */ | - | ||||||
| 219 | - | |||||||
| 220 | /*! \fn void QAbstractEventDispatcher::unregisterSocketNotifier(QSocketNotifier *notifier) | - | ||||||
| 221 | - | |||||||
| 222 | Unregisters \a notifier from the event dispatcher. Subclasses must | - | ||||||
| 223 | reimplement this method to tie a socket notifier into another | - | ||||||
| 224 | event loop. Reimplementations must call the base | - | ||||||
| 225 | implementation. | - | ||||||
| 226 | */ | - | ||||||
| 227 | - | |||||||
| 228 | /*! | - | ||||||
| 229 | \obsolete | - | ||||||
| 230 | - | |||||||
| 231 | \fn int QAbstractEventDispatcher::registerTimer(int interval, QObject *object) | - | ||||||
| 232 | - | |||||||
| 233 | Registers a timer with the specified \a interval for the given \a object | - | ||||||
| 234 | and returns the timer id. | - | ||||||
| 235 | */ | - | ||||||
| 236 | - | |||||||
| 237 | /*! | - | ||||||
| 238 | \obsolete | - | ||||||
| 239 | - | |||||||
| 240 | \fn void QAbstractEventDispatcher::registerTimer(int timerId, int interval, QObject *object) | - | ||||||
| 241 | - | |||||||
| 242 | Register a timer with the specified \a timerId and \a interval for the | - | ||||||
| 243 | given \a object. | - | ||||||
| 244 | */ | - | ||||||
| 245 | - | |||||||
| 246 | /*! | - | ||||||
| 247 | Registers a timer with the specified \a interval and \a timerType for the | - | ||||||
| 248 | given \a object and returns the timer id. | - | ||||||
| 249 | */ | - | ||||||
| 250 | int QAbstractEventDispatcher::registerTimer(int interval, Qt::TimerType timerType, QObject *object) | - | ||||||
| 251 | { | - | ||||||
| 252 | int id = QAbstractEventDispatcherPrivate::allocateTimerId(); | - | ||||||
| 253 | registerTimer(id, interval, timerType, object); | - | ||||||
| 254 | return id; executed 165302 times by 206 tests: return id;Executed by:
| 165302 | ||||||
| 255 | } | - | ||||||
| 256 | - | |||||||
| 257 | /*! | - | ||||||
| 258 | \fn void QAbstractEventDispatcher::registerTimer(int timerId, int interval, Qt::TimerType timerType, QObject *object) | - | ||||||
| 259 | - | |||||||
| 260 | Register a timer with the specified \a timerId, \a interval, and \a | - | ||||||
| 261 | timerType for the given \a object. | - | ||||||
| 262 | */ | - | ||||||
| 263 | - | |||||||
| 264 | /*! | - | ||||||
| 265 | \fn bool QAbstractEventDispatcher::unregisterTimer(int timerId) | - | ||||||
| 266 | - | |||||||
| 267 | Unregisters the timer with the given \a timerId. | - | ||||||
| 268 | Returns \c true if successful; otherwise returns \c false. | - | ||||||
| 269 | - | |||||||
| 270 | \sa registerTimer(), unregisterTimers() | - | ||||||
| 271 | */ | - | ||||||
| 272 | - | |||||||
| 273 | /*! | - | ||||||
| 274 | \fn bool QAbstractEventDispatcher::unregisterTimers(QObject *object) | - | ||||||
| 275 | - | |||||||
| 276 | Unregisters all the timers associated with the given \a object. | - | ||||||
| 277 | Returns \c true if all timers were successful removed; otherwise returns \c false. | - | ||||||
| 278 | - | |||||||
| 279 | \sa unregisterTimer(), registeredTimers() | - | ||||||
| 280 | */ | - | ||||||
| 281 | - | |||||||
| 282 | /*! | - | ||||||
| 283 | \fn QList<TimerInfo> QAbstractEventDispatcher::registeredTimers(QObject *object) const | - | ||||||
| 284 | - | |||||||
| 285 | Returns a list of registered timers for \a object. The TimerInfo struct has | - | ||||||
| 286 | \c timerId, \c interval, and \c timerType members. | - | ||||||
| 287 | - | |||||||
| 288 | \sa Qt::TimerType | - | ||||||
| 289 | */ | - | ||||||
| 290 | - | |||||||
| 291 | /*! | - | ||||||
| 292 | \fn int QAbstractEventDispatcher::remainingTime(int timerId) | - | ||||||
| 293 | - | |||||||
| 294 | Returns the remaining time in milliseconds with the given \a timerId. | - | ||||||
| 295 | If the timer is inactive, the returned value will be -1. If the timer is | - | ||||||
| 296 | overdue, the returned value will be 0. | - | ||||||
| 297 | - | |||||||
| 298 | \sa Qt::TimerType | - | ||||||
| 299 | */ | - | ||||||
| 300 | - | |||||||
| 301 | /*! \fn void QAbstractEventDispatcher::wakeUp() | - | ||||||
| 302 | \threadsafe | - | ||||||
| 303 | - | |||||||
| 304 | Wakes up the event loop. | - | ||||||
| 305 | - | |||||||
| 306 | \sa awake() | - | ||||||
| 307 | */ | - | ||||||
| 308 | - | |||||||
| 309 | /*! | - | ||||||
| 310 | \fn void QAbstractEventDispatcher::interrupt() | - | ||||||
| 311 | - | |||||||
| 312 | Interrupts event dispatching. The event dispatcher will | - | ||||||
| 313 | return from processEvents() as soon as possible. | - | ||||||
| 314 | */ | - | ||||||
| 315 | - | |||||||
| 316 | /*! \fn void QAbstractEventDispatcher::flush() | - | ||||||
| 317 | - | |||||||
| 318 | Flushes the event queue. This normally returns almost | - | ||||||
| 319 | immediately. Does nothing on platforms other than X11. | - | ||||||
| 320 | */ | - | ||||||
| 321 | - | |||||||
| 322 | // ### DOC: Are these called when the _application_ starts/stops or just | - | ||||||
| 323 | // when the current _event loop_ starts/stops? | - | ||||||
| 324 | /*! | - | ||||||
| 325 | \internal | - | ||||||
| 326 | */ | - | ||||||
| 327 | void QAbstractEventDispatcher::startingUp() | - | ||||||
| 328 | { } | - | ||||||
| 329 | - | |||||||
| 330 | /*! | - | ||||||
| 331 | \internal | - | ||||||
| 332 | */ | - | ||||||
| 333 | void QAbstractEventDispatcher::closingDown() | - | ||||||
| 334 | { } | - | ||||||
| 335 | - | |||||||
| 336 | /*! | - | ||||||
| 337 | \class QAbstractEventDispatcher::TimerInfo | - | ||||||
| 338 | \inmodule QtCore | - | ||||||
| 339 | - | |||||||
| 340 | This struct represents information about a timer: | - | ||||||
| 341 | \l{QAbstractEventDispatcher::TimerInfo::timerId}{timerId}, | - | ||||||
| 342 | \l{QAbstractEventDispatcher::TimerInfo::interval}{interval}, and | - | ||||||
| 343 | \l{QAbstractEventDispatcher::TimerInfo::timerType}{timerType}. | - | ||||||
| 344 | - | |||||||
| 345 | \sa registeredTimers() | - | ||||||
| 346 | */ | - | ||||||
| 347 | /*! \fn QAbstractEventDispatcher::TimerInfo::TimerInfo(int timerId, int interval, Qt::TimerType timerType) | - | ||||||
| 348 | - | |||||||
| 349 | Constructs a TimerInfo struct with the given \a timerId, \a interval, and | - | ||||||
| 350 | \a timerType. | - | ||||||
| 351 | */ | - | ||||||
| 352 | /*! | - | ||||||
| 353 | \variable QAbstractEventDispatcher::TimerInfo::timerId | - | ||||||
| 354 | - | |||||||
| 355 | The timer's unique id. | - | ||||||
| 356 | */ | - | ||||||
| 357 | /*! | - | ||||||
| 358 | \variable QAbstractEventDispatcher::TimerInfo::interval | - | ||||||
| 359 | - | |||||||
| 360 | The timer's interval. | - | ||||||
| 361 | */ | - | ||||||
| 362 | /*! | - | ||||||
| 363 | \variable QAbstractEventDispatcher::TimerInfo::timerType | - | ||||||
| 364 | - | |||||||
| 365 | The timer's type | - | ||||||
| 366 | - | |||||||
| 367 | \sa Qt::TimerType | - | ||||||
| 368 | */ | - | ||||||
| 369 | - | |||||||
| 370 | /*! | - | ||||||
| 371 | Installs an event filter \a filterObj for all native event filters | - | ||||||
| 372 | received by the application. | - | ||||||
| 373 | - | |||||||
| 374 | The event filter \a filterObj receives events via its \l {QAbstractNativeEventFilter::}{nativeEventFilter()} | - | ||||||
| 375 | function, which is called for all events received by all threads. | - | ||||||
| 376 | - | |||||||
| 377 | The \l {QAbstractNativeEventFilter::}{nativeEventFilter()} function should return true | - | ||||||
| 378 | if the event should be filtered, (in this case, stopped). It should return false to allow | - | ||||||
| 379 | normal Qt processing to continue: the native event can then be translated | - | ||||||
| 380 | into a QEvent and handled by the standard Qt \l{QEvent} {event} filtering, | - | ||||||
| 381 | e.g. QObject::installEventFilter(). | - | ||||||
| 382 | - | |||||||
| 383 | If multiple event filters are installed, the filter that was installed last | - | ||||||
| 384 | is activated first. | - | ||||||
| 385 | - | |||||||
| 386 | \note The filter function set here receives native messages, | - | ||||||
| 387 | that is, MSG or XEvent structs. | - | ||||||
| 388 | - | |||||||
| 389 | For maximum portability, you should always try to use QEvent objects | - | ||||||
| 390 | and QObject::installEventFilter() whenever possible. | - | ||||||
| 391 | - | |||||||
| 392 | \sa QObject::installEventFilter() | - | ||||||
| 393 | - | |||||||
| 394 | \since 5.0 | - | ||||||
| 395 | */ | - | ||||||
| 396 | void QAbstractEventDispatcher::installNativeEventFilter(QAbstractNativeEventFilter *filterObj) | - | ||||||
| 397 | { | - | ||||||
| 398 | Q_D(QAbstractEventDispatcher); | - | ||||||
| 399 | - | |||||||
| 400 | // clean up unused items in the list | - | ||||||
| 401 | d->eventFilters.removeAll(0); | - | ||||||
| 402 | d->eventFilters.removeAll(filterObj); | - | ||||||
| 403 | d->eventFilters.prepend(filterObj); | - | ||||||
| 404 | } executed 373 times by 2 tests: end of blockExecuted by:
| 373 | ||||||
| 405 | - | |||||||
| 406 | /*! | - | ||||||
| 407 | Removes the event filter \a filter from this object. The | - | ||||||
| 408 | request is ignored if such an event filter has not been installed. | - | ||||||
| 409 | - | |||||||
| 410 | All event filters for this object are automatically removed when | - | ||||||
| 411 | this object is destroyed. | - | ||||||
| 412 | - | |||||||
| 413 | It is always safe to remove an event filter, even during event filter | - | ||||||
| 414 | filter activation (that is, even from within the \l {QAbstractNativeEventFilter::}{nativeEventFilter()} function). | - | ||||||
| 415 | - | |||||||
| 416 | \sa installNativeEventFilter(), QAbstractNativeEventFilter | - | ||||||
| 417 | \since 5.0 | - | ||||||
| 418 | */ | - | ||||||
| 419 | void QAbstractEventDispatcher::removeNativeEventFilter(QAbstractNativeEventFilter *filter) | - | ||||||
| 420 | { | - | ||||||
| 421 | Q_D(QAbstractEventDispatcher); | - | ||||||
| 422 | for (int i = 0; i < d->eventFilters.count(); ++i) {
| 69-442 | ||||||
| 423 | if (d->eventFilters.at(i) == filter) {
| 69-373 | ||||||
| 424 | d->eventFilters[i] = 0; | - | ||||||
| 425 | break; executed 373 times by 2 tests: break;Executed by:
| 373 | ||||||
| 426 | } | - | ||||||
| 427 | } executed 69 times by 1 test: end of blockExecuted by:
| 69 | ||||||
| 428 | } executed 442 times by 2 tests: end of blockExecuted by:
| 442 | ||||||
| 429 | - | |||||||
| 430 | /*! | - | ||||||
| 431 | Sends \a message through the event filters that were set by | - | ||||||
| 432 | installNativeEventFilter(). This function returns \c true as soon as an | - | ||||||
| 433 | event filter returns \c true, and false otherwise to indicate that | - | ||||||
| 434 | the processing of the event should continue. | - | ||||||
| 435 | - | |||||||
| 436 | Subclasses of QAbstractEventDispatcher \e must call this function | - | ||||||
| 437 | for \e all messages received from the system to ensure | - | ||||||
| 438 | compatibility with any extensions that may be used in the | - | ||||||
| 439 | application. The type of event \a eventType is specific to the platform | - | ||||||
| 440 | plugin chosen at run-time, and can be used to cast message to the right type. | - | ||||||
| 441 | The \a result pointer is only used on Windows, and corresponds to the LRESULT pointer. | - | ||||||
| 442 | - | |||||||
| 443 | Note that the type of \a message is platform dependent. See | - | ||||||
| 444 | QAbstractNativeEventFilter for details. | - | ||||||
| 445 | - | |||||||
| 446 | \sa installNativeEventFilter(), QAbstractNativeEventFilter::nativeEventFilter() | - | ||||||
| 447 | \since 5.0 | - | ||||||
| 448 | */ | - | ||||||
| 449 | bool QAbstractEventDispatcher::filterNativeEvent(const QByteArray &eventType, void *message, long *result) | - | ||||||
| 450 | { | - | ||||||
| 451 | Q_D(QAbstractEventDispatcher); | - | ||||||
| 452 | if (!d->eventFilters.isEmpty()) {
| 234191-2647553 | ||||||
| 453 | // Raise the loopLevel so that deleteLater() calls in or triggered | - | ||||||
| 454 | // by event_filter() will be processed from the main event loop. | - | ||||||
| 455 | QScopedLoopLevelCounter loopLevelCounter(d->threadData); | - | ||||||
| 456 | for (int i = 0; i < d->eventFilters.size(); ++i) {
| 2647553 | ||||||
| 457 | QAbstractNativeEventFilter *filter = d->eventFilters.at(i); | - | ||||||
| 458 | if (!filter)
| 6313-2641240 | ||||||
| 459 | continue; executed 6313 times by 1 test: continue;Executed by:
| 6313 | ||||||
| 460 | if (filter->nativeEventFilter(eventType, message, result))
| 0-2641240 | ||||||
| 461 | return true; never executed: return true; | 0 | ||||||
| 462 | } executed 2641240 times by 2 tests: end of blockExecuted by:
| 2641240 | ||||||
| 463 | } executed 2647553 times by 2 tests: end of blockExecuted by:
| 2647553 | ||||||
| 464 | return false; executed 2881744 times by 114 tests: return false;Executed by:
| 2881744 | ||||||
| 465 | } | - | ||||||
| 466 | - | |||||||
| 467 | /*! \fn bool QAbstractEventDispatcher::filterEvent(void *message) | - | ||||||
| 468 | \deprecated | - | ||||||
| 469 | - | |||||||
| 470 | Calls filterNativeEvent() with an empty eventType and \a message. | - | ||||||
| 471 | This function returns \c true as soon as an | - | ||||||
| 472 | event filter returns \c true, and false otherwise to indicate that | - | ||||||
| 473 | the processing of the event should continue. | - | ||||||
| 474 | */ | - | ||||||
| 475 | - | |||||||
| 476 | /*! \fn bool QAbstractEventDispatcher::registerEventNotifier(QWinEventNotifier *notifier); | - | ||||||
| 477 | - | |||||||
| 478 | This pure virtual method exists on windows only and has to be reimplemented by a Windows specific | - | ||||||
| 479 | event dispatcher implementation. \a notifier is the QWinEventNotifier instance to be registered. | - | ||||||
| 480 | - | |||||||
| 481 | The method should return true if the registration of \a notifier was sucessful, otherwise false. | - | ||||||
| 482 | - | |||||||
| 483 | QWinEventNotifier calls this method in it's constructor and there should never be a need to call this | - | ||||||
| 484 | method directly. | - | ||||||
| 485 | - | |||||||
| 486 | \sa QWinEventNotifier, unregisterEventNotifier() | - | ||||||
| 487 | */ | - | ||||||
| 488 | - | |||||||
| 489 | /*! \fn bool QAbstractEventDispatcher::unregisterEventNotifier(QWinEventNotifier *notifier); | - | ||||||
| 490 | - | |||||||
| 491 | This pure virtual method exists on windows only and has to be reimplemented by a Windows specific | - | ||||||
| 492 | event dispatcher implementation. \a notifier is the QWinEventNotifier instance to be unregistered. | - | ||||||
| 493 | - | |||||||
| 494 | QWinEventNotifier calls this method in it's destructor and there should never be a need to call this | - | ||||||
| 495 | method directly. | - | ||||||
| 496 | - | |||||||
| 497 | \sa QWinEventNotifier, registerEventNotifier() | - | ||||||
| 498 | */ | - | ||||||
| 499 | - | |||||||
| 500 | /*! \fn void QAbstractEventDispatcher::awake() | - | ||||||
| 501 | - | |||||||
| 502 | This signal is emitted after the event loop returns from a | - | ||||||
| 503 | function that could block. | - | ||||||
| 504 | - | |||||||
| 505 | \sa wakeUp(), aboutToBlock() | - | ||||||
| 506 | */ | - | ||||||
| 507 | - | |||||||
| 508 | /*! \fn void QAbstractEventDispatcher::aboutToBlock() | - | ||||||
| 509 | - | |||||||
| 510 | This signal is emitted before the event loop calls a function that | - | ||||||
| 511 | could block. | - | ||||||
| 512 | - | |||||||
| 513 | \sa awake() | - | ||||||
| 514 | */ | - | ||||||
| 515 | - | |||||||
| 516 | QT_END_NAMESPACE | - | ||||||
| Source code | Switch to Preprocessed file |