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 "filelistmodel.h" 0019 0020 #include <elf/elffileset.h> 0021 0022 FileListModel::FileListModel(QObject* parent): QAbstractListModel(parent) 0023 { 0024 } 0025 0026 FileListModel::~FileListModel() = default; 0027 0028 ElfFileSet* FileListModel::fileSet() const 0029 { 0030 return m_fileSet; 0031 } 0032 0033 void FileListModel::setFileSet(ElfFileSet* fileSet) 0034 { 0035 beginResetModel(); 0036 m_fileSet = fileSet; 0037 endResetModel(); 0038 } 0039 0040 QVariant FileListModel::data(const QModelIndex& index, int role) const 0041 { 0042 if (!index.isValid() || !m_fileSet) 0043 return {}; 0044 0045 switch (role) { 0046 case Qt::DisplayRole: 0047 return m_fileSet->file(index.row())->displayName(); 0048 case FileIndexRole: 0049 return index.row(); 0050 case FileRole: 0051 return QVariant::fromValue(m_fileSet->file(index.row())); 0052 } 0053 0054 return {}; 0055 } 0056 0057 int FileListModel::rowCount(const QModelIndex& parent) const 0058 { 0059 if (parent.isValid() || !m_fileSet) 0060 return 0; 0061 return m_fileSet->size(); 0062 } 0063 0064 QVariant FileListModel::headerData(int section, Qt::Orientation orientation, int role) const 0065 { 0066 if (role == Qt::DisplayRole && orientation == Qt::Horizontal) 0067 return tr("Shared Object"); 0068 return QAbstractItemModel::headerData(section, orientation, role); 0069 }