File indexing completed on 2024-05-12 05:43:32
0001 /* 0002 Copyright (C) 2013-2014 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 #ifndef ELFMODEL_H 0019 #define ELFMODEL_H 0020 0021 #include "elfnodevariant.h" 0022 0023 #include <QAbstractItemModel> 0024 0025 class ElfFileSet; 0026 class ElfSection; 0027 class ElfSymbolTableEntry; 0028 class ElfGotEntry; 0029 class ElfPltEntry; 0030 class DwarfDie; 0031 0032 /** Model for the ELF structure. 0033 * 0034 * Internal pointer is the ElfNodeVariant pointer containing the _parent_ for the node. 0035 */ 0036 class ElfModel : public QAbstractItemModel 0037 { 0038 Q_OBJECT 0039 public: 0040 enum Role { 0041 SizeRole = Qt::UserRole + 1, 0042 DetailRole, 0043 FileRole, 0044 SectionRole, 0045 NodeUrl 0046 }; 0047 0048 explicit ElfModel(QObject* parent = nullptr); 0049 ~ElfModel(); 0050 0051 ElfFileSet* fileSet() const; 0052 void setFileSet(ElfFileSet* fileSet); 0053 0054 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; 0055 int columnCount(const QModelIndex& parent = QModelIndex()) const override; 0056 int rowCount(const QModelIndex& parent = QModelIndex()) const override; 0057 QModelIndex parent(const QModelIndex& child) const override; 0058 QModelIndex index(int row, int column, const QModelIndex& parent) const override; 0059 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 0060 0061 QModelIndex indexForNode(ElfSection* section) const; 0062 QModelIndex indexForNode(ElfSymbolTableEntry* symbol) const; 0063 QModelIndex indexForNode(ElfGotEntry *entry) const; 0064 QModelIndex indexForNode(ElfPltEntry *entry) const; 0065 QModelIndex indexForNode(DwarfDie* die) const; 0066 QModelIndex indexForUrl(const QUrl &url) const; 0067 0068 private: 0069 friend class ParentVisitor; 0070 0071 QModelIndex indexForNode(void* payload, ElfNodeVariant::Type type) const; 0072 0073 void clearInternalPointerMap(); 0074 ElfNodeVariant* variantForIndex(const QModelIndex &index) const; 0075 ElfNodeVariant contentForIndex(const QModelIndex& index) const; 0076 ElfNodeVariant* makeVariant(void* payload, ElfNodeVariant::Type type) const; 0077 0078 QUrl urlForIndex(const QModelIndex &index) const; 0079 0080 private: 0081 ElfFileSet *m_fileSet = nullptr; 0082 mutable QHash<void*, ElfNodeVariant*> m_internalPointerMap; 0083 0084 }; 0085 0086 #endif // ELFMODEL_H