Move cache widgets to separate CacheTabWidget
ADD
src/cachetabwidget.cpp
+#include "cachetabwidget.h"
+#include "ui_cachetabwidget.h"
+
+#include "memoryviewerwidget.h"
+
+#include "memorytab.h"
+
+namespace Ripes {
+
+CacheTabWidget::CacheTabWidget(QWidget* parent) : QWidget(parent), m_ui(new Ui::CacheTabWidget) {
+ while (parent != nullptr) {
+ auto* mt = dynamic_cast<MemoryTab*>(parent);
+ if (mt) {
+ m_parent = mt;
+ break;
+ } else {
+ parent = parent->parentWidget();
+ }
+ }
+ Q_ASSERT(m_parent);
+
+ m_ui->setupUi(this);
+
+ m_ui->dataCacheWidget->setType(CacheSim::CacheType::DataCache);
+ m_ui->instructionCacheWidget->setType(CacheSim::CacheType::InstrCache);
+
+ // Make selection changes in the cache trigger the memory viewer to set its central address to the selected address
+ connectCacheWidget(m_ui->dataCacheWidget);
+ connectCacheWidget(m_ui->instructionCacheWidget);
+
+ // Make cache configuration changes emit processor reset requests
+ connect(m_ui->dataCacheWidget, &CacheWidget::configurationChanged, [=] { emit m_parent->reqProcessorReset(); });
+ connect(m_ui->instructionCacheWidget, &CacheWidget::configurationChanged,
+ [=] { emit m_parent->reqProcessorReset(); });
+}
+
+void CacheTabWidget::connectCacheWidget(CacheWidget* w) {
+ connect(w, &CacheWidget::cacheAddressSelected, this, &CacheTabWidget::focusAddressChanged);
+}
+
+CacheTabWidget::~CacheTabWidget() {
+ delete m_ui;
+}
+
+} // namespace Ripes

ADD
src/cachetabwidget.h
+#pragma once
+#include <QWidget>
+
+namespace Ripes {
+class MemoryTab;
+class CacheWidget;
+
+namespace Ui {
+class CacheTabWidget;
+}
+
+class CacheTabWidget : public QWidget {
+ Q_OBJECT
+
+public:
+ explicit CacheTabWidget(QWidget* parent = nullptr);
+ ~CacheTabWidget();
+
+signals:
+ void focusAddressChanged(unsigned address);
+
+private:
+ void connectCacheWidget(CacheWidget* w);
+
+ Ui::CacheTabWidget* m_ui;
+ MemoryTab* m_parent = nullptr;
+};
+
+} // namespace Ripes

ADD
src/cachetabwidget.ui
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Ripes::CacheTabWidget</class>
+ <widget class="QWidget" name="Ripes::CacheTabWidget">
+ <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="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QTabWidget" name="tabWidget">
+ <property name="currentIndex">
+ <number>0</number>
+ </property>
+ <widget class="QWidget" name="tab">
+ <attribute name="title">
+ <string>L1 Data Cache</string>
+ </attribute>
+ <layout class="QGridLayout" name="gridLayout_2">
+ <item row="0" column="0">
+ <widget class="CacheWidget" name="dataCacheWidget" native="true"/>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="tab_2">
+ <attribute name="title">
+ <string>L1 Instr. Cache</string>
+ </attribute>
+ <layout class="QGridLayout" name="gridLayout_3">
+ <item row="0" column="0">
+ <widget class="CacheWidget" name="instructionCacheWidget" native="true"/>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>CacheWidget</class>
+ <extends>QWidget</extends>
+ <header>cachesim/cachewidget.h</header>
+ <container>1</container>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>

MODIFY
src/memorytab.cpp
src/memorytab.cpp
#include "ui_memorytab.h"
#include <QGraphicsItem>
+#include <QPushButton>
#include <QToolBar>
#include "cachesim/cachesim.h"
@@ -17,19 +18,9 @@ MemoryTab::MemoryTab(QToolBar* toolbar, QWidget* parent) : RipesTab(toolbar, par
m_ui->memoryViewerWidget->updateModel();
m_ui->memoryViewerWidget->updateView();
- m_ui->dataCache->setType(CacheSim::CacheType::DataCache);
- m_ui->instructionCache->setType(CacheSim::CacheType::InstrCache);
-
- // Make selection changes in the cache trigger the memory viewer to set its central address to the selected address
- connect(m_ui->dataCache, &CacheWidget::cacheAddressSelected, m_ui->memoryViewerWidget,
- &MemoryViewerWidget::setCentralAddress);
- connect(m_ui->instructionCache, &CacheWidget::cacheAddressSelected, m_ui->memoryViewerWidget,
+ connect(m_ui->cacheTabWidget, &CacheTabWidget::focusAddressChanged, m_ui->memoryViewerWidget,
&MemoryViewerWidget::setCentralAddress);
- // Make cache configuration changes emit processor reset requests
- connect(m_ui->dataCache, &CacheWidget::configurationChanged, [=] { emit reqProcessorReset(); });
- connect(m_ui->instructionCache, &CacheWidget::configurationChanged, [=] { emit reqProcessorReset(); });
-
// During processor running, it should not be possible to interact with the memory viewer or cache widgets
connect(ProcessorHandler::get(), &ProcessorHandler::runStarted, [=] { setEnabled(false); });
connect(ProcessorHandler::get(), &ProcessorHandler::runFinished, [=] { setEnabled(true); });

MODIFY
src/memorytab.h
src/memorytab.h
@@ -17,18 +17,19 @@ class MemoryTab;
}
class MemoryTab : public RipesTab {
+ friend class CacheTabWidget;
Q_OBJECT
public:
MemoryTab(QToolBar* toolbar, QWidget* parent = nullptr);
~MemoryTab() override;
-signals:
- void reqProcessorReset();
-
public slots:
void update();
+signals:
+ void reqProcessorReset();
+
private:
Ui::MemoryTab* m_ui = nullptr;
};

MODIFY
src/memorytab.ui
src/memorytab.ui
<property name="windowTitle">
<string>Form</string>
</property>
- <layout class="QGridLayout" name="gridLayout_5">
+ <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QSplitter" name="splitter">
<property name="orientation">
</layout>
</widget>
</widget>
- <widget class="QTabWidget" name="tabWidget">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="currentIndex">
- <number>0</number>
- </property>
- <widget class="QWidget" name="tab_3">
- <attribute name="title">
- <string>Data cache</string>
- </attribute>
- <layout class="QGridLayout" name="gridLayout">
- <item row="0" column="0">
- <widget class="CacheWidget" name="dataCache" native="true"/>
- </item>
- </layout>
- </widget>
- <widget class="QWidget" name="tab_4">
- <attribute name="title">
- <string>Instruction cache</string>
- </attribute>
- <layout class="QGridLayout" name="gridLayout_3">
- <item row="0" column="0">
- <widget class="CacheWidget" name="instructionCache" native="true"/>
- </item>
- </layout>
- </widget>
- </widget>
+ <widget class="CacheTabWidget" name="cacheTabWidget" native="true"/>
</widget>
</item>
</layout>
<container>1</container>
</customwidget>
<customwidget>
- <class>CacheWidget</class>
+ <class>CacheTabWidget</class>
<extends>QWidget</extends>
- <header>cachesim/cachewidget.h</header>
+ <header>cachetabwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>

Move cache widgets to separate CacheTabWidget