2018-05-21 17:34:41 +00:00
|
|
|
#include "HeadersWidget.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-05-21 17:34:41 +00:00
|
|
|
|
|
|
|
HeadersModel::HeadersModel(QList<HeaderDescription> *headers, QObject *parent)
|
2019-08-19 13:35:25 +00:00
|
|
|
: AddressableItemModel<QAbstractListModel>(parent),
|
2018-05-21 17:34:41 +00:00
|
|
|
headers(headers)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int HeadersModel::rowCount(const QModelIndex &) const
|
|
|
|
{
|
|
|
|
return headers->count();
|
|
|
|
}
|
|
|
|
|
|
|
|
int HeadersModel::columnCount(const QModelIndex &) const
|
|
|
|
{
|
|
|
|
return HeadersModel::ColumnCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant HeadersModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
if (index.row() >= headers->count())
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
const HeaderDescription &header = headers->at(index.row());
|
|
|
|
|
|
|
|
switch (role) {
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
switch (index.column()) {
|
|
|
|
case OffsetColumn:
|
|
|
|
return RAddressString(header.vaddr);
|
|
|
|
case NameColumn:
|
|
|
|
return header.name;
|
|
|
|
case ValueColumn:
|
|
|
|
return header.value;
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
case HeaderDescriptionRole:
|
|
|
|
return QVariant::fromValue(header);
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant HeadersModel::headerData(int section, Qt::Orientation, int role) const
|
|
|
|
{
|
|
|
|
switch (role) {
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
switch (section) {
|
|
|
|
case OffsetColumn:
|
|
|
|
return tr("Offset");
|
|
|
|
case NameColumn:
|
|
|
|
return tr("Name");
|
|
|
|
case ValueColumn:
|
|
|
|
return tr("Value");
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-19 13:35:25 +00:00
|
|
|
RVA HeadersModel::address(const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
const HeaderDescription &header = headers->at(index.row());
|
|
|
|
return header.vaddr;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString HeadersModel::name(const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
const HeaderDescription &header = headers->at(index.row());
|
|
|
|
return header.name;
|
|
|
|
}
|
|
|
|
|
2018-05-21 17:34:41 +00:00
|
|
|
HeadersProxyModel::HeadersProxyModel(HeadersModel *sourceModel, QObject *parent)
|
2019-08-19 13:35:25 +00:00
|
|
|
: AddressableFilterProxyModel(sourceModel, parent)
|
2018-05-21 17:34:41 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HeadersProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
QModelIndex index = sourceModel()->index(row, 0, parent);
|
|
|
|
HeaderDescription item = index.data(HeadersModel::HeaderDescriptionRole).value<HeaderDescription>();
|
|
|
|
return item.name.contains(filterRegExp());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HeadersProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
|
|
|
{
|
2018-09-30 20:00:53 +00:00
|
|
|
HeaderDescription leftHeader = left.data(
|
|
|
|
HeadersModel::HeaderDescriptionRole).value<HeaderDescription>();
|
|
|
|
HeaderDescription rightHeader = right.data(
|
|
|
|
HeadersModel::HeaderDescriptionRole).value<HeaderDescription>();
|
2018-05-21 17:34:41 +00:00
|
|
|
|
|
|
|
switch (left.column()) {
|
|
|
|
case HeadersModel::OffsetColumn:
|
|
|
|
return leftHeader.vaddr < rightHeader.vaddr;
|
|
|
|
case HeadersModel::NameColumn:
|
|
|
|
return leftHeader.name < rightHeader.name;
|
|
|
|
case HeadersModel::ValueColumn:
|
|
|
|
return leftHeader.value < rightHeader.value;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return leftHeader.vaddr < rightHeader.vaddr;
|
|
|
|
}
|
|
|
|
|
|
|
|
HeadersWidget::HeadersWidget(MainWindow *main, QAction *action) :
|
2019-08-19 13:35:25 +00:00
|
|
|
ListDockWidget(main, action)
|
2018-05-21 17:34:41 +00:00
|
|
|
{
|
2019-08-19 13:35:25 +00:00
|
|
|
setWindowTitle(tr("Headers"));
|
|
|
|
setObjectName("HeadersWidget");
|
2018-05-21 17:34:41 +00:00
|
|
|
|
|
|
|
headersModel = new HeadersModel(&headers, this);
|
|
|
|
headersProxyModel = new HeadersProxyModel(headersModel, this);
|
2019-08-19 13:35:25 +00:00
|
|
|
setModels(headersProxyModel);
|
|
|
|
ui->treeView->sortByColumn(HeadersModel::OffsetColumn, Qt::AscendingOrder);
|
2018-05-21 17:34:41 +00:00
|
|
|
|
2019-08-19 13:35:25 +00:00
|
|
|
ui->quickFilterView->closeFilter();
|
|
|
|
showCount(false);
|
2018-05-21 17:34:41 +00:00
|
|
|
|
|
|
|
connect(Core(), &CutterCore::refreshAll, this, &HeadersWidget::refreshHeaders);
|
|
|
|
}
|
|
|
|
|
|
|
|
HeadersWidget::~HeadersWidget() {}
|
|
|
|
|
|
|
|
void HeadersWidget::refreshHeaders()
|
|
|
|
{
|
2018-10-10 11:33:55 +00:00
|
|
|
headersModel->beginResetModel();
|
2018-05-21 17:34:41 +00:00
|
|
|
headers = Core()->getAllHeaders();
|
2018-10-10 11:33:55 +00:00
|
|
|
headersModel->endResetModel();
|
2018-05-21 17:34:41 +00:00
|
|
|
|
2019-08-19 13:35:25 +00:00
|
|
|
ui->treeView->resizeColumnToContents(0);
|
|
|
|
ui->treeView->resizeColumnToContents(1);
|
2018-05-21 17:34:41 +00:00
|
|
|
}
|