BC: Add graph display.

mesh
Pierre-Antoine Rouby 2023-05-04 17:05:15 +02:00
parent d95e69ba9b
commit d13130c9a7
3 changed files with 32 additions and 5 deletions

View File

@ -19,7 +19,7 @@ from PyQt5.QtWidgets import (
QDialogButtonBox, QPushButton, QLineEdit,
QFileDialog, QTableView, QAbstractItemView,
QUndoStack, QShortcut, QAction, QItemDelegate,
QComboBox,
QComboBox, QVBoxLayout, QHeaderView
)
from View.BoundaryCondition.BCUndoCommand import (
@ -37,6 +37,7 @@ from View.BoundaryCondition.Table import (
TableModel, ComboBoxDelegate
)
from View.Network.GraphWidget import GraphWidget
from View.BoundaryCondition.translate import *
from View.BoundaryCondition.Edit.Window import EditBoundaryConditionWindow
@ -54,6 +55,7 @@ class BoundaryConditionWindow(ASubMainWindow, ListedSubWindow):
self.setup_sc()
self.setup_table()
self.setup_graph()
self.setup_connections()
self.ui.setWindowTitle(title)
@ -91,8 +93,18 @@ class BoundaryConditionWindow(ASubMainWindow, ListedSubWindow):
)
table.setSelectionBehavior(QAbstractItemView.SelectRows)
table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
table.setAlternatingRowColors(True)
def setup_graph(self):
self.graph_widget = GraphWidget(
self._study.river,
min_size=None, size=(200,200),
only_display=True,
parent=self
)
self.graph_layout = self.find(QVBoxLayout, "verticalLayout")
self.graph_layout.addWidget(self.graph_widget)
def setup_connections(self):
self.find(QAction, "action_add").triggered.connect(self.add)

View File

@ -79,12 +79,18 @@ class NodeItem(QGraphicsItem):
def mousePressEvent(self, event):
self.update()
if not self.graph._only_display:
super(NodeItem, self).mousePressEvent(event)
def mouseReleaseEvent(self, event):
self.update()
super(NodeItem, self).mouseReleaseEvent(event)
def mouseMoveEvent(self, event):
self.update()
if not self.graph._only_display:
super(NodeItem, self).mouseMoveEvent(event)
class EdgeItem(QGraphicsItem):
Type = QGraphicsItem.UserType + 2
@ -252,12 +258,15 @@ class GraphWidget(QGraphicsView):
changeEdge = pyqtSignal(object)
changeNode = pyqtSignal(object)
def __init__(self, graph, parent=None):
def __init__(self, graph, parent=None,
min_size=(400, 400), max_size=None,
size=None, only_display=False):
super(GraphWidget, self).__init__(parent=parent)
self.timerId = 0
self.parent = parent
self._state = "move"
self._only_display = only_display
self.graph = graph
@ -286,7 +295,13 @@ class GraphWidget(QGraphicsView):
self.scale(1, 1)
self.previousScale = 1
self.setMinimumSize(400, 400)
if min_size:
self.setMinimumSize(*min_size)
if max_size:
self.setMaximumSize(*max_size)
if size:
self.resize(*size)
self.create_items()

View File

@ -37,7 +37,7 @@
<item row="0" column="0">
<widget class="QSplitter" name="splitter">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>