26#include <QApplication>
28#include <QStyleOptionButton>
38drawCheckBox(
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);
55 pixmap.fill(Qt::transparent);
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>();
96 return QVariant::String;
104 if (dataMap.contains(property))
106 return dataMap[property][
"value"].variant;
117 attr << QLatin1String(
"enabled");
128 if (attribute == QLatin1String(
"enabled"))
130 return QVariant::Bool;
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))
181 if (val.type() != QVariant::String && !val.canConvert(QVariant::String))
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"))
210 if (val.type() != QVariant::Bool && !val.canConvert(QVariant::Bool))
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);
void initializeProperty(QtProperty *property) override
QVariant attributeValue(const QtProperty *property, const QString &attribute) const override
void setValue(QtProperty *property, const QVariant &val) override
int attributeType(int propertyType, const QString &attribute) const override
QVariant value(const QtProperty *property) const override
OptionalVariantManager(QObject *parent=0)
int valueType(int propertyType) const override
QIcon valueIcon(const QtProperty *property) const override
QStringList attributes(int propertyType) const override
void uninitializeProperty(QtProperty *property) override
void setAttribute(QtProperty *property, const QString &attribute, const QVariant &value) override
QString valueText(const QtProperty *property) const override
bool isPropertyTypeSupported(int propertyType) const override
static int optionalProprtyTypeId()
void propertyChanged(QtProperty *property)
void initializeProperty(QtProperty *property) override
virtual QVariant value(const QtProperty *property) const
QtVariantPropertyManager(QObject *parent=0)
virtual int attributeType(int propertyType, const QString &attribute) const
virtual QVariant attributeValue(const QtProperty *property, const QString &attribute) const
virtual void setValue(QtProperty *property, const QVariant &val)
QIcon valueIcon(const QtProperty *property) const override
void valueChanged(QtProperty *property, const QVariant &val)
void uninitializeProperty(QtProperty *property) override
virtual void setAttribute(QtProperty *property, const QString &attribute, const QVariant &value)
virtual bool isPropertyTypeSupported(int propertyType) const
virtual QStringList attributes(int propertyType) const
int propertyType(const QtProperty *property) const
QString valueText(const QtProperty *property) const override
int valueType(const QtProperty *property) const
void attributeChanged(QtProperty *property, const QString &attribute, const QVariant &val)