casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TBAction.h
Go to the documentation of this file.
1 //# TBAction.h: Edit actions that can be done, undone, and redone.
2 //# Copyright (C) 2005
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id: $
27 #ifndef TBACTION_H_
28 #define TBACTION_H_
29 
31 
32 #include <casa/BasicSL/String.h>
33 
34 #include <vector>
35 
36 namespace casa {
37 
38 //# Forward Declarations
39 class TBTableTabs;
40 class TBViewArray;
41 class TBData;
42 
43 // <summary>
44 // Abstract parent class of any action that can be performed.
45 // <summary>
46 //
47 // <synopsis>
48 // Any editing change to the underlying table should be encapsulated in a
49 // TBAction. A TBAction subclass needs to be able to perform the designated
50 // action as well as knowing how to undo it. The specific implementation of
51 // performing the action is left up to the subclasses.
52 // </synopsis>
53 
54 class TBAction {
55 public:
56  // Constructor that takes a pointer to the origin object. The origin is
57  // used to, for example, remove actions associated with objects that have
58  // been closed or otherwise made unavailable.
59  TBAction(void* origin);
60 
61  virtual ~TBAction();
62 
63 
64  // Returns a pointer to the origin object.
65  void* getOrigin();
66 
67 
68  // doAction() must be implemented by any subclass. This method performs
69  // the action, updating both the backend and the GUI as necessary.
70  virtual Result doAction() = 0;
71 
72  // undoAction() must be implemented by any subclass. This method undoes
73  // the action, updating both the backend and the GUI as necessary.
74  virtual Result undoAction() = 0;
75 
76  // name() must be implemented by any subclass. This method returns the
77  // name of the action. The name should be human-readable and does not have
78  // to be any specific format.
79  virtual casacore::String name() = 0;
80 
81  // isAssociatedWith() must be implemented by any subclass. This method
82  // returns true if this action is associated with the given origin object,
83  // false otherwise. If an action is associated with an object that is
84  // then closed (like a table or an array) then the action may be removed
85  // from the performed/undone queues.
86  virtual bool isAssociatedWith(void* origin) = 0;
87 
88 protected:
89  // Pointer to origin object.
90  void* origin;
91 };
92 
93 // <summary>
94 // Contains an list of performed actions and a list of undone actions.
95 // <summary>
96 //
97 // <synopsis>
98 // A TBActionList keep track of performed and undone actions and provides
99 // methods to add and move actions between the two lists. The lists have a
100 // maximum length defined by TBConstants::MAX_ACTION_BUFFER; once this limit
101 // has been reached, old actions are discarded.
102 // </synopsis>
103 
104 class TBActionList {
105 public:
106  // Default Constructor to initialize the empty lists.
107  TBActionList();
108 
109  ~TBActionList();
110 
111 
112  // Returns true if the performed list is empty, false otherwise.
113  bool isEmpty();
114 
115  // Returns true if the undone list is empty, false otherwise.
116  bool undoneIsEmpty();
117 
118  // Returns the size of the performed list.
119  int size();
120 
121  // Returns the size of the undone list.
122  int undoneSize();
123 
124  // Returns the name() value of the last performed action, or blank if
125  // there is none.
127 
128  // Returns the name() value of the last undone action, or blank if there
129  // is none.
131 
132  // Returns the performed action at the designated index, or NULL if the
133  // index is invalid.
134  TBAction* at(unsigned int i);
135 
136  // Returns the undone action at the designated index, or NULL if the index
137  // is invalid.
138  TBAction* undoneAt(unsigned int i);
139 
140 
141  // Adds the given TBAction to the performed list and calls the action's
142  // doAction() method.
143  Result doAction(TBAction* action);
144 
145  // Moves the latest performed action to the undone list and calls the
146  // action's undoAction() method.
147  Result undoAction();
148 
149  // Moves the latest undone action to the performed list and calls the
150  // action's doAction() method.
151  Result redoAction();
152 
153  // Removes the given action from the performed list, but does not delete
154  // it. Returns true if the remove was successful, false otherwise.
155  bool remove(TBAction* a);
156 
157  // Removes the given action from the undone list, but does not delete it.
158  // Returns true if the remove was successful, false otherwise.
159  bool removeUndone(TBAction* a);
160 
161 private:
162  // Performed actions list
163  std::vector<TBAction*> actions;
164 
165  // Undone actions list
166  std::vector<TBAction*> undone;
167 };
168 
169 /* Specific Actions */
170 
171 // <summary>
172 // TBAction for when non-array data in the table is edited.
173 // <summary>
174 //
175 // <synopsis>
176 // A TBEditDataAction keeps track of the table, row, column, new value, and old
177 // value. When this action is performed, the underlying table is updated to
178 // the new value at the given row and column; when this action is undone, the
179 // underlying table is updated to the old value.
180 // </synopsis>
181 
182 class TBEditDataAction : public TBAction {
183 public:
186  virtual ~TBEditDataAction();
187 
188 
189  // Implements TBAction::doAction().
190  // Updates the table by calling TBTable::editData() followed by a
191  // TBDataTab::setData() if the edit is successful. Returns the result
192  // of the TBTable::editData() call.
193  Result doAction();
194 
195  // Implements TBAction::undoAction().
196  // Updates the table by calling TBTable::editData() followed by a
197  // TBDataTab::setData() if the edit is successful. Returns the result
198  // of the TBTable::editData() call.
199  Result undoAction();
200 
201  // Implements TBAction::name().
202  // Returns "edit [table name]([row],[col])".
204 
205  // Implements TBAction::isAssociatedWith().
206  // Returns true if o is equal to the TBTableTabs object given in the
207  // constructor, false otherwise.
208  bool isAssociatedWith(void* o);
209 
210 private:
211  // Origin table.
212  TBTableTabs* tt;
213 
214  // Row of the edit data.
215  int row;
216 
217  // Column of the edit data.
218  int col;
219 
220  // New value.
221  TBData* newVal;
222 
223  // Old value.
224  TBData* oldVal;
225 
226  // This action's name.
228 
229 
230  // Updates the underlying table with the given value.
231  Result update(TBData* val);
232 };
233 
234 // <summary>
235 // TBAction for when array data in the table is edited.
236 // <summary>
237 //
238 // <synopsis>
239 // A TBEditArrayDataAction keeps track of the table, row, column, array
240 // coordinates, new value, and old value. When this action is performed, the
241 // underlying table is updated to the new value at the given row, column, and
242 // coordinates; when this action is undone, the underlying table is updated to
243 // the old value.
244 // </synopsis>
245 
246 class TBEditArrayDataAction : public TBAction {
247 public:
249  int col, std::vector<int> coord, TBData* newVal);
250 
251  virtual ~TBEditArrayDataAction();
253 
254  // Implements TBAction::doAction().
255  // Updates the table by calling TBTable::editArrayData() followed by a
256  // TBViewArray::setDataAt() if the edit is successful. Returns the result
257  // of the TBTable::editArrayData().
258  Result doAction();
259 
260  // Implements TBAction::undoAction().
261  // Updates the table by calling TBTable::editArrayData() followed by a
262  // TBViewArray::setDataAt() if the edit is successful. Returns the result
263  // of the TBTable::editArrayData().
264  Result undoAction();
265 
266  // Implements TBAction::name().
267  // Returns "edit [table name]([row],[col])[coords]".
269 
270  // Implements TBAction::isAssociatedWith().
271  // Returns true if o is the TBTableTabs object or the TBViewArray object
272  // given in the constructor, false otherwise.
273  bool isAssociatedWith(void* o);
274 
275 private:
276  // Origin table.
277  TBTableTabs* tt;
278 
279  // Row of the edit data.
280  int row;
281 
282  // Column of the edit data.
283  int col;
284 
285  // casacore::Array coordinates of the edit data.
286  std::vector<int> coords;
287 
288  // New value.
289  TBData* newVal;
290 
291  // Old value.
292  TBData* oldVal;
293 
294  // This action's name.
296 
297  // Indicates whether the array is one-dimensional or not.
298  bool oneDim;
299 
300 
301  // Updates the underlying table with the given value.
302  Result update(TBData* val);
303 };
304 
305 }
306 
307 #endif /* TBACTION_H_ */
TBTableTabs * tt
Origin table.
Definition: TBAction.h:316
virtual ~TBAction()
Result undoAction()
Moves the latest performed action to the undone list and calls the action&#39;s undoAction() method...
Result doAction(TBAction *action)
Adds the given TBAction to the performed list and calls the action&#39;s doAction() method.
bool oneDim
Indicates whether the array is one-dimensional or not.
Definition: TBAction.h:344
Convenience class for a casacore::String/bool tuple.
Definition: TBConstants.h:93
Result doAction()
Implements TBAction::doAction().
Result redoAction()
Moves the latest undone action to the performed list and calls the action&#39;s doAction() method...
TableExprNode array(const TableExprNode &values, const TableExprNodeSet &shape)
Create an array of the given shape and fill it with the values.
Definition: ExprNode.h:1886
TBActionList()
Default Constructor to initialize the empty lists.
void * origin
Pointer to origin object.
Definition: TBAction.h:97
casacore::String name()
Implements TBAction::name().
casacore::Data types used for loaded data.
Definition: TBData.h:51
TBEditDataAction(TBTableTabs *tt, int row, int col, TBData *newVal)
TBAction * undoneAt(unsigned int i)
Returns the undone action at the designated index, or NULL if the index is invalid.
int col
Column of the edit data.
Definition: TBAction.h:248
void * getOrigin()
Returns a pointer to the origin object.
virtual Result undoAction()=0
undoAction() must be implemented by any subclass.
casacore::String actionName
This action&#39;s name.
Definition: TBAction.h:340
TBData * newVal
New value.
Definition: TBAction.h:252
Result update(TBData *val)
Updates the underlying table with the given value.
virtual bool isAssociatedWith(void *origin)=0
isAssociatedWith() must be implemented by any subclass.
Result doAction()
Implements TBAction::doAction().
TBData * oldVal
Old value.
Definition: TBAction.h:256
casacore::String actionName
This action&#39;s name.
Definition: TBAction.h:260
TBEditArrayDataAction(TBTableTabs *tt, TBViewArray *array, int row, int col, std::vector< int > coord, TBData *newVal)
Contains an list of performed actions and a list of undone actions.
Definition: TBAction.h:111
bool isAssociatedWith(void *o)
Implements TBAction::isAssociatedWith().
bool isAssociatedWith(void *o)
Implements TBAction::isAssociatedWith().
std::vector< TBAction * > actions
Performed actions list.
Definition: TBAction.h:185
int row
Row of the edit data.
Definition: TBAction.h:320
std::vector< int > coords
casacore::Array coordinates of the edit data.
Definition: TBAction.h:328
std::vector< TBAction * > undone
Undone actions list.
Definition: TBAction.h:189
Result undoAction()
Implements TBAction::undoAction().
virtual Result doAction()=0
doAction() must be implemented by any subclass.
casacore::String name()
Implements TBAction::name().
Result update(TBData *val)
Updates the underlying table with the given value.
bool undoneIsEmpty()
Returns true if the undone list is empty, false otherwise.
int size()
Returns the size of the performed list.
virtual casacore::String name()=0
name() must be implemented by any subclass.
int row
Row of the edit data.
Definition: TBAction.h:244
bool isEmpty()
Returns true if the performed list is empty, false otherwise.
Collection of table backend and display tabs.
TBAction(void *origin)
Constructor that takes a pointer to the origin object.
TBData * newVal
New value.
Definition: TBAction.h:332
String: the storage and methods of handling collections of characters.
Definition: String.h:223
int col
Column of the edit data.
Definition: TBAction.h:324
casacore::String lastUndoneActionName()
Returns the name() value of the last undone action, or blank if there is none.
Widget for viewing array data in TBArray format.
TBAction for when non-array data in the table is edited.
Definition: TBAction.h:205
TBAction * at(unsigned int i)
Returns the performed action at the designated index, or NULL if the index is invalid.
bool removeUndone(TBAction *a)
Removes the given action from the undone list, but does not delete it.
Result undoAction()
Implements TBAction::undoAction().
Abstract parent class of any action that can be performed.
Definition: TBAction.h:54
TBData * oldVal
Old value.
Definition: TBAction.h:336
TBTableTabs * tt
Origin table.
Definition: TBAction.h:240
casacore::String lastActionName()
Returns the name() value of the last performed action, or blank if there is none. ...
int undoneSize()
Returns the size of the undone list.
TBAction for when array data in the table is edited.
Definition: TBAction.h:280