mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-04-25 03:13:21 +02:00
Add tags column to library view
This commit is contained in:
parent
f5c1140042
commit
e049ba9aa2
2 changed files with 15 additions and 7 deletions
|
|
@ -108,7 +108,8 @@ def roman(cls, num):
|
|||
def __init__(self, parent):
|
||||
QAbstractTableModel.__init__(self, parent)
|
||||
self.db = None
|
||||
self.cols = ['title', 'authors', 'size', 'date', 'rating', 'publisher', 'series']
|
||||
self.cols = ['title', 'authors', 'size', 'date', 'rating', 'publisher', 'tags', 'series']
|
||||
self.editable_cols = [0, 1, 4, 5, 6]
|
||||
self.sorted_on = (3, Qt.AscendingOrder)
|
||||
self.last_search = '' # The last search performed on this model
|
||||
self.read_config()
|
||||
|
|
@ -315,6 +316,10 @@ def data(self, index, role):
|
|||
if pub:
|
||||
return QVariant(BooksView.wrap(pub, 20))
|
||||
elif col == 6:
|
||||
tags = self.db.tags(row)
|
||||
if tags:
|
||||
return QVariant(', '.join(tags.split(',')))
|
||||
elif col == 7:
|
||||
series = self.db.series(row)
|
||||
if series:
|
||||
return QVariant(series)
|
||||
|
|
@ -322,7 +327,7 @@ def data(self, index, role):
|
|||
elif role == Qt.TextAlignmentRole and index.column() in [2, 3, 4]:
|
||||
return QVariant(Qt.AlignRight | Qt.AlignVCenter)
|
||||
elif role == Qt.ToolTipRole and index.isValid():
|
||||
if index.column() in [0, 1, 4, 5]:
|
||||
if index.column() in self.editable_cols:
|
||||
return QVariant("Double click to <b>edit</b> me<br><br>")
|
||||
return NONE
|
||||
|
||||
|
|
@ -337,7 +342,8 @@ def headerData(self, section, orientation, role):
|
|||
elif section == 3: text = _("Date")
|
||||
elif section == 4: text = _("Rating")
|
||||
elif section == 5: text = _("Publisher")
|
||||
elif section == 6: text = _("Series")
|
||||
elif section == 6: text = _("Tags")
|
||||
elif section == 7: text = _("Series")
|
||||
return QVariant(text)
|
||||
else:
|
||||
return QVariant(section+1)
|
||||
|
|
@ -345,7 +351,7 @@ def headerData(self, section, orientation, role):
|
|||
def flags(self, index):
|
||||
flags = QAbstractTableModel.flags(self, index)
|
||||
if index.isValid():
|
||||
if index.column() not in [2, 3]:
|
||||
if index.column() in self.editable_cols:
|
||||
flags |= Qt.ItemIsEditable
|
||||
return flags
|
||||
|
||||
|
|
@ -353,7 +359,7 @@ def setData(self, index, value, role):
|
|||
done = False
|
||||
if role == Qt.EditRole:
|
||||
row, col = index.row(), index.column()
|
||||
if col in [2,3]:
|
||||
if col not in self.editable_cols:
|
||||
return False
|
||||
val = unicode(value.toString().toUtf8(), 'utf-8').strip() if col != 4 else \
|
||||
int(value.toInt()[0])
|
||||
|
|
|
|||
|
|
@ -793,6 +793,7 @@ def refresh(self, sort_field, ascending):
|
|||
'size': 'size',
|
||||
'date': 'timestamp',
|
||||
'rating': 'rating',
|
||||
'tags':'tags',
|
||||
'series': 'series',
|
||||
}
|
||||
field = FIELDS[sort_field]
|
||||
|
|
@ -990,8 +991,7 @@ def set(self, row, column, val):
|
|||
Convenience method for setting the title, authors, publisher or rating
|
||||
'''
|
||||
id = self.data[row][0]
|
||||
cols = {'title' : 1, 'authors': 2, 'publisher': 3, 'rating':4}
|
||||
col = cols[column]
|
||||
col = {'title':1, 'authors':2, 'publisher':3, 'rating':4, 'tags':7}[column]
|
||||
|
||||
self.data[row][col] = val
|
||||
for item in self.cache:
|
||||
|
|
@ -1007,6 +1007,8 @@ def set(self, row, column, val):
|
|||
self.set_publisher(id, val)
|
||||
elif column == 'rating':
|
||||
self.set_rating(id, val)
|
||||
elif column == 'tags':
|
||||
self.set_tags(id, val.split(','), append=False)
|
||||
|
||||
def set_conversion_options(self, id, format, options):
|
||||
data = sqlite.Binary(cPickle.dumps(options))
|
||||
|
|
|
|||
Loading…
Reference in a new issue