Forgot the custom series edit widgets in my last commit

This commit is contained in:
Kovid Goyal 2022-06-23 22:48:38 +05:30
parent 98dea95759
commit ccb6ff9d3e
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 10 additions and 3 deletions

View File

@ -14,6 +14,7 @@ from qt.core import (Qt, QComboBox, QLabel, QSpinBox, QDoubleSpinBox,
QSpacerItem, QIcon, QCheckBox, QWidget, QHBoxLayout, QLineEdit, QSpacerItem, QIcon, QCheckBox, QWidget, QHBoxLayout, QLineEdit,
QMessageBox, QToolButton, QPlainTextEdit, QApplication, QStyle, QDialog) QMessageBox, QToolButton, QPlainTextEdit, QApplication, QStyle, QDialog)
from calibre.ebooks.metadata import title_sort
from calibre.utils.date import qt_to_dt, now, as_local_time, as_utc, internal_iso_format_string from calibre.utils.date import qt_to_dt, now, as_local_time, as_utc, internal_iso_format_string
from calibre.gui2.complete2 import EditWithComplete as EWC from calibre.gui2.complete2 import EditWithComplete as EWC
from calibre.gui2.comments_editor import Editor as CommentsEditor from calibre.gui2.comments_editor import Editor as CommentsEditor
@ -591,7 +592,7 @@ class Text(Base):
class Series(Base): class Series(Base):
def setup_ui(self, parent): def setup_ui(self, parent):
w = EditWithComplete(parent) w = EditWithComplete(parent, sort_key=title_sort)
w.set_separator(None) w.set_separator(None)
w.setSizeAdjustPolicy(QComboBox.SizeAdjustPolicy.AdjustToMinimumContentsLengthWithIcon) w.setSizeAdjustPolicy(QComboBox.SizeAdjustPolicy.AdjustToMinimumContentsLengthWithIcon)
w.setMinimumContentsLength(25) w.setMinimumContentsLength(25)
@ -1178,7 +1179,7 @@ class BulkDateTime(BulkBase):
class BulkSeries(BulkBase): class BulkSeries(BulkBase):
def setup_ui(self, parent): def setup_ui(self, parent):
self.make_widgets(parent, EditWithComplete) self.make_widgets(parent, partial(EditWithComplete, sort_func=title_sort))
values = self.all_values = list(self.db.all_custom(num=self.col_id)) values = self.all_values = list(self.db.all_custom(num=self.col_id))
values.sort(key=sort_key) values.sort(key=sort_key)
self.main_widget.setSizeAdjustPolicy(QComboBox.SizeAdjustPolicy.AdjustToMinimumContentsLengthWithIcon) self.main_widget.setSizeAdjustPolicy(QComboBox.SizeAdjustPolicy.AdjustToMinimumContentsLengthWithIcon)

View File

@ -468,6 +468,7 @@ class CcTextDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{
''' '''
Delegate for text data. Delegate for text data.
''' '''
use_title_sort = False
def __init__(self, parent): def __init__(self, parent):
QStyledItemDelegate.__init__(self, parent) QStyledItemDelegate.__init__(self, parent)
@ -478,7 +479,10 @@ class CcTextDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{
col = m.column_map[index.column()] col = m.column_map[index.column()]
key = m.db.field_metadata.key_to_label(col) key = m.db.field_metadata.key_to_label(col)
if m.db.field_metadata[col]['datatype'] != 'comments': if m.db.field_metadata[col]['datatype'] != 'comments':
editor = EditWithComplete(parent) if self.use_title_sort:
editor = EditWithComplete(parent, sort_func=title_sort)
else:
editor = EditWithComplete(parent)
editor.set_separator(None) editor.set_separator(None)
editor.set_clear_button_enabled(False) editor.set_clear_button_enabled(False)
complete_items = sorted(list(m.db.all_custom(label=key)), key=sort_key) complete_items = sorted(list(m.db.all_custom(label=key)), key=sort_key)
@ -505,6 +509,8 @@ class CcTextDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{
class CcSeriesDelegate(CcTextDelegate): # {{{ class CcSeriesDelegate(CcTextDelegate): # {{{
use_title_sort = True
def initStyleOption(self, option, index): def initStyleOption(self, option, index):
CcTextDelegate.initStyleOption(self, option, index) CcTextDelegate.initStyleOption(self, option, index)
option.textElideMode = Qt.TextElideMode.ElideMiddle option.textElideMode = Qt.TextElideMode.ElideMiddle