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

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 "usedsymbolmodel.h"
0019 
0020 #include <elf/elffile.h>
0021 #include <elf/elfsymboltableentry.h>
0022 #include <elf/elfsymboltablesection.h>
0023 #include <elf/elfhashsection.h>
0024 
0025 #include <demangle/demangler.h>
0026 #include <checks/dependenciescheck.h>
0027 
0028 #include <cassert>
0029 
0030 UsedSymbolModel::UsedSymbolModel(QObject* parent): QAbstractListModel(parent)
0031 {
0032 }
0033 
0034 UsedSymbolModel::~UsedSymbolModel() = default;
0035 
0036 void UsedSymbolModel::setFiles(ElfFile* user, ElfFile* provider)
0037 {
0038     beginResetModel();
0039     const auto l = [](UsedSymbolModel* m) { m->endResetModel(); };
0040     const auto endReset = std::unique_ptr<UsedSymbolModel, decltype(l)>(this, l);
0041 
0042     m_entries.clear();
0043     if (!user || !provider)
0044         return;
0045 
0046     m_entries = DependenciesCheck::usedSymbols(user, provider);
0047 }
0048 
0049 QVariant UsedSymbolModel::data(const QModelIndex& index, int role) const
0050 {
0051     if (!index.isValid())
0052         return {};
0053 
0054     switch (role) {
0055         case Qt::DisplayRole:
0056             return Demangler::demangleFull(m_entries.at(index.row())->name());
0057             break;
0058     }
0059 
0060     return {};
0061 }
0062 
0063 int UsedSymbolModel::rowCount(const QModelIndex& parent) const
0064 {
0065     if (parent.isValid())
0066         return 0;
0067     return m_entries.size();
0068 }
0069 
0070 QVariant UsedSymbolModel::headerData(int section, Qt::Orientation orientation, int role) const
0071 {
0072     if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
0073         switch (section) {
0074             case 0:
0075                 return tr("Symbol");
0076         }
0077     }
0078     return QAbstractItemModel::headerData(section, orientation, role);
0079 }