Permalink
Browse files

GUI: AStyle DisassemblerGraphView and ActionHelpers

  • Loading branch information...
mrexodia committed Mar 12, 2017
1 parent 00ddb31 commit 4cb14b74a9951975e6acf1cbb260a1589abaf993
Showing with 116 additions and 114 deletions.
  1. +2 −0 format.bat
  2. +19 −19 src/gui/Src/Gui/DisassemblerGraphView.cpp
  3. +95 −95 src/gui/Src/Utils/ActionHelpers.h
View
@@ -0,0 +1,2 @@
@echo off
hooks\AStyleWhore.exe Silent
@@ -176,9 +176,9 @@ void DisassemblerGraphView::paintNormal(QPainter & p, QRect & viewportRect, int
{
DisassemblerBlock & block = blockIt.second;
bool blockSelected = false;
for (const Instr& instr : block.block.instrs)
for(const Instr & instr : block.block.instrs)
{
if (instr.addr == this->cur_instr)
if(instr.addr == this->cur_instr)
{
blockSelected = true;
}
@@ -272,7 +272,7 @@ void DisassemblerGraphView::paintNormal(QPainter & p, QRect & viewportRect, int
for(DisassemblerEdge & edge : block.edges)
{
QPen pen(edge.color);
if (blockSelected)
if(blockSelected)
{
pen.setStyle(Qt::DashLine);
}
@@ -748,11 +748,11 @@ void DisassemblerGraphView::computeGraphLayout(DisassemblerBlock & block)
DisassemblerBlock & right = this->blocks[block.new_exits[1]];
if(left.new_exits.size() == 0)
{
left.col = right.col - 2;
int add = left.col < 0 ? - left.col : 0;
this->adjustGraphLayout(right, add, 1);
this->adjustGraphLayout(left, add, 1);
col = right.col_count + add;
left.col = right.col - 2;
int add = left.col < 0 ? - left.col : 0;
this->adjustGraphLayout(right, add, 1);
this->adjustGraphLayout(left, add, 1);
col = right.col_count + add;
}
else if(right.new_exits.size() == 0)
{
@@ -896,7 +896,7 @@ DisassemblerGraphView::DisassemblerEdge DisassemblerGraphView::routeEdge(EdgesVe
{
auto checkColumn = [min_row, max_row, &edge_valid](int column)
{
if (column < 0 || column >= int(edge_valid[min_row].size()))
if(column < 0 || column >= int(edge_valid[min_row].size()))
return false;
for(int row = min_row; row < max_row; row++)
{
@@ -908,9 +908,9 @@ DisassemblerGraphView::DisassemblerEdge DisassemblerGraphView::routeEdge(EdgesVe
return true;
};
if (!checkColumn(col))
if(!checkColumn(col))
{
if (checkColumn(end.col + 1))
if(checkColumn(end.col + 1))
{
col = end.col + 1;
}
@@ -959,10 +959,10 @@ DisassemblerGraphView::DisassemblerEdge DisassemblerGraphView::routeEdge(EdgesVe
if(end.row != (start.row + 1))
{
//Not in same row, need to generate a line for moving to the correct row
if (col == (start.col + 1))
if(col == (start.col + 1))
this->markEdge(vert_edges, start.row + 1, start.col + 1, i, false);
int index = this->findVertEdgeIndex(vert_edges, col, min_row, max_row);
if (col == (start.col + 1))
if(col == (start.col + 1))
edge.start_index = index;
edge.addPoint(end.row, col, index);
horiz = false;
@@ -1068,7 +1068,7 @@ void DisassemblerGraphView::renderFunction(Function & func)
}
else
{
removeFromVec(this->blocks[edge].incoming, block.block.entry);
removeFromVec(this->blocks[edge].incoming, block.block.entry);
}
}
}
@@ -1465,7 +1465,7 @@ void DisassemblerGraphView::fontChanged()
void DisassemblerGraphView::setGraphLayout(DisassemblerGraphView::LayoutType layout)
{
this->layoutType = layout;
if (this->ready)
if(this->ready)
{
this->renderFunction(this->analysis.functions[this->function]);
}
@@ -1614,11 +1614,11 @@ void DisassemblerGraphView::setupContextMenu()
MenuBuilder* layoutMenu = new MenuBuilder(this);
QActionGroup* layoutGroup = new QActionGroup(this);
layoutGroup->addAction(makeAction(tr("Narrow"), [this](){ setGraphLayout(LayoutType::Narrow); }));
layoutGroup->addAction(makeAction(tr("Narrow"), [this]() { setGraphLayout(LayoutType::Narrow); }));
QAction* mediumLayout =
layoutGroup->addAction(makeAction(tr("Medium"), [this](){ setGraphLayout(LayoutType::Medium); }));
layoutGroup->addAction(makeAction(tr("Wide"), [this](){ setGraphLayout(LayoutType::Wide); }));
for (QAction* layoutAction : layoutGroup->actions())
layoutGroup->addAction(makeAction(tr("Medium"), [this]() { setGraphLayout(LayoutType::Medium); }));
layoutGroup->addAction(makeAction(tr("Wide"), [this]() { setGraphLayout(LayoutType::Wide); }));
for(QAction* layoutAction : layoutGroup->actions())
{
layoutAction->setCheckable(true);
layoutMenu->addAction(layoutAction);
@@ -7,123 +7,123 @@ template<class Base>
class ActionHelper
{
private:
Base* getBase()
{
return static_cast<Base*>(this);
}
struct ActionShortcut
{
QAction* action;
QString shortcut;
inline ActionShortcut(QAction* action, const char* shortcut)
: action(action),
shortcut(shortcut)
Base* getBase()
{
return static_cast<Base*>(this);
}
};
struct ActionShortcut
{
QAction* action;
QString shortcut;
inline ActionShortcut(QAction* action, const char* shortcut)
: action(action),
shortcut(shortcut)
{
}
};
public:
virtual void updateShortcuts()
{
for(const auto & actionShortcut : actionShortcutPairs)
actionShortcut.action->setShortcut(ConfigShortcut(actionShortcut.shortcut));
}
virtual void updateShortcuts()
{
for(const auto & actionShortcut : actionShortcutPairs)
actionShortcut.action->setShortcut(ConfigShortcut(actionShortcut.shortcut));
}
private:
inline QAction* connectAction(QAction* action, const char* slot)
{
QObject::connect(action, SIGNAL(triggered(bool)), getBase(), slot);
return action;
}
inline QAction* connectAction(QAction* action, const char* slot)
{
QObject::connect(action, SIGNAL(triggered(bool)), getBase(), slot);
return action;
}
template<class T> // lambda or base member pointer
inline QAction* connectAction(QAction* action, T callback)
{
QObject::connect(action, &QAction::triggered, getBase(), callback);
return action;
}
template<class T> // lambda or base member pointer
inline QAction* connectAction(QAction* action, T callback)
{
QObject::connect(action, &QAction::triggered, getBase(), callback);
return action;
}
inline QAction* connectShortcutAction(QAction* action, const char* shortcut)
{
actionShortcutPairs.push_back(ActionShortcut(action, shortcut));
action->setShortcut(ConfigShortcut(shortcut));
action->setShortcutContext(Qt::WidgetShortcut);
getBase()->addAction(action);
return action;
}
inline QAction* connectMenuAction(QMenu* menu, QAction* action)
{
menu->addAction(action);
return action;
}
inline QAction* connectShortcutAction(QAction* action, const char* shortcut)
{
actionShortcutPairs.push_back(ActionShortcut(action, shortcut));
action->setShortcut(ConfigShortcut(shortcut));
action->setShortcutContext(Qt::WidgetShortcut);
getBase()->addAction(action);
return action;
}
inline QAction* connectMenuAction(QMenu* menu, QAction* action)
{
menu->addAction(action);
return action;
}
protected:
inline QMenu* makeMenu(const QString & title)
{
return new QMenu(title, getBase());
}
inline QMenu* makeMenu(const QString & title)
{
return new QMenu(title, getBase());
}
inline QMenu* makeMenu(const QIcon & icon, const QString & title)
{
QMenu* menu = new QMenu(title, getBase());
menu->setIcon(icon);
return menu;
}
inline QMenu* makeMenu(const QIcon & icon, const QString & title)
{
QMenu* menu = new QMenu(title, getBase());
menu->setIcon(icon);
return menu;
}
template<typename T>
inline QAction* makeAction(const QString & text, T slot)
{
return connectAction(new QAction(text, getBase()), slot);
}
template<typename T>
inline QAction* makeAction(const QString & text, T slot)
{
return connectAction(new QAction(text, getBase()), slot);
}
template<typename T>
inline QAction* makeAction(const QIcon & icon, const QString & text, T slot)
{
return connectAction(new QAction(icon, text, getBase()), slot);
}
template<typename T>
inline QAction* makeAction(const QIcon & icon, const QString & text, T slot)
{
return connectAction(new QAction(icon, text, getBase()), slot);
}
template<typename T>
inline QAction* makeShortcutAction(const QString & text, T slot, const char* shortcut)
{
return connectShortcutAction(makeAction(text, slot), shortcut);
}
template<typename T>
inline QAction* makeShortcutAction(const QString & text, T slot, const char* shortcut)
{
return connectShortcutAction(makeAction(text, slot), shortcut);
}
template<typename T>
inline QAction* makeShortcutAction(const QIcon & icon, const QString & text, T slot, const char* shortcut)
{
return connectShortcutAction(makeAction(icon, text, slot), shortcut);
}
template<typename T>
inline QAction* makeShortcutAction(const QIcon & icon, const QString & text, T slot, const char* shortcut)
{
return connectShortcutAction(makeAction(icon, text, slot), shortcut);
}
template<typename T>
inline QAction* makeMenuAction(QMenu* menu, const QString & text, T slot)
{
return connectMenuAction(menu, makeAction(text, slot));
}
template<typename T>
inline QAction* makeMenuAction(QMenu* menu, const QString & text, T slot)
{
return connectMenuAction(menu, makeAction(text, slot));
}
template<typename T>
inline QAction* makeMenuAction(QMenu* menu, const QIcon & icon, const QString & text, T slot)
{
return connectMenuAction(menu, makeAction(icon, text, slot));
}
template<typename T>
inline QAction* makeMenuAction(QMenu* menu, const QIcon & icon, const QString & text, T slot)
{
return connectMenuAction(menu, makeAction(icon, text, slot));
}
template<typename T>
inline QAction* makeShortcutMenuAction(QMenu* menu, const QString & text, T slot, const char* shortcut)
{
return connectShortcutAction(makeMenuAction(menu, text, slot), shortcut);
}
template<typename T>
inline QAction* makeShortcutMenuAction(QMenu* menu, const QString & text, T slot, const char* shortcut)
{
return connectShortcutAction(makeMenuAction(menu, text, slot), shortcut);
}
template<typename T>
inline QAction* makeShortcutMenuAction(QMenu* menu, const QIcon & icon, const QString & text, T slot, const char* shortcut)
{
return connectShortcutAction(makeMenuAction(menu, icon, text, slot), shortcut);
}
template<typename T>
inline QAction* makeShortcutMenuAction(QMenu* menu, const QIcon & icon, const QString & text, T slot, const char* shortcut)
{
return connectShortcutAction(makeMenuAction(menu, icon, text, slot), shortcut);
}
private:
std::vector<ActionShortcut> actionShortcutPairs;
std::vector<ActionShortcut> actionShortcutPairs;
};
#endif

0 comments on commit 4cb14b7

Please sign in to comment.