Commit e9a6c06d authored by Matthieu Gallien's avatar Matthieu Gallien 🎵
Browse files

clean up the proxy models inheriting AbstractMediaProxyModel

parent f7816af1
......@@ -10,6 +10,8 @@
#include "mediaplaylistproxymodel.h"
#include <QWriteLocker>
#include <QReadLocker>
#include <QtConcurrent>
AbstractMediaProxyModel::AbstractMediaProxyModel(QObject *parent) : QSortFilterProxyModel(parent)
{
......@@ -108,5 +110,32 @@ void AbstractMediaProxyModel::connectPlayList()
mPlayList, static_cast<void(MediaPlayListProxyModel::*)(const DataTypes::EntryDataList&, ElisaUtils::PlayListEnqueueMode, ElisaUtils::PlayListEnqueueTriggerPlay)>(&MediaPlayListProxyModel::enqueue));
}
}
void AbstractMediaProxyModel::genericEnqueueToPlayList(ElisaUtils::PlayListEnqueueMode enqueueMode,
ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay)
{
QtConcurrent::run(&mThreadPool, [=] () {
QReadLocker locker(&mDataLock);
auto allData = DataTypes::EntryDataList{};
allData.reserve(rowCount());
for (int rowIndex = 0, maxRowCount = rowCount(); rowIndex < maxRowCount; ++rowIndex) {
auto currentIndex = index(rowIndex, 0);
allData.push_back(DataTypes::EntryData{data(currentIndex, DataTypes::FullDataRole).value<DataTypes::MusicDataType>(),
data(currentIndex, Qt::DisplayRole).toString(), {}});
}
Q_EMIT entriesToEnqueue(allData, enqueueMode, triggerPlay);
});
}
void AbstractMediaProxyModel::enqueueToPlayList()
{
genericEnqueueToPlayList(ElisaUtils::AppendPlayList, ElisaUtils::DoNotTriggerPlay);
}
void AbstractMediaProxyModel::replaceAndPlayOfPlayList()
{
genericEnqueueToPlayList(ElisaUtils::ReplacePlayList, ElisaUtils::TriggerPlay);
}
#include "moc_abstractmediaproxymodel.cpp"
......@@ -65,6 +65,10 @@ public Q_SLOTS:
void setPlayList(MediaPlayListProxyModel* playList);
void enqueueToPlayList();
void replaceAndPlayOfPlayList();
Q_SIGNALS:
void filterTextChanged(const QString &filterText);
......@@ -99,6 +103,11 @@ protected:
MediaPlayListProxyModel* mPlayList = nullptr;
private:
void genericEnqueueToPlayList(ElisaUtils::PlayListEnqueueMode enqueueMode,
ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay);
};
#endif // ABSTRACTMEDIAPROXYMODEL_H
......@@ -8,9 +8,6 @@
#include "datatypes.h"
#include <QReadLocker>
#include <QtConcurrent>
AllTracksProxyModel::AllTracksProxyModel(QObject *parent) : AbstractMediaProxyModel(parent)
{
setSortCaseSensitivity(Qt::CaseInsensitive);
......@@ -43,32 +40,5 @@ bool AllTracksProxyModel::filterAcceptsRow(int source_row, const QModelIndex &so
return result;
}
void AllTracksProxyModel::genericEnqueueToPlayList(ElisaUtils::PlayListEnqueueMode enqueueMode,
ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay)
{
QtConcurrent::run(&mThreadPool, [=] () {
QReadLocker locker(&mDataLock);
auto allTracks = DataTypes::EntryDataList{};
allTracks.reserve(rowCount());
for (int rowIndex = 0, maxRowCount = rowCount(); rowIndex < maxRowCount; ++rowIndex) {
auto currentIndex = index(rowIndex, 0);
allTracks.push_back(DataTypes::EntryData{data(currentIndex, DataTypes::FullDataRole).value<DataTypes::TrackDataType>(),
data(currentIndex, DataTypes::ColumnsRoles::TitleRole).toString(),
data(currentIndex, DataTypes::ColumnsRoles::ResourceRole).toUrl()});
}
Q_EMIT entriesToEnqueue(allTracks, enqueueMode, triggerPlay);
});
}
void AllTracksProxyModel::enqueueToPlayList()
{
genericEnqueueToPlayList(ElisaUtils::AppendPlayList, ElisaUtils::DoNotTriggerPlay);
}
void AllTracksProxyModel::replaceAndPlayOfPlayList()
{
genericEnqueueToPlayList(ElisaUtils::ReplacePlayList, ElisaUtils::TriggerPlay);
}
#include "moc_alltracksproxymodel.cpp"
......@@ -27,19 +27,12 @@ Q_SIGNALS:
public Q_SLOTS:
void enqueueToPlayList();
void replaceAndPlayOfPlayList();
protected:
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
private:
void genericEnqueueToPlayList(ElisaUtils::PlayListEnqueueMode enqueueMode,
ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay);
};
#endif // ALLTRACKSPROXYMODEL_H
......@@ -20,11 +20,6 @@ GridViewProxyModel::GridViewProxyModel(QObject *parent) : AbstractMediaProxyMode
sortModel(Qt::AscendingOrder);
}
ElisaUtils::PlayListEntryType GridViewProxyModel::dataType() const
{
return mDataType;
}
GridViewProxyModel::~GridViewProxyModel() = default;
bool GridViewProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
......@@ -63,43 +58,5 @@ bool GridViewProxyModel::filterAcceptsRow(int source_row, const QModelIndex &sou
return result;
}
void GridViewProxyModel::genericEnqueueToPlayList(ElisaUtils::PlayListEnqueueMode enqueueMode,
ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay)
{
QtConcurrent::run(&mThreadPool, [=] () {
QReadLocker locker(&mDataLock);
auto allData = DataTypes::EntryDataList{};
allData.reserve(rowCount());
for (int rowIndex = 0, maxRowCount = rowCount(); rowIndex < maxRowCount; ++rowIndex) {
auto currentIndex = index(rowIndex, 0);
allData.push_back(DataTypes::EntryData{data(currentIndex, DataTypes::FullDataRole).value<DataTypes::MusicDataType>(),
data(currentIndex, Qt::DisplayRole).toString(), {}});
}
Q_EMIT entriesToEnqueue(allData, enqueueMode, triggerPlay);
});
}
void GridViewProxyModel::enqueueToPlayList()
{
genericEnqueueToPlayList(ElisaUtils::AppendPlayList, ElisaUtils::DoNotTriggerPlay);
}
void GridViewProxyModel::replaceAndPlayOfPlayList()
{
genericEnqueueToPlayList(ElisaUtils::ReplacePlayList, ElisaUtils::TriggerPlay);
}
void GridViewProxyModel::setDataType(ElisaUtils::PlayListEntryType newDataType)
{
if (mDataType == newDataType) {
return;
}
mDataType = newDataType;
Q_EMIT dataTypeChanged();
}
#include "moc_gridviewproxymodel.cpp"
......@@ -11,46 +11,26 @@
#include "elisaLib_export.h"
#include "abstractmediaproxymodel.h"
#include "elisautils.h"
class ELISALIB_EXPORT GridViewProxyModel : public AbstractMediaProxyModel
{
Q_OBJECT
Q_PROPERTY(ElisaUtils::PlayListEntryType dataType READ dataType WRITE setDataType NOTIFY dataTypeChanged)
public:
explicit GridViewProxyModel(QObject *parent = nullptr);
~GridViewProxyModel() override;
ElisaUtils::PlayListEntryType dataType() const;
Q_SIGNALS:
void dataTypeChanged();
public Q_SLOTS:
void enqueueToPlayList();
void replaceAndPlayOfPlayList();
void setDataType(ElisaUtils::PlayListEntryType newDataType);
protected:
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
private:
void genericEnqueueToPlayList(ElisaUtils::PlayListEnqueueMode enqueueMode,
ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay);
ElisaUtils::PlayListEntryType mDataType = ElisaUtils::Unknown;
};
#endif // GRIDVIEWPROXYMODEL_H
......@@ -44,7 +44,6 @@ FocusScope {
id: proxyModel
sourceModel: realModel
dataType: modelType
playList: elisa.mediaPlayListProxyModel
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment