Commit 501aa573 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[widgets][databaseeditor] Port to ScrollWidget

parent 2d6c01b9
......@@ -42,7 +42,6 @@ from PyQt5.QtWidgets import QInputDialog
from PyQt5.QtWidgets import QLabel
from PyQt5.QtWidgets import QLineEdit
from PyQt5.QtWidgets import QPushButton
from PyQt5.QtWidgets import QScrollArea
from PyQt5.QtWidgets import QStackedWidget
from PyQt5.QtWidgets import QStyledItemDelegate
from PyQt5.QtWidgets import QTableWidget
......@@ -59,6 +58,8 @@ from ..utils import frozen
from ..utils import is_Qt_equal_or_higher
from .editor import AbstractAssetEditor
from .scrollwidget import EditorListWidget
from .scrollwidget import ScrollWidget
from .utils import create_delete_button_and_layout
......@@ -149,34 +150,20 @@ class DatabaseV1Viewer(QWidget):
def __init__(self, parent=None):
super(DatabaseV1Viewer, self).__init__(parent)
self.protocol_viewers = []
container_widget = QWidget()
self.container_widget_layout = QVBoxLayout(container_widget)
self.container_widget_layout.addStretch(1)
scroll_area = QScrollArea()
scroll_area.setWidget(container_widget)
scroll_area.setWidgetResizable(True)
self.scroll_widget = ScrollWidget()
layout = QVBoxLayout(self)
layout.addWidget(scroll_area)
layout.addWidget(self.scroll_widget)
self.json_object = None
def load(self, json_object):
while self.protocol_viewers:
widget = self.protocol_viewers[0]
self.container_widget_layout.removeWidget(widget)
self.protocol_viewers.pop(self.protocol_viewers.index(widget))
widget.setParent(None)
self.scroll_widget.clear()
for protocol in json_object["protocols"]:
protocol_viewer = ProtocolViewer()
protocol_viewer.load(protocol)
self.protocol_viewers.append(protocol_viewer)
index = self.container_widget_layout.count() - 1
self.container_widget_layout.insertWidget(index, protocol_viewer, 2)
self.scroll_widget.addWidget(protocol_viewer)
self.json_object = json_object
......@@ -423,25 +410,23 @@ class ViewsEditor(QWidget):
self.protocol = None
self.prefix_path = None
self.view_editors = []
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.editor_list_widget = EditorListWidget()
self.add_view_button = QPushButton(self.tr("+"))
self.add_view_button.setFixedSize(30, 30)
layout = QVBoxLayout(self)
layout.addWidget(self.scroll_area, 1)
layout.addWidget(self.editor_list_widget, 1)
layout.addWidget(self.add_view_button, 1)
self.editor_list_widget.dataChanged.connect(self.dataChanged)
self.add_view_button.clicked.connect(self.__addView)
@property
def view_editors(self):
return self.editor_list_widget.widget_list
def available_sets(self):
protocol_template = ProtocolTemplate(self.prefix_path, self.protocol)
used_sets = [editor.dbset_name for editor in self.view_editors]
......@@ -479,20 +464,13 @@ class ViewsEditor(QWidget):
def __remove_widget(self, widget):
"""Removes the widget that which signal triggered this slot"""
self.container_widget_layout.removeWidget(widget)
self.view_editors.pop(self.view_editors.index(widget))
widget.setParent(None)
self.dataChanged.emit()
self.editor_list_widget.removeWidget(widget)
self.add_view_button.setEnabled(True)
def __add_widget(self, view_editor):
"""Add a new editor widget"""
index = self.container_widget_layout.count() - 1
self.layout().insertWidget(index, view_editor)
view_editor.dataChanged.connect(self.dataChanged)
self.editor_list_widget.addWidget(view_editor)
view_editor.deletionRequested.connect(self.__removeView)
self.view_editors.append(view_editor)
def set_procotol(self, protocol):
self.protocol = protocol
......@@ -651,27 +629,25 @@ class DatabaseWidget(QWidget):
self.protocoltemplate_model = AssetModel()
self.protocoltemplate_model.asset_type = AssetType.PROTOCOLTEMPLATE
self.protocol_editors = []
self.root_folder = None
self.prefix_path = None
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_protocol_button = QPushButton(self.tr("+"))
self.add_protocol_button.setFixedSize(30, 30)
layout = QVBoxLayout(self)
layout.addWidget(self.scroll_area, 1)
layout.addWidget(self.scroll_widget, 1)
layout.addWidget(self.add_protocol_button, 1)
self.scroll_widget.dataChanged.connect(self.dataChanged)
self.add_protocol_button.clicked.connect(self.__addProtocol)
@property
def protocol_editors(self):
return self.scroll_widget.widget_list
@pyqtSlot()
def __onRemoveRequested(self):
"""Remove the widget clicked"""
......@@ -681,18 +657,12 @@ class DatabaseWidget(QWidget):
def __remove_widget(self, widget):
"""Removes the widget that which signal triggered this slot"""
self.container_widget_layout.removeWidget(widget)
self.protocol_editors.pop(self.protocol_editors.index(widget))
widget.setParent(None)
self.dataChanged.emit()
self.scroll_widget.removeWidget(widget)
def __add_widget(self, protocol_editor):
"""Add the editor to this widget"""
self.protocol_editors.append(protocol_editor)
index = self.container_widget_layout.count() - 1
self.container_widget_layout.insertWidget(index, protocol_editor, 2)
protocol_editor.dataChanged.connect(self.dataChanged)
self.scroll_widget.addWidget(protocol_editor)
protocol_editor.deletionRequested.connect(self.__onRemoveRequested)
@pyqtSlot()
......@@ -712,7 +682,6 @@ class DatabaseWidget(QWidget):
protocol_editor.protocol = protocol
self.__add_widget(protocol_editor)
self.dataChanged.emit()
def setPrefixPath(self, prefix):
"""Re-impl"""
......@@ -725,9 +694,7 @@ class DatabaseWidget(QWidget):
self.blockSignals(True)
while self.protocol_editors:
widget = self.protocol_editors[0]
self.__remove_widget(widget)
self.scroll_widget.clear()
self.blockSignals(False)
......@@ -744,7 +711,7 @@ class DatabaseWidget(QWidget):
return {
"root_folder": self.root_folder,
"protocols": [widget.dump() for widget in self.protocol_editors],
"protocols": [widget.dump() for widget in self.scroll_widget.widget_list],
}
......
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