Skip to content

Commit

Permalink
Debugger: Add support for multiple UI layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoticgd committed Feb 11, 2025
1 parent ecd2fd0 commit ef51360
Show file tree
Hide file tree
Showing 35 changed files with 2,309 additions and 261 deletions.
17 changes: 15 additions & 2 deletions pcsx2-qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ target_sources(pcsx2-qt PRIVATE
Debugger/DisassemblyWidget.cpp
Debugger/DisassemblyWidget.h
Debugger/DisassemblyWidget.ui
Debugger/DockManager.cpp
Debugger/DockManager.h
Debugger/JsonValueWrapper.h
Debugger/RegisterWidget.cpp
Debugger/RegisterWidget.h
Debugger/RegisterWidget.ui
Expand All @@ -189,6 +188,20 @@ target_sources(pcsx2-qt PRIVATE
Debugger/Breakpoints/BreakpointWidget.cpp
Debugger/Breakpoints/BreakpointWidget.h
Debugger/Breakpoints/BreakpointWidget.ui
Debugger/Docking/DockLayout.cpp
Debugger/Docking/DockLayout.h
Debugger/Docking/DockManager.cpp
Debugger/Docking/DockManager.h
Debugger/Docking/DockTables.cpp
Debugger/Docking/DockTables.h
Debugger/Docking/DockViews.cpp
Debugger/Docking/DockViews.h
Debugger/Docking/LayoutEditorDialog.cpp
Debugger/Docking/LayoutEditorDialog.h
Debugger/Docking/LayoutEditorDialog.ui
Debugger/Docking/NoLayoutsWidget.cpp
Debugger/Docking/NoLayoutsWidget.h
Debugger/Docking/NoLayoutsWidget.ui
Debugger/Memory/MemorySearchWidget.cpp
Debugger/Memory/MemorySearchWidget.h
Debugger/Memory/MemorySearchWidget.ui
Expand Down
65 changes: 59 additions & 6 deletions pcsx2-qt/Debugger/DebuggerWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,65 @@

#include "DebuggerWidget.h"

#include "JsonValueWrapper.h"

#include "DebugTools/DebugInterface.h"

#include "common/Assertions.h"

DebuggerWidget::DebuggerWidget(DebugInterface* cpu, QWidget* parent)
: QWidget(parent)
, m_cpu(cpu)
DebugInterface& DebuggerWidget::cpu() const
{
if (m_cpu_override.has_value())
return DebugInterface::get(*m_cpu_override);

pxAssertRel(m_cpu, "DebuggerWidget::cpu called on object with null cpu.");
return *m_cpu;
}

DebugInterface& DebuggerWidget::cpu() const
bool DebuggerWidget::setCpu(DebugInterface& new_cpu)
{
BreakPointCpu before = cpu().getCpuType();
m_cpu = &new_cpu;
BreakPointCpu after = cpu().getCpuType();
return before == after;
}

std::optional<BreakPointCpu> DebuggerWidget::cpuOverride() const
{
return m_cpu_override;
}

bool DebuggerWidget::setCpuOverride(std::optional<BreakPointCpu> new_cpu)
{
BreakPointCpu before = cpu().getCpuType();
m_cpu_override = new_cpu;
BreakPointCpu after = cpu().getCpuType();
return before == after;
}

void DebuggerWidget::toJson(JsonValueWrapper& json)
{
rapidjson::Value cpu_name;
if (m_cpu_override)
{
switch (*m_cpu_override)
{
case BREAKPOINT_EE:
cpu_name.SetString("EE");
break;
case BREAKPOINT_IOP:
cpu_name.SetString("IOP");
break;
default:
return;
}
}

json.value().AddMember("target", cpu_name, json.allocator());
}

void DebuggerWidget::fromJson(JsonValueWrapper& json)
{
pxAssertRel(m_cpu, "DebuggerWidget::cpu() called on object that doesn't have a CPU type set.");
return *m_cpu;
}

void DebuggerWidget::applyMonospaceFont()
Expand All @@ -29,3 +76,9 @@ void DebuggerWidget::applyMonospaceFont()
setStyleSheet(QStringLiteral("font: 10pt 'Monospace'"));
#endif
}

DebuggerWidget::DebuggerWidget(DebugInterface* cpu, QWidget* parent)
: QWidget(parent)
, m_cpu(cpu)
{
}
28 changes: 25 additions & 3 deletions pcsx2-qt/Debugger/DebuggerWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,39 @@ inline void not_yet_implemented()
abort();
}

class JsonValueWrapper;

// The base class for the contents of the dock widgets in the debugger.
class DebuggerWidget : public QWidget
{
Q_OBJECT

protected:
DebuggerWidget(DebugInterface* cpu, QWidget* parent = nullptr);

public:
// Get the effective debug interface associated with this particular widget
// if it's set, otherwise return the one associated with the layout that
// contains this widget.
DebugInterface& cpu() const;

// Set the debug interface associated with the layout. If false is returned,
// we have to recreate the object.
bool setCpu(DebugInterface& new_cpu);

// Get the CPU associated with this particular widget.
std::optional<BreakPointCpu> cpuOverride() const;

// Set the CPU associated with the individual dock widget. If false is
// returned, we have to recreate the object.
bool setCpuOverride(std::optional<BreakPointCpu> new_cpu);

virtual void toJson(JsonValueWrapper& json);
virtual void fromJson(JsonValueWrapper& json);

void applyMonospaceFont();

protected:
DebuggerWidget(DebugInterface* cpu, QWidget* parent = nullptr);

private:
DebugInterface* m_cpu;
std::optional<BreakPointCpu> m_cpu_override;
};
25 changes: 23 additions & 2 deletions pcsx2-qt/Debugger/DebuggerWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "DebuggerWindow.h"

#include "Debugger/Docking/DockManager.h"

#include "DebugTools/DebugInterface.h"
#include "DebugTools/Breakpoints.h"
#include "DebugTools/SymbolImporter.h"
Expand All @@ -11,12 +13,18 @@
#include "MainWindow.h"
#include "AnalysisOptionsDialog.h"

DebuggerWindow* g_debugger_window = nullptr;

DebuggerWindow::DebuggerWindow(QWidget* parent)
: KDDockWidgets::QtWidgets::MainWindow(QStringLiteral("DebuggerWindow"), {}, parent)
, m_dock_manager(this)
{
m_ui.setupUi(this);

// This needs to be set before we create the dock manager.
g_debugger_window = this;

m_dock_manager = new DockManager(this);

connect(m_ui.actionRun, &QAction::triggered, this, &DebuggerWindow::onRunPause);
connect(m_ui.actionStepInto, &QAction::triggered, this, &DebuggerWindow::onStepInto);
connect(m_ui.actionStepOver, &QAction::triggered, this, &DebuggerWindow::onStepOver);
Expand All @@ -37,15 +45,28 @@ DebuggerWindow::DebuggerWindow(QWidget* parent)
//m_ui.cpuTabs->addTab(m_cpuWidget_r5900, "R5900");
//m_ui.cpuTabs->addTab(m_cpuWidget_r3000, "R3000");

m_dock_manager.switchToLayout(0);
m_dock_manager->switchToLayout(0);

//QTabBar* tabs = new QTabBar();
//tabs->addTab("Test");
//m_ui.menuBar->layout()->addWidget(tabs);

QMenuBar* menu_bar = menuBar();

setMenuWidget(m_dock_manager->createLayoutSwitcher(menu_bar));

connect(m_ui.menuWindows, &QMenu::aboutToShow, this, [this]() {
m_dock_manager->createWindowsMenu(m_ui.menuWindows);
});
}

DebuggerWindow::~DebuggerWindow() = default;

DockManager& DebuggerWindow::dockManager()
{
return *m_dock_manager;
}

// There is no straightforward way to set the tab text to bold in Qt
// Sorry colour blind people, but this is the best we can do for now
void DebuggerWindow::setTabActiveStyle(BreakPointCpu enabledCpu)
Expand Down
10 changes: 8 additions & 2 deletions pcsx2-qt/Debugger/DebuggerWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

#include "ui_DebuggerWindow.h"

#include "DockManager.h"
#include "DebugTools/DebugInterface.h"

#include <kddockwidgets/MainWindow.h>

class DockManager;

class DebuggerWindow : public KDDockWidgets::QtWidgets::MainWindow
{
Q_OBJECT
Expand All @@ -17,6 +19,8 @@ class DebuggerWindow : public KDDockWidgets::QtWidgets::MainWindow
DebuggerWindow(QWidget* parent);
~DebuggerWindow();

DockManager& dockManager();

public slots:
void onVMStateChanged();
void onRunPause();
Expand All @@ -36,7 +40,9 @@ public slots:
QAction* m_actionStepOver;
QAction* m_actionStepOut;

DockManager m_dock_manager;
DockManager* m_dock_manager;

void setTabActiveStyle(BreakPointCpu toggledCPU);
};

extern DebuggerWindow* g_debugger_window;
6 changes: 0 additions & 6 deletions pcsx2-qt/Debugger/DebuggerWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@
<string>Windows</string>
</property>
</widget>
<widget class="QMenu" name="menuLayouts">
<property name="title">
<string>Layouts</string>
</property>
</widget>
<widget class="QMenu" name="menuView">
<property name="title">
<string>View</string>
Expand All @@ -92,7 +87,6 @@
<addaction name="menuView"/>
<addaction name="menuDebug"/>
<addaction name="menuWindows"/>
<addaction name="menuLayouts"/>
</widget>
<widget class="QToolBar" name="viewToolBar">
<property name="windowTitle">
Expand Down
108 changes: 0 additions & 108 deletions pcsx2-qt/Debugger/DockManager.cpp

This file was deleted.

Loading

0 comments on commit ef51360

Please sign in to comment.