From c98a0c26c4ccb5c4ae0e9f5810be910a7b299037 Mon Sep 17 00:00:00 2001 From: bd Date: Sat, 26 Apr 2025 03:06:14 -0400 Subject: Add proper tables display for storage devices --- gui/storageview.h | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 gui/storageview.h (limited to 'gui/storageview.h') diff --git a/gui/storageview.h b/gui/storageview.h new file mode 100644 index 0000000..4956f23 --- /dev/null +++ b/gui/storageview.h @@ -0,0 +1,86 @@ +// Simulator for the RISC-V[ECTOR] mini-ISA +// Copyright (C) 2025 Siddarth Suresh +// Copyright (C) 2025 bdunahu + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#ifndef STORAGEVIEW_H +#define STORAGEVIEW_H + +#include +#include + +// see https://doc.qt.io/qt-6/qabstracttablemodel.html +class StorageView : public QAbstractTableModel +{ + Q_OBJECT + public: + /** + * Constructor. Initializes a clean StorageView object with + * `rows' rows. + * @param the number of rows + */ + StorageView(int rows, QObject *parent = nullptr); + + /** + * Returns the number of rows in this table. + * @param the parent + * @return the number of rows under the given parent. + */ + int rowCount(const QModelIndex &) const override; + /** + * Returns the number of columns in this table. + * @param the parent + * @return the number of columns under the given parent (hint: it's + * LINE_SIZE) + */ + int columnCount(const QModelIndex &) const override; + + /** + * Returns a properly formatted cell, including alignment.This function is + * specific to the implementation details of QAbstractTableModel. + */ + QVariant + data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + + /** + * Adds custom formatting options for row and column headers. + */ + QVariant headerData( + int section, + Qt::Orientation o, + int role = Qt::DisplayRole) const override; + + /** + * Ensures the table is enabled, but not selectable. + */ + Qt::ItemFlags flags(const QModelIndex &i) const override; + + /** + * @param field to assign to `this->d' + */ + void set_data(const QVector> &data); + + private: + /** + * The number of rows in this table. + */ + int r; + /** + * The data this table displays. + */ + QVector> d; +}; + +#endif // STORAGEVIEW_H -- cgit v1.2.3 From ae2aaecfc1b2402a55e99cf674eff7b6175b0b6d Mon Sep 17 00:00:00 2001 From: bd Date: Sat, 26 Apr 2025 14:57:56 -0400 Subject: Basic hex formatting on row headers for storage tables --- gui/digitlabelhelper.h | 3 +-- gui/gui.cc | 3 ++- gui/storageview.cc | 15 +++++++++++++-- gui/storageview.h | 7 +++++++ 4 files changed, 23 insertions(+), 5 deletions(-) (limited to 'gui/storageview.h') diff --git a/gui/digitlabelhelper.h b/gui/digitlabelhelper.h index 26e4637..4d45c68 100644 --- a/gui/digitlabelhelper.h +++ b/gui/digitlabelhelper.h @@ -36,8 +36,7 @@ class DigitLabelHelper { if (is_cleared) return QString(); - return is_hex ? QString::asprintf("%X", value) - : QString::number(value); + return is_hex ? QString::asprintf("%X", value) : QString::number(value); } }; diff --git a/gui/gui.cc b/gui/gui.cc index 80d4a2a..2555435 100644 --- a/gui/gui.cc +++ b/gui/gui.cc @@ -353,7 +353,6 @@ void GUI::make_tabs(int num) qDeleteAll(this->tab_boxes); for (i = 0; i < num; ++i) { - // make the name if (i == 0) { n = "Registers"; e = new StorageView(0, this); @@ -370,6 +369,8 @@ void GUI::make_tabs(int num) t->setModel(e); d = new DigitLabelDelegate(t); + connect( + this, &GUI::hex_toggled, e, &StorageView::set_hex_display); connect( this, &GUI::hex_toggled, d, &DigitLabelDelegate::set_hex_display); diff --git a/gui/storageview.cc b/gui/storageview.cc index 43837a9..22baca0 100644 --- a/gui/storageview.cc +++ b/gui/storageview.cc @@ -17,6 +17,7 @@ #include "storageview.h" #include "definitions.h" +#include "digitlabelhelper.h" #include #include @@ -59,12 +60,13 @@ QVariant StorageView::headerData(int section, Qt::Orientation o, int role) const return QVariant(); if (o == Qt::Vertical) { - return section * 4; + return DigitLabelHelper::format_value(section * 4, this->is_hex); } return QVariant(); } -Qt::ItemFlags StorageView::flags(const QModelIndex &i) const { +Qt::ItemFlags StorageView::flags(const QModelIndex &i) const +{ (void)i; return Qt::ItemIsEnabled; } @@ -75,3 +77,12 @@ void StorageView::set_data(const QVector> &data) this->d = data; endResetModel(); } + +void StorageView::set_hex_display(bool hex) +{ + if (this->is_hex != hex) { + beginResetModel(); + this->is_hex = hex; + endResetModel(); + } +} diff --git a/gui/storageview.h b/gui/storageview.h index 4956f23..0518d8f 100644 --- a/gui/storageview.h +++ b/gui/storageview.h @@ -72,11 +72,18 @@ class StorageView : public QAbstractTableModel */ void set_data(const QVector> &data); + public slots: + void set_hex_display(bool hex); + private: /** * The number of rows in this table. */ int r; + /** + * Whether or not the headers should be displayed in hex. + */ + bool is_hex = true; /** * The data this table displays. */ -- cgit v1.2.3