From 94c0d7b5045244f20dfa13f7d31e0e06901908c2 Mon Sep 17 00:00:00 2001 From: bd Date: Sat, 26 Apr 2025 12:32:34 -0400 Subject: Add a digit delegate to toggle table base display --- gui/digitlabeldelegate.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 gui/digitlabeldelegate.h (limited to 'gui/digitlabeldelegate.h') 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 . + +#ifndef DIGITLABELDELEGATE_H +#define DIGITLABELDELEGATE_H + +#include +#include +#include +#include +#include +#include + +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 -- cgit v1.2.3 From b32bc409c18ceb4cd8147f11021e2c4b2746184b Mon Sep 17 00:00:00 2001 From: bd Date: Sat, 26 Apr 2025 14:41:02 -0400 Subject: right-align colum headers on table objects --- gui/digitlabeldelegate.cc | 6 ------ gui/digitlabeldelegate.h | 3 +-- gui/digitlabelhelper.h | 2 +- gui/storageview.cc | 7 +++++++ 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'gui/digitlabeldelegate.h') diff --git a/gui/digitlabeldelegate.cc b/gui/digitlabeldelegate.cc index 641b5a0..bf4b175 100644 --- a/gui/digitlabeldelegate.cc +++ b/gui/digitlabeldelegate.cc @@ -19,12 +19,6 @@ #include "digitlabelhelper.h" #include -DigitLabelDelegate::DigitLabelDelegate(QObject *parent) - : QStyledItemDelegate(parent) -{ - ; -} - void DigitLabelDelegate::set_hex_display(bool hex) { if (this->is_hex != hex) { diff --git a/gui/digitlabeldelegate.h b/gui/digitlabeldelegate.h index a823154..7714d25 100644 --- a/gui/digitlabeldelegate.h +++ b/gui/digitlabeldelegate.h @@ -28,9 +28,8 @@ class DigitLabelDelegate : public QStyledItemDelegate { Q_OBJECT - public: - explicit DigitLabelDelegate(QObject *parent = nullptr); + using QStyledItemDelegate::QStyledItemDelegate; public slots: void set_hex_display(bool hex); diff --git a/gui/digitlabelhelper.h b/gui/digitlabelhelper.h index 715089a..26e4637 100644 --- a/gui/digitlabelhelper.h +++ b/gui/digitlabelhelper.h @@ -36,7 +36,7 @@ class DigitLabelHelper { if (is_cleared) return QString(); - return is_hex ? QString::asprintf("%04X", value) + return is_hex ? QString::asprintf("%X", value) : QString::number(value); } }; diff --git a/gui/storageview.cc b/gui/storageview.cc index f6f9736..43837a9 100644 --- a/gui/storageview.cc +++ b/gui/storageview.cc @@ -48,6 +48,13 @@ QVariant StorageView::data(const QModelIndex &i, int role) const QVariant StorageView::headerData(int section, Qt::Orientation o, int role) const { + Qt::Alignment a; + + if (role == Qt::TextAlignmentRole) { + a = Qt::AlignRight | Qt::AlignVCenter; + return QVariant(static_cast(a)); + } + if (role != Qt::DisplayRole) return QVariant(); -- cgit v1.2.3