CNodeItem.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #ifndef CNODEITEM_H
  2. #define CNODEITEM_H
  3. #include <QObject>
  4. #include "CNode.h"
  5. #include <QPoint>
  6. class CRectItem;
  7. class CTextItem;
  8. class CLineItem;
  9. class CNodeItem : public QObject
  10. {
  11. Q_OBJECT
  12. public:
  13. explicit CNodeItem(const CNodeData data, CNodeItem *parent = nullptr);
  14. CNodeData data() const;
  15. void setData(CNodeData data);
  16. void addSubNode(CNodeItem *n);
  17. void removeNode(int number);
  18. CNodeItem *subNode(int number);
  19. CRectItem *rectItem() const;
  20. CTextItem *textItem() const;
  21. CLineItem *lineItem() const;
  22. QPointF pos() const;
  23. void setPos(const QPointF pos);
  24. qreal xMargin() const;
  25. void setXMargin(qreal x);
  26. qreal yMargin() const;
  27. void setYMargin(qreal y);
  28. qreal minWidth() const;
  29. void setMinWidth(qreal w);
  30. qreal maxWidth() const;
  31. void setMaxWidth(qreal w);
  32. qreal minHeight() const;
  33. void setMinHeight(qreal h);
  34. void connectSignalsAndSlots();
  35. void updateItemsGeometry();
  36. int height() const; // 节点的高度
  37. int depth() const; // 节点的深度
  38. int leafs() const; // 叶子节点个数或包含的路径条数
  39. ///
  40. /// \brief sizeOfLevel 以此节点为根节点的子树中,某一层的节点数
  41. /// \param lev 节点层级,当前节点为1,向下递增
  42. /// \return 节点数
  43. ///
  44. int sizeOfLevel(int lev) const;
  45. qreal textWidth() const;
  46. qreal textHeight() const;
  47. qreal borderWidth() const;
  48. qreal borderHeight() const;
  49. qreal hNodeSpace() const;
  50. void setHNodeSpace(qreal h);
  51. qreal vNodeSpace() const;
  52. void setVNodeSpace(qreal v);
  53. /// 子节点的布局高度
  54. qreal childrenHeight() const;
  55. /// 以此节点为根节点的子树的布局高度
  56. qreal treeHeight() const;
  57. ///
  58. /// \brief maxBorderWidthOfLevel 以此节点为根节点的子树中,某一层所有同辈节点中的最大边框宽度
  59. /// \param lev 节点层级,当前节点为1,向下递增
  60. /// \return 边框宽度
  61. ///
  62. qreal maxBorderWidthOfLevel(int lev = 1) const;
  63. void beginEditing();
  64. void endEditing();
  65. CNodeItem *editingNode();
  66. void setHighlighted(bool h);
  67. signals:
  68. void sigEditNode(CNodeData n);
  69. void sigAddSubItem(int pNumber);
  70. void sigRemoveItem(int number);
  71. void sigTextChanged();
  72. void sigWillBeginEditing();
  73. public slots:
  74. void slotEditNode();
  75. void slotSelect();
  76. void slotSubNode();
  77. void slotRemove();
  78. void slotTextChanged();
  79. void slotWillBeginEditing();
  80. private:
  81. CNodeData m_data;
  82. CRectItem *m_rectItem = nullptr;
  83. CTextItem *m_textItem = nullptr;
  84. CLineItem *m_lineItem = nullptr;
  85. QPointF m_pos;
  86. qreal m_xMargin = 10;
  87. qreal m_yMargin = 5;
  88. qreal m_minWidth = 200;
  89. qreal m_maxWidth = 300;
  90. qreal m_minHeight = 30;
  91. qreal m_hNodeSpace = 80;
  92. qreal m_vNodeSpace = 10;
  93. };
  94. #endif // CNODEITEM_H