41 #include <QApplication>
43 #include <QDoubleSpinBox>
73 QMap<const QtProperty*, Data> propertyToData;
87 if (!propertyToData.contains(property))
92 return propertyToData[property].prefix;
97 if (!propertyToData.contains(property))
102 return propertyToData[property].suffix;
107 if (!propertyToData.contains(property))
112 DecoratedDoublePropertyManager::Data
data = propertyToData[property];
120 propertyToData[property] =
data;
128 if (!propertyToData.contains(property))
133 DecoratedDoublePropertyManager::Data
data = propertyToData[property];
141 propertyToData[property] =
data;
151 if (!propertyToData.contains(property))
156 DecoratedDoublePropertyManager::Data
data = propertyToData[property];
157 text =
data.prefix + text +
data.suffix;
164 propertyToData[property] = DecoratedDoublePropertyManager::Data();
170 propertyToData.remove(property);
188 void slotPrefixChanged(
QtProperty* property,
const QString& prefix);
189 void slotSuffixChanged(
QtProperty* property,
const QString& prefix);
190 void slotEditorDestroyed(QObject*
object);
195 QMap<QtProperty*, QList<QDoubleSpinBox*> > createdEditors;
196 QMap<QDoubleSpinBox*, QtProperty*> editorToProperty;
213 connect(manager, SIGNAL(prefixChanged(
QtProperty*,
const QString&)),
this, SLOT(slotPrefixChanged(
QtProperty*,
const QString&)));
214 connect(manager, SIGNAL(suffixChanged(
QtProperty*,
const QString&)),
this, SLOT(slotSuffixChanged(
QtProperty*,
const QString&)));
228 QDoubleSpinBox* spinBox = qobject_cast<QDoubleSpinBox*>(w);
235 spinBox->setPrefix(manager->
prefix(property));
236 spinBox->setSuffix(manager->
suffix(property));
238 createdEditors[property].append(spinBox);
239 editorToProperty[spinBox] = property;
247 disconnect(manager, SIGNAL(prefixChanged(
QtProperty*,
const QString&)),
this, SLOT(slotPrefixChanged(
QtProperty*,
const QString&)));
248 disconnect(manager, SIGNAL(suffixChanged(
QtProperty*,
const QString&)),
this, SLOT(slotSuffixChanged(
QtProperty*,
const QString&)));
251 void DecoratedDoubleSpinBoxFactory::slotPrefixChanged(
QtProperty* property,
const QString& prefix)
253 if (!createdEditors.contains(property))
265 QList<QDoubleSpinBox*> editors = createdEditors[property];
266 QListIterator<QDoubleSpinBox*> itEditor(editors);
268 while (itEditor.hasNext())
270 QDoubleSpinBox* editor = itEditor.next();
271 editor->setPrefix(prefix);
275 void DecoratedDoubleSpinBoxFactory::slotSuffixChanged(
QtProperty* property,
const QString& prefix)
277 if (!createdEditors.contains(property))
289 QList<QDoubleSpinBox*> editors = createdEditors[property];
290 QListIterator<QDoubleSpinBox*> itEditor(editors);
292 while (itEditor.hasNext())
294 QDoubleSpinBox* editor = itEditor.next();
295 editor->setSuffix(prefix);
299 void DecoratedDoubleSpinBoxFactory::slotEditorDestroyed(QObject*
object)
301 QMap<QDoubleSpinBox*, QtProperty*>::ConstIterator itEditor =
302 editorToProperty.constBegin();
304 while (itEditor != editorToProperty.constEnd())
306 if (itEditor.key() ==
object)
308 QDoubleSpinBox* editor = itEditor.key();
310 editorToProperty.remove(editor);
311 createdEditors[property].removeAll(editor);
313 if (createdEditors[property].isEmpty())
315 createdEditors.remove(property);
326 int main(
int argc,
char** argv)
328 QApplication app(argc, argv);
332 undecoratedManager->
setValue(undecoratedProperty, 123.45);
336 decoratedManager->
setPrefix(decoratedProperty,
"speed: ");
337 decoratedManager->
setSuffix(decoratedProperty,
" km/h");
338 decoratedManager->
setValue(decoratedProperty, 123.45);
350 int ret = app.exec();
352 delete decoratedFactory;
353 delete decoratedManager;
354 delete undecoratedFactory;
355 delete undecoratedManager;