view include/QObjectEntity.h @ 282:256ab6cb8e85

Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
author eldar
date Fri, 16 Oct 2009 02:43:59 +0000
parents 34a37904ff77
children 18bd68f586c6
line wrap: on
line source

#ifndef QQOBJECTENTITY_H
#define QQOBJECTENTITY_H

#include "qtd_core.h"
#include <qobject.h>
#include <iostream>

QTD_EXPORT(void, qtd_delete_d_qobject, (void* dPtr))

#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(QObject *qObject, void *dId) : QtD_Entity(dId)
    {
        qObject->setUserData(userDataId, this);
    }

    virtual ~QtD_QObjectEntity()
    {        
        if (dId)
            destroyEntity();     
    }
    
    inline void destroyEntity(QObject *qObject = NULL)
    {
        Q_ASSERT(dId);
        qtd_delete_d_qobject(dId);
        if (qObject)
        {
            qObject->setUserData(userDataId, NULL);
            dId = NULL;
        }
    }

    inline static QtD_QObjectEntity* getQObjectEntity(const QObject *qObject)
    {
        return static_cast<QtD_QObjectEntity*>(qObject->userData(userDataId));
    }
};

#endif // QQOBJECTENTITY_H