Mercurial > projects > qtd
comparison d2/qt/core/QVariant.d @ 394:92be7d54716e
Adapted QVariant.fromValue to D2 so that it at least compiles.
I am not sure if the code is really correct, though.
author | David Nadlinger <code@klickverbot.at> |
---|---|
date | Sat, 28 Aug 2010 03:15:31 +0200 |
parents | a032df77b6ab |
children |
comparison
equal
deleted
inserted
replaced
393:1049b01aebd2 | 394:92be7d54716e |
---|---|
23 private import qt.core.QLineF; | 23 private import qt.core.QLineF; |
24 private import qt.core.QRect; | 24 private import qt.core.QRect; |
25 private import qt.core.QLocale; | 25 private import qt.core.QLocale; |
26 | 26 |
27 import std.string; | 27 import std.string; |
28 | 28 import std.traits : isDynamicArray, isStaticArray; |
29 import std.range : ElementType; | |
29 | 30 |
30 public class QVariant : QtdObject | 31 public class QVariant : QtdObject |
31 { | 32 { |
32 enum Type { | 33 enum Type { |
33 Invalid = 0, | 34 Invalid = 0, |
88 LastType = 0xffffffff // need this so that gcc >= 3.4 allocates 32 bits for Type | 89 LastType = 0xffffffff // need this so that gcc >= 3.4 allocates 32 bits for Type |
89 } | 90 } |
90 | 91 |
91 // Functions | 92 // Functions |
92 | 93 |
93 private int getMetaId(T)(string name) | 94 static private int getMetaId(T)(string name) |
94 { | 95 { |
95 static shared int sharedId; | 96 static shared int sharedId; |
96 static int id; | 97 static int id; |
97 if (id == 0) | 98 if (id == 0) |
98 { | 99 { |
99 synchronized(qtdMoLock) | 100 synchronized |
100 { | 101 { |
101 if (sharedId == 0) | 102 if (sharedId == 0) |
102 sharedId = qRegisterMetaType!T(name); | 103 sharedId = qRegisterMetaType!T(name); |
103 } | 104 } |
104 id = sharedId; | 105 id = sharedId; |
113 { | 114 { |
114 string name = obj.classinfo.name; | 115 string name = obj.classinfo.name; |
115 // TODO: Still hacky. No need to pass name to id getter. | 116 // TODO: Still hacky. No need to pass name to id getter. |
116 var = new QVariant(getMetaId!T(name), cast(void*)(obj)); | 117 var = new QVariant(getMetaId!T(name), cast(void*)(obj)); |
117 } | 118 } |
118 else static if (isDynamicArrayType!(T) || isStaticArrayType!(T) ) | 119 else static if (isDynamicArray!(T) || isStaticArray!(T) ) |
119 { | 120 { |
120 string name = typeid(ElementTypeOfArray!(T)).toString ~ "[]"; | 121 string name = typeid(ElementType!(T)).toString ~ "[]"; |
121 auto darray = new DArrayToC; | 122 auto darray = new DArrayToC; |
122 darray.array = obj.dup; | 123 darray.array = obj.dup; |
123 var = new QVariant(getMetaId!T(name), cast(void*)(darray)); | 124 var = new QVariant(getMetaId!T(name), cast(void*)(darray)); |
124 } | 125 } |
125 else | 126 else |