File indexing completed on 2024-12-01 06:51:42

0001 /***************************************************************************
0002                                cmapcmdgroup.cpp
0003                              -------------------
0004     begin                : Wed Feb 27 2002
0005     copyright            : (C) 2002 by Kmud Developer Team
0006     email                : kmud-devel@kmud.de
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *                                                                         *
0011  *   This program is free software; you can redistribute it and/or modify  *
0012  *   it under the terms of the GNU General Public License as published by  *
0013  *   the Free Software Foundation; either version 2 of the License, or     *
0014  *   (at your option) any later version.                                   *
0015  *                                                                         *
0016  ***************************************************************************/
0017 
0018 #include "cmapcmdgroup.h"
0019 
0020 #include "cmapmanager.h"
0021 
0022 CMapCmdGroup::CMapCmdGroup(CMapManager *mapManager,QString name) : CMapCommand(name)
0023 {
0024 m_mapManager = mapManager;
0025 }
0026 
0027 CMapCmdGroup::~CMapCmdGroup()
0028 {
0029   foreach (CMapCommand *cmd, commands)
0030     delete cmd;
0031 }
0032 
0033 void CMapCmdGroup::redo()
0034 {
0035   foreach (CMapCommand *c, commands)
0036     c->redo();
0037 }
0038 
0039 void CMapCmdGroup::undo()
0040 {
0041   m_mapManager->setUndoActive(false);
0042 
0043   // undo must go in reverse order, so that the last performed action is the first restored ones. This is because the preceeding actions may rely on the changed done by the following actions not yet having been done.
0044   for (int idx = commands.count() - 1; idx >= 0; --idx)
0045     commands.at(idx)->undo();
0046 
0047   m_mapManager->setUndoActive(true);
0048 }
0049 
0050 
0051 void CMapCmdGroup::addCommand(CMapCommand *command)
0052 {
0053   commands.append(command);
0054 }
0055 
0056 void CMapCmdGroup::setPreviousGroup(CMapCmdGroup *group)
0057 {
0058   previousGroup = group;
0059 }
0060 
0061 CMapCmdGroup *CMapCmdGroup::getPreviousGroup(void)
0062 {
0063   return previousGroup;
0064 }
0065