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_METAPOS_H 0021 #define TIKZ_METAPOS_H 0022 0023 #include "tikz.h" 0024 #include "tikz_export.h" 0025 #include "Pos.h" 0026 0027 #include <QSharedPointer> 0028 0029 namespace tikz { 0030 namespace core { 0031 0032 class MetaPos; 0033 class MetaPosPrivate; 0034 class Node; 0035 class Document; 0036 0037 /** 0038 * MetaPos represents a position in the TikZ scene. 0039 * This position may either be a simple coordinate, or a node. 0040 * In case of a node, the anchor additionally takes effect. 0041 */ 0042 class TIKZKITCORE_EXPORT MetaPos 0043 { 0044 // 0045 // types 0046 // 0047 public: 0048 /** 0049 * Define a shared pointer for MetaPos. 0050 * 0051 * MetaPos is designed to be passed by value (value semantics). 0052 * However, sometimes a pointer type is needed, e.g. if a MetaPos is 0053 * returned by a function. In that case, using a MetaPos::Ptr allows to 0054 * safely return a pointer type without risting memory leaks. 0055 * 0056 * The MetaPos::Ptr typedef deletes the MetaPos object automatically if 0057 * no reference to the object exists anymore. 0058 */ 0059 typedef QSharedPointer<tikz::core::MetaPos> Ptr; 0060 0061 public: 0062 /** 0063 * Constructor. 0064 * The @p document should be a valid pointer, otherwise the behaviour 0065 * is undefined. 0066 */ 0067 MetaPos(Document * document); 0068 0069 /** 0070 * Constructor that deserializes this position from @p str. 0071 * The @p document should be a valid pointer, otherwise the behaviour 0072 * is undefined. 0073 */ 0074 MetaPos(const QString & str, Document * document); 0075 0076 /** 0077 * Copy constructor. 0078 * 0079 * Copies all data except the signal and slot connections. 0080 */ 0081 MetaPos(const MetaPos & pos); 0082 0083 /** 0084 * Non-virtual destructor. 0085 */ 0086 ~MetaPos(); 0087 0088 /** 0089 * Get the associated Document. 0090 */ 0091 Document * document() const; 0092 0093 /** 0094 * Convert this MetaPos to a string. 0095 * Possible forms are 0096 * - "(3cm, 6cm)", "(20.033pt, -12pt)" for simple scene coordinates. 0097 * - "(1)" for nodes 0098 * - "(4.north east)" for nodes with anchors. 0099 */ 0100 QString toString() const; 0101 0102 /** 0103 * Set this MetaPos from @p str by converting the string. 0104 */ 0105 void fromString(const QString & str); 0106 0107 // 0108 // operators 0109 // 0110 public: 0111 /** 0112 * Assignment operator. 0113 * The assignment operator copies all data. The notification object 0114 * as well as its connection remain unchanged. 0115 */ 0116 MetaPos & operator=(const MetaPos & other); 0117 0118 /** 0119 * Check for equality of this object with @p other. 0120 */ 0121 bool operator==(const MetaPos & other) const; 0122 0123 /** 0124 * Check for inequality of this object with @p other. 0125 */ 0126 bool operator!=(const MetaPos & other) const; 0127 0128 // 0129 // x/y-position methods 0130 // 0131 public: 0132 /** 0133 * Get the coordinate of this node. 0134 * If no Node is associated, the position set with setPos() is returned. 0135 * If node() is non-null, node()->pos() is returned. 0136 */ 0137 tikz::Pos pos() const; 0138 0139 /** 0140 * Set the coordinates to @p pos. 0141 * Calling this function emits changed(), if @p pos != pos(). 0142 */ 0143 void setPos(const tikz::Pos & pos); 0144 0145 // 0146 // Node methods 0147 // 0148 public: 0149 /** 0150 * Get the Node of this MetaPos. 0151 * The return value may be 0. 0152 */ 0153 Node* node() const; 0154 0155 /** 0156 * Set the node to @p node. 0157 * Calling this function emits changed(), if @p pos != pos(). 0158 * @return @p true, if the node changed, otherwise @p false. 0159 */ 0160 bool setNode(Node * node); 0161 0162 /** 0163 * Get the anchor of this pos. 0164 * The return value may be 0. 0165 */ 0166 QString anchor() const; 0167 0168 /** 0169 * Set the anchor of this node to @p anchor. 0170 */ 0171 void setAnchor(const QString & anchor); 0172 0173 // 0174 // Notification object 0175 // 0176 public: 0177 /** 0178 * Call this function to get the notification object. 0179 * The notification object is a QObject that emits the signal 0180 * \p void changed(MetaPos * metaPos). 0181 * 0182 * Connect to this object if you need to get change signals. 0183 */ 0184 QObject * notificationObject(); 0185 0186 private: 0187 /** 0188 * Disable default constructor. 0189 */ 0190 MetaPos() = delete; 0191 0192 /** 0193 * Private data pointer. 0194 */ 0195 MetaPosPrivate * const d; 0196 }; 0197 0198 } 0199 } 0200 0201 namespace QTest 0202 { 0203 // forward declaration of template in qtestcase.h 0204 template<typename T> char* toString(const T&); 0205 0206 template<> 0207 TIKZKITCORE_EXPORT char *toString(const tikz::core::MetaPos & metaPos); 0208 } 0209 0210 #endif // TIKZ_METAPOS_H 0211 0212 // kate: indent-width 4; replace-tabs on;