Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYActionManager.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14  */
15 
21 // Added by qt3to4:
22 #include <QList>
23 
26 #include "TYActionManager.h"
27 
28 TYActionManager::TYActionManager(int size) : _current(-1), _savedAt(-1), _size(size), _modified(false) {}
29 
31 {
32  while (!_history.isEmpty())
33  {
34  delete _history.takeFirst();
35  }
36 }
37 
39 {
40  if (_current < (int)_history.count() - 1)
41  {
42  if (_current < _savedAt)
43  {
44  _savedAt = -2;
45  }
46 
47  QList<TYAction*> actions;
48 
49  for (int i = 0; i <= _current; ++i)
50  {
51  actions.insert(i, _history.at(0));
52  _history.takeAt(0);
53  }
54 
55  actions.append(pAction);
56  while (!_history.isEmpty())
57  {
58  delete _history.takeFirst();
59  }
60  _history = actions;
61  }
62  else
63  {
64  _history.append(pAction);
65  }
66 
67  if ((int)_history.count() > _size)
68  {
69  _savedAt--;
70  _history.removeFirst();
71  }
72  else
73  {
74  ++_current;
75  }
76 
77  emitUndoRedo();
78  _modified = true;
80 }
81 
83 {
84  TYAction* undoAction = 0;
85  TYAction* redoAction = 0;
86 
87  if (_current >= 0 && _current < (int)_history.count())
88  {
89  undoAction = _history.at(_current);
90  }
91  if (_current + 1 >= 0 && _current + 1 < (int)_history.count())
92  {
93  redoAction = _history.at(_current + 1);
94  }
95 
96  bool ua = (undoAction != 0);
97  QString uc;
98  if (ua)
99  {
100  uc = undoAction->getName();
101  }
102 
103  bool ra = (redoAction != 0);
104  QString rc;
105  if (ra)
106  {
107  rc = redoAction->getName();
108  }
109 
110  emit undoRedoChanged(ua, ra, uc, rc);
111 
112  TYMainWindow* pMW = getTYMainWnd();
113  if (pMW != NULL)
114  {
115  pMW->updateModelers();
116  }
117 }
118 
119 void TYActionManager::setModified(bool modified)
120 {
121  _modified = modified;
122 
123  if (!_modified)
124  {
125  _savedAt = _current;
126  }
127 
129 }
130 
132 {
133  if (_current > -1)
134  {
135  _history.at(_current)->undo();
136  --_current;
137  }
138 
139  emitUndoRedo();
142 }
143 
145 {
146  if (_current > -1)
147  {
148  if (_current < (int)_history.count() - 1)
149  {
150  ++_current;
151  _history.at(_current)->redo();
152  }
153  }
154  else
155  {
156  if (_history.count() > 0)
157  {
158  ++_current;
159  _history.at(_current)->redo();
160  }
161  }
162 
163  emitUndoRedo();
166 }
167 
169 {
170  _size = size;
171 
172  // On supprime les entrees en trop si la nouvelle taille est
173  // plus grande que la precedente
174  while ((int)_history.count() > _size)
175  {
176  _savedAt--;
177  _history.removeLast();
178  _modified = true;
179  }
180 
181  // Trim au max si current depasse
182  _current = (_current > _size - 1) ? _size - 1 : _current;
183 
184  emitUndoRedo();
186 }
187 
189 {
190  while (!_history.isEmpty())
191  {
192  delete _history.takeFirst();
193  }
194 
195  _current = -1;
196  _savedAt = -1;
197  _modified = false;
198 
199  emitUndoRedo();
200  _modified = true;
202 }
Gere les undos (fichier header)
TYMainWindow * getTYMainWnd()
Retourne le pointeur sur la fenetre principale.
pour l'application Tympan (fichier header)
Fenetre principale de l'application Tympan (fichier header)
void reset()
Reinitialise l'historique.
void setModified(bool modified)
Set/Get de l'etat du manager.
void redo()
Effectue a nouveau la derniere action annulee.
bool _modified
Indique l'etat du manager.
int _size
Nombre maximum d'actions pour l'historique.
void modificationChanged(bool modified)
Indique si un undo ou un redo a ete fait.
int _savedAt
Index de l'action a laquelle une sauvegarde a ete effectuee.
void addAction(TYAction *pAction)
Ajoute une nouvelle action a l'historique.
void undo()
Annule la derniere action.
virtual ~TYActionManager()
Destructeur.
void emitUndoRedo()
Envoie un signal informant sur l'etat de ce ActionManager.
TYActionManager(int size)
Constructeur.
void setHistorySize(int size)
Definit la taille de l'historique.
QList< TYAction * > _history
L'historique des actions.
void undoRedoChanged(bool undoAvailable, bool redoAvailable, const QString &undoCmd, const QString &redoCmd)
Indique l'etat de ce ActionManager.
int _current
Index de l'action courante.
Definit une action, necessaire pour la gestion de l'undo.
Definition: TYAction.h:37
QString getName() const
Definition: TYAction.cpp:29
Fenetre principale de l'application Tympan.
Definition: TYMainWindow.h:53
void updateModelers(bool clipping=true, bool axesAndGrid=true, bool displayList=true)