2017-10-02 16:18:40 +00:00
|
|
|
#include "SymbolsWidget.h"
|
|
|
|
#include "ui_SymbolsWidget.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)
|
|
|
|
: QAbstractListModel(parent),
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SymbolsProxyModel::SymbolsProxyModel(SymbolsModel *sourceModel, QObject *parent)
|
|
|
|
: QSortFilterProxyModel(parent)
|
|
|
|
{
|
|
|
|
setSourceModel(sourceModel);
|
|
|
|
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) :
|
|
|
|
CutterDockWidget(main, action),
|
2018-10-10 12:34:46 +00:00
|
|
|
ui(new Ui::SymbolsWidget),
|
|
|
|
tree(new CutterTreeWidget(this))
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2017-04-13 15:14:02 +00:00
|
|
|
|
2018-10-10 12:34:46 +00:00
|
|
|
// Add Status Bar footer
|
|
|
|
tree->addStatusBar(ui->verticalLayout);
|
|
|
|
|
2018-05-02 12:06:31 +00:00
|
|
|
symbolsModel = new SymbolsModel(&symbols, this);
|
|
|
|
symbolsProxyModel = new SymbolsProxyModel(symbolsModel, this);
|
|
|
|
ui->symbolsTreeView->setModel(symbolsProxyModel);
|
|
|
|
ui->symbolsTreeView->sortByColumn(SymbolsModel::AddressColumn, Qt::AscendingOrder);
|
|
|
|
|
|
|
|
// Ctrl-F to show/hide the filter entry
|
|
|
|
QShortcut *searchShortcut = new QShortcut(QKeySequence::Find, this);
|
|
|
|
connect(searchShortcut, &QShortcut::activated, ui->quickFilterView, &QuickFilterView::showFilter);
|
|
|
|
searchShortcut->setContext(Qt::WidgetWithChildrenShortcut);
|
|
|
|
|
|
|
|
// Esc to clear the filter entry
|
|
|
|
QShortcut *clearShortcut = new QShortcut(QKeySequence(Qt::Key_Escape), this);
|
|
|
|
connect(clearShortcut, &QShortcut::activated, ui->quickFilterView, &QuickFilterView::clearFilter);
|
|
|
|
clearShortcut->setContext(Qt::WidgetWithChildrenShortcut);
|
|
|
|
|
|
|
|
connect(ui->quickFilterView, SIGNAL(filterTextChanged(const QString &)),
|
|
|
|
symbolsProxyModel, SLOT(setFilterWildcard(const QString &)));
|
|
|
|
connect(ui->quickFilterView, SIGNAL(filterClosed()), ui->symbolsTreeView, SLOT(setFocus()));
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2018-10-10 12:34:46 +00:00
|
|
|
connect(ui->quickFilterView, &QuickFilterView::filterTextChanged, this, [this] {
|
|
|
|
tree->showItemsNumber(symbolsProxyModel->rowCount());
|
|
|
|
});
|
|
|
|
|
2017-04-13 15:14:02 +00:00
|
|
|
setScrollMode();
|
|
|
|
|
2018-05-02 12:06:31 +00:00
|
|
|
connect(Core(), SIGNAL(refreshAll()), this, SLOT(refreshSymbols()));
|
2017-04-13 15:14:02 +00:00
|
|
|
}
|
|
|
|
|
2017-11-19 12:56:10 +00:00
|
|
|
SymbolsWidget::~SymbolsWidget() {}
|
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2018-05-02 12:06:31 +00:00
|
|
|
void SymbolsWidget::on_symbolsTreeView_doubleClicked(const QModelIndex &index)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2018-11-05 21:51:27 +00:00
|
|
|
if (!index.isValid()) {
|
2018-04-23 07:54:06 +00:00
|
|
|
return;
|
2018-11-05 21:51:27 +00:00
|
|
|
}
|
2017-04-09 17:09:35 +00:00
|
|
|
|
2018-05-02 12:06:31 +00:00
|
|
|
auto symbol = index.data(SymbolsModel::SymbolDescriptionRole).value<SymbolDescription>();
|
2018-04-12 06:33:30 +00:00
|
|
|
Core()->seek(symbol.vaddr);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
2017-04-13 15:14:02 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
qhelpers::adjustColumns(ui->symbolsTreeView, SymbolsModel::ColumnCount, 0);
|
2018-10-10 12:34:46 +00:00
|
|
|
|
|
|
|
tree->showItemsNumber(symbolsProxyModel->rowCount());
|
2017-04-13 15:14:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SymbolsWidget::setScrollMode()
|
|
|
|
{
|
2018-05-02 12:06:31 +00:00
|
|
|
qhelpers::setVerticalScrollMode(ui->symbolsTreeView);
|
2017-04-13 15:14:02 +00:00
|
|
|
}
|