#ifndef CNODEITEM_H #define CNODEITEM_H #include #include "CNode.h" #include class CRectItem; class CTextItem; class CLineItem; class CNodeItem : public QObject { Q_OBJECT public: explicit CNodeItem(const CNodeData data, CNodeItem *parent = nullptr); CNodeData data() const; void setData(CNodeData data); void addSubNode(CNodeItem *n); void removeNode(int number); CNodeItem *subNode(int number); CRectItem *rectItem() const; CTextItem *textItem() const; CLineItem *lineItem() const; QPointF pos() const; void setPos(const QPointF pos); qreal xMargin() const; void setXMargin(qreal x); qreal yMargin() const; void setYMargin(qreal y); qreal minWidth() const; void setMinWidth(qreal w); qreal maxWidth() const; void setMaxWidth(qreal w); qreal minHeight() const; void setMinHeight(qreal h); void connectSignalsAndSlots(); void updateItemsGeometry(); int height() const; // 节点的高度 int depth() const; // 节点的深度 int leafs() const; // 叶子节点个数或包含的路径条数 /// /// \brief sizeOfLevel 以此节点为根节点的子树中,某一层的节点数 /// \param lev 节点层级,当前节点为1,向下递增 /// \return 节点数 /// int sizeOfLevel(int lev) const; qreal textWidth() const; qreal textHeight() const; qreal borderWidth() const; qreal borderHeight() const; qreal hNodeSpace() const; void setHNodeSpace(qreal h); qreal vNodeSpace() const; void setVNodeSpace(qreal v); /// 子节点的布局高度 qreal childrenHeight() const; /// 以此节点为根节点的子树的布局高度 qreal treeHeight() const; /// /// \brief maxBorderWidthOfLevel 以此节点为根节点的子树中,某一层所有同辈节点中的最大边框宽度 /// \param lev 节点层级,当前节点为1,向下递增 /// \return 边框宽度 /// qreal maxBorderWidthOfLevel(int lev = 1) const; void beginEditing(); void endEditing(); CNodeItem *editingNode(); void setHighlighted(bool h); signals: void sigEditNode(CNodeData n); void sigAddSubItem(int pNumber); void sigRemoveItem(int number); void sigTextChanged(); void sigWillBeginEditing(); public slots: void slotEditNode(); void slotSelect(); void slotSubNode(); void slotRemove(); void slotTextChanged(); void slotWillBeginEditing(); private: CNodeData m_data; CRectItem *m_rectItem = nullptr; CTextItem *m_textItem = nullptr; CLineItem *m_lineItem = nullptr; QPointF m_pos; qreal m_xMargin = 10; qreal m_yMargin = 5; qreal m_minWidth = 200; qreal m_maxWidth = 300; qreal m_minHeight = 30; qreal m_hNodeSpace = 80; qreal m_vNodeSpace = 10; }; #endif // CNODEITEM_H