mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Various rendering optimizations in the book list. Long text is no longer word wrapped. This should significantly speed up sort operation
This commit is contained in:
parent
c3afee03a8
commit
1c4a68e1d4
@ -198,12 +198,12 @@ class BooksModel(QAbstractTableModel):
|
|||||||
return
|
return
|
||||||
ascending = order == Qt.AscendingOrder
|
ascending = order == Qt.AscendingOrder
|
||||||
self.db.sort(self.column_map[col], ascending)
|
self.db.sort(self.column_map[col], ascending)
|
||||||
self.research(reset=False)
|
|
||||||
if reset:
|
if reset:
|
||||||
self.clear_caches()
|
self.clear_caches()
|
||||||
self.reset()
|
self.reset()
|
||||||
self.sorted_on = (self.column_map[col], order)
|
self.sorted_on = (self.column_map[col], order)
|
||||||
|
|
||||||
|
|
||||||
def resort(self, reset=True):
|
def resort(self, reset=True):
|
||||||
try:
|
try:
|
||||||
col = self.column_map.index(self.sorted_on[0])
|
col = self.column_map.index(self.sorted_on[0])
|
||||||
@ -222,7 +222,7 @@ class BooksModel(QAbstractTableModel):
|
|||||||
def rowCount(self, parent):
|
def rowCount(self, parent):
|
||||||
if parent and parent.isValid():
|
if parent and parent.isValid():
|
||||||
return 0
|
return 0
|
||||||
return self.db.rows() if self.db else 0
|
return len(self.db.data) if self.db else 0
|
||||||
|
|
||||||
def count(self):
|
def count(self):
|
||||||
return self.rowCount(None)
|
return self.rowCount(None)
|
||||||
@ -400,7 +400,7 @@ class BooksModel(QAbstractTableModel):
|
|||||||
au = self.db.data[r][aidx]
|
au = self.db.data[r][aidx]
|
||||||
if au:
|
if au:
|
||||||
au = [a.strip().replace('|', ',') for a in au.split(',')]
|
au = [a.strip().replace('|', ',') for a in au.split(',')]
|
||||||
return '\n'.join(au)
|
return ' & '.join(au)
|
||||||
|
|
||||||
def timestamp(r):
|
def timestamp(r):
|
||||||
dt = self.db.data[r][tmdx]
|
dt = self.db.data[r][tmdx]
|
||||||
@ -428,10 +428,15 @@ class BooksModel(QAbstractTableModel):
|
|||||||
if series:
|
if series:
|
||||||
return series + ' [%d]'%self.db.data[r][siix]
|
return series + ' [%d]'%self.db.data[r][siix]
|
||||||
|
|
||||||
|
def size(r):
|
||||||
|
size = self.db.data[r][sidx]
|
||||||
|
if size:
|
||||||
|
return '%.1f'%(float(size)/(1024*1024))
|
||||||
|
|
||||||
self.dc = {
|
self.dc = {
|
||||||
'title' : lambda r : self.db.data[r][tidx],
|
'title' : lambda r : self.db.data[r][tidx],
|
||||||
'authors' : authors,
|
'authors' : authors,
|
||||||
'size' : lambda r : '%.1f'%(float(self.db.data[r][sidx])/(1024*1024)),
|
'size' : size,
|
||||||
'timestamp': timestamp,
|
'timestamp': timestamp,
|
||||||
'rating' : rating,
|
'rating' : rating,
|
||||||
'publisher': publisher,
|
'publisher': publisher,
|
||||||
@ -521,10 +526,8 @@ class BooksView(TableView):
|
|||||||
QObject.connect(self.selectionModel(), SIGNAL('currentRowChanged(QModelIndex, QModelIndex)'),
|
QObject.connect(self.selectionModel(), SIGNAL('currentRowChanged(QModelIndex, QModelIndex)'),
|
||||||
self._model.current_changed)
|
self._model.current_changed)
|
||||||
# Adding and removing rows should resize rows to contents
|
# Adding and removing rows should resize rows to contents
|
||||||
QObject.connect(self.model(), SIGNAL('rowsRemoved(QModelIndex, int, int)'), self.resizeRowsToContents)
|
#QObject.connect(self.model(), SIGNAL('rowsRemoved(QModelIndex, int, int)'), self.resizeRowsToContents)
|
||||||
QObject.connect(self.model(), SIGNAL('rowsInserted(QModelIndex, int, int)'), self.resizeRowsToContents)
|
#QObject.connect(self.model(), SIGNAL('rowsInserted(QModelIndex, int, int)'), self.resizeRowsToContents)
|
||||||
# Resetting the model should resize rows (model is reset after search and sort operations)
|
|
||||||
QObject.connect(self.model(), SIGNAL('modelReset()'), self.resizeRowsToContents)
|
|
||||||
self.set_visible_columns()
|
self.set_visible_columns()
|
||||||
|
|
||||||
def columns_sorted(self):
|
def columns_sorted(self):
|
||||||
|
@ -316,6 +316,9 @@
|
|||||||
<property name="showGrid" >
|
<property name="showGrid" >
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="wordWrap" >
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
@ -353,6 +356,9 @@
|
|||||||
<property name="showGrid" >
|
<property name="showGrid" >
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="wordWrap" >
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
@ -388,6 +394,9 @@
|
|||||||
<property name="showGrid" >
|
<property name="showGrid" >
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="wordWrap" >
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
@ -288,8 +288,9 @@ class ResultCache(SearchQueryParser):
|
|||||||
fcmp = self.seriescmp if field == 'series' else \
|
fcmp = self.seriescmp if field == 'series' else \
|
||||||
functools.partial(self.cmp, FIELD_MAP[field],
|
functools.partial(self.cmp, FIELD_MAP[field],
|
||||||
str=field not in ('size', 'rating', 'timestamp'))
|
str=field not in ('size', 'rating', 'timestamp'))
|
||||||
self._map.sort(cmp=fcmp, reverse=not ascending)
|
|
||||||
|
|
||||||
|
self._map.sort(cmp=fcmp, reverse=not ascending)
|
||||||
|
self._map_filtered = [id for id in self._map if id in self._map_filtered]
|
||||||
|
|
||||||
def search(self, query):
|
def search(self, query):
|
||||||
if not query or not query.strip():
|
if not query or not query.strip():
|
||||||
@ -363,7 +364,7 @@ class LibraryDatabase2(LibraryDatabase):
|
|||||||
self.data = ResultCache()
|
self.data = ResultCache()
|
||||||
self.search = self.data.search
|
self.search = self.data.search
|
||||||
self.refresh = functools.partial(self.data.refresh, self)
|
self.refresh = functools.partial(self.data.refresh, self)
|
||||||
self.sort = functools.partial(self.data.refresh, self)
|
self.sort = self.data.sort
|
||||||
self.index = self.data.index
|
self.index = self.data.index
|
||||||
self.refresh_ids = functools.partial(self.data.refresh_ids, self.conn)
|
self.refresh_ids = functools.partial(self.data.refresh_ids, self.conn)
|
||||||
self.row = self.data.row
|
self.row = self.data.row
|
||||||
@ -1008,6 +1009,7 @@ class LibraryDatabase2(LibraryDatabase):
|
|||||||
if not hasattr(path, 'read'):
|
if not hasattr(path, 'read'):
|
||||||
stream.close()
|
stream.close()
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
self.data.refresh_ids(self.conn, ids) # Needed to update format list and size
|
||||||
if duplicates:
|
if duplicates:
|
||||||
paths = tuple(duplicate[0] for duplicate in duplicates)
|
paths = tuple(duplicate[0] for duplicate in duplicates)
|
||||||
formats = tuple(duplicate[1] for duplicate in duplicates)
|
formats = tuple(duplicate[1] for duplicate in duplicates)
|
||||||
@ -1032,6 +1034,7 @@ class LibraryDatabase2(LibraryDatabase):
|
|||||||
stream = open(path, 'rb')
|
stream = open(path, 'rb')
|
||||||
self.add_format(id, ext, stream, index_is_id=True)
|
self.add_format(id, ext, stream, index_is_id=True)
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
self.data.refresh_ids(self.conn, [id]) # Needed to update format list and size
|
||||||
self.notify('add', [id])
|
self.notify('add', [id])
|
||||||
|
|
||||||
def move_library_to(self, newloc, progress=None):
|
def move_library_to(self, newloc, progress=None):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user