27 #include <QStyleOptionButton>
28 #include <QApplication>
36 static QIcon drawCheckBox(
bool value)
38 QStyleOptionButton opt;
39 opt.state |=
value ? QStyle::State_On : QStyle::State_Off;
40 opt.state |= QStyle::State_Enabled;
41 const QStyle* style = QApplication::style();
45 const int indicatorWidth = style->pixelMetric(QStyle::PM_IndicatorWidth, &opt);
46 const int indicatorHeight = style->pixelMetric(QStyle::PM_IndicatorHeight, &opt);
47 const int listViewIconSize = indicatorWidth;
48 const int pixmapWidth = indicatorWidth;
49 const int pixmapHeight = qMax(indicatorHeight, listViewIconSize);
51 opt.rect = QRect(0, 0, indicatorWidth, indicatorHeight);
52 QPixmap pixmap = QPixmap(pixmapWidth, pixmapHeight);
56 const int xoff = (pixmapWidth > indicatorWidth) ? (pixmapWidth - indicatorWidth) / 2 : 0;
57 const int yoff = (pixmapHeight > indicatorHeight) ? (pixmapHeight - indicatorHeight) / 2 : 0;
58 QPainter painter(&pixmap);
59 painter.translate(xoff, yoff);
60 style->drawPrimitive(QStyle::PE_IndicatorCheckBox, &opt, &painter);
74 return qMetaTypeId<OptionalPropertyType>();
97 if (dataMap.contains(property))
99 return dataMap[property][
"value"].variant;
109 attr << QLatin1String(
"enabled");
119 if (attribute == QLatin1String(
"enabled"))
130 if (dataMap.contains(property))
132 return dataMap[property][attribute].variant;
139 if (dataMap.contains(property))
141 return dataMap[property][
"value"].variant.toString();
148 if (dataMap.contains(property))
150 auto it = dataMap.constFind(property);
152 if (it == dataMap.constEnd())
157 return (it.value()[
"enabled"].variant.isValid() && it.value()[
"enabled"].variant.toBool()) ? checkedIcon : uncheckedIcon;
164 if (dataMap.contains(property))
170 QString
str = val.value<QString>();
171 Data d = dataMap[property][
"value"];
172 if (d.variant.isValid() && d.variant.toString() ==
str)
177 dataMap[property][
"value"] = d;
186 const QString& attribute,
const QVariant& val)
188 if (dataMap.contains(property))
191 if (attribute == QLatin1String(
"enabled"))
197 bool enabled = val.value<
bool>();
198 Data d = dataMap[property][
"enabled"];
199 if (d.variant.isValid() && d.variant.toBool() ==
enabled)
203 dataMap[property][
"enabled"].variant = val;
209 dataMap[property][attribute].variant = val;
231 dataMap.remove(property);