[vlc-commits] qt: playlist: make PlaylistListModel selectable
Romain Vimont
git at videolan.org
Tue Jul 16 14:09:12 CEST 2019
vlc | branch: master | Romain Vimont <rom1v at videolabs.io> | Tue Jul 9 18:30:27 2019 +0200| [92936190888b62fd82132a49fcf53dc5a5f38a9e] | committer: Jean-Baptiste Kempf
qt: playlist: make PlaylistListModel selectable
Make it inherit SelectableListModel, and implement required functions.
The actual selection state is stored in the playlist items themselves.
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=92936190888b62fd82132a49fcf53dc5a5f38a9e
---
.../gui/qt/components/playlist/playlist_item.cpp | 10 +++++++++
.../gui/qt/components/playlist/playlist_item.hpp | 5 +++++
.../gui/qt/components/playlist/playlist_model.cpp | 24 ++++++++++++++++++++--
.../gui/qt/components/playlist/playlist_model.hpp | 11 ++++++++--
4 files changed, 46 insertions(+), 4 deletions(-)
diff --git a/modules/gui/qt/components/playlist/playlist_item.cpp b/modules/gui/qt/components/playlist/playlist_item.cpp
index 8281daa059..c9bb3d2995 100644
--- a/modules/gui/qt/components/playlist/playlist_item.cpp
+++ b/modules/gui/qt/components/playlist/playlist_item.cpp
@@ -30,6 +30,16 @@ PlaylistItem::PlaylistItem(vlc_playlist_item_t* item)
}
}
+bool PlaylistItem::isSelected() const
+{
+ return d->selected;
+}
+
+void PlaylistItem::setSelected(bool selected)
+{
+ d->selected = selected;
+}
+
QString PlaylistItem::getTitle() const
{
return d->title;
diff --git a/modules/gui/qt/components/playlist/playlist_item.hpp b/modules/gui/qt/components/playlist/playlist_item.hpp
index 88ab12ffa0..88cca497fd 100644
--- a/modules/gui/qt/components/playlist/playlist_item.hpp
+++ b/modules/gui/qt/components/playlist/playlist_item.hpp
@@ -63,6 +63,9 @@ public:
return d ? d->item.get() : nullptr;
}
+ bool isSelected() const;
+ void setSelected(bool selected);
+
QString getTitle() const;
QString getArtist() const;
@@ -80,6 +83,8 @@ private:
struct Data : public QSharedData {
PlaylistItemPtr item;
+ bool selected = false;
+
/* cached values */
QString title;
QString artist;
diff --git a/modules/gui/qt/components/playlist/playlist_model.cpp b/modules/gui/qt/components/playlist/playlist_model.cpp
index 12edef2296..983319abd9 100644
--- a/modules/gui/qt/components/playlist/playlist_model.cpp
+++ b/modules/gui/qt/components/playlist/playlist_model.cpp
@@ -233,13 +233,13 @@ PlaylistListModelPrivate::notifyItemsChanged(int idx, int count, const QVector<i
// public API
PlaylistListModel::PlaylistListModel(QObject *parent)
- : QAbstractListModel(parent)
+ : SelectableListModel(parent)
, d_ptr(new PlaylistListModelPrivate(this))
{
}
PlaylistListModel::PlaylistListModel(vlc_playlist_t *raw_playlist, QObject *parent)
- : QAbstractListModel(parent)
+ : SelectableListModel(parent)
, d_ptr(new PlaylistListModelPrivate(this))
{
setPlaylistId(PlaylistPtr(raw_playlist));
@@ -249,6 +249,23 @@ PlaylistListModel::~PlaylistListModel()
{
}
+bool PlaylistListModel::isRowSelected(int row) const
+{
+ Q_D(const PlaylistListModel);
+ return d->m_items[row].isSelected();
+}
+
+void PlaylistListModel::setRowSelected(int row, bool selected)
+{
+ Q_D(PlaylistListModel);
+ return d->m_items[row].setSelected(selected);
+}
+
+int PlaylistListModel::getSelectedRole() const
+{
+ return SelectedRole;
+}
+
QHash<int, QByteArray>
PlaylistListModel::roleNames() const
{
@@ -259,6 +276,7 @@ PlaylistListModel::roleNames() const
{ ArtistRole , "artist" },
{ AlbumRole , "album" },
{ ArtworkRole, "artwork" },
+ { SelectedRole, "selected" },
};
}
@@ -440,6 +458,8 @@ PlaylistListModel::data(const QModelIndex &index, int role) const
return d->m_items[row].getAlbum();
case ArtworkRole:
return d->m_items[row].getArtwork();
+ case SelectedRole:
+ return d->m_items[row].isSelected();
default:
return {};
}
diff --git a/modules/gui/qt/components/playlist/playlist_model.hpp b/modules/gui/qt/components/playlist/playlist_model.hpp
index a1215496ac..ff6f0a46f6 100644
--- a/modules/gui/qt/components/playlist/playlist_model.hpp
+++ b/modules/gui/qt/components/playlist/playlist_model.hpp
@@ -27,12 +27,13 @@
#include <QVector>
#include "playlist_common.hpp"
#include "playlist_item.hpp"
+#include "../selectable_list_model.hpp"
namespace vlc {
namespace playlist {
class PlaylistListModelPrivate;
-class PlaylistListModel : public QAbstractListModel
+class PlaylistListModel : public SelectableListModel
{
Q_OBJECT
Q_PROPERTY(PlaylistPtr playlistId READ getPlaylistId WRITE setPlaylistId NOTIFY playlistIdChanged)
@@ -46,7 +47,8 @@ public:
IsCurrentRole,
ArtistRole,
AlbumRole,
- ArtworkRole
+ ArtworkRole,
+ SelectedRole,
};
PlaylistListModel(QObject *parent = nullptr);
@@ -67,6 +69,11 @@ public:
int getCurrentIndex() const;
+protected:
+ bool isRowSelected(int row) const override;
+ void setRowSelected(int row, bool selected) override;
+ int getSelectedRole() const override;
+
public slots:
PlaylistPtr getPlaylistId() const;
void setPlaylistId(PlaylistPtr id);
More information about the vlc-commits
mailing list