mirror of https://gitlab.com/pamhyr/pamhyr2
BC: Add graph display.
parent
d95e69ba9b
commit
d13130c9a7
|
|
@ -19,7 +19,7 @@ from PyQt5.QtWidgets import (
|
||||||
QDialogButtonBox, QPushButton, QLineEdit,
|
QDialogButtonBox, QPushButton, QLineEdit,
|
||||||
QFileDialog, QTableView, QAbstractItemView,
|
QFileDialog, QTableView, QAbstractItemView,
|
||||||
QUndoStack, QShortcut, QAction, QItemDelegate,
|
QUndoStack, QShortcut, QAction, QItemDelegate,
|
||||||
QComboBox,
|
QComboBox, QVBoxLayout, QHeaderView
|
||||||
)
|
)
|
||||||
|
|
||||||
from View.BoundaryCondition.BCUndoCommand import (
|
from View.BoundaryCondition.BCUndoCommand import (
|
||||||
|
|
@ -37,6 +37,7 @@ from View.BoundaryCondition.Table import (
|
||||||
TableModel, ComboBoxDelegate
|
TableModel, ComboBoxDelegate
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from View.Network.GraphWidget import GraphWidget
|
||||||
from View.BoundaryCondition.translate import *
|
from View.BoundaryCondition.translate import *
|
||||||
from View.BoundaryCondition.Edit.Window import EditBoundaryConditionWindow
|
from View.BoundaryCondition.Edit.Window import EditBoundaryConditionWindow
|
||||||
|
|
||||||
|
|
@ -54,6 +55,7 @@ class BoundaryConditionWindow(ASubMainWindow, ListedSubWindow):
|
||||||
|
|
||||||
self.setup_sc()
|
self.setup_sc()
|
||||||
self.setup_table()
|
self.setup_table()
|
||||||
|
self.setup_graph()
|
||||||
self.setup_connections()
|
self.setup_connections()
|
||||||
|
|
||||||
self.ui.setWindowTitle(title)
|
self.ui.setWindowTitle(title)
|
||||||
|
|
@ -91,8 +93,18 @@ class BoundaryConditionWindow(ASubMainWindow, ListedSubWindow):
|
||||||
)
|
)
|
||||||
|
|
||||||
table.setSelectionBehavior(QAbstractItemView.SelectRows)
|
table.setSelectionBehavior(QAbstractItemView.SelectRows)
|
||||||
|
table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
||||||
table.setAlternatingRowColors(True)
|
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):
|
def setup_connections(self):
|
||||||
self.find(QAction, "action_add").triggered.connect(self.add)
|
self.find(QAction, "action_add").triggered.connect(self.add)
|
||||||
|
|
|
||||||
|
|
@ -79,12 +79,18 @@ class NodeItem(QGraphicsItem):
|
||||||
|
|
||||||
def mousePressEvent(self, event):
|
def mousePressEvent(self, event):
|
||||||
self.update()
|
self.update()
|
||||||
|
if not self.graph._only_display:
|
||||||
super(NodeItem, self).mousePressEvent(event)
|
super(NodeItem, self).mousePressEvent(event)
|
||||||
|
|
||||||
def mouseReleaseEvent(self, event):
|
def mouseReleaseEvent(self, event):
|
||||||
self.update()
|
self.update()
|
||||||
super(NodeItem, self).mouseReleaseEvent(event)
|
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):
|
class EdgeItem(QGraphicsItem):
|
||||||
Type = QGraphicsItem.UserType + 2
|
Type = QGraphicsItem.UserType + 2
|
||||||
|
|
||||||
|
|
@ -252,12 +258,15 @@ class GraphWidget(QGraphicsView):
|
||||||
changeEdge = pyqtSignal(object)
|
changeEdge = pyqtSignal(object)
|
||||||
changeNode = 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)
|
super(GraphWidget, self).__init__(parent=parent)
|
||||||
|
|
||||||
self.timerId = 0
|
self.timerId = 0
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self._state = "move"
|
self._state = "move"
|
||||||
|
self._only_display = only_display
|
||||||
|
|
||||||
self.graph = graph
|
self.graph = graph
|
||||||
|
|
||||||
|
|
@ -286,7 +295,13 @@ class GraphWidget(QGraphicsView):
|
||||||
|
|
||||||
self.scale(1, 1)
|
self.scale(1, 1)
|
||||||
self.previousScale = 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()
|
self.create_items()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QSplitter" name="splitter">
|
<widget class="QSplitter" name="splitter">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue