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/lib | |
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/lib')
-rw-r--r-- | src/designer/src/lib/shared/qdesigner_propertycommand.cpp | 30 | ||||
-rw-r--r-- | src/designer/src/lib/shared/qdesigner_propertysheet.cpp | 91 | ||||
-rw-r--r-- | src/designer/src/lib/shared/qdesigner_utils.cpp | 26 | ||||
-rw-r--r-- | src/designer/src/lib/shared/qdesigner_utils_p.h | 20 | ||||
-rw-r--r-- | src/designer/src/lib/uilib/ui4.cpp | 32 | ||||
-rw-r--r-- | src/designer/src/lib/uilib/ui4_p.h | 24 |
6 files changed, 215 insertions, 8 deletions
diff --git a/src/designer/src/lib/shared/qdesigner_propertycommand.cpp b/src/designer/src/lib/shared/qdesigner_propertycommand.cpp index 7d4f99cde..10d670f83 100644 --- a/src/designer/src/lib/shared/qdesigner_propertycommand.cpp +++ b/src/designer/src/lib/shared/qdesigner_propertycommand.cpp @@ -170,6 +170,7 @@ enum RectSubPropertyMask { SubPropertyX=1, SubPropertyY = 2, SubPropertyWidth = enum SizePolicySubPropertyMask { SubPropertyHSizePolicy = 1, SubPropertyHStretch = 2, SubPropertyVSizePolicy = 4, SubPropertyVStretch = 8 }; enum AlignmentSubPropertyMask { SubPropertyHorizontalAlignment = 1, SubPropertyVerticalAlignment = 2 }; enum StringSubPropertyMask { SubPropertyStringValue = 1, SubPropertyStringComment = 2, SubPropertyStringTranslatable = 4, SubPropertyStringDisambiguation = 8 }; +enum StringListSubPropertyMask { SubPropertyStringListValue = 1, SubPropertyStringListComment = 2, SubPropertyStringListTranslatable = 4, SubPropertyStringListDisambiguation = 8 }; enum KeySequenceSubPropertyMask { SubPropertyKeySequenceValue = 1, SubPropertyKeySequenceComment = 2, SubPropertyKeySequenceTranslatable = 4, SubPropertyKeySequenceDisambiguation = 8 }; enum CommonSubPropertyMask { SubPropertyAll = 0xFFFFFFFF }; @@ -216,6 +217,16 @@ unsigned compareSubProperties(const qdesigner_internal::PropertySheetStringValue COMPARE_SUBPROPERTY(str1, str2, disambiguation, rc, SubPropertyStringDisambiguation) return rc; } +// find changed subproperties of qdesigner_internal::PropertySheetStringListValue +unsigned compareSubProperties(const qdesigner_internal::PropertySheetStringListValue & str1, const qdesigner_internal::PropertySheetStringListValue & str2) +{ + unsigned rc = 0; + COMPARE_SUBPROPERTY(str1, str2, value, rc, SubPropertyStringListValue) + COMPARE_SUBPROPERTY(str1, str2, comment, rc, SubPropertyStringListComment) + COMPARE_SUBPROPERTY(str1, str2, translatable, rc, SubPropertyStringListTranslatable) + COMPARE_SUBPROPERTY(str1, str2, disambiguation, rc, SubPropertyStringListDisambiguation) + return rc; +} // find changed subproperties of qdesigner_internal::PropertySheetKeySequenceValue unsigned compareSubProperties(const qdesigner_internal::PropertySheetKeySequenceValue & str1, const qdesigner_internal::PropertySheetKeySequenceValue & str2) { @@ -336,6 +347,8 @@ unsigned compareSubProperties(const QVariant & q1, const QVariant & q2, qdesigne return qvariant_cast<qdesigner_internal::PropertySheetIconValue>(q1).compare(qvariant_cast<qdesigner_internal::PropertySheetIconValue>(q2)); else if (q1.userType() == qMetaTypeId<qdesigner_internal::PropertySheetStringValue>()) return compareSubProperties(qvariant_cast<qdesigner_internal::PropertySheetStringValue>(q1), qvariant_cast<qdesigner_internal::PropertySheetStringValue>(q2)); + else if (q1.userType() == qMetaTypeId<qdesigner_internal::PropertySheetStringListValue>()) + return compareSubProperties(qvariant_cast<qdesigner_internal::PropertySheetStringListValue>(q1), qvariant_cast<qdesigner_internal::PropertySheetStringListValue>(q2)); else if (q1.userType() == qMetaTypeId<qdesigner_internal::PropertySheetKeySequenceValue>()) return compareSubProperties(qvariant_cast<qdesigner_internal::PropertySheetKeySequenceValue>(q1), qvariant_cast<qdesigner_internal::PropertySheetKeySequenceValue>(q2)); // Enumerations, flags @@ -398,6 +411,18 @@ qdesigner_internal::PropertySheetStringValue applyStringSubProperty(const qdesig return rc; } +// apply changed subproperties to a qdesigner_internal::PropertySheetStringListValue +qdesigner_internal::PropertySheetStringListValue applyStringListSubProperty(const qdesigner_internal::PropertySheetStringListValue &oldValue, + const qdesigner_internal::PropertySheetStringListValue &newValue, unsigned mask) +{ + qdesigner_internal::PropertySheetStringListValue rc = oldValue; + SET_SUBPROPERTY(rc, newValue, value, setValue, mask, SubPropertyStringListValue) + SET_SUBPROPERTY(rc, newValue, comment, setComment, mask, SubPropertyStringListComment) + SET_SUBPROPERTY(rc, newValue, translatable, setTranslatable, mask, SubPropertyStringListTranslatable) + SET_SUBPROPERTY(rc, newValue, disambiguation, setDisambiguation, mask, SubPropertyStringListDisambiguation) + return rc; +} + // apply changed subproperties to a qdesigner_internal::PropertySheetKeySequenceValue qdesigner_internal::PropertySheetKeySequenceValue applyKeySequenceSubProperty(const qdesigner_internal::PropertySheetKeySequenceValue &oldValue, const qdesigner_internal::PropertySheetKeySequenceValue &newValue, unsigned mask) @@ -540,6 +565,11 @@ PropertyHelper::Value applySubProperty(const QVariant &oldValue, const QVariant qvariant_cast<qdesigner_internal::PropertySheetStringValue>(oldValue), qvariant_cast<qdesigner_internal::PropertySheetStringValue>(newValue), mask); return PropertyHelper::Value(QVariant::fromValue(str), changed); + } else if (oldValue.userType() == qMetaTypeId<qdesigner_internal::PropertySheetStringListValue>()) { + qdesigner_internal::PropertySheetStringListValue str = applyStringListSubProperty( + qvariant_cast<qdesigner_internal::PropertySheetStringListValue>(oldValue), + qvariant_cast<qdesigner_internal::PropertySheetStringListValue>(newValue), mask); + return PropertyHelper::Value(QVariant::fromValue(str), changed); } else if (oldValue.userType() == qMetaTypeId<qdesigner_internal::PropertySheetKeySequenceValue>()) { qdesigner_internal::PropertySheetKeySequenceValue key = applyKeySequenceSubProperty( qvariant_cast<qdesigner_internal::PropertySheetKeySequenceValue>(oldValue), diff --git a/src/designer/src/lib/shared/qdesigner_propertysheet.cpp b/src/designer/src/lib/shared/qdesigner_propertysheet.cpp index f9af686c2..7c48ed206 100644 --- a/src/designer/src/lib/shared/qdesigner_propertysheet.cpp +++ b/src/designer/src/lib/shared/qdesigner_propertysheet.cpp @@ -209,6 +209,10 @@ public: void addStringProperty(int index); qdesigner_internal::PropertySheetStringValue stringProperty(int index) const; void setStringProperty(int index, const qdesigner_internal::PropertySheetStringValue &value); + bool isStringListProperty(int index) const; + void addStringListProperty(int index); + qdesigner_internal::PropertySheetStringListValue stringListProperty(int index) const; + void setStringListProperty(int index, const qdesigner_internal::PropertySheetStringListValue &value); bool isKeySequenceProperty(int index) const; void addKeySequenceProperty(int index); @@ -244,6 +248,7 @@ public: QHash<QString, int> m_addIndex; QHash<int, QVariant> m_resourceProperties; // only PropertySheetPixmapValue snd PropertySheetIconValue here QHash<int, qdesigner_internal::PropertySheetStringValue> m_stringProperties; // only PropertySheetStringValue + QHash<int, qdesigner_internal::PropertySheetStringListValue> m_stringListProperties; // only PropertySheetStringListValue QHash<int, qdesigner_internal::PropertySheetKeySequenceValue> m_keySequenceProperties; // only PropertySheetKeySequenceValue const bool m_canHaveLayoutAttributes; @@ -347,6 +352,28 @@ void QDesignerPropertySheetPrivate::setStringProperty(int index, const qdesigner m_stringProperties[index] = value; } +bool QDesignerPropertySheetPrivate::isStringListProperty(int index) const +{ + return m_stringListProperties.contains(index); +} + +void QDesignerPropertySheetPrivate::addStringListProperty(int index) +{ + m_stringListProperties.insert(index, qdesigner_internal::PropertySheetStringListValue()); +} + +qdesigner_internal::PropertySheetStringListValue QDesignerPropertySheetPrivate::stringListProperty(int index) const +{ + return m_stringListProperties.value(index); +} + +void QDesignerPropertySheetPrivate::setStringListProperty(int index, const qdesigner_internal::PropertySheetStringListValue &value) +{ + Q_ASSERT(isStringListProperty(index)); + + m_stringListProperties[index] = value; +} + bool QDesignerPropertySheetPrivate::isKeySequenceProperty(int index) const { return m_keySequenceProperties.contains(index); @@ -591,14 +618,26 @@ QDesignerPropertySheet::QDesignerPropertySheet(QObject *object, QObject *parent) info.group = pgroup; info.propertyType = propertyTypeFromName(name); - if (p->type() == QVariant::Cursor || p->type() == QVariant::Icon || p->type() == QVariant::Pixmap) { + const QVariant::Type type = p->type(); + switch (type) { + case QVariant::Cursor: + case QVariant::Icon: + case QVariant::Pixmap: info.defaultValue = p->read(d->m_object); - if (p->type() == QVariant::Icon || p->type() == QVariant::Pixmap) - d->addResourceProperty(index, p->type()); - } else if (p->type() == QVariant::String) { + if (type == QVariant::Icon || type == QVariant::Pixmap) + d->addResourceProperty(index, type); + break; + case QVariant::String: d->addStringProperty(index); - } else if (p->type() == QVariant::KeySequence) { + break; + case QVariant::StringList: + d->addStringListProperty(index); + break; + case QVariant::KeySequence: d->addKeySequenceProperty(index); + break; + default: + break; } } @@ -724,6 +763,8 @@ int QDesignerPropertySheet::addDynamicProperty(const QString &propName, const QV v = QVariant::fromValue(qdesigner_internal::PropertySheetPixmapValue()); else if (value.type() == QVariant::String) v = QVariant::fromValue(qdesigner_internal::PropertySheetStringValue(value.toString())); + else if (value.type() == QVariant::StringList) + v = QVariant::fromValue(qdesigner_internal::PropertySheetStringListValue(value.toStringList())); else if (value.type() == QVariant::KeySequence) { const QKeySequence keySequence = qvariant_cast<QKeySequence>(value); v = QVariant::fromValue(qdesigner_internal::PropertySheetKeySequenceValue(keySequence)); @@ -757,12 +798,23 @@ int QDesignerPropertySheet::addDynamicProperty(const QString &propName, const QV info.defaultValue = value; info.kind = QDesignerPropertySheetPrivate::DynamicProperty; setPropertyGroup(index, tr("Dynamic Properties")); - if (value.type() == QVariant::Icon || value.type() == QVariant::Pixmap) + switch (value.type()) { + case QVariant::Icon: + case QVariant::Pixmap: d->addResourceProperty(index, value.type()); - else if (value.type() == QVariant::String) + break; + case QVariant::String: d->addStringProperty(index); - else if (value.type() == QVariant::KeySequence) + break; + case QVariant::StringList: + d->addStringListProperty(index); + break; + case QVariant::KeySequence: d->addKeySequenceProperty(index); + break; + default: + break; + } return index; } @@ -871,6 +923,8 @@ int QDesignerPropertySheet::createFakeProperty(const QString &propertyName, cons QVariant v = value.isValid() ? value : metaProperty(index); if (v.type() == QVariant::String) v = QVariant::fromValue(qdesigner_internal::PropertySheetStringValue()); + if (v.type() == QVariant::StringList) + v = QVariant::fromValue(qdesigner_internal::PropertySheetStringListValue()); if (v.type() == QVariant::KeySequence) v = QVariant::fromValue(qdesigner_internal::PropertySheetKeySequenceValue()); d->m_fakeProperties.insert(index, v); @@ -1002,6 +1056,16 @@ QVariant QDesignerPropertySheet::property(int index) const return QVariant::fromValue(value); } + if (d->isStringListProperty(index)) { + const QStringList listValue = metaProperty(index).toStringList(); + qdesigner_internal::PropertySheetStringListValue value = d->stringListProperty(index); + if (listValue != value.value()) { + value.setValue(listValue); + d->setStringListProperty(index, value); // cache it + } + return QVariant::fromValue(value); + } + if (d->isKeySequenceProperty(index)) { QKeySequence keyValue = qvariant_cast<QKeySequence>(metaProperty(index)); qdesigner_internal::PropertySheetKeySequenceValue value = d->keySequenceProperty(index); @@ -1049,6 +1113,9 @@ QVariant QDesignerPropertySheet::resolvePropertyValue(int index, const QVariant if (value.canConvert<qdesigner_internal::PropertySheetStringValue>()) return qvariant_cast<qdesigner_internal::PropertySheetStringValue>(value).value(); + if (value.canConvert<qdesigner_internal::PropertySheetStringListValue>()) + return qvariant_cast<qdesigner_internal::PropertySheetStringListValue>(value).value(); + if (value.canConvert<qdesigner_internal::PropertySheetKeySequenceValue>()) return qvariant_cast<qdesigner_internal::PropertySheetKeySequenceValue>(value).value(); @@ -1137,6 +1204,8 @@ void QDesignerPropertySheet::setProperty(int index, const QVariant &value) d->setResourceProperty(index, value); if (d->isStringProperty(index)) d->setStringProperty(index, qvariant_cast<qdesigner_internal::PropertySheetStringValue>(value)); + if (d->isStringListProperty(index)) + d->setStringListProperty(index, qvariant_cast<qdesigner_internal::PropertySheetStringListValue>(value)); if (d->isKeySequenceProperty(index)) d->setKeySequenceProperty(index, qvariant_cast<qdesigner_internal::PropertySheetKeySequenceValue>(value)); d->m_object->setProperty(propertyName(index).toUtf8(), resolvePropertyValue(index, value)); @@ -1153,6 +1222,8 @@ void QDesignerPropertySheet::setProperty(int index, const QVariant &value) d->setResourceProperty(index, value); if (d->isStringProperty(index)) d->setStringProperty(index, qvariant_cast<qdesigner_internal::PropertySheetStringValue>(value)); + if (d->isStringListProperty(index)) + d->setStringListProperty(index, qvariant_cast<qdesigner_internal::PropertySheetStringListValue>(value)); if (d->isKeySequenceProperty(index)) d->setKeySequenceProperty(index, qvariant_cast<qdesigner_internal::PropertySheetKeySequenceValue>(value)); const QDesignerMetaPropertyInterface *p = d->m_meta->property(index); @@ -1203,6 +1274,8 @@ bool QDesignerPropertySheet::reset(int index) setProperty(index, QVariant::fromValue(value)); return true; } + if (d->isStringListProperty(index)) + setProperty(index, QVariant::fromValue(qdesigner_internal::PropertySheetStringListValue())); if (d->isKeySequenceProperty(index)) setProperty(index, QVariant::fromValue(qdesigner_internal::PropertySheetKeySequenceValue())); if (d->isResourceProperty(index)) { @@ -1215,6 +1288,8 @@ bool QDesignerPropertySheet::reset(int index) QVariant newValue = defaultValue; if (d->isStringProperty(index)) { newValue = QVariant::fromValue(qdesigner_internal::PropertySheetStringValue(newValue.toString())); + } else if (d->isStringListProperty(index)) { + newValue = QVariant::fromValue(qdesigner_internal::PropertySheetStringListValue(newValue.toStringList())); } else if (d->isKeySequenceProperty(index)) { const QKeySequence keySequence = qvariant_cast<QKeySequence>(newValue); newValue = QVariant::fromValue(qdesigner_internal::PropertySheetKeySequenceValue(keySequence)); diff --git a/src/designer/src/lib/shared/qdesigner_utils.cpp b/src/designer/src/lib/shared/qdesigner_utils.cpp index 007c584da..59be22a82 100644 --- a/src/designer/src/lib/shared/qdesigner_utils.cpp +++ b/src/designer/src/lib/shared/qdesigner_utils.cpp @@ -498,6 +498,32 @@ namespace qdesigner_internal return m_value == rhs.m_value && PropertySheetTranslatableData::equals(rhs); } + PropertySheetStringListValue::PropertySheetStringListValue(const QStringList &value, + bool translatable, + const QString &disambiguation, + const QString &comment) : + PropertySheetTranslatableData(translatable, disambiguation, comment), m_value(value) + { + } + + QStringList PropertySheetStringListValue::value() const + { + return m_value; + } + + void PropertySheetStringListValue::setValue(const QStringList &value) + { + m_value = value; + } + + bool PropertySheetStringListValue::equals(const PropertySheetStringListValue &rhs) const + { + return m_value == rhs.m_value && PropertySheetTranslatableData::equals(rhs); + } + + QStringList m_value; + + PropertySheetKeySequenceValue::PropertySheetKeySequenceValue(const QKeySequence &value, bool translatable, const QString &disambiguation, const QString &comment) : PropertySheetTranslatableData(translatable, disambiguation, comment), diff --git a/src/designer/src/lib/shared/qdesigner_utils_p.h b/src/designer/src/lib/shared/qdesigner_utils_p.h index b902f63b5..6be5c7848 100644 --- a/src/designer/src/lib/shared/qdesigner_utils_p.h +++ b/src/designer/src/lib/shared/qdesigner_utils_p.h @@ -369,7 +369,26 @@ private: QString m_value; }; +// -------------- StringValue: Returned by the property sheet for string lists +class QDESIGNER_SHARED_EXPORT PropertySheetStringListValue : public PropertySheetTranslatableData +{ +public: + PropertySheetStringListValue(const QStringList &value = QStringList(), + bool translatable = true, + const QString &disambiguation = QString(), + const QString &comment = QString()); + + bool operator==(const PropertySheetStringListValue &other) const { return equals(other); } + bool operator!=(const PropertySheetStringListValue &other) const { return !equals(other); } + + QStringList value() const; + void setValue(const QStringList &value); +private: + bool equals(const PropertySheetStringListValue &rhs) const; + + QStringList m_value; +}; // -------------- StringValue: Returned by the property sheet for strings class QDESIGNER_SHARED_EXPORT PropertySheetKeySequenceValue : public PropertySheetTranslatableData @@ -411,6 +430,7 @@ Q_DECLARE_METATYPE(qdesigner_internal::PropertySheetFlagValue) Q_DECLARE_METATYPE(qdesigner_internal::PropertySheetPixmapValue) Q_DECLARE_METATYPE(qdesigner_internal::PropertySheetIconValue) Q_DECLARE_METATYPE(qdesigner_internal::PropertySheetStringValue) +Q_DECLARE_METATYPE(qdesigner_internal::PropertySheetStringListValue) Q_DECLARE_METATYPE(qdesigner_internal::PropertySheetKeySequenceValue) diff --git a/src/designer/src/lib/uilib/ui4.cpp b/src/designer/src/lib/uilib/ui4.cpp index e43f2a5eb..504f08f1d 100644 --- a/src/designer/src/lib/uilib/ui4.cpp +++ b/src/designer/src/lib/uilib/ui4.cpp @@ -6028,6 +6028,9 @@ void DomStringList::clear(bool clear_all) if (clear_all) { m_text.clear(); + m_has_attr_notr = false; + m_has_attr_comment = false; + m_has_attr_extraComment = false; } m_children = 0; @@ -6036,6 +6039,9 @@ void DomStringList::clear(bool clear_all) DomStringList::DomStringList() { m_children = 0; + m_has_attr_notr = false; + m_has_attr_comment = false; + m_has_attr_extraComment = false; } DomStringList::~DomStringList() @@ -6046,6 +6052,23 @@ DomStringList::~DomStringList() void DomStringList::read(QXmlStreamReader &reader) { + foreach (const QXmlStreamAttribute &attribute, reader.attributes()) { + QStringRef name = attribute.name(); + if (name == QStringLiteral("notr")) { + setAttributeNotr(attribute.value().toString()); + continue; + } + if (name == QStringLiteral("comment")) { + setAttributeComment(attribute.value().toString()); + continue; + } + if (name == QStringLiteral("extracomment")) { + setAttributeExtraComment(attribute.value().toString()); + continue; + } + reader.raiseError(QStringLiteral("Unexpected attribute ") + name.toString()); + } + for (bool finished = false; !finished && !reader.hasError();) { switch (reader.readNext()) { case QXmlStreamReader::StartElement : { @@ -6074,6 +6097,15 @@ void DomStringList::write(QXmlStreamWriter &writer, const QString &tagName) cons { writer.writeStartElement(tagName.isEmpty() ? QString::fromUtf8("stringlist") : tagName.toLower()); + if (hasAttributeNotr()) + writer.writeAttribute(QStringLiteral("notr"), attributeNotr()); + + if (hasAttributeComment()) + writer.writeAttribute(QStringLiteral("comment"), attributeComment()); + + if (hasAttributeExtraComment()) + writer.writeAttribute(QStringLiteral("extracomment"), attributeExtraComment()); + for (int i = 0; i < m_string.size(); ++i) { QString v = m_string[i]; writer.writeTextElement(QStringLiteral("string"), v); diff --git a/src/designer/src/lib/uilib/ui4_p.h b/src/designer/src/lib/uilib/ui4_p.h index ce8e9c147..019236a74 100644 --- a/src/designer/src/lib/uilib/ui4_p.h +++ b/src/designer/src/lib/uilib/ui4_p.h @@ -2593,6 +2593,21 @@ public: inline void setText(const QString &s) { m_text = s; } // attribute accessors + inline bool hasAttributeNotr() const { return m_has_attr_notr; } + inline QString attributeNotr() const { return m_attr_notr; } + inline void setAttributeNotr(const QString& a) { m_attr_notr = a; m_has_attr_notr = true; } + inline void clearAttributeNotr() { m_has_attr_notr = false; } + + inline bool hasAttributeComment() const { return m_has_attr_comment; } + inline QString attributeComment() const { return m_attr_comment; } + inline void setAttributeComment(const QString& a) { m_attr_comment = a; m_has_attr_comment = true; } + inline void clearAttributeComment() { m_has_attr_comment = false; } + + inline bool hasAttributeExtraComment() const { return m_has_attr_extraComment; } + inline QString attributeExtraComment() const { return m_attr_extraComment; } + inline void setAttributeExtraComment(const QString& a) { m_attr_extraComment = a; m_has_attr_extraComment = true; } + inline void clearAttributeExtraComment() { m_has_attr_extraComment = false; } + // child element accessors inline QStringList elementString() const { return m_string; } void setElementString(const QStringList& a); @@ -2602,6 +2617,15 @@ private: void clear(bool clear_all = true); // attribute data + QString m_attr_notr; + bool m_has_attr_notr; + + QString m_attr_comment; + bool m_has_attr_comment; + + QString m_attr_extraComment; + bool m_has_attr_extraComment; + // child element data uint m_children; QStringList m_string; |