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);
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<GraphWidget*>(dockWidget)->getGraphView()->getBlocks().empty();
auto graphWidget = qobject_cast<GraphWidget*>(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<DisassemblyWidget*>(dockWidget);
if (disasmWidget && !dockWidget->visibleRegion().isNull()) {
if (!graphContainsFunc) {
auto disasm = qobject_cast<DisassemblyWidget*>(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<GraphWidget*>(it);
}
if (!disassemblyDock) {
disassemblyDock = qobject_cast<DisassemblyWidget*>(it);
}
if (!hexdumpDock) {
hexdumpDock = qobject_cast<HexdumpWidget*>(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()

View File

@ -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<QDockWidget *> dockWidgets;
QMultiMap<QAction *, QDockWidget *> dockWidgetsOfAction;
DisassemblyWidget *disassemblyDock = nullptr;
HexdumpWidget *hexdumpDock = nullptr;
PseudocodeWidget *pseudocodeDock = nullptr;
GraphWidget *graphDock = nullptr;
OverviewWidget *overviewDock = nullptr;
EntrypointWidget *entrypointDock = nullptr;
FunctionsWidget *functionsDock = nullptr;

View File

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

View File

@ -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();
}

View File

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