Maki
Formally verified low-code orchestration
Loading...
Searching...
No Matches
document_cloner.h
1#pragma once
2
3#include <QHash>
4#include <QPointF>
5#include <QString>
6#include <QVector>
7#include <memory>
8#include <optional>
9
10#include "node_info.h"
11
12class FlowSaveInfo;
14class IParameter;
15
16class DocumentCloner final
17{
18public:
19 // Produces a detached, fully cloned node subtree.
20 // Does not modify SaveInfo or publish events.
21 static NodeSaveInfo cloneNodeForPaste(const NodeSaveInfo& original, const QString& newParentId, const QPointF& position);
22
23private:
24 DocumentCloner() = default;
25
26 // Pass 1: assign IDs to all objects before cloning references.
27 void indexNode(const NodeSaveInfo& node);
28 void indexFlow(const FlowSaveInfo& flow);
29
30 // Pass 2: clone the objects and remap their references.
31 std::shared_ptr<NodeSaveInfo> cloneNode(const NodeSaveInfo& original, const std::optional<QString>& parentOverride, const QPointF& positionOffset);
32
33 std::shared_ptr<FlowSaveInfo> cloneFlow(const FlowSaveInfo& original, const QString& newOwnerId);
34
35 std::shared_ptr<TransitionSaveInfo> cloneTransition(const TransitionSaveInfo& original, const QPointF& positionOffset);
36
37 static QVector<std::shared_ptr<IParameter>> cloneParameters(const QVector<std::shared_ptr<IParameter>>& parameters);
38
39 QString mappedNodeId(const QString& originalId) const;
40
41 // Maps are shared by the entire clone operation.
42 QHash<QString, QString> mNodeIds;
43 QHash<QString, QString> mFlowIds;
44
45 // Preserve shared identity if a node/flow is referenced
46 // more than once inside the source graph.
47 QHash<QString, std::shared_ptr<NodeSaveInfo>> mClonedNodes;
48 QHash<QString, std::shared_ptr<FlowSaveInfo>> mClonedFlows;
49};
Represents the save information for a flow.
Definition flow_info.h:15
Represents a node that can be saved and loaded.
Definition node_info.h:16
Represents transition save information.
Definition transition_info.h:14