QmlDesigner: Fix material manager

Task-number: QDS-1332
Change-Id: I70828c3ce584ab72115f92dda4a27341e00085e2
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Henning Gruendl
2019-12-11 14:45:40 +01:00
committed by Henning Gründl
parent 3094d5b3ae
commit 88bbd748dd
4 changed files with 18 additions and 7 deletions

View File

@@ -55,8 +55,6 @@ Rectangle {
border.color: StudioTheme.Values.themeControlOutline border.color: StudioTheme.Values.themeControlOutline
border.width: StudioTheme.Values.border border.width: StudioTheme.Values.border
property int numVisibleItems: myRepeater.count
Layout.preferredWidth: StudioTheme.Values.height * 10 Layout.preferredWidth: StudioTheme.Values.height * 10
Layout.preferredHeight: myColumn.height Layout.preferredHeight: myColumn.height
@@ -158,6 +156,13 @@ Rectangle {
} }
} }
Item {
id: dummyItem
visible: myRepeater.count === 0
width: StudioTheme.Values.height
height: StudioTheme.Values.height
}
Row { Row {
id: row id: row
spacing: -StudioTheme.Values.border spacing: -StudioTheme.Values.border
@@ -175,7 +180,7 @@ Rectangle {
StudioControls.AbstractButton { StudioControls.AbstractButton {
buttonIcon: "+" buttonIcon: "+"
iconFont: StudioTheme.Constants.font iconFont: StudioTheme.Constants.font
enabled: !myRepeater.dirty enabled: !myRepeater.dirty && !(editableListView.backendValue.isInModel && !editableListView.backendValue.isIdList)
onClicked: { onClicked: {
var idx = myRepeater.localModel.push("") - 1 var idx = myRepeater.localModel.push("") - 1
myRepeater.model = myRepeater.localModel // trigger on change handler myRepeater.model = myRepeater.localModel // trigger on change handler
@@ -187,7 +192,7 @@ Rectangle {
StudioControls.AbstractButton { StudioControls.AbstractButton {
buttonIcon: "-" buttonIcon: "-"
iconFont: StudioTheme.Constants.font iconFont: StudioTheme.Constants.font
enabled: myRepeater.model.length enabled: myRepeater.model.length && !(editableListView.backendValue.isInModel && !editableListView.backendValue.isIdList)
onClicked: { onClicked: {
var lastItem = myColumn.currentIndex === myRepeater.localModel.length - 1 var lastItem = myColumn.currentIndex === myRepeater.localModel.length - 1
if (myColumn.currentItem.initialModelData === "") { if (myColumn.currentItem.initialModelData === "") {

View File

@@ -375,7 +375,9 @@ QStringList PropertyEditorValue::getExpressionAsList() const
bool PropertyEditorValue::idListAdd(const QString &value) bool PropertyEditorValue::idListAdd(const QString &value)
{ {
QTC_ASSERT(isIdList(), return false); const QmlDesigner::QmlObjectNode objectNode(modelNode());
if (!isIdList() && (objectNode.isValid() && objectNode.hasProperty(name())))
return false;
static const QRegExp rx("^[a-z_]\\w*|^[A-Z]\\w*\\.{1}([a-z_]\\w*\\.?)+"); static const QRegExp rx("^[a-z_]\\w*|^[A-Z]\\w*\\.{1}([a-z_]\\w*\\.?)+");
if (!rx.exactMatch(value)) if (!rx.exactMatch(value))
@@ -393,7 +395,6 @@ bool PropertyEditorValue::idListRemove(int idx)
QTC_ASSERT(isIdList(), return false); QTC_ASSERT(isIdList(), return false);
auto stringList = generateStringList(expression()); auto stringList = generateStringList(expression());
if (idx < 0 || idx >= stringList.size()) if (idx < 0 || idx >= stringList.size())
return false; return false;
@@ -438,6 +439,8 @@ QString PropertyEditorValue::generateString(const QStringList &stringList) const
{ {
if (stringList.size() > 1) if (stringList.size() > 1)
return "[" + stringList.join(",") + "]"; return "[" + stringList.join(",") + "]";
else if (stringList.isEmpty())
return QString();
else else
return stringList.first(); return stringList.first();
} }

View File

@@ -83,6 +83,7 @@ class PropertyEditorValue : public QObject
Q_PROPERTY(bool isValid READ isValid NOTIFY isValidChanged FINAL) Q_PROPERTY(bool isValid READ isValid NOTIFY isValidChanged FINAL)
Q_PROPERTY(bool isTranslated READ isTranslated NOTIFY expressionChanged FINAL) Q_PROPERTY(bool isTranslated READ isTranslated NOTIFY expressionChanged FINAL)
Q_PROPERTY(bool isIdList READ isIdList NOTIFY expressionChanged FINAL)
Q_PROPERTY(QStringList expressionAsList READ getExpressionAsList NOTIFY expressionChanged FINAL) Q_PROPERTY(QStringList expressionAsList READ getExpressionAsList NOTIFY expressionChanged FINAL)
Q_PROPERTY(QString name READ nameAsQString FINAL) Q_PROPERTY(QString name READ nameAsQString FINAL)

View File

@@ -280,8 +280,10 @@ void PropertyEditorView::changeExpression(const QString &propertyName)
} }
} }
if (value->expression().isEmpty()) if (value->expression().isEmpty()) {
value->resetValue();
return; return;
}
if (qmlObjectNode.expression(name) != value->expression() || !qmlObjectNode.propertyAffectedByCurrentState(name)) if (qmlObjectNode.expression(name) != value->expression() || !qmlObjectNode.propertyAffectedByCurrentState(name))
qmlObjectNode.setBindingProperty(name, value->expression()); qmlObjectNode.setBindingProperty(name, value->expression());