Only allow playlist editing if song is editable

Set proper flags in model instead of overriding edit in view.

Proper fix for #524
This commit is contained in:
Jonas Kvinge 2020-08-30 22:23:38 +02:00
parent 495c6bc21c
commit 22afcbcbb6
2 changed files with 8 additions and 12 deletions

View File

@ -645,13 +645,14 @@ void Playlist::set_current_row(const int i, const AutoScroll autoscroll, const b
Qt::ItemFlags Playlist::flags(const QModelIndex &idx) const {
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
if (column_is_editable(static_cast<Column>(idx.column()))) flags |= Qt::ItemIsEditable;
if (idx.isValid()) return flags | Qt::ItemIsDragEnabled;
return Qt::ItemIsDropEnabled;
if (idx.isValid()) {
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
if (item_at(idx.row())->Metadata().IsEditable() && column_is_editable(static_cast<Column>(idx.column()))) flags |= Qt::ItemIsEditable;
return flags;
}
else {
return Qt::ItemIsDropEnabled;
}
}

View File

@ -704,11 +704,6 @@ QModelIndex PlaylistView::PrevEditableIndex(const QModelIndex &current) {
bool PlaylistView::edit(const QModelIndex &idx, QAbstractItemView::EditTrigger trigger, QEvent *event) {
// Only allow playlist editing if song is editable.
if (trigger == QAbstractItemView::AllEditTriggers && !event && playlist_ && !playlist_->item_at(idx.row())->Metadata().IsEditable()) {
return false;
}
bool result = QAbstractItemView::edit(idx, trigger, event);
if (result && trigger == QAbstractItemView::AllEditTriggers && !event) {
playlist_->set_editing(idx.row());