Implement scrolling in memoryView
MODIFY
RISC-V-sim.pro
RISC-V-sim.pro
@@ -22,7 +22,8 @@ SOURCES += src/main.cpp \
src/runnercache.cpp \
src/cacheinspector.cpp \
src/memorymodel.cpp \
- src/memorydisplaydelegate.cpp
+ src/memorydisplaydelegate.cpp \
+ src/memoryview.cpp
HEADERS += \
src/parser.h \
@@ -41,7 +42,8 @@ HEADERS += \
src/runnercache.h \
src/cacheinspector.h \
src/memorymodel.h \
- src/memorydisplaydelegate.h
+ src/memorydisplaydelegate.h \
+ src/memoryview.h
FORMS += \
src/mainwindow.ui \

MODIFY
src/memorytab.cpp
src/memorytab.cpp
#include "registerwidget.h"
+#include <QWheelEvent>
#include <algorithm>
MemoryTab::MemoryTab(QWidget *parent)
@@ -138,6 +139,15 @@ void MemoryTab::initializeMemoryView() {
m_model->offsetCentralAddress(-4);
m_ui->memoryView->viewport()->repaint();
});
+
+ // Connect scroll events to the model
+ connect(m_ui->memoryView, &MemoryView::scrolled, [=](bool dir) {
+ if (dir) {
+ m_model->offsetCentralAddress(4);
+ } else {
+ m_model->offsetCentralAddress(-4);
+ };
+ });
}
MemoryTab::~MemoryTab() { delete m_ui; }

MODIFY
src/memorytab.ui
src/memorytab.ui
<item row="0" column="0">
<layout class="QVBoxLayout" name="memoryLayout">
<item>
- <widget class="QTableView" name="memoryView"/>
+ <widget class="MemoryView" name="memoryView"/>
</item>
</layout>
</item>
</item>
</layout>
</widget>
+ <customwidgets>
+ <customwidget>
+ <class>MemoryView</class>
+ <extends>QTableView</extends>
+ <header>memoryview.h</header>
+ </customwidget>
+ </customwidgets>
<resources/>
<connections/>
</ui>

ADD
src/memoryview.cpp
+#include "memoryview.h"
+
+MemoryView::MemoryView(QWidget *parent) : QTableView(parent) {}
+
+void MemoryView::wheelEvent(QWheelEvent *event) {
+ if (event->angleDelta().y() > 0) {
+ emit scrolled(true);
+ } else {
+ emit scrolled(false);
+ }
+}

ADD
src/memoryview.h
+#ifndef MEMORYVIEW_H
+#define MEMORYVIEW_H
+
+#include <QTableView>
+#include <QWheelEvent>
+
+// Extension of QTableView - catches QWheelEvents and triggers the memory model
+// to shift its
+// central address
+
+class MemoryView : public QTableView {
+ Q_OBJECT
+
+public:
+ MemoryView(QWidget *parent = nullptr);
+
+ void wheelEvent(QWheelEvent *event) override;
+
+signals:
+ void scrolled(bool dir);
+};
+
+#endif // MEMORYVIEW_H

Implement scrolling in memoryView