Commit f0865102 authored by Thomas Hartmann's avatar Thomas Hartmann

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: default avatarMarco Bubke <marco.bubke@digia.com>
parent c283ecaf
......@@ -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
......
......@@ -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<PropertyEditorValue*>(variantToQObject(m_backendValuesPropertyMap.value(propertyName)));
if (propertyValue) {
propertyValue->setValue(value);
if (!qmlObjectNode.hasBindingProperty(name))
propertyValue->setExpression(value.toString());
else
......
......@@ -34,6 +34,7 @@
#include <nodeproperty.h>
#include <nodemetainfo.h>
#include <qmlobjectnode.h>
#include <bindingproperty.h>
//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;
}
......
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment