Commit 04ff532c authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[widgets][protocoltemplateeditor] Port to ScrollWidget

parent a89a04bb
......@@ -34,7 +34,6 @@ from PyQt5.QtWidgets import QHeaderView
from PyQt5.QtWidgets import QInputDialog
from PyQt5.QtWidgets import QLineEdit
from PyQt5.QtWidgets import QPushButton
from PyQt5.QtWidgets import QScrollArea
from PyQt5.QtWidgets import QStyledItemDelegate
from PyQt5.QtWidgets import QTableWidget
from PyQt5.QtWidgets import QTableWidgetItem
......@@ -46,6 +45,8 @@ from ..utils import frozen
from ..backend.assetmodel import AssetType
from ..backend.assetmodel import AssetModel
from .scrollwidget import ScrollWidget
from .editor import AbstractAssetEditor
......@@ -205,29 +206,27 @@ class ProtocolTemplateEditor(AbstractAssetEditor):
self.setObjectName(self.__class__.__name__)
self.set_title(self.tr("Protocol Template"))
self.set_widgets = []
self.dataformat_model = AssetModel()
self.dataformat_model.asset_type = AssetType.DATAFORMAT
container_widget = QWidget()
self.container_widget_layout = QVBoxLayout(container_widget)
self.container_widget_layout.addStretch(1)
self.scroll_area = QScrollArea()
self.scroll_area.setWidget(container_widget)
self.scroll_area.setWidgetResizable(True)
self.scroll_widget = ScrollWidget()
self.add_set_button = QPushButton(self.tr("+"))
self.add_set_button.setFixedSize(30, 30)
self.layout().addWidget(self.scroll_area, 1)
self.layout().addWidget(self.scroll_widget, 1)
self.layout().addWidget(self.add_set_button, 1)
self.scroll_widget.dataChanged.connect(self.dataChanged)
self.add_set_button.clicked.connect(self.__addSet)
self.contextChanged.connect(
lambda: self.dataformat_model.setPrefixPath(self.prefix_path)
)
@property
def set_widgets(self):
return self.scroll_widget.widget_list
@pyqtSlot()
def __onRemoveRequested(self):
"""Remove the widget clicked"""
......@@ -237,10 +236,7 @@ class ProtocolTemplateEditor(AbstractAssetEditor):
def __remove_widget(self, widget):
"""Removes the widget that which signal triggered this slot"""
self.container_widget_layout.removeWidget(widget)
self.set_widgets.pop(self.set_widgets.index(widget))
widget.setParent(None)
self.dataChanged.emit()
self.scroll_widget.removeWidget(widget)
@pyqtSlot()
def __addSet(self):
......@@ -276,7 +272,7 @@ class ProtocolTemplateEditor(AbstractAssetEditor):
"""Ensure that the latest set is visible"""
if self.set_widgets:
self.scroll_area.ensureWidgetVisible(self.set_widgets[-1], 10, 10)
self.scroll_widget.ensureWidgetVisible(self.set_widgets[-1], 10, 10)
def __load_json(self, json_object):
"""Load the json object passed as parameter"""
......@@ -284,10 +280,7 @@ class ProtocolTemplateEditor(AbstractAssetEditor):
for set_ in json_object["sets"]:
set_widget = SetWidget(self.dataformat_model)
set_widget.load(set_)
self.set_widgets.append(set_widget)
index = self.container_widget_layout.count() - 1
self.container_widget_layout.insertWidget(index, set_widget, 2)
set_widget.dataChanged.connect(self.dataChanged)
self.scroll_widget.addWidget(set_widget)
set_widget.deletionRequested.connect(self.__onRemoveRequested)
if self.set_widgets:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment