Commit 358e4230 authored by Samuel GAIST's avatar Samuel GAIST

[widgets][editor] Add validation method to editor

This method will allow to check whether the content of the editor
is valid and continue further.
parent 4bd0bdfd
......@@ -23,6 +23,7 @@
# #
###############################################################################
from ..backend.assetmodel import AssetType
from ..utils import frozen
from .editor import AbstractAssetEditor
......@@ -31,7 +32,7 @@ from .editor import AbstractAssetEditor
@frozen
class AlgorithmEditor(AbstractAssetEditor):
def __init__(self, parent=None):
super(AlgorithmEditor, self).__init__(parent)
super(AlgorithmEditor, self).__init__(AssetType.ALGORITHM, parent)
self.setObjectName(self.__class__.__name__)
self.set_title(self.tr("Algorithm"))
......
......@@ -23,6 +23,7 @@
# #
###############################################################################
from ..backend.assetmodel import AssetType
from ..utils import frozen
from .editor import AbstractAssetEditor
......@@ -31,7 +32,7 @@ from .editor import AbstractAssetEditor
@frozen
class DatabaseEditor(AbstractAssetEditor):
def __init__(self, parent=None):
super(DatabaseEditor, self).__init__(parent)
super(DatabaseEditor, self).__init__(AssetType.DATABASE, parent)
self.setObjectName(self.__class__.__name__)
self.set_title(self.tr("Database"))
......
......@@ -31,7 +31,12 @@ from .editor import AbstractAssetEditor
@frozen
class DataformatEditor(AbstractAssetEditor):
def __init__(self, parent=None):
super(DataformatEditor, self).__init__(parent)
"""Constructor
:param parent QWidget: parent of this widget
"""
super(DataformatEditor, self).__init__(AssetType.DATAFORMAT, parent)
self.setObjectName(self.__class__.__name__)
self.set_title(self.tr("Dataformat"))
......
......@@ -23,6 +23,7 @@
# #
###############################################################################
from ..backend.assetmodel import AssetType
import simplejson as json
from PyQt5.QtCore import pyqtSignal
......@@ -40,7 +41,7 @@ class AbstractAssetEditor(QWidget):
dataChanged = pyqtSignal()
def __init__(self, title, parent=None):
def __init__(self, asset_type, parent=None):
"""Constructor
:param str title: Title of the editor
......@@ -49,6 +50,8 @@ class AbstractAssetEditor(QWidget):
super(AbstractAssetEditor, self).__init__(parent)
self.asset_type = asset_type
self.clear_dirty()
self.title_label = QLabel(self.tr("Unknown"))
self.description_lineedit = QLineEdit()
......@@ -96,6 +99,11 @@ class AbstractAssetEditor(QWidget):
raise NotImplementedError
def is_valid(self):
_, errors = self.asset_type.validate(self.dump_json())
return errors == [], errors
def set_dirty(self):
"""Flag the editor as dirty"""
......@@ -164,8 +172,8 @@ class PlaceholderEditor(AbstractAssetEditor):
:param parent QWidget: parent of this widget
"""
super(PlaceholderEditor, self).__init__(parent)
self.set_title("Nothing to edit")
super(PlaceholderEditor, self).__init__(AssetType.UNKNOWN, parent)
self.set_title(self.tr("Nothing to edit"))
self.information_group_box.hide()
def _load_json(self, json_object):
......
......@@ -23,6 +23,7 @@
# #
###############################################################################
from ..backend.assetmodel import AssetType
from ..utils import frozen
from .editor import AbstractAssetEditor
......@@ -31,7 +32,7 @@ from .editor import AbstractAssetEditor
@frozen
class ExperimentEditor(AbstractAssetEditor):
def __init__(self, parent=None):
super(ExperimentEditor, self).__init__(parent)
super(ExperimentEditor, self).__init__(AssetType.EXPERIMENT, parent)
self.setObjectName(self.__class__.__name__)
self.set_title(self.tr("Experiment"))
......
......@@ -42,7 +42,7 @@ class LibraryEditor(AbstractAssetEditor):
:param parent QWidget: parent of this widget
"""
super(LibraryEditor, self).__init__(parent)
super(LibraryEditor, self).__init__(AssetType.LIBRARY, parent)
self.setObjectName(self.__class__.__name__)
self.set_title(self.tr("Library"))
......
......@@ -23,6 +23,7 @@
# #
###############################################################################
from ..backend.assetmodel import AssetType
from ..utils import frozen
from .editor import AbstractAssetEditor
......@@ -31,7 +32,7 @@ from .editor import AbstractAssetEditor
@frozen
class PlotterEditor(AbstractAssetEditor):
def __init__(self, parent=None):
super(PlotterEditor, self).__init__(parent)
super(PlotterEditor, self).__init__(AssetType.PLOTTER, parent)
self.setObjectName(self.__class__.__name__)
self.set_title(self.tr("Plotter"))
......
......@@ -23,6 +23,7 @@
# #
###############################################################################
from ..backend.assetmodel import AssetType
from ..utils import frozen
from .editor import AbstractAssetEditor
......@@ -31,7 +32,9 @@ from .editor import AbstractAssetEditor
@frozen
class PlotterParametersEditor(AbstractAssetEditor):
def __init__(self, parent=None):
super(PlotterParametersEditor, self).__init__(parent)
super(PlotterParametersEditor, self).__init__(
AssetType.PLOTTERPARAMETERS, parent
)
self.setObjectName(self.__class__.__name__)
self.set_title(self.tr("Plotter Parameters"))
......
......@@ -23,6 +23,7 @@
# #
###############################################################################
from ..backend.assetmodel import AssetType
from ..utils import frozen
from .editor import AbstractAssetEditor
......@@ -31,7 +32,7 @@ from .editor import AbstractAssetEditor
@frozen
class ToolchainEditor(AbstractAssetEditor):
def __init__(self, parent=None):
super(ToolchainEditor, self).__init__(parent)
super(ToolchainEditor, self).__init__(AssetType.TOOLCHAIN, parent)
self.setObjectName(self.__class__.__name__)
self.set_title(self.tr("Toolchain"))
......
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