impr: able to edit chart/score when original value is invalid

This commit is contained in:
283375 2023-09-06 01:17:37 +08:00
parent 1955a7963a
commit 3f42be3212
2 changed files with 27 additions and 21 deletions

View File

@ -152,10 +152,10 @@ class ChartDelegate(TextSegmentDelegate):
def createEditor(
self, parent: QWidget, option: QStyleOptionViewItem, index: QModelIndex
) -> ChartSelectorDelegateWrapper:
if isinstance(self.getChart(index), Chart):
editor = ChartSelectorDelegateWrapper(parent)
editor.setWindowFlag(Qt.WindowType.Sheet, True)
editor.setWindowFlag(Qt.WindowType.FramelessWindowHint, True)
if isinstance(self.getChart(index), Chart):
editor.setText(self.getChart(index))
editor.move(parent.mapToGlobal(parent.pos()))
editor.accepted.connect(self._commitEditor)

View File

@ -198,23 +198,28 @@ class ScoreDelegate(TextSegmentDelegate):
self.closeEditor.emit(editor)
def createEditor(self, parent, option, index) -> ScoreEditorDelegateWrapper:
score = self.getScore(index)
chart = self.getChart(index)
if isinstance(score, Score) and isinstance(chart, Chart):
editor = ScoreEditorDelegateWrapper(parent)
editor.setWindowFlag(Qt.WindowType.Sheet, True)
editor.setWindowFlag(Qt.WindowType.FramelessWindowHint, True)
chart = self.getChart(index)
score = self.getScore(index)
if isinstance(chart, Chart):
editor.setWindowTitle(
f"{chart.title}({chart.song_id}) | {rating_class_to_text(chart.rating_class)} | {chart.set}"
)
editor.setText(self.getScore(index))
else:
editor.setWindowTitle("-")
if isinstance(score, Score):
editor.setText(score)
editor.setValidateBeforeAccept(False)
editor.move(parent.mapToGlobal(parent.pos()))
editor.accepted.connect(self._commitEditor)
editor.rejected.connect(self._closeEditor)
editor.show()
return editor
return super().createEditor(parent, option, index)
def updateEditorGeometry(self, editor, option, index):
editor.setMaximumWidth(option.rect.width())
@ -225,8 +230,9 @@ class ScoreDelegate(TextSegmentDelegate):
def setEditorData(self, editor: ScoreEditorDelegateWrapper, index) -> None:
score = self.getScore(index)
chart = self.getChart(index)
if isinstance(score, Score) and isinstance(chart, Chart):
if isinstance(chart, Chart):
editor.setChart(chart)
if isinstance(score, Score):
editor.setValue(score)
def confirmSetModelData(self, editor: ScoreEditorDelegateWrapper):