mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Avoid qudratic lookup when serializing tag browser state
This commit is contained in:
parent
cc410ac6da
commit
ce05d2cc3b
@ -1046,6 +1046,9 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
id(internal_pointer))
|
id(internal_pointer))
|
||||||
return idx
|
return idx
|
||||||
|
|
||||||
|
def category_row_map(self):
|
||||||
|
return {category.category_key:row for row, category in enumerate(self.root_item.children)}
|
||||||
|
|
||||||
def index_for_category(self, name):
|
def index_for_category(self, name):
|
||||||
for row, category in enumerate(self.root_item.children):
|
for row, category in enumerate(self.root_item.children):
|
||||||
if category.category_key == name:
|
if category.category_key == name:
|
||||||
|
@ -13,7 +13,7 @@ from itertools import izip
|
|||||||
|
|
||||||
from PyQt5.Qt import (
|
from PyQt5.Qt import (
|
||||||
QStyledItemDelegate, Qt, QTreeView, pyqtSignal, QSize, QIcon, QApplication,
|
QStyledItemDelegate, Qt, QTreeView, pyqtSignal, QSize, QIcon, QApplication,
|
||||||
QMenu, QPoint, QToolTip, QCursor, QDrag, QRect,
|
QMenu, QPoint, QToolTip, QCursor, QDrag, QRect, QModelIndex,
|
||||||
QLinearGradient, QPalette, QColor, QPen, QBrush, QFont
|
QLinearGradient, QPalette, QColor, QPen, QBrush, QFont
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -213,15 +213,16 @@ class TagsView(QTreeView): # {{{
|
|||||||
def get_state(self):
|
def get_state(self):
|
||||||
state_map = {}
|
state_map = {}
|
||||||
expanded_categories = []
|
expanded_categories = []
|
||||||
row = -1
|
|
||||||
hide_empty_categories = self.model().prefs['tag_browser_hide_empty_categories']
|
hide_empty_categories = self.model().prefs['tag_browser_hide_empty_categories']
|
||||||
|
crmap = self._model.category_row_map()
|
||||||
for category in self._model.category_nodes:
|
for category in self._model.category_nodes:
|
||||||
if (category.category_key in self.hidden_categories or
|
if (category.category_key in self.hidden_categories or
|
||||||
(hide_empty_categories and len(category.child_tags()) == 0)):
|
(hide_empty_categories and len(category.child_tags()) == 0)):
|
||||||
continue
|
continue
|
||||||
row += 1
|
row = crmap.get(category.category_key)
|
||||||
index = self._model.index_for_category(category.category_key)
|
if row is not None:
|
||||||
if index is not None and self.isExpanded(index):
|
index = self._model.index(row, 0, QModelIndex())
|
||||||
|
if self.isExpanded(index):
|
||||||
expanded_categories.append(category.category_key)
|
expanded_categories.append(category.category_key)
|
||||||
states = [c.tag.state for c in category.child_tags()]
|
states = [c.tag.state for c in category.child_tags()]
|
||||||
names = [(c.tag.name, c.tag.category) for c in category.child_tags()]
|
names = [(c.tag.name, c.tag.category) for c in category.child_tags()]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user