summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Hartmann <thomas.hartmann@qt.io>2020-04-16 18:17:28 +0200
committerThomas Hartmann <thomas.hartmann@qt.io>2020-04-24 11:26:21 +0000
commit8c50ceb294dbdfd7a50e81d3d7d6277b414c16b7 (patch)
treee284bfee395a691b46dc0d06b634c61a77aa4a19
parent49cfa2d05029777ebc32dad6375fc2000e631a47 (diff)
downloadqt-creator-8c50ceb294dbdfd7a50e81d3d7d6277b414c16b7.tar.gz
QmlDesigner: Add setStartFlowItem
Change-Id: I6ad377bcca4e1db84a802909c1b5d8b9ccfe5a14 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
-rw-r--r--src/plugins/qmldesigner/designercore/include/qmlitemnode.h5
-rw-r--r--src/plugins/qmldesigner/designercore/model/qmlitemnode.cpp56
2 files changed, 49 insertions, 12 deletions
diff --git a/src/plugins/qmldesigner/designercore/include/qmlitemnode.h b/src/plugins/qmldesigner/designercore/include/qmlitemnode.h
index ef8f1b28ba..d779cc15bf 100644
--- a/src/plugins/qmldesigner/designercore/include/qmlitemnode.h
+++ b/src/plugins/qmldesigner/designercore/include/qmlitemnode.h
@@ -182,8 +182,13 @@ public:
const QList<ModelNode> wildcards() const;
const QList<ModelNode> decicions() const;
QList<ModelNode> transitionsForTarget(const ModelNode &modelNode);
+ QList<ModelNode> transitionsForSource(const ModelNode &modelNode);
void removeDanglingTransitions();
void removeAllTransitions();
+ void setStartFlowItem(const QmlFlowItemNode &flowItem);
+ ModelNode createTransition();
+protected:
+ QList<ModelNode> transitionsForProperty(const PropertyName &propertyName, const ModelNode &modelNode);
};
diff --git a/src/plugins/qmldesigner/designercore/model/qmlitemnode.cpp b/src/plugins/qmldesigner/designercore/model/qmlitemnode.cpp
index 098f8317a5..e2f0602cc2 100644
--- a/src/plugins/qmldesigner/designercore/model/qmlitemnode.cpp
+++ b/src/plugins/qmldesigner/designercore/model/qmlitemnode.cpp
@@ -664,9 +664,7 @@ QList<QmlFlowItemNode> QmlFlowViewNode::flowItems() const
ModelNode QmlFlowViewNode::addTransition(const QmlFlowTargetNode &from, const QmlFlowTargetNode &to)
{
- ModelNode transition = view()->createModelNode("FlowView.FlowTransition", 1, 0);
-
- nodeListProperty("flowTransitions").reparentHere(transition);
+ ModelNode transition = createTransition();
QmlFlowTargetNode f = from;
QmlFlowTargetNode t = to;
@@ -684,8 +682,6 @@ const QList<ModelNode> QmlFlowViewNode::transitions() const
return modelNode().nodeListProperty("flowTransitions").toModelNodeList();
return {};
-
-
}
const QList<ModelNode> QmlFlowViewNode::wildcards() const
@@ -706,13 +702,12 @@ const QList<ModelNode> QmlFlowViewNode::decicions() const
QList<ModelNode> QmlFlowViewNode::transitionsForTarget(const ModelNode &modelNode)
{
- QList<ModelNode> list;
- for (const ModelNode &transition : transitions()) {
- if (transition.hasBindingProperty("to")
- && transition.bindingProperty("to").resolveToModelNode() == modelNode)
- list.append(transition);
- }
- return list;
+ return transitionsForProperty("to", modelNode);
+}
+
+QList<ModelNode> QmlFlowViewNode::transitionsForSource(const ModelNode &modelNode)
+{
+ return transitionsForProperty("from", modelNode);
}
void QmlFlowViewNode::removeDanglingTransitions()
@@ -830,4 +825,41 @@ void QmlFlowViewNode::removeAllTransitions()
removeProperty("flowTransitions");
}
+void QmlFlowViewNode::setStartFlowItem(const QmlFlowItemNode &flowItem)
+{
+ QTC_ASSERT(flowItem.isValid(), return);
+ QmlFlowItemNode item = flowItem;
+
+ ModelNode transition;
+
+ for (const ModelNode &node : transitionsForSource(modelNode()))
+ transition = node;
+ if (!transition.isValid())
+ transition = createTransition();
+
+ transition.bindingProperty("from").setExpression(modelNode().validId());
+ transition.bindingProperty("to").setExpression(item.validId());
+}
+
+ModelNode QmlFlowViewNode::createTransition()
+{
+ ModelNode transition = view()->createModelNode("FlowView.FlowTransition", 1, 0);
+ nodeListProperty("flowTransitions").reparentHere(transition);
+
+ return transition;
+}
+
+QList<ModelNode> QmlFlowViewNode::transitionsForProperty(const PropertyName &propertyName,
+ const ModelNode &modelNode)
+{
+ QList<ModelNode> list;
+ for (const ModelNode &transition : transitions()) {
+ if (transition.hasBindingProperty(propertyName)
+ && transition.bindingProperty(propertyName).resolveToModelNode() == modelNode)
+ list.append(transition);
+ }
+ return list;
+
+}
+
} //QmlDesigner