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

[widgets] Moved description widget content in AbstractAssetEditor

DescriptionWidget was over-engineering.
parent 208f2e47
......@@ -29,11 +29,9 @@ from PyQt5 import QtCore
from PyQt5.QtCore import QStringListModel
from PyQt5.QtWidgets import QPushButton
from PyQt5.QtWidgets import QVBoxLayout
from ..widgets.editor import AbstractAssetEditor
from ..widgets.field import FieldWidget
from ..widgets.description import DescriptionWidget
class MockAssetEditor(AbstractAssetEditor):
......@@ -45,10 +43,7 @@ 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.layout().addWidget(self.add_field_button)
self.add_field_button.clicked.connect(self.__add_field)
......@@ -58,7 +53,7 @@ class MockAssetEditor(AbstractAssetEditor):
def set_dataformat_model(self, model):
self.dataformat_model = model
def load_json(self, json_object):
def _load_json(self, json_object):
"""Load the json object passed as parameter"""
for name, type_ in json_object["field"].items():
......@@ -67,10 +62,7 @@ class MockAssetEditor(AbstractAssetEditor):
field.format_type = type_
self.layout().addWidget(field)
short_text = json_object["description"]
self.description.form_description.setText(short_text)
def dump_json(self):
def _dump_json(self):
"""Returns the json representation of the asset"""
json_data = {}
......@@ -79,7 +71,6 @@ class MockAssetEditor(AbstractAssetEditor):
json_data["field"] = {}
for field in field_list:
json_data["field"][field.format_name] = field.format_type
json_data["description"] = self.description.short_description
return json_data
......
# 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.QtCore import pyqtProperty
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()
shortDescriptionChanged = pyqtSignal(str)
def __init__(self, parent=None):
"""Constructor
:param parent QWidget: parent widget
"""
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 shortDescription(self):
"""Short description text"""
return self.form_description.text()
def setShortDescription(self, description):
"""Set short description text
:param description str: Description
"""
self.form_description.setText(description)
short_description = pyqtProperty(
str,
fget=shortDescription,
fset=setShortDescription,
notify=shortDescriptionChanged,
)
......@@ -25,13 +25,13 @@
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtWidgets import QLabel
from PyQt5.QtWidgets import QFormLayout
from PyQt5.QtWidgets import QGroupBox
from PyQt5.QtWidgets import QLabel
from PyQt5.QtWidgets import QLineEdit
from PyQt5.QtWidgets import QWidget
from PyQt5.QtWidgets import QVBoxLayout
from .description import DescriptionWidget
class AbstractAssetEditor(QWidget):
"""Base class for BEAT asset editors"""
......@@ -48,19 +48,18 @@ class AbstractAssetEditor(QWidget):
super(AbstractAssetEditor, self).__init__(parent)
self.clear_dirty()
self.titleLabel = QLabel(self.tr("Unknown"))
self.description_widget = DescriptionWidget()
self.title_label = QLabel(self.tr("Unknown"))
self.description_lineedit = QLineEdit()
self.information_group_box = QGroupBox(self.tr("Information"))
group_box_layout = QVBoxLayout(self.information_group_box)
group_box_layout.addWidget(self.description_widget)
group_box_layout.addStretch(1)
group_box_layout = QFormLayout(self.information_group_box)
group_box_layout.addRow(self.tr("Short description"), self.description_lineedit)
layout = QVBoxLayout(self)
layout.addWidget(self.titleLabel)
layout.addWidget(self.title_label)
layout.addWidget(self.information_group_box)
self.description_widget.dataChanged.connect(self.dataChanged)
self.description_lineedit.textChanged.connect(self.dataChanged)
self.dataChanged.connect(self.set_dirty)
def _load_json(self, json_object):
......@@ -92,7 +91,7 @@ class AbstractAssetEditor(QWidget):
:param title str: Title of the widget
"""
self.titleLabel.setText(title)
self.title_label.setText(title)
def set_dataformat_model(self, model):
"""Sets the model used to get Dataformat informations"""
......@@ -102,14 +101,14 @@ class AbstractAssetEditor(QWidget):
"""Load the json object passed as parameter"""
self.blockSignals(True)
self.description_widget.short_description = json_object.get("description")
self.description_lineedit.setText(json_object.get("description"))
self._load_json(json_object)
self.blockSignals(False)
self.clear_dirty()
def dump_json(self):
"""Returns the json representation of the asset"""
json_data = {"description": self.description_widget.short_description}
json_data = {"description": self.description_lineedit.text()}
json_data.update(self._dump_json())
return json_data
......
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