From 624a920aec2443a6a740b56b9c42c4f82b8c60bb Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Tue, 28 Jan 2020 19:41:46 +0100 Subject: [PATCH] Dont update temporary metadata while editing song with inline editor --- src/core/mainwindow.cpp | 1 + src/playlist/playlist.cpp | 7 +++++-- src/playlist/playlist.h | 3 +++ src/playlist/playlistview.cpp | 14 +++++++++++++- src/playlist/playlistview.h | 4 +++- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/core/mainwindow.cpp b/src/core/mainwindow.cpp index d55a1f9c2..396eda181 100644 --- a/src/core/mainwindow.cpp +++ b/src/core/mainwindow.cpp @@ -1880,6 +1880,7 @@ void MainWindow::EditValue() { } ui_->playlist->view()->edit(current.sibling(current.row(), column)); + } void MainWindow::AddFile() { diff --git a/src/playlist/playlist.cpp b/src/playlist/playlist.cpp index c4de7bef7..32320d878 100644 --- a/src/playlist/playlist.cpp +++ b/src/playlist/playlist.cpp @@ -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()) { diff --git a/src/playlist/playlist.h b/src/playlist/playlist.h index f7f2e58c2..1e4279280 100644 --- a/src/playlist/playlist.h +++ b/src/playlist/playlist.h @@ -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 diff --git a/src/playlist/playlistview.cpp b/src/playlist/playlistview.cpp index 218e78f28..d942b7c9f 100644 --- a/src/playlist/playlistview.cpp +++ b/src/playlist/playlistview.cpp @@ -674,6 +674,16 @@ QModelIndex PlaylistView::PrevEditableIndex(const QModelIndex ¤t) { } +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) { diff --git a/src/playlist/playlistview.h b/src/playlist/playlistview.h index 1e08e013d..72cd3d8f0 100644 --- a/src/playlist/playlistview.h +++ b/src/playlist/playlistview.h @@ -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: