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

0001 /* This file is part of the TikZKit project.
0002  *
0003  * Copyright (C) 2013-2018 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_PROPERTY_H
0021 #define TIKZ_UNDO_SET_PROPERTY_H
0022 
0023 #include "tikz_export.h"
0024 #include "UndoItem.h"
0025 #include "Entity.h"
0026 
0027 namespace tikz {
0028 namespace core {
0029 
0030 class Node;
0031 class Document;
0032 
0033 class TIKZKITCORE_EXPORT UndoSetProperty : public UndoItem
0034 {
0035     public:
0036         /**
0037          * Constructor.
0038          */
0039         UndoSetProperty(Document * doc);
0040 
0041         /**
0042          * Constructor.
0043          */
0044         UndoSetProperty(const Uid & entityUid, const QString & propertyName, const QVariant & newValue);
0045 
0046         /**
0047          * Destructor
0048          */
0049         virtual ~UndoSetProperty();
0050 
0051         /**
0052          * Return uniq undo item id.
0053          */
0054         int id() const override {
0055             return uniqId<decltype(this)>();
0056         }
0057 
0058         /**
0059          * Undo: add node again.
0060          */
0061         void undo() override;
0062 
0063         /**
0064          * Redo: delete node again.
0065          */
0066         void redo() override;
0067 
0068         /**
0069          * Merge undo items, if possible.
0070          */
0071         bool mergeWith(const UndoItem * command) override;
0072 
0073 protected:
0074         /**
0075         * Load the undo item state from the @p json object.
0076         */
0077         void loadData(const QJsonObject & json) override;
0078 
0079         /**
0080          * Serializie to JSON object.
0081          */
0082         QJsonObject saveData() const override;
0083 
0084     private:
0085         /**
0086          * The unique Entity id.
0087          */
0088         Uid m_entityUid;
0089 
0090         /**
0091          * The property name.
0092          */
0093         QString m_propertyName;
0094 
0095         /**
0096          * The old value of the property.
0097          * If the property was not set, this holds an invalid QVariant().
0098          */
0099         QVariant m_undoValue;
0100 
0101         /**
0102          * The new value of the property.
0103          */
0104         QVariant m_redoValue;
0105 };
0106 
0107 }
0108 }
0109 
0110 #endif // TIKZ_UNDO_SET_PROPERTY_H
0111 
0112 // kate: indent-width 4; replace-tabs on;