From 15aa1a7dde1a1797e1b67cecd3cfec52aeb5be8d Mon Sep 17 00:00:00 2001 From: Anonymus Raccoon Date: Tue, 24 Mar 2020 23:15:33 +0100 Subject: [PATCH] Implementing the clear button --- sources/Debugger/MemoryBusDebug.cpp | 16 ++++++++++++++-- sources/Debugger/MemoryBusDebug.hpp | 4 +++- ui/busView.ui | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/sources/Debugger/MemoryBusDebug.cpp b/sources/Debugger/MemoryBusDebug.cpp index 2fe1ecd..ef0fab9 100644 --- a/sources/Debugger/MemoryBusDebug.cpp +++ b/sources/Debugger/MemoryBusDebug.cpp @@ -101,6 +101,11 @@ namespace ComSquare::Debugger this->_proxy.refresh(); }); + QMainWindow::connect(this->_ui.clearBtn, &QPushButton::pressed, [this]() { + this->_model.clearLogs(); + this->_proxy.refresh(); + }); + this->_window->show(); } @@ -204,7 +209,7 @@ QVariant BusLogModel::headerData(int section, Qt::Orientation orientation, int r } } -void BusLogModel::log(ComSquare::Debugger::BusLog log) +void BusLogModel::log(const ComSquare::Debugger::BusLog& log) { int row = this->_logs.size(); this->beginInsertRows(QModelIndex(), row, row); @@ -218,9 +223,16 @@ ComSquare::Debugger::BusLog BusLogModel::getLogAt(int index) return this->_logs[index]; } +void BusLogModel::clearLogs() +{ + this->beginResetModel(); + this->_logs.clear(); + this->endResetModel(); +} + BusLoggerProxy::BusLoggerProxy(BusLogModel &parent) : QSortFilterProxyModel(), _parent(parent) {} -bool BusLoggerProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const +bool BusLoggerProxy::filterAcceptsRow(int sourceRow, const QModelIndex &) const { ComSquare::Debugger::BusLog log = this->_parent.getLogAt(sourceRow); diff --git a/sources/Debugger/MemoryBusDebug.hpp b/sources/Debugger/MemoryBusDebug.hpp index 7432b7b..6f7ff3b 100644 --- a/sources/Debugger/MemoryBusDebug.hpp +++ b/sources/Debugger/MemoryBusDebug.hpp @@ -56,10 +56,12 @@ public: const int column = 6; //! @brief Add a log to the model - void log(ComSquare::Debugger::BusLog log); + void log(const ComSquare::Debugger::BusLog& log); //! @brief Get a log at an index. ComSquare::Debugger::BusLog getLogAt(int index); + //! @brief Clear all the logs + void clearLogs(); //! @brief The number of row the table has. int rowCount(const QModelIndex &parent) const override; diff --git a/ui/busView.ui b/ui/busView.ui index 5185e76..9b91312 100644 --- a/ui/busView.ui +++ b/ui/busView.ui @@ -359,7 +359,7 @@ - + Clear