mirror of
https://git.suyu.dev/suyu/suyu
synced 2024-12-25 10:52:48 -06:00
Merge pull request #981 from Subv/checkboxes
Qt/GPU Breakpoints: Changed the widget to have a checkbox next to each bp type
This commit is contained in:
commit
43e1f56ff5
3 changed files with 40 additions and 71 deletions
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QTreeWidget>
|
#include <QTreeView>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ BreakPointModel::BreakPointModel(std::shared_ptr<Pica::DebugContext> debug_conte
|
||||||
|
|
||||||
int BreakPointModel::columnCount(const QModelIndex& parent) const
|
int BreakPointModel::columnCount(const QModelIndex& parent) const
|
||||||
{
|
{
|
||||||
return 2;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BreakPointModel::rowCount(const QModelIndex& parent) const
|
int BreakPointModel::rowCount(const QModelIndex& parent) const
|
||||||
|
@ -38,9 +38,7 @@ QVariant BreakPointModel::data(const QModelIndex& index, int role) const
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
{
|
{
|
||||||
switch (index.column()) {
|
if (index.column() == 0) {
|
||||||
case 0:
|
|
||||||
{
|
|
||||||
static const std::map<Pica::DebugContext::Event, QString> map = {
|
static const std::map<Pica::DebugContext::Event, QString> map = {
|
||||||
{ Pica::DebugContext::Event::PicaCommandLoaded, tr("Pica command loaded") },
|
{ Pica::DebugContext::Event::PicaCommandLoaded, tr("Pica command loaded") },
|
||||||
{ Pica::DebugContext::Event::PicaCommandProcessed, tr("Pica command processed") },
|
{ Pica::DebugContext::Event::PicaCommandProcessed, tr("Pica command processed") },
|
||||||
|
@ -53,17 +51,16 @@ QVariant BreakPointModel::data(const QModelIndex& index, int role) const
|
||||||
};
|
};
|
||||||
|
|
||||||
DEBUG_ASSERT(map.size() == static_cast<size_t>(Pica::DebugContext::Event::NumEvents));
|
DEBUG_ASSERT(map.size() == static_cast<size_t>(Pica::DebugContext::Event::NumEvents));
|
||||||
|
|
||||||
return (map.find(event) != map.end()) ? map.at(event) : QString();
|
return (map.find(event) != map.end()) ? map.at(event) : QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
case 1:
|
|
||||||
return data(index, Role_IsEnabled).toBool() ? tr("Enabled") : tr("Disabled");
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case Qt::CheckStateRole:
|
||||||
|
{
|
||||||
|
if (index.column() == 0)
|
||||||
|
return data(index, Role_IsEnabled).toBool() ? Qt::Checked : Qt::Unchecked;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,37 +84,34 @@ QVariant BreakPointModel::data(const QModelIndex& index, int role) const
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant BreakPointModel::headerData(int section, Qt::Orientation orientation, int role) const
|
Qt::ItemFlags BreakPointModel::flags(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
switch(role) {
|
if (!index.isValid())
|
||||||
case Qt::DisplayRole:
|
return 0;
|
||||||
{
|
|
||||||
if (section == 0) {
|
|
||||||
return tr("Event");
|
|
||||||
} else if (section == 1) {
|
|
||||||
return tr("Status");
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
Qt::ItemFlags flags = Qt::ItemIsEnabled;
|
||||||
}
|
if (index.column() == 0)
|
||||||
}
|
flags |= Qt::ItemIsUserCheckable;
|
||||||
|
return flags;
|
||||||
return QVariant();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool BreakPointModel::setData(const QModelIndex& index, const QVariant& value, int role)
|
bool BreakPointModel::setData(const QModelIndex& index, const QVariant& value, int role)
|
||||||
{
|
{
|
||||||
const auto event = static_cast<Pica::DebugContext::Event>(index.row());
|
const auto event = static_cast<Pica::DebugContext::Event>(index.row());
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Role_IsEnabled:
|
case Qt::CheckStateRole:
|
||||||
{
|
{
|
||||||
|
if (index.column() != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
auto context = context_weak.lock();
|
auto context = context_weak.lock();
|
||||||
if (!context)
|
if (!context)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
context->breakpoints[event].enabled = value.toBool();
|
context->breakpoints[event].enabled = value == Qt::Checked;
|
||||||
QModelIndex changed_index = createIndex(index.row(), 1);
|
QModelIndex changed_index = createIndex(index.row(), 0);
|
||||||
emit dataChanged(changed_index, changed_index);
|
emit dataChanged(changed_index, changed_index);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -136,7 +130,7 @@ void BreakPointModel::OnBreakPointHit(Pica::DebugContext::Event event)
|
||||||
active_breakpoint = context->active_breakpoint;
|
active_breakpoint = context->active_breakpoint;
|
||||||
at_breakpoint = context->at_breakpoint;
|
at_breakpoint = context->at_breakpoint;
|
||||||
emit dataChanged(createIndex(static_cast<int>(event), 0),
|
emit dataChanged(createIndex(static_cast<int>(event), 0),
|
||||||
createIndex(static_cast<int>(event), 1));
|
createIndex(static_cast<int>(event), 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void BreakPointModel::OnResumed()
|
void BreakPointModel::OnResumed()
|
||||||
|
@ -147,7 +141,7 @@ void BreakPointModel::OnResumed()
|
||||||
|
|
||||||
at_breakpoint = context->at_breakpoint;
|
at_breakpoint = context->at_breakpoint;
|
||||||
emit dataChanged(createIndex(static_cast<int>(active_breakpoint), 0),
|
emit dataChanged(createIndex(static_cast<int>(active_breakpoint), 0),
|
||||||
createIndex(static_cast<int>(active_breakpoint), 1));
|
createIndex(static_cast<int>(active_breakpoint), 0));
|
||||||
active_breakpoint = context->active_breakpoint;
|
active_breakpoint = context->active_breakpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,13 +159,15 @@ GraphicsBreakPointsWidget::GraphicsBreakPointsWidget(std::shared_ptr<Pica::Debug
|
||||||
|
|
||||||
breakpoint_model = new BreakPointModel(debug_context, this);
|
breakpoint_model = new BreakPointModel(debug_context, this);
|
||||||
breakpoint_list = new QTreeView;
|
breakpoint_list = new QTreeView;
|
||||||
|
breakpoint_list->setRootIsDecorated(false);
|
||||||
|
breakpoint_list->setHeaderHidden(true);
|
||||||
breakpoint_list->setModel(breakpoint_model);
|
breakpoint_list->setModel(breakpoint_model);
|
||||||
|
|
||||||
toggle_breakpoint_button = new QPushButton(tr("Enable"));
|
|
||||||
toggle_breakpoint_button->setEnabled(false);
|
|
||||||
|
|
||||||
qRegisterMetaType<Pica::DebugContext::Event>("Pica::DebugContext::Event");
|
qRegisterMetaType<Pica::DebugContext::Event>("Pica::DebugContext::Event");
|
||||||
|
|
||||||
|
connect(breakpoint_list, SIGNAL(doubleClicked(const QModelIndex&)),
|
||||||
|
this, SLOT(OnItemDoubleClicked(const QModelIndex&)));
|
||||||
|
|
||||||
connect(resume_button, SIGNAL(clicked()), this, SLOT(OnResumeRequested()));
|
connect(resume_button, SIGNAL(clicked()), this, SLOT(OnResumeRequested()));
|
||||||
|
|
||||||
connect(this, SIGNAL(BreakPointHit(Pica::DebugContext::Event,void*)),
|
connect(this, SIGNAL(BreakPointHit(Pica::DebugContext::Event,void*)),
|
||||||
|
@ -187,11 +183,6 @@ GraphicsBreakPointsWidget::GraphicsBreakPointsWidget(std::shared_ptr<Pica::Debug
|
||||||
connect(this, SIGNAL(BreakPointsChanged(const QModelIndex&,const QModelIndex&)),
|
connect(this, SIGNAL(BreakPointsChanged(const QModelIndex&,const QModelIndex&)),
|
||||||
breakpoint_model, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)));
|
breakpoint_model, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)));
|
||||||
|
|
||||||
connect(breakpoint_list->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
|
|
||||||
this, SLOT(OnBreakpointSelectionChanged(QModelIndex)));
|
|
||||||
|
|
||||||
connect(toggle_breakpoint_button, SIGNAL(clicked()), this, SLOT(OnToggleBreakpointEnabled()));
|
|
||||||
|
|
||||||
QWidget* main_widget = new QWidget;
|
QWidget* main_widget = new QWidget;
|
||||||
auto main_layout = new QVBoxLayout;
|
auto main_layout = new QVBoxLayout;
|
||||||
{
|
{
|
||||||
|
@ -201,7 +192,6 @@ GraphicsBreakPointsWidget::GraphicsBreakPointsWidget(std::shared_ptr<Pica::Debug
|
||||||
main_layout->addLayout(sub_layout);
|
main_layout->addLayout(sub_layout);
|
||||||
}
|
}
|
||||||
main_layout->addWidget(breakpoint_list);
|
main_layout->addWidget(breakpoint_list);
|
||||||
main_layout->addWidget(toggle_breakpoint_button);
|
|
||||||
main_widget->setLayout(main_layout);
|
main_widget->setLayout(main_layout);
|
||||||
|
|
||||||
setWidget(main_widget);
|
setWidget(main_widget);
|
||||||
|
@ -237,32 +227,15 @@ void GraphicsBreakPointsWidget::OnResumeRequested()
|
||||||
context->Resume();
|
context->Resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsBreakPointsWidget::OnBreakpointSelectionChanged(const QModelIndex& index)
|
void GraphicsBreakPointsWidget::OnItemDoubleClicked(const QModelIndex& index)
|
||||||
{
|
{
|
||||||
if (!index.isValid()) {
|
if (!index.isValid())
|
||||||
toggle_breakpoint_button->setEnabled(false);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
toggle_breakpoint_button->setEnabled(true);
|
QModelIndex check_index = breakpoint_list->model()->index(index.row(), 0);
|
||||||
UpdateToggleBreakpointButton(index);
|
QVariant enabled = breakpoint_list->model()->data(check_index, Qt::CheckStateRole);
|
||||||
}
|
QVariant new_state = Qt::Unchecked;
|
||||||
|
if (enabled == Qt::Unchecked)
|
||||||
void GraphicsBreakPointsWidget::OnToggleBreakpointEnabled()
|
new_state = Qt::Checked;
|
||||||
{
|
breakpoint_list->model()->setData(check_index, new_state, Qt::CheckStateRole);
|
||||||
QModelIndex index = breakpoint_list->selectionModel()->currentIndex();
|
|
||||||
bool new_state = !(breakpoint_model->data(index, BreakPointModel::Role_IsEnabled).toBool());
|
|
||||||
|
|
||||||
breakpoint_model->setData(index, new_state,
|
|
||||||
BreakPointModel::Role_IsEnabled);
|
|
||||||
UpdateToggleBreakpointButton(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphicsBreakPointsWidget::UpdateToggleBreakpointButton(const QModelIndex& index)
|
|
||||||
{
|
|
||||||
if (true == breakpoint_model->data(index, BreakPointModel::Role_IsEnabled).toBool()) {
|
|
||||||
toggle_breakpoint_button->setText(tr("Disable"));
|
|
||||||
} else {
|
|
||||||
toggle_breakpoint_button->setText(tr("Enable"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,10 +31,9 @@ public:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void OnBreakPointHit(Pica::DebugContext::Event event, void* data);
|
void OnBreakPointHit(Pica::DebugContext::Event event, void* data);
|
||||||
|
void OnItemDoubleClicked(const QModelIndex&);
|
||||||
void OnResumeRequested();
|
void OnResumeRequested();
|
||||||
void OnResumed();
|
void OnResumed();
|
||||||
void OnBreakpointSelectionChanged(const QModelIndex&);
|
|
||||||
void OnToggleBreakpointEnabled();
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void Resumed();
|
void Resumed();
|
||||||
|
@ -42,11 +41,8 @@ signals:
|
||||||
void BreakPointsChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);
|
void BreakPointsChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void UpdateToggleBreakpointButton(const QModelIndex& index);
|
|
||||||
|
|
||||||
QLabel* status_text;
|
QLabel* status_text;
|
||||||
QPushButton* resume_button;
|
QPushButton* resume_button;
|
||||||
QPushButton* toggle_breakpoint_button;
|
|
||||||
|
|
||||||
BreakPointModel* breakpoint_model;
|
BreakPointModel* breakpoint_model;
|
||||||
QTreeView* breakpoint_list;
|
QTreeView* breakpoint_list;
|
||||||
|
|
|
@ -23,7 +23,7 @@ public:
|
||||||
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
|
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||||
|
|
||||||
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
|
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue