comparison qt/core/QVariant.d @ 87:f46133029d8b

qtd: Implement QMetaType. QVariant may save D types now.
author SokoL_SD
date Tue, 26 May 2009 10:59:07 +0000
parents fd6eb3a1759d
children cbdfc92eac7f
comparison
equal deleted inserted replaced
86:bee1446909c5 87:f46133029d8b
1 module qt.core.QVariant; 1 module qt.core.QVariant;
2 2
3 public import qt.QGlobal; 3 public import qt.QGlobal;
4 private import qt.QtDObject; 4 private import qt.QtDObject;
5 private import qt.core.QMetaType;
5 6
6 // automatic imports------------- 7 // automatic imports-------------
7 private import qt.core.QSizeF; 8 private import qt.core.QSizeF;
8 private import qt.core.QPoint; 9 private import qt.core.QPoint;
9 private import qt.core.QRectF; 10 private import qt.core.QRectF;
26 version (Tango) 27 version (Tango)
27 { 28 {
28 import tango.core.Array; 29 import tango.core.Array;
29 import tango.stdc.stringz; 30 import tango.stdc.stringz;
30 import tango.text.convert.Utf; 31 import tango.text.convert.Utf;
32 import tango.core.Traits;
31 } 33 }
32 34
33 35
34 public class QVariant : QtDObject 36 public class QVariant : QtDObject
35 { 37 {
89 91
90 UserType = 127, 92 UserType = 127,
91 93
92 LastType = 0xffffffff // need this so that gcc >= 3.4 allocates 32 bits for Type 94 LastType = 0xffffffff // need this so that gcc >= 3.4 allocates 32 bits for Type
93 } 95 }
94 96
95 // Functions 97 // Functions
98
99 static public QVariant fromValue(T)(T obj)
100 {
101 QVariant var;
102 static if (is(T == class) || is(T == interface))
103 {
104 int i = qtd_MetatypeId(toStringz(obj.classinfo.name));
105 var = new QVariant(i, cast(void*)(obj));
106 }
107 else static if (isDynamicArrayType!(T) || isStaticArrayType!(T) )
108 {
109 int i = qtd_MetatypeId(toStringz(typeid(ElementTypeOfArray!(T)).toString ~ "[]"));
110 auto darray = new DArrayToC;
111 darray.array = obj.dup;
112 var = new QVariant(i, cast(void*)(darray));
113 }
114 else
115 {
116 int i = qtd_MetatypeId(toStringz(typeid(T).toString));
117 auto data = new T;
118 *data = obj;
119 var = new QVariant(i, cast(void*)(data));
120 }
121 return var;
122 }
123
124 static public QVariant opCall(T)(T obj)
125 {
126 return fromValue(obj);
127 }
96 128
97 public this() { 129 public this() {
98 void* __qt_return_value = qtd_QVariant_QVariant(); 130 void* __qt_return_value = qtd_QVariant_QVariant();
99 super(__qt_return_value); 131 super(__qt_return_value);
100 } 132 }
265 public this(ulong ull) { 297 public this(ulong ull) {
266 void* __qt_return_value = qtd_QVariant_QVariant_ulong(ull); 298 void* __qt_return_value = qtd_QVariant_QVariant_ulong(ull);
267 super(__qt_return_value); 299 super(__qt_return_value);
268 } 300 }
269 301
270
271 public final bool canConvert(Type type) { 302 public final bool canConvert(Type type) {
272 return qtd_QVariant_canConvert(nativeId, type); 303 return qtd_QVariant_canConvert(nativeId, type);
304 }
305
306 public final Type value(Type)() {
307 static if ( is(Type == QBitArray) )
308 return toBitArra;
309 else static if ( is(Type == bool) )
310 return toBool;
311 else static if ( is(Type == QByteArray) )
312 return toByteArray;
313 else static if ( is(Type == QDate) )
314 return toDate;
315 else static if ( is(Type == QDateTime) )
316 return toDateTime;
317 else static if ( is(Type == double) )
318 return toDouble;
319 else static if ( is(Type == int) )
320 return toInt;
321 else static if ( is(Type == QLine) )
322 return toLine;
323 else static if ( is(Type == QLineF) )
324 return toLineF;
325 else static if ( is(Type == QLocale) )
326 return toLocale;
327 else static if ( is(Type == long) )
328 return toLongLong;
329 else static if ( is(Type == QPoint) )
330 return toPoint;
331 else static if ( is(Type == QPointF) )
332 return toPointF;
333 else static if ( is(Type == QRect) )
334 return toRect;
335 else static if ( is(Type == QRectF) )
336 return toRectF;
337 else static if ( is(Type == QRegExp) )
338 return toRegExp;
339 else static if ( is(Type == QSize) )
340 return toSize;
341 else static if ( is(Type == QSizeF) )
342 return toSizeF;
343 else static if ( is(Type == string) )
344 return toString;
345 else static if ( is(Type == QTime) )
346 return toTime;
347 else static if ( is(Type == uint) )
348 return toUInt;
349 else static if ( is(Type == ulong) )
350 return toULongLong;
351 else static if ( is(Type == QUrl) )
352 return toUrl;
353 else static if( is( Type == class ) || is( Type == interface ) )
354 {
355 Object object = cast(Object)qtd_QVariant_data(nativeId);
356 if(object)
357 return cast(Type)(object);
358 return null;
359 }
360 else static if (isDynamicArrayType!(Type) || isStaticArrayType!(Type) )
361 {
362 auto array = cast(DArrayToC*)qtd_QVariant_data(nativeId);
363 return cast(Type)(array.array);
364 }
365 else
366 {
367 return *cast(Type*)qtd_QVariant_data(nativeId);
368 }
273 } 369 }
274 370
275 public final void clear() { 371 public final void clear() {
276 qtd_QVariant_clear(nativeId); 372 qtd_QVariant_clear(nativeId);
277 } 373 }
528 private extern(C) ulong qtd_QVariant_toULongLong_nativepointerbool(void* __this_nativeId, 624 private extern(C) ulong qtd_QVariant_toULongLong_nativepointerbool(void* __this_nativeId,
529 bool* ok0); 625 bool* ok0);
530 private extern(C) void* qtd_QVariant_toUrl(void* __this_nativeId); 626 private extern(C) void* qtd_QVariant_toUrl(void* __this_nativeId);
531 private extern(C) char* qtd_QVariant_typeName(void* __this_nativeId); 627 private extern(C) char* qtd_QVariant_typeName(void* __this_nativeId);
532 private extern(C) int qtd_QVariant_userType(void* __this_nativeId); 628 private extern(C) int qtd_QVariant_userType(void* __this_nativeId);
629 private extern(C) void *qtd_QVariant_data(void* __this_nativeId);
630
533 // Just the private functions for abstract functions implemeneted in superclasses 631 // Just the private functions for abstract functions implemeneted in superclasses
534 632
535
536
537 // Virtual Dispatch functions 633 // Virtual Dispatch functions