Commit 49d40aa3 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[editors] Made prefix_path a Qt property in AbstractAssetEditor

The prefix path is going to be used by all editors.[widgets] Remove field and test_editors

These were serving demonstration purposes. They are not needed
anymore.
parent 079d6b96
......@@ -187,7 +187,7 @@ class TestViewEditor:
def views_editor(qtbot, test_prefix):
editor = ViewsEditor()
qtbot.addWidget(editor)
editor.set_prefix_root(test_prefix)
editor.setPrefixPath(test_prefix)
return editor
......@@ -246,7 +246,7 @@ class TestProtocolEditor:
def test_load_and_dump(self, qtbot, test_prefix, reference_database_json):
protocol_editor = ProtocolEditor()
qtbot.addWidget(protocol_editor)
protocol_editor.set_prefix_root(test_prefix)
protocol_editor.setPrefixPath(test_prefix)
for protocol in reference_database_json["protocols"]:
protocol_editor.load(protocol)
......@@ -260,7 +260,7 @@ class TestProtocolEditor:
def database_widget(qtbot, test_prefix):
editor = DatabaseWidget()
qtbot.addWidget(editor)
editor.set_prefix_root(test_prefix)
editor.setPrefixPath(test_prefix)
return editor
......@@ -330,7 +330,7 @@ class TestDatabaseEditor:
with open(asset_model.json_path(test_database), "rt") as json_file:
json_data = json.load(json_file)
editor = DatabaseEditor()
editor.set_prefix_root(test_prefix)
editor.setPrefixPath(test_prefix)
editor.load_json(json_data)
assert editor.dump_json() == json_data
......@@ -228,7 +228,7 @@ class TestDataformatEditor:
def test_load_and_dump_data(self, qtbot, monkeypatch, test_prefix, reference_json):
editor = DataformatEditor()
qtbot.addWidget(editor)
editor.set_prefix_root(test_prefix)
editor.setPrefixPath(test_prefix)
editor.load_json(reference_json)
......@@ -239,7 +239,7 @@ class TestDataformatEditor:
def test_add(self, qtbot, monkeypatch, test_prefix, dataformat_model):
editor = DataformatEditor()
qtbot.addWidget(editor)
editor.set_prefix_root(test_prefix)
editor.setPrefixPath(test_prefix)
model_index = dataformat_model.index(0, 0)
value = model_index.data()
......
......@@ -34,7 +34,7 @@ class TestLibraryEditor:
reference_json = {"description": "test", "uses": {}}
editor = LibraryEditor()
qtbot.addWidget(editor)
editor.set_prefix_root(test_prefix)
editor.setPrefixPath(test_prefix)
editor.load_json(reference_json)
assert editor.dump_json() == reference_json
......@@ -45,7 +45,7 @@ class TestLibraryEditor:
reference_json = {"description": "test", "uses": {}}
editor = LibraryEditor()
qtbot.addWidget(editor)
editor.set_prefix_root(test_prefix)
editor.setPrefixPath(test_prefix)
editor.load_json(faulty_json)
assert editor.dump_json() == reference_json
......
......@@ -130,7 +130,7 @@ class TestProtocolTemplateEditor:
)
editor = ProtocolTemplateEditor()
editor.set_prefix_root(test_prefix)
editor.setPrefixPath(test_prefix)
editor.load_json(reference_pt_json)
qtbot.addWidget(editor)
......@@ -144,7 +144,7 @@ class TestProtocolTemplateEditor:
edited_json["sets"] = []
editor = ProtocolTemplateEditor()
editor.set_prefix_root(test_prefix)
editor.setPrefixPath(test_prefix)
editor.load_json(reference_pt_json)
qtbot.addWidget(editor)
......
......@@ -251,7 +251,7 @@ class AssetWidget(QWidget):
self.prefix_root_path = prefix_root_path
for i in range(0, self.editors.count()):
self.editors.widget(i).set_prefix_root(prefix_root_path)
self.editors.widget(i).prefix_path = prefix_root_path
def load_json(self, file_path):
""" Load the content of the file given in parameter
......
......@@ -490,7 +490,7 @@ class ViewsEditor(QWidget):
def set_procotol(self, protocol):
self.protocol = protocol
def set_prefix_root(self, prefix):
def setPrefixPath(self, prefix):
self.prefix_path = prefix
def load(self, json_object):
......@@ -554,8 +554,8 @@ class ProtocolEditor(QWidget):
protocol = pyqtProperty(str, fget=protocol, fset=setProtocol)
def set_prefix_root(self, prefix):
self.views_editor.set_prefix_root(prefix)
def setPrefixPath(self, prefix):
self.views_editor.setPrefixPath(prefix)
def load(self, json_object):
"""Load the json object passed as parameter"""
......@@ -695,14 +695,14 @@ class DatabaseWidget(QWidget):
if ok_pressed:
protocol_editor = ProtocolEditor()
protocol_editor.set_prefix_root(self.prefix_path)
protocol_editor.setPrefixPath(self.prefix_path)
protocol_editor.name = name
protocol_editor.protocol = protocol
self.__add_widget(protocol_editor)
self.dataChanged.emit()
def set_prefix_root(self, prefix):
def setPrefixPath(self, prefix):
"""Re-impl"""
self.prefix_path = prefix
......@@ -723,7 +723,7 @@ class DatabaseWidget(QWidget):
for protocol in json_object["protocols"]:
protocol_editor = ProtocolEditor()
protocol_editor.set_prefix_root(self.prefix_path)
protocol_editor.setPrefixPath(self.prefix_path)
protocol_editor.load(protocol)
self.__add_widget(protocol_editor)
......@@ -753,11 +753,9 @@ class DatabaseEditor(AbstractAssetEditor):
self.layout().addWidget(self.stacked_widget, 1)
self.database_widget.dataChanged.connect(self.dataChanged)
def set_prefix_root(self, prefix):
"""Re-impl"""
self.database_widget.set_prefix_root(prefix)
self.prefixPathChanged.connect(
lambda path: self.database_widget.setPrefixPath(path)
)
def _load_json(self, json_object):
"""Load the json object passed as parameter"""
......
......@@ -598,10 +598,9 @@ class DataformatEditor(AbstractAssetEditor):
lambda: self.__add_entry([0, default_object_dataformat()])
)
def set_prefix_root(self, prefix):
"""Re-impl"""
self.dataformat_model.prefix_path = prefix
self.prefixPathChanged.connect(
lambda path: self.dataformat_model.setPrefixPath(path)
)
def __add_entry(self, content):
"""Add a new dataformat entry to the editor
......
......@@ -27,6 +27,7 @@ from ..backend.assetmodel import AssetType
import simplejson as json
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtCore import pyqtProperty
from PyQt5.QtWidgets import QFormLayout
from PyQt5.QtWidgets import QGroupBox
......@@ -40,6 +41,7 @@ class AbstractAssetEditor(QWidget):
"""Base class for BEAT asset editors"""
dataChanged = pyqtSignal()
prefixPathChanged = pyqtSignal(str)
def __init__(self, asset_type, parent=None):
"""Constructor
......@@ -52,6 +54,7 @@ class AbstractAssetEditor(QWidget):
self.asset_type = asset_type
self.schema_version = None
self._prefix_path = None
self.clear_dirty()
self.title_label = QLabel(self.tr("Unknown"))
......@@ -120,6 +123,11 @@ class AbstractAssetEditor(QWidget):
return self._dirty
def create_action(self):
"""Returns the action to use to create a new asset"""
raise NotImplementedError
def set_title(self, title):
"""Set the title of the widget
......@@ -128,14 +136,25 @@ class AbstractAssetEditor(QWidget):
self.title_label.setText(title)
def set_prefix_root(self, prefix):
def setPrefixPath(self, prefix):
"""Set the prefix root path
Default: does nothing
:param prefix str: prefix path
"""
pass
if self._prefix_path == prefix:
return
self._prefix_path = prefix
self.prefixPathChanged.emit(prefix)
def prefixPath(self):
return self._prefix_path
prefix_path = pyqtProperty(
str, fget=prefixPath, fset=setPrefixPath, notify=prefixPathChanged
)
def load_json(self, json_object):
"""Load the json object passed as parameter"""
......
......@@ -53,11 +53,9 @@ class LibraryEditor(AbstractAssetEditor):
self.layout().addWidget(self.libraries_widget)
self.libraries_widget.dataChanged.connect(self.dataChanged)
def set_prefix_root(self, prefix):
"""Re-impl"""
self.library_model.prefix_path = prefix
self.prefixPathChanged.connect(
lambda path: self.library_model.setPrefixPath(path)
)
def _load_json(self, json_object):
"""Load the json object passed as parameter"""
......
......@@ -220,11 +220,9 @@ class ProtocolTemplateEditor(AbstractAssetEditor):
self.layout().addWidget(self.add_set_button, 1)
self.add_set_button.clicked.connect(self.__add_set)
def set_prefix_root(self, prefix):
"""Re-impl"""
self.dataformat_model.prefix_path = prefix
self.prefixPathChanged.connect(
lambda path: self.dataformat_model.setPrefixPath(path)
)
def __on_remove_requested(self):
"""Remove the widget clicked"""
......
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