[vlc-commits] qt: allow getCount to initiate the cache in MLBaseModel

Pierre Lamot git at videolan.org
Mon Jan 4 12:40:40 UTC 2021


vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Thu Dec 17 13:32:50 2020 +0100| [b37154909d36e30598d1480bb972704c9543c073] | committer: Pierre Lamot

qt: allow getCount to initiate the cache in MLBaseModel

The count property might be accessed before browsing the model.

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

 modules/gui/qt/medialibrary/mlbasemodel.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/modules/gui/qt/medialibrary/mlbasemodel.cpp b/modules/gui/qt/medialibrary/mlbasemodel.cpp
index 4549dacb57..68eb28dac9 100644
--- a/modules/gui/qt/medialibrary/mlbasemodel.cpp
+++ b/modules/gui/qt/medialibrary/mlbasemodel.cpp
@@ -237,7 +237,7 @@ void MLBaseModel::unsetSortCriteria()
 
 int MLBaseModel::rowCount(const QModelIndex &parent) const
 {
-    if (parent.isValid())
+    if (!m_mediaLib || parent.isValid())
         return 0;
 
     validateCache();
@@ -302,7 +302,10 @@ QVariantList MLBaseModel::getIdsForIndexes(QVariantList indexes) const
 
 unsigned MLBaseModel::getCount() const
 {
-    if (!m_cache || m_cache->count() == COUNT_UNINITIALIZED)
+    if (!m_mediaLib)
+        return 0;
+    validateCache();
+    if (m_cache->count() == COUNT_UNINITIALIZED)
         return 0;
     return static_cast<unsigned>(m_cache->count());
 }



More information about the vlc-commits mailing list