2017-10-02 16:18:40 +00:00
|
|
|
#include "ExportsWidget.h"
|
|
|
|
#include "ui_ExportsWidget.h"
|
2017-10-01 19:09:42 +00:00
|
|
|
#include "MainWindow.h"
|
|
|
|
#include "utils/Helpers.h"
|
2017-05-19 07:45:26 +00:00
|
|
|
|
|
|
|
ExportsModel::ExportsModel(QList<ExportDescription> *exports, QObject *parent)
|
2017-06-03 12:27:23 +00:00
|
|
|
: QAbstractListModel(parent),
|
|
|
|
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
|
|
|
|
{
|
|
|
|
return Columns::COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
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()) {
|
2017-06-03 12:27:23 +00:00
|
|
|
case OFFSET:
|
|
|
|
return RAddressString(exp.vaddr);
|
|
|
|
case SIZE:
|
|
|
|
return RSizeString(exp.size);
|
|
|
|
case TYPE:
|
|
|
|
return exp.type;
|
|
|
|
case NAME:
|
|
|
|
return exp.name;
|
2017-05-19 07:45:26 +00:00
|
|
|
default:
|
|
|
|
return QVariant();
|
2017-06-03 12:27:23 +00:00
|
|
|
}
|
|
|
|
case ExportDescriptionRole:
|
|
|
|
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) {
|
2017-06-03 12:27:23 +00:00
|
|
|
case OFFSET:
|
|
|
|
return tr("Address");
|
|
|
|
case SIZE:
|
|
|
|
return tr("Size");
|
|
|
|
case TYPE:
|
|
|
|
return tr("Type");
|
|
|
|
case NAME:
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExportsModel::beginReloadExports()
|
|
|
|
{
|
|
|
|
beginResetModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExportsModel::endReloadExports()
|
|
|
|
{
|
|
|
|
endResetModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
ExportsSortFilterProxyModel::ExportsSortFilterProxyModel(ExportsModel *source_model,
|
|
|
|
QObject *parent)
|
2017-06-03 12:27:23 +00:00
|
|
|
: QSortFilterProxyModel(parent)
|
2017-05-19 07:45:26 +00:00
|
|
|
{
|
|
|
|
setSourceModel(source_model);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ExportsSortFilterProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
QModelIndex index = sourceModel()->index(row, 0, parent);
|
|
|
|
ExportDescription exp = index.data(ExportsModel::ExportDescriptionRole).value<ExportDescription>();
|
|
|
|
return exp.name.contains(filterRegExp());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ExportsSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
ExportDescription left_exp = left.data(
|
|
|
|
ExportsModel::ExportDescriptionRole).value<ExportDescription>();
|
|
|
|
ExportDescription right_exp = 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()) {
|
2017-06-03 12:27:23 +00:00
|
|
|
case ExportsModel::SIZE:
|
|
|
|
if (left_exp.size != right_exp.size)
|
|
|
|
return left_exp.size < right_exp.size;
|
|
|
|
// fallthrough
|
|
|
|
case ExportsModel::OFFSET:
|
|
|
|
if (left_exp.vaddr != right_exp.vaddr)
|
|
|
|
return left_exp.vaddr < right_exp.vaddr;
|
|
|
|
// fallthrough
|
|
|
|
case ExportsModel::NAME:
|
|
|
|
return left_exp.name < right_exp.name;
|
|
|
|
case ExportsModel::TYPE:
|
|
|
|
if (left_exp.type != right_exp.type)
|
|
|
|
return left_exp.type < right_exp.type;
|
|
|
|
default:
|
|
|
|
break;
|
2017-05-19 07:45:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// fallback
|
|
|
|
return left_exp.vaddr < right_exp.vaddr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-16 21:46:57 +00:00
|
|
|
ExportsWidget::ExportsWidget(MainWindow *main, QAction *action) :
|
|
|
|
CutterDockWidget(main, action),
|
|
|
|
ui(new Ui::ExportsWidget)
|
2017-05-19 07:45:26 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
exports_model = new ExportsModel(&exports, this);
|
|
|
|
exports_proxy_model = new ExportsSortFilterProxyModel(exports_model, this);
|
|
|
|
ui->exportsTreeView->setModel(exports_proxy_model);
|
|
|
|
ui->exportsTreeView->sortByColumn(ExportsModel::OFFSET, Qt::AscendingOrder);
|
|
|
|
|
|
|
|
setScrollMode();
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
exports_model->beginReloadExports();
|
2017-10-09 18:08:35 +00:00
|
|
|
exports = CutterCore::getInstance()->getAllExports();
|
2017-05-19 07:45:26 +00:00
|
|
|
exports_model->endReloadExports();
|
|
|
|
|
2018-04-01 08:25:31 +00:00
|
|
|
qhelpers::adjustColumns(ui->exportsTreeView, 3, 0);
|
2017-05-19 07:45:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ExportsWidget::setScrollMode()
|
|
|
|
{
|
|
|
|
qhelpers::setVerticalScrollMode(ui->exportsTreeView);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExportsWidget::on_exportsTreeView_doubleClicked(const QModelIndex &index)
|
|
|
|
{
|
|
|
|
ExportDescription exp = index.data(ExportsModel::ExportDescriptionRole).value<ExportDescription>();
|
2017-10-09 18:08:35 +00:00
|
|
|
CutterCore::getInstance()->seek(exp.vaddr);
|
2017-05-19 07:45:26 +00:00
|
|
|
}
|