@@ -23,24 +23,7 @@ void TreeVisualiser::paintEvent(QPaintEvent *event) {
2323}
2424
2525TreeVisualiser::TreeVisualiser (QWidget *parent) : QWidget(parent) {
26- Node *nroot = new Node (Node::NodeType::Expression, " +" );
27- nroot->setLevel (1 );
28- Node *child1 = new Node (Node::NodeType::Number, " 3" );
29- child1->setLevel (2 );
30- Node *child2 = new Node (Node::NodeType::Number, " 4" );
31- child2->setLevel (1 );
32- Node *child3 = new Node (Node::NodeType::Number, " 5" );
33- child3->setLevel (3 );
34-
35- Node *child4 = new Node (Node::NodeType::Number, " A7a" );
36- Node *child5 = new Node (Node::NodeType::Addition, " 5555555" );
37-
38- this ->root = nroot;
39- this ->root ->addChild (child1);
40- this ->root ->addChild (child2);
41- child2->addChild (child3);
42- child2->addChild (child4);
43- child1->addChild (child5);
26+
4427}
4528
4629void TreeVisualiser::drawTree (QPainter *painter, Node *node, int x, int y, int availableWidth, int level) {
@@ -62,7 +45,7 @@ void TreeVisualiser::drawTree(QPainter *painter, Node *node, int x, int y, int a
6245 if (!hasValue (node->getType ())) {
6346 nodeText = node->getNodeTypeString ().toString () + " \n (" + node->getValue () + " )" ;
6447 } else {
65- nodeText = node->getValue ();
48+ nodeText = node->getNodeTypeString (). toString ();
6649 }
6750 painter->drawText (QRect (x - 40 , y - 20 , 80 , 40 ),
6851 Qt::AlignCenter | Qt::TextWordWrap, nodeText);
@@ -94,14 +77,14 @@ void TreeVisualiser::drawTree(QPainter *painter, Node *node, int x, int y, int a
9477 int childWidth = childWidths[i];
9578
9679 // Calculate position for each child
97- int childX = startX + childWidth / 2 ;
98- int childY = (child-> getLevel () == node-> getLevel ())? y : y + verticalSpacing;
80+ int childX = startX + childWidth / 2 - 20 ;
81+ int childY = y + verticalSpacing;
9982
10083 // Draw connection line to child node
10184 painter->setPen (QPen (Qt::black, 2 ));
10285 int yLineOffset = (child->getLevel () == node->getLevel ())? 0 : 20 ;
10386
104- painter->drawLine (x, y + yLineOffset , childX, childY);
87+ painter->drawLine (x, y + 20 , childX, childY);
10588
10689 // Recursively draw the child node
10790 drawTree (painter, child, childX, childY, childWidth, child->getLevel ());
0 commit comments