Add custom columns to user defined categories.

Fix bug #5425 (saved searches enhancements)
This commit is contained in:
Charles Haley 2010-05-02 01:15:37 +01:00
parent 50aeaaaeff
commit 3ff7e6ecfe
5 changed files with 30 additions and 12 deletions

View File

@ -22,7 +22,7 @@ class Item:
return 'name=%s, label=%s, index=%s, exists='%(self.name, self.label, self.index, self.exists) return 'name=%s, label=%s, index=%s, exists='%(self.name, self.label, self.index, self.exists)
class TagCategories(QDialog, Ui_TagCategories): class TagCategories(QDialog, Ui_TagCategories):
category_labels = ['', 'author', 'series', 'publisher', 'tag'] category_labels_orig = ['', 'author', 'series', 'publisher', 'tag']
def __init__(self, window, db, index=None): def __init__(self, window, db, index=None):
QDialog.__init__(self, window) QDialog.__init__(self, window)
@ -33,6 +33,9 @@ class TagCategories(QDialog, Ui_TagCategories):
self.index = index self.index = index
self.applied_items = [] self.applied_items = []
cc_icon = QIcon(I('column.svg'))
self.category_labels = self.category_labels_orig[:]
category_icons = [None, QIcon(I('user_profile.svg')), QIcon(I('series.svg')), category_icons = [None, QIcon(I('user_profile.svg')), QIcon(I('series.svg')),
QIcon(I('publisher.png')), QIcon(I('tags.svg'))] QIcon(I('publisher.png')), QIcon(I('tags.svg'))]
category_values = [None, category_values = [None,
@ -43,6 +46,14 @@ class TagCategories(QDialog, Ui_TagCategories):
] ]
category_names = ['', _('Authors'), _('Series'), _('Publishers'), _('Tags')] category_names = ['', _('Authors'), _('Series'), _('Publishers'), _('Tags')]
cc_map = self.db.custom_column_label_map
for cc in cc_map:
if cc_map[cc]['datatype'] == 'text':
self.category_labels.append(cc)
category_icons.append(cc_icon)
category_values.append(lambda col=cc: self.db.all_custom(label=col))
category_names.append(cc_map[cc]['name'])
self.all_items = [] self.all_items = []
self.all_items_dict = {} self.all_items_dict = {}
for idx,label in enumerate(self.category_labels): for idx,label in enumerate(self.category_labels):

View File

@ -724,7 +724,7 @@ class BooksModel(QAbstractTableModel):
'timestamp': functools.partial(datetime_type, idx=self.db.FIELD_MAP['timestamp']), 'timestamp': functools.partial(datetime_type, idx=self.db.FIELD_MAP['timestamp']),
'pubdate' : functools.partial(datetime_type, idx=self.db.FIELD_MAP['pubdate']), 'pubdate' : functools.partial(datetime_type, idx=self.db.FIELD_MAP['pubdate']),
'rating' : functools.partial(rating_type, idx=self.db.FIELD_MAP['rating']), 'rating' : functools.partial(rating_type, idx=self.db.FIELD_MAP['rating']),
'publisher': functools.partial(text_type, idx=self.db.FIELD_MAP['title'], mult=False), 'publisher': functools.partial(text_type, idx=self.db.FIELD_MAP['publisher'], mult=False),
'tags' : functools.partial(tags, idx=self.db.FIELD_MAP['tags']), 'tags' : functools.partial(tags, idx=self.db.FIELD_MAP['tags']),
'series' : functools.partial(series, idx=self.db.FIELD_MAP['series'], siix=self.db.FIELD_MAP['series_index']), 'series' : functools.partial(series, idx=self.db.FIELD_MAP['series'], siix=self.db.FIELD_MAP['series_index']),
} }

View File

@ -279,9 +279,10 @@ class SavedSearchBox(QComboBox):
idx = self.currentIndex idx = self.currentIndex
if idx < 0: if idx < 0:
return return
ss = self.saved_searches.lookup(unicode(self.currentText()))
self.saved_searches.delete(unicode(self.currentText())) self.saved_searches.delete(unicode(self.currentText()))
self.clear_to_help() self.clear_to_help()
self.search_box.set_search_string('') self.search_box.set_search_string(ss)
self.emit(SIGNAL('changed()')) self.emit(SIGNAL('changed()'))
# SIGNALed from the main UI # SIGNALed from the main UI

View File

@ -184,7 +184,7 @@ class TagTreeItem(object):
return QVariant('[%d] %s'%(self.tag.count, self.tag.name)) return QVariant('[%d] %s'%(self.tag.count, self.tag.name))
if role == Qt.DecorationRole: if role == Qt.DecorationRole:
return self.icon_state_map[self.tag.state] return self.icon_state_map[self.tag.state]
if role == Qt.ToolTipRole and self.tag.tooltip: if role == Qt.ToolTipRole and self.tag.tooltip is not None:
return QVariant(self.tag.tooltip) return QVariant(self.tag.tooltip)
return NONE return NONE
@ -248,11 +248,17 @@ class TagsModel(QAbstractItemModel):
self.categories.append(self.db.custom_column_label_map[c]['name']) self.categories.append(self.db.custom_column_label_map[c]['name'])
self.cat_icon_map.append(self.custcol_icon) self.cat_icon_map.append(self.custcol_icon)
# Now the rest of the normal tag categories
for i in range(self.tags_categories_start, len(self.row_map_orig)):
self.row_map.append(self.row_map_orig[i])
self.categories.append(self.categories_orig[i])
self.cat_icon_map.append(self.cat_icon_map_orig[i])
# Now do the user-defined categories. There is a time/space tradeoff here. # Now do the user-defined categories. There is a time/space tradeoff here.
# By converting the tags into a map, we can do the verification in the category # By converting the tags into a map, we can do the verification in the category
# loop much faster, at the cost of duplicating the categories lists. # loop much faster, at the cost of duplicating the categories lists.
taglist = {} taglist = {}
for c in self.row_map_orig: for c in self.row_map:
taglist[c] = dict(map(lambda t:(t.name if c != 'author' else t.name.replace('|', ','), t), data[c])) taglist[c] = dict(map(lambda t:(t.name if c != 'author' else t.name.replace('|', ','), t), data[c]))
for c in self.user_categories: for c in self.user_categories:
@ -269,11 +275,6 @@ class TagsModel(QAbstractItemModel):
self.categories.append(c) self.categories.append(c)
self.cat_icon_map.append(self.usercat_icon) self.cat_icon_map.append(self.usercat_icon)
# Now the rest of the normal tag categories
for i in range(self.tags_categories_start, len(self.row_map_orig)):
self.row_map.append(self.row_map_orig[i])
self.categories.append(self.categories_orig[i])
self.cat_icon_map.append(self.cat_icon_map_orig[i])
data['search'] = self.get_search_nodes(self.search_icon) # Add the search category data['search'] = self.get_search_nodes(self.search_icon) # Add the search category
self.row_map.append(self.search_keys[0]) self.row_map.append(self.search_keys[0])
self.categories.append(self.search_keys[1]) self.categories.append(self.search_keys[1])

View File

@ -648,9 +648,14 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
query += ' ORDER BY {0} ASC'.format(cn[1]) query += ' ORDER BY {0} ASC'.format(cn[1])
data = self.conn.get(query) data = self.conn.get(query)
category = cn[0] category = cn[0]
icon = icon_map[category] if category in icon_map else icon_map['*custom'] if category in icon_map:
icon = icon_map[category]
tooltip = ''
else:
icon = icon_map['*custom']
tooltip = self.custom_column_label_map[category]['name']
if ids is None: # no filtering if ids is None: # no filtering
categories[category] = [Tag(r[1], count=r[2], id=r[0], icon=icon) categories[category] = [Tag(r[1], count=r[2], id=r[0], icon=icon, tooltip = tooltip)
for r in data] for r in data]
else: # filter out zero-count tags else: # filter out zero-count tags
categories[category] = [Tag(r[1], count=r[2], id=r[0], icon=icon) categories[category] = [Tag(r[1], count=r[2], id=r[0], icon=icon)