mirror of https://github.com/KDE/kasts.git
Implement EpisodeProxyModel to filter based on status
This commit is contained in:
parent
6d5831a715
commit
531c6a2483
|
@ -19,6 +19,7 @@ set(SRCS_base
|
|||
models/entriesmodel.cpp
|
||||
models/queuemodel.cpp
|
||||
models/episodemodel.cpp
|
||||
models/episodeproxymodel.cpp
|
||||
models/downloadmodel.cpp
|
||||
models/errorlogmodel.cpp
|
||||
models/podcastsearchmodel.cpp
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
#include "kasts-version.h"
|
||||
#include "models/downloadmodel.h"
|
||||
#include "models/entriesmodel.h"
|
||||
#include "models/episodemodel.h"
|
||||
#include "models/episodeproxymodel.h"
|
||||
#include "models/errorlogmodel.h"
|
||||
#include "models/feedsmodel.h"
|
||||
#include "models/podcastsearchmodel.h"
|
||||
|
@ -120,7 +120,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
qmlRegisterType<FeedsModel>("org.kde.kasts", 1, 0, "FeedsModel");
|
||||
qmlRegisterType<QueueModel>("org.kde.kasts", 1, 0, "QueueModel");
|
||||
qmlRegisterType<EpisodeModel>("org.kde.kasts", 1, 0, "EpisodeModel");
|
||||
qmlRegisterType<EpisodeProxyModel>("org.kde.kasts", 1, 0, "EpisodeProxyModel");
|
||||
qmlRegisterType<Mpris2>("org.kde.kasts", 1, 0, "Mpris2");
|
||||
qmlRegisterType<PodcastSearchModel>("org.kde.kasts", 1, 0, "PodcastSearchModel");
|
||||
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* SPDX-FileCopyrightText: 2021 Bart De Vries <bart@mogwai.be>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||
*/
|
||||
|
||||
#include "models/episodeproxymodel.h"
|
||||
|
||||
EpisodeProxyModel::EpisodeProxyModel()
|
||||
: QSortFilterProxyModel(nullptr)
|
||||
{
|
||||
m_currentFilter = NoFilter;
|
||||
m_episodeModel = new EpisodeModel();
|
||||
setSourceModel(m_episodeModel);
|
||||
}
|
||||
|
||||
EpisodeProxyModel::~EpisodeProxyModel()
|
||||
{
|
||||
delete m_episodeModel;
|
||||
}
|
||||
|
||||
bool EpisodeProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
||||
{
|
||||
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
|
||||
|
||||
switch (m_currentFilter) {
|
||||
case NoFilter:
|
||||
return true;
|
||||
case ReadFilter:
|
||||
return sourceModel()->data(index, EpisodeModel::Roles::ReadRole).value<bool>();
|
||||
case NotReadFilter:
|
||||
return !sourceModel()->data(index, EpisodeModel::Roles::ReadRole).value<bool>();
|
||||
case NewFilter:
|
||||
return sourceModel()->data(index, EpisodeModel::Roles::NewRole).value<bool>();
|
||||
case NotNewFilter:
|
||||
return !sourceModel()->data(index, EpisodeModel::Roles::NewRole).value<bool>();
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
EpisodeProxyModel::FilterType EpisodeProxyModel::filterType() const
|
||||
{
|
||||
return m_currentFilter;
|
||||
}
|
||||
|
||||
void EpisodeProxyModel::setFilterType(FilterType type)
|
||||
{
|
||||
m_currentFilter = type;
|
||||
Q_EMIT filterTypeChanged(m_currentFilter);
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/**
|
||||
* SPDX-FileCopyrightText: 2021 Bart De Vries <bart@mogwai.be>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
#include "models/episodemodel.h"
|
||||
|
||||
class EpisodeProxyModel : public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum FilterType {
|
||||
NoFilter,
|
||||
ReadFilter,
|
||||
NotReadFilter,
|
||||
NewFilter,
|
||||
NotNewFilter,
|
||||
};
|
||||
Q_ENUM(FilterType)
|
||||
|
||||
Q_PROPERTY(FilterType filterType READ filterType WRITE setFilterType NOTIFY filterTypeChanged)
|
||||
|
||||
explicit EpisodeProxyModel();
|
||||
~EpisodeProxyModel();
|
||||
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
|
||||
|
||||
FilterType filterType() const;
|
||||
void setFilterType(FilterType type);
|
||||
|
||||
Q_SIGNALS:
|
||||
void filterTypeChanged(FilterType filter);
|
||||
|
||||
private:
|
||||
EpisodeModel *m_episodeModel;
|
||||
FilterType m_currentFilter;
|
||||
};
|
|
@ -17,8 +17,6 @@ Kirigami.ScrollablePage {
|
|||
|
||||
title: i18n("Episode List")
|
||||
|
||||
property var episodeType: EpisodeModel.All
|
||||
|
||||
supportsRefreshing: true
|
||||
onRefreshingChanged: {
|
||||
if(refreshing) {
|
||||
|
@ -52,15 +50,15 @@ Kirigami.ScrollablePage {
|
|||
}
|
||||
}
|
||||
|
||||
EpisodeModel {
|
||||
id: episodeModel
|
||||
EpisodeProxyModel {
|
||||
id: episodeProxyModel
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: episodeList
|
||||
anchors.fill: parent
|
||||
visible: count !== 0
|
||||
model: episodeModel
|
||||
model: episodeProxyModel
|
||||
|
||||
delegate: Kirigami.DelegateRecycler {
|
||||
width: episodeList.width
|
||||
|
|
Loading…
Reference in New Issue