File indexing completed on 2024-05-12 04:35:03

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 #ifndef TIKZ_UNDO_SET_NODE_POS_H
0021 #define TIKZ_UNDO_SET_NODE_POS_H
0022 
0023 #include "UndoItem.h"
0024 #include "MetaPos.h"
0025 #include "Uid.h"
0026 
0027 namespace tikz {
0028 namespace core {
0029 
0030 class Node;
0031 class Document;
0032 
0033 class UndoSetNodePos : public UndoItem
0034 {
0035     public:
0036         /**
0037          * Constructor.
0038          */
0039         UndoSetNodePos(Document * doc);
0040 
0041         /**
0042          * Constructor.
0043          */
0044         UndoSetNodePos(Node * node,
0045                        const tikz::core::MetaPos & newPos,
0046                        Document * doc);
0047 
0048         /**
0049          * Destructor.
0050          */
0051         virtual ~UndoSetNodePos();
0052 
0053         /**
0054          * Return uniq undo item id.
0055          */
0056         int id() const override {
0057             return uniqId<decltype(this)>();
0058         }
0059 
0060         /**
0061          * Undo: delete node again.
0062          */
0063         void undo() override;
0064 
0065         /**
0066          * Redo: create node again.
0067          */
0068         void redo() override;
0069 
0070         /**
0071          * Merge undo items, if possible.
0072          */
0073         bool mergeWith(const UndoItem * command) override;
0074 
0075     protected:
0076         /**
0077          * Load the undo item state from the @p json object.
0078          */
0079         void loadData(const QJsonObject & json) override;
0080 
0081         /**
0082          * Serializie to JSON object.
0083          */
0084         QJsonObject saveData() const override;
0085 
0086     private:
0087         /**
0088          * The unique Node id.
0089          */
0090         Uid m_nodeUid;
0091 
0092         /**
0093          * Undo position.
0094          */
0095         tikz::core::MetaPos m_undoPos;
0096 
0097         /**
0098          * Redo position.
0099          */
0100         tikz::core::MetaPos m_redoPos;
0101 };
0102 
0103 }
0104 }
0105 
0106 #endif // TIKZ_UNDO_SET_NODE_POS_H
0107 
0108 // kate: indent-width 4; replace-tabs on;