summaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-04-26 03:06:14 -0400
committerbd <bdunahu@operationnull.com>2025-04-26 03:06:14 -0400
commitc98a0c26c4ccb5c4ae0e9f5810be910a7b299037 (patch)
tree25ee156ab0922694fa795ba6085749bcfcc157e7 /gui
parent858a682d11cef5b7695050967b1c6b184eda3c6a (diff)
Add proper tables display for storage devices
Diffstat (limited to 'gui')
-rw-r--r--gui/gui.cc71
-rw-r--r--gui/gui.h6
-rw-r--r--gui/resources/styles.qss30
-rw-r--r--gui/storageview.cc70
-rw-r--r--gui/storageview.h86
-rw-r--r--gui/worker.cc20
-rw-r--r--gui/worker.h9
7 files changed, 229 insertions, 63 deletions
diff --git a/gui/gui.cc b/gui/gui.cc
index 905b018..9baed38 100644
--- a/gui/gui.cc
+++ b/gui/gui.cc
@@ -19,8 +19,11 @@
#include "./ui_gui.h"
#include "dynamicwaysentry.h"
#include "messages.h"
+#include "storageview.h"
#include <QPixmap>
#include <QString>
+#include <QTableView>
+#include <QHeaderView>
GUI::GUI(QWidget *parent) : QMainWindow(parent), ui(new Ui::GUI)
{
@@ -131,37 +134,6 @@ void displayArrayHTML(QTextEdit *textEdit, const std::array<int, GPR_NUM> &data)
textEdit->setReadOnly(true);
}
-void displayTableHTML(
- QTextEdit *textEdit,
- const std::vector<std::array<signed int, LINE_SIZE>> &data)
-{
- textEdit->setReadOnly(false);
- QString tableText = "<table border='1' cellspacing='0' cellpadding='8' "
- "style='border-collapse: collapse; width: 100%; "
- "border: 2px solid black;'>";
-
- int index = 0;
- for (const auto &row : data) {
- tableText += "<tr>";
- for (signed int value : row) {
- tableText += QString("<td align='center' style='border: 2px solid "
- "black; min-width: 60px; padding: 10px;'>"
- "%1 <sup style='font-size: 10px; font-weight: "
- "bold; color: black;'>%2</sup>"
- "</td>")
- .arg(QString::asprintf("%04X", value))
- .arg(index);
- index++;
- }
- tableText += "</tr>";
- }
-
- tableText += "</table>";
-
- textEdit->setHtml(tableText);
- textEdit->setReadOnly(true);
-}
-
void GUI::on_worker_refresh_gui(int cycles, int pc)
{
ui->p_counter->set_value(pc);
@@ -241,16 +213,15 @@ void GUI::onWorkerWriteBackInfo(const InstrDTO *i)
}
}
-void GUI::onWorkerShowStorage(
- const std::vector<std::array<signed int, LINE_SIZE>> data, int i)
+void GUI::onWorkerShowStorage(const QVector<QVector<int>> &data, int i)
{
- std::cout << this->tab_text_boxes.size() << std::endl;
- displayTableHTML(this->tab_text_boxes.at(i), data);
+ this->tab_boxes.at(i)->set_data(data);
}
void GUI::onWorkerShowRegisters(const std::array<int, GPR_NUM> &data)
{
- displayArrayHTML(this->tab_text_boxes.at(0), data);
+ ;
+ // displayArrayHTML(this->tab_boxes.at(0), data);
}
void GUI::on_upload_intructions_btn_clicked()
@@ -368,27 +339,33 @@ void GUI::on_config_clicked()
void GUI::make_tabs(int num)
{
int i;
- QStringList names;
- QTextEdit *e;
+ QStringList xTra;
+ StorageView *e;
+ QTableView *t;
QString n;
- names = {"Registers", "DRAM"};
+ xTra = {"Registers", "DRAM"};
ui->storage->clear();
- this->tab_text_boxes.clear();
+
+ this->tab_boxes.clear();
+ qDeleteAll(this->tab_boxes);
for (i = 0; i < num; ++i) {
- e = new QTextEdit();
- e->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ e = new StorageView(10, this);
+
+ t = new QTableView;
+ t->setModel(e);
+ t->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
// make the name
- if (i < names.size())
- n = names[i];
+ if (i < xTra.size())
+ n = xTra[i];
else
- n = QString("Level %1").arg(i - 1);
+ n = QString("L%1").arg(i - 1);
- ui->storage->addTab(e, n);
- this->tab_text_boxes.push_back(e);
+ ui->storage->addTab(t, n);
+ this->tab_boxes.push_back(e);
}
}
diff --git a/gui/gui.h b/gui/gui.h
index 26e9b03..f723729 100644
--- a/gui/gui.h
+++ b/gui/gui.h
@@ -18,6 +18,7 @@
#ifndef GUI_H
#define GUI_H
+#include "storageview.h"
#include "worker.h"
#include <QFile>
#include <QFileDialog>
@@ -67,8 +68,7 @@ class GUI : public QMainWindow
void onWorkerWriteBackInfo(const InstrDTO *);
- void onWorkerShowStorage(
- const std::vector<std::array<signed int, LINE_SIZE>> data, int i);
+ void onWorkerShowStorage(const QVector<QVector<int>> &data, int i);
void onWorkerShowRegisters(const std::array<int, GPR_NUM> &data);
@@ -104,7 +104,7 @@ class GUI : public QMainWindow
/**
* The list of storage displays.
*/
- std::vector<QTextEdit *> tab_text_boxes;
+ std::vector<StorageView *> tab_boxes;
/**
* Whether or not numerical values are currently displaying in hex.
diff --git a/gui/resources/styles.qss b/gui/resources/styles.qss
index 76d0311..a61035e 100644
--- a/gui/resources/styles.qss
+++ b/gui/resources/styles.qss
@@ -50,15 +50,27 @@ QGroupBox::title {
QLabel {
}
-/* text entry */
-QLineEdit {
- font-size: 18pt;
- border-radius: 0px;
- padding: 0 4px;
- selection-background-color: "#00cc00";
+QTableView {
+ border: 0px;
+ selection-background-color: transparent;
+ selection-color: black;
+ outline: none;
+}
+
+QTableView::item {
+ border: none;
+ padding: 4px;
+}
+
+QHeaderView::section {
+ color: "#00cc00";
+ background-color: "#000200";
+ border: none;
}
-QTextEdit, QListView {
+QTableView QTableCornerButton::section {
+ background-color: "#000200";
+ border: none;
}
QPushButton {
@@ -71,8 +83,8 @@ QPushButton {
QPushButton:pressed {
color: "#00cc00";
- background-color: "#000200";
-}
+ background-color: "#000200";}
+
QPushButton:flat {
border: none; /* no border for a flat push button */
diff --git a/gui/storageview.cc b/gui/storageview.cc
new file mode 100644
index 0000000..f6f9736
--- /dev/null
+++ b/gui/storageview.cc
@@ -0,0 +1,70 @@
+// 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 <https://www.gnu.org/licenses/>.
+
+#include "storageview.h"
+#include "definitions.h"
+#include <QAbstractTableModel>
+#include <QVector>
+
+StorageView::StorageView(int rows, QObject *parent)
+ : QAbstractTableModel(parent)
+{
+ this->r = rows;
+ this->d.resize(rows);
+ for (auto &row : this->d)
+ row.resize(LINE_SIZE, 0);
+}
+
+int StorageView::rowCount(const QModelIndex &) const { return this->r; }
+
+int StorageView::columnCount(const QModelIndex &) const { return LINE_SIZE; }
+
+QVariant StorageView::data(const QModelIndex &i, int role) const
+{
+ Qt::Alignment a;
+
+ if (role == Qt::TextAlignmentRole) {
+ a = Qt::AlignRight | Qt::AlignVCenter;
+ return QVariant(static_cast<int>(a));
+ }
+ if (!i.isValid() || role != Qt::DisplayRole)
+ return QVariant();
+ return this->d[i.row()][i.column()];
+}
+
+QVariant StorageView::headerData(int section, Qt::Orientation o, int role) const
+{
+ if (role != Qt::DisplayRole)
+ return QVariant();
+
+ if (o == Qt::Vertical) {
+ return section * 4;
+ }
+ return QVariant();
+}
+
+Qt::ItemFlags StorageView::flags(const QModelIndex &i) const {
+ (void)i;
+ return Qt::ItemIsEnabled;
+}
+
+void StorageView::set_data(const QVector<QVector<int>> &data)
+{
+ beginResetModel();
+ this->d = data;
+ endResetModel();
+}
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 <https://www.gnu.org/licenses/>.
+
+#ifndef STORAGEVIEW_H
+#define STORAGEVIEW_H
+
+#include <QAbstractTableModel>
+#include <QVector>
+
+// 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<QVector<int>> &data);
+
+ private:
+ /**
+ * The number of rows in this table.
+ */
+ int r;
+ /**
+ * The data this table displays.
+ */
+ QVector<QVector<int>> d;
+};
+
+#endif // STORAGEVIEW_H
diff --git a/gui/worker.cc b/gui/worker.cc
index a0e21f6..6419b73 100644
--- a/gui/worker.cc
+++ b/gui/worker.cc
@@ -83,11 +83,10 @@ void Worker::update()
this->ct_mutex.lock();
emit register_storage(this->ct->get_gprs());
- emit storage(this->s.at(0)->view(0, 255), 1);
+ emit storage(this->data_to_QT(this->s.at(0)->get_data()), 1);
for (i = 1; i < s.size(); ++i)
- emit storage(
- this->s.at(i - 1)->view(0, 1 << this->size_inc * i), i + 1);
+ emit storage(this->data_to_QT(this->s.at(i - 1)->get_data()), i + 1);
emit clock_cycles(this->ct->get_clock_cycle(), this->ct->get_pc());
emit if_info(this->if_stage->get_instr());
@@ -97,3 +96,18 @@ void Worker::update()
emit wb_info(this->wb_stage->get_instr());
this->ct_mutex.unlock();
}
+
+QVector<QVector<int>>
+Worker::data_to_QT(std::vector<std::array<signed int, LINE_SIZE>> data)
+{
+ QVector<QVector<int>> r;
+ QVector<int> tmp;
+
+ r.reserve(static_cast<int>(data.size()));
+
+ for (const auto &line : data) {
+ tmp = QVector<int>(line.begin(), line.end());
+ r.append(tmp);
+ }
+ return r;
+}
diff --git a/gui/worker.h b/gui/worker.h
index 06e4a16..c0e72d3 100644
--- a/gui/worker.h
+++ b/gui/worker.h
@@ -70,7 +70,7 @@ class Worker : public QObject
signals:
void clock_cycles(int value, int pc);
void
- storage(const std::vector<std::array<signed int, LINE_SIZE>> data, int i);
+ storage(QVector<QVector<int>> data, int i);
void register_storage(const std::array<int, GPR_NUM> data);
void if_info(const InstrDTO *);
void id_info(const InstrDTO *);
@@ -81,6 +81,13 @@ class Worker : public QObject
private:
/**
+ * Converts a vector of arrays into a QVector of QVectors.
+ * @param the original data
+ * @return a less universal version of the same thing
+ */
+ QVector<QVector<int>>
+ data_to_QT(std::vector<std::array<signed int, LINE_SIZE>> data);
+ /**
* Sets the GUI signals to update the storage, clock cycle, and stage
* displays.
*/