mirror of
https://github.com/status-im/dotherside.git
synced 2025-02-12 04:26:43 +00:00
[DQml] Little refactoring
This commit is contained in:
parent
b6965e8250
commit
81e2b3d6b3
@ -21,6 +21,7 @@ public class QObject
|
|||||||
this.disableDosCalls = disableDosCalls;
|
this.disableDosCalls = disableDosCalls;
|
||||||
if (!this.disableDosCalls)
|
if (!this.disableDosCalls)
|
||||||
dos_qobject_create(this.vptr, cast(void*)this, &staticSlotCallback);
|
dos_qobject_create(this.vptr, cast(void*)this, &staticSlotCallback);
|
||||||
|
qobjectInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
~this()
|
~this()
|
||||||
@ -37,6 +38,9 @@ public class QObject
|
|||||||
return this.vptr;
|
return this.vptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void qobjectInit()
|
||||||
|
{}
|
||||||
|
|
||||||
protected void onSlotCalled(QVariant slotName, QVariant[] parameters)
|
protected void onSlotCalled(QVariant slotName, QVariant[] parameters)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,8 @@ import std.algorithm;
|
|||||||
import std.string;
|
import std.string;
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
|
|
||||||
struct QtProperty {
|
struct QtProperty
|
||||||
|
{
|
||||||
public string type;
|
public string type;
|
||||||
public string name;
|
public string name;
|
||||||
public string read;
|
public string read;
|
||||||
@ -23,6 +24,7 @@ struct QtProperty {
|
|||||||
struct QtSlot {};
|
struct QtSlot {};
|
||||||
struct QtSignal {};
|
struct QtSignal {};
|
||||||
|
|
||||||
|
|
||||||
string GenerateVariantConversionCall(string typeName)
|
string GenerateVariantConversionCall(string typeName)
|
||||||
{
|
{
|
||||||
switch (typeName)
|
switch (typeName)
|
||||||
@ -66,16 +68,15 @@ string GenerateCaseBlock(FunctionInfo info)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
string GenerateOnSlotCalled(T)()
|
string GenerateOnSlotCalled(QtInfo info)
|
||||||
{
|
{
|
||||||
string result = "protected override void onSlotCalled(QVariant slotName, QVariant[] arguments)\n";
|
string result = "protected override void onSlotCalled(QVariant slotName, QVariant[] arguments)\n";
|
||||||
result ~= "{\n";
|
result ~= "{\n";
|
||||||
result ~= "switch(slotName.toString())\n";
|
result ~= "switch(slotName.toString())\n";
|
||||||
result ~= "{\n";
|
result ~= "{\n";
|
||||||
auto info = IterateUDA!(T)();
|
|
||||||
foreach (slot; info.slots)
|
foreach (slot; info.slots)
|
||||||
result ~= GenerateCaseBlock(slot);
|
result ~= GenerateCaseBlock(slot);
|
||||||
result ~= "default: break;\n";
|
result ~= "default: super.onSlotCalled(slotName, arguments);\n";
|
||||||
result ~= "}\n"; //
|
result ~= "}\n"; //
|
||||||
result ~= "}";
|
result ~= "}";
|
||||||
return result;
|
return result;
|
||||||
@ -98,17 +99,11 @@ string GenerateSignalCall(FunctionInfo info)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
string GenerateQtSignals(T)()
|
string GenerateQtSignals(QtInfo info)
|
||||||
{
|
{
|
||||||
string result = "";
|
string result = "";
|
||||||
|
|
||||||
auto info = IterateUDA!(T)();
|
|
||||||
|
|
||||||
foreach (signal; info.signals)
|
foreach (signal; info.signals)
|
||||||
{
|
|
||||||
result ~= GenerateSignalCall(signal) ~ "\n";
|
result ~= GenerateSignalCall(signal) ~ "\n";
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,8 +125,8 @@ string GenerateMetaType(string typeName)
|
|||||||
string GenerateMetaTypesListForSlot(FunctionInfo info)
|
string GenerateMetaTypesListForSlot(FunctionInfo info)
|
||||||
{
|
{
|
||||||
string result = GenerateMetaType(info.returnType);
|
string result = GenerateMetaType(info.returnType);
|
||||||
foreach (typeName; info.parameterTypes)
|
result ~= ", ";
|
||||||
result ~= format(", %s", GenerateMetaType(typeName));
|
result ~= GenerateMetaTypesListForSignal(info);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,14 +142,12 @@ string GenerateMetaTypesListForSignal(FunctionInfo info)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
string GenerateQObjectInit(T)()
|
string GenerateQObjectInit(QtInfo info)
|
||||||
{
|
{
|
||||||
string result = "";
|
string result = "";
|
||||||
result ~= "protected void qobjectInit()\n";
|
result ~= "protected override void qobjectInit()\n";
|
||||||
result ~= "{\n";
|
result ~= "{\n";
|
||||||
|
|
||||||
auto info = IterateUDA!(T)();
|
|
||||||
|
|
||||||
foreach (slot; info.slots)
|
foreach (slot; info.slots)
|
||||||
{
|
{
|
||||||
auto metaTypes = GenerateMetaTypesListForSlot(slot);
|
auto metaTypes = GenerateMetaTypesListForSlot(slot);
|
||||||
@ -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 ~= format("registerProperty(\"%s\", %s, \"%s\", \"%s\", \"%s\");\n", property.name, GenerateMetaType(property.type), property.read, property.write, property.notify);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result ~= "super.qobjectInit();\n";
|
||||||
|
|
||||||
result ~= "}";
|
result ~= "}";
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -179,9 +174,10 @@ string GenerateQObjectInit(T)()
|
|||||||
string Q_OBJECT(T)()
|
string Q_OBJECT(T)()
|
||||||
{
|
{
|
||||||
string result = "";
|
string result = "";
|
||||||
result ~= GenerateOnSlotCalled!(Contact) ~ "\n";
|
auto info = IterateUDA!(T);
|
||||||
result ~= GenerateQObjectInit!(Contact) ~ "\n";
|
result ~= GenerateOnSlotCalled(info) ~ "\n";
|
||||||
result ~= GenerateQtSignals!(Contact) ~ "\n";
|
result ~= GenerateQObjectInit(info) ~ "\n";
|
||||||
|
result ~= GenerateQtSignals(info) ~ "\n";
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,9 +250,7 @@ class Contact : QObject
|
|||||||
mixin(Q_OBJECT!(Contact));
|
mixin(Q_OBJECT!(Contact));
|
||||||
|
|
||||||
this()
|
this()
|
||||||
{
|
{}
|
||||||
qobjectInit();
|
|
||||||
}
|
|
||||||
|
|
||||||
~this() {}
|
~this() {}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user