From f43a48aee8a2e95f6781a5e496a70214a19eebe7 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Wed, 29 Jan 2020 14:09:37 +0100 Subject: [PATCH] QmlDesigner: Implement operations for FlowEditor Change-Id: I9bb1ee00981085e26b6b0a17aad94e1b30dc2f71 Reviewed-by: Tim Jenssen --- .../componentcore/modelnodeoperations.cpp | 83 +++++++++++++++++++ .../componentcore/modelnodeoperations.h | 3 + 2 files changed, 86 insertions(+) diff --git a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp index 098ce88d7ce..c0f53f4946a 100644 --- a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp +++ b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -1014,6 +1015,88 @@ bool addImageToProject(const QStringList &fileNames, const QString &defaultDirec return allSuccessful; } +void createFlowActionArea(const SelectionContext &selectionContext) +{ + AbstractView *view = selectionContext.view(); + + QTC_ASSERT(view && selectionContext.hasSingleSelectedModelNode(), return); + ModelNode container = selectionContext.currentSingleSelectedNode(); + QTC_ASSERT(container.isValid(), return); + QTC_ASSERT(container.metaInfo().isValid(), return); + + NodeMetaInfo actionAreaMetaInfo = view->model()->metaInfo("FlowView.FlowActionArea", -1, -1); + QTC_ASSERT(actionAreaMetaInfo.isValid(), return); + + const QPointF pos = selectionContext.scenePosition().isNull() ? QPointF() : selectionContext.scenePosition() - QmlItemNode(container).flowPosition(); + + view->executeInTransaction("DesignerActionManager:createFlowActionArea", + [view, container, actionAreaMetaInfo, pos](){ + + ModelNode flowActionNode = + view->createModelNode("FlowView.FlowActionArea", + actionAreaMetaInfo.majorVersion(), + actionAreaMetaInfo.minorVersion()); + + if (!pos.isNull()) { + flowActionNode.variantProperty("x").setValue(pos.x()); + flowActionNode.variantProperty("y").setValue(pos.y()); + } + + container.defaultNodeListProperty().reparentHere(flowActionNode); + view->setSelectedModelNode(flowActionNode); + }); + +} + +void addTransition(const SelectionContext &selectionContext) +{ + if (selectionContext.view()) { + AbstractView *view = selectionContext.view(); + QmlFlowItemNode targetItem = selectionContext.targetNode(); + QmlFlowActionAreaNode actionArea = selectionContext.currentSingleSelectedNode(); + + QTC_ASSERT(targetItem.isValid(), return); + QTC_ASSERT(actionArea.isValid(), return); + + + view->executeInTransaction("DesignerActionManager:addTransition", + [view, targetItem, &actionArea](){ + actionArea.assignTargetFlowItem(targetItem); + }); + } +} + +void addFlowEffect(const SelectionContext &selectionContext, const TypeName &typeName) +{ + AbstractView *view = selectionContext.view(); + + QTC_ASSERT(view && selectionContext.hasSingleSelectedModelNode(), return); + ModelNode container = selectionContext.currentSingleSelectedNode(); + QTC_ASSERT(container.isValid(), return); + QTC_ASSERT(container.metaInfo().isValid(), return); + QTC_ASSERT(QmlItemNode::isFlowTransition(container), return); + + NodeMetaInfo effectMetaInfo = view->model()->metaInfo("FlowView." + typeName, -1, -1); + QTC_ASSERT(typeName == "None" || effectMetaInfo.isValid(), return); + + view->executeInTransaction("DesignerActionManager:addFlowEffect", + [view, container, effectMetaInfo](){ + + if (container.hasProperty("effect")) + container.removeProperty("effect"); + + if (effectMetaInfo.isValid()) { + ModelNode effectNode = + view->createModelNode(effectMetaInfo.typeName(), + effectMetaInfo.majorVersion(), + effectMetaInfo.minorVersion()); + + container.nodeProperty("effect").reparentHere(effectNode); + view->setSelectedModelNode(effectNode); + } + }); +} + } // namespace Mode } //QmlDesigner diff --git a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h index 52dfaf6f1d7..994110297e0 100644 --- a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h +++ b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h @@ -74,6 +74,9 @@ void decreaseIndexOfStackedContainer(const SelectionContext &selectionContext); void addTabBarToStackedContainer(const SelectionContext &selectionContext); bool addImageToProject(const QStringList &fileNames, const QString &directory); bool addFontToProject(const QStringList &fileNames, const QString &directory); +void createFlowActionArea(const SelectionContext &selectionContext); +void addTransition(const SelectionContext &selectionState); +void addFlowEffect(const SelectionContext &selectionState, const TypeName &typeName); } // namespace ModelNodeOperationso } //QmlDesigner