Warning, file /utilities/telly-skout/src/channelsproxymodel.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 // SPDX-FileCopyrightText: 2022 Plata Hill <plata.hill@kdemail.net> 0002 // SPDX-License-Identifier: LGPL-2.1-or-later 0003 0004 #include "channelsproxymodel.h" 0005 0006 #include "channel.h" 0007 #include "database.h" 0008 0009 ChannelsProxyModel::ChannelsProxyModel(QObject *parent) 0010 : QSortFilterProxyModel(parent) 0011 , m_onlyFavorites(false) 0012 , m_group("") 0013 { 0014 connect(&Database::instance(), &Database::channelDetailsUpdated, this, [this]() { 0015 invalidateFilter(); 0016 }); 0017 } 0018 0019 ChannelsProxyModel::~ChannelsProxyModel() 0020 { 0021 } 0022 0023 bool ChannelsProxyModel::onlyFavorites() const 0024 { 0025 return m_onlyFavorites; 0026 } 0027 0028 void ChannelsProxyModel::setOnlyFavorites(const bool &onlyFavorites) 0029 { 0030 if (m_onlyFavorites != onlyFavorites) { 0031 m_onlyFavorites = onlyFavorites; 0032 invalidateFilter(); 0033 Q_EMIT onlyFavoritesChanged(); 0034 } 0035 } 0036 0037 const QString &ChannelsProxyModel::group() const 0038 { 0039 return m_group.value(); 0040 } 0041 0042 void ChannelsProxyModel::setGroup(const QString &group) 0043 { 0044 if (m_group.value() != group) { 0045 m_group = GroupId(group); 0046 invalidateFilter(); 0047 Q_EMIT groupChanged(); 0048 } 0049 } 0050 0051 bool ChannelsProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const 0052 { 0053 const auto idx = sourceModel()->index(source_row, 0, source_parent); 0054 0055 if (!QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent)) { 0056 return false; 0057 } 0058 0059 // no filter 0060 if (!m_onlyFavorites && m_group.value().isEmpty()) { 0061 return true; 0062 } 0063 0064 // at least one filter 0065 auto channel = idx.data(0).value<Channel *>(); 0066 0067 const bool onlyFavoritesMatches = !m_onlyFavorites || channel->favorite(); 0068 const bool groupMatches = m_group.value().isEmpty() || channel->groups().contains(m_group.value()); 0069 0070 return onlyFavoritesMatches && groupMatches; 0071 }