Loading view/binaryTreeToPlanarTreeGui.py +1 −1 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ class BinaryTreeToPlanarTreeGui(LevelGui): def createPlanarTreeView(self): self.planarTreeScene = QGraphicsScene() self.planarTreeView = TreeView(self.planarTreeScene, controller=self.controller) self.planarTreeView = TreeView(self.planarTreeScene, controller=self.controller, root=True) self.planarTreeView.drawTree() def error(self, index: int, nodeType: str): Loading view/planarTreeToBinaryTreeGui.py +1 −1 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ class PlanarTreeToBinaryTreeGui(LevelGui): def createPlanarTreeView(self): self.planarTreeScene = QGraphicsScene() self.planarTreeView = TreeView(self.planarTreeScene, controller=self.controller, model=True) self.planarTreeView = TreeView(self.planarTreeScene, controller=self.controller, model=True, root=True) self.planarTreeView.drawTree() def error(self, index: int, nodeType: str): Loading view/treeView.py +25 −12 Original line number Diff line number Diff line import math from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtCore import Qt, QObject, pyqtSignal from model.node import Leaf, EmptyNode, BinaryNode, IncompleteNode from model.node import Leaf, EmptyNode, BinaryNode, IncompleteNode, PlanarNode from model.tree import Tree Loading Loading @@ -70,10 +72,21 @@ class TreeView(QGraphicsView): self.scene().setSceneRect(self.treeItemsGroup.sceneBoundingRect()) def drawTreeRec(self, tree, nodeWidth, lineWidth, heightRatio, widthRatio, root): branchPen = QPen(QColor(113, 125, 126)) nodePen = QPen(QColor(21, 67, 96)) branchPen = QPen(QColor(21, 67, 96)) if not root: if isinstance(tree, PlanarNode): nodeColor = QColor(245, 183, 177) else: nodeColor = QColor(169, 204, 227) else: nodeColor = QColor(187, 143, 206) nodePen.setWidth(0.1 * nodeWidth) space = nodeWidth / 15.356667 branchPen.setDashPattern([space, space]) nodePen.setDashPattern([space, space]) branchPen.setWidth(lineWidth) branchPen.setCapStyle(Qt.RoundCap) nodePen = QPen(QColor(113, 125, 126)) nodePen.setWidth(0.1 * nodeWidth) if isinstance(tree, Leaf): Loading @@ -87,7 +100,7 @@ class TreeView(QGraphicsView): leaf.setOpacity(0) self.treeItemsGroup.addToGroup(leaf) leafButton = LeafButton(self.controller, self.indexChildButton, 0.1 * nodeWidth) nodeButton = NodeButton(self.controller, self.indexChildButton, 0.1 * nodeWidth) nodeButton = NodeButton(self.controller, self.indexChildButton, 0.1 * nodeWidth, nodeColor) self.indexChildButton += 1 leafButton.setRect(tree.x * widthRatio - nodeWidth / 2 - 0.05 * nodeWidth, tree.y * heightRatio + nodeWidth / 4, Loading @@ -114,7 +127,7 @@ class TreeView(QGraphicsView): node = QGraphicsEllipseItem() node.setRect(tree.x * widthRatio - nodeWidth / 2, tree.y * heightRatio, nodeWidth, nodeWidth) node.setPen(nodePen) node.setBrush(QColor(174, 214, 241)) node.setBrush(nodeColor) self.treeItemsGroup.addToGroup(node) self.drawTreeRec(tree.left, nodeWidth, lineWidth, heightRatio, widthRatio, False) self.drawTreeRec(tree.right, nodeWidth, lineWidth, heightRatio, widthRatio, False) Loading @@ -127,7 +140,7 @@ class TreeView(QGraphicsView): branchButton = BranchButton(self.controller, self.indexChildButton, 0.1 * nodeWidth, tree.x * widthRatio + 0.05 * nodeWidth, tree.y * heightRatio + nodeWidth / 4, nodeWidth / 2 - 0.1 * nodeWidth) nodeButton = NodeButton(self.controller, self.indexChildButton, 0.1 * nodeWidth) nodeButton = NodeButton(self.controller, self.indexChildButton, 0.1 * nodeWidth, nodeColor) self.indexChildButton += 1 nodeButton.setRect(tree.x * widthRatio - nodeWidth / 2 - 0.05 * nodeWidth, tree.y * heightRatio + nodeWidth / 4, nodeWidth / 2 - 0.1 * nodeWidth, nodeWidth / 2 - 0.1 * nodeWidth) Loading @@ -146,7 +159,7 @@ class TreeView(QGraphicsView): node = QGraphicsEllipseItem() node.setRect(tree.x * widthRatio - nodeWidth / 2, tree.y * heightRatio, nodeWidth, nodeWidth) node.setPen(nodePen) node.setBrush(QColor(174, 214, 241)) node.setBrush(nodeColor) self.treeItemsGroup.addToGroup(node) for child in tree.children: self.drawTreeRec(child, nodeWidth, lineWidth, heightRatio, widthRatio, False) Loading @@ -155,7 +168,7 @@ class TreeView(QGraphicsView): node = QGraphicsEllipseItem() node.setRect(tree.x * widthRatio - nodeWidth / 2, tree.y * heightRatio, nodeWidth, nodeWidth) node.setPen(nodePen) node.setBrush(QColor(174, 214, 241)) node.setBrush(nodeColor) self.treeItemsGroup.addToGroup(node) Loading @@ -172,7 +185,7 @@ class LeafButton(QGraphicsRectItem): self.clickableObject = Clickable() self.index = buttonIndex self.controller = controller self.pen = QPen(QColor(113, 125, 126)) self.pen = QPen(QColor(21, 67, 96)) self.pen.setWidth(width) self.setPen(self.pen) self.connect() Loading @@ -189,13 +202,13 @@ class LeafButton(QGraphicsRectItem): class NodeButton(QGraphicsEllipseItem): def __init__(self, controller, buttonIndex, width): def __init__(self, controller, buttonIndex, width, color): super(QGraphicsEllipseItem, self).__init__() self.clickableObject = Clickable() self.index = buttonIndex self.controller = controller self.setBrush(QColor(174, 214, 241)) self.pen = QPen(QColor(113, 125, 126)) self.setBrush(color) self.pen = QPen(QColor(21, 67, 96)) self.pen.setWidth(width) self.setPen(self.pen) self.connect() Loading Loading
view/binaryTreeToPlanarTreeGui.py +1 −1 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ class BinaryTreeToPlanarTreeGui(LevelGui): def createPlanarTreeView(self): self.planarTreeScene = QGraphicsScene() self.planarTreeView = TreeView(self.planarTreeScene, controller=self.controller) self.planarTreeView = TreeView(self.planarTreeScene, controller=self.controller, root=True) self.planarTreeView.drawTree() def error(self, index: int, nodeType: str): Loading
view/planarTreeToBinaryTreeGui.py +1 −1 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ class PlanarTreeToBinaryTreeGui(LevelGui): def createPlanarTreeView(self): self.planarTreeScene = QGraphicsScene() self.planarTreeView = TreeView(self.planarTreeScene, controller=self.controller, model=True) self.planarTreeView = TreeView(self.planarTreeScene, controller=self.controller, model=True, root=True) self.planarTreeView.drawTree() def error(self, index: int, nodeType: str): Loading
view/treeView.py +25 −12 Original line number Diff line number Diff line import math from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtCore import Qt, QObject, pyqtSignal from model.node import Leaf, EmptyNode, BinaryNode, IncompleteNode from model.node import Leaf, EmptyNode, BinaryNode, IncompleteNode, PlanarNode from model.tree import Tree Loading Loading @@ -70,10 +72,21 @@ class TreeView(QGraphicsView): self.scene().setSceneRect(self.treeItemsGroup.sceneBoundingRect()) def drawTreeRec(self, tree, nodeWidth, lineWidth, heightRatio, widthRatio, root): branchPen = QPen(QColor(113, 125, 126)) nodePen = QPen(QColor(21, 67, 96)) branchPen = QPen(QColor(21, 67, 96)) if not root: if isinstance(tree, PlanarNode): nodeColor = QColor(245, 183, 177) else: nodeColor = QColor(169, 204, 227) else: nodeColor = QColor(187, 143, 206) nodePen.setWidth(0.1 * nodeWidth) space = nodeWidth / 15.356667 branchPen.setDashPattern([space, space]) nodePen.setDashPattern([space, space]) branchPen.setWidth(lineWidth) branchPen.setCapStyle(Qt.RoundCap) nodePen = QPen(QColor(113, 125, 126)) nodePen.setWidth(0.1 * nodeWidth) if isinstance(tree, Leaf): Loading @@ -87,7 +100,7 @@ class TreeView(QGraphicsView): leaf.setOpacity(0) self.treeItemsGroup.addToGroup(leaf) leafButton = LeafButton(self.controller, self.indexChildButton, 0.1 * nodeWidth) nodeButton = NodeButton(self.controller, self.indexChildButton, 0.1 * nodeWidth) nodeButton = NodeButton(self.controller, self.indexChildButton, 0.1 * nodeWidth, nodeColor) self.indexChildButton += 1 leafButton.setRect(tree.x * widthRatio - nodeWidth / 2 - 0.05 * nodeWidth, tree.y * heightRatio + nodeWidth / 4, Loading @@ -114,7 +127,7 @@ class TreeView(QGraphicsView): node = QGraphicsEllipseItem() node.setRect(tree.x * widthRatio - nodeWidth / 2, tree.y * heightRatio, nodeWidth, nodeWidth) node.setPen(nodePen) node.setBrush(QColor(174, 214, 241)) node.setBrush(nodeColor) self.treeItemsGroup.addToGroup(node) self.drawTreeRec(tree.left, nodeWidth, lineWidth, heightRatio, widthRatio, False) self.drawTreeRec(tree.right, nodeWidth, lineWidth, heightRatio, widthRatio, False) Loading @@ -127,7 +140,7 @@ class TreeView(QGraphicsView): branchButton = BranchButton(self.controller, self.indexChildButton, 0.1 * nodeWidth, tree.x * widthRatio + 0.05 * nodeWidth, tree.y * heightRatio + nodeWidth / 4, nodeWidth / 2 - 0.1 * nodeWidth) nodeButton = NodeButton(self.controller, self.indexChildButton, 0.1 * nodeWidth) nodeButton = NodeButton(self.controller, self.indexChildButton, 0.1 * nodeWidth, nodeColor) self.indexChildButton += 1 nodeButton.setRect(tree.x * widthRatio - nodeWidth / 2 - 0.05 * nodeWidth, tree.y * heightRatio + nodeWidth / 4, nodeWidth / 2 - 0.1 * nodeWidth, nodeWidth / 2 - 0.1 * nodeWidth) Loading @@ -146,7 +159,7 @@ class TreeView(QGraphicsView): node = QGraphicsEllipseItem() node.setRect(tree.x * widthRatio - nodeWidth / 2, tree.y * heightRatio, nodeWidth, nodeWidth) node.setPen(nodePen) node.setBrush(QColor(174, 214, 241)) node.setBrush(nodeColor) self.treeItemsGroup.addToGroup(node) for child in tree.children: self.drawTreeRec(child, nodeWidth, lineWidth, heightRatio, widthRatio, False) Loading @@ -155,7 +168,7 @@ class TreeView(QGraphicsView): node = QGraphicsEllipseItem() node.setRect(tree.x * widthRatio - nodeWidth / 2, tree.y * heightRatio, nodeWidth, nodeWidth) node.setPen(nodePen) node.setBrush(QColor(174, 214, 241)) node.setBrush(nodeColor) self.treeItemsGroup.addToGroup(node) Loading @@ -172,7 +185,7 @@ class LeafButton(QGraphicsRectItem): self.clickableObject = Clickable() self.index = buttonIndex self.controller = controller self.pen = QPen(QColor(113, 125, 126)) self.pen = QPen(QColor(21, 67, 96)) self.pen.setWidth(width) self.setPen(self.pen) self.connect() Loading @@ -189,13 +202,13 @@ class LeafButton(QGraphicsRectItem): class NodeButton(QGraphicsEllipseItem): def __init__(self, controller, buttonIndex, width): def __init__(self, controller, buttonIndex, width, color): super(QGraphicsEllipseItem, self).__init__() self.clickableObject = Clickable() self.index = buttonIndex self.controller = controller self.setBrush(QColor(174, 214, 241)) self.pen = QPen(QColor(113, 125, 126)) self.setBrush(color) self.pen = QPen(QColor(21, 67, 96)) self.pen.setWidth(width) self.setPen(self.pen) self.connect() Loading