#include <QDebug>
MyListFilterModel::MyListFilterModel(QObject *parent) :
- QSortFilterProxyModel(parent), m_hideEmptyAnime(false)
+ QSortFilterProxyModel(parent), m_hideEmptyAnime(false), m_hideWatchedEpisodes(false)
{
setFilterCaseSensitivity(Qt::CaseInsensitive);
return m_hideEmptyAnime;
}
+bool MyListFilterModel::hideWatchedEpisodes() const
+{
+ return m_hideWatchedEpisodes;
+}
+
LocalMyList::MyListModel *MyListFilterModel::myListModel() const
{
return qobject_cast<LocalMyList::MyListModel *>(sourceModel());
emit hideEmptyAnimeChanged(hide);
}
+void MyListFilterModel::setHideWatchedEpisodes(bool hideWatchedEpisodes)
+{
+ if (m_hideWatchedEpisodes == hideWatchedEpisodes)
+ return;
+
+ m_hideWatchedEpisodes = hideWatchedEpisodes;
+
+ if (LocalMyList::instance()->settings()->get("myListHideWatchedEpisodes", hideWatchedEpisodes) != hideWatchedEpisodes)
+ {
+ LocalMyList::instance()->settings()->set("myListHideWatchedEpisodes", hideWatchedEpisodes);
+ LocalMyList::instance()->settings()->commit();
+ }
+ invalidateFilter();
+
+ emit hideWatchedEpisodesChanged(hideWatchedEpisodes);
+}
+
void MyListFilterModel::configChanged()
{
setHideEmptyAnime(LocalMyList::instance()->settings()->get("myListHideEmptyAnime", false));
+ setHideWatchedEpisodes(LocalMyList::instance()->settings()->get("myListHideWatchedEpisodes", false));
}
bool MyListFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
- if (source_parent.isValid())
- return true;
-
const QModelIndex idx = sourceModel()->index(source_row, 0, source_parent);
- if (m_hideEmptyAnime && !sourceModel()->rowCount(idx) && !sourceModel()->canFetchMore(idx))
- return false;
- return sourceModel()->data(idx).toString().contains(filterRegExp());
+ if (!source_parent.isValid())
+ {
+ if (m_hideEmptyAnime)
+ {
+ if (!sourceModel()->rowCount(idx) && !sourceModel()->canFetchMore(idx))
+ return false;
+
+ if (m_hideWatchedEpisodes)
+ {
+ const LocalMyList::MyListNode *node = myListModel()->node(idx);
+ if (node->type() == LocalMyList::MyListNode::AnimeNode)
+ {
+ const LocalMyList::AnimeData &animeData = static_cast<const LocalMyList::MyListAnimeNode *>(node)->internalData();
+ if (animeData.watchedEpisodes == animeData.episodesInMyList)
+ return false;
+ }
+ }
+ }
+
+ return sourceModel()->data(idx).toString().contains(filterRegExp());
+ }
+ else if (m_hideWatchedEpisodes)
+ {
+ const LocalMyList::MyListNode *node = myListModel()->node(idx);
+ if (node->type() == LocalMyList::MyListNode::EpisodeNode)
+ {
+ const LocalMyList::EpisodeData &episodeData = static_cast<const LocalMyList::MyListEpisodeNode *>(node)->internalData();
+ if (episodeData.watchedDate.isValid())
+ return false;
+ }
+ }
+
+ return true;
}
{
Q_OBJECT
Q_PROPERTY(bool hideEmptyAnime READ hideEmptyAnime WRITE setHideEmptyAnime NOTIFY hideEmptyAnimeChanged)
+ Q_PROPERTY(bool hideWatchedEpisodes READ hideWatchedEpisodes WRITE setHideWatchedEpisodes NOTIFY hideWatchedEpisodesChanged)
public:
explicit MyListFilterModel(QObject *parent = 0);
bool hideEmptyAnime() const;
+ bool hideWatchedEpisodes() const;
public slots:
LocalMyList::MyListModel *myListModel() const;
LocalMyList::MyListNode *node(const QModelIndex &idx) const;
void setHideEmptyAnime(bool hide);
+ void setHideWatchedEpisodes(bool hideWatchedEpisodes);
void configChanged();
signals:
- void hideEmptyAnimeChanged(bool arg);
+ void hideEmptyAnimeChanged(bool hideEmptyAnime);
+ void hideWatchedEpisodesChanged(bool hideWatchedEpisodes);
protected:
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
private:
bool m_hideEmptyAnime;
+ bool m_hideWatchedEpisodes;
};
#endif // MYLISTFILTERMODEL_H