diff --git a/D/build.sh b/D/build.sh index 12ad8ac..ff01183 100755 --- a/D/build.sh +++ b/D/build.sh @@ -1 +1 @@ -dmd -debug dotherside.d dslot.d dsignal.d dobject.d typemapper.d dothersideinterface.di test.d -L-lDOtherSide -L-L../build/DOtherSide +dmd -debug dotherside.d dslot.d dsignal.d dobject.d dothersideinterface.di test.d -L-lDOtherSide -L-L../build/DOtherSide diff --git a/D/test.d b/D/test.d index eb429c9..209e90e 100644 --- a/D/test.d +++ b/D/test.d @@ -2,8 +2,8 @@ import std.stdio; import std.string; import std.traits; import std.conv; -import core.memory; import std.functional; +import core.memory; import dotherside; import dobject; import dslot; @@ -13,9 +13,9 @@ class MyObject : DObject { this() { - nameChanged = registerSignal!(string)("nameChanged"); foo = registerSlot("foo", &_foo); bar = registerSlot("bar", &_bar); + nameChanged = registerSignal!(string)("nameChanged"); tor = registerSlot("tor", &_tor); } diff --git a/D/typemapper.d b/D/typemapper.d deleted file mode 100644 index 3911a0d..0000000 --- a/D/typemapper.d +++ /dev/null @@ -1,10 +0,0 @@ -import std.stdio; -import std.container; -import std.conv; -import std.typecons; -import std.traits; - -public static class TypeMapper -{ - -} \ No newline at end of file diff --git a/DOtherSide/DynamicQObject/DynamicQObject.cpp b/DOtherSide/DynamicQObject/DynamicQObject.cpp index 679e06f..a4e7c93 100644 --- a/DOtherSide/DynamicQObject/DynamicQObject.cpp +++ b/DOtherSide/DynamicQObject/DynamicQObject.cpp @@ -32,11 +32,34 @@ bool DynamicQObject::registerSlot(const QString& name, m_slotsByName.insertMulti(slot.name(), slot); m_slotsBySignature[slot.signature()] = slot; - QMetaObjectBuilder builder(m_metaObject.data()); - QMetaMethodBuilder methodBuilder = builder.addSlot(slot.signature()); + // Collect the current methods and signals + QList signalsList; + QList methodsList; + + for (int i = m_metaObject->methodOffset(); i < m_metaObject->methodCount(); ++i) + { + auto method = m_metaObject->method(i); + if (method.methodType() == QMetaMethod::Signal) + signalsList.append(method); + else + methodsList.append(method); + } + + QMetaObjectBuilder newMetaObjectBuilder; + newMetaObjectBuilder.setFlags(QMetaObjectBuilder::DynamicMetaObject); + newMetaObjectBuilder.setClassName("DynamicObject"); + newMetaObjectBuilder.setSuperClass(&QObject::staticMetaObject); + + foreach(auto method, signalsList) + newMetaObjectBuilder.addMethod(method); + + foreach (auto method, methodsList) + newMetaObjectBuilder.addMethod(method); + + QMetaMethodBuilder methodBuilder = newMetaObjectBuilder.addSlot(slot.signature()); methodBuilder.setReturnType(QMetaType::typeName(returnType)); methodBuilder.setAttributes(QMetaMethod::Scriptable); - m_metaObject.reset(builder.toMetaObject()); + m_metaObject.reset(newMetaObjectBuilder.toMetaObject()); slotIndex = m_metaObject->indexOfSlot(QMetaObject::normalizedSignature(slot.signature())); @@ -53,11 +76,35 @@ bool DynamicQObject::registerSignal(const QString& name, const QList signalsList; + QList methodsList; + + for (int i = m_metaObject->methodOffset(); i < m_metaObject->methodCount(); ++i) + { + auto method = m_metaObject->method(i); + if (method.methodType() == QMetaMethod::Signal) + signalsList.append(method); + else + methodsList.append(method); + } + + QMetaObjectBuilder newMetaObjectBuilder; + newMetaObjectBuilder.setFlags(QMetaObjectBuilder::DynamicMetaObject); + newMetaObjectBuilder.setClassName("DynamicObject"); + newMetaObjectBuilder.setSuperClass(&QObject::staticMetaObject); + + foreach(auto method, signalsList) + newMetaObjectBuilder.addMethod(method); + + QMetaMethodBuilder methodBuilder = newMetaObjectBuilder.addSignal(signal.signature()); methodBuilder.setReturnType(QMetaType::typeName(QMetaType::Void)); methodBuilder.setAccess(QMetaMethod::Public); - m_metaObject.reset(builder.toMetaObject()); + + foreach (auto method, methodsList) + newMetaObjectBuilder.addMethod(method); + + m_metaObject.reset(newMetaObjectBuilder.toMetaObject()); signalIndex = m_metaObject->indexOfSignal(QMetaObject::normalizedSignature(signal.signature()));