Skip to content
Snippets Groups Projects
Commit ae914553 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

Merge branch 'reusable_widget_short_description' into 'v2'

Reusable widget short description

See merge request !55
parents 4d89532a 8cee4655
No related branches found
No related tags found
1 merge request!55Reusable widget short description
Pipeline #27672 passed
......@@ -33,6 +33,7 @@ from PyQt5.QtWidgets import QVBoxLayout
from ..widgets.editor import AbstractAssetEditor
from ..widgets.field import FieldWidget
from ..widgets.description import DescriptionWidget
class MockAssetEditor(AbstractAssetEditor):
......@@ -44,7 +45,9 @@ class MockAssetEditor(AbstractAssetEditor):
super(MockAssetEditor, self).__init__(parent)
self.dataformat_model = None
self.add_field_button = QPushButton(self.tr("Add"))
self.description = DescriptionWidget()
layout = QVBoxLayout(self)
layout.addWidget(self.description)
layout.addWidget(self.add_field_button)
self.add_field_button.clicked.connect(self.__add_field)
......@@ -58,21 +61,25 @@ class MockAssetEditor(AbstractAssetEditor):
def load_json(self, json_object):
"""Load the json object passed as parameter"""
for name, type_ in json_object.items():
for name, type_ in json_object["field"].items():
field = FieldWidget(self.dataformat_model)
field.format_name = name
field.format_type = type_
self.layout().addWidget(field)
short_text = json_object["description"]
self.description.form_description.setText(short_text)
def dump_json(self):
"""Returns the json representation of the asset"""
field_list = self.findChildren(FieldWidget)
json_data = {}
field_list = self.findChildren(FieldWidget)
json_data["field"] = {}
for field in field_list:
json_data[field.format_name] = field.format_type
json_data["field"][field.format_name] = field.format_type
json_data["description"] = self.description.short_description()
return json_data
......@@ -85,8 +92,11 @@ def dataformat_model():
class TestMockEditor:
"""Test that the mock editor works correctly"""
def test_json_load_and_dump(self, qtbot, dataformat_model):
json_reference = {"value32": "float32", "value64": "float64"}
def test_json_load_and_dump_field_widget(self, qtbot, dataformat_model):
json_reference = {
"field": {"value32": "float32", "value64": "float64"},
"description": "Short description test",
}
widget = MockAssetEditor()
widget.set_dataformat_model(dataformat_model)
......@@ -94,7 +104,7 @@ class TestMockEditor:
assert widget.dump_json() == json_reference
def test_dataformat_creation(self, qtbot, dataformat_model):
def test_dataformat_creation_field_widget(self, qtbot, dataformat_model):
widget = MockAssetEditor()
widget.set_dataformat_model(dataformat_model)
......@@ -108,7 +118,10 @@ class TestMockEditor:
field.format_name = "value32"
field.format_type = "float32"
assert widget.dump_json() == {"value32": "float32"}
assert widget.dump_json() == {
"field": {"value32": "float32"},
"description": "",
}
qtbot.mouseClick(widget.add_field_button, QtCore.Qt.LeftButton)
fields = widget.findChildren(FieldWidget)
......@@ -120,4 +133,7 @@ class TestMockEditor:
field.format_name = "value64"
field.format_type = "float64"
assert widget.dump_json() == {"value32": "float32", "value64": "float64"}
assert widget.dump_json() == {
"field": {"value32": "float32", "value64": "float64"},
"description": "",
}
# vim: set fileencoding=utf-8 :
###############################################################################
# #
# Copyright (c) 2019 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# This file is part of the beat.editor module of the BEAT platform. #
# #
# Commercial License Usage #
# Licensees holding valid commercial BEAT licenses may use this file in #
# accordance with the terms contained in a written agreement between you #
# and Idiap. For further information contact tto@idiap.ch #
# #
# Alternatively, this file may be used under the terms of the GNU Affero #
# Public License version 3 as published by the Free Software and appearing #
# in the file LICENSE.AGPL included in the packaging of this file. #
# The BEAT platform is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
# or FITNESS FOR A PARTICULAR PURPOSE. #
# #
# You should have received a copy of the GNU Affero Public License along #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/. #
# #
###############################################################################
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtWidgets import QLineEdit
from PyQt5.QtWidgets import QWidget
from PyQt5.QtWidgets import QFormLayout
class DescriptionWidget(QWidget):
"""Class representing the short description of a beat object"""
dataChanged = pyqtSignal()
def __init__(self, parent=None):
"""Constructor"""
super(DescriptionWidget, self).__init__(parent)
self.form_description = QLineEdit()
layout = QFormLayout(self)
layout.addRow(self.tr("Short Description:"), self.form_description)
self.form_description.textChanged.connect(self.dataChanged)
def short_description(self):
"""Short description text"""
return self.form_description.text()
......@@ -58,6 +58,7 @@ class FieldWidget(QWidget):
@property
def format_type(self):
"""Data format type property"""
return self.dataformat_box.currentText()
@format_type.setter
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment