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_NODE_H 0021 #define TIKZ_NODE_H 0022 0023 #include "Entity.h" 0024 #include "tikz.h" 0025 #include "Pos.h" 0026 0027 #include <QString> 0028 #include <QVariant> 0029 0030 namespace tikz { 0031 namespace core { 0032 0033 class NodePrivate; 0034 class Style; 0035 class Document; 0036 class Visitor; 0037 class MetaPos; 0038 0039 class TIKZKITCORE_EXPORT Node : public Entity 0040 { 0041 Q_OBJECT 0042 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) 0043 Q_PROPERTY(tikz::Pos pos READ pos WRITE setPos) 0044 Q_PROPERTY(Uid style READ styleUid WRITE setStyle) 0045 0046 public: 0047 /** 0048 * Destructor 0049 */ 0050 virtual ~Node(); 0051 0052 /** 0053 * Returns EntityType::Node. 0054 */ 0055 tikz::EntityType entityType() const override; 0056 0057 // 0058 // visitor pattern 0059 // 0060 public: 0061 /** 0062 * Visitor pattern. 0063 * Visits all elements of the document. 0064 */ 0065 bool accept(Visitor & visitor); 0066 0067 // 0068 // serialization 0069 // 0070 public: 0071 /** 0072 * Load the state from the @p json object. 0073 */ 0074 void loadData(const QJsonObject & json) override; 0075 0076 /** 0077 * Save the state to the json object. 0078 */ 0079 QJsonObject saveData() const override; 0080 0081 // 0082 // position, style and text 0083 // 0084 public Q_SLOTS: 0085 /** 0086 * Set the coordinates to @p pos. 0087 * @see pos(), setMetaPos() 0088 */ 0089 void setPos(const tikz::Pos& pos); 0090 0091 /** 0092 * Set the Node's MetaPos to @p pos. 0093 * @see setPos() 0094 */ 0095 void setMetaPos(const tikz::core::MetaPos & pos); 0096 0097 /** 0098 * Sets the text of this node to @p text. 0099 */ 0100 void setText(const QString& text); 0101 0102 public: 0103 /** 0104 * Set the coordinates to @p pos. 0105 * @see pos() 0106 */ 0107 tikz::Pos pos() const; 0108 0109 /** 0110 * Get the position of this ellipse as MetaPos object. 0111 */ 0112 const tikz::core::MetaPos & metaPos() const; 0113 0114 /** 0115 * Returns the text of this node. 0116 */ 0117 QString text() const; 0118 0119 /** 0120 * Get the Style object of this node. 0121 * The returned style is always a valid pointer. 0122 */ 0123 Style * style() const; 0124 0125 /** 0126 * Get the Style object of this node. 0127 */ 0128 Uid styleUid() const; 0129 0130 /** 0131 * Set the internal style of this node to @p uid. 0132 * If the node previously had a valid 0133 */ 0134 void setStyle(const Uid & styleUid); 0135 0136 Q_SIGNALS: 0137 /** 0138 * This signal is emitted whenever this node's text changed. 0139 */ 0140 void textChanged(const QString& text); 0141 0142 // 0143 // internal to tikz::Document 0144 // 0145 protected: 0146 friend class Document; 0147 0148 /** 0149 * Constructor that associates this node with the tikz Document 0150 * referred to by @p nodeUid. 0151 * @param nodeUid unique id of the node 0152 * @param styleUid unique id of the style this 0153 */ 0154 Node(const Uid & nodeUid); 0155 0156 private: 0157 /** 0158 * private default constructor, not implemented 0159 */ 0160 Node(); 0161 0162 private: 0163 NodePrivate * const d; 0164 }; 0165 0166 } 0167 } 0168 0169 #endif // TIKZ_NODE_H 0170 0171 // kate: indent-width 4; replace-tabs on;