File indexing completed on 2024-11-10 04:56:49

0001 /*
0002     SPDX-FileCopyrightText: 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "effectsfilterproxymodel.h"
0008 
0009 #include "effectsmodel.h"
0010 
0011 namespace KWin
0012 {
0013 
0014 EffectsFilterProxyModel::EffectsFilterProxyModel(QObject *parent)
0015     : QSortFilterProxyModel(parent)
0016 {
0017 }
0018 
0019 EffectsFilterProxyModel::~EffectsFilterProxyModel()
0020 {
0021 }
0022 
0023 QString EffectsFilterProxyModel::query() const
0024 {
0025     return m_query;
0026 }
0027 
0028 void EffectsFilterProxyModel::setQuery(const QString &query)
0029 {
0030     if (m_query != query) {
0031         m_query = query;
0032         Q_EMIT queryChanged();
0033         invalidateFilter();
0034     }
0035 }
0036 
0037 bool EffectsFilterProxyModel::excludeInternal() const
0038 {
0039     return m_excludeInternal;
0040 }
0041 
0042 void EffectsFilterProxyModel::setExcludeInternal(bool exclude)
0043 {
0044     if (m_excludeInternal != exclude) {
0045         m_excludeInternal = exclude;
0046         Q_EMIT excludeInternalChanged();
0047         invalidateFilter();
0048     }
0049 }
0050 
0051 bool EffectsFilterProxyModel::excludeUnsupported() const
0052 {
0053     return m_excludeUnsupported;
0054 }
0055 
0056 void EffectsFilterProxyModel::setExcludeUnsupported(bool exclude)
0057 {
0058     if (m_excludeUnsupported != exclude) {
0059         m_excludeUnsupported = exclude;
0060         Q_EMIT excludeUnsupportedChanged();
0061         invalidateFilter();
0062     }
0063 }
0064 
0065 bool EffectsFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
0066 {
0067     const QModelIndex idx = sourceModel()->index(sourceRow, 0, sourceParent);
0068 
0069     if (!m_query.isEmpty()) {
0070         const bool matches = idx.data(EffectsModel::NameRole).toString().contains(m_query, Qt::CaseInsensitive) || idx.data(EffectsModel::DescriptionRole).toString().contains(m_query, Qt::CaseInsensitive) || idx.data(EffectsModel::CategoryRole).toString().contains(m_query, Qt::CaseInsensitive);
0071         if (!matches) {
0072             return false;
0073         }
0074     }
0075 
0076     if (m_excludeInternal) {
0077         if (idx.data(EffectsModel::InternalRole).toBool()) {
0078             return false;
0079         }
0080     }
0081 
0082     if (m_excludeUnsupported) {
0083         if (!idx.data(EffectsModel::SupportedRole).toBool()) {
0084             return false;
0085         }
0086     }
0087 
0088     return true;
0089 }
0090 
0091 } // namespace KWin
0092 
0093 #include "moc_effectsfilterproxymodel.cpp"