Add a PoC of moving vertices in the visualisation

This implementation is really barebones, mostly-broken (each vertex can
only remember one line), but demonstrates that implementing moving is
going to be quite simple.
moving_topology
LEdoian 1 year ago
parent ac3508727d
commit 21dbc83ff5

@ -9,6 +9,7 @@ from dataclasses import dataclass
import re
import random
from PySide6 import QtCore, QtGui, QtWidgets
from .qt_widgets import MyGraphicsRectItem
# Classification
@ -140,7 +141,7 @@ def create_qgritems(at):
x = pos.x
y = pos.y
shape = QtWidgets.QGraphicsRectItem(-size/2, -size/2, size, size)
shape = MyGraphicsRectItem(-size/2, -size/2, size, size)
shape.setBrush(brush)
shape.setPos(x, y)
shape.setToolTip(rk)
@ -149,6 +150,7 @@ def create_qgritems(at):
# Centering:
text_width = label.boundingRect().width()
label.setX(-text_width/2)
shape.setFlag(QtWidgets.QGraphicsItem.ItemIsMovable | QtWidgets.QGraphicsItem.ItemIsSelectable)
at.router_annotations[rk].append(shape)
for nk, n in topo.networks.items():
@ -166,7 +168,7 @@ def create_qgritems(at):
x = pos.x
y = pos.y
shape = QtWidgets.QGraphicsRectItem(-size/2, -size/2, size, size)
shape = MyGraphicsRectItem(-size/2, -size/2, size, size)
shape.setBrush(brush)
shape.setPos(x, y)
shape.setToolTip(nk)
@ -175,6 +177,7 @@ def create_qgritems(at):
# Centering:
text_width = label.boundingRect().width()
label.setX(-text_width/2)
shape.setFlag(QtWidgets.QGraphicsItem.ItemIsMovable | QtWidgets.QGraphicsItem.ItemIsSelectable)
at.network_annotations[nk].append(shape)
for lk, l in topo.links.items():
@ -183,16 +186,24 @@ def create_qgritems(at):
rpos = None
for tag in at.router_annotations[rid][-1::-1]:
if isinstance(tag, QtWidgets.QGraphicsRectItem):
ritem = tag
if isinstance(tag, Position):
rpos = tag
break
npos = None
for tag in at.network_annotations[nid][-1::-1]:
if isinstance(tag, QtWidgets.QGraphicsRectItem):
nitem = tag
if isinstance(tag, Position):
npos = tag
break
line = QtWidgets.QGraphicsLineItem(rpos.x, rpos.y, npos.x, npos.y)
ritem.setData(0, line)
nitem.setData(0, line)
line.setData(0, nitem)
line.setData(1, ritem)
at.link_annotations[lk].append(line)
return at

@ -0,0 +1,23 @@
from PySide6.QtWidgets import QGraphicsRectItem
from PySide6.QtCore import QLineF
class MyGraphicsRectItem(QGraphicsRectItem):
#def __init__(self, *a, **kwa):
# return super().__init__(*a, **kwa)
#def itemChange(self, change, val):
# return super().itemChange(change, val)
def mouseMoveEvent(self, evt):
print(f'Moving: {self}')
line = self.data(0)
other_end = line.data(0)
if other_end == self:
other_end = line.data(1)
new_qlinef = QLineF(
self.x(),
self.y(),
other_end.x(),
other_end.y(),
)
line.setLine(new_qlinef)
return super().mouseMoveEvent(evt)
Loading…
Cancel
Save