File indexing completed on 2024-05-26 04:38:26

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