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 <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),
functions(functions),
import_addresses(import_addresses),
highlight_font(highlight_font),
default_font(default_font),
importAddresses(importAddresses),
highlightFont(highlight_font),
defaultFont(default_font),
nested(nested),
current_index(-1)
currentIndex(-1)
{
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
{
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:
if (import_addresses->contains(function.offset) &&
if (importAddresses->contains(function.offset) &&
(nested ? false : index.column() == ImportColumn))
return QIcon(":/img/icons/import_light.svg");
return QVariant();
case Qt::FontRole:
if (current_index == function_index)
return highlight_font;
return default_font;
if (currentIndex == function_index)
return highlightFont;
return defaultFont;
case Qt::ToolTipRole:
{
@ -173,7 +173,7 @@ QVariant FunctionModel::data(const QModelIndex &index, int role) const
return QVariant::fromValue(function);
case IsImportRole:
return import_addresses->contains(function.offset);
return importAddresses->contains(function.offset);
default:
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;
}
@ -275,9 +275,6 @@ void FunctionModel::functionRenamed(const QString &prev_name, const QString &new
}
}
FunctionSortFilterProxyModel::FunctionSortFilterProxyModel(FunctionModel *source_model, QObject *parent)
: QSortFilterProxyModel(parent)
{
@ -364,12 +361,12 @@ FunctionsWidget::FunctionsWidget(MainWindow *main, QWidget *parent) :
QFont default_font = QFont(font_info.family(), font_info.pointSize());
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);
function_proxy_model = new FunctionSortFilterProxyModel(function_model, this);
ui->functionsTreeView->setModel(function_proxy_model);
functionModel = new FunctionModel(&functions, &importAddresses, false, default_font, highlight_font, this);
functionProxyModel = new FunctionSortFilterProxyModel(functionModel, this);
ui->functionsTreeView->setModel(functionProxyModel);
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()));
setScrollMode();
@ -395,15 +392,15 @@ FunctionsWidget::~FunctionsWidget() {}
void FunctionsWidget::refreshTree()
{
function_model->beginReloadFunctions();
functionModel->beginReloadFunctions();
functions = CutterCore::getInstance()->getAllFunctions();
import_addresses.clear();
importAddresses.clear();
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
ui->functionsTreeView->resizeColumnToContents(0);
@ -468,17 +465,10 @@ void FunctionsWidget::on_actionFunctionsRename_triggered()
{
// Get new function name
QString new_name = r->getName();
// Rename function in r2 core
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
CutterCore::getInstance()->seek(function.offset);
}
@ -507,7 +497,7 @@ void FunctionsWidget::showTitleContextMenu(const QPoint &pt)
menu->addAction(ui->actionHorizontal);
menu->addAction(ui->actionVertical);
if (!function_model->isNested())
if (!functionModel->isNested())
{
ui->actionHorizontal->setChecked(true);
ui->actionVertical->setChecked(false);
@ -526,13 +516,13 @@ void FunctionsWidget::showTitleContextMenu(const QPoint &pt)
void FunctionsWidget::on_actionHorizontal_triggered()
{
function_model->setNested(false);
functionModel->setNested(false);
ui->functionsTreeView->setIndentation(8);
}
void FunctionsWidget::on_actionVertical_triggered()
{
function_model->setNested(true);
functionModel->setNested(true);
ui->functionsTreeView->setIndentation(20);
}

View File

@ -24,14 +24,14 @@ class FunctionModel : public QAbstractItemModel
private:
QList<FunctionDescription> *functions;
QSet<RVA> *import_addresses;
QSet<RVA> *importAddresses;
QFont highlight_font;
QFont default_font;
QFont highlightFont;
QFont defaultFont;
bool nested;
int current_index;
int currentIndex;
bool functionIsImport(ut64 addr) const;
@ -41,7 +41,7 @@ public:
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 parent(const QModelIndex &index) const;
@ -115,10 +115,10 @@ private:
MainWindow *main;
QList<FunctionDescription> functions;
QSet<RVA> import_addresses;
QSet<RVA> importAddresses;
FunctionModel *function_model;
FunctionSortFilterProxyModel *function_proxy_model;
FunctionModel *functionModel;
FunctionSortFilterProxyModel *functionProxyModel;
void setScrollMode();
};