mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix Tag Browser recount method
This commit is contained in:
parent
83ec03f19b
commit
5b61e4c95e
@ -12,7 +12,7 @@ from itertools import izip
|
|||||||
from PyQt4.Qt import Qt, QTreeView, QApplication, \
|
from PyQt4.Qt import Qt, QTreeView, QApplication, \
|
||||||
QFont, SIGNAL, QSize, QIcon, QPoint, \
|
QFont, SIGNAL, QSize, QIcon, QPoint, \
|
||||||
QAbstractItemModel, QVariant, QModelIndex
|
QAbstractItemModel, QVariant, QModelIndex
|
||||||
from calibre.gui2 import config, NONE, is_gui_thread, Dispatcher
|
from calibre.gui2 import config, NONE
|
||||||
from calibre.utils.search_query_parser import saved_searches
|
from calibre.utils.search_query_parser import saved_searches
|
||||||
from calibre.library.database2 import Tag
|
from calibre.library.database2 import Tag
|
||||||
|
|
||||||
@ -54,18 +54,19 @@ class TagsView(QTreeView):
|
|||||||
self.model().clear_state()
|
self.model().clear_state()
|
||||||
|
|
||||||
def recount(self, *args):
|
def recount(self, *args):
|
||||||
if not is_gui_thread():
|
|
||||||
# Re-call in GUI thread
|
|
||||||
return Dispatcher(self.recount)(*args)
|
|
||||||
ci = self.currentIndex()
|
ci = self.currentIndex()
|
||||||
if not ci.isValid():
|
if not ci.isValid():
|
||||||
ci = self.indexAt(QPoint(10, 10))
|
ci = self.indexAt(QPoint(10, 10))
|
||||||
|
path = self.model().path_for_index(ci)
|
||||||
try:
|
try:
|
||||||
self.model().refresh()
|
self.model().refresh()
|
||||||
except: #Database connection could be closed if an integrity check is happening
|
except: #Database connection could be closed if an integrity check is happening
|
||||||
pass
|
pass
|
||||||
if ci.isValid():
|
if path:
|
||||||
self.scrollTo(ci, QTreeView.PositionAtTop)
|
idx = self.model().index_for_path(path)
|
||||||
|
if idx.isValid():
|
||||||
|
self.setCurrentIndex(idx)
|
||||||
|
self.scrollTo(idx, QTreeView.PositionAtCenter)
|
||||||
|
|
||||||
class TagTreeItem(object):
|
class TagTreeItem(object):
|
||||||
|
|
||||||
@ -139,6 +140,7 @@ class TagTreeItem(object):
|
|||||||
if self.type == self.TAG:
|
if self.type == self.TAG:
|
||||||
self.tag.state = (self.tag.state + 1)%3
|
self.tag.state = (self.tag.state + 1)%3
|
||||||
|
|
||||||
|
|
||||||
class TagsModel(QAbstractItemModel):
|
class TagsModel(QAbstractItemModel):
|
||||||
categories = [_('Authors'), _('Series'), _('Formats'), _('Publishers'), _('News'), _('Tags'), _('Searches')]
|
categories = [_('Authors'), _('Series'), _('Formats'), _('Publishers'), _('News'), _('Tags'), _('Searches')]
|
||||||
row_map = ['author', 'series', 'format', 'publisher', 'news', 'tag', 'search']
|
row_map = ['author', 'series', 'format', 'publisher', 'news', 'tag', 'search']
|
||||||
@ -213,6 +215,21 @@ class TagsModel(QAbstractItemModel):
|
|||||||
def flags(self, *args):
|
def flags(self, *args):
|
||||||
return Qt.ItemIsEnabled|Qt.ItemIsSelectable
|
return Qt.ItemIsEnabled|Qt.ItemIsSelectable
|
||||||
|
|
||||||
|
def path_for_index(self, index):
|
||||||
|
ans = []
|
||||||
|
while index.isValid():
|
||||||
|
ans.append(index.row())
|
||||||
|
index = self.parent(index)
|
||||||
|
ans.reverse()
|
||||||
|
return ans
|
||||||
|
|
||||||
|
def index_for_path(self, path):
|
||||||
|
parent = QModelIndex()
|
||||||
|
for i in path:
|
||||||
|
parent = self.index(i, 0, parent)
|
||||||
|
if not parent.isValid():
|
||||||
|
return QModelIndex()
|
||||||
|
return parent
|
||||||
|
|
||||||
def index(self, row, column, parent):
|
def index(self, row, column, parent):
|
||||||
if not self.hasIndex(row, column, parent):
|
if not self.hasIndex(row, column, parent):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user