[vlc-commits] [Git][videolan/vlc][master] 3 commits: qt: improve state checking in ml model

Steve Lhomme (@robUx4) gitlab at videolan.org
Thu Jul 27 12:50:33 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
148eebff by Prince Gupta at 2023-07-27T12:23:49+00:00
qt: improve state checking in ml model

assigning ml will initialize cache, no need to request initialization everywhere

- - - - -
7886e53e by Prince Gupta at 2023-07-27T12:23:49+00:00
qt: remove redundant access specifiers

- - - - -
9c230251 by Prince Gupta at 2023-07-27T12:23:49+00:00
qt: fix typo in method name

- - - - -


2 changed files:

- modules/gui/qt/medialibrary/mlbasemodel.cpp
- modules/gui/qt/medialibrary/mlbasemodel.hpp


Changes:

=====================================
modules/gui/qt/medialibrary/mlbasemodel.cpp
=====================================
@@ -324,7 +324,7 @@ Qt::SortOrder MLBaseModel::getSortOrder() const
     return m_sort_desc ? Qt::SortOrder::DescendingOrder : Qt::SortOrder::AscendingOrder;
 }
 
-void MLBaseModel::setSortOder(Qt::SortOrder order)
+void MLBaseModel::setSortOrder(Qt::SortOrder order)
 {
     bool desc = (order == Qt::SortOrder::DescendingOrder);
     if (m_sort_desc == desc)
@@ -361,11 +361,9 @@ void MLBaseModel::unsetSortCriteria()
 
 int MLBaseModel::rowCount(const QModelIndex &parent) const
 {
-    if (!cachable() || parent.isValid())
+    if (!m_cache || parent.isValid())
         return 0;
 
-    validateCache();
-
     return m_cache->count();
 }
 
@@ -421,13 +419,9 @@ QVariantList MLBaseModel::getIdsForIndexes(const QVariantList & indexes) const
 
 unsigned MLBaseModel::getCount() const
 {
-    if (!cachable())
+    if (!m_cache || m_cache->count() == COUNT_UNINITIALIZED)
         return 0;
 
-    validateCache();
-
-    if (m_cache->count() == COUNT_UNINITIALIZED)
-        return 0;
     return static_cast<unsigned>(m_cache->count());
 }
 
@@ -512,8 +506,6 @@ void MLBaseModel::invalidateCache()
 
 MLItem *MLBaseModel::item(int signedidx) const
 {
-    validateCache();
-
     if (!m_cache)
         return nullptr;
 


=====================================
modules/gui/qt/medialibrary/mlbasemodel.hpp
=====================================
@@ -53,7 +53,7 @@ class MLBaseModel : public QAbstractListModel, public QQmlParserStatus
 
     Q_PROPERTY(QString searchPattern READ searchPattern WRITE setSearchPattern FINAL)
 
-    Q_PROPERTY(Qt::SortOrder sortOrder READ getSortOrder WRITE setSortOder NOTIFY sortOrderChanged FINAL)
+    Q_PROPERTY(Qt::SortOrder sortOrder READ getSortOrder WRITE setSortOrder NOTIFY sortOrderChanged FINAL)
 
     Q_PROPERTY(QString sortCriteria READ getSortCriteria WRITE setSortCriteria
                NOTIFY sortCriteriaChanged RESET unsetSortCriteria FINAL)
@@ -71,7 +71,10 @@ public:
 
     virtual ~MLBaseModel();
 
-public: // Interface
+
+    virtual QVariant itemRoleData(MLItem *item, int role) const = 0;
+
+
     Q_INVOKABLE void sortByColumn(QByteArray name, Qt::SortOrder order);
 
     Q_INVOKABLE virtual MLItemId getIdForIndex(QVariant index) const;
@@ -85,8 +88,31 @@ public: // Interface
     Q_INVOKABLE void getData(const QModelIndexList &indexes, QJSValue callback);
 
     QVariant data(const QModelIndex &index, int role) const override final;
+    int rowCount(const QModelIndex &parent = {}) const override;
+
+public:
+    // properties functions
+
+    MLItemId parentId() const;
+    void setParentId(MLItemId parentId);
+    void unsetParentId();
+
+    MediaLib* ml() const;
+    void setMl(MediaLib* ml);
+
+    const QString& searchPattern() const;
+    void setSearchPattern( const QString& pattern );
+
+    Qt::SortOrder getSortOrder() const;
+    void setSortOrder(Qt::SortOrder order);
+    const QString getSortCriteria() const;
+    void setSortCriteria(const QString& criteria);
+    void unsetSortCriteria();
+
+    virtual unsigned int getCount() const;
+
+    bool loading() const;
 
-    virtual QVariant itemRoleData(MLItem *item, int role) const = 0;
 
 signals:
     void parentIdChanged();
@@ -97,12 +123,11 @@ signals:
     void countChanged(unsigned int) const;
     void loadingChanged() const;
 
+
 protected slots:
     void onResetRequested();
     void onLocalSizeChanged(size_t size);
 
-private:
-    static void onVlcMlEvent( void* data, const vlc_ml_event_t* event );
 
 protected:
     void classBegin() override;
@@ -164,29 +189,9 @@ protected:
 
     virtual std::unique_ptr<BaseLoader> createLoader() const = 0;
 
-public:
-    MLItemId parentId() const;
-    void setParentId(MLItemId parentId);
-    void unsetParentId();
-
-    MediaLib* ml() const;
-    void setMl(MediaLib* ml);
-
-    const QString& searchPattern() const;
-    void setSearchPattern( const QString& pattern );
-
-    Qt::SortOrder getSortOrder() const;
-    void setSortOder(Qt::SortOrder order);
-    const QString getSortCriteria() const;
-    void setSortCriteria(const QString& criteria);
-    void unsetSortCriteria();
-
-    int rowCount(const QModelIndex &parent = {}) const override;
-    virtual unsigned int getCount() const;
-
-    bool loading() const;
-
 private:
+    static void onVlcMlEvent( void* data, const vlc_ml_event_t* event );
+
     void onCacheDataChanged(int first, int last);
     void onCacheBeginInsertRows(int first, int last);
     void onCacheBeginRemoveRows(int first, int last);



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/3a3214a13315b9bc805e258116568cea7e653b84...9c230251f76dc518dfbca7db72dc5cc2a491dce3

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/3a3214a13315b9bc805e258116568cea7e653b84...9c230251f76dc518dfbca7db72dc5cc2a491dce3
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list