FunctionsWidget code cleaning

This commit is contained in:
xarkes 2018-02-09 15:03:03 +01:00
parent c8e6cae150
commit dd6b591d9d
2 changed files with 33 additions and 43 deletions

View File

@ -14,14 +14,14 @@
#include <QResource> #include <QResource>
#include <QShortcut> #include <QShortcut>
FunctionModel::FunctionModel(QList<FunctionDescription> *functions, QSet<RVA> *import_addresses, bool nested, QFont default_font, QFont highlight_font, QObject *parent) FunctionModel::FunctionModel(QList<FunctionDescription> *functions, QSet<RVA> *importAddresses, bool nested, QFont default_font, QFont highlight_font, QObject *parent)
: QAbstractItemModel(parent), : QAbstractItemModel(parent),
functions(functions), functions(functions),
import_addresses(import_addresses), importAddresses(importAddresses),
highlight_font(highlight_font), highlightFont(highlight_font),
default_font(default_font), defaultFont(default_font),
nested(nested), nested(nested),
current_index(-1) currentIndex(-1)
{ {
connect(Core(), SIGNAL(seekChanged(RVA)), this, SLOT(seekChanged(RVA))); connect(Core(), SIGNAL(seekChanged(RVA)), this, SLOT(seekChanged(RVA)));
@ -72,7 +72,7 @@ int FunctionModel::columnCount(const QModelIndex &/*parent*/) const
bool FunctionModel::functionIsImport(ut64 addr) const bool FunctionModel::functionIsImport(ut64 addr) const
{ {
return import_addresses->contains(addr); return importAddresses->contains(addr);
} }
@ -137,15 +137,15 @@ QVariant FunctionModel::data(const QModelIndex &index, int role) const
} }
case Qt::DecorationRole: case Qt::DecorationRole:
if (import_addresses->contains(function.offset) && if (importAddresses->contains(function.offset) &&
(nested ? false : index.column() == ImportColumn)) (nested ? false : index.column() == ImportColumn))
return QIcon(":/img/icons/import_light.svg"); return QIcon(":/img/icons/import_light.svg");
return QVariant(); return QVariant();
case Qt::FontRole: case Qt::FontRole:
if (current_index == function_index) if (currentIndex == function_index)
return highlight_font; return highlightFont;
return default_font; return defaultFont;
case Qt::ToolTipRole: case Qt::ToolTipRole:
{ {
@ -173,7 +173,7 @@ QVariant FunctionModel::data(const QModelIndex &index, int role) const
return QVariant::fromValue(function); return QVariant::fromValue(function);
case IsImportRole: case IsImportRole:
return import_addresses->contains(function.offset); return importAddresses->contains(function.offset);
default: default:
return QVariant(); return QVariant();
@ -255,9 +255,9 @@ bool FunctionModel::updateCurrentIndex()
} }
} }
bool changed = current_index != index; bool changed = currentIndex != index;
current_index = index; currentIndex = index;
return changed; return changed;
} }
@ -275,9 +275,6 @@ void FunctionModel::functionRenamed(const QString &prev_name, const QString &new
} }
} }
FunctionSortFilterProxyModel::FunctionSortFilterProxyModel(FunctionModel *source_model, QObject *parent) FunctionSortFilterProxyModel::FunctionSortFilterProxyModel(FunctionModel *source_model, QObject *parent)
: QSortFilterProxyModel(parent) : QSortFilterProxyModel(parent)
{ {
@ -364,12 +361,12 @@ FunctionsWidget::FunctionsWidget(MainWindow *main, QWidget *parent) :
QFont default_font = QFont(font_info.family(), font_info.pointSize()); QFont default_font = QFont(font_info.family(), font_info.pointSize());
QFont highlight_font = QFont(font_info.family(), font_info.pointSize(), QFont::Bold); QFont highlight_font = QFont(font_info.family(), font_info.pointSize(), QFont::Bold);
function_model = new FunctionModel(&functions, &import_addresses, false, default_font, highlight_font, this); functionModel = new FunctionModel(&functions, &importAddresses, false, default_font, highlight_font, this);
function_proxy_model = new FunctionSortFilterProxyModel(function_model, this); functionProxyModel = new FunctionSortFilterProxyModel(functionModel, this);
ui->functionsTreeView->setModel(function_proxy_model); ui->functionsTreeView->setModel(functionProxyModel);
ui->functionsTreeView->sortByColumn(FunctionModel::NameColumn, Qt::AscendingOrder); ui->functionsTreeView->sortByColumn(FunctionModel::NameColumn, Qt::AscendingOrder);
connect(ui->quickFilterView, SIGNAL(filterTextChanged(const QString &)), function_proxy_model, SLOT(setFilterWildcard(const QString &))); connect(ui->quickFilterView, SIGNAL(filterTextChanged(const QString &)), functionProxyModel, SLOT(setFilterWildcard(const QString &)));
connect(ui->quickFilterView, SIGNAL(filterClosed()), ui->functionsTreeView, SLOT(setFocus())); connect(ui->quickFilterView, SIGNAL(filterClosed()), ui->functionsTreeView, SLOT(setFocus()));
setScrollMode(); setScrollMode();
@ -395,15 +392,15 @@ FunctionsWidget::~FunctionsWidget() {}
void FunctionsWidget::refreshTree() void FunctionsWidget::refreshTree()
{ {
function_model->beginReloadFunctions(); functionModel->beginReloadFunctions();
functions = CutterCore::getInstance()->getAllFunctions(); functions = CutterCore::getInstance()->getAllFunctions();
import_addresses.clear(); importAddresses.clear();
foreach (ImportDescription import, CutterCore::getInstance()->getAllImports()) foreach (ImportDescription import, CutterCore::getInstance()->getAllImports())
import_addresses.insert(import.plt); importAddresses.insert(import.plt);
function_model->endReloadFunctions(); functionModel->endReloadFunctions();
// resize offset and size columns // resize offset and size columns
ui->functionsTreeView->resizeColumnToContents(0); ui->functionsTreeView->resizeColumnToContents(0);
@ -468,17 +465,10 @@ void FunctionsWidget::on_actionFunctionsRename_triggered()
{ {
// Get new function name // Get new function name
QString new_name = r->getName(); QString new_name = r->getName();
// Rename function in r2 core // Rename function in r2 core
CutterCore::getInstance()->renameFunction(function.name, new_name); CutterCore::getInstance()->renameFunction(function.name, new_name);
// Scroll to show the new name in functions tree widget
//
// QAbstractItemView::EnsureVisible
// QAbstractItemView::PositionAtTop
// QAbstractItemView::PositionAtBottom
// QAbstractItemView::PositionAtCenter
//
//ui->functionsTreeWidget->scrollToItem(selected_rows.first(), QAbstractItemView::PositionAtTop);
// Seek to new renamed function // Seek to new renamed function
CutterCore::getInstance()->seek(function.offset); CutterCore::getInstance()->seek(function.offset);
} }
@ -507,7 +497,7 @@ void FunctionsWidget::showTitleContextMenu(const QPoint &pt)
menu->addAction(ui->actionHorizontal); menu->addAction(ui->actionHorizontal);
menu->addAction(ui->actionVertical); menu->addAction(ui->actionVertical);
if (!function_model->isNested()) if (!functionModel->isNested())
{ {
ui->actionHorizontal->setChecked(true); ui->actionHorizontal->setChecked(true);
ui->actionVertical->setChecked(false); ui->actionVertical->setChecked(false);
@ -526,13 +516,13 @@ void FunctionsWidget::showTitleContextMenu(const QPoint &pt)
void FunctionsWidget::on_actionHorizontal_triggered() void FunctionsWidget::on_actionHorizontal_triggered()
{ {
function_model->setNested(false); functionModel->setNested(false);
ui->functionsTreeView->setIndentation(8); ui->functionsTreeView->setIndentation(8);
} }
void FunctionsWidget::on_actionVertical_triggered() void FunctionsWidget::on_actionVertical_triggered()
{ {
function_model->setNested(true); functionModel->setNested(true);
ui->functionsTreeView->setIndentation(20); ui->functionsTreeView->setIndentation(20);
} }

View File

@ -24,14 +24,14 @@ class FunctionModel : public QAbstractItemModel
private: private:
QList<FunctionDescription> *functions; QList<FunctionDescription> *functions;
QSet<RVA> *import_addresses; QSet<RVA> *importAddresses;
QFont highlight_font; QFont highlightFont;
QFont default_font; QFont defaultFont;
bool nested; bool nested;
int current_index; int currentIndex;
bool functionIsImport(ut64 addr) const; bool functionIsImport(ut64 addr) const;
@ -41,7 +41,7 @@ public:
enum Column { NameColumn = 0, SizeColumn, ImportColumn, OffsetColumn, ColumnCount }; enum Column { NameColumn = 0, SizeColumn, ImportColumn, OffsetColumn, ColumnCount };
FunctionModel(QList<FunctionDescription> *functions, QSet<RVA> *import_addresses, bool nested, QFont default_font, QFont highlight_font, QObject *parent = 0); FunctionModel(QList<FunctionDescription> *functions, QSet<RVA> *importAddresses, bool nested, QFont defaultFont, QFont highlightFont, QObject *parent = 0);
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &index) const; QModelIndex parent(const QModelIndex &index) const;
@ -115,10 +115,10 @@ private:
MainWindow *main; MainWindow *main;
QList<FunctionDescription> functions; QList<FunctionDescription> functions;
QSet<RVA> import_addresses; QSet<RVA> importAddresses;
FunctionModel *function_model; FunctionModel *functionModel;
FunctionSortFilterProxyModel *function_proxy_model; FunctionSortFilterProxyModel *functionProxyModel;
void setScrollMode(); void setScrollMode();
}; };