KTextAddons

translatorproxymodel.cpp
1/*
2 SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "translatorproxymodel.h"
8#include "translatormodel.h"
9
10TranslatorProxyModel::TranslatorProxyModel(QObject *parent)
11 : QSortFilterProxyModel{parent}
12{
13}
14
15TranslatorProxyModel::~TranslatorProxyModel() = default;
16
17bool TranslatorProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
18{
19 if (!mSearchString.isEmpty()) {
20 const QString source = sourceModel()->index(source_row, TranslatorModel::Source, source_parent).data().toString();
21 const QString target = sourceModel()->index(source_row, TranslatorModel::Target, source_parent).data().toString();
22 if (source.contains(mSearchString, Qt::CaseInsensitive) || target.contains(mSearchString, Qt::CaseInsensitive)) {
23 return true;
24 }
25 return false;
26 }
27 return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
28}
29
30QString TranslatorProxyModel::searchString() const
31{
32 return mSearchString;
33}
34
35void TranslatorProxyModel::setSearchString(const QString &newSearchString)
36{
37 if (mSearchString != newSearchString) {
38 mSearchString = newSearchString;
40 }
41}
42
43#include "moc_translatorproxymodel.cpp"
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
QChar * data()
bool isEmpty() const const
CaseInsensitive
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:19:49 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.