Replace DisassemblerGraphView::sent_seek with connect/disconnect

This commit is contained in:
Florian Märkl 2018-05-24 18:53:12 +02:00
parent b857e724e8
commit e642406192
2 changed files with 26 additions and 21 deletions

View File

@ -37,7 +37,7 @@ DisassemblerGraphView::DisassemblerGraphView(QWidget *parent)
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot()));
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdatedSlot()));
connect(Core(), SIGNAL(seekChanged(RVA)), this, SLOT(onSeekChanged(RVA)));
connectSeekChanged(false);
// Space to switch to disassembly
QShortcut *shortcut_disassembly = new QShortcut(QKeySequence(Qt::Key_Space), this);
@ -103,6 +103,15 @@ DisassemblerGraphView::DisassemblerGraphView(QWidget *parent)
colorsUpdatedSlot();
}
void DisassemblerGraphView::connectSeekChanged(bool disconnect)
{
if (disconnect) {
QObject::disconnect(Core(), SIGNAL(seekChanged(RVA)), this, SLOT(onSeekChanged(RVA)));
} else {
connect(Core(), SIGNAL(seekChanged(RVA)), this, SLOT(onSeekChanged(RVA)));
}
}
DisassemblerGraphView::~DisassemblerGraphView()
{
for (QShortcut *shortcut : shortcuts) {
@ -232,6 +241,7 @@ void DisassemblerGraphView::loadCurrentGraph()
}
}
void DisassemblerGraphView::prepareGraphNode(GraphBlock &block)
{
DisassemblyBlock &db = disassembly_blocks[block.entry];
@ -260,7 +270,6 @@ void DisassemblerGraphView::prepareGraphNode(GraphBlock &block)
block.height = (height * charHeight) + extra;
}
void DisassemblerGraphView::initFont()
{
setFont(Config()->getFont());
@ -396,6 +405,7 @@ GraphView::EdgeConfiguration DisassemblerGraphView::edgeConfiguration(GraphView:
return ec;
}
RVA DisassemblerGraphView::getAddrForMouseEvent(GraphBlock &block, QPoint *point)
{
DisassemblyBlock &db = disassembly_blocks[block.entry];
@ -419,7 +429,6 @@ RVA DisassemblerGraphView::getAddrForMouseEvent(GraphBlock &block, QPoint *point
return RVA_INVALID;
}
DisassemblerGraphView::Instr *DisassemblerGraphView::getInstrForMouseEvent(
GraphView::GraphBlock &block, QPoint *point)
{
@ -485,8 +494,6 @@ DisassemblerGraphView::DisassemblyBlock *DisassemblerGraphView::blockForAddress(
void DisassemblerGraphView::onSeekChanged(RVA addr)
{
mMenu->setOffset(addr);
// If this seek was NOT done by us...
if (!sent_seek) {
DisassemblyBlock *db = blockForAddress(addr);
if (db) {
// This is a local address! We animated to it.
@ -504,8 +511,6 @@ void DisassemblerGraphView::onSeekChanged(RVA addr)
}
}
}
sent_seek = false;
}
void DisassemblerGraphView::zoomIn(QPoint mouse)
{
@ -587,8 +592,9 @@ void DisassemblerGraphView::prevInstr()
void DisassemblerGraphView::seek(RVA addr, bool update_viewport)
{
sent_seek = true;
connectSeekChanged(true);
Core()->seek(addr);
connectSeekChanged(false);
if (update_viewport) {
viewport()->update();
}
@ -625,7 +631,6 @@ void DisassemblerGraphView::blockDoubleClicked(GraphView::GraphBlock &block, QMo
}
QList<XrefDescription> refs = Core()->getXRefs(instr, false, false);
if (refs.length()) {
sent_seek = false;
Core()->seek(refs.at(0).to);
}
if (refs.length() > 1) {
@ -665,6 +670,7 @@ void DisassemblerGraphView::blockTransitionedTo(GraphView::GraphBlock *to)
seek(to->entry);
}
void DisassemblerGraphView::on_actionExportGraph_triggered()
{
QString fileName = QFileDialog::getSaveFileName(this,
@ -677,8 +683,6 @@ void DisassemblerGraphView::on_actionExportGraph_triggered()
QTextStream fileOut(&file);
fileOut << Core()->cmd("ag -");
}
void DisassemblerGraphView::wheelEvent(QWheelEvent *event)
{
// when CTRL is pressed, we zoom in/out with mouse wheel

View File

@ -171,7 +171,6 @@ private slots:
private:
bool first_draw = true;
bool transition_dont_seek = false;
bool sent_seek = false;
HighlightToken *highlight_token;
// Font data
@ -183,6 +182,8 @@ private:
DisassemblyContextMenu *mMenu;
void connectSeekChanged(bool disconnect);
void initFont();
void prepareGraphNode(GraphBlock &block);
RVA getAddrForMouseEvent(GraphBlock &block, QPoint *point);