Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkVerboseLimitedLinearUndo.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 #include "mitkOperationEvent.h"
19 
21 {
22 }
23 
25 {
26 }
27 
29 {
30  if (!undoStackItem)
31  return false;
32 
33  // clear the redolist, if a new operation is saved
34  if (!m_RedoList.empty())
35  {
36  this->ClearList(&m_RedoList);
37  InvokeEvent(RedoEmptyEvent());
38  }
39 
40  m_UndoList.push_back(undoStackItem);
41 
42  InvokeEvent(UndoNotEmptyEvent());
43 
44  return true;
45 }
46 
48 {
50 
51  if (m_UndoList.empty())
52  return descriptions;
53 
54  int oeid = m_UndoList.back()->GetObjectEventId(); // ObjectEventID of current group
55  std::string currentDescription; // description of current group
56  int currentDescriptionCount(0); // counter, how many items of the current group gave descriptions
57  bool niceDescriptionFound(false); // have we yet seen a plain descriptive entry (not OperationEvent)?
58  std::string lastDescription; // stores the last description to inhibit entries like "name AND name AND name..." if
59  // name is always the same
60 
61  for (auto iter = m_UndoList.rbegin(); iter != m_UndoList.rend(); ++iter)
62  {
63  if (oeid != (*iter)->GetObjectEventId())
64  {
65  // current description complete, append to list
66  if (currentDescription.empty())
67  currentDescription = "Some unnamed action"; // set a default description
68 
69  descriptions.push_back(StackDescriptionItem(oeid, currentDescription));
70 
71  currentDescription = ""; // prepare for next group
72  currentDescriptionCount = 0;
73  niceDescriptionFound = false;
74  oeid = (*iter)->GetObjectEventId();
75  }
76 
77  if (!(*iter)->GetDescription().empty()) // if there is a description
78  {
79  if (!dynamic_cast<OperationEvent *>(*iter))
80  {
81  // anything but an OperationEvent overrides the collected descriptions
82  currentDescription = (*iter)->GetDescription();
83  niceDescriptionFound = true;
84  }
85  else if (!niceDescriptionFound) // mere descriptive items override OperationEvents' descriptions
86  {
87  if (currentDescriptionCount) // if we have already seen another description
88  {
89  if (lastDescription != (*iter)->GetDescription())
90  {
91  // currentDescription += '\n'; // concatenate descriptions with newline
92  currentDescription += " AND "; // this has to wait until the popup can process multiline items
93  currentDescription += (*iter)->GetDescription();
94  }
95  }
96  else
97  {
98  currentDescription += (*iter)->GetDescription();
99  }
100  }
101  lastDescription = (*iter)->GetDescription();
102  ++currentDescriptionCount;
103  }
104 
105  } // for
106 
107  // add last description to list
108  if (currentDescription.empty())
109  currentDescription = "Some unnamed action";
110  descriptions.push_back(StackDescriptionItem(oeid, currentDescription));
111 
112  return descriptions; // list ready
113 }
114 
116 {
118 
119  if (m_RedoList.empty())
120  return descriptions;
121 
122  int oeid = m_RedoList.back()->GetObjectEventId(); // ObjectEventID of current group
123  std::string currentDescription; // description of current group
124  int currentDescriptionCount(0); // counter, how many items of the current group gave descriptions
125  bool niceDescriptionFound(false); // have we yet seen a plain descriptive entry (not OperationEvent)?
126  std::string lastDescription; // stores the last description to inhibit entries like "name AND name AND name..." if
127  // name is always the same
128 
129  for (auto iter = m_RedoList.rbegin(); iter != m_RedoList.rend(); ++iter)
130  {
131  if (oeid != (*iter)->GetObjectEventId())
132  {
133  // current description complete, append to list
134  if (currentDescription.empty())
135  currentDescription = "Some unnamed action"; // set a default description
136 
137  descriptions.push_back(StackDescriptionItem(oeid, currentDescription));
138 
139  currentDescription = ""; // prepare for next group
140  currentDescriptionCount = 0;
141  niceDescriptionFound = false;
142  oeid = (*iter)->GetObjectEventId();
143  }
144 
145  if (!(*iter)->GetDescription().empty()) // if there is a description
146  {
147  if (!dynamic_cast<OperationEvent *>(*iter))
148  {
149  // anything but an OperationEvent overrides the collected descriptions
150  currentDescription = (*iter)->GetDescription();
151  niceDescriptionFound = true;
152  }
153  else if (!niceDescriptionFound) // mere descriptive items override OperationEvents' descriptions
154  {
155  if (currentDescriptionCount) // if we have already seen another description
156  {
157  if (lastDescription != (*iter)->GetDescription())
158  {
159  // currentDescription += '\n'; // concatenate descriptions with newline
160  currentDescription += " AND "; // this has to wait until the popup can process multiline items
161  currentDescription += (*iter)->GetDescription();
162  }
163  }
164  else
165  {
166  currentDescription += (*iter)->GetDescription();
167  }
168  }
169  lastDescription = (*iter)->GetDescription();
170  ++currentDescriptionCount;
171  }
172 
173  } // for
174 
175  // add last description to list
176  if (currentDescription.empty())
177  currentDescription = "Some unnamed action";
178  descriptions.push_back(StackDescriptionItem(oeid, currentDescription));
179 
180  return descriptions; // list ready
181 }
virtual bool SetOperationEvent(UndoStackItem *undoStackItem) override
a list of pairs (int,string), representing a stack with ObjectEventIDs and descriptions ...
std::pair< int, std::string > StackDescriptionItem
Represents an entry of the undo or redo stack.
virtual StackDescription GetRedoDescriptions()
std::vector< StackDescriptionItem > StackDescription
virtual StackDescription GetUndoDescriptions()