2017-10-02 16:18:40 +00:00
|
|
|
#include "SymbolsWidget.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>
|
|
|
|
|
2018-05-02 12:06:31 +00:00
|
|
|
SymbolsModel::SymbolsModel(QList<SymbolDescription> *symbols, QObject *parent)
|
2019-08-19 13:35:25 +00:00
|
|
|
: AddressableItemModel<QAbstractListModel>(parent),
|
2018-05-02 12:06:31 +00:00
|
|
|
symbols(symbols)
|
|
|
|
{
|
|
|
|
}
|
2017-04-13 15:14:02 +00:00
|
|
|
|
2018-05-02 12:06:31 +00:00
|
|
|
int SymbolsModel::rowCount(const QModelIndex &) const
|
|
|
|
{
|
|
|
|
return symbols->count();
|
|
|
|
}
|
|
|
|
|
|
|
|
int SymbolsModel::columnCount(const QModelIndex &) const
|
|
|
|
{
|
|
|
|
return SymbolsModel::ColumnCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant SymbolsModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
2018-11-05 21:51:27 +00:00
|
|
|
if (index.row() >= symbols->count()) {
|
2018-05-02 12:06:31 +00:00
|
|
|
return QVariant();
|
2018-11-05 21:51:27 +00:00
|
|
|
}
|
2018-05-02 12:06:31 +00:00
|
|
|
|
|
|
|
const SymbolDescription &symbol = symbols->at(index.row());
|
|
|
|
|
|
|
|
switch (role) {
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
switch (index.column()) {
|
|
|
|
case SymbolsModel::AddressColumn:
|
|
|
|
return RAddressString(symbol.vaddr);
|
|
|
|
case SymbolsModel::TypeColumn:
|
|
|
|
return QString("%1 %2").arg(symbol.bind, symbol.type).trimmed();
|
|
|
|
case SymbolsModel::NameColumn:
|
|
|
|
return symbol.name;
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
case SymbolsModel::SymbolDescriptionRole:
|
|
|
|
return QVariant::fromValue(symbol);
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant SymbolsModel::headerData(int section, Qt::Orientation, int role) const
|
|
|
|
{
|
|
|
|
switch (role) {
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
switch (section) {
|
|
|
|
case SymbolsModel::AddressColumn:
|
|
|
|
return tr("Address");
|
|
|
|
case SymbolsModel::TypeColumn:
|
|
|
|
return tr("Type");
|
|
|
|
case SymbolsModel::NameColumn:
|
|
|
|
return tr("Name");
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-19 13:35:25 +00:00
|
|
|
RVA SymbolsModel::address(const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
const SymbolDescription &symbol = symbols->at(index.row());
|
|
|
|
return symbol.vaddr;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString SymbolsModel::name(const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
const SymbolDescription &symbol = symbols->at(index.row());
|
|
|
|
return symbol.name;
|
|
|
|
}
|
|
|
|
|
2018-05-02 12:06:31 +00:00
|
|
|
SymbolsProxyModel::SymbolsProxyModel(SymbolsModel *sourceModel, QObject *parent)
|
2019-08-19 13:35:25 +00:00
|
|
|
: AddressableFilterProxyModel(sourceModel, parent)
|
2018-05-02 12:06:31 +00:00
|
|
|
{
|
|
|
|
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
|
|
|
setSortCaseSensitivity(Qt::CaseInsensitive);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SymbolsProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
QModelIndex index = sourceModel()->index(row, 0, parent);
|
|
|
|
auto symbol = index.data(SymbolsModel::SymbolDescriptionRole).value<SymbolDescription>();
|
|
|
|
|
|
|
|
return symbol.name.contains(filterRegExp());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SymbolsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
|
|
|
{
|
|
|
|
auto leftSymbol = left.data(SymbolsModel::SymbolDescriptionRole).value<SymbolDescription>();
|
|
|
|
auto rightSymbol = right.data(SymbolsModel::SymbolDescriptionRole).value<SymbolDescription>();
|
|
|
|
|
|
|
|
switch (left.column()) {
|
|
|
|
case SymbolsModel::AddressColumn:
|
|
|
|
return leftSymbol.vaddr < rightSymbol.vaddr;
|
|
|
|
case SymbolsModel::TypeColumn:
|
|
|
|
return leftSymbol.type < rightSymbol.type;
|
|
|
|
case SymbolsModel::NameColumn:
|
|
|
|
return leftSymbol.name < rightSymbol.name;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2018-03-16 21:46:57 +00:00
|
|
|
SymbolsWidget::SymbolsWidget(MainWindow *main, QAction *action) :
|
2019-08-19 13:35:25 +00:00
|
|
|
ListDockWidget(main, action)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2019-08-19 13:35:25 +00:00
|
|
|
setWindowTitle(tr("Symbols"));
|
|
|
|
setObjectName("SymbolsWidget");
|
2018-10-10 12:34:46 +00:00
|
|
|
|
2018-05-02 12:06:31 +00:00
|
|
|
symbolsModel = new SymbolsModel(&symbols, this);
|
|
|
|
symbolsProxyModel = new SymbolsProxyModel(symbolsModel, this);
|
2019-08-19 13:35:25 +00:00
|
|
|
setModels(symbolsProxyModel);
|
|
|
|
ui->treeView->sortByColumn(SymbolsModel::AddressColumn, Qt::AscendingOrder);
|
|
|
|
|
|
|
|
connect(Core(), &CutterCore::refreshAll, this, &SymbolsWidget::refreshSymbols);
|
2017-04-13 15:14:02 +00:00
|
|
|
}
|
|
|
|
|
2017-11-19 12:56:10 +00:00
|
|
|
SymbolsWidget::~SymbolsWidget() {}
|
|
|
|
|
2018-05-02 12:06:31 +00:00
|
|
|
void SymbolsWidget::refreshSymbols()
|
2017-04-13 15:14:02 +00:00
|
|
|
{
|
2018-10-10 11:33:55 +00:00
|
|
|
symbolsModel->beginResetModel();
|
2018-05-02 12:06:31 +00:00
|
|
|
symbols = Core()->getAllSymbols();
|
2018-10-10 11:33:55 +00:00
|
|
|
symbolsModel->endResetModel();
|
2018-05-02 12:06:31 +00:00
|
|
|
|
2019-08-19 13:35:25 +00:00
|
|
|
qhelpers::adjustColumns(ui->treeView, SymbolsModel::ColumnCount, 0);
|
2017-04-13 15:14:02 +00:00
|
|
|
}
|