From 5c6a88c638e7446576775dfcec1721ed19b0af15 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 11 Jan 2012 12:11:59 +0100 Subject: Qt Designer: Simplify property editor for translatable properties. - Introduce sub-propertymanager for translatable properties inheriting PropertySheetTranslatableData. - Use common enumeration values for sub-propertymanager functions to make it easier to chain them. Task-number: QTBUG-8926 Task-number: QTBUG-20440 Change-Id: I8e99aa01fdca7e474a0ec83b7209a28a2a689bf9 Sanity-Review: Qt Sanity Bot Reviewed-by: Friedemann Kleint --- .../propertyeditor/brushpropertymanager.cpp | 24 +- .../propertyeditor/brushpropertymanager.h | 5 +- .../propertyeditor/designerpropertymanager.cpp | 423 +++++++++------------ .../propertyeditor/designerpropertymanager.h | 51 ++- .../propertyeditor/fontpropertymanager.cpp | 10 +- .../propertyeditor/fontpropertymanager.h | 5 +- 6 files changed, 243 insertions(+), 275 deletions(-) diff --git a/src/designer/src/components/propertyeditor/brushpropertymanager.cpp b/src/designer/src/components/propertyeditor/brushpropertymanager.cpp index e28a066ff..e7eac4c83 100644 --- a/src/designer/src/components/propertyeditor/brushpropertymanager.cpp +++ b/src/designer/src/components/propertyeditor/brushpropertymanager.cpp @@ -41,7 +41,7 @@ #include "brushpropertymanager.h" #include "qtpropertymanager.h" -#include "qtvariantproperty.h" +#include "designerpropertymanager.h" #include "qtpropertybrowserutils_p.h" #include @@ -213,7 +213,7 @@ void BrushPropertyManager::slotPropertyDestroyed(QtProperty *property) } -BrushPropertyManager::ValueChangedResult BrushPropertyManager::valueChanged(QtVariantPropertyManager *vm, QtProperty *property, const QVariant &value) +int BrushPropertyManager::valueChanged(QtVariantPropertyManager *vm, QtProperty *property, const QVariant &value) { switch (value.type()) { case QVariant::Int: // Style subproperty? @@ -223,9 +223,9 @@ BrushPropertyManager::ValueChangedResult BrushPropertyManager::valueChanged(QtVa const int index = value.toInt(); newBrush.setStyle(brushStyleIndexToStyle(index)); if (newBrush == oldValue) - return Unchanged; + return DesignerPropertyManager::Unchanged; vm->variantProperty(brushProperty)->setValue(newBrush); - return Changed; + return DesignerPropertyManager::Changed; } break; case QVariant::Color: // Color subproperty? @@ -234,35 +234,35 @@ BrushPropertyManager::ValueChangedResult BrushPropertyManager::valueChanged(QtVa QBrush newBrush = oldValue; newBrush.setColor(qvariant_cast(value)); if (newBrush == oldValue) - return Unchanged; + return DesignerPropertyManager::Unchanged; vm->variantProperty(brushProperty)->setValue(newBrush); - return Changed; + return DesignerPropertyManager::Changed; } break; default: break; } - return NoMatch; + return DesignerPropertyManager::NoMatch; } -BrushPropertyManager::ValueChangedResult BrushPropertyManager::setValue(QtVariantPropertyManager *vm, QtProperty *property, const QVariant &value) +int BrushPropertyManager::setValue(QtVariantPropertyManager *vm, QtProperty *property, const QVariant &value) { if (value.type() != QVariant::Brush) - return NoMatch; + return DesignerPropertyManager::NoMatch; const PropertyBrushMap::iterator brit = m_brushValues.find(property); if (brit == m_brushValues.end()) - return NoMatch; + return DesignerPropertyManager::NoMatch; const QBrush newBrush = qvariant_cast(value); if (newBrush == brit.value()) - return Unchanged; + return DesignerPropertyManager::Unchanged; brit.value() = newBrush; if (QtProperty *styleProperty = m_brushPropertyToStyleSubProperty.value(property)) vm->variantProperty(styleProperty)->setValue(brushStyleToIndex(newBrush.style())); if (QtProperty *colorProperty = m_brushPropertyToColorSubProperty.value(property)) vm->variantProperty(colorProperty)->setValue(newBrush.color()); - return Changed; + return DesignerPropertyManager::Changed; } bool BrushPropertyManager::valueText(const QtProperty *property, QString *text) const diff --git a/src/designer/src/components/propertyeditor/brushpropertymanager.h b/src/designer/src/components/propertyeditor/brushpropertymanager.h index d82d624b4..a4ddf4cca 100644 --- a/src/designer/src/components/propertyeditor/brushpropertymanager.h +++ b/src/designer/src/components/propertyeditor/brushpropertymanager.h @@ -69,9 +69,8 @@ public: bool uninitializeProperty(QtProperty *property); // Call from slotValueChanged(). - enum ValueChangedResult { NoMatch, Unchanged, Changed }; - ValueChangedResult valueChanged(QtVariantPropertyManager *vm, QtProperty *property, const QVariant &value); - ValueChangedResult setValue(QtVariantPropertyManager *vm, QtProperty *property, const QVariant &value); + int valueChanged(QtVariantPropertyManager *vm, QtProperty *property, const QVariant &value); + int setValue(QtVariantPropertyManager *vm, QtProperty *property, const QVariant &value); bool valueText(const QtProperty *property, QString *text) const; bool valueIcon(const QtProperty *property, QIcon *icon) const; diff --git a/src/designer/src/components/propertyeditor/designerpropertymanager.cpp b/src/designer/src/components/propertyeditor/designerpropertymanager.cpp index 391ecb06e..1bc7f2d6b 100644 --- a/src/designer/src/components/propertyeditor/designerpropertymanager.cpp +++ b/src/designer/src/components/propertyeditor/designerpropertymanager.cpp @@ -101,6 +101,153 @@ QT_BEGIN_NAMESPACE namespace qdesigner_internal { +template +void TranslatablePropertyManager::initialize(QtVariantPropertyManager *m, + QtProperty *property, + const PropertySheetValue &value) +{ + m_values.insert(property, value); + + QtVariantProperty *translatable = m->addProperty(QVariant::Bool, DesignerPropertyManager::tr("translatable")); + translatable->setValue(value.translatable()); + m_valueToTranslatable.insert(property, translatable); + m_translatableToValue.insert(translatable, property); + property->addSubProperty(translatable); + + QtVariantProperty *disambiguation = m->addProperty(QVariant::String, DesignerPropertyManager::tr("disambiguation")); + disambiguation->setValue(value.disambiguation()); + m_valueToDisambiguation.insert(property, disambiguation); + m_disambiguationToValue.insert(disambiguation, property); + property->addSubProperty(disambiguation); + + QtVariantProperty *comment = m->addProperty(QVariant::String, DesignerPropertyManager::tr("comment")); + comment->setValue(value.comment()); + m_valueToComment.insert(property, comment); + m_commentToValue.insert(comment, property); + property->addSubProperty(comment); +} + +template +bool TranslatablePropertyManager::uninitialize(QtProperty *property) +{ + if (QtProperty *comment = m_valueToComment.value(property)) { + delete comment; + m_commentToValue.remove(comment); + } else { + return false; + } + if (QtProperty *translatable = m_valueToTranslatable.value(property)) { + delete translatable; + m_translatableToValue.remove(translatable); + } + if (QtProperty *disambiguation = m_valueToDisambiguation.value(property)) { + delete disambiguation; + m_disambiguationToValue.remove(disambiguation); + } + m_values.remove(property); + m_valueToComment.remove(property); + m_valueToTranslatable.remove(property); + m_valueToDisambiguation.remove(property); + return true; +} + +template +bool TranslatablePropertyManager::destroy(QtProperty *subProperty) +{ + if (QtProperty *stringCommentProperty = m_commentToValue.value(subProperty, 0)) { + m_valueToComment.remove(stringCommentProperty); + m_commentToValue.remove(subProperty); + return true; + } + if (QtProperty *stringTranslatableProperty = m_translatableToValue.value(subProperty, 0)) { + m_valueToTranslatable.remove(stringTranslatableProperty); + m_translatableToValue.remove(subProperty); + return true; + } + if (QtProperty *stringDisambiguationProperty = m_disambiguationToValue.value(subProperty, 0)) { + m_valueToDisambiguation.remove(stringDisambiguationProperty); + m_disambiguationToValue.remove(subProperty); + return true; + } + return false; +} + +template +int TranslatablePropertyManager::valueChanged(QtVariantPropertyManager *m, + QtProperty *propertyIn, + const QVariant &value) +{ + if (QtProperty *property = m_translatableToValue.value(propertyIn, 0)) { + const PropertySheetValue oldValue = m_values.value(property); + PropertySheetValue newValue = oldValue; + newValue.setTranslatable(value.toBool()); + if (newValue != oldValue) { + m->variantProperty(property)->setValue(QVariant::fromValue(newValue)); + return DesignerPropertyManager::Changed; + } + return DesignerPropertyManager::Unchanged; + } + if (QtProperty *property = m_commentToValue.value(propertyIn)) { + const PropertySheetValue oldValue = m_values.value(property); + PropertySheetValue newValue = oldValue; + newValue.setComment(value.toString()); + if (newValue != oldValue) { + m->variantProperty(property)->setValue(QVariant::fromValue(newValue)); + return DesignerPropertyManager::Changed; + } + return DesignerPropertyManager::Unchanged; + } + if (QtProperty *property = m_disambiguationToValue.value(propertyIn, 0)) { + const PropertySheetValue oldValue = m_values.value(property); + PropertySheetValue newValue = oldValue; + newValue.setDisambiguation(value.toString()); + if (newValue != oldValue) { + m->variantProperty(property)->setValue(QVariant::fromValue(newValue)); + return DesignerPropertyManager::Changed; + } + return DesignerPropertyManager::Unchanged; + } + return DesignerPropertyManager::NoMatch; +} + +template +int TranslatablePropertyManager::setValue(QtVariantPropertyManager *m, + QtProperty *property, + int expectedTypeId, + const QVariant &variantValue) +{ + typedef typename QMap::iterator Iterator; + + const Iterator it = m_values.find(property); + if (it == m_values.end()) + return DesignerPropertyManager::NoMatch; + if (variantValue.userType() != expectedTypeId) + return DesignerPropertyManager::NoMatch; + const PropertySheetValue value = qvariant_cast(variantValue); + if (value == it.value()) + return DesignerPropertyManager::Unchanged; + if (QtVariantProperty *comment = m->variantProperty(m_valueToComment.value(property))) + comment->setValue(value.comment()); + if (QtVariantProperty *translatable = m->variantProperty(m_valueToTranslatable.value(property))) + translatable->setValue(value.translatable()); + if (QtVariantProperty *disambiguation = m->variantProperty(m_valueToDisambiguation.value(property))) + disambiguation->setValue(value.disambiguation()); + it.value() = value; + return DesignerPropertyManager::Changed; +} + +template +bool TranslatablePropertyManager::value(const QtProperty *property, QVariant *rc) const +{ + typedef typename QMap::const_iterator ConstIterator; + + ConstIterator it = m_values.constFind(const_cast(property)); + if (it == m_values.constEnd()) + return false; + *rc = QVariant::fromValue(it.value()); + return true; +} + // ------------ TextEditor class TextEditor : public QWidget { @@ -808,6 +955,20 @@ void DesignerPropertyManager::slotValueChanged(QtProperty *property, const QVari return; bool enableSubPropertyHandling = true; + // Find a matching manager + int subResult = m_stringManager.valueChanged(this, property, value); + if (subResult == NoMatch) + subResult = m_keySequenceManager.valueChanged(this, property, value); + if (subResult == NoMatch) + subResult = m_brushManager.valueChanged(this, property, value); + if (subResult == NoMatch) + subResult = m_fontManager.valueChanged(this, property, value); + if (subResult != NoMatch) { + if (subResult == Changed) + emit valueChanged(property, value, enableSubPropertyHandling); + return; + } + if (QtProperty *flagProperty = m_flagToProperty.value(property, 0)) { const QList subFlags = m_propertyToFlags.value(flagProperty); const int subFlagCount = subFlags.count(); @@ -894,54 +1055,6 @@ void DesignerPropertyManager::slotValueChanged(QtProperty *property, const QVari return; variantProperty(alignProperty)->setValue(newValue); - } else if (QtProperty *stringProperty = m_commentToString.value(property, 0)) { - const PropertySheetStringValue v = m_stringValues.value(stringProperty); - PropertySheetStringValue newValue = v; - newValue.setComment(value.toString()); - if (v == newValue) - return; - - variantProperty(stringProperty)->setValue(QVariant::fromValue(newValue)); - } else if (QtProperty *stringProperty = m_translatableToString.value(property, 0)) { - const PropertySheetStringValue v = m_stringValues.value(stringProperty); - PropertySheetStringValue newValue = v; - newValue.setTranslatable(value.toBool()); - if (v == newValue) - return; - - variantProperty(stringProperty)->setValue(QVariant::fromValue(newValue)); - } else if (QtProperty *stringProperty = m_disambiguationToString.value(property, 0)) { - const PropertySheetStringValue v = m_stringValues.value(stringProperty); - PropertySheetStringValue newValue = v; - newValue.setDisambiguation(value.toString()); - if (v == newValue) - return; - - variantProperty(stringProperty)->setValue(QVariant::fromValue(newValue)); - } else if (QtProperty *keySequenceProperty = m_commentToKeySequence.value(property, 0)) { - const PropertySheetKeySequenceValue v = m_keySequenceValues.value(keySequenceProperty); - PropertySheetKeySequenceValue newValue = v; - newValue.setComment(value.toString()); - if (v == newValue) - return; - - variantProperty(keySequenceProperty)->setValue(QVariant::fromValue(newValue)); - } else if (QtProperty *keySequenceProperty = m_translatableToKeySequence.value(property, 0)) { - const PropertySheetKeySequenceValue v = m_keySequenceValues.value(keySequenceProperty); - PropertySheetKeySequenceValue newValue = v; - newValue.setTranslatable(value.toBool()); - if (v == newValue) - return; - - variantProperty(keySequenceProperty)->setValue(QVariant::fromValue(newValue)); - } else if (QtProperty *keySequenceProperty = m_disambiguationToKeySequence.value(property, 0)) { - const PropertySheetKeySequenceValue v = m_keySequenceValues.value(keySequenceProperty); - PropertySheetKeySequenceValue newValue = v; - newValue.setDisambiguation(value.toString()); - if (v == newValue) - return; - - variantProperty(keySequenceProperty)->setValue(QVariant::fromValue(newValue)); } else if (QtProperty *iProperty = m_iconSubPropertyToProperty.value(property, 0)) { QtVariantProperty *iconProperty = variantProperty(iProperty); PropertySheetIconValue icon = qvariant_cast(iconProperty->value()); @@ -960,13 +1073,7 @@ void DesignerPropertyManager::slotValueChanged(QtProperty *property, const QVari m_sourceOfChange = origSourceOfChange; } else if (m_iconValues.contains(property)) { enableSubPropertyHandling = m_sourceOfChange; - } else { - if (m_brushManager.valueChanged(this, property, value) == BrushPropertyManager::Unchanged) - return; - if (m_fontManager.valueChanged(this, property, value) == FontPropertyManager::Unchanged) - return; } - emit valueChanged(property, value, enableSubPropertyHandling); } @@ -983,24 +1090,8 @@ void DesignerPropertyManager::slotPropertyDestroyed(QtProperty *property) } else if (QtProperty *alignProperty = m_alignVToProperty.value(property, 0)) { m_propertyToAlignV.remove(alignProperty); m_alignVToProperty.remove(property); - } else if (QtProperty *stringCommentProperty = m_commentToString.value(property, 0)) { - m_stringToComment.remove(stringCommentProperty); - m_commentToString.remove(property); - } else if (QtProperty *stringTranslatableProperty = m_translatableToString.value(property, 0)) { - m_stringToTranslatable.remove(stringTranslatableProperty); - m_translatableToString.remove(property); - } else if (QtProperty *stringDisambiguationProperty = m_disambiguationToString.value(property, 0)) { - m_stringToDisambiguation.remove(stringDisambiguationProperty); - m_disambiguationToString.remove(property); - } else if (QtProperty *keySequenceCommentProperty = m_commentToKeySequence.value(property, 0)) { - m_keySequenceToComment.remove(keySequenceCommentProperty); - m_commentToKeySequence.remove(property); - } else if (QtProperty *keySequenceTranslatableProperty = m_translatableToKeySequence.value(property, 0)) { - m_keySequenceToTranslatable.remove(keySequenceTranslatableProperty); - m_translatableToKeySequence.remove(property); - } else if (QtProperty *keySequenceDisambiguationProperty = m_disambiguationToKeySequence.value(property, 0)) { - m_keySequenceToDisambiguation.remove(keySequenceDisambiguationProperty); - m_disambiguationToKeySequence.remove(property); + } else if (m_stringManager.destroy(property) + || m_keySequenceManager.destroy(property)) { } else if (QtProperty *iconProperty = m_iconSubPropertyToProperty.value(property, 0)) { if (m_propertyToTheme.value(iconProperty) == property) { m_propertyToTheme.remove(iconProperty); @@ -1537,10 +1628,11 @@ QVariant DesignerPropertyManager::value(const QtProperty *property) const return QVariant::fromValue(m_iconValues.value(const_cast(property))); if (m_pixmapValues.contains(const_cast(property))) return QVariant::fromValue(m_pixmapValues.value(const_cast(property))); - if (m_stringValues.contains(const_cast(property))) - return QVariant::fromValue(m_stringValues.value(const_cast(property))); - if (m_keySequenceValues.contains(const_cast(property))) - return QVariant::fromValue(m_keySequenceValues.value(const_cast(property))); + QVariant rc; + if (m_stringManager.value(property, &rc) + || m_keySequenceManager.value(property, &rc) + || m_brushManager.value(property, &rc)) + return rc; if (m_uintValues.contains(const_cast(property))) return m_uintValues.value(const_cast(property)); if (m_longLongValues.contains(const_cast(property))) @@ -1554,9 +1646,6 @@ QVariant DesignerPropertyManager::value(const QtProperty *property) const if (m_stringListValues.contains(const_cast(property))) return m_stringListValues.value(const_cast(property)); - QVariant rc; - if (m_brushManager.value(property, &rc)) - return rc; return QtVariantPropertyManager::value(property); } @@ -1592,6 +1681,19 @@ int DesignerPropertyManager::valueType(int propertyType) const void DesignerPropertyManager::setValue(QtProperty *property, const QVariant &value) { + int subResult = m_stringManager.setValue(this, property, designerStringTypeId(), value); + if (subResult == NoMatch) + subResult = m_keySequenceManager.setValue(this, property, designerKeySequenceTypeId(), value); + if (subResult == NoMatch) + subResult = m_brushManager.setValue(this, property, value); + if (subResult != NoMatch) { + if (subResult == Changed) { + emit QtVariantPropertyManager::valueChanged(property, value); + emit propertyChanged(property); + } + return; + } + const PropertyFlagDataMap::iterator fit = m_flagValues.find(property); if (fit != m_flagValues.end()) { @@ -1669,62 +1771,6 @@ void DesignerPropertyManager::setValue(QtProperty *property, const QVariant &val emit QtVariantPropertyManager::valueChanged(property, v); emit propertyChanged(property); - return; - } else if (m_stringValues.contains(property)) { - if (value.userType() != designerStringTypeId()) - return; - - const PropertySheetStringValue v = qvariant_cast(value); - - const PropertySheetStringValue val = m_stringValues.value(property); - - if (val == v) - return; - - QtVariantProperty *comment = variantProperty(m_stringToComment.value(property)); - QtVariantProperty *translatable = variantProperty(m_stringToTranslatable.value(property)); - QtVariantProperty *disambiguation = variantProperty(m_stringToDisambiguation.value(property)); - - if (comment) - comment->setValue(v.comment()); - if (translatable) - translatable->setValue(v.translatable()); - if (disambiguation) - disambiguation->setValue(v.disambiguation()); - - m_stringValues[property] = v; - - emit QtVariantPropertyManager::valueChanged(property, QVariant::fromValue(v)); - emit propertyChanged(property); - - return; - } else if (m_keySequenceValues.contains(property)) { - if (value.userType() != designerKeySequenceTypeId()) - return; - - const PropertySheetKeySequenceValue v = qvariant_cast(value); - - const PropertySheetKeySequenceValue val = m_keySequenceValues.value(property); - - if (val == v) - return; - - QtVariantProperty *comment = variantProperty(m_keySequenceToComment.value(property)); - QtVariantProperty *translatable = variantProperty(m_keySequenceToTranslatable.value(property)); - QtVariantProperty *disambiguation = variantProperty(m_keySequenceToDisambiguation.value(property)); - - if (comment) - comment->setValue(v.comment()); - if (translatable) - translatable->setValue(v.translatable()); - if (disambiguation) - disambiguation->setValue(v.disambiguation()); - - m_keySequenceValues[property] = v; - - emit QtVariantPropertyManager::valueChanged(property, QVariant::fromValue(v)); - emit propertyChanged(property); - return; } else if (m_paletteValues.contains(property)) { if (value.type() != QVariant::Palette && !value.canConvert(QVariant::Palette)) @@ -1914,16 +1960,6 @@ void DesignerPropertyManager::setValue(QtProperty *property, const QVariant &val return; } - switch (m_brushManager.setValue(this, property, value)) { - case BrushPropertyManager::Unchanged: - return; - case BrushPropertyManager::Changed: - emit QtVariantPropertyManager::valueChanged(property, value); - emit propertyChanged(property); - return; - default: - break; - } m_fontManager.setValue(this, property, value); QtVariantPropertyManager::setValue(property, value); if (QtVariantPropertyManager::valueType(property) == QVariant::String) @@ -2020,50 +2056,12 @@ void DesignerPropertyManager::initializeProperty(QtProperty *property) createIconSubProperty(property, QIcon::Selected, QIcon::Off, tr("Selected Off")); createIconSubProperty(property, QIcon::Selected, QIcon::On, tr("Selected On")); } else if (type == designerStringTypeId()) { - PropertySheetStringValue val; - m_stringValues[property] = val; - m_stringAttributes[property] = ValidationMultiLine; - m_stringFontAttributes[property] = QApplication::font(); - m_stringThemeAttributes[property] = false; - - QtVariantProperty *translatable = addProperty(QVariant::Bool, tr("translatable")); - translatable->setValue(val.translatable()); - m_stringToTranslatable[property] = translatable; - m_translatableToString[translatable] = property; - property->addSubProperty(translatable); - - QtVariantProperty *disambiguation = addProperty(QVariant::String, tr("disambiguation")); - disambiguation->setValue(val.disambiguation()); - m_stringToDisambiguation[property] = disambiguation; - m_disambiguationToString[disambiguation] = property; - property->addSubProperty(disambiguation); - - QtVariantProperty *comment = addProperty(QVariant::String, tr("comment")); - comment->setValue(val.comment()); - m_stringToComment[property] = comment; - m_commentToString[comment] = property; - property->addSubProperty(comment); + m_stringManager.initialize(this, property, PropertySheetStringValue()); + m_stringAttributes.insert(property, ValidationMultiLine); + m_stringFontAttributes.insert(property, QApplication::font()); + m_stringThemeAttributes.insert(property, false); } else if (type == designerKeySequenceTypeId()) { - PropertySheetKeySequenceValue val; - m_keySequenceValues[property] = val; - - QtVariantProperty *translatable = addProperty(QVariant::Bool, tr("translatable")); - translatable->setValue(val.translatable()); - m_keySequenceToTranslatable[property] = translatable; - m_translatableToKeySequence[translatable] = property; - property->addSubProperty(translatable); - - QtVariantProperty *disambiguation = addProperty(QVariant::String, tr("disambiguation")); - disambiguation->setValue(val.disambiguation()); - m_keySequenceToDisambiguation[property] = disambiguation; - m_disambiguationToKeySequence[disambiguation] = property; - property->addSubProperty(disambiguation); - - QtVariantProperty *comment = addProperty(QVariant::String, tr("comment")); - comment->setValue(val.comment()); - m_keySequenceToComment[property] = comment; - m_commentToKeySequence[comment] = property; - property->addSubProperty(comment); + m_keySequenceManager.initialize(this, property, PropertySheetKeySequenceValue()); } } @@ -2110,44 +2108,10 @@ void DesignerPropertyManager::uninitializeProperty(QtProperty *property) m_alignVToProperty.remove(alignV); } - QtProperty *stringComment = m_stringToComment.value(property); - if (stringComment) { - delete stringComment; - m_commentToString.remove(stringComment); - } - - QtProperty *stringTranslatable = m_stringToTranslatable.value(property); - if (stringTranslatable) { - delete stringTranslatable; - m_translatableToString.remove(stringTranslatable); - } - - QtProperty *stringDisambiguation = m_stringToDisambiguation.value(property); - if (stringDisambiguation) { - delete stringDisambiguation; - m_disambiguationToString.remove(stringDisambiguation); - } + m_stringManager.uninitialize(property); + m_keySequenceManager.uninitialize(property); - QtProperty *keySequenceComment = m_keySequenceToComment.value(property); - if (keySequenceComment) { - delete keySequenceComment; - m_commentToKeySequence.remove(keySequenceComment); - } - - QtProperty *keySequenceTranslatable = m_keySequenceToTranslatable.value(property); - if (keySequenceTranslatable) { - delete keySequenceTranslatable; - m_translatableToKeySequence.remove(keySequenceTranslatable); - } - - QtProperty *keySequenceDisambiguation = m_keySequenceToDisambiguation.value(property); - if (keySequenceDisambiguation) { - delete keySequenceDisambiguation; - m_disambiguationToKeySequence.remove(keySequenceDisambiguation); - } - - QtProperty *iconTheme = m_propertyToTheme.value(property); - if (iconTheme) { + if (QtProperty *iconTheme = m_propertyToTheme.value(property)) { delete iconTheme; m_iconSubPropertyToProperty.remove(iconTheme); } @@ -2155,18 +2119,9 @@ void DesignerPropertyManager::uninitializeProperty(QtProperty *property) m_propertyToAlignH.remove(property); m_propertyToAlignV.remove(property); - m_stringToComment.remove(property); - m_stringToTranslatable.remove(property); - m_stringToDisambiguation.remove(property); - m_stringValues.remove(property); m_stringAttributes.remove(property); m_stringFontAttributes.remove(property); - m_keySequenceToComment.remove(property); - m_keySequenceToTranslatable.remove(property); - m_keySequenceToDisambiguation.remove(property); - m_keySequenceValues.remove(property); - m_paletteValues.remove(property); m_iconValues.remove(property); diff --git a/src/designer/src/components/propertyeditor/designerpropertymanager.h b/src/designer/src/components/propertyeditor/designerpropertymanager.h index 18d76d5ee..f28858c19 100644 --- a/src/designer/src/components/propertyeditor/designerpropertymanager.h +++ b/src/designer/src/components/propertyeditor/designerpropertymanager.h @@ -98,10 +98,40 @@ private: int m_spacing; }; +// Helper for handling sub-properties of properties inheriting PropertySheetTranslatableData +// (translatable, disambiguation, comment). +template +class TranslatablePropertyManager +{ +public: + void initialize(QtVariantPropertyManager *m, QtProperty *property, const PropertySheetValue &value); + bool uninitialize(QtProperty *property); + bool destroy(QtProperty *subProperty); + + bool value(const QtProperty *property, QVariant *rc) const; + int valueChanged(QtVariantPropertyManager *m, QtProperty *property, + const QVariant &value); + + int setValue(QtVariantPropertyManager *m, QtProperty *property, + int expectedTypeId, const QVariant &value); + +private: + QMap m_values; + QMap m_valueToComment; + QMap m_valueToTranslatable; + QMap m_valueToDisambiguation; + + QMap m_commentToValue; + QMap m_translatableToValue; + QMap m_disambiguationToValue; +}; + class DesignerPropertyManager : public QtVariantPropertyManager { Q_OBJECT public: + enum ValueChangedResult { NoMatch, Unchanged, Changed }; + explicit DesignerPropertyManager(QDesignerFormEditorInterface *core, QObject *parent = 0); ~DesignerPropertyManager(); @@ -182,23 +212,8 @@ private: PropertyToPropertyMap m_iconSubPropertyToProperty; PropertyToPropertyMap m_propertyToTheme; - QMap m_stringValues; - QMap m_stringToComment; - QMap m_stringToTranslatable; - QMap m_stringToDisambiguation; - - QMap m_commentToString; - QMap m_translatableToString; - QMap m_disambiguationToString; - - QMap m_keySequenceValues; - QMap m_keySequenceToComment; - QMap m_keySequenceToTranslatable; - QMap m_keySequenceToDisambiguation; - - QMap m_commentToKeySequence; - QMap m_translatableToKeySequence; - QMap m_disambiguationToKeySequence; + TranslatablePropertyManager m_stringManager; + TranslatablePropertyManager m_keySequenceManager; struct PaletteData { @@ -304,7 +319,7 @@ private: QMap m_editorToStringListProperty; }; -} +} // namespace qdesigner_internal QT_END_NAMESPACE diff --git a/src/designer/src/components/propertyeditor/fontpropertymanager.cpp b/src/designer/src/components/propertyeditor/fontpropertymanager.cpp index 47c69a81d..f974abf02 100644 --- a/src/designer/src/components/propertyeditor/fontpropertymanager.cpp +++ b/src/designer/src/components/propertyeditor/fontpropertymanager.cpp @@ -41,7 +41,7 @@ #include "fontpropertymanager.h" #include "qtpropertymanager.h" -#include "qtvariantproperty.h" +#include "designerpropertymanager.h" #include "qtpropertybrowserutils_p.h" #include @@ -237,14 +237,14 @@ namespace qdesigner_internal { return 0; } - FontPropertyManager::ValueChangedResult FontPropertyManager::valueChanged(QtVariantPropertyManager *vm, QtProperty *property, const QVariant &value) + int FontPropertyManager::valueChanged(QtVariantPropertyManager *vm, QtProperty *property, const QVariant &value) { QtProperty *antialiasingProperty = m_antialiasingToProperty.value(property, 0); if (!antialiasingProperty) { if (m_propertyToFontSubProperties.contains(property)) { updateModifiedState(property, value); } - return NoMatch; + return DesignerPropertyManager::NoMatch; } QtVariantProperty *fontProperty = vm->variantProperty(antialiasingProperty); @@ -253,11 +253,11 @@ namespace qdesigner_internal { QFont font = qvariant_cast(fontProperty->value()); const QFont::StyleStrategy oldValue = font.styleStrategy(); if (newValue == oldValue) - return Unchanged; + return DesignerPropertyManager::Unchanged; font.setStyleStrategy(newValue); fontProperty->setValue(QVariant::fromValue(font)); - return Changed; + return DesignerPropertyManager::Changed; } void FontPropertyManager::updateModifiedState(QtProperty *property, const QVariant &value) diff --git a/src/designer/src/components/propertyeditor/fontpropertymanager.h b/src/designer/src/components/propertyeditor/fontpropertymanager.h index cf013c4f7..9b8db308f 100644 --- a/src/designer/src/components/propertyeditor/fontpropertymanager.h +++ b/src/designer/src/components/propertyeditor/fontpropertymanager.h @@ -84,9 +84,8 @@ public: bool resetFontSubProperty(QtVariantPropertyManager *vm, QtProperty *subProperty); - // Call from slotValueChanged(). - enum ValueChangedResult { NoMatch, Unchanged, Changed }; - ValueChangedResult valueChanged(QtVariantPropertyManager *vm, QtProperty *property, const QVariant &value); + // Call from slotValueChanged(), returns DesignerPropertyManager::ValueChangedResult + int valueChanged(QtVariantPropertyManager *vm, QtProperty *property, const QVariant &value); // Call from setValue() before calling setValue() on QtVariantPropertyManager. void setValue(QtVariantPropertyManager *vm, QtProperty *property, const QVariant &value); -- cgit v1.2.1