Commit 73328f6f authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[widgets] Implement library editor

Fixes #178
parent 9aa483ca
......@@ -30,10 +30,19 @@ from ..widgets.libraryeditor import LibraryEditor
class TestLibraryEditor:
"""Test that the mock editor works correctly"""
def test_load_and_dump(self, qtbot):
reference_json = {"description": "test"}
def test_load_and_dump(self, qtbot, test_prefix):
reference_json = {"description": "test", "uses": {}}
editor = LibraryEditor()
editor.set_prefix_root(test_prefix)
editor.load_json(reference_json)
assert editor.dump_json() == reference_json
def test_load_and_dump_wrong(self, qtbot, test_prefix):
faulty_json = {"description": "test", "uses": {"alias": "test/dummy/1"}}
reference_json = {"description": "test", "uses": {}}
editor = LibraryEditor()
editor.set_prefix_root(test_prefix)
editor.load_json(faulty_json)
assert editor.dump_json() == reference_json
......@@ -232,6 +232,8 @@ class AssetWidget(QWidget):
"""Sets the root path of the prefix to edit"""
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)
def load_json(self, file_path):
""" Load the content of the file given in parameter
......
......@@ -93,6 +93,15 @@ class AbstractAssetEditor(QWidget):
self.title_label.setText(title)
def set_prefix_root(self, prefix):
"""Set the prefix root path
Default: does nothing
:param prefix str: prefix path
"""
pass
def set_dataformat_model(self, model):
"""Sets the model used to get Dataformat informations"""
raise NotImplementedError
......
......@@ -25,7 +25,11 @@
from ..utils import frozen
from ..backend.assetmodel import AssetType
from ..backend.assetmodel import AssetModel
from .editor import AbstractAssetEditor
from .libraries import LibrariesWidget
@frozen
......@@ -35,10 +39,26 @@ class LibraryEditor(AbstractAssetEditor):
self.setObjectName(self.__class__.__name__)
self.set_title(self.tr("Library"))
self.library_model = AssetModel()
self.library_model.asset_type = AssetType.LIBRARY
self.libraries_widget = LibrariesWidget()
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
def _load_json(self, json_object):
"""Load the json object passed as parameter"""
pass
self.libraries_widget.set_available_libraries(self.library_model.stringList())
self.libraries_widget.set_used_libraries(json_object.get("uses", {}))
def _dump_json(self):
"""Returns the json representation of the asset"""
return {}
return {"uses": self.libraries_widget.get_used_libraries()}
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