mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Another try at preventing random edit dialogs while not losing "editing" when tabbing over read-only fields.
The problem of random dialogs is handled in delegates.py. Losing "editing" when tabbing is handled by jumping over fields that are readonly or are implemented by a doalog. This is a behavior change. We will see whether it will result in screams of complaint. NB: after hours of trying, this was the only solution I found to both the random dialog and the loss of editing.
This commit is contained in:
parent
9eaef3ceb0
commit
b3b08b0e17
@ -218,12 +218,15 @@ class StyledItemDelegate(QStyledItemDelegate):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.table_widget = args[0]
|
self.table_widget = args[0]
|
||||||
|
# Set this to True here. It is up the the subclasses to set it to False if needed.
|
||||||
|
self.is_editable_with_tab = True
|
||||||
|
|
||||||
def createEditor(self, parent, option, index):
|
def createEditor(self, parent, option, index):
|
||||||
if self.table_widget.currentIndex().row() != index.row():
|
if self.table_widget.currentIndex() != index:
|
||||||
print(f'createEditor row error: delegate: {self.__class__.__name__}. '
|
idx = self.table_widget.currentIndex()
|
||||||
f'row: {self.table_widget.currentIndex().row()}, '
|
print(f'createEditor idx err: delegate={self.__class__.__name__}. '
|
||||||
f'index row: {index.row()}, index column:{index.column()}')
|
f'cur idx=({idx.row()}, {idx.column()}), '
|
||||||
|
f'given idx=({index.row()}, {index.column()})')
|
||||||
return None
|
return None
|
||||||
return self.create_editor(parent, option, index)
|
return self.create_editor(parent, option, index)
|
||||||
|
|
||||||
@ -579,6 +582,7 @@ class CcLongTextDelegate(StyledItemDelegate): # {{{
|
|||||||
StyledItemDelegate.__init__(self, parent)
|
StyledItemDelegate.__init__(self, parent)
|
||||||
self.table_widget = parent
|
self.table_widget = parent
|
||||||
self.document = QTextDocument()
|
self.document = QTextDocument()
|
||||||
|
self.is_editable_with_tab = False
|
||||||
|
|
||||||
def create_editor(self, parent, option, index):
|
def create_editor(self, parent, option, index):
|
||||||
m = index.model()
|
m = index.model()
|
||||||
@ -607,6 +611,7 @@ class CcMarkdownDelegate(StyledItemDelegate): # {{{
|
|||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.table_widget = parent
|
self.table_widget = parent
|
||||||
self.document = QTextDocument()
|
self.document = QTextDocument()
|
||||||
|
self.is_editable_with_tab = False
|
||||||
|
|
||||||
def paint(self, painter, option, index):
|
def paint(self, painter, option, index):
|
||||||
self.initStyleOption(option, index)
|
self.initStyleOption(option, index)
|
||||||
@ -760,6 +765,7 @@ class CcCommentsDelegate(StyledItemDelegate): # {{{
|
|||||||
StyledItemDelegate.__init__(self, parent)
|
StyledItemDelegate.__init__(self, parent)
|
||||||
self.table_widget = parent
|
self.table_widget = parent
|
||||||
self.document = QTextDocument()
|
self.document = QTextDocument()
|
||||||
|
self.is_editable_with_tab = False
|
||||||
|
|
||||||
def paint(self, painter, option, index):
|
def paint(self, painter, option, index):
|
||||||
self.initStyleOption(option, index)
|
self.initStyleOption(option, index)
|
||||||
@ -886,6 +892,7 @@ class CcTemplateDelegate(StyledItemDelegate): # {{{
|
|||||||
StyledItemDelegate.__init__(self, parent)
|
StyledItemDelegate.__init__(self, parent)
|
||||||
self.table_widget = parent
|
self.table_widget = parent
|
||||||
self.disallow_edit = gprefs['edit_metadata_templates_only_F2_on_booklist']
|
self.disallow_edit = gprefs['edit_metadata_templates_only_F2_on_booklist']
|
||||||
|
self.is_editable_with_tab = False
|
||||||
|
|
||||||
def create_editor(self, parent, option, index):
|
def create_editor(self, parent, option, index):
|
||||||
if self.disallow_edit:
|
if self.disallow_edit:
|
||||||
|
@ -1652,7 +1652,22 @@ class BooksView(QTableView): # {{{
|
|||||||
hint = QAbstractItemDelegate.EndEditHint.NoHint
|
hint = QAbstractItemDelegate.EndEditHint.NoHint
|
||||||
ans = super().closeEditor(editor, hint)
|
ans = super().closeEditor(editor, hint)
|
||||||
if move_by is not None and self.currentIndex() == orig and self.state() is not QAbstractItemView.State.EditingState:
|
if move_by is not None and self.currentIndex() == orig and self.state() is not QAbstractItemView.State.EditingState:
|
||||||
|
# Skip over columns that aren't editable or are implemented by a dialog
|
||||||
|
while True:
|
||||||
index = self.moveCursor(move_by, Qt.KeyboardModifier.NoModifier)
|
index = self.moveCursor(move_by, Qt.KeyboardModifier.NoModifier)
|
||||||
|
if not index.isValid():
|
||||||
|
break
|
||||||
|
self.setCurrentIndex(index)
|
||||||
|
m = self._model
|
||||||
|
col = m.column_map[index.column()]
|
||||||
|
if m.is_custom_column(col):
|
||||||
|
# Don't try to open editors implemented by dialogs such as
|
||||||
|
# markdown, composites and comments
|
||||||
|
if self.itemDelegateForIndex(index).is_editable_with_tab:
|
||||||
|
break
|
||||||
|
elif m.flags(index) & Qt.ItemFlag.ItemIsEditable:
|
||||||
|
# Standard editable column
|
||||||
|
break
|
||||||
if index.isValid():
|
if index.isValid():
|
||||||
def edit():
|
def edit():
|
||||||
if index.isValid():
|
if index.isValid():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user