summaryrefslogtreecommitdiff
path: root/src/citra_qt/debugger/graphics_breakpoints.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/citra_qt/debugger/graphics_breakpoints.cpp')
-rw-r--r--src/citra_qt/debugger/graphics_breakpoints.cpp112
1 files changed, 44 insertions, 68 deletions
diff --git a/src/citra_qt/debugger/graphics_breakpoints.cpp b/src/citra_qt/debugger/graphics_breakpoints.cpp
index 1da64f616..5202c168c 100644
--- a/src/citra_qt/debugger/graphics_breakpoints.cpp
+++ b/src/citra_qt/debugger/graphics_breakpoints.cpp
@@ -4,7 +4,7 @@
4 4
5#include <QMetaType> 5#include <QMetaType>
6#include <QPushButton> 6#include <QPushButton>
7#include <QTreeWidget> 7#include <QTreeView>
8#include <QVBoxLayout> 8#include <QVBoxLayout>
9#include <QLabel> 9#include <QLabel>
10 10
@@ -23,7 +23,7 @@ BreakPointModel::BreakPointModel(std::shared_ptr<Pica::DebugContext> debug_conte
23 23
24int BreakPointModel::columnCount(const QModelIndex& parent) const 24int BreakPointModel::columnCount(const QModelIndex& parent) const
25{ 25{
26 return 2; 26 return 1;
27} 27}
28 28
29int BreakPointModel::rowCount(const QModelIndex& parent) const 29int BreakPointModel::rowCount(const QModelIndex& parent) const
@@ -38,29 +38,29 @@ QVariant BreakPointModel::data(const QModelIndex& index, int role) const
38 switch (role) { 38 switch (role) {
39 case Qt::DisplayRole: 39 case Qt::DisplayRole:
40 { 40 {
41 switch (index.column()) { 41 if (index.column() == 0) {
42 case 0:
43 {
44 static const std::map<Pica::DebugContext::Event, QString> map = { 42 static const std::map<Pica::DebugContext::Event, QString> map = {
45 { Pica::DebugContext::Event::CommandLoaded, tr("Pica command loaded") }, 43 { Pica::DebugContext::Event::PicaCommandLoaded, tr("Pica command loaded") },
46 { Pica::DebugContext::Event::CommandProcessed, tr("Pica command processed") }, 44 { Pica::DebugContext::Event::PicaCommandProcessed, tr("Pica command processed") },
47 { Pica::DebugContext::Event::IncomingPrimitiveBatch, tr("Incoming primitive batch") }, 45 { Pica::DebugContext::Event::IncomingPrimitiveBatch, tr("Incoming primitive batch") },
48 { Pica::DebugContext::Event::FinishedPrimitiveBatch, tr("Finished primitive batch") }, 46 { Pica::DebugContext::Event::FinishedPrimitiveBatch, tr("Finished primitive batch") },
49 { Pica::DebugContext::Event::VertexLoaded, tr("Vertex loaded") } 47 { Pica::DebugContext::Event::VertexLoaded, tr("Vertex loaded") },
48 { Pica::DebugContext::Event::IncomingDisplayTransfer, tr("Incoming display transfer") },
49 { Pica::DebugContext::Event::GSPCommandProcessed, tr("GSP command processed") },
50 { Pica::DebugContext::Event::BufferSwapped, tr("Buffers swapped") }
50 }; 51 };
51 52
52 DEBUG_ASSERT(map.size() == static_cast<size_t>(Pica::DebugContext::Event::NumEvents)); 53 DEBUG_ASSERT(map.size() == static_cast<size_t>(Pica::DebugContext::Event::NumEvents));
53
54 return (map.find(event) != map.end()) ? map.at(event) : QString(); 54 return (map.find(event) != map.end()) ? map.at(event) : QString();
55 } 55 }
56 56
57 case 1: 57 break;
58 return data(index, Role_IsEnabled).toBool() ? tr("Enabled") : tr("Disabled"); 58 }
59
60 default:
61 break;
62 }
63 59
60 case Qt::CheckStateRole:
61 {
62 if (index.column() == 0)
63 return data(index, Role_IsEnabled).toBool() ? Qt::Checked : Qt::Unchecked;
64 break; 64 break;
65 } 65 }
66 66
@@ -84,37 +84,34 @@ QVariant BreakPointModel::data(const QModelIndex& index, int role) const
84 return QVariant(); 84 return QVariant();
85} 85}
86 86
87QVariant BreakPointModel::headerData(int section, Qt::Orientation orientation, int role) const 87Qt::ItemFlags BreakPointModel::flags(const QModelIndex &index) const
88{ 88{
89 switch(role) { 89 if (!index.isValid())
90 case Qt::DisplayRole: 90 return 0;
91 {
92 if (section == 0) {
93 return tr("Event");
94 } else if (section == 1) {
95 return tr("Status");
96 }
97
98 break;
99 }
100 }
101 91
102 return QVariant(); 92 Qt::ItemFlags flags = Qt::ItemIsEnabled;
93 if (index.column() == 0)
94 flags |= Qt::ItemIsUserCheckable;
95 return flags;
103} 96}
104 97
98
105bool BreakPointModel::setData(const QModelIndex& index, const QVariant& value, int role) 99bool BreakPointModel::setData(const QModelIndex& index, const QVariant& value, int role)
106{ 100{
107 const auto event = static_cast<Pica::DebugContext::Event>(index.row()); 101 const auto event = static_cast<Pica::DebugContext::Event>(index.row());
108 102
109 switch (role) { 103 switch (role) {
110 case Role_IsEnabled: 104 case Qt::CheckStateRole:
111 { 105 {
106 if (index.column() != 0)
107 return false;
108
112 auto context = context_weak.lock(); 109 auto context = context_weak.lock();
113 if (!context) 110 if (!context)
114 return false; 111 return false;
115 112
116 context->breakpoints[event].enabled = value.toBool(); 113 context->breakpoints[event].enabled = value == Qt::Checked;
117 QModelIndex changed_index = createIndex(index.row(), 1); 114 QModelIndex changed_index = createIndex(index.row(), 0);
118 emit dataChanged(changed_index, changed_index); 115 emit dataChanged(changed_index, changed_index);
119 return true; 116 return true;
120 } 117 }
@@ -133,7 +130,7 @@ void BreakPointModel::OnBreakPointHit(Pica::DebugContext::Event event)
133 active_breakpoint = context->active_breakpoint; 130 active_breakpoint = context->active_breakpoint;
134 at_breakpoint = context->at_breakpoint; 131 at_breakpoint = context->at_breakpoint;
135 emit dataChanged(createIndex(static_cast<int>(event), 0), 132 emit dataChanged(createIndex(static_cast<int>(event), 0),
136 createIndex(static_cast<int>(event), 1)); 133 createIndex(static_cast<int>(event), 0));
137} 134}
138 135
139void BreakPointModel::OnResumed() 136void BreakPointModel::OnResumed()
@@ -144,7 +141,7 @@ void BreakPointModel::OnResumed()
144 141
145 at_breakpoint = context->at_breakpoint; 142 at_breakpoint = context->at_breakpoint;
146 emit dataChanged(createIndex(static_cast<int>(active_breakpoint), 0), 143 emit dataChanged(createIndex(static_cast<int>(active_breakpoint), 0),
147 createIndex(static_cast<int>(active_breakpoint), 1)); 144 createIndex(static_cast<int>(active_breakpoint), 0));
148 active_breakpoint = context->active_breakpoint; 145 active_breakpoint = context->active_breakpoint;
149} 146}
150 147
@@ -162,13 +159,15 @@ GraphicsBreakPointsWidget::GraphicsBreakPointsWidget(std::shared_ptr<Pica::Debug
162 159
163 breakpoint_model = new BreakPointModel(debug_context, this); 160 breakpoint_model = new BreakPointModel(debug_context, this);
164 breakpoint_list = new QTreeView; 161 breakpoint_list = new QTreeView;
162 breakpoint_list->setRootIsDecorated(false);
163 breakpoint_list->setHeaderHidden(true);
165 breakpoint_list->setModel(breakpoint_model); 164 breakpoint_list->setModel(breakpoint_model);
166 165
167 toggle_breakpoint_button = new QPushButton(tr("Enable"));
168 toggle_breakpoint_button->setEnabled(false);
169
170 qRegisterMetaType<Pica::DebugContext::Event>("Pica::DebugContext::Event"); 166 qRegisterMetaType<Pica::DebugContext::Event>("Pica::DebugContext::Event");
171 167
168 connect(breakpoint_list, SIGNAL(doubleClicked(const QModelIndex&)),
169 this, SLOT(OnItemDoubleClicked(const QModelIndex&)));
170
172 connect(resume_button, SIGNAL(clicked()), this, SLOT(OnResumeRequested())); 171 connect(resume_button, SIGNAL(clicked()), this, SLOT(OnResumeRequested()));
173 172
174 connect(this, SIGNAL(BreakPointHit(Pica::DebugContext::Event,void*)), 173 connect(this, SIGNAL(BreakPointHit(Pica::DebugContext::Event,void*)),
@@ -184,11 +183,6 @@ GraphicsBreakPointsWidget::GraphicsBreakPointsWidget(std::shared_ptr<Pica::Debug
184 connect(this, SIGNAL(BreakPointsChanged(const QModelIndex&,const QModelIndex&)), 183 connect(this, SIGNAL(BreakPointsChanged(const QModelIndex&,const QModelIndex&)),
185 breakpoint_model, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&))); 184 breakpoint_model, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)));
186 185
187 connect(breakpoint_list->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
188 this, SLOT(OnBreakpointSelectionChanged(QModelIndex)));
189
190 connect(toggle_breakpoint_button, SIGNAL(clicked()), this, SLOT(OnToggleBreakpointEnabled()));
191
192 QWidget* main_widget = new QWidget; 186 QWidget* main_widget = new QWidget;
193 auto main_layout = new QVBoxLayout; 187 auto main_layout = new QVBoxLayout;
194 { 188 {
@@ -198,7 +192,6 @@ GraphicsBreakPointsWidget::GraphicsBreakPointsWidget(std::shared_ptr<Pica::Debug
198 main_layout->addLayout(sub_layout); 192 main_layout->addLayout(sub_layout);
199 } 193 }
200 main_layout->addWidget(breakpoint_list); 194 main_layout->addWidget(breakpoint_list);
201 main_layout->addWidget(toggle_breakpoint_button);
202 main_widget->setLayout(main_layout); 195 main_widget->setLayout(main_layout);
203 196
204 setWidget(main_widget); 197 setWidget(main_widget);
@@ -234,32 +227,15 @@ void GraphicsBreakPointsWidget::OnResumeRequested()
234 context->Resume(); 227 context->Resume();
235} 228}
236 229
237void GraphicsBreakPointsWidget::OnBreakpointSelectionChanged(const QModelIndex& index) 230void GraphicsBreakPointsWidget::OnItemDoubleClicked(const QModelIndex& index)
238{ 231{
239 if (!index.isValid()) { 232 if (!index.isValid())
240 toggle_breakpoint_button->setEnabled(false);
241 return; 233 return;
242 }
243 234
244 toggle_breakpoint_button->setEnabled(true); 235 QModelIndex check_index = breakpoint_list->model()->index(index.row(), 0);
245 UpdateToggleBreakpointButton(index); 236 QVariant enabled = breakpoint_list->model()->data(check_index, Qt::CheckStateRole);
246} 237 QVariant new_state = Qt::Unchecked;
247 238 if (enabled == Qt::Unchecked)
248void GraphicsBreakPointsWidget::OnToggleBreakpointEnabled() 239 new_state = Qt::Checked;
249{ 240 breakpoint_list->model()->setData(check_index, new_state, Qt::CheckStateRole);
250 QModelIndex index = breakpoint_list->selectionModel()->currentIndex();
251 bool new_state = !(breakpoint_model->data(index, BreakPointModel::Role_IsEnabled).toBool());
252
253 breakpoint_model->setData(index, new_state,
254 BreakPointModel::Role_IsEnabled);
255 UpdateToggleBreakpointButton(index);
256}
257
258void GraphicsBreakPointsWidget::UpdateToggleBreakpointButton(const QModelIndex& index)
259{
260 if (true == breakpoint_model->data(index, BreakPointModel::Role_IsEnabled).toBool()) {
261 toggle_breakpoint_button->setText(tr("Disable"));
262 } else {
263 toggle_breakpoint_button->setText(tr("Enable"));
264 }
265} 241}