Introduce QMetaType::UnknownType.
[profile/ivi/qtbase.git] / src / corelib / kernel / qbasictimer.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qbasictimer.h"
43 #include "qabstracteventdispatcher.h"
44 #include "qabstracteventdispatcher_p.h"
45
46 QT_BEGIN_NAMESPACE
47
48 /*!
49     \class QBasicTimer
50     \brief The QBasicTimer class provides timer events for objects.
51
52     \ingroup events
53
54     This is a fast, lightweight, and low-level class used by Qt
55     internally. We recommend using the higher-level QTimer class
56     rather than this class if you want to use timers in your
57     applications. Note that this timer is a repeating timer that
58     will send subsequent timer events unless the stop() function is called.
59
60     To use this class, create a QBasicTimer, and call its start()
61     function with a timeout interval and with a pointer to a QObject
62     subclass. When the timer times out it will send a timer event to
63     the QObject subclass. The timer can be stopped at any time using
64     stop(). isActive() returns true for a timer that is running;
65     i.e. it has been started, has not reached the timeout time, and
66     has not been stopped. The timer's ID can be retrieved using
67     timerId().
68
69     The \l{widgets/wiggly}{Wiggly} example uses QBasicTimer to repaint
70     a widget at regular intervals.
71
72     \sa QTimer, QTimerEvent, QObject::timerEvent(), Timers, {Wiggly Example}
73 */
74
75
76 /*!
77     \fn QBasicTimer::QBasicTimer()
78
79     Contructs a basic timer.
80
81     \sa start()
82 */
83 /*!
84     \fn QBasicTimer::~QBasicTimer()
85
86     Destroys the basic timer.
87 */
88
89 /*!
90     \fn bool QBasicTimer::isActive() const
91
92     Returns true if the timer is running and has not been stopped; otherwise
93     returns false.
94
95     \sa start() stop()
96 */
97
98 /*!
99     \fn int QBasicTimer::timerId() const
100
101     Returns the timer's ID.
102
103     \sa QTimerEvent::timerId()
104 */
105
106 /*!
107     \fn void QBasicTimer::start(int msec, QObject *object)
108
109     Starts (or restarts) the timer with a \a msec milliseconds timeout. The
110     timer will be a Qt::CoarseTimer. See Qt::TimerType for information on the
111     different timer types.
112
113     The given \a object will receive timer events.
114
115     \sa stop() isActive() QObject::timerEvent() Qt::CoarseTimer
116  */
117 void QBasicTimer::start(int msec, QObject *obj)
118 {
119     QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance();
120     if (!eventDispatcher) {
121         qWarning("QBasicTimer::start: QBasicTimer can only be used with threads started with QThread");
122         return;
123     }
124     if (id) {
125         eventDispatcher->unregisterTimer(id);
126         QAbstractEventDispatcherPrivate::releaseTimerId(id);
127     }
128     id = 0;
129     if (obj)
130         id = eventDispatcher->registerTimer(msec, Qt::CoarseTimer, obj);
131 }
132
133 /*!
134     \overload
135
136     Starts (or restarts) the timer with a \a msec milliseconds timeout and the
137     given \a timerType. See Qt::TimerType for information on the different
138     timer types.
139
140     The given \a object will receive timer events.
141
142     \sa stop() isActive() QObject::timerEvent() Qt::TimerType
143  */
144 void QBasicTimer::start(int msec, Qt::TimerType timerType, QObject *obj)
145 {
146     QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance();
147     if (!eventDispatcher) {
148         qWarning("QBasicTimer::start: QBasicTimer can only be used with threads started with QThread");
149         return;
150     }
151     if (id) {
152         eventDispatcher->unregisterTimer(id);
153         QAbstractEventDispatcherPrivate::releaseTimerId(id);
154     }
155     id = 0;
156     if (obj)
157         id = eventDispatcher->registerTimer(msec, timerType, obj);
158 }
159
160 /*!
161     Stops the timer.
162
163     \sa start() isActive()
164 */
165 void QBasicTimer::stop()
166 {
167     if (id) {
168         QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance();
169         if (eventDispatcher)
170             eventDispatcher->unregisterTimer(id);
171         QAbstractEventDispatcherPrivate::releaseTimerId(id);
172     }
173     id = 0;
174 }
175
176 QT_END_NAMESPACE