11 :synopsis: Repackaging of the limiting ROS qt_dotgraph.node_item module. 13 Oh my spaghettified magnificence, 14 Bless my noggin with a tickle from your noodly appendages! 22 from python_qt_binding.QtCore
import QPointF, Qt
23 from python_qt_binding.QtGui
import QBrush, QPolygonF, QPainterPath, QPen
25 from python_qt_binding.QtGui
import QGraphicsEllipseItem, QGraphicsPolygonItem, QGraphicsRectItem, QGraphicsSimpleTextItem
27 from python_qt_binding.QtWidgets
import QGraphicsEllipseItem, QGraphicsPolygonItem, QGraphicsRectItem, QGraphicsSimpleTextItem
29 from .graph_item
import GraphItem
38 def __init__(self, highlight_level, bounding_box, label, shape, color=None, parent=None, label_pos=None, tooltip=None):
39 super(NodeItem, self).
__init__(highlight_level, parent)
45 self._label_pen.setJoinStyle(Qt.RoundJoin)
47 self._ellipse_pen.setWidth(1)
58 elif shape ==
'octagon':
59 rect = bounding_box.getRect()
60 octagon_polygon = QPolygonF([QPointF(rect[0], rect[1] + 3 * rect[3] / 10),
61 QPointF(rect[0], rect[1] + 7 * rect[3] / 10),
62 QPointF(rect[0] + 3 * rect[2] / 10, rect[1] + rect[3]),
63 QPointF(rect[0] + 7 * rect[2] / 10, rect[1] + rect[3]),
64 QPointF(rect[0] + rect[2], rect[1] + 7 * rect[3] / 10),
65 QPointF(rect[0] + rect[2], rect[1] + 3 * rect[3] / 10),
66 QPointF(rect[0] + 7 * rect[2] / 10, rect[1]),
67 QPointF(rect[0] + 3 * rect[2] / 10, rect[1])])
70 elif shape ==
'doubleoctagon':
71 rect = bounding_box.getRect()
74 octagon_polygon = QPolygonF([QPointF(rect[0], rect[1] + 3 * rect[3] / 10),
75 QPointF(rect[0], rect[1] + 7 * rect[3] / 10),
76 QPointF(rect[0] + 3 * rect[2] / 10, rect[1] + rect[3]),
77 QPointF(rect[0] + 7 * rect[2] / 10, rect[1] + rect[3]),
78 QPointF(rect[0] + rect[2], rect[1] + 7 * rect[3] / 10),
79 QPointF(rect[0] + rect[2], rect[1] + 3 * rect[3] / 10),
80 QPointF(rect[0] + 7 * rect[2] / 10, rect[1]),
81 QPointF(rect[0] + 3 * rect[2] / 10, rect[1]),
83 QPointF(rect[0], rect[1] + 3 * rect[3] / 10),
84 QPointF(rect[0] + inner_fold, rect[1] + 3 * rect[3] / 10 + inner_fold / 2),
85 QPointF(rect[0] + inner_fold, rect[1] + 7 * rect[3] / 10 - inner_fold / 2),
86 QPointF(rect[0] + 3 * rect[2] / 10, rect[1] + rect[3] - inner_fold),
87 QPointF(rect[0] + 7 * rect[2] / 10, rect[1] + rect[3] - inner_fold),
88 QPointF(rect[0] + rect[2] - inner_fold, rect[1] + 7 * rect[3] / 10 - inner_fold / 2),
89 QPointF(rect[0] + rect[2] - inner_fold, rect[1] + 3 * rect[3] / 10 + inner_fold / 2),
90 QPointF(rect[0] + 7 * rect[2] / 10, rect[1] + inner_fold),
91 QPointF(rect[0] + 3 * rect[2] / 10, rect[1] + inner_fold),
92 QPointF(rect[0] + inner_fold, rect[1] + 3 * rect[3] / 10 + inner_fold / 2)
98 rect = bounding_box.getRect()
99 note_polygon = QPolygonF([QPointF(rect[0] + 9 * rect[2] / 10, rect[1]),
100 QPointF(rect[0], rect[1]),
101 QPointF(rect[0], rect[1] + rect[3]),
102 QPointF(rect[0] + rect[2], rect[1] + rect[3]),
103 QPointF(rect[0] + rect[2], rect[1] + rect[3] / 5),
104 QPointF(rect[0] + 9 * rect[2] / 10, rect[1] + rect[3] / 5),
105 QPointF(rect[0] + 9 * rect[2] / 10, rect[1]),
106 QPointF(rect[0] + rect[2], rect[1] + rect[3] / 5),
107 QPointF(rect[0] + rect[2], rect[1] + rect[3] / 5)])
114 self.
_label = QGraphicsSimpleTextItem(label)
115 label_rect = self._label.boundingRect()
116 if label_pos
is None:
117 label_rect.moveCenter(bounding_box.center())
119 label_rect.moveCenter(label_pos)
120 self._label.setPos(label_rect.x(), label_rect.y())
121 self.addToGroup(self.
_label)
122 if tooltip
is not None:
123 self.setToolTip(tooltip)
127 self.setAcceptHoverEvents(
True)
136 path = QPainterPath()
140 return super(self.__class__, self).
shape()
143 self._incoming_edges.add(edge)
146 self._outgoing_edges.add(edge)
152 self._brush.setColor(color)
153 self._ellipse_pen.setColor(color)
154 self._label_pen.setColor(color)
157 self._label.setBrush(self.
_brush)
164 if self._highlight_level > 1:
167 incoming_nodes = set()
168 for incoming_edge
in self._incoming_edges.difference(cyclic_edges):
169 incoming_edge.set_node_color(self._COLOR_BLUE)
170 if incoming_edge.from_node != self:
171 incoming_nodes.add(incoming_edge.from_node)
173 outgoing_nodes = set()
174 for outgoing_edge
in self._outgoing_edges.difference(cyclic_edges):
175 outgoing_edge.set_node_color(self._COLOR_GREEN)
176 if outgoing_edge.to_node != self:
177 outgoing_nodes.add(outgoing_edge.to_node)
179 for edge
in cyclic_edges:
180 edge.set_node_color(self._COLOR_TEAL)
182 if self._highlight_level > 2:
183 cyclic_nodes = incoming_nodes.intersection(outgoing_nodes)
185 for incoming_node
in incoming_nodes.difference(cyclic_nodes):
186 incoming_node.set_node_color(self._COLOR_BLUE)
188 for outgoing_node
in outgoing_nodes.difference(cyclic_nodes):
189 outgoing_node.set_node_color(self._COLOR_GREEN)
191 for node
in cyclic_nodes:
192 node.set_node_color(self._COLOR_TEAL)
196 if self._highlight_level > 1:
198 incoming_edge.set_node_color()
199 if self._highlight_level > 2
and incoming_edge.from_node != self:
200 incoming_edge.from_node.set_node_color()
202 outgoing_edge.set_node_color()
203 if self._highlight_level > 2
and outgoing_edge.to_node != self:
204 outgoing_edge.to_node.set_node_color()
def hoverLeaveEvent(self, event)
def set_node_color(self, color=None)
def __init__(self, highlight_level, bounding_box, label, shape, color=None, parent=None, label_pos=None, tooltip=None)
def set_hovershape(self, newhovershape)
def add_incoming_edge(self, edge)
def add_outgoing_edge(self, edge)
def hoverEnterEvent(self, event)