File indexing completed on 2024-05-12 05:43:33

0001 /*
0002     Copyright (C) 2015 Volker Krause <vkrause@kde.org>
0003 
0004     This program is free software; you can redistribute it and/or modify it
0005     under the terms of the GNU Library General Public License as published by
0006     the Free Software Foundation; either version 2 of the License, or (at your
0007     option) any later version.
0008 
0009     This program is distributed in the hope that it will be useful, but WITHOUT
0010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
0012     License for more details.
0013 
0014     You should have received a copy of the GNU General Public License
0015     along with this program.  If not, see <https://www.gnu.org/licenses/>.
0016 */
0017 
0018 #include "sectionproxymodel.h"
0019 #include "elfmodel.h"
0020 
0021 SectionProxyModel::SectionProxyModel(QObject* parent): QSortFilterProxyModel(parent)
0022 {
0023 }
0024 
0025 SectionProxyModel::~SectionProxyModel() = default;
0026 
0027 bool SectionProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
0028 {
0029     const auto sourceIndex = sourceModel()->index(source_row, 0, source_parent);
0030     const auto fileData = sourceModel()->data(sourceIndex, ElfModel::FileRole);
0031     const auto secData = sourceModel()->data(sourceIndex, ElfModel::SectionRole);
0032 
0033     if (fileData.isNull() && secData.isNull()) {
0034         return false;
0035     } else if (QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent)) {
0036         return true;
0037     }
0038     // implement our own recursive filtering,
0039     // code taken from KRecursiveFilterProxyModel::filterAcceptsRow()
0040     bool accepted = false;
0041 
0042     const int numChildren = sourceModel()->rowCount(sourceIndex);
0043     for (int row = 0, rows = numChildren; row < rows; ++row) {
0044         if (filterAcceptsRow(row, sourceIndex)) {
0045             accepted = true;
0046             break;
0047         }
0048     }
0049     return accepted;
0050 }