1 module dqml.qvariant;
2 
3 import dqml.global;
4 import dqml.dothersideinterface;
5 import dqml.qobject;
6 import std.string;
7 
8 class QVariant
9 {
10     public this()
11     {
12         this.vptr = dos_qvariant_create();
13     }
14 
15     public this(int value)
16     {
17         this.vptr = dos_qvariant_create_int(value);
18     }
19 
20     public this(bool value)
21     {
22         this.vptr = dos_qvariant_create_bool(value);
23     }
24 
25     public this(string value)
26     {
27         this.vptr = dos_qvariant_create_string(value.toStringz());
28     }
29 
30     public this(float value)
31     {
32         this.vptr = dos_qvariant_create_float(value);
33     }
34 
35     public this(double value)
36     {
37         this.vptr = dos_qvariant_create_double(value);
38     }
39 
40     public this(QObject value)
41     {
42         this.vptr = dos_qvariant_create_qobject(value.voidPointer());
43     }
44 
45     public this(void* vptr, Ownership ownership)
46     {
47         this.vptr = ownership == Ownership.Take ? vptr : dos_qvariant_create_qvariant(vptr);
48     }
49 
50     ~this()
51     {
52         dos_qvariant_delete(this.vptr);
53     }
54 
55     public void* voidPointer()
56     {
57         return this.vptr;
58     }
59 
60     public void setValue(int value)
61     {
62         dos_qvariant_setInt(this.vptr, value);
63     }
64 
65     public void setValue(bool value)
66     {
67         dos_qvariant_setBool(this.vptr, value);
68     }
69 
70     public void setValue(string value)
71     {
72         dos_qvariant_setString(this.vptr, value.toStringz());
73     }
74 
75     public void setValue(QObject value)
76     {
77         dos_qvariant_setQObject(this.vptr, value.voidPointer());
78     }
79 
80     public void setValue(float value)
81     {
82         dos_qvariant_setFloat(this.vptr, value);
83     }
84 
85     public void setValue(double value)
86     {
87         dos_qvariant_setDouble(this.vptr, value);
88     }
89 
90     public void getValue(ref int value)
91     {
92         value = toInt();
93     }
94 
95     public void getValue(ref bool value)
96     {
97         value = toBool();
98     }
99 
100     public void getValue(ref string value)
101     {
102         value = toString();
103     }
104 
105     public void getValue(ref float value)
106     {
107         value = toFloat();
108     }
109 
110     public void getValue(ref double value)
111     {
112         value = toDouble();
113     }
114 
115     public bool isNull()
116     {
117         return dos_qvariant_isnull(this.vptr);
118     }
119 
120     public bool toBool()
121     {
122         return dos_qvariant_toBool(this.vptr);
123     }
124 
125     public int toInt()
126     {
127         return dos_qvariant_toInt(this.vptr);
128     }
129 
130     public float toFloat()
131     {
132         return dos_qvariant_toFloat(this.vptr);
133     }
134 
135     public double toDouble()
136     {
137         return dos_qvariant_toDouble(this.vptr);
138     }
139 
140     public override string toString()
141     {
142         char* array = dos_qvariant_toString(this.vptr);
143         string result = fromStringz(array).dup;
144         dos_chararray_delete(array);
145         return result;
146     }
147 
148     private void* vptr = null;
149 }