1 // QT_MODULES: gui
2 module testgui1;
3 
4 import qt.config;
5 import qt.helpers;
6 
7 unittest
8 {
9     import qt.core.metatype;
10     import qt.core.namespace;
11     import qt.core.string;
12     import qt.core.variant;
13     import qt.gui.brush;
14     import qt.gui.color;
15     import qt.gui.standarditemmodel;
16 
17     QStandardItem item = new QStandardItem;
18     QString tmp = QString("test");
19     item.setText(tmp);
20     QString text = item.text();
21     assert(text == "test");
22     assert(qMetaTypeId!(QString)() == QVariant.Type.String);
23     assert(item.data(/+ Qt:: +/qt.core.namespace.ItemDataRole.DisplayRole).userType() == qMetaTypeId!(QString)());
24     QVariant variant = QVariant.fromValue(text);
25     item.setData(variant, /+ Qt:: +/qt.core.namespace.ItemDataRole.DisplayRole);
26     text = item.text();
27     assert(text == "test");
28 
29     auto tmp2 = QColor(/+ Qt:: +/qt.core.namespace.GlobalColor.red); QBrush brush = QBrush(tmp2);
30     item.setBackground(brush);
31     brush = item.background();
32     assert(brush.color() == QColor(/+ Qt:: +/qt.core.namespace.GlobalColor.red));
33 
34     QColor color2 = QColor.fromRgb(101, 102, 103, 104);
35     assert(color2.red() == 101);
36     assert(color2.green() == 102);
37     assert(color2.blue() == 103);
38     assert(color2.alpha() == 104);
39 
40     QBrush brush2 = QBrush(color2);
41     item.setBackground(brush2);
42     brush2 = item.background();
43     assert(brush2.color() == color2);
44 }
45 
46 unittest
47 {
48     import qt.core.list;
49     import qt.core.variant;
50     import qt.gui.brush;
51     import qt.gui.color;
52 
53     QBrushData* data;
54     {
55         QBrush b = QBrush(QColor(1, 2, 3));
56         data = *cast(QBrushData**)&b;
57         assert(data.ref_.loadRelaxed() == 1);
58         data.ref_.ref_(); // Add reference, so it is not freed and we can check the count at the end.
59         assert(data.ref_.loadRelaxed() == 2);
60         QBrush b2 = b;
61         assert(data.ref_.loadRelaxed() == 3);
62     }
63     assert(data.ref_.loadRelaxed() == 1); // Only our extra reference remains.
64     {
65         QBrush b = QBrush(QColor(1, 2, 3));
66         data = *cast(QBrushData**)&b;
67         assert(data.ref_.loadRelaxed() == 1);
68         data.ref_.ref_(); // Add reference, so it is not freed and we can check the count at the end.
69         assert(data.ref_.loadRelaxed() == 2);
70         QVariant v = QVariant.fromValue(b);
71         assert(data.ref_.loadRelaxed() == 3);
72         QVariant v2 = v;
73         assert(data.ref_.loadRelaxed() == 4);
74     }
75     assert(data.ref_.loadRelaxed() == 1); // Only our extra reference remains.
76     {
77         QBrush b = QBrush(QColor(1, 2, 3));
78         data = *cast(QBrushData**)&b;
79         assert(data.ref_.loadRelaxed() == 1);
80         data.ref_.ref_(); // Add reference, so it is not freed and we can check the count at the end.
81         assert(data.ref_.loadRelaxed() == 2);
82         QList!(QBrush) l = QList!(QBrush).create();
83         l.append(b);
84         assert(data.ref_.loadRelaxed() == 3);
85     }
86     assert(data.ref_.loadRelaxed() == 1); // Only our extra reference remains.
87 }