Fix all number items being deleted on initial edit in book list

This commit is contained in:
Kovid Goyal 2012-07-13 21:45:50 +05:30
parent 5102a20efb
commit 69f74c2018
2 changed files with 22 additions and 8 deletions

View File

@ -372,6 +372,9 @@ class EditWithComplete(EnComboBox):
def text(self): def text(self):
return unicode(self.lineEdit().text()) return unicode(self.lineEdit().text())
def selectAll(self):
self.lineEdit().selectAll()
def setText(self, val): def setText(self, val):
le = self.lineEdit() le = self.lineEdit()
le.no_popup = True le.no_popup = True

View File

@ -125,12 +125,15 @@ class TextDelegate(QStyledItemDelegate): # {{{
editor.set_separator(None) editor.set_separator(None)
complete_items = [i[1] for i in self.auto_complete_function()] complete_items = [i[1] for i in self.auto_complete_function()]
editor.update_items_cache(complete_items) editor.update_items_cache(complete_items)
ct = index.data(Qt.DisplayRole).toString()
editor.show_initial_value(ct)
else: else:
editor = EnLineEdit(parent) editor = EnLineEdit(parent)
return editor return editor
def setEditorData(self, editor, index):
ct = unicode(index.data(Qt.DisplayRole).toString())
editor.setText(ct)
editor.selectAll()
def setModelData(self, editor, model, index): def setModelData(self, editor, model, index):
if isinstance(editor, EditWithComplete): if isinstance(editor, EditWithComplete):
val = editor.lineEdit().text() val = editor.lineEdit().text()
@ -164,12 +167,15 @@ class CompleteDelegate(QStyledItemDelegate): # {{{
all_items = list(self.db.all_custom( all_items = list(self.db.all_custom(
label=self.db.field_metadata.key_to_label(col))) label=self.db.field_metadata.key_to_label(col)))
editor.update_items_cache(all_items) editor.update_items_cache(all_items)
ct = index.data(Qt.DisplayRole).toString()
editor.show_initial_value(ct)
else: else:
editor = EnLineEdit(parent) editor = EnLineEdit(parent)
return editor return editor
def setEditorData(self, editor, index):
ct = unicode(index.data(Qt.DisplayRole).toString())
editor.setText(ct)
editor.selectAll()
def setModelData(self, editor, model, index): def setModelData(self, editor, model, index):
if isinstance(editor, EditWithComplete): if isinstance(editor, EditWithComplete):
val = editor.lineEdit().text() val = editor.lineEdit().text()
@ -183,10 +189,12 @@ class LanguagesDelegate(QStyledItemDelegate): # {{{
def createEditor(self, parent, option, index): def createEditor(self, parent, option, index):
editor = LanguagesEdit(parent=parent) editor = LanguagesEdit(parent=parent)
editor.init_langs(index.model().db) editor.init_langs(index.model().db)
ct = index.data(Qt.DisplayRole).toString()
editor.show_initial_value(ct)
return editor return editor
def setEditorData(self, editor, index):
ct = unicode(index.data(Qt.DisplayRole).toString())
editor.show_initial_value(ct)
def setModelData(self, editor, model, index): def setModelData(self, editor, model, index):
val = ','.join(editor.lang_codes) val = ','.join(editor.lang_codes)
model.setData(index, QVariant(val), Qt.EditRole) model.setData(index, QVariant(val), Qt.EditRole)
@ -249,10 +257,13 @@ class CcTextDelegate(QStyledItemDelegate): # {{{
complete_items = sorted(list(m.db.all_custom(label=m.db.field_metadata.key_to_label(col))), complete_items = sorted(list(m.db.all_custom(label=m.db.field_metadata.key_to_label(col))),
key=sort_key) key=sort_key)
editor.update_items_cache(complete_items) editor.update_items_cache(complete_items)
ct = index.data(Qt.DisplayRole).toString()
editor.show_initial_value(ct)
return editor return editor
def setEditorData(self, editor, index):
ct = unicode(index.data(Qt.DisplayRole).toString())
editor.setText(ct)
editor.selectAll()
def setModelData(self, editor, model, index): def setModelData(self, editor, model, index):
val = editor.text() val = editor.text()
model.setData(index, QVariant(val), Qt.EditRole) model.setData(index, QVariant(val), Qt.EditRole)