mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add tags column to library view
This commit is contained in:
parent
f5c1140042
commit
e049ba9aa2
@ -108,7 +108,8 @@ class BooksModel(QAbstractTableModel):
|
||||
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 @@ class BooksModel(QAbstractTableModel):
|
||||
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 @@ class BooksModel(QAbstractTableModel):
|
||||
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 @@ class BooksModel(QAbstractTableModel):
|
||||
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 @@ class BooksModel(QAbstractTableModel):
|
||||
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 @@ class BooksModel(QAbstractTableModel):
|
||||
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 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
||||
'size': 'size',
|
||||
'date': 'timestamp',
|
||||
'rating': 'rating',
|
||||
'tags':'tags',
|
||||
'series': 'series',
|
||||
}
|
||||
field = FIELDS[sort_field]
|
||||
@ -990,8 +991,7 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
||||
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 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
||||
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…
x
Reference in New Issue
Block a user