File indexing completed on 2024-12-08 07:33:47

0001 // SPDX-FileCopyrightText: 2022 James Graham <james.h.graham@protonmail.com>
0002 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0003 
0004 #include "statefiltermodel.h"
0005 
0006 #include "statemodel.h"
0007 
0008 bool StateFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
0009 {
0010     Q_UNUSED(sourceParent);
0011     // No need to run the check if there are no items in m_stateEventTypesFiltered.
0012     if (m_stateEventTypesFiltered.empty()) {
0013         return true;
0014     }
0015     return !m_stateEventTypesFiltered.contains(sourceModel()->data(sourceModel()->index(sourceRow, 0), StateModel::TypeRole).toString());
0016 }
0017 
0018 void StateFilterModel::addStateEventTypeFiltered(const QString &stateEventType)
0019 {
0020     if (!m_stateEventTypesFiltered.contains(stateEventType)) {
0021         m_stateEventTypesFiltered.append(stateEventType);
0022         invalidateFilter();
0023     }
0024 }
0025 
0026 void StateFilterModel::removeStateEventTypeFiltered(const QString &stateEventType)
0027 {
0028     if (m_stateEventTypesFiltered.contains(stateEventType)) {
0029         m_stateEventTypesFiltered.removeAll(stateEventType);
0030         invalidateFilter();
0031     }
0032 }
0033 
0034 #include "moc_statefiltermodel.cpp"