File indexing completed on 2024-11-24 04:16:55

0001 /*
0002   SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "translatorproxymodel.h"
0008 #include "translatormodel.h"
0009 
0010 TranslatorProxyModel::TranslatorProxyModel(QObject *parent)
0011     : QSortFilterProxyModel{parent}
0012 {
0013 }
0014 
0015 TranslatorProxyModel::~TranslatorProxyModel() = default;
0016 
0017 bool TranslatorProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
0018 {
0019     if (!mSearchString.isEmpty()) {
0020         const QString source = sourceModel()->index(source_row, TranslatorModel::Source, source_parent).data().toString();
0021         const QString target = sourceModel()->index(source_row, TranslatorModel::Target, source_parent).data().toString();
0022         if (source.contains(mSearchString, Qt::CaseInsensitive) || target.contains(mSearchString, Qt::CaseInsensitive)) {
0023             return true;
0024         }
0025         return false;
0026     }
0027     return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
0028 }
0029 
0030 QString TranslatorProxyModel::searchString() const
0031 {
0032     return mSearchString;
0033 }
0034 
0035 void TranslatorProxyModel::setSearchString(const QString &newSearchString)
0036 {
0037     if (mSearchString != newSearchString) {
0038         mSearchString = newSearchString;
0039         invalidateFilter();
0040     }
0041 }
0042 
0043 #include "moc_translatorproxymodel.cpp"