Skip to content
Snippets Groups Projects
Commit c1b908fa authored by Oscar Gustafsson's avatar Oscar Gustafsson :bicyclist:
Browse files

Factor out common code

parent 085fe753
No related branches found
No related tags found
1 merge request!113Factor out common code
Pipeline #88245 passed
...@@ -162,27 +162,24 @@ class GraphicsComponentItem(QGraphicsItemGroup): ...@@ -162,27 +162,24 @@ class GraphicsComponentItem(QGraphicsItemGroup):
execution_time_pen.setColor(execution_time_color) execution_time_pen.setColor(execution_time_color)
execution_time_pen.setWidthF(3 / self._scale) execution_time_pen.setWidthF(3 / self._scale)
def generate_path(points):
path = QPainterPath(
QPointF(points[0][0], points[0][1] * self._height)
) # starting point
for _x, _y in points[1:]:
path.lineTo(_x, _y * self._height)
path.closeSubpath()
return path
# Set the starting position # Set the starting position
latency, execution_time = self._operation.get_plot_coordinates() latency, execution_time = self._operation.get_plot_coordinates()
latency_path = QPainterPath( latency_path = generate_path(latency)
QPointF(latency[0][0], latency[0][1] * self._height)
) # starting point
for _x, _y in latency[1:]:
latency_path.lineTo(_x, _y * self._height)
latency_path.closeSubpath()
self._latency_item = QGraphicsPathItem(latency_path) self._latency_item = QGraphicsPathItem(latency_path)
self._latency_item.setPen(latency_outline_pen) self._latency_item.setPen(latency_outline_pen)
if execution_time: if execution_time:
execution_time_path = QPainterPath( execution_time_path = generate_path(execution_time)
QPointF(
execution_time[0][0], execution_time[0][1] * self._height
)
) # starting point
for _x, _y in execution_time[1:]:
execution_time_path.lineTo(_x, _y * self._height)
execution_time_path.closeSubpath()
self._execution_time_item = QGraphicsPathItem(execution_time_path) self._execution_time_item = QGraphicsPathItem(execution_time_path)
self._execution_time_item.setPen(execution_time_pen) self._execution_time_item.setPen(execution_time_pen)
...@@ -192,31 +189,23 @@ class GraphicsComponentItem(QGraphicsItemGroup): ...@@ -192,31 +189,23 @@ class GraphicsComponentItem(QGraphicsItemGroup):
) # used by component filling ) # used by component filling
inputs, outputs = self._operation.get_io_coordinates() inputs, outputs = self._operation.get_io_coordinates()
for i, (x, y) in enumerate(inputs):
pos = QPointF(x, y * self._height) def create_ports(io_coordinates, prefix):
key = f"in{i}" for i, (x, y) in enumerate(io_coordinates):
self._ports[key]["pos"] = pos pos = QPointF(x, y * self._height)
port_pos = self.mapToParent(pos) key = f"{prefix}{i}"
port = QGraphicsEllipseItem( self._ports[key]["pos"] = pos
-port_size / 2, -port_size / 2, port_size, port_size port_pos = self.mapToParent(pos)
) port = QGraphicsEllipseItem(
port.setPen(port_outline_pen) -port_size / 2, -port_size / 2, port_size, port_size
port.setBrush(port_filling_brush) )
port.setPos(port_pos.x(), port_pos.y()) port.setPen(port_outline_pen)
self._port_items.append(port) port.setBrush(port_filling_brush)
port.setPos(port_pos.x(), port_pos.y())
for i, (x, y) in enumerate(outputs): self._port_items.append(port)
pos = QPointF(x, y * self._height)
key = f"out{i}" create_ports(inputs, "in")
self._ports[key]["pos"] = pos create_ports(outputs, "out")
port_pos = self.mapToParent(pos)
port = QGraphicsEllipseItem(
-port_size / 2, -port_size / 2, port_size, port_size
)
port.setPen(port_outline_pen)
port.setBrush(port_filling_brush)
port.setPos(port_pos.x(), port_pos.y())
self._port_items.append(port)
# op-id/label # op-id/label
self._label_item = QGraphicsSimpleTextItem(self._operation.graph_id) self._label_item = QGraphicsSimpleTextItem(self._operation.graph_id)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment