diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2009-07-31 16:46:11 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2009-08-04 14:29:34 (GMT) |
commit | d6e7238903d381bf2c2c9f89c17085e714384e87 (patch) | |
tree | b47b9969b15cdd9c4faf92011692864d8be655f9 | |
parent | 9081e1e65681aab1c1d8a913b1a493fe1d37e837 (diff) | |
download | Qt-d6e7238903d381bf2c2c9f89c17085e714384e87.zip Qt-d6e7238903d381bf2c2c9f89c17085e714384e87.tar.gz Qt-d6e7238903d381bf2c2c9f89c17085e714384e87.tar.bz2 |
Reorganise QObjectPrivate so that it's easier to tell what's in it.
Also rename QDeclarativeData to QObjectDeletionNotification, since it
has no relation to declarative UI. It's just notification of the
object's deletion. Make the destructor non-inline and place it in
qobject.cpp, so that the virtual table is emitted there and exported
from QtCore.
Also move the QObjectData destructor to qobject.cpp. This means you
cannot create any class deriving directly from QObjectData outside
QtCore, which is the intention anyways (it's a private class and only
QObjectPrivate derives from it).
Reviewed-by: Bradley T. Hughes
-rw-r--r-- | src/corelib/kernel/qobject.cpp | 16 | ||||
-rw-r--r-- | src/corelib/kernel/qobject_p.h | 113 | ||||
-rw-r--r-- | src/gui/kernel/qwidget.cpp | 7 |
3 files changed, 66 insertions, 70 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index c989d15..1938012 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -122,8 +122,11 @@ extern "C" Q_CORE_EXPORT void qt_removeObject(QObject *) } } +QObjectData::~QObjectData() {} +QObjectDeletionNotification::~QObjectDeletionNotification() {} + QObjectPrivate::QObjectPrivate(int version) - : threadData(0), currentSender(0), declarativeData(0), connectionLists(0), senders(0) + : threadData(0), connectionLists(0), senders(0), currentSender(0), deletionNotification(0), objectGuards(0) { if (version != QObjectPrivateVersion) qFatal("Cannot mix incompatible Qt libraries"); @@ -144,7 +147,6 @@ QObjectPrivate::QObjectPrivate(int version) inEventHandler = false; inThreadChangeEvent = false; deleteWatch = 0; - objectGuards = 0; metaObject = 0; hasGuards = false; } @@ -767,6 +769,8 @@ QObject::~QObject() } emit destroyed(this); + if (d->deletionNotification) + d->deletionNotification->destroyed(this); { QMutexLocker locker(signalSlotLock(this)); @@ -844,14 +848,6 @@ QObject::~QObject() d->eventFilters.clear(); - // As declarativeData is in a union with currentChildBeingDeleted, this must - // be done (and declarativeData set back to 0) before deleting children. - if(d->declarativeData) { - QDeclarativeData *dd = d->declarativeData; - d->declarativeData = 0; - dd->destroyed(this); - } - if (!d->children.isEmpty()) d->deleteChildren(); diff --git a/src/corelib/kernel/qobject_p.h b/src/corelib/kernel/qobject_p.h index 0b41c9a..52b4658 100644 --- a/src/corelib/kernel/qobject_p.h +++ b/src/corelib/kernel/qobject_p.h @@ -82,63 +82,21 @@ void Q_CORE_EXPORT qt_register_signal_spy_callbacks(const QSignalSpyCallbackSet extern QSignalSpyCallbackSet Q_CORE_EXPORT qt_signal_spy_callback_set; -inline QObjectData::~QObjectData() {} - enum { QObjectPrivateVersion = QT_VERSION }; -class QDeclarativeData +class Q_CORE_EXPORT QObjectDeletionNotification { public: - virtual ~QDeclarativeData() {} - virtual void destroyed(QObject *) {} + virtual ~QObjectDeletionNotification(); + virtual void destroyed(QObject *) = 0; }; +typedef QObjectDeletionNotification QDeclarativeData; // remove me when Declarative UI updates class Q_CORE_EXPORT QObjectPrivate : public QObjectData { Q_DECLARE_PUBLIC(QObject) public: - QObjectPrivate(int version = QObjectPrivateVersion); - virtual ~QObjectPrivate(); - -#ifdef QT3_SUPPORT - QList<QObject *> pendingChildInsertedEvents; - void sendPendingChildInsertedEvents(); - void removePendingChildInsertedEvents(QObject *child); -#else - // preserve binary compatibility with code compiled without Qt 3 support - QList<QObject *> unused; -#endif - - // id of the thread that owns the object - QThreadData *threadData; - void moveToThread_helper(); - void setThreadData_helper(QThreadData *currentData, QThreadData *targetData); - void _q_reregisterTimers(void *pointer); - - struct Sender - { - QObject *sender; - int signal; - int ref; - }; - // object currently activating the object - Sender *currentSender; - - QDeclarativeData *declarativeData; - - bool isSender(const QObject *receiver, const char *signal) const; - QObjectList receiverList(const char *signal) const; - QObjectList senderList() const; - - QList<QPointer<QObject> > eventFilters; - - void setParent_helper(QObject *); - - void deleteChildren(); - - static void clearGuards(QObject *); - struct ExtraData { #ifndef QT_NO_USERDATA @@ -147,12 +105,7 @@ public: QList<QByteArray> propertyNames; QList<QVariant> propertyValues; }; - ExtraData *extraData; - mutable quint32 connectedSignals[2]; - - QString objectName; - // Note: you must hold the signalSlotLock() before accessing the lists below or calling the functions struct Connection { QObject *sender; @@ -167,11 +120,34 @@ public: }; typedef QList<Connection *> ConnectionList; - QObjectConnectionListVector *connectionLists; + struct Sender + { + QObject *sender; + int signal; + int ref; + }; + + + QObjectPrivate(int version = QObjectPrivateVersion); + virtual ~QObjectPrivate(); + void deleteChildren(); + + void setParent_helper(QObject *); + void moveToThread_helper(); + void setThreadData_helper(QThreadData *currentData, QThreadData *targetData); + void _q_reregisterTimers(void *pointer); + + bool isSender(const QObject *receiver, const char *signal) const; + QObjectList receiverList(const char *signal) const; + QObjectList senderList() const; + void addConnection(int signal, Connection *c); void cleanConnectionLists(); - Connection *senders; //linked list; +#ifdef QT3_SUPPORT + void sendPendingChildInsertedEvents(); + void removePendingChildInsertedEvents(QObject *child); +#endif static Sender *setCurrentSender(QObject *receiver, Sender *sender); @@ -180,13 +156,38 @@ public: Sender *previousSender); static int *setDeleteWatch(QObjectPrivate *d, int *newWatch); static void resetDeleteWatch(QObjectPrivate *d, int *oldWatch, int deleteWatch); - - int *deleteWatch; - QGuard<QObject> *objectGuards; + static void clearGuards(QObject *); static QObjectPrivate *get(QObject *o) { return o->d_func(); } + +public: + QString objectName; + ExtraData *extraData; // extra data set by the user + QThreadData *threadData; // id of the thread that owns the object + + QObjectConnectionListVector *connectionLists; + + Connection *senders; // linked list of connections connected to this object + Sender *currentSender; // object currently activating the object + mutable quint32 connectedSignals[2]; // 64-bit, so doesn't cause padding on 64-bit platforms + +#ifdef QT3_SUPPORT + QList<QObject *> pendingChildInsertedEvents; +#else + // preserve binary compatibility with code compiled without Qt 3 support + // ### why? + QList<QObject *> unused; +#endif + + QList<QPointer<QObject> > eventFilters; + + // these objects are all used to indicate that a QObject was deleted + // plus QPointer, which keeps a separate list + QObjectDeletionNotification *deletionNotification; + QGuard<QObject> *objectGuards; + int *deleteWatch; }; inline void q_guard_addGuard(QGuard<QObject> *g) diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 765b26f..075f9c3 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -1375,10 +1375,9 @@ QWidget::~QWidget() // set all QPointers for this object to zero QObjectPrivate::clearGuards(this); - if(d->declarativeData) { - QDeclarativeData *dd = d->declarativeData; - d->declarativeData = 0; - dd->destroyed(this); + if (d->deletionNotification) { + d->deletionNotification->destroyed(this); + d->deletionNotification = 0; // don't activate again in ~QObject } if (!d->children.isEmpty()) |