diff options
author | Friedemann Kleint <Friedemann.Kleint@nokia.com> | 2012-01-12 12:10:47 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-20 11:40:11 +0100 |
commit | e3abbbbde7bfb268f076832ae2af5d113df58a36 (patch) | |
tree | 9eda4491a99801e1ecc6a2cd920ec5be6adc8614 /src/designer/src/components | |
parent | ab9406faeb355d0bd8e0f7e2a6d0fe8d07d8e7d8 (diff) |
Qt Designer: Add translation-attributes to string list properties.
- Add translation parameters to XML schema for ui.
- Introduce PropertySheetStringListValue to property sheet,
load & save code, add to property sheet and property editor.
Task-number: QTBUG-8926
Task-number: QTBUG-20440
Change-Id: Ib5e9e2e9ba603bb68984a102e3c3fc8ff1cb4df0
Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@nokia.com>
Diffstat (limited to 'src/designer/src/components')
3 files changed, 127 insertions, 80 deletions
diff --git a/src/designer/src/components/formeditor/qdesigner_resource.cpp b/src/designer/src/components/formeditor/qdesigner_resource.cpp index 0b4f2673a..462900a38 100644 --- a/src/designer/src/components/formeditor/qdesigner_resource.cpp +++ b/src/designer/src/components/formeditor/qdesigner_resource.cpp @@ -944,7 +944,8 @@ void QDesignerResource::applyProperties(QObject *o, const QList<DomProperty*> &p if (!readDomEnumerationValue(p, sheet, index, v)) v = toVariant(o->metaObject(), *it); - if (p->kind() == DomProperty::String) { + switch (p->kind()) { + case DomProperty::String: if (index != -1 && sheet->property(index).userType() == qMetaTypeId<PropertySheetKeySequenceValue>()) { const DomString *key = p->elementString(); PropertySheetKeySequenceValue keyVal(QKeySequence(key->text())); @@ -956,6 +957,16 @@ void QDesignerResource::applyProperties(QObject *o, const QList<DomProperty*> &p translationParametersFromDom(str, &strVal); v = QVariant::fromValue(strVal); } + break; + case DomProperty::StringList: { + const DomStringList *list = p->elementStringList(); + PropertySheetStringListValue listValue(list->elementString()); + translationParametersFromDom(list, &listValue); + v = QVariant::fromValue(listValue); + } + break; + default: + break; } d->applyPropertyInternally(o, propertyName, v); @@ -974,6 +985,9 @@ void QDesignerResource::applyProperties(QObject *o, const QList<DomProperty*> &p } else if (v.canConvert<PropertySheetStringValue>()) { defaultValue = QVariant(QVariant::String); isDefault = (qvariant_cast<PropertySheetStringValue>(v) == PropertySheetStringValue()); + } else if (v.canConvert<PropertySheetStringListValue>()) { + defaultValue = QVariant(QVariant::StringList); + isDefault = (qvariant_cast<PropertySheetStringListValue>(v) == PropertySheetStringListValue()); } else if (v.canConvert<PropertySheetKeySequenceValue>()) { defaultValue = QVariant(QVariant::KeySequence); isDefault = (qvariant_cast<PropertySheetKeySequenceValue>(v) == PropertySheetKeySequenceValue()); @@ -2001,6 +2015,19 @@ DomProperty *QDesignerResource::createProperty(QObject *object, const QString &p p->setAttributeName(propertyName); return applyProperStdSetAttribute(object, propertyName, p); + } else if (value.canConvert<PropertySheetStringListValue>()) { + const PropertySheetStringListValue listValue = qvariant_cast<PropertySheetStringListValue>(value); + DomProperty *p = new DomProperty; + if (!hasSetter(core(), object, propertyName)) + p->setAttributeStdset(0); + + p->setAttributeName(propertyName); + + DomStringList *domStringList = new DomStringList(); + domStringList->setElementString(listValue.value()); + translationParametersToDom(listValue, domStringList); + p->setElementStringList(domStringList); + return applyProperStdSetAttribute(object, propertyName, p); } else if (value.canConvert<PropertySheetKeySequenceValue>()) { const PropertySheetKeySequenceValue keyVal = qvariant_cast<PropertySheetKeySequenceValue>(value); DomProperty *p = stringToDomProperty(keyVal.value().toString(), keyVal); diff --git a/src/designer/src/components/propertyeditor/designerpropertymanager.cpp b/src/designer/src/components/propertyeditor/designerpropertymanager.cpp index 1bc7f2d6b..2a88eba33 100644 --- a/src/designer/src/components/propertyeditor/designerpropertymanager.cpp +++ b/src/designer/src/components/propertyeditor/designerpropertymanager.cpp @@ -960,6 +960,8 @@ void DesignerPropertyManager::slotValueChanged(QtProperty *property, const QVari if (subResult == NoMatch) subResult = m_keySequenceManager.valueChanged(this, property, value); if (subResult == NoMatch) + subResult = m_stringListManager.valueChanged(this, property, value); + if (subResult == NoMatch) subResult = m_brushManager.valueChanged(this, property, value); if (subResult == NoMatch) subResult = m_fontManager.valueChanged(this, property, value); @@ -1091,6 +1093,7 @@ void DesignerPropertyManager::slotPropertyDestroyed(QtProperty *property) m_propertyToAlignV.remove(alignProperty); m_alignVToProperty.remove(property); } else if (m_stringManager.destroy(property) + || m_stringListManager.destroy(property) || m_keySequenceManager.destroy(property)) { } else if (QtProperty *iconProperty = m_iconSubPropertyToProperty.value(property, 0)) { if (m_propertyToTheme.value(iconProperty) == property) { @@ -1427,6 +1430,11 @@ int DesignerPropertyManager::designerStringTypeId() return qMetaTypeId<PropertySheetStringValue>(); } +int DesignerPropertyManager::designerStringListTypeId() +{ + return qMetaTypeId<PropertySheetStringListValue>(); +} + int DesignerPropertyManager::designerKeySequenceTypeId() { return qMetaTypeId<PropertySheetKeySequenceValue>(); @@ -1456,10 +1464,11 @@ bool DesignerPropertyManager::isPropertyTypeSupported(int propertyType) const return true; if (propertyType == designerIconTypeId()) return true; - if (propertyType == designerStringTypeId()) + if (propertyType == designerStringTypeId() || propertyType == designerStringListTypeId()) return true; if (propertyType == designerKeySequenceTypeId()) return true; + return QtVariantPropertyManager::isPropertyTypeSupported(propertyType); } @@ -1527,18 +1536,21 @@ QString DesignerPropertyManager::valueText(const QtProperty *property) const if (m_byteArrayValues.contains(const_cast<QtProperty *>(property))) { return QString::fromUtf8(m_byteArrayValues.value(const_cast<QtProperty *>(property))); } - if (m_stringListValues.contains(const_cast<QtProperty *>(property))) { - return m_stringListValues.value(const_cast<QtProperty *>(property)).join(QStringLiteral("; ")); - } - if (QtVariantPropertyManager::valueType(property) == QVariant::String || QtVariantPropertyManager::valueType(property) == designerStringTypeId()) { + const int vType = QtVariantPropertyManager::valueType(property); + if (vType == QVariant::String || vType == designerStringTypeId()) { const QString str = (QtVariantPropertyManager::valueType(property) == QVariant::String) ? value(property).toString() : qvariant_cast<PropertySheetStringValue>(value(property)).value(); const int validationMode = attributeValue(property, QLatin1String(validationModesAttributeC)).toInt(); return TextPropertyEditor::stringToEditorString(str, static_cast<TextPropertyValidationMode>(validationMode)); } - if (QtVariantPropertyManager::valueType(property) == designerKeySequenceTypeId()) { + if (vType == QVariant::StringList || vType == designerStringListTypeId()) { + QVariant v = value(property); + const QStringList list = v.type() == QVariant::StringList ? v.toStringList() : qvariant_cast<PropertySheetStringListValue>(v).value(); + return list.join(QStringLiteral("; ")); + } + if (vType == designerKeySequenceTypeId()) { return qvariant_cast<PropertySheetKeySequenceValue>(value(property)).value(); } - if (QtVariantPropertyManager::valueType(property) == QVariant::Bool) { + if (vType == QVariant::Bool) { return QString(); } @@ -1631,6 +1643,7 @@ QVariant DesignerPropertyManager::value(const QtProperty *property) const QVariant rc; if (m_stringManager.value(property, &rc) || m_keySequenceManager.value(property, &rc) + || m_stringListManager.value(property, &rc) || m_brushManager.value(property, &rc)) return rc; if (m_uintValues.contains(const_cast<QtProperty *>(property))) @@ -1643,8 +1656,6 @@ QVariant DesignerPropertyManager::value(const QtProperty *property) const return m_urlValues.value(const_cast<QtProperty *>(property)); if (m_byteArrayValues.contains(const_cast<QtProperty *>(property))) return m_byteArrayValues.value(const_cast<QtProperty *>(property)); - if (m_stringListValues.contains(const_cast<QtProperty *>(property))) - return m_stringListValues.value(const_cast<QtProperty *>(property)); return QtVariantPropertyManager::value(property); } @@ -1672,7 +1683,7 @@ int DesignerPropertyManager::valueType(int propertyType) const return propertyType; if (propertyType == designerIconTypeId()) return propertyType; - if (propertyType == designerStringTypeId()) + if (propertyType == designerStringTypeId() || propertyType == designerStringListTypeId()) return propertyType; if (propertyType == designerKeySequenceTypeId()) return propertyType; @@ -1683,6 +1694,8 @@ void DesignerPropertyManager::setValue(QtProperty *property, const QVariant &val { int subResult = m_stringManager.setValue(this, property, designerStringTypeId(), value); if (subResult == NoMatch) + subResult = m_stringListManager.setValue(this, property, designerStringListTypeId(), value); + if (subResult == NoMatch) subResult = m_keySequenceManager.setValue(this, property, designerKeySequenceTypeId(), value); if (subResult == NoMatch) subResult = m_brushManager.setValue(this, property, value); @@ -1943,22 +1956,6 @@ void DesignerPropertyManager::setValue(QtProperty *property, const QVariant &val emit propertyChanged(property); return; - } else if (m_stringListValues.contains(property)) { - if (value.type() != QVariant::StringList && !value.canConvert(QVariant::StringList)) - return; - - const QStringList v = value.toStringList(); - - const QStringList oldValue = m_stringListValues.value(property); - if (v == oldValue) - return; - - m_stringListValues[property] = v; - - emit QtVariantPropertyManager::valueChanged(property, v); - emit propertyChanged(property); - - return; } m_fontManager.setValue(this, property, value); QtVariantPropertyManager::setValue(property, value); @@ -2002,9 +1999,6 @@ void DesignerPropertyManager::initializeProperty(QtProperty *property) case QVariant::ByteArray: m_byteArrayValues[property] = 0; break; - case QVariant::StringList: - m_stringListValues[property] = QStringList(); - break; case QVariant::Brush: m_brushManager.initializeProperty(this, property, enumTypeId()); break; @@ -2060,6 +2054,8 @@ void DesignerPropertyManager::initializeProperty(QtProperty *property) m_stringAttributes.insert(property, ValidationMultiLine); m_stringFontAttributes.insert(property, QApplication::font()); m_stringThemeAttributes.insert(property, false); + } else if (type == designerStringListTypeId()) { + m_stringListManager.initialize(this, property, PropertySheetStringListValue()); } else if (type == designerKeySequenceTypeId()) { m_keySequenceManager.initialize(this, property, PropertySheetKeySequenceValue()); } @@ -2109,6 +2105,7 @@ void DesignerPropertyManager::uninitializeProperty(QtProperty *property) } m_stringManager.uninitialize(property); + m_stringListManager.uninitialize(property); m_keySequenceManager.uninitialize(property); if (QtProperty *iconTheme = m_propertyToTheme.value(property)) { @@ -2147,7 +2144,6 @@ void DesignerPropertyManager::uninitializeProperty(QtProperty *property) m_uLongLongValues.remove(property); m_urlValues.remove(property); m_byteArrayValues.remove(property); - m_stringListValues.remove(property); m_fontManager.uninitializeProperty(property); m_brushManager.uninitializeProperty(property); @@ -2338,13 +2334,14 @@ void DesignerEditorFactory::slotValueChanged(QtProperty *property, const QVarian default: if (type == DesignerPropertyManager::designerIconTypeId()) { PropertySheetIconValue iconValue = qvariant_cast<PropertySheetIconValue>(value); - const QString theme = iconValue.theme(); applyToEditors(m_iconPropertyToEditors.value(property), &PixmapEditor::setTheme, iconValue.theme()); applyToEditors(m_iconPropertyToEditors.value(property), &PixmapEditor::setPath, iconValue.pixmap(QIcon::Normal, QIcon::Off).path()); } else if (type == DesignerPropertyManager::designerPixmapTypeId()) { applyToEditors(m_pixmapPropertyToEditors.value(property), &PixmapEditor::setPath, qvariant_cast<PropertySheetPixmapValue>(value).path()); } else if (type == DesignerPropertyManager::designerStringTypeId()) { applyToEditors(m_stringPropertyToEditors.value(property), &TextEditor::setText, qvariant_cast<PropertySheetStringValue>(value).value()); + } else if (type == DesignerPropertyManager::designerStringListTypeId()) { + applyToEditors(m_stringListPropertyToEditors.value(property), &StringListEditorButton::setStringList, qvariant_cast<PropertySheetStringListValue>(value).value()); } else if (type == DesignerPropertyManager::designerKeySequenceTypeId()) { applyToEditors(m_keySequencePropertyToEditors.value(property), &QtKeySequenceEdit::setKeySequence, qvariant_cast<PropertySheetKeySequenceValue>(value).value()); } @@ -2452,15 +2449,6 @@ QWidget *DesignerEditorFactory::createEditor(QtVariantPropertyManager *manager, editor = ed; } break; - case QVariant::StringList: { - StringListEditorButton *ed = new StringListEditorButton(manager->value(property).toStringList(), parent); - m_stringListPropertyToEditors[property].append(ed); - m_editorToStringListProperty[ed] = property; - connect(ed, SIGNAL(destroyed(QObject*)), this, SLOT(slotEditorDestroyed(QObject*))); - connect(ed, SIGNAL(stringListChanged(QStringList)), this, SLOT(slotStringListChanged(QStringList))); - editor = ed; - } - break; default: if (type == DesignerPropertyManager::designerPixmapTypeId()) { PixmapEditor *ed = new PixmapEditor(m_core, parent); @@ -2504,6 +2492,16 @@ QWidget *DesignerEditorFactory::createEditor(QtVariantPropertyManager *manager, connect(ed, SIGNAL(destroyed(QObject*)), this, SLOT(slotEditorDestroyed(QObject*))); connect(ed, SIGNAL(textChanged(QString)), this, SLOT(slotStringTextChanged(QString))); editor = ed; + } else if (type == DesignerPropertyManager::designerStringListTypeId() || type == QVariant::StringList) { + const QVariant variantValue = manager->value(property); + const QStringList value = type == QVariant::StringList ? variantValue.toStringList() : + qvariant_cast<PropertySheetStringListValue>(variantValue).value(); + StringListEditorButton *ed = new StringListEditorButton(value, parent); + m_stringListPropertyToEditors[property].append(ed); + m_editorToStringListProperty.insert(ed, property); + connect(ed, SIGNAL(destroyed(QObject*)), this, SLOT(slotEditorDestroyed(QObject*))); + connect(ed, SIGNAL(stringListChanged(QStringList)), this, SLOT(slotStringListChanged(QStringList))); + editor = ed; } else if (type == DesignerPropertyManager::designerKeySequenceTypeId()) { QtKeySequenceEdit *ed = new QtKeySequenceEdit(parent); ed->setKeySequence(qvariant_cast<PropertySheetKeySequenceValue>(manager->value(property)).value()); @@ -2617,52 +2615,56 @@ void DesignerEditorFactory::slotByteArrayChanged(const QString &value) updateManager(this, &m_changingPropertyValue, m_editorToByteArrayProperty, qobject_cast<QWidget *>(sender()), value.toUtf8()); } +template <class Editor> +QtProperty *findPropertyForEditor(const QMap<Editor *, QtProperty *> &editorMap, + const QObject *sender) +{ + typedef typename QMap<Editor *, QtProperty *>::const_iterator Iterator; + const Iterator cend = editorMap.constEnd(); + for (Iterator it = editorMap.constBegin(); it != cend; ++it) + if (it.key() == sender) + return it.value(); + return 0; +} + void DesignerEditorFactory::slotStringTextChanged(const QString &value) { - QMapIterator<TextEditor *, QtProperty *> it(m_editorToStringProperty); - while (it.hasNext()) { - if (it.next().key() == sender()) { - QtProperty *prop = it.value(); - QtVariantPropertyManager *manager = propertyManager(prop); - QtVariantProperty *varProp = manager->variantProperty(prop); - QVariant val = varProp->value(); - if (val.userType() == DesignerPropertyManager::designerStringTypeId()) { - PropertySheetStringValue strVal = qvariant_cast<PropertySheetStringValue>(val); - strVal.setValue(value); - // Disable translation if no translation subproperties exist. - if (varProp->subProperties().empty()) - strVal.setTranslatable(false); - val = QVariant::fromValue(strVal); - } else { - val = QVariant(value); - } - m_changingPropertyValue = true; - manager->variantProperty(prop)->setValue(val); - m_changingPropertyValue = false; + if (QtProperty *prop = findPropertyForEditor(m_editorToStringProperty, sender())) { + QtVariantPropertyManager *manager = propertyManager(prop); + QtVariantProperty *varProp = manager->variantProperty(prop); + QVariant val = varProp->value(); + if (val.userType() == DesignerPropertyManager::designerStringTypeId()) { + PropertySheetStringValue strVal = qvariant_cast<PropertySheetStringValue>(val); + strVal.setValue(value); + // Disable translation if no translation subproperties exist. + if (varProp->subProperties().empty()) + strVal.setTranslatable(false); + val = QVariant::fromValue(strVal); + } else { + val = QVariant(value); } + m_changingPropertyValue = true; + manager->variantProperty(prop)->setValue(val); + m_changingPropertyValue = false; } } void DesignerEditorFactory::slotKeySequenceChanged(const QKeySequence &value) { - QMapIterator<QtKeySequenceEdit *, QtProperty *> it(m_editorToKeySequenceProperty); - while (it.hasNext()) { - if (it.next().key() == sender()) { - QtProperty *prop = it.value(); - QtVariantPropertyManager *manager = propertyManager(prop); - QtVariantProperty *varProp = manager->variantProperty(prop); - QVariant val = varProp->value(); - if (val.userType() == DesignerPropertyManager::designerKeySequenceTypeId()) { - PropertySheetKeySequenceValue keyVal = qvariant_cast<PropertySheetKeySequenceValue>(val); - keyVal.setValue(value); - val = QVariant::fromValue(keyVal); - } else { - val = QVariant::fromValue(value); - } - m_changingPropertyValue = true; - manager->variantProperty(prop)->setValue(val); - m_changingPropertyValue = false; + if (QtProperty *prop = findPropertyForEditor(m_editorToKeySequenceProperty, sender())) { + QtVariantPropertyManager *manager = propertyManager(prop); + QtVariantProperty *varProp = manager->variantProperty(prop); + QVariant val = varProp->value(); + if (val.userType() == DesignerPropertyManager::designerKeySequenceTypeId()) { + PropertySheetKeySequenceValue keyVal = qvariant_cast<PropertySheetKeySequenceValue>(val); + keyVal.setValue(value); + val = QVariant::fromValue(keyVal); + } else { + val = QVariant::fromValue(value); } + m_changingPropertyValue = true; + manager->variantProperty(prop)->setValue(val); + m_changingPropertyValue = false; } } @@ -2693,7 +2695,24 @@ void DesignerEditorFactory::slotIconThemeChanged(const QString &value) void DesignerEditorFactory::slotStringListChanged(const QStringList &value) { - updateManager(this, &m_changingPropertyValue, m_editorToStringListProperty, qobject_cast<QWidget *>(sender()), QVariant::fromValue(value)); + if (QtProperty *prop = findPropertyForEditor(m_editorToStringListProperty, sender())) { + QtVariantPropertyManager *manager = propertyManager(prop); + QtVariantProperty *varProp = manager->variantProperty(prop); + QVariant val = varProp->value(); + if (val.userType() == DesignerPropertyManager::designerStringListTypeId()) { + PropertySheetStringListValue listValue = qvariant_cast<PropertySheetStringListValue>(val); + listValue.setValue(value); + // Disable translation if no translation subproperties exist. + if (varProp->subProperties().empty()) + listValue.setTranslatable(false); + val = QVariant::fromValue(listValue); + } else { + val = QVariant(value); + } + m_changingPropertyValue = true; + manager->variantProperty(prop)->setValue(val); + m_changingPropertyValue = false; + } } ResetDecorator::~ResetDecorator() diff --git a/src/designer/src/components/propertyeditor/designerpropertymanager.h b/src/designer/src/components/propertyeditor/designerpropertymanager.h index f28858c19..55e8abb49 100644 --- a/src/designer/src/components/propertyeditor/designerpropertymanager.h +++ b/src/designer/src/components/propertyeditor/designerpropertymanager.h @@ -156,6 +156,7 @@ public: static int designerPixmapTypeId(); static int designerIconTypeId(); static int designerStringTypeId(); + static int designerStringListTypeId(); static int designerKeySequenceTypeId(); void setObject(QObject *object) { m_object = object; } @@ -214,6 +215,7 @@ private: TranslatablePropertyManager<PropertySheetStringValue> m_stringManager; TranslatablePropertyManager<PropertySheetKeySequenceValue> m_keySequenceManager; + TranslatablePropertyManager<PropertySheetStringListValue> m_stringListManager; struct PaletteData { @@ -231,7 +233,6 @@ private: QMap<QtProperty *, qulonglong> m_uLongLongValues; QMap<QtProperty *, QUrl> m_urlValues; QMap<QtProperty *, QByteArray> m_byteArrayValues; - QMap<QtProperty *, QStringList> m_stringListValues; typedef QMap<QtProperty *, int> PropertyIntMap; PropertyIntMap m_stringAttributes; |