From 144ff50879c339ecd68187b7e9627dfe90a86512 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 15 Jul 2011 09:54:13 -0600 Subject: [PATCH] When editing metadata directly in the books list, have a little pop up menu so that all existing values can be accessed by mouse only. So when you edit authors, you can use the mouse to select an existing author, and so on. --- src/calibre/gui2/library/delegates.py | 31 ++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py index 02f7452694..b0fdef4c21 100644 --- a/src/calibre/gui2/library/delegates.py +++ b/src/calibre/gui2/library/delegates.py @@ -16,7 +16,7 @@ from PyQt4.Qt import (QColor, Qt, QModelIndex, QSize, QApplication, from calibre.gui2 import UNDEFINED_QDATE, error_dialog from calibre.gui2.widgets import EnLineEdit -from calibre.gui2.complete import MultiCompleteLineEdit +from calibre.gui2.complete import MultiCompleteLineEdit, MultiCompleteComboBox from calibre.utils.date import now, format_date from calibre.utils.config import tweaks from calibre.utils.formatter import validation_formatter @@ -166,13 +166,26 @@ class TextDelegate(QStyledItemDelegate): # {{{ def createEditor(self, parent, option, index): if self.auto_complete_function: - editor = MultiCompleteLineEdit(parent) + editor = MultiCompleteComboBox(parent) editor.set_separator(None) complete_items = [i[1] for i in self.auto_complete_function()] editor.update_items_cache(complete_items) + for item in sorted(complete_items, key=sort_key): + editor.addItem(item) + ct = index.data(Qt.DisplayRole).toString() + editor.setEditText(ct) + editor.lineEdit().selectAll() else: editor = EnLineEdit(parent) return editor + + def setModelData(self, editor, model, index): + if isinstance(editor, MultiCompleteComboBox): + val = editor.lineEdit().text() + model.setData(index, QVariant(val), Qt.EditRole) + else: + QStyledItemDelegate.setModelData(self, editor, model, index) + #}}} class CompleteDelegate(QStyledItemDelegate): # {{{ @@ -188,7 +201,7 @@ class CompleteDelegate(QStyledItemDelegate): # {{{ def createEditor(self, parent, option, index): if self.db and hasattr(self.db, self.items_func_name): col = index.model().column_map[index.column()] - editor = MultiCompleteLineEdit(parent) + editor = MultiCompleteComboBox(parent) editor.set_separator(self.sep) editor.set_space_before_sep(self.space_before_sep) if self.sep == '&': @@ -199,9 +212,21 @@ class CompleteDelegate(QStyledItemDelegate): # {{{ all_items = list(self.db.all_custom( label=self.db.field_metadata.key_to_label(col))) editor.update_items_cache(all_items) + for item in sorted(all_items, key=sort_key): + editor.addItem(item) + ct = index.data(Qt.DisplayRole).toString() + editor.setEditText(ct) + editor.lineEdit().selectAll() else: editor = EnLineEdit(parent) return editor + + def setModelData(self, editor, model, index): + if isinstance(editor, MultiCompleteComboBox): + val = editor.lineEdit().text() + model.setData(index, QVariant(val), Qt.EditRole) + else: + QStyledItemDelegate.setModelData(self, editor, model, index) # }}} class CcDateDelegate(QStyledItemDelegate): # {{{