Line data Source code
1 : /**
2 : * @file
3 : *
4 : * @brief
5 : *
6 : * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
7 : */
8 :
9 : #include "cutkeycommand.hpp"
10 :
11 0 : CutKeyCommand::CutKeyCommand (QString type, ConfigNodePtr source, ConfigNodePtr target, int sourceIndex, QUndoCommand * parent)
12 0 : : QUndoCommand (parent), m_sourceParentModel (source->getParentModel ()), m_source (new ConfigNode (*source)), m_target (target),
13 0 : m_isExpanded (target->isExpanded ()), m_sourceIndex (sourceIndex), m_targetIndex (-1)
14 : {
15 0 : setText (type);
16 :
17 0 : QString newPath = m_target->getPath () + "/" + m_source->getName ();
18 0 : m_source->setPath (newPath);
19 0 : }
20 :
21 0 : void CutKeyCommand::undo ()
22 : {
23 0 : m_isExpanded = m_target->isExpanded ();
24 0 : m_sourceParentModel->insertRow (m_sourceIndex, m_source);
25 0 : m_target->getChildren ()->removeRow (m_targetIndex);
26 :
27 0 : if (m_sourceParentModel == m_target->getChildren ())
28 : {
29 0 : m_sourceParentModel->refresh ();
30 : }
31 0 : }
32 :
33 0 : void CutKeyCommand::redo ()
34 : {
35 0 : m_target->setIsExpanded (m_isExpanded);
36 0 : m_target->appendChild (m_source);
37 0 : m_sourceParentModel->removeRow (m_sourceIndex);
38 :
39 0 : if (m_sourceParentModel == m_target->getChildren ())
40 : {
41 0 : m_targetIndex = m_target->getChildCount ();
42 0 : m_sourceParentModel->refresh ();
43 : }
44 : else
45 0 : m_targetIndex = m_target->getChildCount () - 1;
46 0 : }
|