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

[widgets][dataformateditor] Use validated input widgets

parent 2dbf66dc
......@@ -28,7 +28,6 @@ import random
import pytest
from PyQt5 import QtCore
from PyQt5.QtWidgets import QInputDialog
from ..backend.assetmodel import DataFormatModel
from ..widgets.dataformateditor import DataformatArrayWidget
......@@ -37,6 +36,7 @@ from ..widgets.dataformateditor import DataformatObjectWidget
from ..widgets.dataformateditor import DataformatWidget
from ..widgets.dataformateditor import default_dataformat
from ..widgets.dataformateditor import default_object_dataformat
from ..widgets.dialogs import NameInputDialog
@pytest.fixture()
......@@ -103,14 +103,14 @@ class TestDataformatObjectWidget:
reference_json = {"test_type": value}
monkeypatch.setattr(
QInputDialog, "getText", classmethod(lambda *args: ("test_type", True))
NameInputDialog, "getText", classmethod(lambda *args: ("test_type", True))
)
editor.add_type_action.trigger()
assert editor.dump() == reference_json
monkeypatch.setattr(
QInputDialog, "getText", classmethod(lambda *args: ("test_object", True))
NameInputDialog, "getText", classmethod(lambda *args: ("test_object", True))
)
editor.add_object_action.trigger()
reference_json["test_object"] = default_object_dataformat()
......@@ -118,7 +118,7 @@ class TestDataformatObjectWidget:
assert editor.dump() == reference_json
monkeypatch.setattr(
QInputDialog,
NameInputDialog,
"getText",
classmethod(lambda *args: ("test_type_array", True)),
)
......@@ -128,7 +128,7 @@ class TestDataformatObjectWidget:
assert editor.dump() == reference_json
monkeypatch.setattr(
QInputDialog,
NameInputDialog,
"getText",
classmethod(lambda *args: ("test_object_array", True)),
)
......@@ -243,7 +243,7 @@ class TestDataformatEditor:
value = model_index.data()
monkeypatch.setattr(
QInputDialog, "getText", classmethod(lambda *args: ("test_type", True))
NameInputDialog, "getText", classmethod(lambda *args: ("test_type", True))
)
editor.add_type_action.trigger()
reference_json = {"test_type": value}
......@@ -253,7 +253,7 @@ class TestDataformatEditor:
assert validated, errors
monkeypatch.setattr(
QInputDialog, "getText", classmethod(lambda *args: ("test_object", True))
NameInputDialog, "getText", classmethod(lambda *args: ("test_object", True))
)
editor.add_object_action.trigger()
reference_json["test_object"] = default_object_dataformat()
......@@ -263,7 +263,7 @@ class TestDataformatEditor:
assert validated, errors
monkeypatch.setattr(
QInputDialog,
NameInputDialog,
"getText",
classmethod(lambda *args: ("test_type_array", True)),
)
......@@ -275,7 +275,7 @@ class TestDataformatEditor:
assert validated, errors
monkeypatch.setattr(
QInputDialog,
NameInputDialog,
"getText",
classmethod(lambda *args: ("test_object_array", True)),
)
......
......@@ -30,9 +30,7 @@ from PyQt5.QtWidgets import QComboBox
from PyQt5.QtWidgets import QFormLayout
from PyQt5.QtWidgets import QGroupBox
from PyQt5.QtWidgets import QHBoxLayout
from PyQt5.QtWidgets import QInputDialog
from PyQt5.QtWidgets import QLabel
from PyQt5.QtWidgets import QLineEdit
from PyQt5.QtWidgets import QMenu
from PyQt5.QtWidgets import QPushButton
from PyQt5.QtWidgets import QSpinBox
......@@ -42,8 +40,10 @@ from ..backend.asset import AssetType
from ..backend.assetmodel import DataFormatModel
from ..decorators import frozen
from ..utils import dataformat_basetypes
from .dialogs import NameInputDialog
from .editor import AbstractAssetEditor
from .scrollwidget import ScrollWidget
from .validatedhelpers import NameLineEdit
def create_button_layout(button):
......@@ -114,7 +114,7 @@ class DataformatBaseWidget(QGroupBox):
self.delete_button = QPushButton(self.tr("-"))
self.delete_button.setFixedSize(30, 30)
self.name_lineedit = QLineEdit()
self.name_lineedit = NameLineEdit()
self.name_layout = QHBoxLayout()
self.name_layout.addWidget(self.name_lineedit, 10)
......@@ -288,9 +288,7 @@ class DataformatObjectWidget(DataformatBaseWidget):
format_names = [widgets.name() for widgets in self.dataformat_widgets]
while True:
name, ok_pressed = QInputDialog.getText(
self, self.tr("Field name"), self.tr("Name")
)
name, ok_pressed = NameInputDialog.getText(self, self.tr("Field name"))
if not ok_pressed:
break
......@@ -617,9 +615,7 @@ class DataformatEditor(AbstractAssetEditor):
format_names = [widgets.name() for widgets in self.dataformat_widgets]
while True:
name, ok_pressed = QInputDialog.getText(
self, self.tr("Field name"), self.tr("Name")
)
name, ok_pressed = NameInputDialog.getText(self, self.tr("Field name"))
if not ok_pressed:
break
......
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