File indexing completed on 2024-04-21 04:03:06

0001 /***************************************************************************
0002                                cmapcmdelementproperties.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 "cmapcmdelementproperties.h"
0019 
0020 #include "cmapelement.h"
0021 #include "cmapmanager.h"
0022 #include "cmaplevel.h"
0023 #include "cmaproom.h"
0024 
0025 CMapCmdElementProperties::CMapCmdElementProperties(CMapManager *mapManager,QString name,CMapElement *element) : CMapCommand(name)
0026 {
0027     m_manager = mapManager;
0028     m_properties = new KMemConfig;
0029     element->saveProperties(m_properties->group("Element"));
0030 }
0031 
0032 CMapCmdElementProperties::~CMapCmdElementProperties()
0033 {
0034     delete m_properties;
0035 }
0036 
0037 void CMapCmdElementProperties::redo()
0038 {
0039     int active = m_manager->getUndoActive();    
0040     m_manager->setUndoActive(false);
0041 
0042     CMapElement *elm = m_manager->findElement(m_properties->group("Element"));
0043 
0044     if (elm)
0045     {
0046         elm->loadProperties(m_properties->group("New"));
0047         m_manager->changedElement(elm);
0048     }
0049     m_manager->setUndoActive(active);
0050 }
0051 
0052 void CMapCmdElementProperties::undo()
0053 {
0054     int active = m_manager->getUndoActive();    
0055     m_manager->setUndoActive(false);
0056 
0057     CMapElement *elm = m_manager->findElement(m_properties->group("Element"));
0058 
0059     if (elm)
0060     {
0061         elm->loadProperties(m_properties->group("Old"));
0062         m_manager->changedElement(elm);
0063     }
0064     m_manager->setUndoActive(active);
0065 }
0066 
0067 KConfigGroup CMapCmdElementProperties::getOrgProperties(void)
0068 {
0069     return m_properties->group("Old");
0070 }
0071 
0072 KConfigGroup CMapCmdElementProperties::getNewProperties(void)
0073 {
0074     return m_properties->group("New");
0075 }
0076 
0077 void CMapCmdElementProperties::setNewProperties(KConfigGroup newProperties)
0078 {
0079   KConfigGroup grp = m_properties->group("New");
0080   newProperties.copyTo(&grp);
0081 }
0082 
0083 void CMapCmdElementProperties::setOldProperties(KConfigGroup oldProperties)
0084 {
0085   KConfigGroup grp = m_properties->group("Old");
0086   oldProperties.copyTo(&grp);
0087 }
0088 
0089 /** Used to store check if the values are different and store then if they are */
0090 void CMapCmdElementProperties::compare(QString id,QString orgValue,QString dialogValue)
0091 {
0092     if (orgValue!=dialogValue)
0093     {
0094         m_properties->group("Old").writeEntry(id,orgValue);
0095         m_properties->group("New").writeEntry(id,dialogValue);
0096     }
0097 }
0098 
0099 /** Used to store check if the values are different and store then if they are */
0100 void CMapCmdElementProperties::compare(QString id,bool orgValue,bool dialogValue)
0101 {
0102     if (orgValue!=dialogValue)
0103     {
0104         m_properties->group("Old").writeEntry(id,orgValue);
0105         m_properties->group("New").writeEntry(id,dialogValue);
0106     }
0107 }
0108 
0109 /** Used to store check if the values are different and store then if they are */
0110 void CMapCmdElementProperties::compare(QString id,int orgValue,int dialogValue)
0111 {
0112     if (orgValue!=dialogValue)
0113     {
0114         m_properties->group("Old").writeEntry(id,orgValue);
0115         m_properties->group("New").writeEntry(id,dialogValue);
0116     }
0117 }
0118 
0119 /** Used to store check if the values are different and store then if they are */
0120 void CMapCmdElementProperties::compare(QString id,QColor orgValue,QColor dialogValue)
0121 {
0122     if (orgValue!=dialogValue)
0123     {
0124         m_properties->group("Old").writeEntry(id,orgValue);
0125         m_properties->group("New").writeEntry(id,dialogValue);
0126     }
0127 }
0128 
0129 /** Used to store check if the values are different and store then if they are */
0130 void CMapCmdElementProperties::compare(QString id,QStringList orgValue,QStringList dialogValue)
0131 {
0132     if (orgValue!=dialogValue)
0133     {
0134         m_properties->group("Old").writeEntry(id,orgValue);
0135         m_properties->group("New").writeEntry(id,dialogValue);
0136     }
0137 }
0138 
0139 /** Used to store check if the values are different and store then if they are */
0140 void CMapCmdElementProperties::compare(QString id,QFont orgValue,QFont dialogValue)
0141 {
0142     if (orgValue!=dialogValue)
0143     {
0144         m_properties->group("Old").writeEntry(id,orgValue);
0145         m_properties->group("New").writeEntry(id,dialogValue);
0146     }
0147 }
0148 
0149 /** Used to store check if the values are different and store then if they are */
0150 void CMapCmdElementProperties::compare(QString id,QSize orgValue,QSize dialogValue)
0151 {
0152     if (orgValue!=dialogValue)
0153     {
0154         m_properties->group("Old").writeEntry(id,orgValue);
0155         m_properties->group("New").writeEntry(id,dialogValue);
0156     }
0157 }
0158