From 81e2b3d6b3f33d187fb961e259395462a7e219d2 Mon Sep 17 00:00:00 2001 From: Filippo Cucchetto Date: Fri, 8 May 2015 23:06:10 +0200 Subject: [PATCH] [DQml] Little refactoring --- D/DQml/qobject.d | 4 +++ D/Examples/SlotsAndProperties/contact.d | 40 +++++++++++-------------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/D/DQml/qobject.d b/D/DQml/qobject.d index 22343f0..cbcaed5 100644 --- a/D/DQml/qobject.d +++ b/D/DQml/qobject.d @@ -21,6 +21,7 @@ public class QObject this.disableDosCalls = disableDosCalls; if (!this.disableDosCalls) dos_qobject_create(this.vptr, cast(void*)this, &staticSlotCallback); + qobjectInit(); } ~this() @@ -36,6 +37,9 @@ public class QObject { return this.vptr; } + + protected void qobjectInit() + {} protected void onSlotCalled(QVariant slotName, QVariant[] parameters) { diff --git a/D/Examples/SlotsAndProperties/contact.d b/D/Examples/SlotsAndProperties/contact.d index dd524b4..1189f1d 100644 --- a/D/Examples/SlotsAndProperties/contact.d +++ b/D/Examples/SlotsAndProperties/contact.d @@ -4,7 +4,8 @@ import std.algorithm; import std.string; import std.stdio; -struct QtProperty { +struct QtProperty +{ public string type; public string name; public string read; @@ -23,6 +24,7 @@ struct QtProperty { struct QtSlot {}; struct QtSignal {}; + string GenerateVariantConversionCall(string typeName) { switch (typeName) @@ -66,16 +68,15 @@ string GenerateCaseBlock(FunctionInfo info) return result; } -string GenerateOnSlotCalled(T)() +string GenerateOnSlotCalled(QtInfo info) { string result = "protected override void onSlotCalled(QVariant slotName, QVariant[] arguments)\n"; result ~= "{\n"; result ~= "switch(slotName.toString())\n"; result ~= "{\n"; - auto info = IterateUDA!(T)(); foreach (slot; info.slots) result ~= GenerateCaseBlock(slot); - result ~= "default: break;\n"; + result ~= "default: super.onSlotCalled(slotName, arguments);\n"; result ~= "}\n"; // result ~= "}"; return result; @@ -98,17 +99,11 @@ string GenerateSignalCall(FunctionInfo info) return result; } -string GenerateQtSignals(T)() +string GenerateQtSignals(QtInfo info) { string result = ""; - - auto info = IterateUDA!(T)(); - foreach (signal; info.signals) - { result ~= GenerateSignalCall(signal) ~ "\n"; - } - return result; } @@ -130,8 +125,8 @@ string GenerateMetaType(string typeName) string GenerateMetaTypesListForSlot(FunctionInfo info) { string result = GenerateMetaType(info.returnType); - foreach (typeName; info.parameterTypes) - result ~= format(", %s", GenerateMetaType(typeName)); + result ~= ", "; + result ~= GenerateMetaTypesListForSignal(info); return result; } @@ -147,13 +142,11 @@ string GenerateMetaTypesListForSignal(FunctionInfo info) return result; } -string GenerateQObjectInit(T)() +string GenerateQObjectInit(QtInfo info) { string result = ""; - result ~= "protected void qobjectInit()\n"; + result ~= "protected override void qobjectInit()\n"; result ~= "{\n"; - - auto info = IterateUDA!(T)(); foreach (slot; info.slots) { @@ -172,6 +165,8 @@ string GenerateQObjectInit(T)() result ~= format("registerProperty(\"%s\", %s, \"%s\", \"%s\", \"%s\");\n", property.name, GenerateMetaType(property.type), property.read, property.write, property.notify); } + result ~= "super.qobjectInit();\n"; + result ~= "}"; return result; } @@ -179,9 +174,10 @@ string GenerateQObjectInit(T)() string Q_OBJECT(T)() { string result = ""; - result ~= GenerateOnSlotCalled!(Contact) ~ "\n"; - result ~= GenerateQObjectInit!(Contact) ~ "\n"; - result ~= GenerateQtSignals!(Contact) ~ "\n"; + auto info = IterateUDA!(T); + result ~= GenerateOnSlotCalled(info) ~ "\n"; + result ~= GenerateQObjectInit(info) ~ "\n"; + result ~= GenerateQtSignals(info) ~ "\n"; return result; } @@ -254,9 +250,7 @@ class Contact : QObject mixin(Q_OBJECT!(Contact)); this() - { - qobjectInit(); - } + {} ~this() {}