2017-10-02 16:18:40 +00:00
|
|
|
#include "RelocsWidget.h"
|
2019-08-19 13:35:25 +00:00
|
|
|
#include "ui_ListDockWidget.h"
|
2019-02-22 16:50:45 +00:00
|
|
|
#include "core/MainWindow.h"
|
2018-10-17 07:55:53 +00:00
|
|
|
#include "common/Helpers.h"
|
2017-04-13 15:14:02 +00:00
|
|
|
|
2019-03-14 09:28:42 +00:00
|
|
|
#include <QShortcut>
|
|
|
|
#include <QTreeWidget>
|
|
|
|
|
2018-03-25 10:57:55 +00:00
|
|
|
RelocsModel::RelocsModel(QList<RelocDescription> *relocs, QObject *parent) :
|
2019-08-19 13:35:25 +00:00
|
|
|
AddressableItemModel<QAbstractTableModel>(parent),
|
2018-03-25 10:57:55 +00:00
|
|
|
relocs(relocs)
|
|
|
|
{}
|
|
|
|
|
|
|
|
int RelocsModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
2018-04-24 18:40:40 +00:00
|
|
|
return parent.isValid() ? 0 : relocs->count();
|
2018-03-25 10:57:55 +00:00
|
|
|
}
|
|
|
|
|
2018-09-30 20:00:53 +00:00
|
|
|
int RelocsModel::columnCount(const QModelIndex &) const
|
2018-03-25 10:57:55 +00:00
|
|
|
{
|
2018-04-24 18:40:40 +00:00
|
|
|
return RelocsModel::ColumnCount;
|
2018-03-25 10:57:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant RelocsModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
const RelocDescription &reloc = relocs->at(index.row());
|
2018-09-30 20:00:53 +00:00
|
|
|
switch (role) {
|
2018-03-25 10:57:55 +00:00
|
|
|
case Qt::DisplayRole:
|
2018-09-30 20:00:53 +00:00
|
|
|
switch (index.column()) {
|
2018-04-24 18:40:40 +00:00
|
|
|
case RelocsModel::VAddrColumn:
|
2018-03-25 10:57:55 +00:00
|
|
|
return RAddressString(reloc.vaddr);
|
2018-04-24 18:40:40 +00:00
|
|
|
case RelocsModel::TypeColumn:
|
2018-03-25 10:57:55 +00:00
|
|
|
return reloc.type;
|
2018-04-24 18:40:40 +00:00
|
|
|
case RelocsModel::NameColumn:
|
2018-03-25 10:57:55 +00:00
|
|
|
return reloc.name;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-06-26 16:17:03 +00:00
|
|
|
break;
|
2018-04-24 18:40:40 +00:00
|
|
|
case RelocsModel::RelocDescriptionRole:
|
|
|
|
return QVariant::fromValue(reloc);
|
|
|
|
case RelocsModel::AddressRole:
|
|
|
|
return reloc.vaddr;
|
2018-03-25 10:57:55 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant RelocsModel::headerData(int section, Qt::Orientation, int role) const
|
|
|
|
{
|
2018-04-24 18:40:40 +00:00
|
|
|
if (role == Qt::DisplayRole)
|
2018-09-30 20:00:53 +00:00
|
|
|
switch (section) {
|
2018-04-24 18:40:40 +00:00
|
|
|
case RelocsModel::VAddrColumn:
|
2018-03-25 10:57:55 +00:00
|
|
|
return tr("Address");
|
2018-04-24 18:40:40 +00:00
|
|
|
case RelocsModel::TypeColumn:
|
2018-03-25 10:57:55 +00:00
|
|
|
return tr("Type");
|
2018-04-24 18:40:40 +00:00
|
|
|
case RelocsModel::NameColumn:
|
2018-03-25 10:57:55 +00:00
|
|
|
return tr("Name");
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
2019-08-19 13:35:25 +00:00
|
|
|
RVA RelocsModel::address(const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
const RelocDescription &reloc = relocs->at(index.row());
|
|
|
|
return reloc.vaddr;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString RelocsModel::name(const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
const RelocDescription &reloc = relocs->at(index.row());
|
|
|
|
return reloc.name;
|
|
|
|
}
|
|
|
|
|
2018-04-24 18:40:40 +00:00
|
|
|
RelocsProxyModel::RelocsProxyModel(RelocsModel *sourceModel, QObject *parent)
|
2019-08-19 13:35:25 +00:00
|
|
|
: AddressableFilterProxyModel(sourceModel, parent)
|
2018-04-24 18:40:40 +00:00
|
|
|
{
|
|
|
|
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
|
|
|
setSortCaseSensitivity(Qt::CaseInsensitive);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RelocsProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
QModelIndex index = sourceModel()->index(row, 0, parent);
|
|
|
|
auto reloc = index.data(RelocsModel::RelocDescriptionRole).value<RelocDescription>();
|
|
|
|
|
|
|
|
return reloc.name.contains(filterRegExp());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RelocsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
|
|
|
{
|
|
|
|
if (!left.isValid() || !right.isValid())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (left.parent().isValid() || right.parent().isValid())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto leftReloc = left.data(RelocsModel::RelocDescriptionRole).value<RelocDescription>();
|
|
|
|
auto rightReloc = right.data(RelocsModel::RelocDescriptionRole).value<RelocDescription>();
|
|
|
|
|
|
|
|
switch (left.column()) {
|
|
|
|
case RelocsModel::VAddrColumn:
|
|
|
|
return leftReloc.vaddr < rightReloc.vaddr;
|
|
|
|
case RelocsModel::TypeColumn:
|
|
|
|
return leftReloc.type < rightReloc.type;
|
|
|
|
case RelocsModel::NameColumn:
|
|
|
|
return leftReloc.name < rightReloc.name;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2018-03-25 10:57:55 +00:00
|
|
|
|
2018-03-16 21:46:57 +00:00
|
|
|
RelocsWidget::RelocsWidget(MainWindow *main, QAction *action) :
|
2019-08-19 13:35:25 +00:00
|
|
|
ListDockWidget(main, action),
|
2018-04-24 18:40:40 +00:00
|
|
|
relocsModel(new RelocsModel(&relocs, this)),
|
2019-08-19 13:35:25 +00:00
|
|
|
relocsProxyModel(new RelocsProxyModel(relocsModel, this))
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2019-08-19 13:35:25 +00:00
|
|
|
setWindowTitle(tr("Relocs"));
|
|
|
|
setObjectName("RelocsWidget");
|
2018-04-24 18:40:40 +00:00
|
|
|
|
2019-08-19 13:35:25 +00:00
|
|
|
setModels(relocsProxyModel);
|
|
|
|
ui->treeView->sortByColumn(RelocsModel::NameColumn, Qt::AscendingOrder);
|
2018-04-24 18:40:40 +00:00
|
|
|
|
2019-12-11 22:18:40 +00:00
|
|
|
connect(Core(), &CutterCore::codeRebased, this, &RelocsWidget::refreshRelocs);
|
2019-08-19 13:35:25 +00:00
|
|
|
connect(Core(), &CutterCore::refreshAll, this, &RelocsWidget::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::refreshRelocs()
|
2017-04-13 15:14:02 +00:00
|
|
|
{
|
2018-10-10 11:33:55 +00:00
|
|
|
relocsModel->beginResetModel();
|
2018-03-25 10:57:55 +00:00
|
|
|
relocs = Core()->getAllRelocs();
|
2018-10-10 11:33:55 +00:00
|
|
|
relocsModel->endResetModel();
|
2019-08-19 13:35:25 +00:00
|
|
|
qhelpers::adjustColumns(ui->treeView, 3, 0);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|