Commit df163952 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[widgets][protocoltemplateeditor] Cleanup

parent 7cbc452a
......@@ -49,6 +49,8 @@ from .editor import AbstractAssetEditor
class DataformatDelegate(QStyledItemDelegate):
"""Delegate to edit dataformat entries"""
def __init__(self, dataformat_model, parent=None):
super(DataformatDelegate, self).__init__(parent)
self.dataformat_model = dataformat_model
......@@ -60,6 +62,7 @@ class DataformatDelegate(QStyledItemDelegate):
class SetWidget(QWidget):
"""Editor for a set"""
dataChanged = pyqtSignal()
deletionRequested = pyqtSignal()
......@@ -111,21 +114,22 @@ class SetWidget(QWidget):
self.form_layout.addRow(self.tr("Name"), self.name_lineedit)
self.form_layout.addRow(self.tr("Outputs"), outputs_layout)
self.name_lineedit.textChanged.connect(self.dataChanged)
self.outputs_tablewidget.cellChanged.connect(self.dataChanged)
self.outputs_tablewidget.itemSelectionChanged.connect(
self.__on_item_selection_changed
)
layout = QVBoxLayout(self)
layout.addLayout(delete_layout)
layout.addLayout(self.form_layout)
self.name_lineedit.textChanged.connect(self.dataChanged)
self.delete_button.clicked.connect(self.deletionRequested)
self.add_button.clicked.connect(self.__add_output)
self.remove_button.clicked.connect(self.__remove_outputs)
self.outputs_tablewidget.cellChanged.connect(self.dataChanged)
self.outputs_tablewidget.itemSelectionChanged.connect(
self.__on_item_selection_changed
)
def __add_output(self):
"""Add a new output"""
new_row = self.outputs_tablewidget.rowCount()
self.outputs_tablewidget.setRowCount(new_row + 1)
name_item = QTableWidgetItem(self.tr("Change_me"))
......@@ -136,6 +140,8 @@ class SetWidget(QWidget):
self.dataChanged.emit()
def __remove_outputs(self):
"""Remove the selected output(s)"""
selected_items = self.outputs_tablewidget.selectedItems()
rows = []
......@@ -153,18 +159,14 @@ class SetWidget(QWidget):
def __on_item_selection_changed(self):
self.remove_button.setEnabled(bool(self.outputs_tablewidget.selectedItems()))
def dump(self):
json_data = {"name": self.name_lineedit.text()}
outputs = {}
for i in range(self.outputs_tablewidget.rowCount()):
outputs[
self.outputs_tablewidget.item(i, 0).text()
] = self.outputs_tablewidget.item(i, 1).text()
def name(self):
"""Name of the set"""
json_data["outputs"] = outputs
return json_data
return self.name_lineedit.text()
def load(self, json_data):
"""Load this widget with the content of json_data"""
self.name_lineedit.setText(json_data["name"])
outputs = json_data["outputs"]
self.outputs_tablewidget.setRowCount(len(outputs))
......@@ -176,14 +178,24 @@ class SetWidget(QWidget):
self.outputs_tablewidget.setItem(row, 1, type_item)
row += 1
def name(self):
"""Name of the set"""
def dump(self):
"""Returns the json representation of this set"""
return self.name_lineedit.text()
json_data = {"name": self.name_lineedit.text()}
outputs = {}
for i in range(self.outputs_tablewidget.rowCount()):
outputs[
self.outputs_tablewidget.item(i, 0).text()
] = self.outputs_tablewidget.item(i, 1).text()
json_data["outputs"] = outputs
return json_data
@frozen
class ProtocolTemplateEditor(AbstractAssetEditor):
"""Editor for protocol template objects"""
def __init__(self, parent=None):
super(ProtocolTemplateEditor, self).__init__(parent)
self.setObjectName(self.__class__.__name__)
......@@ -228,10 +240,7 @@ class ProtocolTemplateEditor(AbstractAssetEditor):
self.dataChanged.emit()
def __add_set(self):
"""Add a new set
:param content dict: dictionary to load
"""
"""Add a new set"""
set_names = [widget.name() for widget in self.set_widgets]
......@@ -294,6 +303,7 @@ class ProtocolTemplateEditor(AbstractAssetEditor):
def _dump_json(self):
"""Returns the json representation of the asset"""
return {
"schema_version": 1,
"sets": [widget.dump() for widget in 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