Create a basic memory-view in MemoryTab
MODIFY
src/memorytab.cpp
src/memorytab.cpp
#include "registerwidget.h"
+#include <algorithm>
+
MemoryTab::MemoryTab(QWidget *parent)
: QWidget(parent), m_ui(new Ui::MemoryTab) {
m_ui->setupUi(this);
}
void MemoryTab::init() {
- // !! m_memoryPtr and m_regPtr must be set before initializing
+ Q_ASSERT(m_memoryPtr != nullptr && m_regPtr != nullptr);
+ initializeMemoryView();
// Initialize register ABInames
QStringList ABInames = QStringList() << "zero"
@@ -100,4 +103,26 @@ void MemoryTab::updateRegisterWidget(int n) {
m_regWidgetPtrs[n]->setText();
}
+void MemoryTab::initializeMemoryView() {
+ std::vector<std::pair<uint32_t, uint8_t>> sortedMemory(m_memoryPtr->begin(),
+ m_memoryPtr->end());
+ std::sort(sortedMemory.begin(), sortedMemory.end(),
+ [](std::pair<uint32_t, uint8_t> a, std::pair<uint32_t, uint8_t> b) {
+ return a.first > b.first;
+ });
+ m_ui->memoryView->setRowCount(sortedMemory.size());
+ m_ui->memoryView->setColumnCount(2);
+ m_ui->memoryView->setSortingEnabled(false);
+ m_ui->memoryView->setHorizontalHeaderLabels(QStringList() << "Address"
+ << "Value");
+ m_ui->memoryView->verticalHeader()->setVisible(false);
+ int i = 0;
+ for (const auto &entry : sortedMemory) {
+ auto addr = new QTableWidgetItem(QString().setNum(entry.first, 16));
+ auto val = new QTableWidgetItem(QString("%1").arg(entry.second));
+ m_ui->memoryView->setItem(i, 0, addr);
+ m_ui->memoryView->setItem(i, 1, val);
+ i++;
+ }
+}
MemoryTab::~MemoryTab() { delete m_ui; }

MODIFY
src/memorytab.h
src/memorytab.h
@@ -27,6 +27,8 @@ public slots:
void updateRegisterWidget(int n);
private:
+ void initializeMemoryView();
+
Ui::MemoryTab *m_ui;
std::unordered_map<uint32_t, uint8_t> *m_memoryPtr;

MODIFY
src/memorytab.ui
src/memorytab.ui
<item row="0" column="0">
<layout class="QVBoxLayout" name="memoryLayout">
<item>
- <widget class="QTableView" name="tableView"/>
+ <widget class="QTableWidget" name="memoryView"/>
</item>
</layout>
</item>
</item>
<item>
<widget class="QComboBox" name="comboBox">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
<item>
<property name="text">
<string>Hex</string>

Create a basic memory-view in MemoryTab