8f427b2 by axis at 2009-04-24 1
/****************************************************************************
2
**
89c08c0 by Jason McDonald at 2012-01-11 3
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
04e3b30 by Jason McDonald at 2009-09-09 4
** All rights reserved.
858c70f by Jason McDonald at 2009-06-16 5
** Contact: Nokia Corporation (qt-info@nokia.com)
8f427b2 by axis at 2009-04-24 6
**
7
** This file is part of the QtCore module of the Qt Toolkit.
8
**
9
** $QT_BEGIN_LICENSE:LGPL$
10
** GNU Lesser General Public License Usage
1eea52e by Jyri Tahtela at 2011-05-13 11
** This file may be used under the terms of the GNU Lesser General Public
12
** License version 2.1 as published by the Free Software Foundation and
13
** appearing in the file LICENSE.LGPL included in the packaging of this
14
** file. Please review the following information to ensure the GNU Lesser
15
** General Public License version 2.1 requirements will be met:
16
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
8f427b2 by axis at 2009-04-24 17
**
04e3b30 by Jason McDonald at 2009-09-09 18
** In addition, as a special exception, Nokia gives you certain additional
1eea52e by Jyri Tahtela at 2011-05-13 19
** rights. These rights are described in the Nokia Qt LGPL Exception
04e3b30 by Jason McDonald at 2009-09-09 20
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
8f427b2 by axis at 2009-04-24 21
**
1eea52e by Jyri Tahtela at 2011-05-13 22
** GNU General Public License Usage
23
** Alternatively, this file may be used under the terms of the GNU General
24
** Public License version 3.0 as published by the Free Software Foundation
25
** and appearing in the file LICENSE.GPL included in the packaging of this
26
** file. Please review the following information to ensure the GNU General
27
** Public License version 3.0 requirements will be met:
28
** http://www.gnu.org/copyleft/gpl.html.
309db73 by Jason McDonald at 2009-08-31 29
**
1eea52e by Jyri Tahtela at 2011-05-13 30
** Other Usage
31
** Alternatively, this file may be used in accordance with the terms and
32
** conditions contained in a signed written agreement between you and Nokia.
309db73 by Jason McDonald at 2009-08-31 33
**
34
**
35
**
36
**
8f427b2 by axis at 2009-04-24 37
**
38
** $QT_END_LICENSE$
39
**
40
****************************************************************************/
41
42
#ifndef QOBJECT_H
43
#define QOBJECT_H
44
45
#ifndef QT_NO_QOBJECT
46
47
#include <QtCore/qobjectdefs.h>
48
#include <QtCore/qstring.h>
49
#include <QtCore/qbytearray.h>
50
#include <QtCore/qlist.h>
51
#ifdef QT_INCLUDE_COMPAT
52
#include <QtCore/qcoreevent.h>
53
#endif
7604f80 by Robert Griebl at 2009-06-10 54
#include <QtCore/qscopedpointer.h>
8f427b2 by axis at 2009-04-24 55
56
QT_BEGIN_HEADER
57
58
QT_BEGIN_NAMESPACE
59
60
QT_MODULE(Core)
61
62
class QEvent;
63
class QTimerEvent;
64
class QChildEvent;
65
struct QMetaObject;
66
class QVariant;
67
class QObjectPrivate;
68
class QObject;
69
class QThread;
70
class QWidget;
71
#ifndef QT_NO_REGEXP
72
class QRegExp;
73
#endif
74
#ifndef QT_NO_USERDATA
75
class QObjectUserData;
76
#endif
77
78
typedef QList<QObject*> QObjectList;
79
99160bb by Olivier Goffart at 2010-08-06 80
Q_CORE_EXPORT void qt_qFindChildren_helper(const QObject *parent, const QString &name, const QRegExp *re,
81
                                           const QMetaObject &mo, QList<void *> *list);
82
Q_CORE_EXPORT QObject *qt_qFindChild_helper(const QObject *parent, const QString &name, const QMetaObject &mo);
8f427b2 by axis at 2009-04-24 83
bed1014 by Jan-Arve Sæther at 2009-12-04 84
class
2e3ecbb by Jan-Arve Sæther at 2009-12-04 85
#if defined(__INTEL_COMPILER) && defined(Q_OS_WIN)
bed1014 by Jan-Arve Sæther at 2009-12-04 86
Q_CORE_EXPORT
2e3ecbb by Jan-Arve Sæther at 2009-12-04 87
#endif
bed1014 by Jan-Arve Sæther at 2009-12-04 88
QObjectData {
8f427b2 by axis at 2009-04-24 89
public:
90
    virtual ~QObjectData() = 0;
91
    QObject *q_ptr;
92
    QObject *parent;
93
    QObjectList children;
94
95
    uint isWidget : 1;
96
    uint pendTimer : 1;
97
    uint blockSig : 1;
98
    uint wasDeleted : 1;
99
    uint ownObjectName : 1;
100
    uint sendChildEvents : 1;
101
    uint receiveChildEvents : 1;
580d7f2 by Olivier Goffart at 2010-05-18 102
    uint inEventHandler : 1; //only used if QT_JAMBI_BUILD
8f427b2 by axis at 2009-04-24 103
    uint inThreadChangeEvent : 1;
1a5e717 by Olivier Goffart at 2009-06-10 104
    uint hasGuards : 1; //true iff there is one or more QPointer attached to this object
105
    uint unused : 22;
8f427b2 by axis at 2009-04-24 106
    int postedEvents;
f858dd8 by Aaron Kennedy at 2009-07-31 107
    QMetaObject *metaObject; // assert dynamic
8f427b2 by axis at 2009-04-24 108
};
109
110
111
class Q_CORE_EXPORT QObject
112
{
113
    Q_OBJECT
114
    Q_PROPERTY(QString objectName READ objectName WRITE setObjectName)
e5800dd by Harald Fernengel at 2009-08-06 115
    Q_DECLARE_PRIVATE(QObject)
8f427b2 by axis at 2009-04-24 116
117
public:
118
    Q_INVOKABLE explicit QObject(QObject *parent=0);
119
    virtual ~QObject();
120
121
    virtual bool event(QEvent *);
122
    virtual bool eventFilter(QObject *, QEvent *);
123
124
#ifdef qdoc
125
    static QString tr(const char *sourceText, const char *comment = 0, int n = -1);
126
    static QString trUtf8(const char *sourceText, const char *comment = 0, int n = -1);
127
    virtual const QMetaObject *metaObject() const;
128
    static const QMetaObject staticMetaObject;
129
#endif
130
#ifdef QT_NO_TRANSLATION
131
    static QString tr(const char *sourceText, const char *, int)
132
        { return QString::fromLatin1(sourceText); }
133
    static QString tr(const char *sourceText, const char * = 0)
134
        { return QString::fromLatin1(sourceText); }
135
#ifndef QT_NO_TEXTCODEC
136
    static QString trUtf8(const char *sourceText, const char *, int)
137
        { return QString::fromUtf8(sourceText); }
138
    static QString trUtf8(const char *sourceText, const char * = 0)
139
        { return QString::fromUtf8(sourceText); }
140
#endif
141
#endif //QT_NO_TRANSLATION
142
143
    QString objectName() const;
144
    void setObjectName(const QString &name);
145
146
    inline bool isWidgetType() const { return d_ptr->isWidget; }
147
148
    inline bool signalsBlocked() const { return d_ptr->blockSig; }
149
    bool blockSignals(bool b);
150
151
    QThread *thread() const;
152
    void moveToThread(QThread *thread);
153
154
    int startTimer(int interval);
155
    void killTimer(int id);
156
157
    template<typename T>
158
    inline T findChild(const QString &aName = QString()) const
99160bb by Olivier Goffart at 2010-08-06 159
    { return static_cast<T>(qt_qFindChild_helper(this, aName, reinterpret_cast<T>(0)->staticMetaObject)); }
8f427b2 by axis at 2009-04-24 160
161
    template<typename T>
162
    inline QList<T> findChildren(const QString &aName = QString()) const
99160bb by Olivier Goffart at 2010-08-06 163
    {
164
        QList<T> list;
165
        union {
166
            QList<T> *typedList;
167
            QList<void *> *voidList;
168
        } u;
169
        u.typedList = &list;
170
        qt_qFindChildren_helper(this, aName, 0, reinterpret_cast<T>(0)->staticMetaObject, u.voidList);
171
        return list;
172
    }
8f427b2 by axis at 2009-04-24 173
174
#ifndef QT_NO_REGEXP
175
    template<typename T>
176
    inline QList<T> findChildren(const QRegExp &re) const
99160bb by Olivier Goffart at 2010-08-06 177
    {
178
        QList<T> list;
179
        union {
180
            QList<T> *typedList;
181
            QList<void *> *voidList;
182
        } u;
183
        u.typedList = &list;
184
        qt_qFindChildren_helper(this, QString(), &re, reinterpret_cast<T>(0)->staticMetaObject, u.voidList);
185
        return list;
186
    }
8f427b2 by axis at 2009-04-24 187
#endif
188
189
#ifdef QT3_SUPPORT
190
    QT3_SUPPORT QObject *child(const char *objName, const char *inheritsClass = 0,
191
                   bool recursiveSearch = true) const;
192
    QT3_SUPPORT QObjectList queryList(const char *inheritsClass = 0,
193
                          const char *objName = 0,
194
                          bool regexpMatch = true,
195
                          bool recursiveSearch = true) const;
196
#endif
197
    inline const QObjectList &children() const { return d_ptr->children; }
198
199
    void setParent(QObject *);
200
    void installEventFilter(QObject *);
201
    void removeEventFilter(QObject *);
202
203
204
    static bool connect(const QObject *sender, const char *signal,
205
                        const QObject *receiver, const char *member, Qt::ConnectionType =
206
#ifdef qdoc
207
                        Qt::AutoConnection
208
#else
209
#ifdef QT3_SUPPORT
210
                        Qt::AutoCompatConnection
211
#else
212
                        Qt::AutoConnection
213
#endif
214
#endif
215
        );
4a2ba04 by Sergey Vidyuk at 2010-06-18 216
        
217
    static bool connect(const QObject *sender, const QMetaMethod &signal,
218
                        const QObject *receiver, const QMetaMethod &method,
219
                        Qt::ConnectionType type = 
220
#ifdef qdoc
221
                        Qt::AutoConnection
222
#else
223
#ifdef QT3_SUPPORT
224
                        Qt::AutoCompatConnection
225
#else
226
                        Qt::AutoConnection
227
#endif
228
#endif
229
        );
230
8f427b2 by axis at 2009-04-24 231
    inline bool connect(const QObject *sender, const char *signal,
232
                        const char *member, Qt::ConnectionType type =
233
#ifdef qdoc
234
                        Qt::AutoConnection
235
#else
236
#ifdef QT3_SUPPORT
237
                        Qt::AutoCompatConnection
238
#else
239
                        Qt::AutoConnection
240
#endif
241
#endif
242
        ) const;
243
244
    static bool disconnect(const QObject *sender, const char *signal,
245
                           const QObject *receiver, const char *member);
4a2ba04 by Sergey Vidyuk at 2010-06-18 246
    static bool disconnect(const QObject *sender, const QMetaMethod &signal,
247
                           const QObject *receiver, const QMetaMethod &member);
8f427b2 by axis at 2009-04-24 248
    inline bool disconnect(const char *signal = 0,
249
                           const QObject *receiver = 0, const char *member = 0)
250
        { return disconnect(this, signal, receiver, member); }
251
    inline bool disconnect(const QObject *receiver, const char *member = 0)
252
        { return disconnect(this, 0, receiver, member); }
253
254
    void dumpObjectTree();
255
    void dumpObjectInfo();
256
257
#ifndef QT_NO_PROPERTIES
258
    bool setProperty(const char *name, const QVariant &value);
259
    QVariant property(const char *name) const;
260
    QList<QByteArray> dynamicPropertyNames() const;
261
#endif // QT_NO_PROPERTIES
262
263
#ifndef QT_NO_USERDATA
264
    static uint registerUserData();
265
    void setUserData(uint id, QObjectUserData* data);
266
    QObjectUserData* userData(uint id) const;
267
#endif // QT_NO_USERDATA
268
269
Q_SIGNALS:
270
    void destroyed(QObject * = 0);
271
272
public:
273
    inline QObject *parent() const { return d_ptr->parent; }
274
275
    inline bool inherits(const char *classname) const
276
        { return const_cast<QObject *>(this)->qt_metacast(classname) != 0; }
277
278
public Q_SLOTS:
279
    void deleteLater();
280
281
protected:
282
    QObject *sender() const;
a6892d6 by John Brooks at 2010-08-12 283
    int senderSignalIndex() const;
8f427b2 by axis at 2009-04-24 284
    int receivers(const char* signal) const;
285
286
    virtual void timerEvent(QTimerEvent *);
287
    virtual void childEvent(QChildEvent *);
288
    virtual void customEvent(QEvent *);
289
290
    virtual void connectNotify(const char *signal);
291
    virtual void disconnectNotify(const char *signal);
292
293
#ifdef QT3_SUPPORT
294
public:
295
    QT3_SUPPORT_CONSTRUCTOR QObject(QObject *parent, const char *name);
296
    inline QT3_SUPPORT void insertChild(QObject *o)
297
        { if (o) o->setParent(this); }
298
    inline QT3_SUPPORT void removeChild(QObject *o)
299
        { if (o) o->setParent(0); }
300
    inline QT3_SUPPORT bool isA(const char *classname) const
301
        { return qstrcmp(classname, metaObject()->className()) == 0; }
302
    inline QT3_SUPPORT const char *className() const { return metaObject()->className(); }
303
    inline QT3_SUPPORT const char *name() const { return objectName().latin1_helper(); }
304
    inline QT3_SUPPORT const char *name(const char *defaultName) const
305
        { QString s = objectName(); return s.isEmpty()?defaultName:s.latin1_helper(); }
306
    inline QT3_SUPPORT void setName(const char *aName) { setObjectName(QLatin1String(aName)); }
307
protected:
308
    inline QT3_SUPPORT bool checkConnectArgs(const char *signal,
309
                                  const QObject *,
310
                                  const char *member)
311
        { return QMetaObject::checkConnectArgs(signal, member); }
312
    static inline QT3_SUPPORT QByteArray normalizeSignalSlot(const char *signalSlot)
313
        { return QMetaObject::normalizedSignature(signalSlot); }
314
#endif
315
316
protected:
317
    QObject(QObjectPrivate &dd, QObject *parent = 0);
318
319
protected:
7604f80 by Robert Griebl at 2009-06-10 320
    QScopedPointer<QObjectData> d_ptr;
8f427b2 by axis at 2009-04-24 321
322
    static const QMetaObject staticQtMetaObject;
323
324
    friend struct QMetaObject;
325
    friend class QApplication;
326
    friend class QApplicationPrivate;
327
    friend class QCoreApplication;
328
    friend class QCoreApplicationPrivate;
329
    friend class QWidget;
330
    friend class QThreadData;
331
332
private:
333
    Q_DISABLE_COPY(QObject)
334
    Q_PRIVATE_SLOT(d_func(), void _q_reregisterTimers(void *))
335
};
336
337
inline bool QObject::connect(const QObject *asender, const char *asignal,
338
                             const char *amember, Qt::ConnectionType atype) const
339
{ return connect(asender, asignal, this, amember, atype); }
340
341
#ifndef QT_NO_USERDATA
342
class Q_CORE_EXPORT QObjectUserData {
343
public:
344
    virtual ~QObjectUserData();
345
};
346
#endif
347
6bc6003 by David Boddie at 2011-05-06 348
#ifdef qdoc
349
T qFindChild(const QObject *o, const QString &name = QString());
350
QList<T> qFindChildren(const QObject *oobj, const QString &name = QString());
351
QList<T> qFindChildren(const QObject *o, const QRegExp &re);
352
#endif
99160bb by Olivier Goffart at 2010-08-06 353
#ifdef QT_DEPRECATED
8f427b2 by axis at 2009-04-24 354
template<typename T>
99160bb by Olivier Goffart at 2010-08-06 355
inline QT_DEPRECATED T qFindChild(const QObject *o, const QString &name = QString())
356
{ return o->findChild<T>(name); }
8f427b2 by axis at 2009-04-24 357
358
template<typename T>
a4d1be7 by Thiago Macieira at 2010-09-21 359
inline QT_DEPRECATED QList<T> qFindChildren(const QObject *o, const QString &name = QString())
8f427b2 by axis at 2009-04-24 360
{
99160bb by Olivier Goffart at 2010-08-06 361
    return o->findChildren<T>(name);
8f427b2 by axis at 2009-04-24 362
}
363
364
#ifndef QT_NO_REGEXP
365
template<typename T>
99160bb by Olivier Goffart at 2010-08-06 366
inline QT_DEPRECATED QList<T> qFindChildren(const QObject *o, const QRegExp &re)
8f427b2 by axis at 2009-04-24 367
{
99160bb by Olivier Goffart at 2010-08-06 368
    return o->findChildren<T>(re);
8f427b2 by axis at 2009-04-24 369
}
370
#endif
371
99160bb by Olivier Goffart at 2010-08-06 372
#endif //QT_DEPRECATED
373
8f427b2 by axis at 2009-04-24 374
template <class T>
375
inline T qobject_cast(QObject *object)
376
{
26f43dc by miniak at 2010-08-03 377
#if !defined(QT_NO_QOBJECT_CHECK)
5e3c4b6 by Olivier Goffart at 2011-01-28 378
    reinterpret_cast<T>(object)->qt_check_for_QOBJECT_macro(*reinterpret_cast<T>(object));
8f427b2 by axis at 2009-04-24 379
#endif
5e3c4b6 by Olivier Goffart at 2011-01-28 380
    return static_cast<T>(reinterpret_cast<T>(object)->staticMetaObject.cast(object));
8f427b2 by axis at 2009-04-24 381
}
382
383
template <class T>
384
inline T qobject_cast(const QObject *object)
385
{
26f43dc by miniak at 2010-08-03 386
#if !defined(QT_NO_QOBJECT_CHECK)
5e3c4b6 by Olivier Goffart at 2011-01-28 387
    reinterpret_cast<T>(object)->qt_check_for_QOBJECT_macro(*reinterpret_cast<T>(const_cast<QObject *>(object)));
8f427b2 by axis at 2009-04-24 388
#endif
5e3c4b6 by Olivier Goffart at 2011-01-28 389
    return static_cast<T>(reinterpret_cast<T>(object)->staticMetaObject.cast(object));
8f427b2 by axis at 2009-04-24 390
}
391
392
e1ef9b4 by Leonardo Sobral Cunha at 2009-08-28 393
template <class T> inline const char * qobject_interface_iid()
46ca473 by Aaron Kennedy at 2009-07-31 394
{ return 0; }
395
8f427b2 by axis at 2009-04-24 396
#ifndef Q_MOC_RUN
397
#  define Q_DECLARE_INTERFACE(IFace, IId) \
46ca473 by Aaron Kennedy at 2009-07-31 398
    template <> inline const char *qobject_interface_iid<IFace *>() \
399
    { return IId; } \
8f427b2 by axis at 2009-04-24 400
    template <> inline IFace *qobject_cast<IFace *>(QObject *object) \
401
    { return reinterpret_cast<IFace *>((object ? object->qt_metacast(IId) : 0)); } \
402
    template <> inline IFace *qobject_cast<IFace *>(const QObject *object) \
403
    { return reinterpret_cast<IFace *>((object ? const_cast<QObject *>(object)->qt_metacast(IId) : 0)); }
404
#endif // Q_MOC_RUN
405
406
#ifndef QT_NO_DEBUG_STREAM
407
Q_CORE_EXPORT QDebug operator<<(QDebug, const QObject *);
408
#endif
409
410
QT_END_NAMESPACE
411
412
QT_END_HEADER
413
414
#endif
415
416
#endif // QOBJECT_H