Fix tag browser being reset when editing metadata. Also speed up editing metadata by not generating notifications for individual changes.

This commit is contained in:
Kovid Goyal 2010-04-04 16:53:49 +05:30
parent 5b61e4c95e
commit 0953c48b08
4 changed files with 14 additions and 12 deletions

View File

@ -122,10 +122,10 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
if aum:
aum = [a.strip().replace('|', ',') for a in aum.split(',')]
new_title = authors_to_string(aum)
self.db.set_title(id, new_title)
self.db.set_title(id, new_title, notify=False)
if title:
new_authors = string_to_authors(title)
self.db.set_authors(id, new_authors)
self.db.set_authors(id, new_authors, notify=False)
self.changed = True

View File

@ -657,11 +657,11 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
self.db.set_comment(self.id, qstring_to_unicode(self.comments.toPlainText()), notify=False)
d = self.pubdate.date()
d = qt_to_dt(d)
self.db.set_pubdate(self.id, d)
self.db.set_pubdate(self.id, d, notify=False)
d = self.date.date()
d = qt_to_dt(d)
if d.date() != self.orig_timestamp.date():
self.db.set_timestamp(self.id, d)
self.db.set_timestamp(self.id, d, notify=False)
if self.cover_changed:
if self.cover_data is not None:

View File

@ -9,7 +9,7 @@ Browsing book collection by tags.
from itertools import izip
from PyQt4.Qt import Qt, QTreeView, QApplication, \
from PyQt4.Qt import Qt, QTreeView, QApplication, pyqtSignal, \
QFont, SIGNAL, QSize, QIcon, QPoint, \
QAbstractItemModel, QVariant, QModelIndex
from calibre.gui2 import config, NONE
@ -18,6 +18,8 @@ from calibre.library.database2 import Tag
class TagsView(QTreeView):
need_refresh = pyqtSignal()
def __init__(self, *args):
QTreeView.__init__(self, *args)
self.setUniformRowHeights(True)
@ -33,7 +35,11 @@ class TagsView(QTreeView):
self.connect(self, SIGNAL('clicked(QModelIndex)'), self.toggle)
self.popularity.setChecked(config['sort_by_popularity'])
self.connect(self.popularity, SIGNAL('stateChanged(int)'), self.sort_changed)
self.connect(self, SIGNAL('need_refresh()'), self.recount, Qt.QueuedConnection)
self.need_refresh.connect(self.recount, type=Qt.QueuedConnection)
db.add_listener(self.database_changed)
def database_changed(self, event, ids):
self.need_refresh.emit()
@property
def match_all(self):
@ -164,9 +170,6 @@ class TagsModel(QAbstractItemModel):
for tag in data[r]:
TagTreeItem(parent=c, data=tag, icon_map=self.icon_map)
self.db.add_listener(self.database_changed)
self.connect(self, SIGNAL('need_refresh()'), self.refresh,
Qt.QueuedConnection)
def get_search_nodes(self):
l = []
@ -174,9 +177,6 @@ class TagsModel(QAbstractItemModel):
l.append(Tag(i, tooltip=saved_searches.lookup(i)))
return l
def database_changed(self, event, ids):
self.emit(SIGNAL('need_refresh()'))
def refresh(self):
data = self.db.get_categories(config['sort_by_popularity'])
data['search'] = self.get_search_nodes()

View File

@ -1556,6 +1556,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
if self.cover_flow:
self.cover_flow.dataChanged()
m.current_changed(current, previous)
self.tags_view.recount()
def edit_bulk_metadata(self, checked):
'''
@ -1572,6 +1573,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
self.library_view.model().db).changed:
self.library_view.model().resort(reset=False)
self.library_view.model().research()
self.tags_view.recount()
############################################################################