From f08651024b3e0fc118f7007349555d928328ff14 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Tue, 10 Dec 2013 14:52:17 +0100 Subject: [PATCH] QmlDesigner.PropertyEditor: Fixing expressions and tr checkbox The handling of expressions in states was broken in conjunction with states. This patch fixes a couple of related issues: * The notifier of isTranslated (PropertyEditorValue) has to be expressionChanged, since this property depends on the expression. * isTranslated() has to return also true if there is only an expression in the base state. If the string is translated in the base state it should be translated in other states, too. * In states the expression set in createPropertyEditorValue() has to be the expression of the current stateif there is one. We can not just fall back to instanceValue. * I did a couple of fixes in LineEdit.qml. We cannot bind checked directly, since the binding will be deleted when checked is changed by the control. I removed all code regarding transactions. We react to onEditingFinished, so it is not required. The translated state is properly preserved now, when setting the value. Task-number: QTCREATORBUG-10674 Task-number: QTCREATORBUG-10791 Change-Id: I95721711a37e63c4c7c38e275089d6de0bb92bec Reviewed-by: Marco Bubke --- .../HelperWidgets/LineEdit.qml | 48 ++++++++++++------- .../propertyeditorqmlbackend.cpp | 6 ++- .../propertyeditor/propertyeditorvalue.cpp | 13 +++-- .../propertyeditor/propertyeditorvalue.h | 2 +- 4 files changed, 46 insertions(+), 23 deletions(-) diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/HelperWidgets/LineEdit.qml b/share/qtcreator/qmldesigner/propertyEditorQmlSources/HelperWidgets/LineEdit.qml index cc7fdca50d8..ee947a82496 100644 --- a/share/qtcreator/qmldesigner/propertyEditorQmlSources/HelperWidgets/LineEdit.qml +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/HelperWidgets/LineEdit.qml @@ -35,9 +35,9 @@ import QtQuick.Controls.Styles 1.0 Controls.TextField { Controls.Action { - //Workaround to avoid that "Delete" deletes the item. - shortcut: "Delete" - } + //Workaround to avoid that "Delete" deletes the item. + shortcut: "Delete" + } id: lineEdit property variant backendValue @@ -62,20 +62,23 @@ Controls.TextField { } } - onEditingFinished: { - if (backendValue.value !== text) - backendValue.value = text; - } - - - onFocusChanged: { - if (focus) { - transaction.start(); + onEditingFinished: { + if (backendValue.isTranslated) { + backendValue.expression = "qsTr(\"" + trCheckbox.escapeString(text) + "\")" } else { - transaction.end(); + if (lineEdit.backendValue.value !== text) + lineEdit.backendValue.value = text; } } + // onFocusChanged: { + // if (focus) { + // transaction.start(); + // } else { + // transaction.end(); + // } + // } + style: TextFieldStyle { selectionColor: lineEdit.textColor selectedTextColor: "black" @@ -112,12 +115,24 @@ Controls.TextField { anchors.verticalCenter: parent.verticalCenter id: trCheckbox - checked: backendValue.isTranslated + + property bool isTranslated: colorLogic.backendValue.isTranslated + property bool backendValueValue: colorLogic.backendValue.value + + onIsTranslatedChanged: { + checked = lineEdit.backendValue.isTranslated + } + + onBackendValueValueChanged: { + checked = lineEdit.backendValue.isTranslated + } + onClicked: { if (trCheckbox.checked) { - backendValue.expression = "qsTr(\"" + escapeString(lineEdit.text) + "\")" + lineEdit.backendValue.expression = "qsTr(\"" + escapeString(lineEdit.text) + "\")" } else { - backendValue.value = lineEdit.text + var textValue = lineEdit.text + lineEdit.backendValue.value = textValue } colorLogic.evaluate(); } @@ -137,7 +152,6 @@ Controls.TextField { style: CheckBoxStyle { spacing: 8 - label: Controls.Label { text: control.text ; color: checkBox.textColor } indicator: Item { implicitWidth: 16 implicitHeight: 16 diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp index 67376a966b9..13746204b30 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp @@ -179,7 +179,10 @@ void PropertyEditorQmlBackend::createPropertyEditorValue(const QmlObjectNode &qm qmlObjectNode.modelNode().property(propertyName).isBindingProperty()) { valueObject->setExpression(qmlObjectNode.modelNode().bindingProperty(propertyName).expression()); } else { - valueObject->setExpression(qmlObjectNode.instanceValue(name).toString()); + if (qmlObjectNode.hasBindingProperty(propertyName)) + valueObject->setExpression(qmlObjectNode.expression(name)); + else + valueObject->setExpression(qmlObjectNode.instanceValue(name).toString()); } } @@ -190,6 +193,7 @@ void PropertyEditorQmlBackend::setValue(const QmlObjectNode & qmlObjectNode, con PropertyEditorValue *propertyValue = qobject_cast(variantToQObject(m_backendValuesPropertyMap.value(propertyName))); if (propertyValue) { propertyValue->setValue(value); + if (!qmlObjectNode.hasBindingProperty(name)) propertyValue->setExpression(value.toString()); else diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp index 528f8ea71ec..afa42fda079 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp @@ -34,6 +34,7 @@ #include #include #include +#include //using namespace QmlDesigner; @@ -155,7 +156,6 @@ void PropertyEditorValue::setValue(const QVariant &value) QString PropertyEditorValue::expression() const { - return m_expression; } @@ -220,17 +220,22 @@ void PropertyEditorValue::setIsValid(bool valid) bool PropertyEditorValue::isTranslated() const { - if (modelNode().isValid() && modelNode().metaInfo().isValid() && modelNode().metaInfo().hasProperty(name())) + if (modelNode().isValid() && modelNode().metaInfo().isValid() && modelNode().metaInfo().hasProperty(name())) { if (modelNode().metaInfo().propertyTypeName(name()) == "QString" || modelNode().metaInfo().propertyTypeName(name()) == "string") { const QmlDesigner::QmlObjectNode objectNode(modelNode()); if (objectNode.isValid() && objectNode.hasBindingProperty(name())) { - //qsTr() QRegExp rx("qsTr(\"*\")"); + //qsTr() rx.setPatternSyntax(QRegExp::Wildcard); - return rx.exactMatch(expression()); + if (objectNode.propertyAffectedByCurrentState(name())) { + return rx.exactMatch(expression()); + } else { + return rx.exactMatch(modelNode().bindingProperty(name()).expression()); + } } return false; } + } return false; } diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.h b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.h index 17c51944ca3..ee48d23001d 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.h +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.h @@ -84,7 +84,7 @@ class PropertyEditorValue : public QObject Q_PROPERTY(bool isInSubState READ isInSubState NOTIFY valueChangedQml FINAL) Q_PROPERTY(bool isBound READ isBound NOTIFY isBoundChanged FINAL) Q_PROPERTY(bool isValid READ isValid NOTIFY isValidChanged FINAL) - Q_PROPERTY(bool isTranslated READ isTranslated NOTIFY valueChangedQml FINAL) + Q_PROPERTY(bool isTranslated READ isTranslated NOTIFY expressionChanged FINAL) Q_PROPERTY(QString name READ name FINAL) Q_PROPERTY(PropertyEditorNodeWrapper* complexNode READ complexNode NOTIFY complexNodeChanged FINAL)