File indexing completed on 2024-05-19 04:36:20

0001 /* This file is part of the TikZKit project.
0002  *
0003  * Copyright (C) 2013-2015 Dominik Haumann <dhaumann@kde.org>
0004  *
0005  * This library is free software; you can redistribute it and/or modify
0006  * it under the terms of the GNU Library General Public License as published
0007  * by the Free Software Foundation, either version 2 of the License, or
0008  * (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  * GNU Library General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Library General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, see
0017  * <http://www.gnu.org/licenses/>.
0018  */
0019 
0020 #include "UndoCreateEntity.h"
0021 #include "Document.h"
0022 
0023 namespace tikz {
0024 namespace core {
0025 
0026 UndoCreateEntity::UndoCreateEntity(Document * doc)
0027     : UndoItem("Create Entity", doc)
0028 {
0029 }
0030 
0031 UndoCreateEntity::UndoCreateEntity(const Uid & uid, EntityType type, Document * doc)
0032     : UndoItem("Create Entity", doc)
0033     , m_uid(uid)
0034     , m_entityType(type)
0035 {
0036 }
0037 
0038 UndoCreateEntity::~UndoCreateEntity() = default;
0039 
0040 void UndoCreateEntity::undo()
0041 {
0042     document()->deleteEntity(m_uid);
0043 }
0044 
0045 void UndoCreateEntity::redo()
0046 {
0047     document()->createEntity(m_uid, m_entityType);
0048 }
0049 
0050 void UndoCreateEntity::loadData(const QJsonObject & json)
0051 {
0052     m_uid = Uid(json["uid"].toString(), document());
0053     m_entityType = toEntityType(json["type"].toString());
0054 }
0055 
0056 QJsonObject UndoCreateEntity::saveData() const
0057 {
0058     QJsonObject json;
0059     json["uid"] = m_uid.toString();
0060     json["type"] = toString(m_entityType);
0061     return json;
0062 }
0063 
0064 }
0065 }
0066 
0067 // kate: indent-width 4; replace-tabs on;