QmlDesigner: Fix cloning of extended states

* When cloning an extended state add the new state after the extended
  group
* When cloning a state that extends another one also copy the extends
  property
* Fix two "call to a temporary is a no-op" clang warnings

Task-number: QDS-8412
Change-Id: I1e8595ddc69f210a27c04fc91869df3beb4ba980
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Henning Gruendl
2022-11-24 12:33:45 +01:00
committed by Henning Gründl
parent fd1864d678
commit dd2c4cc6ea
2 changed files with 30 additions and 6 deletions

View File

@@ -229,6 +229,16 @@ void StatesEditorView::cloneState(int nodeId)
int from = newNode.parentProperty().indexOf(newNode);
int to = stateNode.parentProperty().indexOf(stateNode) + 1;
// When duplicating an extended state the new state needs to be added after the extend group.
if (!modelState.hasExtend()) {
auto modelNodeList = activeStatesGroupNode().nodeListProperty("states").toModelNodeList();
for (; to != modelNodeList.count(); ++to) {
QmlModelState currentState(modelNodeList.at(to));
if (!currentState.isValid() || currentState.isBaseState() || !currentState.hasExtend())
break;
}
}
executeInTransaction("moveState", [this, &newState, from, to]() {
activeStatesGroupNode().nodeListProperty("states").slide(from, to);
setCurrentState(newState);

View File

@@ -254,17 +254,31 @@ QmlModelState QmlModelState::duplicate(const QString &name) const
if (!isValid())
return {};
// QmlModelState newState(stateGroup().addState(name));
QmlModelState newState(createQmlState(view(), {{PropertyName("name"), QVariant(name)}}));
if (hasExtend())
newState.setExtend(extend());
const QList<ModelNode> nodes = modelNode().nodeListProperty("changes").toModelNodeList();
for (const ModelNode &childNode : nodes) {
ModelNode newModelNode(view()->createModelNode(childNode.type(), childNode.majorVersion(), childNode.minorVersion()));
ModelNode newModelNode(view()->createModelNode(childNode.type(),
childNode.majorVersion(),
childNode.minorVersion()));
for (const BindingProperty &bindingProperty : childNode.bindingProperties()) {
auto property = newModelNode.bindingProperty(bindingProperty.name());
property.setExpression(bindingProperty.expression());
}
const QList<BindingProperty> bindingProperties = childNode.bindingProperties();
for (const BindingProperty &bindingProperty : bindingProperties)
newModelNode.bindingProperty(bindingProperty.name()).setExpression(bindingProperty.expression());
const QList<VariantProperty> variantProperties = childNode.variantProperties();
for (const VariantProperty &variantProperty : variantProperties)
newModelNode.variantProperty(variantProperty.name()).setValue(variantProperty.value());
newModelNode.bindingProperty(bindingProperty.name())
.setExpression(bindingProperty.expression());
for (const VariantProperty &variantProperty : childNode.variantProperties()) {
auto property = newModelNode.variantProperty(variantProperty.name());
property.setValue(variantProperty.value());
}
newState.modelNode().nodeListProperty("changes").reparentHere(newModelNode);
}