Merge remote-tracking branch 'gitea/moving_topology' into topo-mov

topo-mov
LEdoian 1 year ago
commit 7b2ff09168

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