Dont update temporary metadata while editing song with inline editor

This commit is contained in:
Jonas Kvinge 2020-01-28 19:41:46 +01:00
parent 2bf8187bff
commit 624a920aec
5 changed files with 25 additions and 4 deletions

View File

@ -1880,6 +1880,7 @@ void MainWindow::EditValue() {
}
ui_->playlist->view()->edit(current.sibling(current.row(), column));
}
void MainWindow::AddFile() {

View File

@ -139,7 +139,8 @@ Playlist::Playlist(PlaylistBackend *backend, TaskManager *task_manager, Collecti
cancel_restore_(false),
scrobbled_(false),
nowplaying_(false),
scrobble_point_(-1) {
scrobble_point_(-1),
editing_(-1) {
undo_stack_->setUndoLimit(kUndoStackSize);
@ -1504,7 +1505,9 @@ void Playlist::SetStreamMetadata(const QUrl &url, const Song &song, const bool m
current_item()->SetTemporaryMetadata(song);
if (minor) {
emit dataChanged(index(current_item_index_.row(), 0), index(current_item_index_.row(), ColumnCount - 1));
if (editing_ != current_item_index_.row()) {
emit dataChanged(index(current_item_index_.row(), 0), index(current_item_index_.row(), ColumnCount - 1));
}
// if the song is invalid, we won't play it - there's no point in informing anybody about the change
const Song metadata(current_item_metadata());
if (metadata.is_valid()) {

View File

@ -220,6 +220,7 @@ class Playlist : public QAbstractListModel {
bool nowplaying() const { return nowplaying_; }
void set_scrobbled(bool state) { scrobbled_ = state; }
void set_nowplaying(bool state) { nowplaying_ = state; }
void set_editing(const int row) { editing_ = row; }
qint64 scrobble_point_nanosec() const { return scrobble_point_; }
void UpdateScrobblePoint(const qint64 seek_point_nanosec = 0);
@ -395,6 +396,8 @@ class Playlist : public QAbstractListModel {
bool nowplaying_;
qint64 scrobble_point_;
int editing_;
};
#endif // PLAYLIST_H

View File

@ -674,6 +674,16 @@ QModelIndex PlaylistView::PrevEditableIndex(const QModelIndex &current) {
}
bool PlaylistView::edit(const QModelIndex &index, QAbstractItemView::EditTrigger trigger, QEvent *event) {
bool result = QAbstractItemView::edit(index, trigger, event);
if (result && trigger == QAbstractItemView::AllEditTriggers && !event) {
playlist_->set_editing(index.row());
}
return result;
}
void PlaylistView::closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint) {
if (hint == QAbstractItemDelegate::NoHint) {
@ -693,13 +703,15 @@ void PlaylistView::closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHi
else {
QTreeView::closeEditor(editor, QAbstractItemDelegate::NoHint);
setCurrentIndex(index);
edit(index);
QAbstractItemView::edit(index);
}
}
else {
QTreeView::closeEditor(editor, hint);
}
playlist_->set_editing(-1);
}
void PlaylistView::mouseMoveEvent(QMouseEvent *event) {

View File

@ -78,7 +78,7 @@ class PlaylistHeader;
// This proxy style uses QCommonStyle to paint the affected elements.
// This class is used by internet search view as well.
class PlaylistProxyStyle : public QProxyStyle {
public:
public:
PlaylistProxyStyle(QStyle *base);
void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const;
@ -121,6 +121,7 @@ class PlaylistView : public QTreeView {
void SaveSettings();
void SetColumnAlignment(int section, Qt::Alignment alignment);
void JumpToCurrentlyPlayingTrack();
void edit(const QModelIndex &index) { return QAbstractItemView::edit(index); }
signals:
void PlayItem(const QModelIndex &index);
@ -155,6 +156,7 @@ class PlaylistView : public QTreeView {
// QAbstractItemView
void rowsInserted(const QModelIndex &parent, int start, int end);
bool edit(const QModelIndex &index, QAbstractItemView::EditTrigger trigger, QEvent *event);
void closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint);
private slots: