[vlc-devel] [PATCH 4/8] qt: medialib: un-templatize MLSlidingWindowModel

Romain Vimont rom1v at videolabs.io
Thu Dec 3 12:12:08 CET 2020


MLSlidingWindowModel was generic over its item type, and with many
non-template subclasses, each subclasses defining the actual concrete
type.

Therefore, this static genericity was "internal". In practice, it didn't
bring a lot a value, but it caused every subclass to recompile
the whole implementation.

To improve compilation times, remove the template parameter and always
use the item super-type MLItem. When an item of the concrete type is
necessary (once per subclass), just cast locally.

This change alone does not improve complitation times significantly,
because the implementation is still in the header file, which also
includes the whole ListCache implementation. The following commits will
solve these problems.
---
 modules/gui/qt/medialibrary/mlalbummodel.cpp  | 10 +++---
 modules/gui/qt/medialibrary/mlalbummodel.hpp  |  6 ++--
 .../gui/qt/medialibrary/mlalbumtrackmodel.cpp | 10 +++---
 .../gui/qt/medialibrary/mlalbumtrackmodel.hpp |  6 ++--
 modules/gui/qt/medialibrary/mlartistmodel.cpp |  8 ++---
 modules/gui/qt/medialibrary/mlartistmodel.hpp |  6 ++--
 modules/gui/qt/medialibrary/mlbasemodel.hpp   | 33 +++++++++----------
 modules/gui/qt/medialibrary/mlgenremodel.cpp  | 10 +++---
 modules/gui/qt/medialibrary/mlgenremodel.hpp  |  6 ++--
 .../gui/qt/medialibrary/mlrecentsmodel.cpp    | 10 +++---
 .../gui/qt/medialibrary/mlrecentsmodel.hpp    |  6 ++--
 .../qt/medialibrary/mlrecentsvideomodel.cpp   | 10 +++---
 .../qt/medialibrary/mlrecentsvideomodel.hpp   |  6 ++--
 modules/gui/qt/medialibrary/mlurlmodel.cpp    | 10 +++---
 modules/gui/qt/medialibrary/mlurlmodel.hpp    |  6 ++--
 modules/gui/qt/medialibrary/mlvideomodel.cpp  | 10 +++---
 modules/gui/qt/medialibrary/mlvideomodel.hpp  |  6 ++--
 17 files changed, 79 insertions(+), 80 deletions(-)

diff --git a/modules/gui/qt/medialibrary/mlalbummodel.cpp b/modules/gui/qt/medialibrary/mlalbummodel.cpp
index 23bb3e74d4..4b78a8196d 100644
--- a/modules/gui/qt/medialibrary/mlalbummodel.cpp
+++ b/modules/gui/qt/medialibrary/mlalbummodel.cpp
@@ -29,7 +29,7 @@ QHash<QByteArray, vlc_ml_sorting_criteria_t> MLAlbumModel::M_names_to_criteria =
 };
 
 MLAlbumModel::MLAlbumModel(QObject *parent)
-    : MLSlidingWindowModel<MLAlbum>(parent)
+    : MLSlidingWindowModel(parent)
 {
 }
 
@@ -38,7 +38,7 @@ QVariant MLAlbumModel::data(const QModelIndex &index, int role) const
     if (!index.isValid() || index.row() < 0)
         return QVariant();
 
-    const MLAlbum* ml_item = item(index.row());
+    const MLAlbum* ml_item = static_cast<MLAlbum *>(item(index.row()));
     if ( ml_item == NULL )
         return QVariant();
 
@@ -146,7 +146,7 @@ vlc_ml_sorting_criteria_t MLAlbumModel::roleToCriteria(int role) const
     }
 }
 
-ListCacheLoader<std::unique_ptr<MLAlbum>> *
+ListCacheLoader<std::unique_ptr<MLItem>> *
 MLAlbumModel::createLoader() const
 {
     return new Loader(*this);
@@ -162,7 +162,7 @@ size_t MLAlbumModel::Loader::count() const
     return vlc_ml_count_albums_of(m_ml, &queryParams, m_parent.type, m_parent.id);
 }
 
-std::vector<std::unique_ptr<MLAlbum>>
+std::vector<std::unique_ptr<MLItem>>
 MLAlbumModel::Loader::load(size_t index, size_t count) const
 {
     MLQueryParams params = getParams(index, count);
@@ -175,7 +175,7 @@ MLAlbumModel::Loader::load(size_t index, size_t count) const
         album_list.reset( vlc_ml_list_albums_of(m_ml, &queryParams, m_parent.type, m_parent.id ) );
     if ( album_list == nullptr )
         return {};
-    std::vector<std::unique_ptr<MLAlbum>> res;
+    std::vector<std::unique_ptr<MLItem>> res;
     for( const vlc_ml_album_t& album: ml_range_iterate<vlc_ml_album_t>( album_list ) )
         res.emplace_back( std::make_unique<MLAlbum>( m_ml, &album ) );
     return res;
diff --git a/modules/gui/qt/medialibrary/mlalbummodel.hpp b/modules/gui/qt/medialibrary/mlalbummodel.hpp
index 9f57d77b78..da5dd9071e 100644
--- a/modules/gui/qt/medialibrary/mlalbummodel.hpp
+++ b/modules/gui/qt/medialibrary/mlalbummodel.hpp
@@ -28,7 +28,7 @@
 #include "mlalbum.hpp"
 #include "medialib.hpp"
 
-class MLAlbumModel : public MLSlidingWindowModel<MLAlbum>
+class MLAlbumModel : public MLSlidingWindowModel
 {
     Q_OBJECT
 
@@ -58,7 +58,7 @@ public:
     Q_INVOKABLE QHash<int, QByteArray> roleNames() const override;
 
 protected:
-    ListCacheLoader<std::unique_ptr<MLAlbum>> *createLoader() const override;
+    ListCacheLoader<std::unique_ptr<MLItem>> *createLoader() const override;
 
 private:
     vlc_ml_sorting_criteria_t roleToCriteria(int role) const override;
@@ -73,7 +73,7 @@ private:
     {
         Loader(const MLAlbumModel &model) : BaseLoader(model) {}
         size_t count() const override;
-        std::vector<std::unique_ptr<MLAlbum>> load(size_t index, size_t count) const override;
+        std::vector<std::unique_ptr<MLItem>> load(size_t index, size_t count) const override;
     };
 };
 
diff --git a/modules/gui/qt/medialibrary/mlalbumtrackmodel.cpp b/modules/gui/qt/medialibrary/mlalbumtrackmodel.cpp
index fab64930f8..7ef6b3a87e 100644
--- a/modules/gui/qt/medialibrary/mlalbumtrackmodel.cpp
+++ b/modules/gui/qt/medialibrary/mlalbumtrackmodel.cpp
@@ -30,7 +30,7 @@ QHash<QByteArray, vlc_ml_sorting_criteria_t> MLAlbumTrackModel::M_names_to_crite
 };
 
 MLAlbumTrackModel::MLAlbumTrackModel(QObject *parent)
-    : MLSlidingWindowModel<MLAlbumTrack>(parent)
+    : MLSlidingWindowModel(parent)
 {
 }
 
@@ -39,7 +39,7 @@ QVariant MLAlbumTrackModel::data(const QModelIndex &index, int role) const
     if (!index.isValid() || index.row() < 0)
         return QVariant();
 
-    const MLAlbumTrack* ml_track = item(index.row());
+    const MLAlbumTrack* ml_track = static_cast<MLAlbumTrack *>(item(index.row()));
     if ( !ml_track )
         return QVariant();
 
@@ -151,7 +151,7 @@ void MLAlbumTrackModel::onVlcMlEvent(const MLEvent &event)
     MLBaseModel::onVlcMlEvent( event );
 }
 
-ListCacheLoader<std::unique_ptr<MLAlbumTrack>> *
+ListCacheLoader<std::unique_ptr<MLItem>> *
 MLAlbumTrackModel::createLoader() const
 {
     return new Loader(*this);
@@ -167,7 +167,7 @@ size_t MLAlbumTrackModel::Loader::count() const
     return vlc_ml_count_media_of(m_ml, &queryParams, m_parent.type, m_parent.id );
 }
 
-std::vector<std::unique_ptr<MLAlbumTrack>>
+std::vector<std::unique_ptr<MLItem>>
 MLAlbumTrackModel::Loader::load(size_t index, size_t count) const
 {
     MLQueryParams params = getParams(index, count);
@@ -181,7 +181,7 @@ MLAlbumTrackModel::Loader::load(size_t index, size_t count) const
         media_list.reset( vlc_ml_list_media_of(m_ml, &queryParams, m_parent.type, m_parent.id ) );
     if ( media_list == nullptr )
         return {};
-    std::vector<std::unique_ptr<MLAlbumTrack>> res;
+    std::vector<std::unique_ptr<MLItem>> res;
     for( const vlc_ml_media_t& media: ml_range_iterate<vlc_ml_media_t>( media_list ) )
         res.emplace_back( std::make_unique<MLAlbumTrack>( m_ml, &media ) );
     return res;
diff --git a/modules/gui/qt/medialibrary/mlalbumtrackmodel.hpp b/modules/gui/qt/medialibrary/mlalbumtrackmodel.hpp
index e494b597cb..889a7e0502 100644
--- a/modules/gui/qt/medialibrary/mlalbumtrackmodel.hpp
+++ b/modules/gui/qt/medialibrary/mlalbumtrackmodel.hpp
@@ -28,7 +28,7 @@
 #include "mlalbumtrack.hpp"
 
 
-class MLAlbumTrackModel : public MLSlidingWindowModel<MLAlbumTrack>
+class MLAlbumTrackModel : public MLSlidingWindowModel
 {
     Q_OBJECT
 
@@ -58,7 +58,7 @@ public:
     QHash<int, QByteArray> roleNames() const override;
 
 protected:
-    ListCacheLoader<std::unique_ptr<MLAlbumTrack>> *createLoader() const override;
+    ListCacheLoader<std::unique_ptr<MLItem>> *createLoader() const override;
 
 private:
     vlc_ml_sorting_criteria_t roleToCriteria(int role) const override;
@@ -72,7 +72,7 @@ private:
     {
         Loader(const MLAlbumTrackModel &model) : BaseLoader(model) {}
         size_t count() const override;
-        std::vector<std::unique_ptr<MLAlbumTrack>> load(size_t index, size_t count) const override;
+        std::vector<std::unique_ptr<MLItem>> load(size_t index, size_t count) const override;
     };
 };
 #endif // MLTRACKMODEL_HPP
diff --git a/modules/gui/qt/medialibrary/mlartistmodel.cpp b/modules/gui/qt/medialibrary/mlartistmodel.cpp
index 7422709096..9438681b2d 100644
--- a/modules/gui/qt/medialibrary/mlartistmodel.cpp
+++ b/modules/gui/qt/medialibrary/mlartistmodel.cpp
@@ -32,7 +32,7 @@ QVariant MLArtistModel::data(const QModelIndex &index, int role) const
     if (!index.isValid() || index.row() < 0)
         return QVariant();
 
-    const MLArtist* ml_artist = item(index.row());
+    const MLArtist* ml_artist = static_cast<MLArtist *>(item(index.row()));
     if ( !ml_artist )
         return QVariant();
 
@@ -111,7 +111,7 @@ void MLArtistModel::thumbnailUpdated(int idx)
     emit dataChanged(index(idx), index(idx), {ARTIST_COVER});
 }
 
-ListCacheLoader<std::unique_ptr<MLArtist>> *
+ListCacheLoader<std::unique_ptr<MLItem>> *
 MLArtistModel::createLoader() const
 {
     return new Loader(*this);
@@ -127,7 +127,7 @@ size_t MLArtistModel::Loader::count() const
     return vlc_ml_count_artists_of(m_ml, &queryParams, m_parent.type, m_parent.id );
 }
 
-std::vector<std::unique_ptr<MLArtist>>
+std::vector<std::unique_ptr<MLItem>>
 MLArtistModel::Loader::load(size_t index, size_t count) const
 {
     MLQueryParams params = getParams(index, count);
@@ -140,7 +140,7 @@ MLArtistModel::Loader::load(size_t index, size_t count) const
         artist_list.reset( vlc_ml_list_artist_of(m_ml, &queryParams, m_parent.type, m_parent.id) );
     if ( artist_list == nullptr )
         return {};
-    std::vector<std::unique_ptr<MLArtist>> res;
+    std::vector<std::unique_ptr<MLItem>> res;
     for( const vlc_ml_artist_t& artist: ml_range_iterate<vlc_ml_artist_t>( artist_list ) )
         res.emplace_back( std::make_unique<MLArtist>( &artist ) );
     return res;
diff --git a/modules/gui/qt/medialibrary/mlartistmodel.hpp b/modules/gui/qt/medialibrary/mlartistmodel.hpp
index 8926731b87..a0153c1483 100644
--- a/modules/gui/qt/medialibrary/mlartistmodel.hpp
+++ b/modules/gui/qt/medialibrary/mlartistmodel.hpp
@@ -27,7 +27,7 @@
 #include "mlbasemodel.hpp"
 #include "mlartist.hpp"
 
-class MLArtistModel : public MLSlidingWindowModel<MLArtist>
+class MLArtistModel : public MLSlidingWindowModel
 {
     Q_OBJECT
 public:
@@ -49,7 +49,7 @@ public:
     QHash<int, QByteArray> roleNames() const override;
 
 protected:
-    ListCacheLoader<std::unique_ptr<MLArtist>> *createLoader() const override;
+    ListCacheLoader<std::unique_ptr<MLItem>> *createLoader() const override;
 
 private:
     vlc_ml_sorting_criteria_t roleToCriteria(int role) const override;
@@ -64,7 +64,7 @@ private:
     {
         Loader(const MLArtistModel &model) : BaseLoader(model) {}
         size_t count() const override;
-        std::vector<std::unique_ptr<MLArtist>> load(size_t index, size_t count) const override;
+        std::vector<std::unique_ptr<MLItem>> load(size_t index, size_t count) const override;
     };
 };
 
diff --git a/modules/gui/qt/medialibrary/mlbasemodel.hpp b/modules/gui/qt/medialibrary/mlbasemodel.hpp
index 22c71a2500..16a719e812 100644
--- a/modules/gui/qt/medialibrary/mlbasemodel.hpp
+++ b/modules/gui/qt/medialibrary/mlbasemodel.hpp
@@ -131,12 +131,11 @@ protected:
  * to be known (so the scrollbar would grow as we scroll, until we displayed all
  * elements), and implies having all elements loaded in RAM at all time.
  */
-template <typename T>
 class MLSlidingWindowModel : public MLBaseModel
 {
 public:
     static constexpr ssize_t COUNT_UNINITIALIZED =
-        ListCache<std::unique_ptr<T>>::COUNT_UNINITIALIZED;
+        ListCache<std::unique_ptr<MLItem>>::COUNT_UNINITIALIZED;
 
     MLSlidingWindowModel(QObject* parent = nullptr)
         : MLBaseModel(parent)
@@ -162,7 +161,7 @@ public:
 
     virtual QVariant getIdForIndex( QVariant index ) const override
     {
-        T* obj = nullptr;
+        MLItem* obj = nullptr;
         if (index.canConvert<int>())
             obj = item( index.toInt() );
         else if ( index.canConvert<QModelIndex>() )
@@ -179,7 +178,7 @@ public:
         QVariantList idList;
         idList.reserve(indexes.length());
         std::transform( indexes.begin(), indexes.end(),std::back_inserter(idList), [this](const QModelIndex& index) -> QVariant {
-            T* obj = item( index.row() );
+            MLItem* obj = item( index.row() );
             if (!obj)
                 return {};
             return QVariant::fromValue(obj->getId());
@@ -193,7 +192,7 @@ public:
 
         idList.reserve(indexes.length());
         std::transform( indexes.begin(), indexes.end(),std::back_inserter(idList), [this](const QVariant& index) -> QVariant {
-            T* obj = nullptr;
+            MLItem* obj = nullptr;
             if (index.canConvert<int>())
                 obj = item( index.toInt() );
             else if ( index.canConvert<QModelIndex>() )
@@ -214,7 +213,7 @@ public:
     }
 
 protected:
-    virtual ListCacheLoader<std::unique_ptr<T>> *createLoader() const = 0;
+    virtual ListCacheLoader<std::unique_ptr<MLItem>> *createLoader() const = 0;
 
     void validateCache() const
     {
@@ -223,13 +222,13 @@ protected:
 
         auto &threadPool = m_mediaLib->threadPool();
         auto loader = createLoader();
-        m_cache.reset(new ListCache<std::unique_ptr<T>>(threadPool, loader));
+        m_cache.reset(new ListCache<std::unique_ptr<MLItem>>(threadPool, loader));
         connect(&*m_cache, &BaseListCache::localSizeAboutToBeChanged,
-                this, &MLSlidingWindowModel<T>::onLocalSizeAboutToBeChanged);
+                this, &MLSlidingWindowModel::onLocalSizeAboutToBeChanged);
         connect(&*m_cache, &BaseListCache::localSizeChanged,
-                this, &MLSlidingWindowModel<T>::onLocalSizeChanged);
+                this, &MLSlidingWindowModel::onLocalSizeChanged);
         connect(&*m_cache, &BaseListCache::localDataChanged,
-                this, &MLSlidingWindowModel<T>::onLocalDataChanged);
+                this, &MLSlidingWindowModel::onLocalDataChanged);
 
         m_cache->initCount();
     }
@@ -239,7 +238,7 @@ protected:
         m_cache.reset();
     }
 
-    T* item(int signedidx) const
+    MLItem* item(int signedidx) const
     {
         validateCache();
 
@@ -251,7 +250,7 @@ protected:
         unsigned int idx = static_cast<unsigned int>(signedidx);
         m_cache->refer(idx);
 
-        const std::unique_ptr<T> *item = m_cache->get(idx);
+        const std::unique_ptr<MLItem> *item = m_cache->get(idx);
         if (!item)
             /* Not in cache */
             return nullptr;
@@ -277,12 +276,12 @@ protected:
                     size_t total = static_cast<size_t>(stotal);
                     for (size_t i = 0; i < total; ++i)
                     {
-                        const std::unique_ptr<T> *item = m_cache->get(i);
+                        const std::unique_ptr<MLItem> *item = m_cache->get(i);
                         if (!item)
                             /* Only consider items available locally in cache */
                             break;
 
-                        T *localItem = item->get();
+                        MLItem *localItem = item->get();
                         if (localItem->getId().id == event.media_thumbnail_generated.i_media_id)
                         {
                             thumbnailUpdated(i);
@@ -299,7 +298,7 @@ protected:
     }
 
     /* Data loader for the cache */
-    struct BaseLoader : public ListCacheLoader<std::unique_ptr<T>>
+    struct BaseLoader : public ListCacheLoader<std::unique_ptr<MLItem>>
     {
         BaseLoader(vlc_medialibrary_t *ml, MLItemId parent, QString searchPattern,
                    vlc_ml_sorting_criteria_t sort, bool sort_desc)
@@ -311,7 +310,7 @@ protected:
         {
         }
 
-        BaseLoader(const MLSlidingWindowModel<T> &model)
+        BaseLoader(const MLSlidingWindowModel &model)
             : BaseLoader(model.m_ml, model.m_parent, model.m_search_pattern, model.m_sort, model.m_sort_desc)
         {
         }
@@ -332,7 +331,7 @@ protected:
 private:
     virtual void thumbnailUpdated( int ) {}
 
-    mutable std::unique_ptr<ListCache<std::unique_ptr<T>>> m_cache;
+    mutable std::unique_ptr<ListCache<std::unique_ptr<MLItem>>> m_cache;
 };
 
 #endif // MLBASEMODEL_HPP
diff --git a/modules/gui/qt/medialibrary/mlgenremodel.cpp b/modules/gui/qt/medialibrary/mlgenremodel.cpp
index b9c562a5f8..534b7fcf32 100644
--- a/modules/gui/qt/medialibrary/mlgenremodel.cpp
+++ b/modules/gui/qt/medialibrary/mlgenremodel.cpp
@@ -26,7 +26,7 @@ QHash<QByteArray, vlc_ml_sorting_criteria_t> MLGenreModel::M_names_to_criteria =
 };
 
 MLGenreModel::MLGenreModel(QObject *parent)
-    : MLSlidingWindowModel<MLGenre>(parent)
+    : MLSlidingWindowModel(parent)
 {
 }
 
@@ -35,7 +35,7 @@ QVariant MLGenreModel::data(const QModelIndex &index, int role) const
     if (!index.isValid() || index.row() < 0)
         return QVariant();
 
-    const MLGenre* ml_genre = item(index.row());
+    const MLGenre* ml_genre = static_cast<MLGenre *>(item(index.row()));
     if (!ml_genre)
         return QVariant();
 
@@ -102,7 +102,7 @@ vlc_ml_sorting_criteria_t MLGenreModel::nameToCriteria(QByteArray name) const
     return M_names_to_criteria.value(name, VLC_ML_SORTING_DEFAULT);
 }
 
-ListCacheLoader<std::unique_ptr<MLGenre>> *
+ListCacheLoader<std::unique_ptr<MLItem>> *
 MLGenreModel::createLoader() const
 {
     return new Loader(*this);
@@ -116,7 +116,7 @@ size_t MLGenreModel::Loader::count() const
     return vlc_ml_count_genres( m_ml, &queryParams );
 }
 
-std::vector<std::unique_ptr<MLGenre>>
+std::vector<std::unique_ptr<MLItem>>
 MLGenreModel::Loader::load(size_t index, size_t count) const
 {
     MLQueryParams params = getParams(index, count);
@@ -127,7 +127,7 @@ MLGenreModel::Loader::load(size_t index, size_t count) const
     );
     if ( genre_list == nullptr )
         return {};
-    std::vector<std::unique_ptr<MLGenre>> res;
+    std::vector<std::unique_ptr<MLItem>> res;
     for( const vlc_ml_genre_t& genre: ml_range_iterate<vlc_ml_genre_t>( genre_list ) )
         res.emplace_back( std::make_unique<MLGenre>( m_ml, &genre ) );
     return res;
diff --git a/modules/gui/qt/medialibrary/mlgenremodel.hpp b/modules/gui/qt/medialibrary/mlgenremodel.hpp
index 10e0ae8daa..b907ec1dc9 100644
--- a/modules/gui/qt/medialibrary/mlgenremodel.hpp
+++ b/modules/gui/qt/medialibrary/mlgenremodel.hpp
@@ -28,7 +28,7 @@
 #include "mlbasemodel.hpp"
 #include "mlgenre.hpp"
 
-class MLGenreModel : public MLSlidingWindowModel<MLGenre>
+class MLGenreModel : public MLSlidingWindowModel
 {
     Q_OBJECT
 
@@ -52,7 +52,7 @@ public:
     QVariant data(const QModelIndex &index, int role) const override;
 
 protected:
-    ListCacheLoader<std::unique_ptr<MLGenre>> *createLoader() const override;
+    ListCacheLoader<std::unique_ptr<MLItem>> *createLoader() const override;
 
 private:
     void onVlcMlEvent(const MLEvent &event) override;
@@ -67,7 +67,7 @@ private:
     {
         Loader(const MLGenreModel &model) : BaseLoader(model) {}
         size_t count() const override;
-        std::vector<std::unique_ptr<MLGenre>> load(size_t index, size_t count) const override;
+        std::vector<std::unique_ptr<MLItem>> load(size_t index, size_t count) const override;
     };
 };
 
diff --git a/modules/gui/qt/medialibrary/mlrecentsmodel.cpp b/modules/gui/qt/medialibrary/mlrecentsmodel.cpp
index 25029467b0..5b801ccb26 100644
--- a/modules/gui/qt/medialibrary/mlrecentsmodel.cpp
+++ b/modules/gui/qt/medialibrary/mlrecentsmodel.cpp
@@ -39,7 +39,7 @@ MLRecentMedia* MLRecentMedia::clone() const {
 
 
 MLRecentsModel::MLRecentsModel( QObject* parent )
-    : MLSlidingWindowModel<MLRecentMedia>( parent )
+    : MLSlidingWindowModel( parent )
 {
 }
 
@@ -48,7 +48,7 @@ QVariant MLRecentsModel::data( const QModelIndex& index , int role ) const
     if (!index.isValid() || index.row() < 0)
         return QVariant();
 
-    const MLRecentMedia* media = item(index.row());
+    const MLRecentMedia* media = static_cast<MLRecentMedia *>(item(index.row()));
     if ( !media )
         return QVariant();
 
@@ -101,7 +101,7 @@ int MLRecentsModel::getNumberOfItemsToShow() const {
     return m_numberOfItemsToShow;
 }
 
-ListCacheLoader<std::unique_ptr<MLRecentMedia>> *
+ListCacheLoader<std::unique_ptr<MLItem>> *
 MLRecentsModel::createLoader() const
 {
     return new Loader(*this, m_numberOfItemsToShow);
@@ -118,13 +118,13 @@ size_t MLRecentsModel::Loader::count() const
     return realCount;
 }
 
-std::vector<std::unique_ptr<MLRecentMedia>>
+std::vector<std::unique_ptr<MLItem>>
 MLRecentsModel::Loader::load(size_t index, size_t count) const
 {
     MLQueryParams params = getParams(index, count);
     auto queryParams = params.toCQueryParams();
 
-    std::vector<std::unique_ptr<MLRecentMedia>> res;
+    std::vector<std::unique_ptr<MLItem>> res;
     if (m_numberOfItemsToShow >= 0)
     {
         if (queryParams.i_offset <= static_cast<uint32_t>(m_numberOfItemsToShow))
diff --git a/modules/gui/qt/medialibrary/mlrecentsmodel.hpp b/modules/gui/qt/medialibrary/mlrecentsmodel.hpp
index 2c586f6b60..98b716d25b 100644
--- a/modules/gui/qt/medialibrary/mlrecentsmodel.hpp
+++ b/modules/gui/qt/medialibrary/mlrecentsmodel.hpp
@@ -48,7 +48,7 @@ private:
     QDateTime m_lastPlayedDate;
 };
 
-class MLRecentsModel : public MLSlidingWindowModel<MLRecentMedia>
+class MLRecentsModel : public MLSlidingWindowModel
 {
     Q_OBJECT
     Q_PROPERTY(int numberOfItemsToShow READ getNumberOfItemsToShow WRITE setNumberOfItemsToShow)
@@ -74,7 +74,7 @@ public:
     int getNumberOfItemsToShow() const;
 
 protected:
-    ListCacheLoader<std::unique_ptr<MLRecentMedia>> *createLoader() const override;
+    ListCacheLoader<std::unique_ptr<MLItem>> *createLoader() const override;
 
 private:
     vlc_ml_sorting_criteria_t roleToCriteria( int /* role */ ) const override{
@@ -94,7 +94,7 @@ private:
         }
 
         size_t count() const override;
-        std::vector<std::unique_ptr<MLRecentMedia>> load(size_t index, size_t count) const override;
+        std::vector<std::unique_ptr<MLItem>> load(size_t index, size_t count) const override;
 
     private:
         int m_numberOfItemsToShow;
diff --git a/modules/gui/qt/medialibrary/mlrecentsvideomodel.cpp b/modules/gui/qt/medialibrary/mlrecentsvideomodel.cpp
index 8324affa33..5b13c27f6c 100644
--- a/modules/gui/qt/medialibrary/mlrecentsvideomodel.cpp
+++ b/modules/gui/qt/medialibrary/mlrecentsvideomodel.cpp
@@ -37,13 +37,13 @@ enum Role {
 }
 
 MLRecentsVideoModel::MLRecentsVideoModel( QObject* parent )
-    : MLSlidingWindowModel<MLVideo>( parent )
+    : MLSlidingWindowModel( parent )
 {
 }
 
 QVariant MLRecentsVideoModel::data( const QModelIndex& index , int role ) const
 {
-    const auto video = item( index.row() );
+    const auto video = static_cast<MLVideo *>( item( index.row() ) );
     if ( video == nullptr )
         return {};
     switch ( role )
@@ -114,7 +114,7 @@ int MLRecentsVideoModel::getNumberOfItemsToShow(){
     return numberOfItemsToShow;
 }
 
-ListCacheLoader<std::unique_ptr<MLVideo>> *
+ListCacheLoader<std::unique_ptr<MLItem>> *
 MLRecentsVideoModel::createLoader() const
 {
     return new Loader(*this, numberOfItemsToShow);
@@ -136,7 +136,7 @@ size_t MLRecentsVideoModel::Loader::count() const
     return std::min(m_video_count, m_numberOfItemsToShow);
 }
 
-std::vector<std::unique_ptr<MLVideo>>
+std::vector<std::unique_ptr<MLItem>>
 MLRecentsVideoModel::Loader::load(size_t index, size_t count) const
 {
     MLQueryParams params = getParams(index, count);
@@ -146,7 +146,7 @@ MLRecentsVideoModel::Loader::load(size_t index, size_t count) const
                 m_ml, &queryParams ) };
     if ( media_list == nullptr )
         return {};
-    std::vector<std::unique_ptr<MLVideo>> res;
+    std::vector<std::unique_ptr<MLItem>> res;
     m_video_count = 0;
     for( vlc_ml_media_t &media: ml_range_iterate<vlc_ml_media_t>( media_list ) )
         if( media.i_type == VLC_ML_MEDIA_TYPE_VIDEO )
diff --git a/modules/gui/qt/medialibrary/mlrecentsvideomodel.hpp b/modules/gui/qt/medialibrary/mlrecentsvideomodel.hpp
index 64525ec0aa..86bb1d4874 100644
--- a/modules/gui/qt/medialibrary/mlrecentsvideomodel.hpp
+++ b/modules/gui/qt/medialibrary/mlrecentsvideomodel.hpp
@@ -31,7 +31,7 @@
 
 #include <QObject>
 
-class MLRecentsVideoModel : public MLSlidingWindowModel<MLVideo>
+class MLRecentsVideoModel : public MLSlidingWindowModel
 {
     Q_OBJECT
     Q_PROPERTY(int numberOfItemsToShow READ getNumberOfItemsToShow WRITE setNumberOfItemsToShow)
@@ -45,7 +45,7 @@ public:
     int numberOfItemsToShow = 10;
 
 protected:
-    ListCacheLoader<std::unique_ptr<MLVideo>> *createLoader() const override;
+    ListCacheLoader<std::unique_ptr<MLItem>> *createLoader() const override;
 
 private:
     vlc_ml_sorting_criteria_t roleToCriteria( int /* role */ ) const override{
@@ -67,7 +67,7 @@ private:
         }
 
         size_t count() const override;
-        std::vector<std::unique_ptr<MLVideo>> load(size_t index, size_t count) const override;
+        std::vector<std::unique_ptr<MLItem>> load(size_t index, size_t count) const override;
 
     private:
         int m_numberOfItemsToShow;
diff --git a/modules/gui/qt/medialibrary/mlurlmodel.cpp b/modules/gui/qt/medialibrary/mlurlmodel.cpp
index 268f96b967..5ebe66eaac 100644
--- a/modules/gui/qt/medialibrary/mlurlmodel.cpp
+++ b/modules/gui/qt/medialibrary/mlurlmodel.cpp
@@ -21,7 +21,7 @@
 #include <QDateTime>
 
 MLUrlModel::MLUrlModel(QObject *parent)
-    : MLSlidingWindowModel<MLUrl>(parent)
+    : MLSlidingWindowModel(parent)
 {
 }
 
@@ -30,7 +30,7 @@ QVariant MLUrlModel::data(const QModelIndex &index, int role) const
     if (!index.isValid() || index.row() < 0)
         return QVariant();
 
-    const MLUrl* ml_url = item(static_cast<unsigned int>(index.row()));
+    const MLUrl* ml_url = static_cast<MLUrl *>(item(index.row()));
     if ( !ml_url )
         return QVariant();
 
@@ -126,7 +126,7 @@ MLUrl *MLUrl::clone() const {
     return new MLUrl( *this );
 }
 
-ListCacheLoader<std::unique_ptr<MLUrl>> *
+ListCacheLoader<std::unique_ptr<MLItem>> *
 MLUrlModel::createLoader() const
 {
     return new Loader(*this);
@@ -140,7 +140,7 @@ size_t MLUrlModel::Loader::count() const
     return vlc_ml_count_stream_history( m_ml, &queryParams );
 }
 
-std::vector<std::unique_ptr<MLUrl>>
+std::vector<std::unique_ptr<MLItem>>
 MLUrlModel::Loader::load(size_t index, size_t count) const
 {
     MLQueryParams params = getParams(index, count);
@@ -151,7 +151,7 @@ MLUrlModel::Loader::load(size_t index, size_t count) const
     if ( media_list == nullptr )
         return {};
 
-    std::vector<std::unique_ptr<MLUrl>> res;
+    std::vector<std::unique_ptr<MLItem>> res;
     for( const vlc_ml_media_t& media: ml_range_iterate<vlc_ml_media_t>( media_list ) )
         res.emplace_back( std::make_unique<MLUrl>( &media ) );
     return res;
diff --git a/modules/gui/qt/medialibrary/mlurlmodel.hpp b/modules/gui/qt/medialibrary/mlurlmodel.hpp
index 4a28aa0f3a..b560c71997 100644
--- a/modules/gui/qt/medialibrary/mlurlmodel.hpp
+++ b/modules/gui/qt/medialibrary/mlurlmodel.hpp
@@ -46,7 +46,7 @@ private:
     QString m_lastPlayedDate;
 };
 
-class MLUrlModel : public MLSlidingWindowModel<MLUrl>
+class MLUrlModel : public MLSlidingWindowModel
 {
     Q_OBJECT
 
@@ -68,7 +68,7 @@ public:
     Q_INVOKABLE void addAndPlay( const QString& url );
 
 protected:
-    ListCacheLoader<std::unique_ptr<MLUrl>> *createLoader() const override;
+    ListCacheLoader<std::unique_ptr<MLItem>> *createLoader() const override;
 
 private:
     vlc_ml_sorting_criteria_t roleToCriteria(int role) const override;
@@ -78,7 +78,7 @@ private:
     {
         Loader(const MLUrlModel &model) : BaseLoader(model) {}
         size_t count() const override;
-        std::vector<std::unique_ptr<MLUrl>> load(size_t index, size_t count) const override;
+        std::vector<std::unique_ptr<MLItem>> load(size_t index, size_t count) const override;
     };
 };
 
diff --git a/modules/gui/qt/medialibrary/mlvideomodel.cpp b/modules/gui/qt/medialibrary/mlvideomodel.cpp
index 27e1414e4b..d2df1b942c 100644
--- a/modules/gui/qt/medialibrary/mlvideomodel.cpp
+++ b/modules/gui/qt/medialibrary/mlvideomodel.cpp
@@ -27,13 +27,13 @@ QHash<QByteArray, vlc_ml_sorting_criteria_t> MLVideoModel::M_names_to_criteria =
 };
 
 MLVideoModel::MLVideoModel(QObject* parent)
-    : MLSlidingWindowModel<MLVideo>(parent)
+    : MLSlidingWindowModel(parent)
 {
 }
 
 QVariant MLVideoModel::data(const QModelIndex& index, int role) const
 {
-    const auto video = item(index.row());
+    const auto video = static_cast<MLVideo *>(item(index.row()));
     if ( video == nullptr )
         return {};
     switch (role)
@@ -137,7 +137,7 @@ void MLVideoModel::thumbnailUpdated(int idx)
     emit dataChanged(index(idx), index(idx), {VIDEO_THUMBNAIL});
 }
 
-ListCacheLoader<std::unique_ptr<MLVideo>> *
+ListCacheLoader<std::unique_ptr<MLItem>> *
 MLVideoModel::createLoader() const
 {
     return new Loader(*this);
@@ -151,7 +151,7 @@ size_t MLVideoModel::Loader::count() const
     return vlc_ml_count_video_media(m_ml, &queryParams);
 }
 
-std::vector<std::unique_ptr<MLVideo>>
+std::vector<std::unique_ptr<MLItem>>
 MLVideoModel::Loader::load(size_t index, size_t count) const
 {
     MLQueryParams params = getParams(index, count);
@@ -161,7 +161,7 @@ MLVideoModel::Loader::load(size_t index, size_t count) const
                 m_ml, &queryParams ) };
     if ( media_list == nullptr )
         return {};
-    std::vector<std::unique_ptr<MLVideo>> res;
+    std::vector<std::unique_ptr<MLItem>> res;
     for( vlc_ml_media_t &media: ml_range_iterate<vlc_ml_media_t>( media_list ) )
         res.emplace_back( std::make_unique<MLVideo>(m_ml, &media) );
     return res;
diff --git a/modules/gui/qt/medialibrary/mlvideomodel.hpp b/modules/gui/qt/medialibrary/mlvideomodel.hpp
index 2f3fda89fa..23ae8b51e2 100644
--- a/modules/gui/qt/medialibrary/mlvideomodel.hpp
+++ b/modules/gui/qt/medialibrary/mlvideomodel.hpp
@@ -31,7 +31,7 @@
 
 #include <QObject>
 
-class MLVideoModel : public MLSlidingWindowModel<MLVideo>
+class MLVideoModel : public MLSlidingWindowModel
 {
     Q_OBJECT
 
@@ -63,7 +63,7 @@ public:
     QHash<int, QByteArray> roleNames() const override;
 
 protected:
-    ListCacheLoader<std::unique_ptr<MLVideo>> *createLoader() const override;
+    ListCacheLoader<std::unique_ptr<MLItem>> *createLoader() const override;
 
 private:
     vlc_ml_sorting_criteria_t roleToCriteria(int role) const override;
@@ -78,7 +78,7 @@ private:
     {
         Loader(const MLVideoModel &model) : BaseLoader(model) {}
         size_t count() const override;
-        std::vector<std::unique_ptr<MLVideo>> load(size_t index, size_t count) const override;
+        std::vector<std::unique_ptr<MLItem>> load(size_t index, size_t count) const override;
     };
 };
 
-- 
2.29.2



More information about the vlc-devel mailing list