26 #include <QApplication>
28 #include <QStyleOptionButton>
38 drawCheckBox(
bool value)
40 QStyleOptionButton opt;
41 opt.state |=
value ? QStyle::State_On : QStyle::State_Off;
42 opt.state |= QStyle::State_Enabled;
43 const QStyle* style = QApplication::style();
47 const int indicatorWidth = style->pixelMetric(QStyle::PM_IndicatorWidth, &opt);
48 const int indicatorHeight = style->pixelMetric(QStyle::PM_IndicatorHeight, &opt);
49 const int listViewIconSize = indicatorWidth;
50 const int pixmapWidth = indicatorWidth;
51 const int pixmapHeight = qMax(indicatorHeight, listViewIconSize);
53 opt.rect = QRect(0, 0, indicatorWidth, indicatorHeight);
54 QPixmap pixmap = QPixmap(pixmapWidth, pixmapHeight);
58 const int xoff = (pixmapWidth > indicatorWidth) ? (pixmapWidth - indicatorWidth) / 2 : 0;
60 (pixmapHeight > indicatorHeight) ? (pixmapHeight - indicatorHeight) / 2 : 0;
61 QPainter painter(&pixmap);
62 painter.translate(xoff, yoff);
63 style->drawPrimitive(QStyle::PE_IndicatorCheckBox, &opt, &painter);
70 checkedIcon(drawCheckBox(true)),
71 uncheckedIcon(drawCheckBox(false))
78 return qMetaTypeId<OptionalPropertyType>();
104 if (dataMap.contains(property))
106 return dataMap[property][
"value"].variant;
117 attr << QLatin1String(
"enabled");
128 if (attribute == QLatin1String(
"enabled"))
140 if (dataMap.contains(property))
142 return dataMap[property][attribute].variant;
150 if (dataMap.contains(property))
152 return dataMap[property][
"value"].variant.toString();
160 if (dataMap.contains(property))
162 auto it = dataMap.constFind(property);
164 if (it == dataMap.constEnd())
169 return (it.value()[
"enabled"].variant.isValid() && it.value()[
"enabled"].variant.toBool())
179 if (dataMap.contains(property))
185 QString
str = val.value<QString>();
186 Data d = dataMap[property][
"value"];
187 if (d.variant.isValid() && d.variant.toString() ==
str)
192 dataMap[property][
"value"] = d;
202 const QString& attribute,
205 if (dataMap.contains(property))
208 if (attribute == QLatin1String(
"enabled"))
214 bool enabled = val.value<
bool>();
215 Data d = dataMap[property][
"enabled"];
216 if (d.variant.isValid() && d.variant.toBool() ==
enabled)
220 dataMap[property][
"enabled"].variant = val;
226 dataMap[property][attribute].variant = val;
250 dataMap.remove(property);