2019-02-02 20:49:38 +00:00
|
|
|
/*
|
2020-08-02 22:10:35 +00:00
|
|
|
* SPDX-FileCopyrightText: 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
2019-02-02 20:49:38 +00:00
|
|
|
*
|
2020-08-02 22:10:35 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2019-02-02 20:49:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "effectsfilterproxymodel.h"
|
|
|
|
|
2019-02-03 20:04:09 +00:00
|
|
|
#include "effectsmodel.h"
|
2019-02-02 20:49:38 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
EffectsFilterProxyModel::EffectsFilterProxyModel(QObject *parent)
|
|
|
|
: QSortFilterProxyModel(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
EffectsFilterProxyModel::~EffectsFilterProxyModel()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QString EffectsFilterProxyModel::query() const
|
|
|
|
{
|
|
|
|
return m_query;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EffectsFilterProxyModel::setQuery(const QString &query)
|
|
|
|
{
|
|
|
|
if (m_query != query) {
|
|
|
|
m_query = query;
|
|
|
|
emit queryChanged();
|
|
|
|
invalidateFilter();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EffectsFilterProxyModel::excludeInternal() const
|
|
|
|
{
|
|
|
|
return m_excludeInternal;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EffectsFilterProxyModel::setExcludeInternal(bool exclude)
|
|
|
|
{
|
|
|
|
if (m_excludeInternal != exclude) {
|
|
|
|
m_excludeInternal = exclude;
|
|
|
|
emit excludeInternalChanged();
|
|
|
|
invalidateFilter();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EffectsFilterProxyModel::excludeUnsupported() const
|
|
|
|
{
|
|
|
|
return m_excludeUnsupported;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EffectsFilterProxyModel::setExcludeUnsupported(bool exclude)
|
|
|
|
{
|
|
|
|
if (m_excludeUnsupported != exclude) {
|
|
|
|
m_excludeUnsupported = exclude;
|
|
|
|
emit excludeUnsupportedChanged();
|
|
|
|
invalidateFilter();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EffectsFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
|
|
|
{
|
|
|
|
const QModelIndex idx = sourceModel()->index(sourceRow, 0, sourceParent);
|
|
|
|
|
|
|
|
if (!m_query.isEmpty()) {
|
2019-02-03 20:04:09 +00:00
|
|
|
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);
|
2019-02-02 20:49:38 +00:00
|
|
|
if (!matches) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_excludeInternal) {
|
2019-02-03 20:04:09 +00:00
|
|
|
if (idx.data(EffectsModel::InternalRole).toBool()) {
|
2019-02-02 20:49:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_excludeUnsupported) {
|
2019-02-03 20:04:09 +00:00
|
|
|
if (!idx.data(EffectsModel::SupportedRole).toBool()) {
|
2019-02-02 20:49:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace KWin
|