From a3c406db9d0165d88d4d6510661faf9424a304cb Mon Sep 17 00:00:00 2001
From: Anonymus Raccoon
Date: Tue, 24 Mar 2020 14:19:03 +0100
Subject: [PATCH] Adding a proxy to filter logs, it's still a bit unstable and
not linked to checkboxes but it works
---
sources/Debugger/MemoryBusDebug.cpp | 27 ++++++++++++++---
sources/Debugger/MemoryBusDebug.hpp | 47 +++++++++++++++++++++++++++--
2 files changed, 66 insertions(+), 8 deletions(-)
diff --git a/sources/Debugger/MemoryBusDebug.cpp b/sources/Debugger/MemoryBusDebug.cpp
index 33a3b89..fa02651 100644
--- a/sources/Debugger/MemoryBusDebug.cpp
+++ b/sources/Debugger/MemoryBusDebug.cpp
@@ -15,18 +15,20 @@ namespace ComSquare::Debugger
_window(new ClosableWindow(*this, &MemoryBusDebug::disableViewer)),
_snes(snes),
_ui(),
- _model()
+ _model(),
+ _proxy(this->_model)
{
this->_window->setContextMenuPolicy(Qt::NoContextMenu);
this->_window->setAttribute(Qt::WA_QuitOnClose, false);
this->_window->setAttribute(Qt::WA_DeleteOnClose);
this->_ui.setupUi(this->_window);
- this->_ui.log->setModel(&this->_model);
+ this->_proxy.setSourceModel(&this->_model);
+ this->_ui.log->setModel(&this->_proxy);
this->_ui.log->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
this->_ui.log->horizontalHeader()->setStretchLastSection(true);
this->_ui.log->horizontalHeader()->setSectionsMovable(true);
- for (int i = 0; i < 5; i++)
+ for (int i = 0; i < this->_model.column; i++)
this->_ui.log->setColumnWidth(i, this->_ui.log->width());
this->_window->show();
}
@@ -80,7 +82,7 @@ int BusLogModel::rowCount(const QModelIndex &) const
int BusLogModel::columnCount(const QModelIndex &) const
{
- return this->_columnCount;
+ return this->column;
}
QVariant BusLogModel::data(const QModelIndex &index, int role) const
@@ -136,5 +138,20 @@ void BusLogModel::log(ComSquare::Debugger::BusLog log)
int row = this->_logs.size();
this->insertRow(row);
emit this->layoutChanged();
- // The row may be inserted but items are not displayed.
+}
+
+ComSquare::Debugger::BusLog BusLogModel::getLogAt(int index)
+{
+ return this->_logs[index];
+}
+
+BusLoggerProxy::BusLoggerProxy(BusLogModel &parent) : QSortFilterProxyModel(), _parent(parent) {}
+
+bool BusLoggerProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
+{
+ ComSquare::Debugger::BusLog log = this->_parent.getLogAt(sourceRow);
+
+ if (log.accessor && log.accessor->getName() == "Cartridge")
+ return false;
+ return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
}
diff --git a/sources/Debugger/MemoryBusDebug.hpp b/sources/Debugger/MemoryBusDebug.hpp
index 9c2dc9e..c90baf6 100644
--- a/sources/Debugger/MemoryBusDebug.hpp
+++ b/sources/Debugger/MemoryBusDebug.hpp
@@ -6,6 +6,7 @@
#define COMSQUARE_MEMORYBUSDEBUG_HPP
#include
+#include
#include "../Memory/MemoryBus.hpp"
#include "../../ui/ui_busView.h"
#include "ClosableWindow.hpp"
@@ -22,27 +23,44 @@ namespace ComSquare::Debugger
uint8_t oldData;
uint8_t newData;
};
+
+ //! @brief The struct representing filters of the memory bus's logger.
+ struct BusLoggerFilters {
+ bool cpu = true;
+ bool apu = true;
+ bool ppu = true;
+ bool rom = true;
+ bool wram = true;
+ bool sram = true;
+ bool vram = true;
+ bool oamram = true;
+ bool cgram = true;
+ };
}
//! @brief The qt model that bind the logs to the view.
class BusLogModel : public QAbstractTableModel
{
-Q_OBJECT
+ Q_OBJECT
private:
//! @brief The logs to display.
std::vector _logs;
- //! @brief The number of column;
- const int _columnCount = 6;
public:
BusLogModel() = default;
BusLogModel(const BusLogModel &) = delete;
const BusLogModel &operator=(const BusLogModel &) = delete;
~BusLogModel() override = default;
+ //! @brief The number of column;
+ const int column = 6;
+
//! @brief Add a log to the model
void log(ComSquare::Debugger::BusLog log);
+ //! @brief Get a log at an index.
+ ComSquare::Debugger::BusLog getLogAt(int index);
+
//! @brief The number of row the table has.
int rowCount(const QModelIndex &parent) const override;
//! @brief The number of column the table has.
@@ -53,6 +71,27 @@ public:
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
};
+//! @brief A class to filter logs from the memory bus's debugger.
+class BusLoggerProxy : public QSortFilterProxyModel {
+ Q_OBJECT
+private:
+ //! @brief The parent to get the original data for filters
+ BusLogModel &_parent;
+protected:
+ //! @brief Function that filter logs.
+ bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
+public:
+ //! @brief Currently enabled read filters
+ ComSquare::Debugger::BusLoggerFilters readFilters = ComSquare::Debugger::BusLoggerFilters();
+ //! @brief Currently enabled write filters
+ ComSquare::Debugger::BusLoggerFilters writeFilters = ComSquare::Debugger::BusLoggerFilters();
+
+ BusLoggerProxy(BusLogModel &parent);
+ BusLoggerProxy(const BusLoggerProxy &) = delete;
+ const BusLoggerProxy &operator=(const BusLoggerProxy &) = delete;
+ ~BusLoggerProxy() override = default;
+};
+
namespace ComSquare::Debugger
{
@@ -67,6 +106,8 @@ namespace ComSquare::Debugger
Ui::BusView _ui;
//! @brief The Log visualizer model for QT.
BusLogModel _model;
+ //! @brief A QT proxy to filter the logs.
+ BusLoggerProxy _proxy;
public:
//! @brief Called when the window is closed. Turn off the debugger and revert to a basic CPU.
void disableViewer();