File indexing completed on 2024-06-16 04:21:01

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 "UndoSetEllipsePos.h"
0021 #include "Document.h"
0022 #include "EllipsePath.h"
0023 
0024 namespace tikz {
0025 namespace core {
0026 
0027 UndoSetEllipsePos::UndoSetEllipsePos(Document * doc)
0028     : UndoItem("Set Ellipse Position", doc)
0029     , m_undoPos(doc)
0030     , m_redoPos(doc)
0031 {
0032 }
0033 
0034 UndoSetEllipsePos::UndoSetEllipsePos(EllipsePath * path,
0035                                      const MetaPos & newPos,
0036                                      Document * doc)
0037     : UndoItem("Set Ellipse Position", doc)
0038     , m_pathUid(path->uid())
0039     , m_undoPos(path->metaPos())
0040     , m_redoPos(newPos)
0041 {
0042 }
0043 
0044 UndoSetEllipsePos::~UndoSetEllipsePos()
0045 {
0046 }
0047 
0048 void UndoSetEllipsePos::undo()
0049 {
0050     auto path = m_pathUid.entity<EllipsePath>();
0051     Q_ASSERT(path != nullptr);
0052 
0053     path->setMetaPos(m_undoPos);
0054 }
0055 
0056 void UndoSetEllipsePos::redo()
0057 {
0058     auto path = m_pathUid.entity<EllipsePath>();
0059     Q_ASSERT(path != nullptr);
0060 
0061     path->setMetaPos(m_redoPos);
0062 }
0063 
0064 bool UndoSetEllipsePos::mergeWith(const UndoItem * command)
0065 {
0066     auto other = static_cast<const UndoSetEllipsePos*>(command);
0067     if (m_pathUid != other->m_pathUid) {
0068         return false;
0069     }
0070 
0071     m_redoPos = other->m_redoPos;
0072     return true;
0073 }
0074 
0075 void UndoSetEllipsePos::loadData(const QJsonObject & json)
0076 {
0077     m_pathUid = Uid(json["uid"].toString(), document());
0078     m_redoPos = MetaPos(json["pos"].toString(), document());
0079 }
0080 
0081 QJsonObject UndoSetEllipsePos::saveData() const
0082 {
0083     QJsonObject json;
0084     json["type"] = "ellipse-set-pos";
0085     json["uid"] = m_pathUid.toString();
0086     json["pos"] = m_redoPos.toString();
0087     return json;
0088 }
0089 
0090 }
0091 }
0092 // kate: indent-width 4; replace-tabs on;