Warning, file /utilities/skanpage/src/FilteredOptionsModel.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /**
0002  * SPDX-FileCopyrightText: 2021 by Alexander Stippich <a.stippich@gmx.net>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #include "FilteredOptionsModel.h"
0008 #include "OptionsModel.h"
0009 
0010 FilteredOptionsModel::FilteredOptionsModel(QObject *parent) : QSortFilterProxyModel(parent)
0011 {
0012 }
0013 
0014 FilteredOptionsModel::~FilteredOptionsModel() = default;
0015 
0016 bool FilteredOptionsModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
0017 {
0018     const auto index = sourceModel()->index(source_row, 0, source_parent);
0019     const auto &state = sourceModel()->data(index, OptionsModel::StateRole).value<KSaneCore::Option::OptionState>();
0020     const auto &type = sourceModel()->data(index, OptionsModel::TypeRole).value<KSaneCore::Option::OptionType>();
0021     
0022     if (!m_showAllOptions) {
0023         return sourceModel()->data(index, OptionsModel::QuickAccessRole).toBool() && state == KSaneCore::Option::StateActive;
0024     }
0025     
0026     if (state != KSaneCore::Option::StateActive || type == KSaneCore::Option::TypeGamma || type == KSaneCore::Option::TypeDetectFail) {
0027         return false;
0028     }
0029 
0030     return true;
0031 }
0032 
0033 void FilteredOptionsModel::showAllOptions(bool show)
0034 {
0035     if (m_showAllOptions != show) {
0036         m_showAllOptions = show;
0037         invalidateFilter();
0038     }
0039 }