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:
Kovid Goyal 2008-11-05 10:22:53 -08:00
parent c3afee03a8
commit 1c4a68e1d4
3 changed files with 26 additions and 11 deletions

View File

@ -198,12 +198,12 @@ class BooksModel(QAbstractTableModel):
return
ascending = order == Qt.AscendingOrder
self.db.sort(self.column_map[col], ascending)
self.research(reset=False)
if reset:
self.clear_caches()
self.reset()
self.sorted_on = (self.column_map[col], order)
def resort(self, reset=True):
try:
col = self.column_map.index(self.sorted_on[0])
@ -222,7 +222,7 @@ class BooksModel(QAbstractTableModel):
def rowCount(self, parent):
if parent and parent.isValid():
return 0
return self.db.rows() if self.db else 0
return len(self.db.data) if self.db else 0
def count(self):
return self.rowCount(None)
@ -400,7 +400,7 @@ class BooksModel(QAbstractTableModel):
au = self.db.data[r][aidx]
if au:
au = [a.strip().replace('|', ',') for a in au.split(',')]
return '\n'.join(au)
return ' & '.join(au)
def timestamp(r):
dt = self.db.data[r][tmdx]
@ -428,10 +428,15 @@ class BooksModel(QAbstractTableModel):
if series:
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 = {
'title' : lambda r : self.db.data[r][tidx],
'authors' : authors,
'size' : lambda r : '%.1f'%(float(self.db.data[r][sidx])/(1024*1024)),
'size' : size,
'timestamp': timestamp,
'rating' : rating,
'publisher': publisher,
@ -521,10 +526,8 @@ class BooksView(TableView):
QObject.connect(self.selectionModel(), SIGNAL('currentRowChanged(QModelIndex, QModelIndex)'),
self._model.current_changed)
# 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('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)
#QObject.connect(self.model(), SIGNAL('rowsRemoved(QModelIndex, int, int)'), self.resizeRowsToContents)
#QObject.connect(self.model(), SIGNAL('rowsInserted(QModelIndex, int, int)'), self.resizeRowsToContents)
self.set_visible_columns()
def columns_sorted(self):

View File

@ -316,6 +316,9 @@
<property name="showGrid" >
<bool>false</bool>
</property>
<property name="wordWrap" >
<bool>false</bool>
</property>
</widget>
</item>
</layout>
@ -353,6 +356,9 @@
<property name="showGrid" >
<bool>false</bool>
</property>
<property name="wordWrap" >
<bool>false</bool>
</property>
</widget>
</item>
</layout>
@ -388,6 +394,9 @@
<property name="showGrid" >
<bool>false</bool>
</property>
<property name="wordWrap" >
<bool>false</bool>
</property>
</widget>
</item>
</layout>

View File

@ -288,8 +288,9 @@ class ResultCache(SearchQueryParser):
fcmp = self.seriescmp if field == 'series' else \
functools.partial(self.cmp, FIELD_MAP[field],
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):
if not query or not query.strip():
@ -363,7 +364,7 @@ class LibraryDatabase2(LibraryDatabase):
self.data = ResultCache()
self.search = self.data.search
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.refresh_ids = functools.partial(self.data.refresh_ids, self.conn)
self.row = self.data.row
@ -1008,6 +1009,7 @@ class LibraryDatabase2(LibraryDatabase):
if not hasattr(path, 'read'):
stream.close()
self.conn.commit()
self.data.refresh_ids(self.conn, ids) # Needed to update format list and size
if duplicates:
paths = tuple(duplicate[0] for duplicate in duplicates)
formats = tuple(duplicate[1] for duplicate in duplicates)
@ -1032,6 +1034,7 @@ class LibraryDatabase2(LibraryDatabase):
stream = open(path, 'rb')
self.add_format(id, ext, stream, index_is_id=True)
self.conn.commit()
self.data.refresh_ids(self.conn, [id]) # Needed to update format list and size
self.notify('add', [id])
def move_library_to(self, newloc, progress=None):