pqUndoStack.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Kitware Inc.
2 // SPDX-FileCopyrightText: Copyright (c) Sandia Corporation
3 // SPDX-License-Identifier: BSD-3-Clause
4 #ifndef pqUndoStack_h
5 #define pqUndoStack_h
6 
7 #include "pqCoreModule.h"
8 #include <QObject>
9 
10 class pqServer;
11 class vtkSMUndoElement;
12 class vtkSMUndoStack;
14 class vtkUndoElement;
15 class vtkUndoSet; // vistrails
16 class vtkPVXMLElement; // vistrails
17 
28 class PQCORE_EXPORT pqUndoStack : public QObject
29 {
30  Q_OBJECT
31 public:
36  pqUndoStack(vtkSMUndoStackBuilder* builder = nullptr, QObject* parent = nullptr);
37  ~pqUndoStack() override;
38 
42  bool canUndo();
43 
47  bool canRedo();
48 
52  QString undoLabel();
53 
57  QString redoLabel();
58 
62  bool ignoreAllChanges() const;
63 
67  void registerElementForLoader(vtkSMUndoElement*);
68 
72  bool getInUndo() const;
73  bool getInRedo() const;
74 
79  void Push(const char* label, vtkUndoSet* set);
80  vtkUndoSet* getLastUndoSet(); // vistrails
81  vtkUndoSet* getUndoSetFromXML(vtkPVXMLElement* root); // vistrails
82 
86  vtkSMUndoStackBuilder* GetUndoStackBuilder();
87 
91  void updateAllModifiedProxies();
92 
93 public Q_SLOTS: // NOLINT(readability-redundant-access-specifiers)
94  void beginUndoSet(QString label);
95  void endUndoSet();
96 
100  void undo();
101 
105  void redo();
106 
110  void clear();
111 
118  void beginNonUndoableChanges();
119  void endNonUndoableChanges();
120 
124  void addToActiveUndoSet(vtkUndoElement* element);
125 
126 Q_SIGNALS:
131  void stackChanged(bool canUndo, QString undoLabel, bool canRedo, QString redoLabel);
132 
133  void canUndoChanged(bool);
134  void canRedoChanged(bool);
135  void undoLabelChanged(const QString&);
136  void redoLabelChanged(const QString&);
137 
138  // Fired after undo.
139  void undone();
140  // Fired after redo.
141  void redone();
142 
143 private Q_SLOTS:
144  void onStackChanged();
145 
146 private: // NOLINT(readability-redundant-access-specifiers)
147  class pqImplementation;
148  pqImplementation* Implementation;
149 };
150 
151 #include "pqApplicationCore.h"
152 
153 inline void BEGIN_UNDO_SET(const QString& name)
154 {
156  if (usStack)
157  {
158  usStack->beginUndoSet(name);
159  }
160 }
161 
162 inline void END_UNDO_SET()
163 {
165  if (usStack)
166  {
167  usStack->endUndoSet();
168  }
169 }
170 
171 inline void CLEAR_UNDO_STACK()
172 {
174  if (usStack)
175  {
176  usStack->clear();
177  }
178 }
179 
180 inline void ADD_UNDO_ELEM(vtkUndoElement* elem)
181 {
183  if (usStack)
184  {
185  usStack->addToActiveUndoSet(elem);
186  }
187 }
188 
189 inline void BEGIN_UNDO_EXCLUDE()
190 {
192  if (usStack)
193  {
194  usStack->beginNonUndoableChanges();
195  }
196 }
197 
198 inline void END_UNDO_EXCLUDE()
199 {
201  if (usStack)
202  {
203  usStack->endNonUndoableChanges();
204  }
205 }
206 
208 {
209 public:
212 
213 private:
214  Q_DISABLE_COPY(pqScopedUndoExclude);
215 };
216 
218 {
219 public:
220  pqScopedUndoSet(const QString& label) { BEGIN_UNDO_SET(label); }
222 
223 private:
224  Q_DISABLE_COPY(pqScopedUndoSet);
225 };
226 
227 #define SCOPED_UNDO_EXCLUDE() SCOPED_UNDO_EXCLUDE__0(__LINE__)
228 #define SCOPED_UNDO_EXCLUDE__0(line) pqScopedUndoExclude val##line
229 
230 #define SCOPED_UNDO_SET(txt) SCOPED_UNDO_SET__0(__LINE__, txt)
231 #define SCOPED_UNDO_SET__0(line, txt) pqScopedUndoSet val##line(txt)
232 
233 #endif
unit undo-redo-able operation.
void CLEAR_UNDO_STACK()
Definition: pqUndoStack.h:171
builds server manager undo sets and pushes them on the undo stack.
void BEGIN_UNDO_SET(const QString &name)
Definition: pqUndoStack.h:153
void endUndoSet()
void ADD_UNDO_ELEM(vtkUndoElement *elem)
Definition: pqUndoStack.h:180
This is the undo/redo stack for the Server Manager.
void beginUndoSet(QString label)
void BEGIN_UNDO_EXCLUDE()
Definition: pqUndoStack.h:189
#define PQCORE_EXPORT
Definition: pqCoreModule.h:15
void clear()
Clears undo stack.
Maintains a collection of vtkUndoElement that can be undone/redone in a single step.
Definition: vtkUndoSet.h:30
void addToActiveUndoSet(vtkUndoElement *element)
One can add arbitrary elements to the undo set currently being built.
void endNonUndoableChanges()
This is used by vtkPVXMLParser to represent an XML document starting at the root element.
pqUndoStack * getUndoStack() const
pqUndoStack represents a vtkSMUndoStack along with a a vtkSMUndoStackBuilder.
Definition: pqUndoStack.h:28
abstract superclass for Server Manager undo elements.
void END_UNDO_SET()
Definition: pqUndoStack.h:162
void END_UNDO_EXCLUDE()
Definition: pqUndoStack.h:198
static pqApplicationCore * instance()
pqServer (should be renamed to pqSession) is a pqServerManagerModelItem subclass that represents a vt...
Definition: pqServer.h:35
pqScopedUndoSet(const QString &label)
Definition: pqUndoStack.h:220
void beginNonUndoableChanges()
when the GUI is performing some changes that should not go on the UndoStack at all, it should call beginNonUndoableChanges().