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 #ifndef TIKZ_CORE_ENTITY_H 0021 #define TIKZ_CORE_ENTITY_H 0022 0023 #include "ConfigObject.h" 0024 #include "tikz.h" 0025 #include "Uid.h" 0026 0027 #include <memory> 0028 #include <QObject> 0029 #include <QJsonObject> 0030 0031 namespace tikz { 0032 namespace core { 0033 0034 class Document; 0035 class EntityPrivate; 0036 0037 class TIKZKITCORE_EXPORT Entity : public ConfigObject 0038 { 0039 Q_OBJECT 0040 Q_PROPERTY(Uid uid READ uid) 0041 0042 public: 0043 /** 0044 * Default constructor. 0045 * Creates a default entity with uid set to -1 and no associated Document. 0046 */ 0047 Entity(); 0048 0049 /** 0050 * Virtual destructor. 0051 */ 0052 virtual ~Entity(); 0053 0054 /** 0055 * Returns the unique entity identifier in terms of a Uid. 0056 * The uid().id() is the same as id(). However, the Uid also passes 0057 * information about the type of the object through Uid::type(). 0058 */ 0059 Uid uid() const; 0060 0061 /** 0062 * Returns the EntityType. 0063 */ 0064 virtual tikz::EntityType entityType() const = 0; 0065 0066 0067 /** 0068 * Returns the document, if passed to the constructor. 0069 */ 0070 Document * document() const; 0071 0072 public: 0073 /** 0074 * Helper function that returns true if the object name is empty. 0075 */ 0076 Q_INVOKABLE bool objectNameSet() const; 0077 0078 /** 0079 * Helper function that always returns true for the object name; 0080 */ 0081 Q_INVOKABLE void unsetObjectName(); 0082 0083 // 0084 // serialization 0085 // 0086 public: 0087 /** 0088 * Load the state from the @p json object. 0089 */ 0090 void load(const QJsonObject & json); 0091 0092 /** 0093 * Save the state to the json object. 0094 */ 0095 QJsonObject save() const; 0096 0097 protected: 0098 /** 0099 * Load the payload state from the @p json object. 0100 * The default implementation is empty. 0101 */ 0102 virtual void loadData(const QJsonObject & json); 0103 0104 /** 0105 * Save the payload state to the json object. 0106 * The default implementation is empty. 0107 */ 0108 virtual QJsonObject saveData() const; 0109 0110 // 0111 // internal to tikz::Document 0112 // 0113 protected: 0114 friend class Document; 0115 0116 /** 0117 * Associate this style with @p uid. The passed @p uid also 0118 * provides the associated tikz Document. 0119 */ 0120 explicit Entity(const Uid & uid); 0121 0122 private: 0123 std::unique_ptr<EntityPrivate> const d; 0124 }; 0125 0126 } 0127 } 0128 #endif // TIKZ_CORE_ENTITY_H 0129 0130 // kate: indent-width 4; replace-tabs on;