Syncing libavogadro/src/* with 0.6.1
[kdeedu-porting.git] / kalzium / libavogadro-kalzium / src / undosequence.cpp
blob56ff37ec2dbb9cb35bd3b554a7493b8f5b2db196
1 /**********************************************************************
2 UndoSequence - Provides an sequence of Undo/Redo in a single command
4 Copyright (C) 2007 Donald Ephraim Curtis
6 This file is part of the Avogadro molecular editor project.
7 For more information, see <http://avogadro.sourceforge.net/>
9 Avogadro is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 Avogadro is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 02110-1301, USA.
23 **********************************************************************/
25 #include <config.h>
26 #include <avogadro/undosequence.h>
28 namespace Avogadro {
30 class UndoSequencePrivate {
31 public:
32 UndoSequencePrivate() {};
34 QList<QUndoCommand *> commands;
37 UndoSequence::UndoSequence() : d(new UndoSequencePrivate)
41 UndoSequence::~UndoSequence()
43 while(!d->commands.isEmpty()) {
44 delete d->commands.takeFirst();
46 delete d;
49 void UndoSequence::undo()
51 // last in first to undo
52 for(int i=d->commands.count()-1; i >= 0; i--)
54 d->commands.at(i)->undo();
58 void UndoSequence::redo()
60 foreach(QUndoCommand *command, d->commands)
62 command->redo();
66 void UndoSequence::append(QUndoCommand *command)
68 d->commands.append(command);
71 } // end namespace Avogadro