KDStateMachineEditor API Documentation 2.1
Loading...
Searching...
No Matches
modifytransitioncommand.cpp
Go to the documentation of this file.
1/*
2 This file is part of the KDAB State Machine Editor Library.
3
4 SPDX-FileCopyrightText: 2014 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
5 Author: Kevin Funk <kevin.funk@kdab.com>
6
7 SPDX-License-Identifier: LGPL-2.1-only OR LicenseRef-KDAB-KDStateMachineEditor
8
9 Licensees holding valid commercial KDAB State Machine Editor Library
10 licenses may use this file in accordance with the KDAB State Machine Editor
11 Library License Agreement provided with the Software.
12
13 Contact info@kdab.com if any conditions of this licensing are not clear to you.
14*/
15
17
18#include "elementmodel.h"
19#include "state.h"
20#include "transition.h"
21
22using namespace KDSME;
23
25 : Command(model, parent)
26 , m_transition(transition)
27 , m_operation(NoOperation)
28{
29}
30
32{
33 if (!m_transition)
34 return;
35
36 switch (m_operation) {
37 case SetSourceStateOperation: {
38 m_oldSourceState = m_transition->sourceState();
39 const ObjectTreeModel::ReparentOperation reparentOperation(model(), m_transition, m_sourceState);
40 m_transition->setSourceState(m_sourceState);
41 } break;
42 case SetTargetStateOperation:
43 m_oldTargetState = m_transition->targetState();
44 m_transition->setTargetState(m_targetState);
45 break;
46 case SetShapeOperation:
47 m_oldShape = m_transition->shape();
48 m_transition->setShape(m_shape);
49 break;
50 case NoOperation:
51 break;
52 }
53}
54
56{
57 if (!m_transition)
58 return;
59
60 switch (m_operation) {
61 case SetSourceStateOperation: {
62 const ObjectTreeModel::ReparentOperation reparentOperation(model(), m_transition, m_oldSourceState);
63 m_transition->setSourceState(m_oldSourceState);
64 } break;
65 case SetTargetStateOperation:
66 m_transition->setTargetState(m_oldTargetState);
67 break;
68 case SetShapeOperation:
69 m_transition->setShape(m_oldShape);
70 break;
71 case NoOperation:
72 break;
73 }
74}
75
76bool ModifyTransitionCommand::mergeWith(const QUndoCommand *other)
77{
78 if (other->id() != id()) {
79 return false;
80 }
81
82 auto cmd = static_cast<const ModifyTransitionCommand *>(other);
83 if (cmd->m_transition != m_transition || cmd->m_operation != m_operation) {
84 return false;
85 }
86
87 m_sourceState = cmd->m_sourceState;
88 m_targetState = cmd->m_targetState;
89 m_shape = cmd->m_shape;
90 return true;
91}
92
94{
95 m_sourceState = sourceState;
96 m_operation = SetSourceStateOperation;
97 updateText();
98}
99
101{
102 m_targetState = targetState; // NOLINT(clang-analyzer-cplusplus.NewDelete)
103 m_operation = SetTargetStateOperation;
104 updateText();
105}
106
107void ModifyTransitionCommand::setShape(const QPainterPath &shape)
108{
109 m_shape = shape;
110 m_operation = SetShapeOperation;
111 updateText();
112}
113
114void ModifyTransitionCommand::updateText()
115{
116 const QString label = m_transition ? m_transition->label() : tr("<Unknown>");
117
118 switch (m_operation) {
119 case SetSourceStateOperation:
120 setText(tr("Set source state of '%1'").arg(label));
121 break;
122 case SetTargetStateOperation:
123 setText(tr("Set target state of '%1'").arg(label));
124 break;
125 case SetShapeOperation:
126 setText(tr("Modify path of '%1'").arg(label));
127 break;
128 case NoOperation:
129 break;
130 }
131}
StateModel * model() const
Definition command.cpp:34
Command for modifying properties of a KDSME::Transition.
bool mergeWith(const QUndoCommand *other) override
Q_INVOKABLE void setTargetState(KDSME::State *targetState)
ModifyTransitionCommand(Transition *transition, StateModel *model, QUndoCommand *parent=nullptr)
Q_INVOKABLE void setSourceState(KDSME::State *sourceState)
Q_INVOKABLE void setShape(const QPainterPath &shape)

© Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
KDStateMachineEditor
Create Qt State Machine metacode using a graphical user interface
https://github.com/KDAB/KDStateMachineEditor
Generated on Tue Jul 15 2025 15:21:47 for KDStateMachineEditor API Documentation by doxygen 1.9.8