diff --git a/pcsx2-qt/Debugger/CpuWidget.cpp b/pcsx2-qt/Debugger/CpuWidget.cpp index 8ee097bf41..ecb0c336c6 100644 --- a/pcsx2-qt/Debugger/CpuWidget.cpp +++ b/pcsx2-qt/Debugger/CpuWidget.cpp @@ -246,7 +246,7 @@ void CpuWidget::onBPListDoubleClicked(const QModelIndex& index) { if (index.column() == BreakpointModel::OFFSET) { - m_ui.disassemblyWidget->gotoAddress(m_bpModel.data(index, Qt::UserRole).toUInt()); + m_ui.disassemblyWidget->gotoAddress(m_bpModel.data(index, BreakpointModel::DataRole).toUInt()); } } } @@ -285,8 +285,8 @@ void CpuWidget::onBPListContextMenu(QPoint pos) contextMenu->addSeparator(); QAction* actionExport = new QAction(tr("Copy all as CSV"), m_ui.breakpointList); connect(actionExport, &QAction::triggered, [this]() { - // It's important to use the User Role here to allow pasting to be translation agnostic - QGuiApplication::clipboard()->setText(QtUtils::AbstractItemModelToCSV(m_ui.breakpointList->model(), Qt::UserRole)); + // It's important to use the Export Role here to allow pasting to be translation agnostic + QGuiApplication::clipboard()->setText(QtUtils::AbstractItemModelToCSV(m_ui.breakpointList->model(), BreakpointModel::ExportRole)); }); contextMenu->addAction(actionExport); @@ -429,7 +429,7 @@ void CpuWidget::contextBPListPasteCSV() } // Size - mc.end = fields[2].toUInt(&ok, 16) + mc.start; + mc.end = fields[2].toUInt(&ok) + mc.start; if (!ok) { Console.WriteLn("Debugger CSV Import: Failed to parse length '%s', skipping", fields[1].toUtf8().constData()); diff --git a/pcsx2-qt/Debugger/Models/BreakpointModel.cpp b/pcsx2-qt/Debugger/Models/BreakpointModel.cpp index d70a90eb85..031150e7f5 100644 --- a/pcsx2-qt/Debugger/Models/BreakpointModel.cpp +++ b/pcsx2-qt/Debugger/Models/BreakpointModel.cpp @@ -98,7 +98,7 @@ QVariant BreakpointModel::data(const QModelIndex& index, int role) const } } } - else if (role == Qt::UserRole) + else if (role == BreakpointModel::DataRole) { auto bp_mc = m_breakpoints.at(index.row()); @@ -144,6 +144,52 @@ QVariant BreakpointModel::data(const QModelIndex& index, int role) const } } } + else if (role == BreakpointModel::ExportRole) + { + auto bp_mc = m_breakpoints.at(index.row()); + + if (const auto* bp = std::get_if(&bp_mc)) + { + switch (index.column()) + { + case BreakpointColumns::TYPE: + return MEMCHECK_INVALID; + case BreakpointColumns::OFFSET: + return QtUtils::FilledQStringFromValue(bp->addr, 16); + case BreakpointColumns::SIZE_LABEL: + return m_cpu.GetSymbolMap().GetLabelString(bp->addr).c_str(); + case BreakpointColumns::OPCODE: + // Note: Fix up the disassemblymanager so we can use it here, instead of calling a function through the disassemblyview (yuck) + return m_cpu.disasm(bp->addr, true).c_str(); + case BreakpointColumns::CONDITION: + return bp->hasCond ? QString::fromLocal8Bit(bp->cond.expressionString) : tr(""); + case BreakpointColumns::HITS: + return 0; + case BreakpointColumns::ENABLED: + return static_cast(bp->enabled); + } + } + else if (const auto* mc = std::get_if(&bp_mc)) + { + switch (index.column()) + { + case BreakpointColumns::TYPE: + return mc->cond; + case BreakpointColumns::OFFSET: + return QtUtils::FilledQStringFromValue(mc->start, 16); + case BreakpointColumns::SIZE_LABEL: + return mc->end - mc->start; + case BreakpointColumns::OPCODE: + return ""; + case BreakpointColumns::CONDITION: + return ""; + case BreakpointColumns::HITS: + return mc->numHits; + case BreakpointColumns::ENABLED: + return (mc->result & MEMCHECK_BREAK); + } + } + } else if (role == Qt::CheckStateRole) { if (index.column() == 6) diff --git a/pcsx2-qt/Debugger/Models/BreakpointModel.h b/pcsx2-qt/Debugger/Models/BreakpointModel.h index 158adfe5be..2285d17c5e 100644 --- a/pcsx2-qt/Debugger/Models/BreakpointModel.h +++ b/pcsx2-qt/Debugger/Models/BreakpointModel.h @@ -38,6 +38,12 @@ public: COLUMN_COUNT }; + enum BreakpointRoles : int + { + DataRole = Qt::UserRole, + ExportRole = Qt::UserRole + 1, + }; + explicit BreakpointModel(DebugInterface& cpu, QObject* parent = nullptr); int rowCount(const QModelIndex& parent = QModelIndex()) const override; diff --git a/pcsx2-qt/QtUtils.cpp b/pcsx2-qt/QtUtils.cpp index 9c70258b09..bbe27c1379 100644 --- a/pcsx2-qt/QtUtils.cpp +++ b/pcsx2-qt/QtUtils.cpp @@ -287,17 +287,8 @@ namespace QtUtils { for (int col = 0; col < model->columnCount(); col++) { - switch(model->data(model->index(row, col), role).metaType().id()) - { - case QMetaType::Int: - case QMetaType::UInt: - csv += QString::number(model->data(model->index(row, col), role).toUInt(nullptr), 16); - break; - default: - csv += model->data(model->index(row, col), role).toString(); - break; - } - + csv += model->data(model->index(row, col), role).toString(); + if (col < model->columnCount() - 1) csv += ","; }