From 06da378362e7d3e73367ce3cc4a1580ecb70a6ce Mon Sep 17 00:00:00 2001 From: xarkes Date: Sun, 13 Jan 2019 16:41:08 +0100 Subject: [PATCH] Readded SectionWidget with RefreshDeferrer --- src/MainWindow.cpp | 6 +++--- src/common/RefreshDeferrer.cpp | 2 +- src/widgets/CommentsWidget.cpp | 11 ++++++----- src/widgets/CutterDockWidget.cpp | 2 +- src/widgets/PseudocodeWidget.cpp | 3 ++- src/widgets/SectionsWidget.cpp | 16 +++++++++++++--- src/widgets/SectionsWidget.h | 2 ++ 7 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index e6cbc8e8..d5038e0a 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -177,13 +177,13 @@ void MainWindow::initUI() disassemblyDock = new DisassemblyWidget(this, ui->actionDisassembly); hexdumpDock = new HexdumpWidget(this, ui->actionHexdump); - //pseudocodeDock = new PseudocodeWidget(this, ui->actionPseudocode); + pseudocodeDock = new PseudocodeWidget(this, ui->actionPseudocode); consoleDock = new ConsoleWidget(this, ui->actionConsole); // Add graph view as dockable graphDock = new GraphWidget(this, ui->actionGraph); - //sectionsDock = new SectionsWidget(this, ui->actionSections); + sectionsDock = new SectionsWidget(this, ui->actionSections); //segmentsDock = new SegmentsWidget(this, ui->actionSegments); //entrypointDock = new EntrypointWidget(this, ui->actionEntrypoints); functionsDock = new FunctionsWidget(this, ui->actionFunctions); @@ -195,7 +195,7 @@ void MainWindow::initUI() //searchDock = new SearchWidget(this, ui->actionSearch); //symbolsDock = new SymbolsWidget(this, ui->actionSymbols); //relocsDock = new RelocsWidget(this, ui->actionRelocs); - //commentsDock = new CommentsWidget(this, ui->actionComments); + commentsDock = new CommentsWidget(this, ui->actionComments); //stringsDock = new StringsWidget(this, ui->actionStrings); //flagsDock = new FlagsWidget(this, ui->actionFlags); //stackDock = new StackWidget(this, ui->actionStack); diff --git a/src/common/RefreshDeferrer.cpp b/src/common/RefreshDeferrer.cpp index c89ffa86..3cf4c4e6 100644 --- a/src/common/RefreshDeferrer.cpp +++ b/src/common/RefreshDeferrer.cpp @@ -32,7 +32,7 @@ void RefreshDeferrer::registerFor(CutterDockWidget *dockWidget) { this->dockWidget = dockWidget; connect(dockWidget, &CutterDockWidget::becameVisibleToUser, this, [this]() { - if(dirty) { + if (dirty) { emit refreshNow(acc ? acc->result() : nullptr); if (acc) { acc->clear(); diff --git a/src/widgets/CommentsWidget.cpp b/src/widgets/CommentsWidget.cpp index 1d2f530a..4d99eb81 100644 --- a/src/widgets/CommentsWidget.cpp +++ b/src/widgets/CommentsWidget.cpp @@ -29,17 +29,18 @@ void CommentsModel::setNested(bool nested) QModelIndex CommentsModel::index(int row, int column, const QModelIndex &parent) const { - if (!parent.isValid()) - return createIndex(row, column, (quintptr)0); + if (!parent.isValid()) { + return createIndex(row, column, (quintptr) 0); + } return createIndex(row, column, (quintptr)(parent.row() + 1)); } -QModelIndex CommentsModel::parent(const QModelIndex &index) const -{ +QModelIndex CommentsModel::parent(const QModelIndex &index) const { /* Ignore invalid indexes and root nodes */ - if (!index.isValid() || index.internalId() == 0) + if (!index.isValid() || index.internalId() == 0) { return QModelIndex(); + } return this->index((int)(index.internalId() - 1), 0); } diff --git a/src/widgets/CutterDockWidget.cpp b/src/widgets/CutterDockWidget.cpp index 12f995ea..f7850bb7 100644 --- a/src/widgets/CutterDockWidget.cpp +++ b/src/widgets/CutterDockWidget.cpp @@ -17,7 +17,7 @@ CutterDockWidget::CutterDockWidget(MainWindow *main, QAction *action) : updateIsVisibleToUser(); } -CutterDockWidget::~CutterDockWidget() {} +CutterDockWidget::~CutterDockWidget() = default; bool CutterDockWidget::eventFilter(QObject *object, QEvent *event) { diff --git a/src/widgets/PseudocodeWidget.cpp b/src/widgets/PseudocodeWidget.cpp index eab0305f..a1ee7648 100644 --- a/src/widgets/PseudocodeWidget.cpp +++ b/src/widgets/PseudocodeWidget.cpp @@ -30,6 +30,7 @@ PseudocodeWidget::PseudocodeWidget(MainWindow *main, QAction *action) : } }); + // TODO Use RefreshDeferrer and remove the refresh button connect(ui->refreshButton, &QAbstractButton::clicked, this, [this]() { doRefresh(Core()->getOffset()); }); @@ -45,7 +46,7 @@ PseudocodeWidget::PseudocodeWidget(MainWindow *main, QAction *action) : doRefresh(RVA_INVALID); } -PseudocodeWidget::~PseudocodeWidget() {} +PseudocodeWidget::~PseudocodeWidget() = default; void PseudocodeWidget::doRefresh(RVA addr) diff --git a/src/widgets/SectionsWidget.cpp b/src/widgets/SectionsWidget.cpp index 5461324d..be2df909 100644 --- a/src/widgets/SectionsWidget.cpp +++ b/src/widgets/SectionsWidget.cpp @@ -45,8 +45,9 @@ QVariant SectionsModel::data(const QModelIndex &index, int role) const QColor("#95A5A6") //COBCRETE }; - if (index.row() >= sections->count()) + if (index.row() >= sections->count()) { return QVariant(); + } const SectionDescription §ion = sections->at(index.row()); @@ -142,13 +143,17 @@ SectionsWidget::SectionsWidget(MainWindow *main, QAction *action) : setWindowTitle(QStringLiteral("Sections")); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + refreshDeferrer = createRefreshDeferrer([this]() { + drawIndicatorOnAddrDocks(); + }); + initSectionsTable(); initQuickFilter(); initAddrMapDocks(); initConnects(); } -SectionsWidget::~SectionsWidget() {} +SectionsWidget::~SectionsWidget() = default; void SectionsWidget::initSectionsTable() { @@ -260,8 +265,9 @@ void SectionsWidget::refreshSections() void SectionsWidget::onSectionsDoubleClicked(const QModelIndex &index) { - if (!index.isValid()) + if (!index.isValid()) { return; + } auto section = index.data(SectionsModel::SectionDescriptionRole).value(); Core()->seek(section.vaddr); @@ -277,6 +283,10 @@ void SectionsWidget::onSectionsSeekChanged(RVA addr) void SectionsWidget::drawIndicatorOnAddrDocks() { + if (!refreshDeferrer->attemptRefresh(nullptr)) { + return; + } + RVA offset = Core()->getOffset(); for (int i = 0; i != virtualAddrDock->proxyModel->rowCount(); i++) { QModelIndex idx = virtualAddrDock->proxyModel->index(i, 0); diff --git a/src/widgets/SectionsWidget.h b/src/widgets/SectionsWidget.h index 5049cbd6..30dba68a 100644 --- a/src/widgets/SectionsWidget.h +++ b/src/widgets/SectionsWidget.h @@ -82,6 +82,8 @@ private: QWidget *dockWidgetContents; QuickFilterView *quickFilterView; + RefreshDeferrer *refreshDeferrer; + QWidget *addrDockWidget; RawAddrDock *rawAddrDock; VirtualAddrDock *virtualAddrDock;