From c96c72a1471b2b252dfac2d89e98bb736af3a219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Tue, 18 Jun 2019 20:22:26 +0200 Subject: [PATCH] Remove Memory Widget Pointers and Toggle Actions --- src/core/MainWindow.cpp | 62 ++++++++++---------------------- src/core/MainWindow.h | 6 ++-- src/core/MainWindow.ui | 44 ++++++++++------------- src/widgets/CutterDockWidget.cpp | 4 +++ src/widgets/CutterDockWidget.h | 1 + 5 files changed, 44 insertions(+), 73 deletions(-) diff --git a/src/core/MainWindow.cpp b/src/core/MainWindow.cpp index 9fa587e7..a33045e5 100644 --- a/src/core/MainWindow.cpp +++ b/src/core/MainWindow.cpp @@ -312,7 +312,11 @@ void MainWindow::initDocks() vTablesDock = new VTablesWidget(this, ui->actionVTables); QSettings s; - QStringList docks = s.value("docks", QStringList { GraphWidget::getWidgetType() }).toStringList(); + QStringList docks = s.value("docks", QStringList { + DisassemblyWidget::getWidgetType(), + GraphWidget::getWidgetType(), + HexdumpWidget::getWidgetType() + }).toStringList(); // Restore all extra widgets QString className; @@ -328,20 +332,6 @@ void MainWindow::initDocks() } } } - - updateMemberPointers(); - - if (!disassemblyDock) { - addExtraDisassembly(); - } - if (!graphDock) { - addExtraGraph(); - } - if (!hexdumpDock) { - addExtraHexdump(); - } - - updateMemberPointers(); } void MainWindow::initLayout() @@ -372,19 +362,19 @@ void MainWindow::updateTasksIndicator() void MainWindow::addExtraGraph() { - auto *extraDock = new GraphWidget(this, ui->actionGraph); + auto *extraDock = new GraphWidget(this, nullptr); addExtraWidget(extraDock); } void MainWindow::addExtraHexdump() { - auto *extraDock = new HexdumpWidget(this, ui->actionHexdump); + auto *extraDock = new HexdumpWidget(this, nullptr); addExtraWidget(extraDock); } void MainWindow::addExtraDisassembly() { - auto *extraDock = new DisassemblyWidget(this, ui->actionDisassembly); + auto *extraDock = new DisassemblyWidget(this, nullptr); addExtraWidget(extraDock); } @@ -559,22 +549,21 @@ void MainWindow::finalizeOpen() // If there are no graph/disasm widgets focus on MainWindow setFocus(); - const QString disasmWidgetClassName = disassemblyDock->metaObject()->className(); - const QString graphWidgetClassName = graphDock->metaObject()->className(); bool graphContainsFunc = false; for (auto dockWidget : dockWidgets) { const QString className = dockWidget->metaObject()->className(); - if (className == graphWidgetClassName && !dockWidget->visibleRegion().isNull()) { - graphContainsFunc = !qobject_cast(dockWidget)->getGraphView()->getBlocks().empty(); + auto graphWidget = qobject_cast(dockWidget); + if (graphWidget && !dockWidget->visibleRegion().isNull()) { + graphContainsFunc = !graphWidget->getGraphView()->getBlocks().empty(); if (graphContainsFunc) { dockWidget->widget()->setFocus(); break; } } - if (className == disasmWidgetClassName && !dockWidget->visibleRegion().isNull()) { + auto disasmWidget = qobject_cast(dockWidget); + if (disasmWidget && !dockWidget->visibleRegion().isNull()) { if (!graphContainsFunc) { - auto disasm = qobject_cast(dockWidget); - disasm->setFocus(); + disasmWidget->setFocus(); } else { break; } @@ -890,22 +879,6 @@ void MainWindow::initCorners() setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea); } -void MainWindow::updateMemberPointers() -{ - QString className; - for (auto it : dockWidgets) { - if (!graphDock) { - graphDock = qobject_cast(it); - } - if (!disassemblyDock) { - disassemblyDock = qobject_cast(it); - } - if (!hexdumpDock) { - hexdumpDock = qobject_cast(it); - } - } -} - void MainWindow::addWidget(QDockWidget* widget) { dockWidgets.push_back(widget); @@ -918,12 +891,16 @@ void MainWindow::addWidget(QDockWidget* widget) for (auto action : widget->actions()) { dockWidgetsOfAction.remove(action, widget); } - updateMemberPointers(); updateDockActionsChecked(); }); } } +void MainWindow::removeWidget(QDockWidget *widget) +{ + dockWidgets.removeAll(widget); +} + void MainWindow::updateDockActionChecked(QAction *action) { auto actions = dockWidgetsOfAction.values(action); @@ -1036,7 +1013,6 @@ void MainWindow::resetDockWidgetList() for (auto it : toClose) { it->close(); } - updateMemberPointers(); } void MainWindow::on_actionLock_triggered() diff --git a/src/core/MainWindow.h b/src/core/MainWindow.h index 42ba25c4..76fd11b8 100644 --- a/src/core/MainWindow.h +++ b/src/core/MainWindow.h @@ -94,7 +94,8 @@ public: void setFilename(const QString &fn); void refreshOmniBar(const QStringList &flags); - void addWidget(QDockWidget* widget); + void addWidget(QDockWidget *widget); + void removeWidget(QDockWidget *widget); void addExtraWidget(CutterDockWidget *extraDock); void addPluginDockWidget(QDockWidget *dockWidget, QAction *action); @@ -211,10 +212,7 @@ private: QList dockWidgets; QMultiMap dockWidgetsOfAction; - DisassemblyWidget *disassemblyDock = nullptr; - HexdumpWidget *hexdumpDock = nullptr; PseudocodeWidget *pseudocodeDock = nullptr; - GraphWidget *graphDock = nullptr; OverviewWidget *overviewDock = nullptr; EntrypointWidget *entrypointDock = nullptr; FunctionsWidget *functionsDock = nullptr; diff --git a/src/core/MainWindow.ui b/src/core/MainWindow.ui index 51812b5a..0f96babe 100644 --- a/src/core/MainWindow.ui +++ b/src/core/MainWindow.ui @@ -20,8 +20,7 @@ Cutter - - + true @@ -54,8 +53,8 @@ 378 100 - 162 - 260 + 156 + 220 @@ -112,14 +111,6 @@ Windows - - - Add extra... - - - - - Plugins @@ -157,8 +148,6 @@ - - @@ -168,13 +157,16 @@ + + + + - @@ -352,7 +344,7 @@ - + :/img/icons/arrow_left.svg:/img/icons/arrow_left.svg @@ -364,7 +356,7 @@ - + :/img/icons/arrow_right.svg:/img/icons/arrow_right.svg @@ -393,7 +385,7 @@ true - + :/unlock:/unlock @@ -507,7 +499,7 @@ false - + :/img/icons/themes.svg:/img/icons/themes.svg @@ -522,7 +514,7 @@ - + :/img/icons/tabs.svg:/img/icons/tabs.svg @@ -534,7 +526,7 @@ - + :/img/icons/spin.svg:/img/icons/spin.svg @@ -690,7 +682,7 @@ true - + :/img/icons/cloud.svg:/img/icons/cloud.svg @@ -770,7 +762,7 @@ true - + :/img/icons/down.svg:/img/icons/down.svg @@ -1073,17 +1065,17 @@ - Hexdump view + Add Hexdump - Disassembly view + Add Disassembly - Graph view + Add Graph diff --git a/src/widgets/CutterDockWidget.cpp b/src/widgets/CutterDockWidget.cpp index 6b925be2..26cf0b87 100644 --- a/src/widgets/CutterDockWidget.cpp +++ b/src/widgets/CutterDockWidget.cpp @@ -6,6 +6,7 @@ CutterDockWidget::CutterDockWidget(MainWindow *parent, QAction *action) : QDockWidget(parent), + mainWindow(parent), action(action) { if (action) { @@ -71,6 +72,9 @@ void CutterDockWidget::closeEvent(QCloseEvent *event) } QDockWidget::closeEvent(event); if (isTransient) { + if (mainWindow) { + mainWindow->removeWidget(this); + } deleteLater(); } diff --git a/src/widgets/CutterDockWidget.h b/src/widgets/CutterDockWidget.h index 96a9bfdb..a800b052 100644 --- a/src/widgets/CutterDockWidget.h +++ b/src/widgets/CutterDockWidget.h @@ -69,6 +69,7 @@ protected: QAction *getBoundAction() const; private: + MainWindow *mainWindow; QAction *action; bool isTransient = false;