1 // 2 // C++ Interface: circuiticndocument 3 // 4 // Description: 5 // 6 // 7 // Author: Zoltan P <zoltan.padrah@gmail.com>, (C) 2008 8 // 9 // Copyright: See COPYING file that comes with this distribution 10 // 11 // 12 #ifndef CIRCUITICNDOCUMENT_H 13 #define CIRCUITICNDOCUMENT_H 14 15 #include <icndocument.h> 16 17 class ECNode; 18 19 typedef QMap < QString, ECNode* > ECNodeMap; 20 21 /** 22 A document holding a circuit 23 24 @author Zoltan P <zoltan.padrah@gmail.com> 25 */ 26 class CircuitICNDocument : public ICNDocument 27 { 28 Q_OBJECT 29 30 public: 31 CircuitICNDocument(const QString& caption, const char* name); 32 33 ~CircuitICNDocument() override; 34 35 36 /** 37 * Reinherit this function to perform special checks on whether the two 38 * given QCanvasItems (either nodes or connectors or both) can be 39 * connected together. 40 */ 41 bool canConnect ( KtlQCanvasItem *qcanvasItem1, KtlQCanvasItem *qcanvasItem2 ) const override; 42 43 /** 44 * Splits Connector con into two connectors at point pos2, and creates a connector from the node 45 * to the intersection of the two new connectors. If pointList is non-null, then the new connector 46 * from the node will be assigned those points 47 */ 48 Connector * createConnector( Node *node, Connector *con, const QPoint &pos2, QPointList *pointList = nullptr ) override; 49 /** 50 * Splits con1 and con2 into two new connectors each at points pos1 and pos2, and creates a new connector 51 * between the two points of intersection given by pos1 and pos2. If pointList is non-null, then the new 52 * connector between the two points will be assigned those points 53 */ 54 Connector *createConnector( Connector *con1, Connector *con2, const QPoint &pos1, const QPoint &pos2, QPointList *pointList = nullptr ) override; 55 /** 56 * Creates a connector between two nodes, and returns a pointer to it 57 * and adds the operation to the undo list 58 */ 59 Connector* createConnector( const QString &startNodeId, const QString &endNodeId, QPointList *pointList = nullptr ) override; 60 /** 61 * Creates a connector from node1 to node2. If pointList is non-null, then the 62 * connector will be assigned those points 63 */ 64 virtual Connector *createConnector(Node *node1, Node *node2, QPointList *pointList = nullptr) 65 { return ICNDocument::createConnector(node1,node2, pointList); } 66 67 /** 68 * Returns a pointer to a node on the canvas with the given id, 69 * or nullptr if no such node exists 70 */ 71 Node* nodeWithID ( const QString &id ) override; 72 ECNode *getEcNodeWithID( const QString &id ); 73 74 /** 75 * Assigns the orphan nodes into NodeGroups. You shouldn't call this 76 * function directly - instead use ItemDocument::requestEvent. 77 */ 78 void slotAssignNodeGroups() override; 79 80 /** 81 * Permantly deletes all items that have been added to the delete list with 82 * the appendDeleteList( KtlQCanvasItem *qcanvasItem ) function. 83 */ 84 void flushDeleteList() override; 85 86 /** 87 * registers (adds to the document) an item (a connector or a node) 88 * @param qcanvasItem the item to be registered 89 * @return true if succeeded, false if it didn't 90 */ 91 bool registerItem ( KtlQCanvasItem *qcanvasItem ) override; 92 93 void unregisterUID ( const QString & uid ) override; 94 95 NodeList nodeList() const override; 96 97 protected: 98 99 /** 100 * If there are two connectors joined to a node, then they can be merged 101 * into one connector. The node will not be removed. 102 * @param ecnode The node between the two connectors 103 * @returns true if it was successful in merging the connectors 104 */ 105 bool joinConnectors( ECNode *ecnode ); 106 /** 107 * Selects all nodes on the document. Should be overridden. 108 */ 109 void selectAllNodes() override; 110 111 112 /** 113 * deletes all the elements containde in the nodeList. Should be overridden. 114 */ 115 void deleteAllNodes() override; 116 117 /** 118 * deletes all node groups in the nodeGroupList. Should be overridden. 119 */ 120 // virtual void deleteAllNodeGroups(); 121 122 /// the list of nodes contained by the document 123 ECNodeMap m_ecNodeList; 124 }; 125 126 #endif 127