Browse Source

qt: make sure to initialize MLBaseModel cache after qml parsing

pull/162/head
Prince Gupta 3 years ago
committed by Jean-Baptiste Kempf
parent
commit
a355f02603
  1. 20
      modules/gui/qt/medialibrary/mlbasemodel.cpp
  2. 12
      modules/gui/qt/medialibrary/mlbasemodel.hpp

20
modules/gui/qt/medialibrary/mlbasemodel.cpp

@ -251,6 +251,18 @@ void MLBaseModel::onVlcMlEvent(void* data, const vlc_ml_event_t* event)
});
}
void MLBaseModel::classBegin()
{
m_qmlInitializing = true;
}
void MLBaseModel::componentComplete()
{
m_qmlInitializing = false;
validateCache();
}
MLItemId MLBaseModel::parentId() const
{
return m_parent;
@ -349,7 +361,7 @@ void MLBaseModel::unsetSortCriteria()
int MLBaseModel::rowCount(const QModelIndex &parent) const
{
if (!m_mediaLib || parent.isValid())
if (!cachable() || parent.isValid())
return 0;
validateCache();
@ -409,9 +421,11 @@ QVariantList MLBaseModel::getIdsForIndexes(const QVariantList & indexes) const
unsigned MLBaseModel::getCount() const
{
if (!m_mediaLib)
if (!cachable())
return 0;
validateCache();
if (m_cache->count() == COUNT_UNINITIALIZED)
return 0;
return static_cast<unsigned>(m_cache->count());
@ -443,7 +457,7 @@ void MLBaseModel::validateCache() const
if (m_cache)
return;
if (!m_mediaLib)
if (!cachable())
return;
auto loader = createLoader();

12
modules/gui/qt/medialibrary/mlbasemodel.hpp

@ -27,6 +27,8 @@
#include <memory>
#include <QAbstractListModel>
#include <QQmlParserStatus>
#include <vlc_media_library.h>
#include "mlqmltypes.hpp"
#include "medialib.hpp"
@ -39,9 +41,10 @@
class MLListCache;
class MediaLib;
class MLBaseModel : public QAbstractListModel
class MLBaseModel : public QAbstractListModel, public QQmlParserStatus
{
Q_OBJECT
Q_INTERFACES(QQmlParserStatus)
Q_PROPERTY(MLItemId parentId READ parentId WRITE setParentId NOTIFY parentIdChanged
RESET unsetParentId FINAL)
@ -99,6 +102,9 @@ private:
static void onVlcMlEvent( void* data, const vlc_ml_event_t* event );
protected:
void classBegin() override;
void componentComplete() override;
virtual vlc_ml_sorting_criteria_t roleToCriteria(int role) const = 0;
static QString getFirstSymbol(QString str);
virtual vlc_ml_sorting_criteria_t nameToCriteria(QByteArray) const {
@ -183,6 +189,8 @@ private:
void onCacheBeginRemoveRows(int first, int last);
void onCacheBeginMoveRows(int first, int last, int destination);
inline bool cachable() const { return m_mediaLib && !m_qmlInitializing; }
protected:
MLItemId m_parent;
@ -199,6 +207,8 @@ protected:
//loader used to load single items
std::shared_ptr<BaseLoader> m_itemLoader;
bool m_qmlInitializing = false;
};
#endif // MLBASEMODEL_HPP

Loading…
Cancel
Save