labplot  2.8.2
About: LabPlot is an application for plotting and analysis of 2D and 3D functions and data. It is a complete rewrite of LabPlot1 and lacks in the first release a lot of features available in the predecessor. On the other hand, the GUI and the usability is more superior.
  Fossies Dox: labplot-2.8.2.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

aspectcommands.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : aspectcommands.h
3  Project : LabPlot
4  --------------------------------------------------------------------
5  Copyright : (C) 2007-2010 by Knut Franke (knut.franke@gmx.de)
6  Copyright : (C) 2007-2009 Tilman Benkert(thzs@gmx.net)
7  Copyright : (C) 2013-2017 by Alexander Semke (alexander.semke@web.de)
8  Description : Undo commands used by AbstractAspect.
9  Only meant to be used within AbstractAspect.cpp
10 
11  ***************************************************************************/
12 
13 /***************************************************************************
14  * *
15  * This program is free software; you can redistribute it and/or modify *
16  * it under the terms of the GNU General Public License as published by *
17  * the Free Software Foundation; either version 2 of the License, or *
18  * (at your option) any later version. *
19  * *
20  * This program is distributed in the hope that it will be useful, *
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
23  * GNU General Public License for more details. *
24  * *
25  * You should have received a copy of the GNU General Public License *
26  * along with this program; if not, write to the Free Software *
27  * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
28  * Boston, MA 02110-1301 USA *
29  * *
30  ***************************************************************************/
31 #ifndef ASPECTCOMMANDS_H
32 #define ASPECTCOMMANDS_H
33 
34 #include "AspectPrivate.h"
35 #include <QUndoCommand>
36 #include <KLocalizedString>
37 
38 class AspectChildRemoveCmd : public QUndoCommand {
39 public:
41  : m_target(target), m_child(child), m_index(-1) {
42  setText(i18n("%1: remove %2", m_target->m_name, m_child->name()));
43  }
44 
45  ~AspectChildRemoveCmd() override {
46  //TODO: this makes labplot crashing on project close/save.
47 // if (m_removed)
48 // delete m_child;
49  }
50 
51  // calling redo transfers ownership of m_child to the undo command
52  void redo() override {
53  AbstractAspect* nextSibling;
54  if (m_child == m_target->m_children.last())
55  nextSibling = nullptr;
56  else
57  nextSibling = m_target->m_children.at(m_target->indexOfChild(m_child) + 1);
58 
60 
61  //emit the "about to be removed" signal also for all children of the aspect being currently removed
64 
66  emit m_target->q->aspectRemoved(m_target->q, nextSibling, m_child);
67 // m_removed = true;
68  }
69 
70  // calling undo transfers ownership of m_child back to its parent aspect
71  void undo() override {
72  Q_ASSERT(m_index != -1); // m_child must be a child of m_target->q
73 
74  emit m_target->q->aspectAboutToBeAdded(m_target->q, nullptr, m_child);
76  emit m_target->q->aspectAdded(m_child);
77 // m_removed = false;
78  }
79 
80 protected:
83  int m_index;
84 // bool m_removed{false};
85 };
86 
88 public:
90  : AspectChildRemoveCmd(target, child) {
91  setText(i18n("%1: add %2", m_target->m_name, m_child->name()));
92  m_index = index;
93 // m_removed = true;
94  }
95 
96  void redo() override {
98  }
99 
100  void undo() override {
102  }
103 };
104 
105 class AspectChildReparentCmd : public QUndoCommand {
106 public:
108  AbstractAspect* child, int new_index)
109  : m_target(target), m_new_parent(new_parent), m_child(child), m_new_index(new_index) {
110  setText(i18n("%1: move %2 to %3.", m_target->m_name, m_child->name(), m_new_parent->m_name));
111  }
112 
113  // calling redo transfers ownership of m_child to the new parent aspect
114  void redo() override {
118  emit m_child->aspectAdded(m_child);
119  }
120 
121  // calling undo transfers ownership of m_child back to its previous parent aspect
122  void undo() override {
123  Q_ASSERT(m_index != -1);
127  emit m_child->aspectAdded(m_child);
128  }
129 
130 protected:
134  int m_index{-1};
136 };
137 
138 #endif
int removeChild(AbstractAspect *)
AbstractAspect *const q
Definition: AspectPrivate.h:53
void insertChild(int index, AbstractAspect *)
QVector< AbstractAspect * > m_children
Definition: AspectPrivate.h:48
int indexOfChild(const AbstractAspect *) const
Base class of all persistent objects in a Project.
void aspectAdded(const AbstractAspect *)
Emitted after a new Aspect has been added to the tree.
@ Recursive
Recursively handle all descendents, not just immediate children.
@ IncludeHidden
Include aspects marked as "hidden" in numbering or listing children.
void aspectAboutToBeRemoved(const AbstractAspect *)
Emitted before an aspect is removed from its parent.
QString name() const
void aspectAboutToBeAdded(const AbstractAspect *parent, const AbstractAspect *before, const AbstractAspect *child)
Emitted before a new child is inserted.
void aspectRemoved(const AbstractAspect *parent, const AbstractAspect *before, const AbstractAspect *child)
Emitted from the parent after removing a child.
QVector< AbstractAspect * > children(AspectType type, ChildIndexFlags flags={}) const
void undo() override
AspectChildAddCmd(AbstractAspectPrivate *target, AbstractAspect *child, int index)
void redo() override
AbstractAspectPrivate * m_target
AbstractAspect * m_child
void redo() override
AspectChildRemoveCmd(AbstractAspectPrivate *target, AbstractAspect *child)
void undo() override
~AspectChildRemoveCmd() override
AspectChildReparentCmd(AbstractAspectPrivate *target, AbstractAspectPrivate *new_parent, AbstractAspect *child, int new_index)
AbstractAspectPrivate * m_new_parent
AbstractAspectPrivate * m_target
void redo() override
AbstractAspect * m_child
void undo() override
#define i18n(m)
Definition: nsl_common.h:38