KDStateMachineEditor API Documentation
2.1
Loading...
Searching...
No Matches
src
view
command
reparentelementcommand.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
16
#include "
reparentelementcommand_p.h
"
17
18
#include "
element.h
"
19
#include "
elementmodel.h
"
20
#include "
statemachinescene.h
"
21
22
#include "debug.h"
23
24
using namespace
KDSME
;
25
26
ReparentElementCommand::ReparentElementCommand
(
StateMachineScene
*view,
Element
*element, QUndoCommand *parent)
27
:
Command
(tr(
"Set parent of '%1'"
).arg(element->label()), parent)
28
, m_view(view)
29
, m_element(element)
30
, m_valid(true)
31
{
32
Q_ASSERT(view);
33
Q_ASSERT(element);
34
}
35
36
void
ReparentElementCommand::setParentElement
(
Element
*parentElement)
37
{
38
m_newParentElement = parentElement;
// NOLINT(clang-analyzer-cplusplus.NewDelete)
39
}
40
41
void
ReparentElementCommand::redo
()
42
{
43
if
(!m_element)
44
return
;
45
46
m_valid = m_element->parentElement();
47
if
(!m_valid) {
48
qCDebug(KDSME_VIEW) <<
"No Element* as parent, not reparenting this item"
;
49
return
;
50
}
51
52
m_oldParentElement = m_element->parentElement();
53
54
const
ObjectTreeModel::ReparentOperation
reparentOperation(m_view->stateModel(), m_element, m_newParentElement);
55
m_element->setParent(m_newParentElement);
56
}
57
58
void
ReparentElementCommand::undo
()
59
{
60
if
(!m_element)
61
return
;
62
63
if
(!m_valid)
64
return
;
65
66
const
ObjectTreeModel::ReparentOperation
reparentOperation(m_view->stateModel(), m_element, m_oldParentElement);
67
m_element->setParent(m_oldParentElement);
68
}
KDSME::Command
Definition
command_p.h:27
KDSME::Element
Definition
element.h:35
KDSME::ObjectTreeModel::ReparentOperation
Definition
objecttreemodel.h:63
KDSME::ReparentElementCommand::setParentElement
Q_INVOKABLE void setParentElement(KDSME::Element *parentElement)
Definition
reparentelementcommand.cpp:36
KDSME::ReparentElementCommand::undo
void undo() override
Definition
reparentelementcommand.cpp:58
KDSME::ReparentElementCommand::ReparentElementCommand
ReparentElementCommand(StateMachineScene *view, Element *element, QUndoCommand *parent=nullptr)
Definition
reparentelementcommand.cpp:26
KDSME::ReparentElementCommand::redo
void redo() override
Definition
reparentelementcommand.cpp:41
KDSME::StateMachineScene
Definition
statemachinescene.h:35
element.h
elementmodel.h
KDSME
Definition
mainwindow.h:21
reparentelementcommand_p.h
statemachinescene.h
© 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