Commit 1eef985a authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

Merge branch '246_fix_dataformat_list_for_protocol_templates' into 'master'

Fix dataformat list for protocol templates

See merge request !146
parents d9c5aa88 fb56e8f3
Pipeline #41885 passed with stages
in 28 minutes and 19 seconds
......@@ -280,13 +280,13 @@ class DataFormatModel(AbstractAssetModel):
return os.path.join(self.prefix_path, self.__asset_type.path)
def fullListEnabled(self):
"""Returns whether the full list mode is enabled.
def defaultFormat(self):
"""Returns a format used to setup a default value
:return: if full list is enabled
:returns: the default format
"""
return self._full_list_enabled
return self.index(0).data()
def setFullListEnabled(self, enabled):
"""Enable/disable the full list mode
......@@ -300,8 +300,6 @@ class DataFormatModel(AbstractAssetModel):
self._full_list_enabled = enabled
self.reload()
full_list_enabled = pyqtProperty(str, fget=fullListEnabled, fset=setFullListEnabled)
def json_path(self, asset_name):
"""Reimpl"""
......
......@@ -80,7 +80,7 @@ def dataformat_model(test_prefix):
def full_dataformat_model(test_prefix):
model = DataFormatModel()
model.prefix_path = test_prefix
model.full_list_enabled = True
model.setFullListEnabled(True)
return model
......
......@@ -155,7 +155,7 @@ class TestDataFormatModel:
def df_model(self, request, test_prefix):
df_model = DataFormatModel()
df_model.prefix_path = test_prefix
df_model.full_list_enabled = request.param
df_model.setFullListEnabled(request.param)
return df_model
def test_model_load(self, df_model):
......
......@@ -44,7 +44,7 @@ from ..widgets.dialogs import NameInputDialog
@pytest.fixture()
def dataformat_model(test_prefix):
asset_model = DataFormatModel()
asset_model.full_list_enabled = True
asset_model.setFullListEnabled(True)
asset_model.prefix_path = test_prefix
return asset_model
......
......@@ -42,18 +42,21 @@ from ..widgets.protocoltemplateeditor import SetWidget
def dataformat_model(test_prefix):
asset_model = DataFormatModel()
asset_model.prefix_path = test_prefix
asset_model.full_list_enabled = True
return asset_model
@pytest.fixture()
def reference_set_json():
return {"name": "test", "outputs": {"out1": "int8"}}
def reference_set_json(dataformat_model):
return {"name": "test", "outputs": {"out1": dataformat_model.defaultFormat()}}
@pytest.fixture()
def reference_pt_json():
return {"sets": [{"name": "original", "outputs": {"a": "int8"}}]}
def reference_pt_json(dataformat_model):
return {
"sets": [
{"name": "original", "outputs": {"a": dataformat_model.defaultFormat()}}
]
}
class TestSetWidget:
......@@ -69,7 +72,7 @@ class TestSetWidget:
def test_add_output(self, qtbot, dataformat_model, reference_set_json):
edited_json = copy.deepcopy(reference_set_json)
edited_json["outputs"]["Change_me"] = "int8"
edited_json["outputs"]["Change_me"] = dataformat_model.defaultFormat()
set_widget = SetWidget(dataformat_model)
set_widget.load(reference_set_json)
......@@ -115,11 +118,16 @@ class TestProtocolTemplateEditor:
assert editor.dump_json() == json_data
def test_add_set(self, qtbot, monkeypatch, beat_context, reference_pt_json):
def test_add_set(
self, qtbot, monkeypatch, beat_context, reference_pt_json, dataformat_model
):
edited_json = copy.deepcopy(reference_pt_json)
edited_json["schema_version"] = 1
edited_json["sets"].append(
{"name": "test_set", "outputs": {"Change_me": "int8"}}
{
"name": "test_set",
"outputs": {"Change_me": dataformat_model.defaultFormat()},
}
)
monkeypatch.setattr(
......
......@@ -462,7 +462,7 @@ class IOWidget(QGroupBox):
new_row = self.tablewidget.rowCount()
self.tablewidget.setRowCount(new_row + 1)
name_item = QTableWidgetItem(self.tr("Name_me"))
type_item = QTableWidgetItem(self.dataformat_model.index(0).data())
type_item = QTableWidgetItem(self.dataformat_model.defaultFormat())
self.tablewidget.setItem(new_row, 0, name_item)
self.tablewidget.setItem(new_row, 1, type_item)
self.tablewidget.scrollToItem(name_item)
......
......@@ -646,7 +646,7 @@ class DataformatEditor(AbstractAssetEditor):
self.set_title(self.tr("Dataformat"))
self.dataformat_model = DataFormatModel()
self.dataformat_model.full_list_enabled = True
self.dataformat_model.setFullListEnabled(True)
self.extends_label = QLabel()
self._add_information_widget(self.tr("Extends"), self.extends_label)
......
......@@ -116,7 +116,7 @@ class SetWidget(QWidget):
new_row = self.outputs_tablewidget.rowCount()
self.outputs_tablewidget.setRowCount(new_row + 1)
name_item = QTableWidgetItem(self.tr("Change_me"))
type_item = QTableWidgetItem(self.dataformat_model.index(0).data())
type_item = QTableWidgetItem(self.dataformat_model.defaultFormat())
self.outputs_tablewidget.setItem(new_row, 0, name_item)
self.outputs_tablewidget.setItem(new_row, 1, type_item)
self.outputs_tablewidget.scrollToItem(type_item)
......@@ -187,7 +187,6 @@ class ProtocolTemplateEditor(AbstractAssetEditor):
self.set_title(self.tr("Protocol Template"))
self.dataformat_model = DataFormatModel()
self.dataformat_model.full_list_enabled = True
self.scroll_widget = ScrollWidget()
......@@ -236,7 +235,7 @@ class ProtocolTemplateEditor(AbstractAssetEditor):
{
"name": name,
"outputs": {
"Change_me": self.dataformat_model.index(0).data()
"Change_me": self.dataformat_model.defaultFormat()
},
}
]
......
Markdown is supported
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