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

0001 /* This file is part of the TikZKit project.
0002  *
0003  * Copyright (C) 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 "UndoFactory.h"
0021 #include "Document.h"
0022 
0023 #include "UndoCreateEntity.h"
0024 #include "UndoDeleteEntity.h"
0025 #include "UndoSetNodePos.h"
0026 #include "UndoSetEdgePos.h"
0027 #include "UndoSetEllipsePos.h"
0028 
0029 namespace tikz {
0030 namespace core {
0031 
0032 class UndoFactoryPrivate {
0033 public:
0034     /**
0035      * Pointer to the document of this undo/redo item.
0036      */
0037     Document* doc = nullptr;
0038 };
0039 
0040 UndoFactory::UndoFactory(Document* doc)
0041     : d(new UndoFactoryPrivate())
0042 {
0043     d->doc = doc;
0044 }
0045 
0046 UndoFactory::~UndoFactory()
0047 {
0048     delete d;
0049 }
0050 
0051 Document* UndoFactory::document()
0052 {
0053     return d->doc;
0054 }
0055 
0056 UndoItem * UndoFactory::createItem(const QString & type)
0057 {
0058     if (type.isEmpty()) {
0059         Q_ASSERT(false);
0060         return nullptr;
0061     }
0062 
0063     if (type == "entity-create") {
0064         return new UndoCreateEntity(document());
0065     } else if (type == "entity-delete") {
0066         return new UndoDeleteEntity(document());
0067     } else if (type == "node-set-pos") {
0068         return new UndoSetNodePos(document());
0069     } else if (type == "edge-set-pos") {
0070         return new UndoSetEdgePos(document());
0071     } else if (type == "ellipse-set-pos") {
0072         return new UndoSetEllipsePos(document());
0073     }
0074 
0075     Q_ASSERT(false);
0076     return nullptr;
0077 }
0078 
0079 }
0080 }
0081 
0082 // kate: indent-width 4; replace-tabs on;