Add createReplacingRefreshDeferrer for convenience

This commit is contained in:
Florian Märkl 2019-01-13 12:40:54 +01:00 committed by xarkes
parent b8c92a460d
commit d651a0d8be
4 changed files with 19 additions and 8 deletions

View File

@ -77,7 +77,7 @@ public:
void registerFor(CutterDockWidget *dockWidget); void registerFor(CutterDockWidget *dockWidget);
signals: signals:
void refreshNow(RefreshDeferrerParamsResult paramsResult); void refreshNow(const RefreshDeferrerParamsResult paramsResult);
}; };
#endif //REFRESHDEFERRER_H #endif //REFRESHDEFERRER_H

View File

@ -3,6 +3,8 @@
#include <QDockWidget> #include <QDockWidget>
#include "common/RefreshDeferrer.h"
class MainWindow; class MainWindow;
class CutterDockWidget : public QDockWidget class CutterDockWidget : public QDockWidget
@ -29,6 +31,19 @@ private:
protected: protected:
void closeEvent(QCloseEvent *event) override; void closeEvent(QCloseEvent *event) override;
template<class ParamResult, typename Func>
RefreshDeferrer *createReplacingRefreshDeferrer(Func refreshNowFunc)
{
auto *deferrer = new RefreshDeferrer(new ReplacingRefreshDeferrerAccumulator<ParamResult>(), this);
deferrer->registerFor(this);
connect(deferrer, &RefreshDeferrer::refreshNow, this, [refreshNowFunc](const RefreshDeferrerParamsResult paramsResult) {
printf("got refresh now!\n");
auto *offset = static_cast<const ParamResult *>(paramsResult);
refreshNowFunc(offset);
});
return deferrer;
}
}; };
#endif // CUTTERWIDGET_H #endif // CUTTERWIDGET_H

View File

@ -35,14 +35,12 @@ static DisassemblyTextBlockUserData *getUserData(const QTextBlock &block)
return static_cast<DisassemblyTextBlockUserData *>(userData); return static_cast<DisassemblyTextBlockUserData *>(userData);
} }
DisassemblyWidget::DisassemblyWidget(MainWindow *main, QAction *action) DisassemblyWidget::DisassemblyWidget(MainWindow *main, QAction *action)
: CutterDockWidget(main, action) : CutterDockWidget(main, action)
, mCtxMenu(new DisassemblyContextMenu(this)) , mCtxMenu(new DisassemblyContextMenu(this))
, mDisasScrollArea(new DisassemblyScrollArea(this)) , mDisasScrollArea(new DisassemblyScrollArea(this))
, mDisasTextEdit(new DisassemblyTextEdit(this)) , mDisasTextEdit(new DisassemblyTextEdit(this))
, seekable(new CutterSeekable(this)) , seekable(new CutterSeekable(this))
, disasmRefresh(new ReplacingRefreshDeferrerAccumulator<RVA>)
{ {
topOffset = bottomOffset = RVA_INVALID; topOffset = bottomOffset = RVA_INVALID;
cursorLineOffset = 0; cursorLineOffset = 0;
@ -64,10 +62,8 @@ DisassemblyWidget::DisassemblyWidget(MainWindow *main, QAction *action)
setupFonts(); setupFonts();
setupColors(); setupColors();
disasmRefresh.registerFor(this); disasmRefresh = createReplacingRefreshDeferrer<RVA>([this](const RVA *offset) {
connect(&disasmRefresh, &RefreshDeferrer::refreshNow, this, [this](RefreshDeferrerParamsResult paramsResult) {
printf("got refresh now!\n"); printf("got refresh now!\n");
RVA *offset = static_cast<RVA *>(paramsResult);
refreshDisasm(*offset); refreshDisasm(*offset);
}); });
@ -203,7 +199,7 @@ QWidget *DisassemblyWidget::getTextWidget()
void DisassemblyWidget::refreshDisasm(RVA offset) 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"); printf("we tried to refresh, but shouldn't yet.\n");
return; return;
} }

View File

@ -59,7 +59,7 @@ private:
int cursorLineOffset; int cursorLineOffset;
bool seekFromCursor; bool seekFromCursor;
RefreshDeferrer disasmRefresh; RefreshDeferrer *disasmRefresh;
RVA readCurrentDisassemblyOffset(); RVA readCurrentDisassemblyOffset();
RVA readDisassemblyOffset(QTextCursor tc); RVA readDisassemblyOffset(QTextCursor tc);