Add MemoryViewerWidget as companion widget for the MemoryModel
MODIFY
src/mainwindow.cpp
src/mainwindow.cpp
@@ -45,7 +45,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), m_ui(new Ui::Main
tb = addToolBar("Processor");
tb->setVisible(false);
- m_memoryTab = new MemoryTab(tb, this);
+ m_memoryTab = new MemoryTab(*m_processorHandler, tb, this);
m_stackedTabs->insertWidget(2, m_memoryTab);
// Setup tab bar

MODIFY
src/memorytab.cpp
src/memorytab.cpp
#include "pipeline.h"
-MemoryTab::MemoryTab(QToolBar* toolbar, QWidget* parent) : RipesTab(toolbar, parent), m_ui(new Ui::MemoryTab) {
+MemoryTab::MemoryTab(ProcessorHandler& handler, QToolBar* toolbar, QWidget* parent)
+ : RipesTab(toolbar, parent), m_handler(handler), m_ui(new Ui::MemoryTab) {
m_ui->setupUi(this);
// Add display types to display comboboxes
@@ -17,6 +18,10 @@ MemoryTab::MemoryTab(QToolBar* toolbar, QWidget* parent) : RipesTab(toolbar, par
m_ui->memorydisplaytype->insertItem(0, type, displayTypes[type]);
}
+ m_ui->memoryViewerWidget->setHandler(&m_handler);
+ m_ui->memoryViewerWidget->updateModel();
+ m_ui->memoryViewerWidget->updateView();
+
m_ui->memorydisplaytype->setCurrentIndex(displayTypeN::Hex);
}
@@ -98,6 +103,7 @@ void MemoryTab::initializeMemoryView() {
void MemoryTab::update() {
m_model->updateModel();
m_ui->rwjumpwidget->updateModel();
+ m_ui->memoryViewerWidget->updateView();
}
void MemoryTab::jumpToAdress(uint32_t address) {

MODIFY
src/memorytab.h
src/memorytab.h
#include "mainmemory.h"
#include "memorydisplaydelegate.h"
#include "memorymodel.h"
+#include "processorhandler.h"
#include "ripestab.h"
namespace Ui {
@@ -22,7 +23,7 @@ class MemoryTab : public RipesTab {
Q_OBJECT
public:
- MemoryTab(QToolBar* toolbar, QWidget* parent = nullptr);
+ MemoryTab(ProcessorHandler& handler, QToolBar* toolbar, QWidget* parent = nullptr);
~MemoryTab() override;
void initMemoryTab();
@@ -44,6 +45,8 @@ private:
std::vector<uint32_t>* m_regPtr;
std::vector<RegisterWidget*> m_regWidgetPtrs;
+
+ ProcessorHandler& m_handler;
};
#endif // MEMORYTAB_H

MODIFY
src/memorytab.ui
src/memorytab.ui
</property>
</widget>
<widget class="QWidget" name="layoutWidget">
- <layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0">
+ <layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<x>0</x>
<y>0</y>
<width>606</width>
- <height>337</height>
+ <height>321</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_6">
</widget>
</widget>
</item>
+ <item>
+ <widget class="MemoryViewerWidget" name="memoryViewerWidget" native="true"/>
+ </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
</layout>
</widget>
<customwidgets>
+ <customwidget>
+ <class>MemoryView</class>
+ <extends>QTableView</extends>
+ <header>memoryview.h</header>
+ </customwidget>
<customwidget>
<class>RegisterWidget</class>
<extends>QWidget</extends>
<header>registerwidget.h</header>
<container>1</container>
</customwidget>
- <customwidget>
- <class>MemoryView</class>
- <extends>QTableView</extends>
- <header>memoryview.h</header>
- </customwidget>
<customwidget>
<class>GoToComboBox</class>
<extends>QComboBox</extends>
<header>rwjumpwidget.h</header>
<container>1</container>
</customwidget>
+ <customwidget>
+ <class>MemoryViewerWidget</class>
+ <extends>QWidget</extends>
+ <header>memoryviewerwidget.h</header>
+ <container>1</container>
+ </customwidget>
</customwidgets>
<resources/>
<connections/>

MODIFY
src/memoryview.cpp
src/memoryview.cpp
@@ -14,34 +14,7 @@ void MemoryView::wheelEvent(QWheelEvent* event) {
}
}
-void MemoryView::setVisibleRows() {
- // Detect and set changes in rowheight
- if (rowHeight(1) != 0) {
- m_rowHeight = rowHeight(1);
- }
-
- // Set visible rows from model, based on tableView size and rowheights
- int modelRows = dynamic_cast<MemoryModel*>(model())->getModelRows();
-
- // Calculate number of visible rows
- int visibleRows = (height() - horizontalHeader()->height() - 10) / m_rowHeight;
- if ((visibleRows % 2) == 0)
- visibleRows--;
-
- // Hide the rows above and below the requested range
- const int removeCnt = (modelRows - visibleRows) / 2;
- for (int i = 0; i < removeCnt; i++) {
- setRowHidden(i, true);
- }
- for (int i = removeCnt; i < (visibleRows + removeCnt); i++) {
- setRowHidden(i, false);
- }
- for (int i = visibleRows + removeCnt; i < (visibleRows + 2 * removeCnt); i++) {
- setRowHidden(i, true);
- }
-}
-
void MemoryView::resizeEvent(QResizeEvent* event) {
QTableView::resizeEvent(event);
- setVisibleRows();
+ emit resized();
}

MODIFY
src/memoryview.h
src/memoryview.h
@@ -20,10 +20,11 @@ protected:
void resizeEvent(QResizeEvent* event) override;
public slots:
- void setVisibleRows();
+ void setVisibleRows() {}
signals:
void scrolled(bool dir);
+ void resized();
private:
int m_rowHeight = 0;

ADD
src/memoryviewerwidget.cpp
+#include "memoryviewerwidget.h"
+#include "ui_memoryviewerwidget.h"
+
+#include <QTableView>
+
+#include "memorymodel.h"
+
+MemoryViewerWidget::MemoryViewerWidget(QWidget* parent) : QWidget(parent), m_ui(new Ui::MemoryViewerWidget) {
+ m_ui->setupUi(this);
+}
+
+MemoryViewerWidget::~MemoryViewerWidget() {
+ delete m_ui;
+}
+
+void MemoryViewerWidget::setHandler(ProcessorHandler* handler) {
+ m_handler = handler;
+ updateModel();
+}
+
+void MemoryViewerWidget::updateView() {
+ m_memoryModel->processorWasClocked();
+}
+
+void MemoryViewerWidget::updateModel() {
+ auto* oldModel = m_memoryModel;
+
+ m_memoryModel = new NewMemoryModel(*m_handler, this);
+ m_ui->memoryView->setModel(m_memoryModel);
+ m_ui->radixSelector->setRadix(m_memoryModel->getRadix());
+ connect(m_ui->radixSelector, &RadixSelectorWidget::radixChanged, m_memoryModel, &NewMemoryModel::setRadix);
+
+ // Connect scroll events on the view to modify the center address of the model
+ connect(m_ui->memoryView, &MemoryView::scrolled, [=](bool dir) {
+ if (dir) {
+ m_memoryModel->offsetCentralAddress(1);
+ } else {
+ m_memoryModel->offsetCentralAddress(-1);
+ }
+ });
+
+ m_memoryModel->setRowsVisible(1);
+ connect(m_ui->memoryView, &MemoryView::resized, [=] {
+ const auto rows = m_ui->memoryView->height() / m_ui->memoryView->rowHeight(0);
+ m_memoryModel->setRowsVisible(rows);
+ });
+
+ m_ui->memoryView->horizontalHeader()->setSectionResizeMode(NewMemoryModel::Address, QHeaderView::Stretch);
+
+ if (oldModel) {
+ delete oldModel;
+ }
+}

ADD
src/memoryviewerwidget.h
+#pragma once
+
+#include <QWidget>
+
+#include "memorymodel.h"
+#include "processorhandler.h"
+
+namespace Ui {
+class MemoryViewerWidget;
+}
+
+class MemoryViewerWidget : public QWidget {
+ Q_OBJECT
+
+public:
+ explicit MemoryViewerWidget(QWidget* parent = nullptr);
+ ~MemoryViewerWidget();
+
+ void updateModel();
+ void setHandler(ProcessorHandler* handler);
+
+ NewMemoryModel* m_memoryModel = nullptr;
+
+public slots:
+ void updateView();
+
+private:
+ Ui::MemoryViewerWidget* m_ui;
+ ProcessorHandler* m_handler = nullptr;
+};

ADD
src/memoryviewerwidget.ui
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MemoryViewerWidget</class>
+ <widget class="QWidget" name="MemoryViewerWidget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="MemoryView" name="memoryView"/>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="RadixSelectorWidget" name="radixSelector" native="true"/>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="gotoButton">
+ <property name="text">
+ <string>Go to address...</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Go to:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QComboBox" name="gotoCombobox"/>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>RadixSelectorWidget</class>
+ <extends>QWidget</extends>
+ <header>radixselectorwidget.h</header>
+ <container>1</container>
+ </customwidget>
+ <customwidget>
+ <class>MemoryView</class>
+ <extends>QTableView</extends>
+ <header>memoryview.h</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>

MODIFY
src/radix.h
src/radix.h
@@ -18,13 +18,13 @@ static const auto binRegex = QRegExp("0[bB][0-1]+");
static const auto unsignedRegex = QRegExp("[0-9]+");
static const auto signedRegex = QRegExp("[-]*[0-9]+");
-static QString encodeRadixValue(uint32_t value, const Radix type) {
+static QString encodeRadixValue(uint32_t value, const Radix type, unsigned width = 32) {
switch (type) {
case Radix::Hex: {
- return "0x" + QString::number(value, 16).rightJustified(32 / 4, '0');
+ return "0x" + QString::number(value, 16).rightJustified(width / 4, '0');
}
case Radix::Binary: {
- return "0b" + QString::number(value, 2).rightJustified(32, '0');
+ return "0b" + QString::number(value, 2).rightJustified(width, '0');
}
case Radix::Unsigned: {
return QString::number(value, 10);

Add MemoryViewerWidget as companion widget for the MemoryModel