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 "issuesmodel.h"
0019 
0020 #include <memory>
0021 
0022 IssuesModel::IssuesModel(QObject* parent): QAbstractTableModel(parent)
0023 {
0024 }
0025 
0026 IssuesModel::~IssuesModel() = default;
0027 
0028 void IssuesModel::setFileSet(ElfFileSet* fileSet)
0029 {
0030     beginResetModel();
0031     const auto l = [](decltype(this) m) { m->endResetModel(); };
0032     const auto endReset = std::unique_ptr<IssuesModel, decltype(l)>(this, l);
0033 
0034     m_fileSet = fileSet;
0035     m_checker.clear();
0036 }
0037 
0038 void IssuesModel::runChecks()
0039 {
0040     if (!m_checker.results().isEmpty())
0041         return;
0042 
0043     beginResetModel();
0044     const auto l = [](decltype(this) m) { m->endResetModel(); };
0045     const auto endReset = std::unique_ptr<IssuesModel, decltype(l)>(this, l);
0046 
0047     if (m_fileSet)
0048         m_checker.findImplicitVirtualDtors(m_fileSet);
0049 }
0050 
0051 QVariant IssuesModel::data(const QModelIndex& index, int role) const
0052 {
0053     if (!index.isValid())
0054         return {};
0055 
0056     const auto res = m_checker.results().at(index.row());
0057     switch (role) {
0058         case Qt::DisplayRole:
0059         {
0060             switch (index.column()) {
0061                 case 0: return tr("%1 (implicit virtual destructor)").arg(QString::fromLatin1(res.fullName));
0062                 case 1: return res.sourceFilePath + QLatin1Char(':') + QString::number(res.lineNumber);
0063             }
0064         }
0065     }
0066 
0067     return {};
0068 }
0069 
0070 int IssuesModel::columnCount(const QModelIndex& parent) const
0071 {
0072     Q_UNUSED(parent);
0073     return 2;
0074 }
0075 
0076 int IssuesModel::rowCount(const QModelIndex& parent) const
0077 {
0078     if (parent.isValid())
0079         return 0;
0080     return m_checker.results().size();
0081 }
0082 
0083 QVariant IssuesModel::headerData(int section, Qt::Orientation orientation, int role) const
0084 {
0085     if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
0086         switch (section) {
0087             case 0: return tr("Issue");
0088             case 1: return tr("Location");
0089         }
0090     }
0091     return QAbstractTableModel::headerData(section, orientation, role);
0092 }