123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- #ifndef CNODEITEM_H
- #define CNODEITEM_H
- #include <QObject>
- #include "CNode.h"
- #include <QPoint>
- 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
|