File indexing completed on 2024-05-19 05:54:11
0001 /* This file was part of the KDE libraries 0002 0003 SPDX-FileCopyrightText: 2021 Tomaz Canabrava <tcanabrava@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "filtermodel.h" 0009 0010 FilterModel::FilterModel(QObject *parent) 0011 : QSortFilterProxyModel(parent) 0012 { 0013 } 0014 0015 FilterModel::~FilterModel() = default; 0016 0017 bool FilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const 0018 { 0019 auto text = filterRegularExpression().pattern(); 0020 if (text.isEmpty()) { 0021 return true; 0022 } 0023 0024 const QModelIndex idx = sourceModel()->index(sourceRow, 0, sourceParent); 0025 if (sourceModel()->rowCount(idx) != 0) { 0026 return true; 0027 } 0028 0029 bool result = idx.data(Qt::DisplayRole).toString().toLower().contains(text.toLower()); 0030 0031 return m_invertFilter == false ? result : !result; 0032 } 0033 0034 void FilterModel::setInvertFilter(bool invert) 0035 { 0036 m_invertFilter = invert; 0037 invalidateFilter(); 0038 } 0039 0040 #include "moc_filtermodel.cpp"