diff qt/qtd/MetaMarshall.d @ 302:55ee4603365d signals

string arguments for signals
author eldar_ins@eldar-laptop
date Sat, 12 Dec 2009 03:22:54 +0500
parents 8627891e4556
children 98b211f3ee34
line wrap: on
line diff
--- a/qt/qtd/MetaMarshall.d	Tue Dec 08 21:13:24 2009 +0000
+++ b/qt/qtd/MetaMarshall.d	Sat Dec 12 03:22:54 2009 +0500
@@ -2,6 +2,34 @@
 
 import std.traits;
 
+// shouldn't be here
+
+string __toString(long v)
+{
+    if (v == 0)
+        return "0";
+
+    string ret;
+
+    bool neg;
+    if (v < 0)
+    {
+        neg = true;
+        v = -v;
+    }
+
+    while (v != 0)
+    {
+        ret = cast(char)(v % 10 + '0') ~ ret;
+        v = cast(long)(v / 10);
+    }
+
+    if (neg)
+        ret = "-" ~ ret;
+
+    return ret;
+}
+
 template isQObjectType(T) // is a QObject type that belongs to the library
 {
     enum isQObjectType = is(T.__isQObjectType);
@@ -19,7 +47,12 @@
 
 template isNativeType(T) // type that doesn't require conversion i.e. is the same in C++ and D
 {
-    enum isNativeType = isNumeric!T || is(T == bool);
+    enum isNativeType = isNumeric!T || is(T == bool) || is(T == struct);
+}
+
+template isStringType(T) // string type
+{
+    enum isStringType = is(T == string);
 }
 
 // converts an argumnent from C++ to D in qt_metacall
@@ -29,6 +62,8 @@
         return T.stringof ~ ".__getObject(*cast(void**)(" ~ ptr ~ "))";
     else static if (isNativeType!T)
         return "*(cast(" ~ T.stringof ~ "*)" ~ ptr ~ ")";
+    else static if (isStringType!T)
+        return "QStringUtil.toNativeString(" ~ ptr ~ ")";
     else
         return "*(cast(" ~ T.stringof ~ "*)" ~ ptr ~ ")";
         //res = T.stringof;
@@ -39,8 +74,10 @@
 {
     static if (isQObjectType!T)
         return T.stringof ~ "*";
+    else static if (isStringType!T)
+        return "QString";
     else static if (isNativeType!T)
-        return T.stringof;
+        return Unqual!T.stringof;
     else
         return T.stringof;
 }
@@ -50,8 +87,19 @@
 {
     static if (isQObjectType!T)
         return arg ~ ".__nativeId";
+    else static if (isStringType!T)
+        return "_qt" ~ arg;
     else static if (isNativeType!T)
         return arg;
     else
         return arg;
 }
+
+string prepareSignalArguments(Args...)()
+{
+    string res;
+    foreach(i, _; Args)
+        static if (isStringType!(Args[i]))
+            res ~= "auto _qt_t" ~ __toString(i) ~ " = QString(_t" ~ __toString(i) ~ ");\n";
+    return res;
+}