From d651a0d8be94e9b7f0974e04c398d3f945202ff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Sun, 13 Jan 2019 12:40:54 +0100 Subject: [PATCH] Add createReplacingRefreshDeferrer for convenience --- src/common/RefreshDeferrer.h | 2 +- src/widgets/CutterDockWidget.h | 15 +++++++++++++++ src/widgets/DisassemblyWidget.cpp | 8 ++------ src/widgets/DisassemblyWidget.h | 2 +- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/common/RefreshDeferrer.h b/src/common/RefreshDeferrer.h index 74f3a452..6932e022 100644 --- a/src/common/RefreshDeferrer.h +++ b/src/common/RefreshDeferrer.h @@ -77,7 +77,7 @@ public: void registerFor(CutterDockWidget *dockWidget); signals: - void refreshNow(RefreshDeferrerParamsResult paramsResult); + void refreshNow(const RefreshDeferrerParamsResult paramsResult); }; #endif //REFRESHDEFERRER_H diff --git a/src/widgets/CutterDockWidget.h b/src/widgets/CutterDockWidget.h index 27fcb080..e643e6d4 100644 --- a/src/widgets/CutterDockWidget.h +++ b/src/widgets/CutterDockWidget.h @@ -3,6 +3,8 @@ #include +#include "common/RefreshDeferrer.h" + class MainWindow; class CutterDockWidget : public QDockWidget @@ -29,6 +31,19 @@ private: protected: void closeEvent(QCloseEvent *event) override; + + template + RefreshDeferrer *createReplacingRefreshDeferrer(Func refreshNowFunc) + { + auto *deferrer = new RefreshDeferrer(new ReplacingRefreshDeferrerAccumulator(), this); + deferrer->registerFor(this); + connect(deferrer, &RefreshDeferrer::refreshNow, this, [refreshNowFunc](const RefreshDeferrerParamsResult paramsResult) { + printf("got refresh now!\n"); + auto *offset = static_cast(paramsResult); + refreshNowFunc(offset); + }); + return deferrer; + } }; #endif // CUTTERWIDGET_H diff --git a/src/widgets/DisassemblyWidget.cpp b/src/widgets/DisassemblyWidget.cpp index dadcb1d1..84e2f3a8 100644 --- a/src/widgets/DisassemblyWidget.cpp +++ b/src/widgets/DisassemblyWidget.cpp @@ -35,14 +35,12 @@ static DisassemblyTextBlockUserData *getUserData(const QTextBlock &block) return static_cast(userData); } - DisassemblyWidget::DisassemblyWidget(MainWindow *main, QAction *action) : CutterDockWidget(main, action) , mCtxMenu(new DisassemblyContextMenu(this)) , mDisasScrollArea(new DisassemblyScrollArea(this)) , mDisasTextEdit(new DisassemblyTextEdit(this)) , seekable(new CutterSeekable(this)) - , disasmRefresh(new ReplacingRefreshDeferrerAccumulator) { topOffset = bottomOffset = RVA_INVALID; cursorLineOffset = 0; @@ -64,10 +62,8 @@ DisassemblyWidget::DisassemblyWidget(MainWindow *main, QAction *action) setupFonts(); setupColors(); - disasmRefresh.registerFor(this); - connect(&disasmRefresh, &RefreshDeferrer::refreshNow, this, [this](RefreshDeferrerParamsResult paramsResult) { + disasmRefresh = createReplacingRefreshDeferrer([this](const RVA *offset) { printf("got refresh now!\n"); - RVA *offset = static_cast(paramsResult); refreshDisasm(*offset); }); @@ -203,7 +199,7 @@ QWidget *DisassemblyWidget::getTextWidget() void DisassemblyWidget::refreshDisasm(RVA offset) { - if(!disasmRefresh.attemptRefresh(new RVA(offset))) { + if(!disasmRefresh->attemptRefresh(new RVA(offset))) { printf("we tried to refresh, but shouldn't yet.\n"); return; } diff --git a/src/widgets/DisassemblyWidget.h b/src/widgets/DisassemblyWidget.h index ea77334d..4912eb8a 100644 --- a/src/widgets/DisassemblyWidget.h +++ b/src/widgets/DisassemblyWidget.h @@ -59,7 +59,7 @@ private: int cursorLineOffset; bool seekFromCursor; - RefreshDeferrer disasmRefresh; + RefreshDeferrer *disasmRefresh; RVA readCurrentDisassemblyOffset(); RVA readDisassemblyOffset(QTextCursor tc);