Skip to content

Commit

Permalink
Support to save and load graph view states
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelma committed Sep 19, 2023
1 parent eec0a47 commit 4be2d33
Show file tree
Hide file tree
Showing 9 changed files with 527 additions and 339 deletions.
12 changes: 8 additions & 4 deletions spinetoolbox/spine_db_editor/graphics_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Classes for drawing graphics items on graph view's QGraphicsScene.
"""
from enum import Enum, auto
from PySide6.QtCore import Qt, Signal, Slot, QLineF, QRectF, QPointF, QObject
from PySide6.QtCore import Qt, Signal, Slot, QLineF, QRectF, QPointF, QObject, QByteArray
from PySide6.QtSvgWidgets import QGraphicsSvgItem
from PySide6.QtWidgets import (
QGraphicsItem,
Expand All @@ -26,7 +26,7 @@
QMenu,
)
from PySide6.QtSvg import QSvgRenderer
from PySide6.QtGui import QPen, QBrush, QPainterPath, QPalette, QGuiApplication, QAction, QColor
from PySide6.QtGui import QPen, QBrush, QPainterPath, QPalette, QGuiApplication, QAction

from spinetoolbox.helpers import DB_ITEM_SEPARATOR, color_from_index
from spinetoolbox.widgets.custom_qwidgets import TitleWidgetAction
Expand Down Expand Up @@ -984,11 +984,12 @@ class Anchor(Enum):
Anchor.BR: Qt.SizeFDiagCursor,
}

def __init__(self, file_path, parent=None):
def __init__(self, svg, parent=None):
super().__init__(parent)
self._renderer = QSvgRenderer()
self._svg_item = _ResizableQGraphicsSvgItem(self)
_loading_ok = self._renderer.load(file_path)
self.svg = svg
_loading_ok = self._renderer.load(QByteArray(self.svg))
self._svg_item.setCacheMode(QGraphicsItem.CacheMode.NoCache) # Needed for the exported pdf to be vector
self._svg_item.setSharedRenderer(self._renderer)
self._scaling_factor = 1
Expand Down Expand Up @@ -1047,9 +1048,12 @@ def _do_resize(self, rect, strong):
self._place_resizers()

def fit_rect(self, rect):
if not isinstance(rect, QRectF):
rect = QRectF(*rect)
self._do_resize(rect, True)

def fit_coordinates(self, p1, p2, scen1, scen2):
# NOTE: not in use at the moment
size = self._renderer.defaultSize()
x1, y1 = p1
x2, y2 = p2
Expand Down
1 change: 0 additions & 1 deletion spinetoolbox/spine_db_editor/ui/spine_db_editor_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ def setupUi(self, MainWindow):
MainWindow.addDockWidget(Qt.RightDockWidgetArea, self.dockWidget_relationship_parameter_definition)
self.dockWidget_object_tree = QDockWidget(MainWindow)
self.dockWidget_object_tree.setObjectName(u"dockWidget_object_tree")
self.dockWidget_object_tree.setFeatures(QDockWidget.DockWidgetClosable|QDockWidget.DockWidgetFloatable|QDockWidget.DockWidgetMovable)
self.dockWidget_object_tree.setAllowedAreas(Qt.AllDockWidgetAreas)
self.dockWidgetContents_6 = QWidget()
self.dockWidgetContents_6.setObjectName(u"dockWidgetContents_6")
Expand Down
9 changes: 8 additions & 1 deletion spinetoolbox/spine_db_editor/ui/spine_db_editor_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
</property>
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
Expand Down Expand Up @@ -433,7 +434,7 @@
</widget>
<widget class="QDockWidget" name="dockWidget_object_tree">
<property name="features">
<set>QDockWidget::DockWidgetClosable|QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable</set>
<set>QDockWidget::AllDockWidgetFeatures</set>
</property>
<property name="allowedAreas">
<set>Qt::AllDockWidgetAreas</set>
Expand Down Expand Up @@ -1287,6 +1288,12 @@
<header>spinetoolbox/spine_db_editor/widgets/custom_qwidgets.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>ProgressBarWidget</class>
<extends>QWidget</extends>
<header>spinetoolbox/spine_db_editor/widgets/custom_qwidgets.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../../ui/resources/resources_icons.qrc"/>
Expand Down
Loading

0 comments on commit 4be2d33

Please sign in to comment.