37 this->size = nodeSize;
39 nodeItem =
new QGraphicsEllipseItem();
40 scene->addItem(nodeItem);
42 edgeItem =
new QGraphicsLineItem();
43 scene->addItem(edgeItem);
52 this->parent = parent;
59 childs.push_back(child);
74 calculateSubTreeSize();
77 updateLayout(positionLeftTop);
88 void TreeNode::updateLayout(QPointF leftTop)
91 if (childs.size() > 0)
94 QPointF childLeftTop = leftTop;
97 std::vector<TreeNodePtr>::iterator iter = childs.begin();
99 while (iter != childs.end())
102 (*iter)->updateLayout(childLeftTop);
105 QSize childSubTreeSize = (*iter)->getSubTreeSize();
114 if (childs.size() == 0)
123 QRectF childsBB = calculateChildsBoundingBox();
126 boundingBox = QRectF(childsBB.center().x() -
getSize().width() / 2.0f, leftTop.y(),
getSize().width(),
getSize().height());
134 QSize TreeNode::calculateSubTreeSize()
136 std::vector<TreeNodePtr>::iterator iter = childs.begin();
142 while (iter != childs.end())
145 QSize childSize = (*iter)->calculateSubTreeSize();
149 if (childSize.height() > height)
151 height = childSize.height();
158 if (childs.size() > 0)
171 this->subTreeSize = QSize(width, height);
176 QRectF TreeNode::calculateChildsBoundingBox()
179 float minX = FLT_MAX;
182 float minY = FLT_MAX;
185 std::vector<TreeNodePtr>::iterator iter = childs.begin();
187 while (iter != childs.end())
189 QRectF childBB = (*iter)->getBoundingBox();
191 if (childBB.left() < minX)
193 minX = childBB.left();
196 if (childBB.right() > maxX)
198 maxX = childBB.right();
201 if (childBB.top() < minY)
203 minY = childBB.top();
206 if (childBB.bottom() > maxY)
208 maxY = childBB.bottom();
214 QRectF result(minX, minY, maxX - minX, maxY - minY);
218 void TreeNode::drawEdges()
220 std::vector<TreeNodePtr>::iterator iter = childs.begin();
222 while (iter != childs.end())
225 QPointF lineEnd = ((*iter)->getBoundingBox().topLeft() + (*iter)->getBoundingBox().topRight()) / 2.0f;
226 QLineF line(lineStart, lineEnd);
228 (*iter)->drawEdge(line);
236 edgeItem->setLine(line);
242 nodeItem->setRect(boundingBox);