File indexing completed on 2024-12-08 07:34:18

0001 /*
0002    SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "servererrorinfohistoryfilterproxymodel.h"
0008 #include "config-ruqola.h"
0009 #include "servererrorinfohistorymodel.h"
0010 #if HAVE_TEXT_UTILS
0011 #include <TextUtils/ConvertText>
0012 #endif
0013 
0014 ServerErrorInfoHistoryFilterProxyModel::ServerErrorInfoHistoryFilterProxyModel(QObject *parent)
0015     : SortFilterProxyModelBase{parent}
0016 {
0017 }
0018 
0019 ServerErrorInfoHistoryFilterProxyModel::~ServerErrorInfoHistoryFilterProxyModel() = default;
0020 
0021 bool ServerErrorInfoHistoryFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
0022 {
0023     const QModelIndex modelIndex = sourceModel()->index(source_row, 0, source_parent);
0024 
0025     if (!mAccountNameFilter.isEmpty()) {
0026         if (!modelIndex.data(ServerErrorInfoHistoryModel::AccountName).toString().contains(mAccountNameFilter, Qt::CaseInsensitive)) {
0027             return false;
0028         }
0029     }
0030     auto match = [&](int role) {
0031         return mFilterString.isEmpty() || modelIndex.data(role).toString().contains(mFilterString, Qt::CaseInsensitive);
0032     };
0033     if (!match(ServerErrorInfoHistoryModel::AccountName) && !match(ServerErrorInfoHistoryModel::MessageStr)) {
0034         return false;
0035     }
0036     return true;
0037 }
0038 
0039 void ServerErrorInfoHistoryFilterProxyModel::setAccountNameFilter(const QString &newAccountNameFilter)
0040 {
0041     if (mAccountNameFilter != newAccountNameFilter) {
0042         mAccountNameFilter = newAccountNameFilter;
0043         invalidate();
0044     }
0045 }
0046 
0047 #include "moc_servererrorinfohistoryfilterproxymodel.cpp"