mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Quick View: Survives changing libraries. Also allow sorting by series index as well as name.
This commit is contained in:
commit
23b1ceaa9a
@ -38,3 +38,6 @@ class ShowQuickviewAction(InterfaceAction):
|
||||
Quickview(self.gui, self.gui.library_view, index)
|
||||
self.current_instance.show()
|
||||
|
||||
def library_changed(self, db):
|
||||
if self.current_instance and not self.current_instance.is_closed:
|
||||
self.current_instance.set_database(db)
|
||||
|
@ -18,16 +18,29 @@ class TableItem(QTableWidgetItem):
|
||||
A QTableWidgetItem that sorts on a separate string and uses ICU rules
|
||||
'''
|
||||
|
||||
def __init__(self, val, sort):
|
||||
def __init__(self, val, sort, idx=0):
|
||||
self.sort = sort
|
||||
self.sort_idx = idx
|
||||
QTableWidgetItem.__init__(self, val)
|
||||
self.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
|
||||
|
||||
def __ge__(self, other):
|
||||
return sort_key(self.sort) >= sort_key(other.sort)
|
||||
l = sort_key(self.sort)
|
||||
r = sort_key(other.sort)
|
||||
if l > r:
|
||||
return 1
|
||||
if l == r:
|
||||
return self.sort_idx >= other.sort_idx
|
||||
return 0
|
||||
|
||||
def __lt__(self, other):
|
||||
return sort_key(self.sort) < sort_key(other.sort)
|
||||
l = sort_key(self.sort)
|
||||
r = sort_key(other.sort)
|
||||
if l < r:
|
||||
return 1
|
||||
if l == r:
|
||||
return self.sort_idx < other.sort_idx
|
||||
return 0
|
||||
|
||||
class Quickview(QDialog, Ui_Quickview):
|
||||
|
||||
@ -95,6 +108,15 @@ class Quickview(QDialog, Ui_Quickview):
|
||||
self.search_button.clicked.connect(self.do_search)
|
||||
view.model().new_bookdisplay_data.connect(self.book_was_changed)
|
||||
|
||||
def set_database(self, db):
|
||||
self.db = db
|
||||
self.items.blockSignals(True)
|
||||
self.books_table.blockSignals(True)
|
||||
self.items.clear()
|
||||
self.books_table.setRowCount(0)
|
||||
self.books_table.blockSignals(False)
|
||||
self.items.blockSignals(False)
|
||||
|
||||
# search button
|
||||
def do_search(self):
|
||||
if self.last_search is not None:
|
||||
@ -185,7 +207,7 @@ class Quickview(QDialog, Ui_Quickview):
|
||||
series = mi.format_field('series')[1]
|
||||
if series is None:
|
||||
series = ''
|
||||
a = TableItem(series, series)
|
||||
a = TableItem(series, mi.series, mi.series_index)
|
||||
a.setToolTip(tt)
|
||||
self.books_table.setItem(row, 2, a)
|
||||
self.books_table.setRowHeight(row, self.books_table_row_height)
|
||||
|
@ -57,19 +57,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<spacer>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<layout class="QHBoxLayout">
|
||||
<item>
|
||||
|
@ -514,7 +514,7 @@ class TagsModel(QAbstractItemModel): # {{{
|
||||
# }}}
|
||||
|
||||
for category in self.category_nodes:
|
||||
process_one_node(category, state_map.get(category.py_name, {}))
|
||||
process_one_node(category, state_map.get(category.category_key, {}))
|
||||
|
||||
# Drag'n Drop {{{
|
||||
def mimeTypes(self):
|
||||
@ -851,7 +851,7 @@ class TagsModel(QAbstractItemModel): # {{{
|
||||
|
||||
def index_for_category(self, name):
|
||||
for row, category in enumerate(self.category_nodes):
|
||||
if category.py_name == name:
|
||||
if category.category_key == name:
|
||||
return self.index(row, 0, QModelIndex())
|
||||
|
||||
def columnCount(self, parent):
|
||||
|
@ -129,10 +129,10 @@ class TagsView(QTreeView): # {{{
|
||||
expanded_categories = []
|
||||
for row, category in enumerate(self._model.category_nodes):
|
||||
if self.isExpanded(self._model.index(row, 0, QModelIndex())):
|
||||
expanded_categories.append(category.py_name)
|
||||
expanded_categories.append(category.category_key)
|
||||
states = [c.tag.state for c in category.child_tags()]
|
||||
names = [(c.tag.name, c.tag.category) for c in category.child_tags()]
|
||||
state_map[category.py_name] = dict(izip(names, states))
|
||||
state_map[category.category_key] = dict(izip(names, states))
|
||||
return expanded_categories, state_map
|
||||
|
||||
def reread_collapse_parameters(self):
|
||||
|
@ -1442,7 +1442,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
||||
raise ValueError('sort ' + sort + ' not a valid value')
|
||||
|
||||
self.books_list_filter.change([] if not ids else ids)
|
||||
id_filter = None if not ids else frozenset(ids)
|
||||
id_filter = None if ids is None else frozenset(ids)
|
||||
|
||||
tb_cats = self.field_metadata
|
||||
tcategories = {}
|
||||
@ -1520,7 +1520,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
||||
rating_dex = self.FIELD_MAP['rating']
|
||||
tag_class = LibraryDatabase2.TCat_Tag
|
||||
for book in self.data.iterall():
|
||||
if id_filter and book[id_dex] not in id_filter:
|
||||
if id_filter is not None and book[id_dex] not in id_filter:
|
||||
continue
|
||||
rating = book[rating_dex]
|
||||
# We kept track of all possible category field_map positions above
|
||||
|
Loading…
x
Reference in New Issue
Block a user