mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
More speedups for NotesItemWidget
This commit is contained in:
parent
a292113f0b
commit
b9e24ffb07
@ -212,6 +212,8 @@ class EditAuthorsDialog(QDialog, Ui_EditAuthorsDialog):
|
|||||||
|
|
||||||
self.table.setRowCount(len(auts_to_show))
|
self.table.setRowCount(len(auts_to_show))
|
||||||
row = 0
|
row = 0
|
||||||
|
from calibre.gui2.ui import get_gui
|
||||||
|
all_items_that_have_notes = get_gui().current_db.new_api.get_all_items_that_have_notes('authors')
|
||||||
for id_, v in self.authors.items():
|
for id_, v in self.authors.items():
|
||||||
if id_ not in auts_to_show:
|
if id_ not in auts_to_show:
|
||||||
continue
|
continue
|
||||||
@ -227,7 +229,7 @@ class EditAuthorsDialog(QDialog, Ui_EditAuthorsDialog):
|
|||||||
self.table.setItem(row, 1, sort_item)
|
self.table.setItem(row, 1, sort_item)
|
||||||
self.table.setItem(row, 2, link_item)
|
self.table.setItem(row, 2, link_item)
|
||||||
|
|
||||||
nw = NotesItemWidget('authors', id_)
|
nw = NotesItemWidget('authors', id_, id_ in all_items_that_have_notes)
|
||||||
self.table.setCellWidget(row, 3, nw)
|
self.table.setCellWidget(row, 3, nw)
|
||||||
|
|
||||||
self.set_icon(name_item, id_)
|
self.set_icon(name_item, id_)
|
||||||
|
@ -205,7 +205,7 @@ class NotesItemWidget(QWidget):
|
|||||||
raise KeyError(f'The value: {self._item_val} is not found in the field: {self.field}')
|
raise KeyError(f'The value: {self._item_val} is not found in the field: {self.field}')
|
||||||
return self._item_id
|
return self._item_id
|
||||||
|
|
||||||
def __init__(self, field, item_id_or_val):
|
def __init__(self, field, item_id_or_val, has_notes):
|
||||||
'''
|
'''
|
||||||
:param db: A database instance, either old or new api
|
:param db: A database instance, either old or new api
|
||||||
:param field: the lookup name of a field
|
:param field: the lookup name of a field
|
||||||
@ -215,6 +215,7 @@ class NotesItemWidget(QWidget):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self.field = field
|
self.field = field
|
||||||
self._item_val = self._item_id = None
|
self._item_val = self._item_id = None
|
||||||
|
self.has_notes = has_notes
|
||||||
if isinstance(item_id_or_val, str):
|
if isinstance(item_id_or_val, str):
|
||||||
self._item_val = item_id_or_val
|
self._item_val = item_id_or_val
|
||||||
else:
|
else:
|
||||||
@ -245,7 +246,7 @@ class NotesItemWidget(QWidget):
|
|||||||
l.addStretch(3)
|
l.addStretch(3)
|
||||||
|
|
||||||
self.setFocusPolicy(Qt.FocusPolicy.StrongFocus)
|
self.setFocusPolicy(Qt.FocusPolicy.StrongFocus)
|
||||||
self.set_checked()
|
self.set_checked(refresh=False)
|
||||||
self.customContextMenuRequested.connect(self.show_context_menu)
|
self.customContextMenuRequested.connect(self.show_context_menu)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -311,11 +312,11 @@ class NotesItemWidget(QWidget):
|
|||||||
self.can_undo = False
|
self.can_undo = False
|
||||||
self.set_checked()
|
self.set_checked()
|
||||||
|
|
||||||
def set_checked(self):
|
def set_checked(self, refresh=True):
|
||||||
notes = self.db.notes_for(self.field, self.item_id)
|
if refresh:
|
||||||
t = bool(notes)
|
self.has_notes = bool(self.db.notes_for(self.field, self.item_id))
|
||||||
self.cb.setChecked(t)
|
self.cb.setChecked(self.has_notes)
|
||||||
self.buttons['delete'].setEnabled(t)
|
self.buttons['delete'].setEnabled(self.has_notes)
|
||||||
self.buttons['undo_delete'].setEnabled(self.can_undo)
|
self.buttons['undo_delete'].setEnabled(self.can_undo)
|
||||||
|
|
||||||
def is_checked(self):
|
def is_checked(self):
|
||||||
@ -643,6 +644,8 @@ class TagListEditor(QDialog, Ui_TagListEditor):
|
|||||||
self.table.setHorizontalHeaderItem(4, self.link_col)
|
self.table.setHorizontalHeaderItem(4, self.link_col)
|
||||||
|
|
||||||
self.table.setRowCount(len(tags))
|
self.table.setRowCount(len(tags))
|
||||||
|
from calibre.gui2.ui import get_gui
|
||||||
|
all_items_that_have_notes = get_gui().current_db.new_api.get_all_items_that_have_notes(self.category)
|
||||||
for row,tag in enumerate(tags):
|
for row,tag in enumerate(tags):
|
||||||
item = NameTableWidgetItem(self.sorter)
|
item = NameTableWidgetItem(self.sorter)
|
||||||
is_deleted = self.all_tags[tag]['is_deleted']
|
is_deleted = self.all_tags[tag]['is_deleted']
|
||||||
@ -694,7 +697,7 @@ class TagListEditor(QDialog, Ui_TagListEditor):
|
|||||||
self.table.setItem(row, self.LINK_COLUMN, item)
|
self.table.setItem(row, self.LINK_COLUMN, item)
|
||||||
|
|
||||||
if self.category is not None:
|
if self.category is not None:
|
||||||
nw = NotesItemWidget(self.category, _id)
|
nw = NotesItemWidget(self.category, _id, _id in all_items_that_have_notes)
|
||||||
self.table.setCellWidget(row, 4, nw)
|
self.table.setCellWidget(row, 4, nw)
|
||||||
|
|
||||||
# re-sort the table
|
# re-sort the table
|
||||||
|
Loading…
x
Reference in New Issue
Block a user