41 #include <QApplication>
66 void slotPropertyDestroyed(
QtProperty* property);
74 QMap<const QtProperty*, Data> propertyToData;
75 QMap<const QtProperty*, QtProperty*> xToProperty;
76 QMap<const QtProperty*, QtProperty*> yToProperty;
83 this, SLOT(slotValueChanged(
QtProperty*,
const QVariant&)));
85 this, SLOT(slotPropertyDestroyed(
QtProperty*)));
93 void VariantManager::slotValueChanged(
QtProperty* property,
const QVariant&
value)
95 if (xToProperty.contains(property))
97 QtProperty* pointProperty = xToProperty[property];
98 QVariant
v = this->
value(pointProperty);
99 QPointF p =
v.value<QPointF>();
100 p.setX(
value.value<
double>());
103 else if (yToProperty.contains(property))
105 QtProperty* pointProperty = yToProperty[property];
106 QVariant
v = this->
value(pointProperty);
107 QPointF p =
v.value<QPointF>();
108 p.setY(
value.value<
double>());
113 void VariantManager::slotPropertyDestroyed(
QtProperty* property)
115 if (xToProperty.contains(property))
117 QtProperty* pointProperty = xToProperty[property];
118 propertyToData[pointProperty].x = 0;
119 xToProperty.remove(property);
121 else if (yToProperty.contains(property))
123 QtProperty* pointProperty = yToProperty[property];
124 propertyToData[pointProperty].y = 0;
125 yToProperty.remove(property);
143 return QVariant::PointF;
151 if (propertyToData.contains(property))
153 return propertyToData[property].value;
161 if (propertyToData.contains(property))
163 QVariant
v = propertyToData[property].value;
164 QPointF p =
v.value<QPointF>();
165 return QString(tr(
"(%1, %2)").arg(QString::number(p.x()))
166 .arg(QString::number(p.y())));
174 if (propertyToData.contains(property))
176 if (val.type() != QVariant::PointF && !val.canConvert(QVariant::PointF))
181 QPointF p = val.value<QPointF>();
182 Data d = propertyToData[property];
187 d.x->setValue(p.x());
192 d.y->setValue(p.y());
195 propertyToData[property] = d;
210 d.value = QPointF(0, 0);
215 d.x->setPropertyName(tr(
"Position X"));
216 property->addSubProperty(d.x);
217 xToProperty[d.x] = property;
220 d.y->setPropertyName(tr(
"Position Y"));
221 property->addSubProperty(d.y);
222 yToProperty[d.y] = property;
224 propertyToData[property] = d;
232 if (propertyToData.contains(property))
234 Data d = propertyToData[property];
238 xToProperty.remove(d.x);
243 yToProperty.remove(d.y);
246 propertyToData.remove(property);
252 int main(
int argc,
char** argv)
254 QApplication app(argc, argv);
260 item->
setValue(QPointF(2.5, 13.13));
272 int ret = app.exec();
274 delete variantFactory;
275 delete variantManager;