UndoRedoStack.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package MemoryX::gui-plugins::SceneEditor
19 * @date 2015
20 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21 * GNU General Public License
22 */
23
24#pragma once
25
26// std
27#include <exception>
28#include <memory>
29#include <vector>
30
31// local
32#include "ClassDefinitions.h"
33#include "Controller.h"
34#include "UndoAction.h"
35
36namespace controller
37{
38 /**
39 * A Stack to save a history of Actions.
40 * This Stack provides Functions to move forward and backward in the history.
41 *
42 * @see controller::UndoAction
43 */
45 {
46 public:
47 /**
48 * A constructor.
49 * Creates a new Instance of this class.
50 */
52
53 /**
54 * Returns the possibility to undo a Action.
55 *
56 * @return True, if there is a Action to undo; false otherwise.
57 */
58 bool canUndo();
59
60 /**
61 * Returns the possibility to redo a Action.
62 *
63 * @return True, if there is a Action to redo; false otherwise.
64 */
65 bool canRedo();
66
67 /**
68 * Goes one step back in the history and returns the Operations need to redo.
69 */
70 std::shared_ptr<std::vector<OperationPtr>> undo();
71
72 /**
73 * Goes one step forward in the history and returns the Operations need to redo.
74 */
75 std::shared_ptr<std::vector<OperationPtr>> redo();
76
77 /**
78 * Removes all actions from the history.
79 */
80 void clear();
81
82 /**
83 * Adds a Action to the history.
84 * The redo history will be cleared.
85 *
86 * @param action The action to add to the history.
87 * @see controller::UndoAction
88 */
89 void push(const std::shared_ptr<std::vector<OperationPtr>>& operations);
90
91 /**
92 * Swaps oldId and newId in all Operations saved in this class.
93 *
94 * @param oldId the first ID
95 * @param newId the second ID
96 */
97 void updateObjectId(std::string oldId, std::string newId);
98
99 private:
100 std::unique_ptr<std::vector<UndoActionPtr>> undoStack;
101 std::unique_ptr<std::vector<UndoActionPtr>> redoStack;
102 };
103} // namespace controller
auto newId
std::shared_ptr< std::vector< OperationPtr > > redo()
Goes one step forward in the history and returns the Operations need to redo.
bool canUndo()
Returns the possibility to undo a Action.
UndoRedoStack()
A constructor.
void push(const std::shared_ptr< std::vector< OperationPtr > > &operations)
Adds a Action to the history.
bool canRedo()
Returns the possibility to redo a Action.
std::shared_ptr< std::vector< OperationPtr > > undo()
Goes one step back in the history and returns the Operations need to redo.
void clear()
Removes all actions from the history.
void updateObjectId(std::string oldId, std::string newId)
Swaps oldId and newId in all Operations saved in this class.