diff options
author | bd <bdunahu@operationnull.com> | 2025-04-26 12:32:34 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-04-26 12:32:34 -0400 |
commit | 94c0d7b5045244f20dfa13f7d31e0e06901908c2 (patch) | |
tree | 2e7d8faf981fb84dcd2c1fbe2daad0e3e013dd0c /gui | |
parent | a78163745b43a0c420ae4ea5792def30a94420eb (diff) |
Add a digit delegate to toggle table base display
Diffstat (limited to 'gui')
-rw-r--r-- | gui/digitlabeldelegate.cc | 57 | ||||
-rw-r--r-- | gui/digitlabeldelegate.h | 47 | ||||
-rw-r--r-- | gui/gui.cc | 12 |
3 files changed, 114 insertions, 2 deletions
diff --git a/gui/digitlabeldelegate.cc b/gui/digitlabeldelegate.cc new file mode 100644 index 0000000..641b5a0 --- /dev/null +++ b/gui/digitlabeldelegate.cc @@ -0,0 +1,57 @@ +// 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 "digitlabeldelegate.h" +#include "digitlabelhelper.h" +#include <QString> + +DigitLabelDelegate::DigitLabelDelegate(QObject *parent) + : QStyledItemDelegate(parent) +{ + ; +} + +void DigitLabelDelegate::set_hex_display(bool hex) +{ + if (this->is_hex != hex) { + this->is_hex = hex; + if (auto v = qobject_cast<QAbstractItemView *>(parent())) + v->viewport()->update(); + } +} + +void DigitLabelDelegate::paint( + QPainter *painter, + const QStyleOptionViewItem &option, + const QModelIndex &index) const +{ + int v; + QString t; + QStyleOptionViewItem o; + QStyle *s; + + v = index.data(Qt::DisplayRole).toInt(); + t = DigitLabelHelper::format_value(v, this->is_hex); + + o = option; + initStyleOption(&o, index); + o.text = t; + + const QWidget *w = option.widget; + s = w ? w->style() : QApplication::style(); + s->drawControl(QStyle::CE_ItemViewItem, &o, painter, w); +} diff --git a/gui/digitlabeldelegate.h b/gui/digitlabeldelegate.h new file mode 100644 index 0000000..a823154 --- /dev/null +++ b/gui/digitlabeldelegate.h @@ -0,0 +1,47 @@ +// 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 DIGITLABELDELEGATE_H +#define DIGITLABELDELEGATE_H + +#include <QAbstractItemView> +#include <QApplication> +#include <QPainter> +#include <QString> +#include <QStyleOptionViewItem> +#include <QStyledItemDelegate> + +class DigitLabelDelegate : public QStyledItemDelegate +{ + Q_OBJECT + + public: + explicit DigitLabelDelegate(QObject *parent = nullptr); + + public slots: + void set_hex_display(bool hex); + + private: + bool is_hex = true; + + void paint( + QPainter *painter, + const QStyleOptionViewItem &option, + const QModelIndex &index) const override; +}; + +#endif // DIGITLABELDELEGATE_H @@ -17,6 +17,7 @@ #include "gui.h" #include "./ui_gui.h" +#include "digitlabeldelegate.h" #include "dynamicwaysentry.h" #include "messages.h" #include "storageview.h" @@ -57,7 +58,6 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent), ui(new Ui::GUI) for (DigitLabel *label : labels) { connect(this, &GUI::hex_toggled, label, &DigitLabel::on_hex_toggle); } - emit this->hex_toggled(this->is_hex); // display clock cycles and PC connect(worker, &Worker::clock_cycles, this, &GUI::on_worker_refresh_gui); @@ -345,6 +345,7 @@ void GUI::make_tabs(int num) StorageView *e; QTableView *t; QString n; + DigitLabelDelegate *d; ui->storage->clear(); @@ -361,11 +362,18 @@ void GUI::make_tabs(int num) e = new StorageView(MEM_LINES, this); } else { n = QString("L%1").arg(i - 1); - e = new StorageView(cache_size_mapper(this->curr_cache_levels, i), this); + e = new StorageView( + cache_size_mapper(this->curr_cache_levels, i), this); } t = new QTableView; t->setModel(e); + d = new DigitLabelDelegate(t); + + connect( + this, &GUI::hex_toggled, d, &DigitLabelDelegate::set_hex_display); + + t->setItemDelegate(d); t->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); ui->storage->addTab(t, n); |