Remove Memory Widget Pointers and Toggle Actions

This commit is contained in:
Florian Märkl 2019-06-18 20:22:26 +02:00
parent ede98df6ac
commit c96c72a147
5 changed files with 44 additions and 73 deletions

View File

@ -312,7 +312,11 @@ void MainWindow::initDocks()
vTablesDock = new VTablesWidget(this, ui->actionVTables); vTablesDock = new VTablesWidget(this, ui->actionVTables);
QSettings s; 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 // Restore all extra widgets
QString className; QString className;
@ -328,20 +332,6 @@ void MainWindow::initDocks()
} }
} }
} }
updateMemberPointers();
if (!disassemblyDock) {
addExtraDisassembly();
}
if (!graphDock) {
addExtraGraph();
}
if (!hexdumpDock) {
addExtraHexdump();
}
updateMemberPointers();
} }
void MainWindow::initLayout() void MainWindow::initLayout()
@ -372,19 +362,19 @@ void MainWindow::updateTasksIndicator()
void MainWindow::addExtraGraph() void MainWindow::addExtraGraph()
{ {
auto *extraDock = new GraphWidget(this, ui->actionGraph); auto *extraDock = new GraphWidget(this, nullptr);
addExtraWidget(extraDock); addExtraWidget(extraDock);
} }
void MainWindow::addExtraHexdump() void MainWindow::addExtraHexdump()
{ {
auto *extraDock = new HexdumpWidget(this, ui->actionHexdump); auto *extraDock = new HexdumpWidget(this, nullptr);
addExtraWidget(extraDock); addExtraWidget(extraDock);
} }
void MainWindow::addExtraDisassembly() void MainWindow::addExtraDisassembly()
{ {
auto *extraDock = new DisassemblyWidget(this, ui->actionDisassembly); auto *extraDock = new DisassemblyWidget(this, nullptr);
addExtraWidget(extraDock); addExtraWidget(extraDock);
} }
@ -559,22 +549,21 @@ void MainWindow::finalizeOpen()
// If there are no graph/disasm widgets focus on MainWindow // If there are no graph/disasm widgets focus on MainWindow
setFocus(); setFocus();
const QString disasmWidgetClassName = disassemblyDock->metaObject()->className();
const QString graphWidgetClassName = graphDock->metaObject()->className();
bool graphContainsFunc = false; bool graphContainsFunc = false;
for (auto dockWidget : dockWidgets) { for (auto dockWidget : dockWidgets) {
const QString className = dockWidget->metaObject()->className(); const QString className = dockWidget->metaObject()->className();
if (className == graphWidgetClassName && !dockWidget->visibleRegion().isNull()) { auto graphWidget = qobject_cast<GraphWidget*>(dockWidget);
graphContainsFunc = !qobject_cast<GraphWidget*>(dockWidget)->getGraphView()->getBlocks().empty(); if (graphWidget && !dockWidget->visibleRegion().isNull()) {
graphContainsFunc = !graphWidget->getGraphView()->getBlocks().empty();
if (graphContainsFunc) { if (graphContainsFunc) {
dockWidget->widget()->setFocus(); dockWidget->widget()->setFocus();
break; break;
} }
} }
if (className == disasmWidgetClassName && !dockWidget->visibleRegion().isNull()) { auto disasmWidget = qobject_cast<DisassemblyWidget*>(dockWidget);
if (disasmWidget && !dockWidget->visibleRegion().isNull()) {
if (!graphContainsFunc) { if (!graphContainsFunc) {
auto disasm = qobject_cast<DisassemblyWidget*>(dockWidget); disasmWidget->setFocus();
disasm->setFocus();
} else { } else {
break; break;
} }
@ -890,22 +879,6 @@ void MainWindow::initCorners()
setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea); setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
} }
void MainWindow::updateMemberPointers()
{
QString className;
for (auto it : dockWidgets) {
if (!graphDock) {
graphDock = qobject_cast<GraphWidget*>(it);
}
if (!disassemblyDock) {
disassemblyDock = qobject_cast<DisassemblyWidget*>(it);
}
if (!hexdumpDock) {
hexdumpDock = qobject_cast<HexdumpWidget*>(it);
}
}
}
void MainWindow::addWidget(QDockWidget* widget) void MainWindow::addWidget(QDockWidget* widget)
{ {
dockWidgets.push_back(widget); dockWidgets.push_back(widget);
@ -918,12 +891,16 @@ void MainWindow::addWidget(QDockWidget* widget)
for (auto action : widget->actions()) { for (auto action : widget->actions()) {
dockWidgetsOfAction.remove(action, widget); dockWidgetsOfAction.remove(action, widget);
} }
updateMemberPointers();
updateDockActionsChecked(); updateDockActionsChecked();
}); });
} }
} }
void MainWindow::removeWidget(QDockWidget *widget)
{
dockWidgets.removeAll(widget);
}
void MainWindow::updateDockActionChecked(QAction *action) void MainWindow::updateDockActionChecked(QAction *action)
{ {
auto actions = dockWidgetsOfAction.values(action); auto actions = dockWidgetsOfAction.values(action);
@ -1036,7 +1013,6 @@ void MainWindow::resetDockWidgetList()
for (auto it : toClose) { for (auto it : toClose) {
it->close(); it->close();
} }
updateMemberPointers();
} }
void MainWindow::on_actionLock_triggered() void MainWindow::on_actionLock_triggered()

View File

@ -94,7 +94,8 @@ public:
void setFilename(const QString &fn); void setFilename(const QString &fn);
void refreshOmniBar(const QStringList &flags); void refreshOmniBar(const QStringList &flags);
void addWidget(QDockWidget* widget); void addWidget(QDockWidget *widget);
void removeWidget(QDockWidget *widget);
void addExtraWidget(CutterDockWidget *extraDock); void addExtraWidget(CutterDockWidget *extraDock);
void addPluginDockWidget(QDockWidget *dockWidget, QAction *action); void addPluginDockWidget(QDockWidget *dockWidget, QAction *action);
@ -211,10 +212,7 @@ private:
QList<QDockWidget *> dockWidgets; QList<QDockWidget *> dockWidgets;
QMultiMap<QAction *, QDockWidget *> dockWidgetsOfAction; QMultiMap<QAction *, QDockWidget *> dockWidgetsOfAction;
DisassemblyWidget *disassemblyDock = nullptr;
HexdumpWidget *hexdumpDock = nullptr;
PseudocodeWidget *pseudocodeDock = nullptr; PseudocodeWidget *pseudocodeDock = nullptr;
GraphWidget *graphDock = nullptr;
OverviewWidget *overviewDock = nullptr; OverviewWidget *overviewDock = nullptr;
EntrypointWidget *entrypointDock = nullptr; EntrypointWidget *entrypointDock = nullptr;
FunctionsWidget *functionsDock = nullptr; FunctionsWidget *functionsDock = nullptr;

View File

@ -20,8 +20,7 @@
<string notr="true">Cutter</string> <string notr="true">Cutter</string>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true"> <string notr="true"/>
</string>
</property> </property>
<property name="documentMode"> <property name="documentMode">
<bool>true</bool> <bool>true</bool>
@ -54,8 +53,8 @@
<rect> <rect>
<x>378</x> <x>378</x>
<y>100</y> <y>100</y>
<width>162</width> <width>156</width>
<height>260</height> <height>220</height>
</rect> </rect>
</property> </property>
<property name="title"> <property name="title">
@ -112,14 +111,6 @@
<property name="title"> <property name="title">
<string>Windows</string> <string>Windows</string>
</property> </property>
<widget class="QMenu" name="menuAddExtraWidget">
<property name="title">
<string>Add extra...</string>
</property>
<addaction name="actionExtraDisassembly"/>
<addaction name="actionExtraGraph"/>
<addaction name="actionExtraHexdump"/>
</widget>
<widget class="QMenu" name="menuPlugins"> <widget class="QMenu" name="menuPlugins">
<property name="title"> <property name="title">
<string>Plugins</string> <string>Plugins</string>
@ -157,8 +148,6 @@
</widget> </widget>
<addaction name="actionDashboard"/> <addaction name="actionDashboard"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionDisassembly"/>
<addaction name="actionGraph"/>
<addaction name="actionFunctions"/> <addaction name="actionFunctions"/>
<addaction name="actionHexdump"/> <addaction name="actionHexdump"/>
<addaction name="actionPseudocode"/> <addaction name="actionPseudocode"/>
@ -168,13 +157,16 @@
<addaction name="actionStrings"/> <addaction name="actionStrings"/>
<addaction name="actionTypes"/> <addaction name="actionTypes"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionExtraDisassembly"/>
<addaction name="actionExtraGraph"/>
<addaction name="actionExtraHexdump"/>
<addaction name="separator"/>
<addaction name="menuAddInfoWidgets"/> <addaction name="menuAddInfoWidgets"/>
<addaction name="menuAddDebugWidgets"/> <addaction name="menuAddDebugWidgets"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionComments"/> <addaction name="actionComments"/>
<addaction name="actionConsole"/> <addaction name="actionConsole"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="menuAddExtraWidget"/>
<addaction name="menuPlugins"/> <addaction name="menuPlugins"/>
</widget> </widget>
<widget class="QMenu" name="menuDebug"> <widget class="QMenu" name="menuDebug">
@ -352,7 +344,7 @@
</action> </action>
<action name="actionBackward"> <action name="actionBackward">
<property name="icon"> <property name="icon">
<iconset resource="resources.qrc"> <iconset>
<normaloff>:/img/icons/arrow_left.svg</normaloff>:/img/icons/arrow_left.svg</iconset> <normaloff>:/img/icons/arrow_left.svg</normaloff>:/img/icons/arrow_left.svg</iconset>
</property> </property>
<property name="text"> <property name="text">
@ -364,7 +356,7 @@
</action> </action>
<action name="actionForward"> <action name="actionForward">
<property name="icon"> <property name="icon">
<iconset resource="resources.qrc"> <iconset>
<normaloff>:/img/icons/arrow_right.svg</normaloff>:/img/icons/arrow_right.svg</iconset> <normaloff>:/img/icons/arrow_right.svg</normaloff>:/img/icons/arrow_right.svg</iconset>
</property> </property>
<property name="text"> <property name="text">
@ -393,7 +385,7 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="resources.qrc"> <iconset>
<normaloff>:/unlock</normaloff>:/unlock</iconset> <normaloff>:/unlock</normaloff>:/unlock</iconset>
</property> </property>
<property name="text"> <property name="text">
@ -507,7 +499,7 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="resources.qrc"> <iconset>
<normaloff>:/img/icons/themes.svg</normaloff>:/img/icons/themes.svg</iconset> <normaloff>:/img/icons/themes.svg</normaloff>:/img/icons/themes.svg</iconset>
</property> </property>
<property name="text"> <property name="text">
@ -522,7 +514,7 @@
</action> </action>
<action name="actionTabs"> <action name="actionTabs">
<property name="icon"> <property name="icon">
<iconset resource="resources.qrc"> <iconset>
<normaloff>:/img/icons/tabs.svg</normaloff>:/img/icons/tabs.svg</iconset> <normaloff>:/img/icons/tabs.svg</normaloff>:/img/icons/tabs.svg</iconset>
</property> </property>
<property name="text"> <property name="text">
@ -534,7 +526,7 @@
</action> </action>
<action name="actionRefresh_Panels"> <action name="actionRefresh_Panels">
<property name="icon"> <property name="icon">
<iconset resource="resources.qrc"> <iconset>
<normaloff>:/img/icons/spin.svg</normaloff>:/img/icons/spin.svg</iconset> <normaloff>:/img/icons/spin.svg</normaloff>:/img/icons/spin.svg</iconset>
</property> </property>
<property name="text"> <property name="text">
@ -690,7 +682,7 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="resources.qrc"> <iconset>
<normaloff>:/img/icons/cloud.svg</normaloff>:/img/icons/cloud.svg</iconset> <normaloff>:/img/icons/cloud.svg</normaloff>:/img/icons/cloud.svg</iconset>
</property> </property>
<property name="text"> <property name="text">
@ -770,7 +762,7 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="resources.qrc"> <iconset>
<normaloff>:/img/icons/down.svg</normaloff>:/img/icons/down.svg</iconset> <normaloff>:/img/icons/down.svg</normaloff>:/img/icons/down.svg</iconset>
</property> </property>
<property name="text"> <property name="text">
@ -1073,17 +1065,17 @@
</action> </action>
<action name="actionExtraHexdump"> <action name="actionExtraHexdump">
<property name="text"> <property name="text">
<string>Hexdump view</string> <string>Add Hexdump</string>
</property> </property>
</action> </action>
<action name="actionExtraDisassembly"> <action name="actionExtraDisassembly">
<property name="text"> <property name="text">
<string>Disassembly view</string> <string>Add Disassembly</string>
</property> </property>
</action> </action>
<action name="actionExtraGraph"> <action name="actionExtraGraph">
<property name="text"> <property name="text">
<string>Graph view</string> <string>Add Graph</string>
</property> </property>
</action> </action>
<action name="actionGrouped_dock_dragging"> <action name="actionGrouped_dock_dragging">

View File

@ -6,6 +6,7 @@
CutterDockWidget::CutterDockWidget(MainWindow *parent, QAction *action) : CutterDockWidget::CutterDockWidget(MainWindow *parent, QAction *action) :
QDockWidget(parent), QDockWidget(parent),
mainWindow(parent),
action(action) action(action)
{ {
if (action) { if (action) {
@ -71,6 +72,9 @@ void CutterDockWidget::closeEvent(QCloseEvent *event)
} }
QDockWidget::closeEvent(event); QDockWidget::closeEvent(event);
if (isTransient) { if (isTransient) {
if (mainWindow) {
mainWindow->removeWidget(this);
}
deleteLater(); deleteLater();
} }

View File

@ -69,6 +69,7 @@ protected:
QAction *getBoundAction() const; QAction *getBoundAction() const;
private: private:
MainWindow *mainWindow;
QAction *action; QAction *action;
bool isTransient = false; bool isTransient = false;