[vlc-commits] qt: expose model count in network models

Pierre Lamot git at videolan.org
Wed Jun 3 12:06:42 CEST 2020


vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Wed Feb 26 11:22:17 2020 +0100| [72f38b4594782ba80d7b3fd1a34f548d70931db8] | committer: Pierre Lamot

qt: expose model count in network models

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=72f38b4594782ba80d7b3fd1a34f548d70931db8
---

 modules/gui/qt/network/networkdevicemodel.cpp | 13 +++++++++++--
 modules/gui/qt/network/networkdevicemodel.hpp |  5 ++++-
 modules/gui/qt/network/networkmediamodel.cpp  |  8 ++++++++
 modules/gui/qt/network/networkmediamodel.hpp  |  4 +++-
 4 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/modules/gui/qt/network/networkdevicemodel.cpp b/modules/gui/qt/network/networkdevicemodel.cpp
index ecc18b8d79..0501d2b95b 100644
--- a/modules/gui/qt/network/networkdevicemodel.cpp
+++ b/modules/gui/qt/network/networkdevicemodel.cpp
@@ -89,8 +89,7 @@ int NetworkDeviceModel::rowCount(const QModelIndex& parent) const
 {
     if ( parent.isValid() )
         return 0;
-    assert( m_items.size() < INT32_MAX );
-    return static_cast<int>( m_items.size() );
+    return getCount();
 }
 
 
@@ -115,6 +114,12 @@ void NetworkDeviceModel::setSdSource(SDCatType s)
     emit sdSourceChanged();
 }
 
+int NetworkDeviceModel::getCount() const
+{
+    assert( m_items.size() < INT32_MAX );
+    return static_cast<int>( m_items.size() );
+}
+
 
 bool NetworkDeviceModel::addToPlaylist(int index)
 {
@@ -180,6 +185,7 @@ bool NetworkDeviceModel::initializeMediaSources()
         beginResetModel();
         m_items.clear();
         endResetModel();
+        emit countChanged();
     }
 
     auto provider = vlc_media_source_provider_Get( libvlc );
@@ -264,6 +270,7 @@ void NetworkDeviceModel::onItemRemoved(MediaSourcePtr mediaSource, input_item_no
             beginRemoveRows({}, idx, idx );
             m_items.erase( it );
             endRemoveRows();
+            emit countChanged();
         }
     }, Qt::QueuedConnection);
 }
@@ -278,6 +285,7 @@ void NetworkDeviceModel::refreshDeviceList( MediaSourcePtr mediaSource, input_it
                 return value.mediaSource == mediaSource;
             }), m_items.end());
             endResetModel();
+            emit countChanged();
         });
     }
 
@@ -321,6 +329,7 @@ void NetworkDeviceModel::refreshDeviceList( MediaSourcePtr mediaSource, input_it
             beginInsertRows( {}, pos, pos );
             m_items.insert( it, std::move( item ) );
             endInsertRows();
+            emit countChanged();
         }
     }, Qt::QueuedConnection);
 }
diff --git a/modules/gui/qt/network/networkdevicemodel.hpp b/modules/gui/qt/network/networkdevicemodel.hpp
index e53c6a96d6..8706f7ba0f 100644
--- a/modules/gui/qt/network/networkdevicemodel.hpp
+++ b/modules/gui/qt/network/networkdevicemodel.hpp
@@ -65,7 +65,7 @@ public:
 
     Q_PROPERTY(QmlMainContext* ctx READ getCtx WRITE setCtx NOTIFY ctxChanged)
     Q_PROPERTY(SDCatType sd_source READ getSdSource WRITE setSdSource NOTIFY sdSourceChanged)
-
+    Q_PROPERTY(int count READ getCount NOTIFY countChanged)
 
 public:
     NetworkDeviceModel( QObject* parent = nullptr );
@@ -80,6 +80,8 @@ public:
     inline QmlMainContext* getCtx() { return m_ctx; }
     inline SDCatType getSdSource() { return m_sdSource; }
 
+    int getCount() const;
+
     Q_INVOKABLE bool addToPlaylist( int index );
     Q_INVOKABLE bool addToPlaylist(const QVariantList& itemIdList);
     Q_INVOKABLE bool addAndPlay( int index );
@@ -88,6 +90,7 @@ public:
 signals:
     void ctxChanged();
     void sdSourceChanged();
+    void countChanged();
 
 private:
     using MediaSourcePtr = vlc_shared_data_ptr_type(vlc_media_source_t,
diff --git a/modules/gui/qt/network/networkmediamodel.cpp b/modules/gui/qt/network/networkmediamodel.cpp
index 1bfa2cfefc..fd0a9f76ce 100644
--- a/modules/gui/qt/network/networkmediamodel.cpp
+++ b/modules/gui/qt/network/networkmediamodel.cpp
@@ -110,6 +110,11 @@ int NetworkMediaModel::rowCount(const QModelIndex& parent) const
 {
     if ( parent.isValid() )
         return 0;
+    return getCount();
+}
+
+int NetworkMediaModel::getCount() const
+{
     assert( m_items.size() < INT32_MAX );
     return static_cast<int>( m_items.size() );
 }
@@ -256,6 +261,7 @@ bool NetworkMediaModel::initializeMediaSources()
         beginResetModel();
         m_items.clear();
         endResetModel();
+        emit countChanged();
     }
 
     if (!m_treeItem)
@@ -370,6 +376,7 @@ void NetworkMediaModel::onItemRemoved(MediaSourcePtr, input_item_node_t * node,
             beginRemoveRows({}, idx, idx );
             m_items.erase( it );
             endRemoveRows();
+            emit countChanged();
         }
     }, Qt::QueuedConnection);
 }
@@ -434,6 +441,7 @@ void NetworkMediaModel::refreshMediaList( MediaSourcePtr mediaSource,
         endResetModel();
     else
         endInsertRows();
+    emit countChanged();
 }
 
 bool NetworkMediaModel::canBeIndexed(const QUrl& url , ItemType itemType )
diff --git a/modules/gui/qt/network/networkmediamodel.hpp b/modules/gui/qt/network/networkmediamodel.hpp
index 08c5c64512..13bece16cb 100644
--- a/modules/gui/qt/network/networkmediamodel.hpp
+++ b/modules/gui/qt/network/networkmediamodel.hpp
@@ -96,7 +96,7 @@ public:
     Q_PROPERTY(bool indexed READ isIndexed WRITE setIndexed NOTIFY isIndexedChanged)
     Q_PROPERTY(bool canBeIndexed READ canBeIndexed NOTIFY canBeIndexedChanged)
     Q_PROPERTY(bool parsingPending READ getParsingPending NOTIFY parsingPendingChanged)
-
+    Q_PROPERTY(int count READ getCount NOTIFY countChanged)
 
     explicit NetworkMediaModel(QObject* parent = nullptr);
     NetworkMediaModel( QmlMainContext* ctx, QString parentMrl, QObject* parent = nullptr );
@@ -122,6 +122,7 @@ public:
     inline bool isIndexed() const { return m_indexed; }
     inline bool canBeIndexed() const { return m_canBeIndexed; }
     inline bool getParsingPending() const { return m_parsingPending; }
+    int getCount() const;
 
     Q_INVOKABLE bool addToPlaylist( int index );
     Q_INVOKABLE bool addToPlaylist(const QVariantList& itemIdList);
@@ -135,6 +136,7 @@ signals:
     void isIndexedChanged();
     void canBeIndexedChanged();
     void parsingPendingChanged(bool);
+    void countChanged();
 
     void ctxChanged();
     void treeChanged();



More information about the vlc-commits mailing list