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

0001 /* This file is part of the TikZKit project.
0002  *
0003  * Copyright (C) 2013-2014 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_SERIALIZE_VISITOR_H
0021 #define TIKZ_SERIALIZE_VISITOR_H
0022 
0023 #include "Visitor.h"
0024 #include <QJsonObject>
0025 
0026 namespace tikz {
0027 namespace core {
0028 
0029 /**
0030  * Visitor pattern.
0031  * Visits all elements of a tikz::core::Document.
0032  */
0033 class SerializeVisitor : public Visitor
0034 {
0035     public:
0036         /**
0037          * Default constructor.
0038          */
0039         SerializeVisitor();
0040 
0041         /**
0042          * Destructor
0043          */
0044         virtual ~SerializeVisitor();
0045 
0046     //
0047     // extra functions
0048     //
0049     public:
0050         /**
0051          * Save the tikz::Document to the file @p filename.
0052          * @return true on success, otherwise false
0053          */
0054         bool save(const QString & filename);
0055 
0056     //
0057     // Visitor pattern
0058     //
0059     public:
0060         /**
0061          * Serializes document @p doc document.
0062          */
0063         void visit(Document * doc) override;
0064 
0065         /**
0066          * Serializes @p node.
0067          */
0068         void visit(Node * node) override;
0069 
0070         /**
0071          * Serializes @p path.
0072          */
0073         void visit(Path * path) override;
0074 
0075         /**
0076          * Serializes @p style.
0077          */
0078         void visit(Style * style) override;
0079 
0080     //
0081     // private data
0082     //
0083     private:
0084         QJsonObject m_root;
0085         QJsonObject m_nodes;
0086         QJsonObject m_paths;
0087         QJsonObject m_styles;
0088 };
0089 
0090 }
0091 }
0092 
0093 #endif // TIKZ_SERIALIZE_VISITOR_H
0094 
0095 // kate: indent-width 4; replace-tabs on;