KTextAddons

voskspeechtotextproxymodel.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 "voskspeechtotextproxymodel.h"
8#include "voskspeechtotextmodel.h"
9
10VoskSpeechToTextProxyModel::VoskSpeechToTextProxyModel(QObject *parent)
11 : QSortFilterProxyModel{parent}
12{
13}
14
15VoskSpeechToTextProxyModel::~VoskSpeechToTextProxyModel() = default;
16
17bool VoskSpeechToTextProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
18{
19 if (!mSearchString.isEmpty()) {
20 const QString source = sourceModel()->index(source_row, VoskSpeechToTextModel::LangText, source_parent).data().toString();
21 if (source.contains(mSearchString, Qt::CaseInsensitive)) {
22 return true;
23 }
24 return false;
25 }
26 return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
27}
28
29QString VoskSpeechToTextProxyModel::searchString() const
30{
31 return mSearchString;
32}
33
34void VoskSpeechToTextProxyModel::setSearchString(const QString &newSearchString)
35{
36 if (mSearchString != newSearchString) {
37 mSearchString = newSearchString;
39 }
40}
41
42bool VoskSpeechToTextProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
43{
44 if (left.column() == VoskSpeechToTextModel::Size) {
45 const QModelIndex leftOrder = left.sibling(left.row(), VoskSpeechToTextModel::SizeByte);
46 const QModelIndex rightOrder = right.sibling(right.row(), VoskSpeechToTextModel::SizeByte);
47 return leftOrder.data().toLongLong() < rightOrder.data().toLongLong();
48 }
49 return QSortFilterProxyModel::lessThan(left, right);
50}
51
52#include "moc_voskspeechtotextproxymodel.cpp"
QVariant data(int role) const const
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const const
virtual bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
QChar * data()
bool isEmpty() const const
CaseInsensitive
QTextStream & left(QTextStream &stream)
QTextStream & right(QTextStream &stream)
qlonglong toLongLong(bool *ok) const const
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.