From b27cd39ddca670f8d60b3d50d7339ce855a8039d Mon Sep 17 00:00:00 2001 From: xarkes Date: Sun, 13 Jan 2019 19:11:59 +0100 Subject: [PATCH] Added RefreshDeferrer to emulation widgets --- src/MainWindow.cpp | 25 +++++++++++++------------ src/widgets/BacktraceWidget.cpp | 7 +++++++ src/widgets/BacktraceWidget.h | 1 + src/widgets/BreakpointWidget.cpp | 10 +++++++++- src/widgets/BreakpointWidget.h | 2 ++ src/widgets/MemoryMapWidget.cpp | 10 +++++++++- src/widgets/MemoryMapWidget.h | 2 ++ src/widgets/RegisterRefsWidget.cpp | 10 +++++++++- src/widgets/RegisterRefsWidget.h | 2 ++ src/widgets/RegistersWidget.cpp | 9 ++++++++- src/widgets/RegistersWidget.h | 1 + src/widgets/StackWidget.cpp | 10 +++++++++- src/widgets/StackWidget.h | 1 + 13 files changed, 73 insertions(+), 17 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index c1554d05..56a9e929 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -198,12 +198,12 @@ void MainWindow::initUI() commentsDock = new CommentsWidget(this, ui->actionComments); stringsDock = new StringsWidget(this, ui->actionStrings); flagsDock = new FlagsWidget(this, ui->actionFlags); - //stackDock = new StackWidget(this, ui->actionStack); - //backtraceDock = new BacktraceWidget(this, ui->actionBacktrace); - //registersDock = new RegistersWidget(this, ui->actionRegisters); - //memoryMapDock = new MemoryMapWidget(this, ui->actionMemoryMap); - //breakpointDock = new BreakpointWidget(this, ui->actionBreakpoint); - //registerRefsDock = new RegisterRefsWidget(this, ui->actionRegisterRefs); + stackDock = new StackWidget(this, ui->actionStack); + backtraceDock = new BacktraceWidget(this, ui->actionBacktrace); + registersDock = new RegistersWidget(this, ui->actionRegisters); + memoryMapDock = new MemoryMapWidget(this, ui->actionMemoryMap); + breakpointDock = new BreakpointWidget(this, ui->actionBreakpoint); + registerRefsDock = new RegisterRefsWidget(this, ui->actionRegisterRefs); #ifdef CUTTER_ENABLE_JUPYTER jupyterDock = new JupyterWidget(this, ui->actionJupyter); #else @@ -578,13 +578,14 @@ void MainWindow::restoreDocks() tabifyDockWidget(dashboardDock, vTablesDock); // Add Stack, Registers and Backtrace vertically stacked - //addDockWidget(Qt::TopDockWidgetArea, stackDock); - //splitDockWidget(stackDock, registersDock, Qt::Vertical); - //tabifyDockWidget(stackDock, backtraceDock); + addDockWidget(Qt::TopDockWidgetArea, stackDock); + splitDockWidget(stackDock, registersDock, Qt::Vertical); + tabifyDockWidget(stackDock, backtraceDock); + // MemoryMap/Breakpoint/RegRefs widget goes in the center tabs - //tabifyDockWidget(dashboardDock, memoryMapDock); - //tabifyDockWidget(dashboardDock, breakpointDock); - //tabifyDockWidget(dashboardDock, registerRefsDock); + tabifyDockWidget(dashboardDock, memoryMapDock); + tabifyDockWidget(dashboardDock, breakpointDock); + tabifyDockWidget(dashboardDock, registerRefsDock); #ifdef CUTTER_ENABLE_JUPYTER tabifyDockWidget(dashboardDock, jupyterDock); #endif diff --git a/src/widgets/BacktraceWidget.cpp b/src/widgets/BacktraceWidget.cpp index fe6228f4..97946f74 100644 --- a/src/widgets/BacktraceWidget.cpp +++ b/src/widgets/BacktraceWidget.cpp @@ -23,6 +23,10 @@ BacktraceWidget::BacktraceWidget(MainWindow *main, QAction *action) : viewBacktrace->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); ui->verticalLayout->addWidget(viewBacktrace); + refreshDeferrer = createRefreshDeferrer([this]() { + updateContents(); + }); + connect(Core(), &CutterCore::refreshAll, this, &BacktraceWidget::updateContents); connect(Core(), &CutterCore::seekChanged, this, &BacktraceWidget::updateContents); connect(Config(), &Configuration::fontsUpdated, this, &BacktraceWidget::fontsUpdatedSlot); @@ -32,6 +36,9 @@ BacktraceWidget::~BacktraceWidget() {} void BacktraceWidget::updateContents() { + if (!refreshDeferrer->attemptRefresh(nullptr)) { + return; + } setBacktraceGrid(); } diff --git a/src/widgets/BacktraceWidget.h b/src/widgets/BacktraceWidget.h index 977d3c7a..4175f24e 100644 --- a/src/widgets/BacktraceWidget.h +++ b/src/widgets/BacktraceWidget.h @@ -31,4 +31,5 @@ private: std::unique_ptr ui; QStandardItemModel *modelBacktrace = new QStandardItemModel(1, 5, this); QTableView *viewBacktrace = new QTableView; + RefreshDeferrer *refreshDeferrer; }; \ No newline at end of file diff --git a/src/widgets/BreakpointWidget.cpp b/src/widgets/BreakpointWidget.cpp index 803737ba..131d5b63 100644 --- a/src/widgets/BreakpointWidget.cpp +++ b/src/widgets/BreakpointWidget.cpp @@ -122,6 +122,10 @@ BreakpointWidget::BreakpointWidget(MainWindow *main, QAction *action) : ui->breakpointTreeView->setModel(breakpointProxyModel); ui->breakpointTreeView->sortByColumn(BreakpointModel::AddrColumn, Qt::AscendingOrder); + refreshDeferrer = createRefreshDeferrer([this]() { + refreshBreakpoint(); + }); + setScrollMode(); actionDelBreakpoint = new QAction(tr("Delete breakpoint")); actionToggleBreakpoint = new QAction(tr("Toggle breakpoint")); @@ -138,10 +142,14 @@ BreakpointWidget::BreakpointWidget(MainWindow *main, QAction *action) : this, SLOT(showBreakpointContextMenu(const QPoint &))); } -BreakpointWidget::~BreakpointWidget() {} +BreakpointWidget::~BreakpointWidget() = default; void BreakpointWidget::refreshBreakpoint() { + if (!refreshDeferrer->attemptRefresh(nullptr)) { + return; + } + breakpointModel->beginResetModel(); breakpoints = Core()->getBreakpoints(); breakpointModel->endResetModel(); diff --git a/src/widgets/BreakpointWidget.h b/src/widgets/BreakpointWidget.h index 8ab89c5e..e10cf138 100644 --- a/src/widgets/BreakpointWidget.h +++ b/src/widgets/BreakpointWidget.h @@ -84,4 +84,6 @@ private: QAction *actionToggleBreakpoint = nullptr; void setScrollMode(); + + RefreshDeferrer *refreshDeferrer; }; diff --git a/src/widgets/MemoryMapWidget.cpp b/src/widgets/MemoryMapWidget.cpp index 61249657..85ff351f 100644 --- a/src/widgets/MemoryMapWidget.cpp +++ b/src/widgets/MemoryMapWidget.cpp @@ -118,14 +118,22 @@ MemoryMapWidget::MemoryMapWidget(MainWindow *main, QAction *action) : setScrollMode(); + refreshDeferrer = createRefreshDeferrer([this]() { + refreshMemoryMap(); + }); + connect(Core(), &CutterCore::refreshAll, this, &MemoryMapWidget::refreshMemoryMap); connect(Core(), &CutterCore::registersChanged, this, &MemoryMapWidget::refreshMemoryMap); } -MemoryMapWidget::~MemoryMapWidget() {} +MemoryMapWidget::~MemoryMapWidget() = default; void MemoryMapWidget::refreshMemoryMap() { + if (!refreshDeferrer->attemptRefresh(nullptr)) { + return; + } + memoryModel->beginResetModel(); memoryMaps = Core()->getMemoryMap(); memoryModel->endResetModel(); diff --git a/src/widgets/MemoryMapWidget.h b/src/widgets/MemoryMapWidget.h index 24da3d10..45b315f7 100644 --- a/src/widgets/MemoryMapWidget.h +++ b/src/widgets/MemoryMapWidget.h @@ -80,4 +80,6 @@ private: QList memoryMaps; void setScrollMode(); + + RefreshDeferrer *refreshDeferrer; }; diff --git a/src/widgets/RegisterRefsWidget.cpp b/src/widgets/RegisterRefsWidget.cpp index e13e0be6..c6e2ef6e 100644 --- a/src/widgets/RegisterRefsWidget.cpp +++ b/src/widgets/RegisterRefsWidget.cpp @@ -119,6 +119,10 @@ RegisterRefsWidget::RegisterRefsWidget(MainWindow *main, QAction *action) : actionCopyValue = new QAction(tr("Copy register value")); actionCopyRef = new QAction(tr("Copy register reference")); + refreshDeferrer = createRefreshDeferrer([this](){ + refreshRegisterRef(); + }); + // Ctrl-F to show/hide the filter entry QShortcut *search_shortcut = new QShortcut(QKeySequence::Find, this); connect(search_shortcut, &QShortcut::activated, ui->quickFilterView, &QuickFilterView::showFilter); @@ -145,10 +149,14 @@ RegisterRefsWidget::RegisterRefsWidget(MainWindow *main, QAction *action) : }); } -RegisterRefsWidget::~RegisterRefsWidget() {} +RegisterRefsWidget::~RegisterRefsWidget() = default; void RegisterRefsWidget::refreshRegisterRef() { + if (!refreshDeferrer->attemptRefresh(nullptr)) { + return; + } + registerRefModel->beginResetModel(); registerRefs = Core()->getRegisterRefs(); registerRefModel->endResetModel(); diff --git a/src/widgets/RegisterRefsWidget.h b/src/widgets/RegisterRefsWidget.h index b3f4adfb..70782ffe 100644 --- a/src/widgets/RegisterRefsWidget.h +++ b/src/widgets/RegisterRefsWidget.h @@ -83,4 +83,6 @@ private: QAction *actionCopyRef; CutterTreeWidget *tree; void setScrollMode(); + + RefreshDeferrer *refreshDeferrer; }; diff --git a/src/widgets/RegistersWidget.cpp b/src/widgets/RegistersWidget.cpp index 392065e6..944f2f74 100644 --- a/src/widgets/RegistersWidget.cpp +++ b/src/widgets/RegistersWidget.cpp @@ -14,14 +14,21 @@ RegistersWidget::RegistersWidget(MainWindow *main, QAction *action) : registerLayout->setVerticalSpacing(0); ui->verticalLayout->addLayout(registerLayout); + refreshDeferrer = createRefreshDeferrer([this]() { + updateContents(); + }); + connect(Core(), &CutterCore::refreshAll, this, &RegistersWidget::updateContents); connect(Core(), &CutterCore::registersChanged, this, &RegistersWidget::updateContents); } -RegistersWidget::~RegistersWidget() {} +RegistersWidget::~RegistersWidget() = default; void RegistersWidget::updateContents() { + if (!refreshDeferrer->attemptRefresh(nullptr)) { + return; + } setRegisterGrid(); } diff --git a/src/widgets/RegistersWidget.h b/src/widgets/RegistersWidget.h index 360c600a..9846f918 100644 --- a/src/widgets/RegistersWidget.h +++ b/src/widgets/RegistersWidget.h @@ -32,4 +32,5 @@ private: QGridLayout *registerLayout = new QGridLayout; int numCols = 2; int registerLen = 0; + RefreshDeferrer *refreshDeferrer; }; \ No newline at end of file diff --git a/src/widgets/StackWidget.cpp b/src/widgets/StackWidget.cpp index dfc3ff92..b1e5a421 100644 --- a/src/widgets/StackWidget.cpp +++ b/src/widgets/StackWidget.cpp @@ -29,6 +29,10 @@ StackWidget::StackWidget(MainWindow *main, QAction *action) : editAction = new QAction(tr("Edit stack value...")); viewStack->setContextMenuPolicy(Qt::CustomContextMenu); + refreshDeferrer = createRefreshDeferrer([this]() { + updateContents(); + }); + connect(Core(), &CutterCore::refreshAll, this, &StackWidget::updateContents); connect(Core(), &CutterCore::seekChanged, this, &StackWidget::updateContents); connect(Core(), &CutterCore::stackChanged, this, &StackWidget::updateContents); @@ -40,10 +44,14 @@ StackWidget::StackWidget(MainWindow *main, QAction *action) : connect(editAction, &QAction::triggered, this, &StackWidget::editStack); } -StackWidget::~StackWidget() {} +StackWidget::~StackWidget() = default; void StackWidget::updateContents() { + if (!refreshDeferrer->attemptRefresh(nullptr)) { + return; + } + setStackGrid(); } diff --git a/src/widgets/StackWidget.h b/src/widgets/StackWidget.h index 9ec2a48e..09871c71 100644 --- a/src/widgets/StackWidget.h +++ b/src/widgets/StackWidget.h @@ -37,4 +37,5 @@ private: QStandardItemModel *modelStack = new QStandardItemModel(1, 3, this); QAction *seekAction; QAction *editAction; + RefreshDeferrer *refreshDeferrer; }; \ No newline at end of file