File indexing completed on 2024-04-14 04:00:17

0001 /***************************************************************************
0002                                cmapcmdelementcreate.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 "cmapcmdelementcreate.h"
0019 
0020 
0021 #include "cmapelement.h"
0022 #include "cmapmanager.h"
0023 #include "cmaplevel.h"
0024 #include "cmaproom.h"
0025 #include "cmappath.h"
0026 
0027 #include "cmapcmdelementproperties.h"
0028 
0029 #include <KLocalizedString>
0030 #include <QDebug>
0031 
0032 CMapCmdElementCreate::CMapCmdElementCreate(CMapManager *mapManager,QString name) : CMapCommand(name),CMapElementUtil(mapManager)
0033 {
0034     manager = mapManager;
0035     properties = new KMemConfig();
0036     groups = 0;
0037         executed = false;
0038 }
0039 
0040 CMapCmdElementCreate::~CMapCmdElementCreate()
0041 {
0042     delete properties;
0043 }
0044 
0045 QList<CMapElement *> *CMapCmdElementCreate::getElements()
0046 {
0047   if (!executed) qWarning() << "CMapCmdElementCreate::getElements called without actually executing the command, this will not work!";
0048 
0049   return &elements;
0050 }
0051 
0052 void CMapCmdElementCreate::redo()
0053 {
0054     QStringList groupList = properties->groupList();
0055     elements.clear();
0056 
0057     for (QStringList::Iterator it = groupList.begin(); it != groupList.end(); ++it)
0058     {
0059         if (*it != "<default>")
0060         {
0061             CMapElement *element = createElement(properties->group (*it));
0062             if (element) elements.append(element);
0063         }
0064     }
0065         executed = true;
0066 }
0067 
0068 void CMapCmdElementCreate::undo()
0069 {
0070     QStringList groupList = properties->groupList();
0071 
0072     for (QStringList::Iterator it = groupList.begin(); it != groupList.end(); ++it)
0073     {
0074         if (*it != "<default>")
0075         {
0076             deleteElement(properties->group(*it));
0077         }
0078     }   
0079 
0080     elements.clear();
0081         executed = false;
0082 }
0083 
0084 void CMapCmdElementCreate::addElement(KMemConfig *newElementProperties,QString grp)
0085 {
0086   KConfigGroup group = properties->group(QString::number(groups++));
0087   newElementProperties->group(grp).copyTo(&group);
0088 }
0089