File indexing completed on 2024-12-22 04:20:26
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_EDGE_PATH_H 0021 #define TIKZ_EDGE_PATH_H 0022 0023 #include "Path.h" 0024 #include "MetaPos.h" 0025 0026 #include "Pos.h" 0027 0028 namespace tikz { 0029 namespace core { 0030 0031 class Node; 0032 class EdgePathPrivate; 0033 0034 /** 0035 * This class represents a TikZ path with one single line element 0036 * from one coordinate/node to another coordinate/node. 0037 * 0038 * Examples are: 0039 * - Straight line: 0040 * \draw (a) -- (b); 0041 * - horizonal/vertical lines: 0042 * \draw (a) -| (b); 0043 * \draw (a) |- (b); 0044 * - bending curve 0045 * \draw (a) to[bend left=30] (b); 0046 * - ... 0047 */ 0048 class TIKZKITCORE_EXPORT EdgePath : public Path 0049 { 0050 Q_OBJECT 0051 0052 public: 0053 /** 0054 * Virtual destructor. 0055 */ 0056 virtual ~EdgePath(); 0057 0058 /** 0059 * Returns the element type of this edge. 0060 */ 0061 PathType type() const override; 0062 0063 /** 0064 * Get the start of this edge as a shared MetaPos object. 0065 * 0066 * @note This method is provided for convenience. 0067 * The returned shared pointer is a copy of position data. 0068 * Hence, modifying the returned MetaPos::Ptr does not change this object. 0069 */ 0070 const tikz::core::MetaPos & startMetaPos() const; 0071 0072 /** 0073 * Get the end of this edge as a shared MetaPos object. 0074 * 0075 * @note This method is provided for convenience. 0076 * The returned shared pointer is a copy of position data. 0077 * Hence, modifying the returned MetaPos::Ptr does not change this object. 0078 */ 0079 const tikz::core::MetaPos & endMetaPos() const; 0080 0081 // 0082 // Node start / end manipulation 0083 // 0084 public: 0085 0086 /** 0087 * Get the start node, which was set with setStart(Node*). 0088 */ 0089 Node* startNode() const; 0090 0091 /** 0092 * Get the end node, which was set with setEnd(Node*). 0093 */ 0094 Node* endNode(); 0095 0096 public Q_SLOTS: 0097 /** 0098 * Sets the start coordinate of the edge to @p node; 0099 */ 0100 void setStartNode(Node* node); 0101 0102 /** 0103 * Sets the end coordinate of the edge to @p node; 0104 */ 0105 void setEndNode(Node* node); 0106 0107 /** 0108 * Set the start position of this path to @p pos. 0109 */ 0110 void setStartMetaPos(const tikz::core::MetaPos & pos); 0111 0112 /** 0113 * Set the end position of this path to @p pos. 0114 */ 0115 void setEndMetaPos(const tikz::core::MetaPos & pos); 0116 0117 // 0118 // x/y-position methods 0119 // 0120 public: 0121 /** 0122 * Get the position of the current start node. 0123 * @note This is the same as startNode()->Pos(). 0124 */ 0125 tikz::Pos startPos() const; 0126 0127 /** 0128 * Set the position of the current end node. 0129 * @note This is the same as endNode()->pos(). 0130 */ 0131 tikz::Pos endPos() const; 0132 0133 public Q_SLOTS: 0134 /** 0135 * Set the position of the current start node to @p pos. 0136 * @param pos the new start position 0137 * @see complement: startPos() 0138 */ 0139 void setStartPos(const tikz::Pos & pos); 0140 0141 /** 0142 * Set the position of the current end node to @p pos. 0143 * @param pos the new end position 0144 * @see complement: endPos() 0145 */ 0146 void setEndPos(const tikz::Pos & pos); 0147 0148 // 0149 // anchor methods 0150 // 0151 public: 0152 /** 0153 * Get the anchor of the start of the edge. 0154 */ 0155 QString startAnchor() const; 0156 0157 /** 0158 * Get the anchor of the end of the edge. 0159 */ 0160 QString endAnchor() const; 0161 0162 public Q_SLOTS: 0163 /** 0164 * Set the anchor of the start of the edge to @p anchor. 0165 */ 0166 void setStartAnchor(const QString & anchor); 0167 0168 /** 0169 * Set the anchor of the end of the edge to @p anchor. 0170 */ 0171 void setEndAnchor(const QString & anchor); 0172 0173 // 0174 // signals 0175 // 0176 Q_SIGNALS: 0177 /** 0178 * This signal is emitted whenever the start node of this edge changes. 0179 * The node @p start may be 0. 0180 */ 0181 void startNodeChanged(tikz::core::Node * start); 0182 0183 /** 0184 * This signal is emitted whenever the end node of this edge changes. 0185 * The node @p start may be 0. 0186 */ 0187 void endNodeChanged(tikz::core::Node * start); 0188 0189 // 0190 // serialization 0191 // 0192 public: 0193 /** 0194 * Load the state from the @p json object. 0195 */ 0196 void loadData(const QJsonObject & json) override; 0197 0198 /** 0199 * Save the state to the json object. 0200 */ 0201 QJsonObject saveData() const override; 0202 0203 // 0204 // internal to tikz::core::Document 0205 // 0206 protected: 0207 friend class Document; 0208 0209 /** 0210 * Constructor that associates this path with the tikz Document 0211 * referred to by @p uid. 0212 * @param type Path type 0213 * @param uid unique id of the path 0214 */ 0215 EdgePath(PathType type, const Uid & uid); 0216 0217 /** 0218 * Destruct the node by saving the start and end pos or node connection. 0219 */ 0220 void deconstruct() override; 0221 0222 /** 0223 * Detach the edge from @p node, since @p node is about to be deleted. 0224 */ 0225 void detachFromNode(Node * node) override; 0226 0227 // 0228 // internal 0229 // 0230 private: 0231 /** 0232 * Private default constructor, not implemented 0233 */ 0234 EdgePath(); 0235 0236 private: 0237 EdgePathPrivate * const d; 0238 }; 0239 0240 } 0241 } 0242 0243 #endif // TIKZ_EDGE_PATH_H 0244 0245 // kate: indent-width 4; replace-tabs on;