pqUndoStack.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ParaView
4  Module: pqUndoStack.h
5 
6  Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
7  All rights reserved.
8 
9  ParaView is a free software; you can redistribute it and/or modify it
10  under the terms of the ParaView license version 1.2.
11 
12  See License_v1.2.txt for the full ParaView license.
13  A copy of this license can be obtained by contacting
14  Kitware Inc.
15  28 Corporate Drive
16  Clifton Park, NY 12065
17  USA
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
23 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 ========================================================================*/
32 #ifndef pqUndoStack_h
33 #define pqUndoStack_h
34 
35 #include "pqCoreModule.h"
36 #include <QObject>
37 
38 class pqServer;
39 class vtkSMUndoElement;
40 class vtkSMUndoStack;
42 class vtkUndoElement;
43 class vtkUndoSet; // vistrails
44 class vtkPVXMLElement; // vistrails
45 
56 class PQCORE_EXPORT pqUndoStack : public QObject
57 {
58  Q_OBJECT
59 public:
64  pqUndoStack(vtkSMUndoStackBuilder* builder = nullptr, QObject* parent = nullptr);
65  ~pqUndoStack() override;
66 
70  bool canUndo();
71 
75  bool canRedo();
76 
80  QString undoLabel();
81 
85  QString redoLabel();
86 
90  bool ignoreAllChanges() const;
91 
95  void registerElementForLoader(vtkSMUndoElement*);
96 
100  bool getInUndo() const;
101  bool getInRedo() const;
102 
107  void Push(const char* label, vtkUndoSet* set);
108  vtkUndoSet* getLastUndoSet(); // vistrails
109  vtkUndoSet* getUndoSetFromXML(vtkPVXMLElement* root); // vistrails
110 
114  vtkSMUndoStackBuilder* GetUndoStackBuilder();
115 
119  void updateAllModifiedProxies();
120 
121 public Q_SLOTS: // NOLINT(readability-redundant-access-specifiers)
122  void beginUndoSet(QString label);
123  void endUndoSet();
124 
128  void undo();
129 
133  void redo();
134 
138  void clear();
139 
146  void beginNonUndoableChanges();
147  void endNonUndoableChanges();
148 
152  void addToActiveUndoSet(vtkUndoElement* element);
153 
154 Q_SIGNALS:
159  void stackChanged(bool canUndo, QString undoLabel, bool canRedo, QString redoLabel);
160 
161  void canUndoChanged(bool);
162  void canRedoChanged(bool);
163  void undoLabelChanged(const QString&);
164  void redoLabelChanged(const QString&);
165 
166  // Fired after undo.
167  void undone();
168  // Fired after redo.
169  void redone();
170 
171 private Q_SLOTS:
172  void onStackChanged();
173 
174 private: // NOLINT(readability-redundant-access-specifiers)
175  class pqImplementation;
176  pqImplementation* Implementation;
177 };
178 
179 #include "pqApplicationCore.h"
180 
181 inline void BEGIN_UNDO_SET(const QString& name)
182 {
184  if (usStack)
185  {
186  usStack->beginUndoSet(name);
187  }
188 }
189 
190 inline void END_UNDO_SET()
191 {
193  if (usStack)
194  {
195  usStack->endUndoSet();
196  }
197 }
198 
199 inline void CLEAR_UNDO_STACK()
200 {
202  if (usStack)
203  {
204  usStack->clear();
205  }
206 }
207 
208 inline void ADD_UNDO_ELEM(vtkUndoElement* elem)
209 {
211  if (usStack)
212  {
213  usStack->addToActiveUndoSet(elem);
214  }
215 }
216 
217 inline void BEGIN_UNDO_EXCLUDE()
218 {
220  if (usStack)
221  {
222  usStack->beginNonUndoableChanges();
223  }
224 }
225 
226 inline void END_UNDO_EXCLUDE()
227 {
229  if (usStack)
230  {
231  usStack->endNonUndoableChanges();
232  }
233 }
234 
236 {
237 public:
240 
241 private:
242  Q_DISABLE_COPY(pqScopedUndoExclude);
243 };
244 
246 {
247 public:
248  pqScopedUndoSet(const QString& label) { BEGIN_UNDO_SET(label); }
250 
251 private:
252  Q_DISABLE_COPY(pqScopedUndoSet);
253 };
254 
255 #define SCOPED_UNDO_EXCLUDE() SCOPED_UNDO_EXCLUDE__0(__LINE__)
256 #define SCOPED_UNDO_EXCLUDE__0(line) pqScopedUndoExclude val##line
257 
258 #define SCOPED_UNDO_SET(txt) SCOPED_UNDO_SET__0(__LINE__, txt)
259 #define SCOPED_UNDO_SET__0(line, txt) pqScopedUndoSet val##line(txt)
260 
261 #endif
unit undo-redo-able operation.
void CLEAR_UNDO_STACK()
Definition: pqUndoStack.h:199
builds server manager undo sets and pushes them on the undo stack.
void BEGIN_UNDO_SET(const QString &name)
Definition: pqUndoStack.h:181
void endUndoSet()
void ADD_UNDO_ELEM(vtkUndoElement *elem)
Definition: pqUndoStack.h:208
This is the undo/redo stack for the Server Manager.
void beginUndoSet(QString label)
void BEGIN_UNDO_EXCLUDE()
Definition: pqUndoStack.h:217
#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:42
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:56
abstract superclass for Server Manager undo elements.
void END_UNDO_SET()
Definition: pqUndoStack.h:190
void END_UNDO_EXCLUDE()
Definition: pqUndoStack.h:226
static pqApplicationCore * instance()
pqServer (should be renamed to pqSession) is a pqServerManagerModelItem subclass that represents a vt...
Definition: pqServer.h:63
pqScopedUndoSet(const QString &label)
Definition: pqUndoStack.h:248
void beginNonUndoableChanges()
when the GUI is performing some changes that should not go on the UndoStack at all, it should call beginNonUndoableChanges().