Mercurial > projects > qtd
diff include/QObjectEntity.h @ 248:7664de4a55e5
Fixed #23.
QtD_QObjectEntity is not created dynamically for shell classes any more.
Class initialization is now performed by static constructors.
When wrapping QObjects returned from functions, their run-time types are now taken into account.
QObjects are allocated on GC heap, a doubly-linked list is used to prevent them from been collected (arguably a better solution than allocating on C heap and adding GC ranges)
Minor changes (including unnecessary).
author | maxter |
---|---|
date | Thu, 20 Aug 2009 14:47:17 +0000 |
parents | e78566595089 |
children | 37eed70de029 |
line wrap: on
line diff
--- a/include/QObjectEntity.h Fri Jul 31 11:05:22 2009 +0000 +++ b/include/QObjectEntity.h Thu Aug 20 14:47:17 2009 +0000 @@ -1,16 +1,37 @@ #ifndef QQOBJECTENTITY_H #define QQOBJECTENTITY_H -#include <cstdlib> +#include "qtd_core.h" +#include <qobject.h> +#include <iostream> + +QTD_EXPORT(void, qtd_delete_d_qobject, (void* dPtr)) -class Qtd_QObjectEntity +#ifdef CPP_SHARED +#define qtd_delete_d_qobject qtd_get_qtd_delete_d_qobject() +#endif + +//TODO: user data ID must be registered with QObject::registerUserData; +#define userDataId 0 + +class QtD_QObjectEntity : public QtD_Entity, public QObjectUserData { public: - Qtd_QObjectEntity(void *d_ptr) { _d_ptr = d_ptr; } - void *d_entity() const { return _d_ptr; } + + QtD_QObjectEntity(QObject *qObject, void *dId) : QtD_Entity(dId) + { + qObject->setUserData(userDataId, this); + } -private: - void *_d_ptr; + virtual ~QtD_QObjectEntity() + { + qtd_delete_d_qobject(dId); + } + + inline static QtD_QObjectEntity* getQObjectEntity(const QObject *qObject) + { + return static_cast<QtD_QObjectEntity*>(qObject->userData(userDataId)); + } }; #endif // QQOBJECTENTITY_H