2017-10-02 16:18:40 +00:00
|
|
|
#include "ExportsWidget.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"
|
2018-10-16 06:25:09 +00:00
|
|
|
#include "WidgetShortcuts.h"
|
|
|
|
|
2019-03-14 09:28:42 +00:00
|
|
|
#include <QShortcut>
|
|
|
|
|
2017-05-19 07:45:26 +00:00
|
|
|
ExportsModel::ExportsModel(QList<ExportDescription> *exports, QObject *parent)
|
2019-08-19 13:35:25 +00:00
|
|
|
: AddressableItemModel<QAbstractListModel>(parent),
|
2017-06-03 12:27:23 +00:00
|
|
|
exports(exports)
|
2017-05-19 07:45:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int ExportsModel::rowCount(const QModelIndex &) const
|
|
|
|
{
|
|
|
|
return exports->count();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ExportsModel::columnCount(const QModelIndex &) const
|
|
|
|
{
|
2018-04-23 07:53:35 +00:00
|
|
|
return ExportsModel::ColumnCount;
|
2017-05-19 07:45:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ExportsModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
2017-06-03 12:27:23 +00:00
|
|
|
if (index.row() >= exports->count())
|
2017-05-19 07:45:26 +00:00
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
const ExportDescription &exp = exports->at(index.row());
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
switch (role) {
|
2017-06-03 12:27:23 +00:00
|
|
|
case Qt::DisplayRole:
|
2018-03-21 20:32:32 +00:00
|
|
|
switch (index.column()) {
|
2018-04-23 07:53:35 +00:00
|
|
|
case ExportsModel::OffsetColumn:
|
2017-06-03 12:27:23 +00:00
|
|
|
return RAddressString(exp.vaddr);
|
2018-04-23 07:53:35 +00:00
|
|
|
case ExportsModel::SizeColumn:
|
2017-06-03 12:27:23 +00:00
|
|
|
return RSizeString(exp.size);
|
2018-04-23 07:53:35 +00:00
|
|
|
case ExportsModel::TypeColumn:
|
2017-06-03 12:27:23 +00:00
|
|
|
return exp.type;
|
2018-04-23 07:53:35 +00:00
|
|
|
case ExportsModel::NameColumn:
|
2017-06-03 12:27:23 +00:00
|
|
|
return exp.name;
|
2017-05-19 07:45:26 +00:00
|
|
|
default:
|
|
|
|
return QVariant();
|
2017-06-03 12:27:23 +00:00
|
|
|
}
|
2018-04-23 07:53:35 +00:00
|
|
|
case ExportsModel::ExportDescriptionRole:
|
2017-06-03 12:27:23 +00:00
|
|
|
return QVariant::fromValue(exp);
|
|
|
|
default:
|
|
|
|
return QVariant();
|
2017-05-19 07:45:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ExportsModel::headerData(int section, Qt::Orientation, int role) const
|
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
switch (role) {
|
2017-06-03 12:27:23 +00:00
|
|
|
case Qt::DisplayRole:
|
2018-03-21 20:32:32 +00:00
|
|
|
switch (section) {
|
2018-04-23 07:53:35 +00:00
|
|
|
case ExportsModel::OffsetColumn:
|
2017-06-03 12:27:23 +00:00
|
|
|
return tr("Address");
|
2018-04-23 07:53:35 +00:00
|
|
|
case ExportsModel::SizeColumn:
|
2017-06-03 12:27:23 +00:00
|
|
|
return tr("Size");
|
2018-04-23 07:53:35 +00:00
|
|
|
case ExportsModel::TypeColumn:
|
2017-06-03 12:27:23 +00:00
|
|
|
return tr("Type");
|
2018-04-23 07:53:35 +00:00
|
|
|
case ExportsModel::NameColumn:
|
2017-06-03 12:27:23 +00:00
|
|
|
return tr("Name");
|
2017-05-19 07:45:26 +00:00
|
|
|
default:
|
|
|
|
return QVariant();
|
2017-06-03 12:27:23 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
return QVariant();
|
2017-05-19 07:45:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-19 13:35:25 +00:00
|
|
|
RVA ExportsModel::address(const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
const ExportDescription &exp = exports->at(index.row());
|
|
|
|
return exp.vaddr;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ExportsModel::name(const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
const ExportDescription &exp = exports->at(index.row());
|
|
|
|
return exp.name;
|
|
|
|
}
|
|
|
|
|
2018-04-24 18:40:40 +00:00
|
|
|
ExportsProxyModel::ExportsProxyModel(ExportsModel *source_model, QObject *parent)
|
2019-08-19 13:35:25 +00:00
|
|
|
: AddressableFilterProxyModel(source_model, parent)
|
2017-05-19 07:45:26 +00:00
|
|
|
{
|
2018-04-23 07:53:35 +00:00
|
|
|
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
|
|
|
setSortCaseSensitivity(Qt::CaseInsensitive);
|
2017-05-19 07:45:26 +00:00
|
|
|
}
|
|
|
|
|
2018-04-24 18:40:40 +00:00
|
|
|
bool ExportsProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) const
|
2017-05-19 07:45:26 +00:00
|
|
|
{
|
|
|
|
QModelIndex index = sourceModel()->index(row, 0, parent);
|
2018-04-24 18:40:40 +00:00
|
|
|
auto exp = index.data(ExportsModel::ExportDescriptionRole).value<ExportDescription>();
|
|
|
|
|
2017-05-19 07:45:26 +00:00
|
|
|
return exp.name.contains(filterRegExp());
|
|
|
|
}
|
|
|
|
|
2018-04-24 18:40:40 +00:00
|
|
|
bool ExportsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
2017-05-19 07:45:26 +00:00
|
|
|
{
|
2018-04-24 18:40:40 +00:00
|
|
|
auto leftExp = left.data(ExportsModel::ExportDescriptionRole).value<ExportDescription>();
|
|
|
|
auto rightExp = right.data(ExportsModel::ExportDescriptionRole).value<ExportDescription>();
|
2017-05-19 07:45:26 +00:00
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
switch (left.column()) {
|
2018-04-23 07:53:35 +00:00
|
|
|
case ExportsModel::SizeColumn:
|
2018-04-24 18:40:40 +00:00
|
|
|
if (leftExp.size != rightExp.size)
|
|
|
|
return leftExp.size < rightExp.size;
|
2017-06-03 12:27:23 +00:00
|
|
|
// fallthrough
|
2018-04-23 07:53:35 +00:00
|
|
|
case ExportsModel::OffsetColumn:
|
2018-04-24 18:40:40 +00:00
|
|
|
if (leftExp.vaddr != rightExp.vaddr)
|
|
|
|
return leftExp.vaddr < rightExp.vaddr;
|
2017-06-03 12:27:23 +00:00
|
|
|
// fallthrough
|
2018-04-23 07:53:35 +00:00
|
|
|
case ExportsModel::NameColumn:
|
2018-04-24 18:40:40 +00:00
|
|
|
return leftExp.name < rightExp.name;
|
2018-04-23 07:53:35 +00:00
|
|
|
case ExportsModel::TypeColumn:
|
2018-04-24 18:40:40 +00:00
|
|
|
if (leftExp.type != rightExp.type)
|
|
|
|
return leftExp.type < rightExp.type;
|
2017-06-03 12:27:23 +00:00
|
|
|
default:
|
|
|
|
break;
|
2017-05-19 07:45:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// fallback
|
2018-04-24 18:40:40 +00:00
|
|
|
return leftExp.vaddr < rightExp.vaddr;
|
2017-05-19 07:45:26 +00:00
|
|
|
}
|
|
|
|
|
2018-03-16 21:46:57 +00:00
|
|
|
ExportsWidget::ExportsWidget(MainWindow *main, QAction *action) :
|
2019-08-19 13:35:25 +00:00
|
|
|
ListDockWidget(main, action)
|
2017-05-19 07:45:26 +00:00
|
|
|
{
|
2019-08-19 13:35:25 +00:00
|
|
|
setWindowTitle(tr("Exports"));
|
|
|
|
setObjectName("ExportsWidget");
|
2017-05-19 07:45:26 +00:00
|
|
|
|
2018-04-23 07:53:35 +00:00
|
|
|
exportsModel = new ExportsModel(&exports, this);
|
2018-04-24 18:40:40 +00:00
|
|
|
exportsProxyModel = new ExportsProxyModel(exportsModel, this);
|
2019-08-19 13:35:25 +00:00
|
|
|
setModels(exportsProxyModel);
|
|
|
|
ui->treeView->sortByColumn(ExportsModel::OffsetColumn, Qt::AscendingOrder);
|
2018-04-23 07:53:35 +00:00
|
|
|
|
2018-10-16 06:25:09 +00:00
|
|
|
QShortcut *toggle_shortcut = new QShortcut(widgetShortcuts["ExportsWidget"], main);
|
|
|
|
connect(toggle_shortcut, &QShortcut::activated, this, [=] (){
|
|
|
|
toggleDockWidget(true);
|
|
|
|
main->updateDockActionChecked(action);
|
|
|
|
} );
|
|
|
|
|
2017-11-19 12:56:10 +00:00
|
|
|
connect(Core(), SIGNAL(refreshAll()), this, SLOT(refreshExports()));
|
2017-05-19 07:45:26 +00:00
|
|
|
}
|
|
|
|
|
2017-11-19 12:56:10 +00:00
|
|
|
ExportsWidget::~ExportsWidget() {}
|
2017-05-19 07:45:26 +00:00
|
|
|
|
|
|
|
void ExportsWidget::refreshExports()
|
|
|
|
{
|
2018-10-10 11:33:55 +00:00
|
|
|
exportsModel->beginResetModel();
|
2018-04-12 06:33:30 +00:00
|
|
|
exports = Core()->getAllExports();
|
2018-10-10 11:33:55 +00:00
|
|
|
exportsModel->endResetModel();
|
2017-05-19 07:45:26 +00:00
|
|
|
|
2019-08-19 13:35:25 +00:00
|
|
|
qhelpers::adjustColumns(ui->treeView, 3, 0);
|
2017-05-19 07:45:26 +00:00
|
|
|
}
|