File indexing completed on 2025-04-27 08:28:09
0001 // 0002 // C++ Interface: circuiticndocument 0003 // 0004 // Description: 0005 // 0006 // 0007 // Author: Zoltan P <zoltan.padrah@gmail.com>, (C) 2008 0008 // 0009 // Copyright: See COPYING file that comes with this distribution 0010 // 0011 // 0012 #ifndef CIRCUITICNDOCUMENT_H 0013 #define CIRCUITICNDOCUMENT_H 0014 0015 #include <icndocument.h> 0016 0017 class ECNode; 0018 0019 typedef QMap<QString, ECNode *> ECNodeMap; 0020 0021 /** 0022 A document holding a circuit 0023 0024 @author Zoltan P <zoltan.padrah@gmail.com> 0025 */ 0026 class CircuitICNDocument : public ICNDocument 0027 { 0028 Q_OBJECT 0029 0030 public: 0031 CircuitICNDocument(const QString &caption); 0032 0033 ~CircuitICNDocument() override; 0034 0035 /** 0036 * Reinherit this function to perform special checks on whether the two 0037 * given QCanvasItems (either nodes or connectors or both) can be 0038 * connected together. 0039 */ 0040 bool canConnect(KtlQCanvasItem *qcanvasItem1, KtlQCanvasItem *qcanvasItem2) const override; 0041 0042 /** 0043 * Splits Connector con into two connectors at point pos2, and creates a connector from the node 0044 * to the intersection of the two new connectors. If pointList is non-null, then the new connector 0045 * from the node will be assigned those points 0046 */ 0047 Connector *createConnector(Node *node, Connector *con, const QPoint &pos2, QPointList *pointList = nullptr) override; 0048 /** 0049 * Splits con1 and con2 into two new connectors each at points pos1 and pos2, and creates a new connector 0050 * between the two points of intersection given by pos1 and pos2. If pointList is non-null, then the new 0051 * connector between the two points will be assigned those points 0052 */ 0053 Connector *createConnector(Connector *con1, Connector *con2, const QPoint &pos1, const QPoint &pos2, QPointList *pointList = nullptr) override; 0054 /** 0055 * Creates a connector between two nodes, and returns a pointer to it 0056 * and adds the operation to the undo list 0057 */ 0058 Connector *createConnector(const QString &startNodeId, const QString &endNodeId, QPointList *pointList = nullptr) override; 0059 /** 0060 * Creates a connector from node1 to node2. If pointList is non-null, then the 0061 * connector will be assigned those points 0062 */ 0063 virtual Connector *createConnector(Node *node1, Node *node2, QPointList *pointList = nullptr) 0064 { 0065 return ICNDocument::createConnector(node1, node2, pointList); 0066 } 0067 0068 /** 0069 * Returns a pointer to a node on the canvas with the given id, 0070 * or nullptr if no such node exists 0071 */ 0072 Node *nodeWithID(const QString &id) override; 0073 ECNode *getEcNodeWithID(const QString &id); 0074 0075 /** 0076 * Assigns the orphan nodes into NodeGroups. You shouldn't call this 0077 * function directly - instead use ItemDocument::requestEvent. 0078 */ 0079 void slotAssignNodeGroups() override; 0080 0081 /** 0082 * Permantly deletes all items that have been added to the delete list with 0083 * the appendDeleteList( KtlQCanvasItem *qcanvasItem ) function. 0084 */ 0085 void flushDeleteList() override; 0086 0087 /** 0088 * registers (adds to the document) an item (a connector or a node) 0089 * @param qcanvasItem the item to be registered 0090 * @return true if succeeded, false if it didn't 0091 */ 0092 bool registerItem(KtlQCanvasItem *qcanvasItem) override; 0093 0094 void unregisterUID(const QString &uid) override; 0095 0096 NodeList nodeList() const override; 0097 0098 protected: 0099 /** 0100 * If there are two connectors joined to a node, then they can be merged 0101 * into one connector. The node will not be removed. 0102 * @param ecnode The node between the two connectors 0103 * @returns true if it was successful in merging the connectors 0104 */ 0105 bool joinConnectors(ECNode *ecnode); 0106 /** 0107 * Selects all nodes on the document. Should be overridden. 0108 */ 0109 void selectAllNodes() override; 0110 0111 /** 0112 * deletes all the elements containde in the nodeList. Should be overridden. 0113 */ 0114 void deleteAllNodes() override; 0115 0116 /** 0117 * deletes all node groups in the nodeGroupList. Should be overridden. 0118 */ 0119 // virtual void deleteAllNodeGroups(); 0120 0121 /// the list of nodes contained by the document 0122 ECNodeMap m_ecNodeList; 0123 }; 0124 0125 #endif