From d9099743d9eaa5e2104fc6d675450cb2ae4460a8 Mon Sep 17 00:00:00 2001 From: un-pogaz <46523284+un-pogaz@users.noreply.github.com> Date: Sun, 28 May 2023 10:47:06 +0200 Subject: [PATCH] group setEditorData() in a shared class for Texts --- src/calibre/gui2/library/delegates.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py index 416ba3d2ab..799e5beac4 100644 --- a/src/calibre/gui2/library/delegates.py +++ b/src/calibre/gui2/library/delegates.py @@ -109,6 +109,11 @@ class UpdateEditorGeometry: initial_geometry.adjust(delta_x, 0, delta_width, 0) editor.setGeometry(initial_geometry) +class EditableTextDelegate: + + def setEditorData(self, editor, index): + n = editor.metaObject().userProperty().name() + editor.setProperty(n, get_val_for_textlike_columns(index)) class DateTimeEdit(DateTimeEditBase): # {{{ @@ -285,7 +290,7 @@ class PubDateDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{ # }}} -class TextDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{ +class TextDelegate(QStyledItemDelegate, UpdateEditorGeometry, EditableTextDelegate): # {{{ use_title_sort = False @@ -316,10 +321,6 @@ class TextDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{ editor = EnLineEdit(parent) return editor - def setEditorData(self, editor, index): - n = editor.metaObject().userProperty().name() - editor.setProperty(n, get_val_for_textlike_columns(index)) - def setModelData(self, editor, model, index): if isinstance(editor, EditWithComplete): val = editor.lineEdit().text() @@ -340,7 +341,7 @@ class SeriesDelegate(TextDelegate): # {{{ # }}} -class CompleteDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{ +class CompleteDelegate(QStyledItemDelegate, UpdateEditorGeometry, EditableTextDelegate): # {{{ def __init__(self, parent, sep, items_func_name, space_before_sep=False): QStyledItemDelegate.__init__(self, parent) @@ -381,10 +382,6 @@ class CompleteDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{ editor = EnLineEdit(parent) return editor - def setEditorData(self, editor, index): - n = editor.metaObject().userProperty().name() - editor.setProperty(n, get_val_for_textlike_columns(index)) - def setModelData(self, editor, model, index): if isinstance(editor, EditWithComplete): val = editor.lineEdit().text() @@ -464,7 +461,7 @@ class CcDateDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{ # }}} -class CcTextDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{ +class CcTextDelegate(QStyledItemDelegate, UpdateEditorGeometry, EditableTextDelegate): # {{{ ''' Delegate for text data. @@ -495,10 +492,6 @@ class CcTextDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{ editor.setText(text) return editor - def setEditorData(self, editor, index): - n = editor.metaObject().userProperty().name() - editor.setProperty(n, get_val_for_textlike_columns(index)) - def setModelData(self, editor, model, index): val = editor.text() or '' if not isinstance(editor, EditWithComplete):