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);
signals:
void refreshNow(RefreshDeferrerParamsResult paramsResult);
void refreshNow(const RefreshDeferrerParamsResult paramsResult);
};
#endif //REFRESHDEFERRER_H

View File

@ -3,6 +3,8 @@
#include <QDockWidget>
#include "common/RefreshDeferrer.h"
class MainWindow;
class CutterDockWidget : public QDockWidget
@ -29,6 +31,19 @@ private:
protected:
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

View File

@ -35,14 +35,12 @@ static DisassemblyTextBlockUserData *getUserData(const QTextBlock &block)
return static_cast<DisassemblyTextBlockUserData *>(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<RVA>)
{
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<RVA>([this](const RVA *offset) {
printf("got refresh now!\n");
RVA *offset = static_cast<RVA *>(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;
}

View File

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