scidavis  2.3.0
About: SciDAVis is a free application for Scientific Data Analysis and Visualization (a fork off of QtiPlot).
  Fossies Dox: scidavis-2.3.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

aspectcommands.h
Go to the documentation of this file.
1 
12 
31 #include "AspectPrivate.h"
32 
33 #include <QUndoCommand>
34 
35 class AspectNameChangeCmd : public QUndoCommand
36 {
37  public:
38  AspectNameChangeCmd(AbstractAspect::Private *target, const QString &new_name)
39  : d_target(target), d_other_name(new_name) {
40  setText(QObject::tr("%1: rename to %2").arg(d_target->name()).arg(new_name));
41  }
42 
43  virtual void redo() {
44  QString tmp = d_target->name();
46  d_other_name = tmp;
47  }
48 
49  virtual void undo() { redo(); }
50 
51  private:
53  QString d_other_name;
54 };
55 
56 class AspectCommentChangeCmd : public QUndoCommand
57 {
58  public:
59  AspectCommentChangeCmd(AbstractAspect::Private *target, const QString &new_comment)
60  : d_target(target), d_other_comment(new_comment) {
61  setText(QObject::tr("%1: change comment").arg(d_target->name()));
62  }
63 
64  virtual void redo() {
65  QString tmp = d_target->comment();
67  d_other_comment = tmp;
68  }
69 
70  virtual void undo() { redo(); }
71 
72  private:
74  QString d_other_comment;
75 };
76 
77 class AspectCaptionSpecChangeCmd : public QUndoCommand
78 {
79  public:
80  AspectCaptionSpecChangeCmd(AbstractAspect::Private *target, const QString &new_caption_spec)
81  : d_target(target), d_other_caption_spec(new_caption_spec) {
82  setText(QObject::tr("%1: change caption").arg(d_target->name()));
83  }
84 
85  virtual void redo() {
86  QString tmp = d_target->captionSpec();
89  }
90 
91  virtual void undo() { redo(); }
92 
93  private:
96 };
97 
98 
99 class AspectCreationTimeChangeCmd : public QUndoCommand
100 {
101  public:
102  AspectCreationTimeChangeCmd(AbstractAspect::Private *target, const QDateTime &new_creation_time)
103  : d_target(target), d_other_creation_time(new_creation_time) {
104  setText(QObject::tr("%1: set creation time").arg(d_target->name()));
105  }
106 
107  virtual void redo() {
108  QDateTime tmp = d_target->creationTime();
110  d_other_creation_time = tmp;
111  }
112 
113  virtual void undo() { redo(); }
114 
115  private:
118 };
119 
120 
121 class AspectChildRemoveCmd : public QUndoCommand
122 {
123  public:
125  : d_target(target), d_child(child), d_index(-1), d_removed(false), d_detach(detach) {
126  setText(QObject::tr("%1: remove %2").arg(d_target->name()).arg(d_child->name()));
127  }
129  if (d_removed && !d_detach)
130  delete d_child;
131  }
132 
133  // calling redo transfers ownership of d_child to the undo command
134  virtual void redo() {
136  d_removed = true;
137  }
138 
139  // calling undo transfers ownership of d_child back to its parent aspect
140  virtual void undo() {
141  Q_ASSERT(d_index != -1); // d_child must be a child of d_target->owner()
143  d_removed = false;
144  }
145 
146  protected:
149  int d_index;
151 };
152 
154 {
155  public:
157  : AspectChildRemoveCmd(target, child, false) {
158  setText(QObject::tr("%1: add %2").arg(d_target->name()).arg(d_child->name()));
159  d_index = index;
160  }
161 
162  virtual void redo() { AspectChildRemoveCmd::undo(); }
163 
164  virtual void undo() { AspectChildRemoveCmd::redo(); }
165 };
166 
167 class AspectChildMoveCmd : public QUndoCommand
168 {
169  public:
170  AspectChildMoveCmd(AbstractAspect::Private * target, int from, int to)
171  : d_target(target), d_from(from), d_to(to) {
172  setText(QObject::tr("%1: move child from position %2 to %3.").arg(d_target->name()).arg(d_from+1).arg(d_to+1));
173  }
174 
175  virtual void redo() {
176  // Moving in one go confuses QTreeView, so we would need another two signals
177  // to be mapped to QAbstractItemModel::layoutAboutToBeChanged() and ::layoutChanged().
178  AbstractAspect * child = d_target->child(d_from);
179  d_target->removeChild(child);
180  d_target->insertChild(d_to, child);
181  }
182 
183  virtual void undo() {
184  AbstractAspect * child = d_target->child(d_to);
185  d_target->removeChild(child);
186  d_target->insertChild(d_from, child);
187  }
188 
189  private:
191  int d_from, d_to;
192 };
193 
194 class AspectChildReparentCmd : public QUndoCommand
195 {
196  public:
198  AbstractAspect* child, int new_index)
199  : d_target(target), d_new_parent(new_parent), d_child(child), d_index(-1), d_new_index(new_index)
200  {
201  setText(QObject::tr("%1: move %2 to %3.").arg(d_target->name()).arg(d_child->name()).arg(d_new_parent->name()));
202  }
204 
205  // calling redo transfers ownership of d_child to the new parent aspect
206  virtual void redo()
207  {
210  }
211 
212  // calling undo transfers ownership of d_child back to its previous parent aspect
213  virtual void undo()
214  {
215  Q_ASSERT(d_index != -1);
218  }
219 
220  protected:
224  int d_index;
226 };
227 
AspectNameChangeCmd
Definition: aspectcommands.h:36
AspectNameChangeCmd::d_target
AbstractAspect::Private * d_target
Definition: aspectcommands.h:52
AspectChildRemoveCmd::d_index
int d_index
Definition: aspectcommands.h:149
AbstractAspect::Private::comment
QString comment() const
Definition: AspectPrivate.cpp:134
AspectNameChangeCmd::d_other_name
QString d_other_name
Definition: aspectcommands.h:53
AspectCommentChangeCmd::d_target
AbstractAspect::Private * d_target
Definition: aspectcommands.h:73
AbstractAspect::Private::captionSpec
QString captionSpec() const
Definition: AspectPrivate.cpp:146
AspectCreationTimeChangeCmd::d_other_creation_time
QDateTime d_other_creation_time
Definition: aspectcommands.h:117
AspectChildMoveCmd::undo
virtual void undo()
Definition: aspectcommands.h:183
AspectChildMoveCmd::d_to
int d_to
Definition: aspectcommands.h:191
AspectCaptionSpecChangeCmd::d_other_caption_spec
QString d_other_caption_spec
Definition: aspectcommands.h:95
AspectChildAddCmd
Definition: aspectcommands.h:154
AspectChildRemoveCmd::d_detach
bool d_detach
Definition: aspectcommands.h:150
AspectChildMoveCmd
Definition: aspectcommands.h:168
AspectCreationTimeChangeCmd::d_target
AbstractAspect::Private * d_target
Definition: aspectcommands.h:116
AspectChildReparentCmd::redo
virtual void redo()
Definition: aspectcommands.h:206
AspectChildReparentCmd::~AspectChildReparentCmd
~AspectChildReparentCmd()
Definition: aspectcommands.h:203
AspectNameChangeCmd::undo
virtual void undo()
Definition: aspectcommands.h:49
AbstractAspect::Private::setComment
void setComment(const QString &value)
Definition: AspectPrivate.cpp:139
AspectChildRemoveCmd::d_child
AbstractAspect * d_child
Definition: aspectcommands.h:148
AbstractAspect::Private::removeChild
int removeChild(AbstractAspect *child)
Definition: AspectPrivate.cpp:98
AspectChildReparentCmd::d_new_index
int d_new_index
Definition: aspectcommands.h:225
AspectChildRemoveCmd::~AspectChildRemoveCmd
~AspectChildRemoveCmd()
Definition: aspectcommands.h:128
AspectCaptionSpecChangeCmd
Definition: aspectcommands.h:78
AspectCommentChangeCmd::AspectCommentChangeCmd
AspectCommentChangeCmd(AbstractAspect::Private *target, const QString &new_comment)
Definition: aspectcommands.h:59
AspectCommentChangeCmd
Definition: aspectcommands.h:57
AspectChildMoveCmd::d_target
AbstractAspect::Private * d_target
Definition: aspectcommands.h:190
AspectChildRemoveCmd::d_removed
bool d_removed
Definition: aspectcommands.h:150
AspectPrivate.h
AbstractAspect::Private
Private data managed by AbstractAspect.
Definition: AspectPrivate.h:42
AbstractAspect::name
QString name() const
Definition: AbstractAspect.cpp:229
AspectChildMoveCmd::AspectChildMoveCmd
AspectChildMoveCmd(AbstractAspect::Private *target, int from, int to)
Definition: aspectcommands.h:170
AspectChildReparentCmd::undo
virtual void undo()
Definition: aspectcommands.h:213
AspectNameChangeCmd::redo
virtual void redo()
Definition: aspectcommands.h:43
AspectNameChangeCmd::AspectNameChangeCmd
AspectNameChangeCmd(AbstractAspect::Private *target, const QString &new_name)
Definition: aspectcommands.h:38
AbstractAspect::Private::name
QString name() const
Definition: AspectPrivate.cpp:122
AspectChildAddCmd::redo
virtual void redo()
Definition: aspectcommands.h:162
AspectChildReparentCmd
Definition: aspectcommands.h:195
AspectChildMoveCmd::redo
virtual void redo()
Definition: aspectcommands.h:175
AspectChildAddCmd::AspectChildAddCmd
AspectChildAddCmd(AbstractAspect::Private *target, AbstractAspect *child, int index)
Definition: aspectcommands.h:156
AspectChildReparentCmd::d_target
AbstractAspect::Private * d_target
Definition: aspectcommands.h:221
AspectChildReparentCmd::d_index
int d_index
Definition: aspectcommands.h:224
AspectCreationTimeChangeCmd::undo
virtual void undo()
Definition: aspectcommands.h:113
AbstractAspect::Private::creationTime
QDateTime creationTime() const
Definition: AspectPrivate.cpp:196
AspectCaptionSpecChangeCmd::redo
virtual void redo()
Definition: aspectcommands.h:85
AspectChildReparentCmd::AspectChildReparentCmd
AspectChildReparentCmd(AbstractAspect::Private *target, AbstractAspect::Private *new_parent, AbstractAspect *child, int new_index)
Definition: aspectcommands.h:197
AbstractAspect::Private::setCaptionSpec
void setCaptionSpec(const QString &value)
Definition: AspectPrivate.cpp:151
AbstractAspect::Private::insertChild
void insertChild(int index, AbstractAspect *child)
Definition: AspectPrivate.cpp:61
AspectChildRemoveCmd::undo
virtual void undo()
Definition: aspectcommands.h:140
AspectChildRemoveCmd
Definition: aspectcommands.h:122
AspectChildReparentCmd::d_new_parent
AbstractAspect::Private * d_new_parent
Definition: aspectcommands.h:222
AspectCommentChangeCmd::redo
virtual void redo()
Definition: aspectcommands.h:64
AspectCommentChangeCmd::d_other_comment
QString d_other_comment
Definition: aspectcommands.h:74
AspectChildRemoveCmd::AspectChildRemoveCmd
AspectChildRemoveCmd(AbstractAspect::Private *target, AbstractAspect *child, bool detach)
Definition: aspectcommands.h:124
AspectCreationTimeChangeCmd::redo
virtual void redo()
Definition: aspectcommands.h:107
AbstractAspect::Private::child
AbstractAspect * child(int index)
Definition: AspectPrivate.cpp:116
AspectCreationTimeChangeCmd::AspectCreationTimeChangeCmd
AspectCreationTimeChangeCmd(AbstractAspect::Private *target, const QDateTime &new_creation_time)
Definition: aspectcommands.h:102
AspectChildAddCmd::undo
virtual void undo()
Definition: aspectcommands.h:164
AspectCaptionSpecChangeCmd::AspectCaptionSpecChangeCmd
AspectCaptionSpecChangeCmd(AbstractAspect::Private *target, const QString &new_caption_spec)
Definition: aspectcommands.h:80
AbstractAspect::Private::setName
void setName(const QString &value)
Definition: AspectPrivate.cpp:127
AspectChildRemoveCmd::redo
virtual void redo()
Definition: aspectcommands.h:134
AbstractAspect::Private::setCreationTime
void setCreationTime(const QDateTime &time)
Definition: AspectPrivate.cpp:158
AspectCaptionSpecChangeCmd::undo
virtual void undo()
Definition: aspectcommands.h:91
AspectChildMoveCmd::d_from
int d_from
Definition: aspectcommands.h:191
AspectCommentChangeCmd::undo
virtual void undo()
Definition: aspectcommands.h:70
AspectChildReparentCmd::d_child
AbstractAspect * d_child
Definition: aspectcommands.h:223
AspectCaptionSpecChangeCmd::d_target
AbstractAspect::Private * d_target
Definition: aspectcommands.h:94
AbstractAspect
Base class of all persistent objects in a Project.
Definition: AbstractAspect.h:86
AspectCreationTimeChangeCmd
Definition: aspectcommands.h:100
AspectChildRemoveCmd::d_target
AbstractAspect::Private * d_target
Definition: aspectcommands.h:147