Fix some problems with the new marking code.

1) The listeners weren't called if only labels changed in the is_marked set.
2) refresh_ids returned no rows if any one of the ids was invalid.
3) I used the wrong method in views.py. I have ids but called the method that expected rows.
This commit is contained in:
Charles Haley 2022-05-22 18:24:13 +01:00
parent 69c406a1e4
commit f3372b2dcc
2 changed files with 20 additions and 14 deletions

View File

@ -386,7 +386,8 @@ class View:
changed_ids = old_marked_ids | cmids
self.cache.clear_search_caches(changed_ids)
self.cache.clear_caches(book_ids=changed_ids)
if old_marked_ids != cmids:
# Always call the listener because the labels might have changed even
# if the ids haven't.
for funcref in itervalues(self.marked_listeners):
func = funcref()
if func is not None:
@ -412,11 +413,16 @@ class View:
def refresh_ids(self, ids):
self.cache.clear_caches(book_ids=ids)
# The ids list can contain invalid ids (deleted etc). We want to filter
# those out while keeping the valid ones.
def f(id_):
try:
return list(map(self.id_to_index, ids))
return self.id_to_index(id_)
except ValueError:
pass
return None
res = [i for i in map(f, ids) if i is not None]
return res if res else None
def remove(self, book_id):
try:

View File

@ -965,15 +965,15 @@ class BooksView(QTableView): # {{{
# viewport correctly. See https://bugs.launchpad.net/bugs/1404697
self.row_header.viewport().update()
# refresh the rows because there might be a composite that uses marked_books()
self.model().refresh_rows(changed)
self.model().refresh_rows(sections)
else:
# Marked items have either appeared or all been removed
self.model().set_row_decoration(current_marked)
self.row_header.headerDataChanged(Qt.Orientation.Vertical, 0, self.row_header.count()-1)
self.row_header.geometriesChanged.emit()
self.set_row_header_visibility()
# refresh the rows because there might be a composite that uses marked_books()
self.model().refresh_rows(current_marked)
# refresh rows for the ids because there might be a composite that uses marked_books()
self.model().refresh_ids(current_marked)
def set_row_header_visibility(self):
visible = self.model().row_decoration is not None or gprefs['row_numbers_in_book_list']