[vlc-devel] [RFC 4/8] qt: playlist: expose count as a property

Romain Vimont rom1v at videolabs.io
Tue Jul 9 18:30:28 CEST 2019


This will allow to bind the number of items to a Qml variable.
---
 modules/gui/qt/components/playlist/playlist_model.cpp | 6 ++++++
 modules/gui/qt/components/playlist/playlist_model.hpp | 2 ++
 2 files changed, 8 insertions(+)

diff --git a/modules/gui/qt/components/playlist/playlist_model.cpp b/modules/gui/qt/components/playlist/playlist_model.cpp
index 983319abd9..49b8aaad22 100644
--- a/modules/gui/qt/components/playlist/playlist_model.cpp
+++ b/modules/gui/qt/components/playlist/playlist_model.cpp
@@ -178,6 +178,8 @@ void PlaylistListModelPrivate::onItemsReset(const QVector<PlaylistItem>& newCont
     q->beginResetModel();
     m_items = newContent;
     q->endResetModel();
+
+    emit q->countChanged(m_items.size());
 }
 
 void PlaylistListModelPrivate::onItemsAdded(const QVector<PlaylistItem>& added, size_t index)
@@ -188,6 +190,8 @@ void PlaylistListModelPrivate::onItemsAdded(const QVector<PlaylistItem>& added,
     m_items.insert(index, count, nullptr);
     std::move(added.cbegin(), added.cend(), m_items.begin() + index);
     q->endInsertRows();
+
+    emit q->countChanged(m_items.size());
 }
 
 void PlaylistListModelPrivate::onItemsMoved(size_t index, size_t count, size_t target)
@@ -218,6 +222,8 @@ void PlaylistListModelPrivate::onItemsRemoved(size_t index, size_t count)
     q->beginRemoveRows({}, index, index + count - 1);
     m_items.remove(index, count);
     q->endRemoveRows();
+
+    emit q->countChanged(m_items.size());
 }
 
 
diff --git a/modules/gui/qt/components/playlist/playlist_model.hpp b/modules/gui/qt/components/playlist/playlist_model.hpp
index ff6f0a46f6..cc932fed70 100644
--- a/modules/gui/qt/components/playlist/playlist_model.hpp
+++ b/modules/gui/qt/components/playlist/playlist_model.hpp
@@ -38,6 +38,7 @@ class PlaylistListModel : public SelectableListModel
     Q_OBJECT
     Q_PROPERTY(PlaylistPtr playlistId READ getPlaylistId WRITE setPlaylistId NOTIFY playlistIdChanged)
     Q_PROPERTY(int currentIndex READ getCurrentIndex NOTIFY currentIndexChanged)
+    Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
 
 public:
     enum Roles
@@ -82,6 +83,7 @@ public slots:
 signals:
     void playlistIdChanged(const PlaylistPtr& );
     void currentIndexChanged( int );
+    void countChanged(int);
 
 private:
     Q_DECLARE_PRIVATE(PlaylistListModel)
-- 
2.20.1



More information about the vlc-devel mailing list