2017-09-25 12:55:41 +00:00
|
|
|
#include <QTreeWidget>
|
2017-10-02 16:18:40 +00:00
|
|
|
#include "RelocsWidget.h"
|
|
|
|
#include "ui_RelocsWidget.h"
|
2017-10-01 19:09:42 +00:00
|
|
|
#include "MainWindow.h"
|
|
|
|
#include "utils/Helpers.h"
|
2017-04-13 15:14:02 +00:00
|
|
|
|
2018-03-25 10:57:55 +00:00
|
|
|
RelocsModel::RelocsModel(QList<RelocDescription> *relocs, QObject *parent) :
|
|
|
|
QAbstractTableModel(parent),
|
|
|
|
relocs(relocs)
|
|
|
|
{}
|
|
|
|
|
|
|
|
int RelocsModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
return parent.isValid()? 0 : relocs->count();
|
|
|
|
}
|
|
|
|
|
|
|
|
int RelocsModel::columnCount(const QModelIndex&) const
|
|
|
|
{
|
|
|
|
return COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant RelocsModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
const RelocDescription &reloc = relocs->at(index.row());
|
|
|
|
switch (role)
|
|
|
|
{
|
|
|
|
case AddressRole:
|
|
|
|
return reloc.vaddr;
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
switch (index.column())
|
|
|
|
{
|
|
|
|
case VADDR:
|
|
|
|
return RAddressString(reloc.vaddr);
|
|
|
|
case TYPE:
|
|
|
|
return reloc.type;
|
|
|
|
case NAME:
|
|
|
|
return reloc.name;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant RelocsModel::headerData(int section, Qt::Orientation, int role) const
|
|
|
|
{
|
|
|
|
if(role == Qt::DisplayRole)
|
|
|
|
switch (section)
|
|
|
|
{
|
|
|
|
case VADDR:
|
|
|
|
return tr("Address");
|
|
|
|
case TYPE:
|
|
|
|
return tr("Type");
|
|
|
|
case NAME:
|
|
|
|
return tr("Name");
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RelocsModel::beginReload()
|
|
|
|
{
|
|
|
|
beginResetModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RelocsModel::endReload()
|
|
|
|
{
|
|
|
|
endResetModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-16 21:46:57 +00:00
|
|
|
RelocsWidget::RelocsWidget(MainWindow *main, QAction *action) :
|
|
|
|
CutterDockWidget(main, action),
|
2018-03-25 10:57:55 +00:00
|
|
|
ui(new Ui::RelocsWidget),
|
|
|
|
model(new RelocsModel(&relocs, this))
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2018-03-25 10:57:55 +00:00
|
|
|
ui->relocsTableView->setModel(model);
|
|
|
|
|
2017-04-13 15:14:02 +00:00
|
|
|
setScrollMode();
|
|
|
|
|
2018-03-25 10:57:55 +00:00
|
|
|
connect(Core(), SIGNAL(refreshAll()), this, SLOT(refreshRelocs()));
|
2017-04-13 15:14:02 +00:00
|
|
|
}
|
|
|
|
|
2017-11-19 12:56:10 +00:00
|
|
|
RelocsWidget::~RelocsWidget() {}
|
2017-04-13 15:14:02 +00:00
|
|
|
|
2018-03-25 10:57:55 +00:00
|
|
|
void RelocsWidget::on_relocsTreeView_doubleClicked(const QModelIndex &index)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2018-03-25 10:57:55 +00:00
|
|
|
Core()->seek(index.data(RelocsModel::AddressRole).toLongLong());
|
2017-04-13 15:14:02 +00:00
|
|
|
}
|
|
|
|
|
2018-03-25 10:57:55 +00:00
|
|
|
void RelocsWidget::refreshRelocs()
|
2017-04-13 15:14:02 +00:00
|
|
|
{
|
2018-03-25 10:57:55 +00:00
|
|
|
model->beginReload();
|
|
|
|
relocs = Core()->getAllRelocs();
|
|
|
|
model->endReload();
|
|
|
|
ui->relocsTableView->resizeColumnsToContents();
|
2017-04-13 15:14:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RelocsWidget::setScrollMode()
|
|
|
|
{
|
2018-03-25 10:57:55 +00:00
|
|
|
qhelpers::setVerticalScrollMode(ui->relocsTableView);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|