summaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-04-26 15:11:19 -0400
committerbd <bdunahu@operationnull.com>2025-04-26 15:11:19 -0400
commit6382d595cf947eb54249ff5fea20d8eb073ef3c1 (patch)
treeece23d61bf25869fe2058a1b2323dac417f25617 /gui
parent118427baa510419041c3f8e9c7a4616b93f01672 (diff)
Move digit formatter to util.h
Diffstat (limited to 'gui')
-rw-r--r--gui/digitlabel.cc4
-rw-r--r--gui/digitlabeldelegate.cc4
-rw-r--r--gui/digitlabelhelper.h43
-rw-r--r--gui/storageview.cc4
-rw-r--r--gui/util.cc8
-rw-r--r--gui/util.h23
6 files changed, 35 insertions, 51 deletions
diff --git a/gui/digitlabel.cc b/gui/digitlabel.cc
index a24a1e1..f77c1fa 100644
--- a/gui/digitlabel.cc
+++ b/gui/digitlabel.cc
@@ -16,7 +16,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "digitlabel.h"
-#include "digitlabelhelper.h"
+#include "util.h"
#include "gui.h"
DigitLabel::DigitLabel(QWidget *parent) : QLabel(parent) { setText(QString()); }
@@ -43,6 +43,6 @@ void DigitLabel::on_hex_toggle(bool is_hex)
void DigitLabel::update_display()
{
QString t;
- t = DigitLabelHelper::format_value(this->v, this->is_hex, this->is_cleared);
+ t = format_toggled_value(this->v, this->is_hex, this->is_cleared);
setText(t);
}
diff --git a/gui/digitlabeldelegate.cc b/gui/digitlabeldelegate.cc
index bf4b175..430946c 100644
--- a/gui/digitlabeldelegate.cc
+++ b/gui/digitlabeldelegate.cc
@@ -16,7 +16,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "digitlabeldelegate.h"
-#include "digitlabelhelper.h"
+#include "util.h"
#include <QString>
void DigitLabelDelegate::set_hex_display(bool hex)
@@ -39,7 +39,7 @@ void DigitLabelDelegate::paint(
QStyle *s;
v = index.data(Qt::DisplayRole).toInt();
- t = DigitLabelHelper::format_value(v, this->is_hex);
+ t = format_toggled_value(v, this->is_hex);
o = option;
initStyleOption(&o, index);
diff --git a/gui/digitlabelhelper.h b/gui/digitlabelhelper.h
deleted file mode 100644
index 744bf0f..0000000
--- a/gui/digitlabelhelper.h
+++ /dev/null
@@ -1,43 +0,0 @@
-// 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 DIGITLABELHELPER_H
-#define DIGITLABELHELPER_H
-
-#include <QString>
-
-class DigitLabelHelper
-{
- public:
- /**
- * Contains the main formatting logic used to format integers. Uses 2's
- * complement for hexadecimal numbers.
- * @param the value to be formated
- * @param if the value should be displayed in hex. If false, displays in
- * decimal.
- * @param if the value should display.
- * @return a string respecting the above parameters.
- */
- static QString format_value(int value, bool is_hex, bool is_cleared = false)
- {
- if (is_cleared)
- return QString();
- return is_hex ? QString::asprintf("%08X", value) : QString::number(value);
- }
-};
-
-#endif // DIGITLABELHELPER_H
diff --git a/gui/storageview.cc b/gui/storageview.cc
index 22baca0..2f444a9 100644
--- a/gui/storageview.cc
+++ b/gui/storageview.cc
@@ -17,7 +17,7 @@
#include "storageview.h"
#include "definitions.h"
-#include "digitlabelhelper.h"
+#include "util.h"
#include <QAbstractTableModel>
#include <QVector>
@@ -60,7 +60,7 @@ QVariant StorageView::headerData(int section, Qt::Orientation o, int role) const
return QVariant();
if (o == Qt::Vertical) {
- return DigitLabelHelper::format_value(section * 4, this->is_hex);
+ return format_toggled_value(section * 4, this->is_hex);
}
return QVariant();
}
diff --git a/gui/util.cc b/gui/util.cc
index ee75e56..72c0d87 100644
--- a/gui/util.cc
+++ b/gui/util.cc
@@ -1,4 +1,5 @@
#include "util.h"
+#include <QString>
int cache_size_mapper(int total_levels, int level)
{
@@ -14,3 +15,10 @@ int cache_size_mapper(int total_levels, int level)
return r;
}
+
+QString format_toggled_value(int value, bool is_hex, bool is_cleared)
+{
+ if (is_cleared)
+ return QString();
+ return is_hex ? QString::asprintf("%X", value) : QString::number(value);
+}
diff --git a/gui/util.h b/gui/util.h
index 87c33f6..8e9d308 100644
--- a/gui/util.h
+++ b/gui/util.h
@@ -1,8 +1,27 @@
+#ifndef UTIL_H
+#define UTIL_H
+
+#include <QString>
+
/**
- * Given `total_levels', returns an integer between 4 and 12 which is a linear map of `level' onto `total_levels'.
- * This is used for generating cache sizes given a number of levels.
+ * Given `total_levels', returns an integer between 4 and 12 which is a linear
+ * map of `level' onto `total_levels'. This is used for generating cache sizes
+ * given a number of levels.
* @param the total number of cache levels, zero-indexed.
* @param a numberedcache level, zero-indexed.
* @return an integer between 4-12, linearly scaled with level.
*/
int cache_size_mapper(int total_levels, int level);
+
+/**
+ * Contains the main formatting logic used to format integers. Uses 2's
+ * complement for hexadecimal numbers.
+ * @param the value to be formated
+ * @param if the value should be displayed in hex. If false, displays in
+ * decimal.
+ * @param if the value should display.
+ * @return a string respecting the above parameters.
+ */
+QString format_toggled_value(int value, bool is_hex, bool is_cleared = false);
+
+#endif // UTIL_H