2015-12-10 05:06:13 +02:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
** Contact: http://www.qt.io/licensing/
|
|
|
|
**
|
|
|
|
** This file is part of the QtCore module of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see http://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at http://www.qt.io/contact-us.
|
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
**
|
|
|
|
** As a special exception, The Qt Company gives you certain additional
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3.0 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU General Public License version 3.0 requirements will be
|
|
|
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef QOBJECT_H
|
|
|
|
#define QOBJECT_H
|
|
|
|
|
|
|
|
#ifndef QT_NO_QOBJECT
|
|
|
|
|
|
|
|
#include <QtCore/qobjectdefs.h>
|
|
|
|
#include <QtCore/qstring.h>
|
|
|
|
#include <QtCore/qlist.h>
|
2016-06-09 01:11:10 +00:00
|
|
|
|
2015-12-10 05:06:13 +02:00
|
|
|
QT_BEGIN_HEADER
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
|
|
|
|
|
|
|
class QEvent;
|
|
|
|
class QTimerEvent;
|
|
|
|
class QChildEvent;
|
|
|
|
struct QMetaObject;
|
|
|
|
class QVariant;
|
|
|
|
class QObjectPrivate;
|
|
|
|
class QObject;
|
|
|
|
class QThread;
|
|
|
|
class QWidget;
|
2016-10-18 22:06:15 +00:00
|
|
|
class QDebug;
|
2015-12-10 05:06:13 +02:00
|
|
|
#ifndef QT_NO_REGEXP
|
|
|
|
class QRegExp;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef QList<QObject*> QObjectList;
|
|
|
|
|
|
|
|
Q_CORE_EXPORT void qt_qFindChildren_helper(const QObject *parent, const QString &name, const QRegExp *re,
|
|
|
|
const QMetaObject &mo, QList<void *> *list);
|
|
|
|
Q_CORE_EXPORT QObject *qt_qFindChild_helper(const QObject *parent, const QString &name, const QMetaObject &mo);
|
|
|
|
|
2016-09-14 03:15:37 +00:00
|
|
|
class QObjectData {
|
2015-12-10 05:06:13 +02:00
|
|
|
public:
|
|
|
|
QObject *q_ptr;
|
|
|
|
QObject *parent;
|
|
|
|
QObjectList children;
|
|
|
|
|
2019-05-21 20:00:35 +00:00
|
|
|
bool isWidget;
|
|
|
|
bool pendTimer;
|
|
|
|
bool blockSig;
|
|
|
|
bool wasDeleted;
|
|
|
|
bool sendChildEvents;
|
|
|
|
bool receiveChildEvents;
|
|
|
|
bool inThreadChangeEvent;
|
2015-12-10 05:06:13 +02:00
|
|
|
int postedEvents;
|
|
|
|
QMetaObject *metaObject; // assert dynamic
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Q_CORE_EXPORT QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(QString objectName READ objectName WRITE setObjectName)
|
|
|
|
Q_DECLARE_PRIVATE(QObject)
|
|
|
|
|
|
|
|
public:
|
2016-11-04 00:12:26 +00:00
|
|
|
Q_INVOKABLE explicit QObject(QObject *parent = Q_NULLPTR);
|
2015-12-10 05:06:13 +02:00
|
|
|
virtual ~QObject();
|
|
|
|
|
|
|
|
virtual bool event(QEvent *);
|
|
|
|
virtual bool eventFilter(QObject *, QEvent *);
|
|
|
|
|
|
|
|
#ifdef QT_NO_TRANSLATION
|
2016-11-04 00:12:26 +00:00
|
|
|
static QString tr(const char *sourceText, const char * = Q_NULLPTR, int = -1)
|
2015-12-10 05:06:13 +02:00
|
|
|
{ return QString::fromLatin1(sourceText); }
|
|
|
|
#ifndef QT_NO_TEXTCODEC
|
2016-11-04 00:12:26 +00:00
|
|
|
static QString trUtf8(const char *sourceText, const char * = Q_NULLPTR, int = -1)
|
2015-12-10 05:06:13 +02:00
|
|
|
{ return QString::fromUtf8(sourceText); }
|
|
|
|
#endif
|
|
|
|
#endif //QT_NO_TRANSLATION
|
|
|
|
|
|
|
|
QString objectName() const;
|
|
|
|
void setObjectName(const QString &name);
|
|
|
|
|
|
|
|
inline bool isWidgetType() const { return d_ptr->isWidget; }
|
|
|
|
|
|
|
|
inline bool signalsBlocked() const { return d_ptr->blockSig; }
|
|
|
|
bool blockSignals(bool b);
|
|
|
|
|
|
|
|
QThread *thread() const;
|
|
|
|
void moveToThread(QThread *thread);
|
|
|
|
|
|
|
|
int startTimer(int interval);
|
|
|
|
void killTimer(int id);
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
inline T findChild(const QString &aName = QString()) const
|
|
|
|
{ return static_cast<T>(qt_qFindChild_helper(this, aName, reinterpret_cast<T>(0)->staticMetaObject)); }
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
inline QList<T> findChildren(const QString &aName = QString()) const
|
|
|
|
{
|
|
|
|
QList<T> list;
|
|
|
|
union {
|
|
|
|
QList<T> *typedList;
|
|
|
|
QList<void *> *voidList;
|
|
|
|
} u;
|
|
|
|
u.typedList = &list;
|
2016-11-04 00:12:26 +00:00
|
|
|
qt_qFindChildren_helper(this, aName, Q_NULLPTR, reinterpret_cast<T>(0)->staticMetaObject, u.voidList);
|
2015-12-10 05:06:13 +02:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef QT_NO_REGEXP
|
|
|
|
template<typename T>
|
|
|
|
inline QList<T> findChildren(const QRegExp &re) const
|
|
|
|
{
|
|
|
|
QList<T> list;
|
|
|
|
union {
|
|
|
|
QList<T> *typedList;
|
|
|
|
QList<void *> *voidList;
|
|
|
|
} u;
|
|
|
|
u.typedList = &list;
|
|
|
|
qt_qFindChildren_helper(this, QString(), &re, reinterpret_cast<T>(0)->staticMetaObject, u.voidList);
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
inline const QObjectList &children() const { return d_ptr->children; }
|
|
|
|
|
|
|
|
void setParent(QObject *);
|
|
|
|
void installEventFilter(QObject *);
|
|
|
|
void removeEventFilter(QObject *);
|
|
|
|
|
|
|
|
|
|
|
|
static bool connect(const QObject *sender, const char *signal,
|
2016-09-21 03:52:13 +00:00
|
|
|
const QObject *receiver, const char *member,
|
|
|
|
Qt::ConnectionType type = Qt::AutoConnection
|
2015-12-10 05:06:13 +02:00
|
|
|
);
|
2016-09-21 03:52:13 +00:00
|
|
|
|
2015-12-10 05:06:13 +02:00
|
|
|
static bool connect(const QObject *sender, const QMetaMethod &signal,
|
|
|
|
const QObject *receiver, const QMetaMethod &method,
|
|
|
|
Qt::ConnectionType type = Qt::AutoConnection
|
|
|
|
);
|
|
|
|
|
|
|
|
inline bool connect(const QObject *sender, const char *signal,
|
2016-09-21 03:52:13 +00:00
|
|
|
const char *member,
|
|
|
|
Qt::ConnectionType type = Qt::AutoConnection
|
|
|
|
) const
|
|
|
|
{ return connect(sender, signal, this, member, type); }
|
|
|
|
|
2015-12-10 05:06:13 +02:00
|
|
|
|
|
|
|
static bool disconnect(const QObject *sender, const char *signal,
|
|
|
|
const QObject *receiver, const char *member);
|
|
|
|
static bool disconnect(const QObject *sender, const QMetaMethod &signal,
|
|
|
|
const QObject *receiver, const QMetaMethod &member);
|
2016-11-04 00:12:26 +00:00
|
|
|
inline bool disconnect(const char *signal = Q_NULLPTR,
|
|
|
|
const QObject *receiver = Q_NULLPTR, const char *member = Q_NULLPTR)
|
2015-12-10 05:06:13 +02:00
|
|
|
{ return disconnect(this, signal, receiver, member); }
|
2016-11-04 00:12:26 +00:00
|
|
|
inline bool disconnect(const QObject *receiver, const char *member = Q_NULLPTR)
|
|
|
|
{ return disconnect(this, Q_NULLPTR, receiver, member); }
|
2015-12-10 05:06:13 +02:00
|
|
|
|
|
|
|
void dumpObjectTree();
|
|
|
|
void dumpObjectInfo();
|
|
|
|
|
|
|
|
#ifndef QT_NO_PROPERTIES
|
|
|
|
bool setProperty(const char *name, const QVariant &value);
|
|
|
|
QVariant property(const char *name) const;
|
|
|
|
QList<QByteArray> dynamicPropertyNames() const;
|
|
|
|
#endif // QT_NO_PROPERTIES
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
2016-11-04 00:12:26 +00:00
|
|
|
void destroyed(QObject * = Q_NULLPTR);
|
2015-12-10 05:06:13 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
inline QObject *parent() const { return d_ptr->parent; }
|
|
|
|
|
|
|
|
inline bool inherits(const char *classname) const
|
2016-11-04 00:12:26 +00:00
|
|
|
{ return const_cast<QObject *>(this)->qt_metacast(classname) != Q_NULLPTR; }
|
2015-12-10 05:06:13 +02:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
void deleteLater();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
QObject *sender() const;
|
|
|
|
int senderSignalIndex() const;
|
|
|
|
int receivers(const char* signal) const;
|
|
|
|
|
|
|
|
virtual void timerEvent(QTimerEvent *);
|
|
|
|
virtual void childEvent(QChildEvent *);
|
|
|
|
virtual void customEvent(QEvent *);
|
|
|
|
|
|
|
|
virtual void connectNotify(const char *signal);
|
|
|
|
virtual void disconnectNotify(const char *signal);
|
|
|
|
|
2016-11-03 22:13:13 +00:00
|
|
|
QObject(QObjectPrivate &dd, QObject *parent = Q_NULLPTR);
|
2015-12-10 05:06:13 +02:00
|
|
|
|
2016-11-01 17:38:09 +00:00
|
|
|
QObjectData* d_ptr;
|
2015-12-10 05:06:13 +02:00
|
|
|
|
|
|
|
static const QMetaObject staticQtMetaObject;
|
|
|
|
|
|
|
|
friend struct QMetaObject;
|
|
|
|
friend class QApplication;
|
|
|
|
friend class QApplicationPrivate;
|
|
|
|
friend class QCoreApplication;
|
|
|
|
friend class QCoreApplicationPrivate;
|
|
|
|
friend class QWidget;
|
|
|
|
friend class QThreadData;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Q_DISABLE_COPY(QObject)
|
|
|
|
Q_PRIVATE_SLOT(d_func(), void _q_reregisterTimers(void *))
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
inline T qobject_cast(QObject *object)
|
|
|
|
{
|
|
|
|
#if !defined(QT_NO_QOBJECT_CHECK)
|
|
|
|
reinterpret_cast<T>(object)->qt_check_for_QOBJECT_macro(*reinterpret_cast<T>(object));
|
|
|
|
#endif
|
|
|
|
return static_cast<T>(reinterpret_cast<T>(object)->staticMetaObject.cast(object));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
inline T qobject_cast(const QObject *object)
|
|
|
|
{
|
|
|
|
#if !defined(QT_NO_QOBJECT_CHECK)
|
|
|
|
reinterpret_cast<T>(object)->qt_check_for_QOBJECT_macro(*reinterpret_cast<T>(const_cast<QObject *>(object)));
|
|
|
|
#endif
|
|
|
|
return static_cast<T>(reinterpret_cast<T>(object)->staticMetaObject.cast(object));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class T> inline const char * qobject_interface_iid()
|
2016-11-09 22:06:38 +00:00
|
|
|
{ return Q_NULLPTR; }
|
2015-12-10 05:06:13 +02:00
|
|
|
|
|
|
|
#ifndef Q_MOC_RUN
|
|
|
|
# define Q_DECLARE_INTERFACE(IFace, IId) \
|
2017-05-09 06:54:24 +00:00
|
|
|
QT_BEGIN_NAMESPACE \
|
2015-12-10 05:06:13 +02:00
|
|
|
template <> inline const char *qobject_interface_iid<IFace *>() \
|
|
|
|
{ return IId; } \
|
|
|
|
template <> inline IFace *qobject_cast<IFace *>(QObject *object) \
|
2016-11-04 12:42:19 +00:00
|
|
|
{ return reinterpret_cast<IFace *>((object ? object->qt_metacast(IId) : Q_NULLPTR)); } \
|
2015-12-10 05:06:13 +02:00
|
|
|
template <> inline IFace *qobject_cast<IFace *>(const QObject *object) \
|
2017-05-09 06:54:24 +00:00
|
|
|
{ return reinterpret_cast<IFace *>((object ? const_cast<QObject *>(object)->qt_metacast(IId) : Q_NULLPTR)); } \
|
|
|
|
QT_END_NAMESPACE
|
2015-12-10 05:06:13 +02:00
|
|
|
#endif // Q_MOC_RUN
|
|
|
|
|
|
|
|
#ifndef QT_NO_DEBUG_STREAM
|
|
|
|
Q_CORE_EXPORT QDebug operator<<(QDebug, const QObject *);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
QT_END_HEADER
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // QOBJECT_H
|