File indexing completed on 2024-12-22 04:28:24

0001 /*
0002   SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "voskspeechtotextproxymodel.h"
0008 #include "voskspeechtotextmodel.h"
0009 
0010 VoskSpeechToTextProxyModel::VoskSpeechToTextProxyModel(QObject *parent)
0011     : QSortFilterProxyModel{parent}
0012 {
0013 }
0014 
0015 VoskSpeechToTextProxyModel::~VoskSpeechToTextProxyModel() = default;
0016 
0017 bool VoskSpeechToTextProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
0018 {
0019     if (!mSearchString.isEmpty()) {
0020         const QString source = sourceModel()->index(source_row, VoskSpeechToTextModel::LangText, source_parent).data().toString();
0021         if (source.contains(mSearchString, Qt::CaseInsensitive)) {
0022             return true;
0023         }
0024         return false;
0025     }
0026     return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
0027 }
0028 
0029 QString VoskSpeechToTextProxyModel::searchString() const
0030 {
0031     return mSearchString;
0032 }
0033 
0034 void VoskSpeechToTextProxyModel::setSearchString(const QString &newSearchString)
0035 {
0036     if (mSearchString != newSearchString) {
0037         mSearchString = newSearchString;
0038         invalidateFilter();
0039     }
0040 }
0041 
0042 bool VoskSpeechToTextProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
0043 {
0044     if (left.column() == VoskSpeechToTextModel::Size) {
0045         const QModelIndex leftOrder = left.sibling(left.row(), VoskSpeechToTextModel::SizeByte);
0046         const QModelIndex rightOrder = right.sibling(right.row(), VoskSpeechToTextModel::SizeByte);
0047         return leftOrder.data().toLongLong() < rightOrder.data().toLongLong();
0048     }
0049     return QSortFilterProxyModel::lessThan(left, right);
0050 }
0051 
0052 #include "moc_voskspeechtotextproxymodel.cpp"