UndoStackManager.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18 */
19 
20 /*!
21 \file terralib/edit/qt/core/UndoStackManager.cpp
22 
23 \brief This class manager the undo stack.
24 */
25 
26 // TerraLib
27 #include "../../../common/STLUtils.h"
28 #include "../../../dataaccess/dataset/ObjectId.h"
29 #include "../../../qt/widgets/canvas/MapDisplay.h"
30 #include "../../../qt/widgets/Utils.h"
31 #include "../../Feature.h"
32 #include "../../Utils.h"
33 #include "../Renderer.h"
34 #include "../Utils.h"
35 #include "UndoStackManager.h"
36 
37 //QT
38 #include <QUndoCommand>
39 #include <QUndoStack>
40 
42 : m_currentIndex(0),
43  m_undoStack(nullptr)
44 {}
45 
47 {
49  m_addWatches.clear();
50 
51  delete m_undoStack;
52 }
53 
55 {
56  if (m_undoStack == nullptr)
57  return;
58 
59  m_undoStack->push(command);
60 }
61 
63 {
64  if (m_undoStack == nullptr)
65  {
66  m_undoStack = new QUndoStack();
67  }
68 
69  return m_undoStack;
70 }
71 
72 const std::vector<te::edit::Feature*>& te::edit::UndoStackManager::getAddWatches() const
73 {
74  return m_addWatches;
75 }
76 
78 {
79  m_addWatches.push_back(feature);
80 
81  //If a feature is changed in the middle of the stack, this change ends up being the top of the stack
82  if (m_currentIndex < (int)(m_addWatches.size() - 2))
83  {
84  std::size_t i = 0;
85  while (i < m_addWatches.size())
86  {
87  m_addWatches.pop_back();
88  i = (m_currentIndex + 1);
89  }
90  m_addWatches.push_back(feature);
91  }
92 
93  m_currentIndex = (int)(m_addWatches.size() - 1);
94 }
95 
97 {
99 
100  m_addWatches.clear();
101 
102  m_undoStack->clear();
103 }
QUndoStack * getUndoStack()
Method that return stack of Undo/Redo.
~UndoStackManager()
Singleton destructor.
void addWatch(Feature *feature)
const std::vector< Feature * > & getAddWatches() const
std::vector< Feature * > m_addWatches
void addUndoStack(QUndoCommand *command)
Method that insert command Undo/Redo of type AddCommand in the Undo/Redo stack.
UndoStackManager()
It initializes the singleton instance of the repository manager.
QUndoStack * m_undoStack
Undo/Redo stack.
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
Definition: BoostUtils.h:55