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)