2016-10-26 04:41:42 +00:00
|
|
|
#include "EntryPointModel.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
2016-10-26 07:23:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
EntryPointModel::EntryPointModel(QObject *parent, EntryPoints *points)
|
2016-10-26 04:41:42 +00:00
|
|
|
: QAbstractTableModel(parent)
|
|
|
|
{
|
2016-10-26 07:23:33 +00:00
|
|
|
setEntryPointsData(points);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EntryPointModel::setEntryPointsData(EntryPoints *points)
|
|
|
|
{
|
|
|
|
entryPoints = points;
|
|
|
|
|
|
|
|
if (entryPoints)
|
|
|
|
{
|
|
|
|
connect(entryPoints,SIGNAL(pointAddedAt(int)),SLOT(handlePointAddition(int)));
|
|
|
|
connect(entryPoints,SIGNAL(pointChangedAt(int)),SLOT(handlePointChange(int)));
|
|
|
|
connect(entryPoints,SIGNAL(pointRemovedAt(int)),SLOT(handlePointRemoval(int)));
|
|
|
|
// insertRows(0,entryPoints->numEntryPoints());
|
|
|
|
}
|
|
|
|
|
2016-10-26 04:41:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant EntryPointModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
2016-10-26 07:23:33 +00:00
|
|
|
if (!entryPoints) return QVariant();
|
|
|
|
|
2016-10-26 04:41:42 +00:00
|
|
|
if (orientation == Qt::Horizontal)
|
|
|
|
{
|
|
|
|
if (role == Qt::DisplayRole)
|
|
|
|
{
|
|
|
|
if (section == 0)
|
|
|
|
return "";
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // Orientation == Qt::Vertical
|
|
|
|
{
|
|
|
|
if (role == Qt::DisplayRole)
|
|
|
|
{
|
2016-10-26 07:23:33 +00:00
|
|
|
return "0x"+uint16ToHex(entryPoints->at(section).address);
|
2016-10-26 04:41:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int EntryPointModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(parent);
|
2016-10-26 07:23:33 +00:00
|
|
|
if (!entryPoints) return 0;
|
|
|
|
|
|
|
|
return entryPoints->numEntryPoints();
|
2016-10-26 04:41:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int EntryPointModel::columnCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(parent);
|
2016-10-26 07:23:33 +00:00
|
|
|
return 1;
|
2016-10-26 04:41:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant EntryPointModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
2016-10-26 07:23:33 +00:00
|
|
|
if (!entryPoints) return QVariant();
|
|
|
|
|
2016-10-26 04:41:42 +00:00
|
|
|
if (role == Qt::DisplayRole)
|
|
|
|
{
|
|
|
|
if (index.column() == 0)
|
|
|
|
{
|
2016-10-26 07:23:33 +00:00
|
|
|
return entryPoints->at(index.row()).note;
|
2016-10-26 04:41:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EntryPointModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
|
|
|
{
|
2016-10-26 07:23:33 +00:00
|
|
|
if (!entryPoints) return false;
|
2016-10-26 04:41:42 +00:00
|
|
|
|
|
|
|
if (data(index, role) != value) {
|
|
|
|
if (index.column() == 0)
|
|
|
|
{
|
2016-10-26 07:23:33 +00:00
|
|
|
entryPoints->pointRefAt(index.row()).note = value.toString();
|
2016-10-26 04:41:42 +00:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
2016-10-26 07:23:33 +00:00
|
|
|
if (!entryPoints) return false;
|
|
|
|
|
2016-10-26 04:41:42 +00:00
|
|
|
beginRemoveRows(parent, row, row + count - 1);
|
|
|
|
for (int idx = 0; idx < count; idx++)
|
|
|
|
{
|
2016-10-26 07:23:33 +00:00
|
|
|
entryPoints->removePointAt(row);
|
2016-10-26 04:41:42 +00:00
|
|
|
}
|
|
|
|
endRemoveRows();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|