File indexing completed on 2024-05-19 04:36:34
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_UI_DOCUMENT_PRIVATE_H 0021 #define TIKZ_UI_DOCUMENT_PRIVATE_H 0022 0023 #include "tikzui.h" 0024 #include "tikzui_export.h" 0025 0026 #include "Document.h" 0027 #include <tikz/core/MetaPos.h> 0028 0029 class QGraphicsView; 0030 0031 namespace tikz { 0032 namespace core { 0033 class Document; 0034 class Node; 0035 class Path; 0036 } 0037 0038 namespace ui { 0039 0040 class NodeItem; 0041 class PathItem; 0042 class TikzScene; 0043 0044 class DocumentPrivate : public tikz::ui::Document 0045 { 0046 Q_OBJECT 0047 0048 public: 0049 /** 0050 * Default constructor. 0051 */ 0052 DocumentPrivate(QObject * parent = nullptr); 0053 0054 /** 0055 * Destructor 0056 */ 0057 virtual ~DocumentPrivate(); 0058 0059 // 0060 // Forward functions for EditMode 0061 // 0062 public Q_SLOTS: 0063 /** 0064 * Set the edit mode to @p mode. 0065 */ 0066 void setEditMode(TikzEditMode mode); 0067 0068 public: 0069 /** 0070 * Get the edit mode. 0071 */ 0072 TikzEditMode editMode() const; 0073 0074 Q_SIGNALS: 0075 /** 0076 * This signal is emitted whenever the edit mode changed through setEditMode. 0077 */ 0078 void editModeChanged(TikzEditMode mode) const; 0079 0080 // 0081 // View management 0082 // 0083 public: 0084 /** 0085 * Called by ViewPrivate on construction to register @p view. 0086 */ 0087 void registerView(tikz::ui::View * view); 0088 0089 /** 0090 * Called by ViewPrivate on destruction to unregister @p view. 0091 */ 0092 void unregisterView(tikz::ui::View * view); 0093 0094 // 0095 // convenience functions 0096 // 0097 public: 0098 /** 0099 * Returns the position for @p pos in tikz::Pos coordinates. 0100 */ 0101 tikz::Pos scenePos(const tikz::core::MetaPos & pos) const override; 0102 0103 /** 0104 * Returns the QGraphicsScene based scene. 0105 */ 0106 TikzScene * scene() const; 0107 0108 public: 0109 /** 0110 * Create a new view attached to @p parent. 0111 * @param parent parent widget 0112 * @return the new view 0113 */ 0114 View * createView(QWidget * parent, 0115 tikz::ui::MainWindow * mainWindow = nullptr) override; 0116 0117 /** 0118 * Returns the views pre-casted to tikz::ui::View%s 0119 */ 0120 QVector<View *> views() const override; 0121 0122 // 0123 // Node and path creation 0124 // 0125 public: 0126 /** 0127 * Returns all NodeItem%s in the DocumentPrivate. 0128 */ 0129 QVector<NodeItem*> nodeItems() const override; 0130 0131 /** 0132 * Returns all PathItem%s in the DocumentPrivate. 0133 */ 0134 QVector<PathItem*> pathItems() const override; 0135 0136 /** 0137 * Creates a new NodeItem associated with this document. 0138 * If the node is not needed anymore, delete it by 0139 * calling deleteNodeItem(nodeItem). 0140 */ 0141 NodeItem * createNodeItem() override; 0142 0143 /** 0144 * Creates a new path associated with this document. 0145 * If the path is not needed anymore, delete it by 0146 * calling deletePathItem(pathItem). 0147 */ 0148 tikz::ui::PathItem * createPathItem(tikz::PathType type = tikz::PathType::Line) override; 0149 0150 /** 0151 * Remove @p node from the document by deleting the node object. 0152 * Afterwards, the pointer is invalid. 0153 * @param node node to delete 0154 */ 0155 void deleteNodeItem(NodeItem * node) override; 0156 0157 /** 0158 * Remove @p path from the document by deleting the path object. 0159 * Afterwards, the pointer is invalid. 0160 * @param path path to delete 0161 */ 0162 void deletePathItem(tikz::ui::PathItem * path) override; 0163 0164 /** 0165 * Get the NodeItem with @p uid. 0166 * @param uid unique id of the node 0167 * @return null, if the id is -1, otherwise a valid pointer to the node 0168 */ 0169 NodeItem * nodeItemFromId(const tikz::core::Uid & uid) const; 0170 0171 /** 0172 * Get the tikz::ui::PathItem with @p uid. 0173 * @param uid unique id of the path 0174 * @return null, if the id is -1, otherwise a valid pointer to the node 0175 */ 0176 tikz::ui::PathItem * pathItemFromId(const tikz::core::Uid & uid) const; 0177 0178 // 0179 // internal: Undo / redo items manipulate with ID 0180 // 0181 protected: 0182 /** 0183 * Create a new entity of @p type associated with this document with @p uid. 0184 */ 0185 tikz::core::Entity * createEntity(const tikz::core::Uid & uid, EntityType type) override; 0186 0187 /** 0188 * Delete entity @p uid associated with this document. 0189 */ 0190 void deleteEntity(const tikz::core::Uid & uid) override; 0191 0192 /** 0193 * Create a new path associated with this document with @p uid. 0194 */ 0195 tikz::core::Path * createPath(tikz::PathType type, const tikz::core::Uid & uid) override; 0196 0197 // 0198 // cleanup functions 0199 // 0200 protected Q_SLOTS: 0201 /** 0202 * Clear all contents of this DocumentPrivate. 0203 * @warning This functions is called from the destructor. 0204 * So never make it virtual. 0205 */ 0206 void clearDocumentPrivate(); 0207 0208 private: 0209 /** 0210 * List of NodeItem%s. 0211 */ 0212 QVector<NodeItem*> m_nodes; 0213 0214 /** 0215 * List of tikz::ui::PathItem%s. 0216 */ 0217 QVector<tikz::ui::PathItem *> m_paths; 0218 0219 /** 0220 * Node lookup map 0221 */ 0222 QHash<tikz::core::Uid, NodeItem*> m_nodeMap; 0223 0224 /** 0225 * Edge lookup map 0226 */ 0227 QHash<tikz::core::Uid, tikz::ui::PathItem *> m_pathMap; 0228 0229 /** 0230 * Graphics scene for the document. 0231 */ 0232 TikzScene * m_scene; 0233 0234 /** 0235 * List of graphics views. 0236 */ 0237 QVector<tikz::ui::View*> m_views; 0238 }; 0239 0240 } 0241 } 0242 0243 #endif // TIKZ_UI_DOCUMENT_PRIVATE_H 0244 0245 // kate: indent-width 4; replace-tabs on;