File indexing completed on 2025-01-26 03:28:30
0001 /* 0002 SPDX-FileCopyrightText: 2023 Montel Laurent <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "accessibleobjecttreeproxymodel.h" 0008 #include "accessibleobjecttreemodel.h" 0009 0010 AccessibleObjectTreeProxyModel::AccessibleObjectTreeProxyModel(AccessibleObjectTreeModel *model, QObject *parent) 0011 : QSortFilterProxyModel{parent} 0012 , mAccessibleObjectTreeModel(model) 0013 { 0014 setSourceModel(mAccessibleObjectTreeModel); 0015 setFilterCaseSensitivity(Qt::CaseInsensitive); 0016 } 0017 0018 AccessibleObjectTreeProxyModel::~AccessibleObjectTreeProxyModel() = default; 0019 0020 bool AccessibleObjectTreeProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const 0021 { 0022 const QModelIndex modelIndex = sourceModel()->index(source_row, 0, source_parent); 0023 if (modelIndex.isValid() && modelIndex.parent().isValid()) { 0024 return true; 0025 } 0026 0027 if (mShowAllElementWithChildren) { 0028 const bool hasChildren = (modelIndex.data(AccessibleObjectTreeModel::ChildrenCount).toInt() > 0); 0029 if (hasChildren == 0) { 0030 return false; 0031 } 0032 } 0033 0034 auto match = [&](int role) { 0035 if (mFilterString.isEmpty()) { 0036 return true; 0037 }; 0038 const QString str = modelIndex.data(role).toString(); 0039 return str.contains(mFilterString, Qt::CaseInsensitive); 0040 }; 0041 if (!match(AccessibleObjectTreeModel::Accessible)) { 0042 return false; 0043 } 0044 return true; 0045 } 0046 0047 bool AccessibleObjectTreeProxyModel::showAllElementWithChildren() const 0048 { 0049 return mShowAllElementWithChildren; 0050 } 0051 0052 void AccessibleObjectTreeProxyModel::setShowAllElementWithChildren(bool newShowAllElementWithChildren) 0053 { 0054 mShowAllElementWithChildren = newShowAllElementWithChildren; 0055 } 0056 0057 void AccessibleObjectTreeProxyModel::setFilterString(const QString &str) 0058 { 0059 if (mFilterString != str) { 0060 mFilterString = str; 0061 invalidate(); 0062 } 0063 } 0064 0065 #include "moc_accessibleobjecttreeproxymodel.cpp"