AppleSAWS/src/binaryfile/entrypointmodel.cpp

153 lines
4.5 KiB
C++

/*****************************************************************************
* AppleSAWS - The Apple Software Analysis WorkShop *
* Copyright (C) 2015-2021 Mark D. Long *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
*****************************************************************************/
#include "entrypointmodel.h"
#include "util.h"
#include <QDebug>
EntryPointModel::EntryPointModel(QObject *parent, EntryPoints *points)
: QAbstractTableModel(parent)
{
setEntryPointsData(points);
}
void EntryPointModel::setEntryPointsData(EntryPoints *points)
{
entryPoints = points;
if (entryPoints)
{
connect(entryPoints, &EntryPoints::pointAddedAt, this, &EntryPointModel::handlePointAddition);
connect(entryPoints, &EntryPoints::pointChangedAt, this, &EntryPointModel::handlePointChange);
}
}
QVariant EntryPointModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (!entryPoints) return QVariant();
if (orientation == Qt::Horizontal)
{
if (role == Qt::DisplayRole)
{
if (section == 0)
return "";
}
}
else // Orientation == Qt::Vertical
{
if (role == Qt::DisplayRole)
{
return "0x"+uint16ToHex(entryPoints->at(section).address);
}
}
return QVariant();
}
int EntryPointModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
if (!entryPoints) return 0;
return entryPoints->numEntryPoints();
}
int EntryPointModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return 1;
}
QVariant EntryPointModel::data(const QModelIndex &index, int role) const
{
if (!entryPoints) return QVariant();
if (role == Qt::DisplayRole)
{
if (index.column() == 0)
{
return entryPoints->at(index.row()).note;
}
}
return QVariant();
}
bool EntryPointModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!entryPoints) return false;
if (data(index, role) != value) {
if (index.column() == 0)
{
entryPoints->pointRefAt(index.row()).note = value.toString();
}
emit dataChanged(index, index, QVector<int>() << role);
return true;
}
return false;
}
Qt::ItemFlags EntryPointModel::flags(const QModelIndex &index) const
{
Q_UNUSED(index);
if (index.column() == 0)
return Qt::ItemIsEditable | QAbstractTableModel::flags(index);
else
return QAbstractTableModel::flags(index);
}
bool EntryPointModel::insertRows(int row, int count, const QModelIndex &parent)
{
beginInsertRows(parent, row, row + count - 1);
endInsertRows();
return false;
}
bool EntryPointModel::removeRows(int row, int count, const QModelIndex &parent)
{
qDebug() << __FILE__ << __LINE__;
if (!entryPoints) return false;
qDebug() << __FILE__ << __LINE__;
bool success = false;
qDebug() << __FILE__ << __LINE__;
beginRemoveRows(parent, row, row + count - 1);
qDebug() << __FILE__ << __LINE__;
for (int idx = 0; idx < count; idx++)
{
qDebug() << __FILE__ << __LINE__;
entryPoints->removePointAt(row);
qDebug() << __FILE__ << __LINE__;
success = true;
}
qDebug() << __FILE__ << __LINE__;
endRemoveRows();
qDebug() << __FILE__ << __LINE__;
return success;
}