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

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 "UndoItem.h"
0021 #include "Document.h"
0022 
0023 namespace tikz {
0024 namespace core {
0025 
0026 class UndoItemPrivate {
0027 public:
0028     /**
0029      * Pointer to the document of this undo/redo item.
0030      */
0031     Document* doc = nullptr;
0032 
0033     /**
0034      * Pointer to the UndoGroup this UndoItem belongs to.
0035      */
0036     UndoGroup * group = nullptr;
0037 
0038     /**
0039      * Description of the undo item.
0040      */
0041     QString text;
0042 };
0043 
0044 UndoItem::UndoItem(const QString & text, Document* doc)
0045     : d(new UndoItemPrivate())
0046 {
0047     d->doc = doc;
0048     d->text = text;
0049 }
0050 
0051 UndoItem::~UndoItem()
0052 {
0053     delete d;
0054 }
0055 
0056 Document* UndoItem::document()
0057 {
0058     return d->doc;
0059 }
0060 
0061 void UndoItem::setText(const QString & text)
0062 {
0063     d->text = text;
0064 }
0065 
0066 QString UndoItem::text() const
0067 {
0068     return d->text;
0069 }
0070 
0071 int UndoItem::id() const
0072 {
0073     return -1;
0074 }
0075 
0076 bool UndoItem::mergeWith(const UndoItem * item)
0077 {
0078     Q_UNUSED(item)
0079     return false;
0080 }
0081 
0082 void UndoItem::load(const QJsonObject & json)
0083 {
0084     // TODO, FIXME
0085 
0086     // load payload
0087     QJsonObject joData = json["data"].toObject();
0088     loadData(joData);
0089 }
0090 
0091 QJsonObject UndoItem::save() const
0092 {
0093     QJsonObject json;
0094 
0095     // TODO, FIXME
0096 
0097     // save payload
0098     json["data"] = saveData();
0099 
0100     return json;
0101 
0102 }
0103 
0104 UndoGroup * UndoItem::group() const
0105 {
0106     return d->group;
0107 }
0108 
0109 void UndoItem::setGroup(UndoGroup * group)
0110 {
0111     d->group = group;
0112 }
0113 
0114 namespace {
0115     int freeId = 0;
0116 }
0117 
0118 int UndoItem::nextFreeId()
0119 {
0120     return freeId++;
0121 }
0122 
0123 }
0124 }
0125 
0126 // kate: indent-width 4; replace-tabs on;