Add "Go to register" in MemoryViewerWidget
MODIFY
src/gotocombobox.cpp
src/gotocombobox.cpp
@@ -20,14 +20,8 @@ void GoToComboBox::showPopup() {
if (count())
clear();
- addItem("Select", QVariant::fromValue<GoToFunction>(GoToFunction::Select));
- addItem("Address...", QVariant::fromValue<GoToFunction>(GoToFunction::Address));
-
- if (ProcessorHandler::get()->getProgram()) {
- for (const auto& section : ProcessorHandler::get()->getProgram()->sections) {
- addItem(section.name, QVariant::fromValue<GoToFunction>(GoToFunction::Section));
- }
- }
+ addItem("Select", QVariant::fromValue<GoToUserData>({GoToFunction::Select, 0}));
+ addTargets();
QComboBox::showPopup();
}
@@ -35,10 +29,10 @@ void GoToComboBox::showPopup() {
void GoToComboBox::signalFilter(int index) {
const auto& value = itemData(index);
- const GoToFunction f = qvariant_cast<GoToFunction>(value);
- switch (f) {
+ const auto f = qvariant_cast<GoToUserData>(value);
+ switch (f.func) {
case GoToFunction::Select:
- return;
+ break;
case GoToFunction::Address: {
// Create goto-address dialog
AddressDialog dialog;
@@ -47,13 +41,39 @@ void GoToComboBox::signalFilter(int index) {
}
break;
}
- case GoToFunction::Section: {
- const QString& sectionName = itemText(index);
- emit jumpToAddress(ProcessorHandler::get()->getProgram()->getSection(sectionName)->address);
+ case GoToFunction::Custom: {
+ emit jumpToAddress(addrForIndex(index));
break;
}
}
-
clear();
}
+
+void GoToSectionComboBox::addTargets() {
+ addItem("Address...", QVariant::fromValue<GoToUserData>({GoToFunction::Address, 0}));
+ if (ProcessorHandler::get()->getProgram()) {
+ for (const auto& section : ProcessorHandler::get()->getProgram()->sections) {
+ addItem(section.name, QVariant::fromValue<GoToUserData>({GoToFunction::Custom, 0}));
+ }
+ }
+}
+
+uint32_t GoToSectionComboBox::addrForIndex(int i) {
+ const QString& sectionName = itemText(i);
+ return ProcessorHandler::get()->getProgram()->getSection(sectionName)->address;
+}
+
+void GoToRegisterComboBox::addTargets() {
+ const auto& isa = ProcessorHandler::get()->currentISA();
+ for (unsigned i = 0; i < isa->regCnt(); i++) {
+ addItem(isa->regName(i) + " (" + isa->regAlias(i) + ")",
+ QVariant::fromValue<GoToUserData>({GoToFunction::Custom, i}));
+ }
+}
+
+uint32_t GoToRegisterComboBox::addrForIndex(int i) {
+ const auto& data = qvariant_cast<GoToUserData>(itemData(i));
+ return ProcessorHandler::get()->getRegisterValue(data.arg);
+}
+
} // namespace Ripes

MODIFY
src/gotocombobox.h
src/gotocombobox.h
namespace Ripes {
-enum class GoToFunction { Select, Address, Section };
+enum class GoToFunction { Select, Address, Custom };
+struct GoToUserData {
+ GoToFunction func;
+ unsigned arg;
+};
class GoToComboBox : public QComboBox {
Q_OBJECT
public:
- explicit GoToComboBox(QWidget* parent = nullptr);
+ GoToComboBox(QWidget* parent = nullptr);
void showPopup() override;
signals:
@@ -21,7 +25,28 @@ public slots:
private:
void signalFilter(int index);
+ virtual void addTargets() = 0;
+ virtual uint32_t addrForIndex(int i) = 0;
+};
+
+class GoToSectionComboBox : public GoToComboBox {
+public:
+ GoToSectionComboBox(QWidget* parent = nullptr) : GoToComboBox(parent) {}
+
+private:
+ void addTargets();
+ uint32_t addrForIndex(int i);
};
+
+class GoToRegisterComboBox : public GoToComboBox {
+public:
+ GoToRegisterComboBox(QWidget* parent = nullptr) : GoToComboBox(parent) {}
+
+private:
+ void addTargets();
+ uint32_t addrForIndex(int i);
+};
+
} // namespace Ripes
-Q_DECLARE_METATYPE(Ripes::GoToFunction);
+Q_DECLARE_METATYPE(Ripes::GoToUserData);

MODIFY
src/memoryviewerwidget.cpp
src/memoryviewerwidget.cpp
@@ -47,7 +47,8 @@ void MemoryViewerWidget::updateModel() {
const auto rows = m_ui->memoryView->height() / m_ui->memoryView->rowHeight(0);
m_memoryModel->setRowsVisible(rows);
});
- connect(m_ui->gotoCombobox, &GoToComboBox::jumpToAddress, m_memoryModel, &MemoryModel::setCentralAddress);
+ connect(m_ui->goToSection, &GoToComboBox::jumpToAddress, m_memoryModel, &MemoryModel::setCentralAddress);
+ connect(m_ui->goToRegister, &GoToComboBox::jumpToAddress, m_memoryModel, &MemoryModel::setCentralAddress);
m_ui->memoryView->horizontalHeader()->setSectionResizeMode(MemoryModel::Address, QHeaderView::Stretch);

MODIFY
src/memoryviewerwidget.ui
src/memoryviewerwidget.ui
</property>
</spacer>
</item>
+ <item>
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Go to register:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="GoToRegisterComboBox" name="goToRegister"/>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Minimum</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>
+ <string>Go to section:</string>
</property>
</widget>
</item>
<item>
- <widget class="GoToComboBox" name="gotoCombobox"/>
+ <widget class="GoToSectionComboBox" name="goToSection"/>
</item>
</layout>
</item>
<header>memoryview.h</header>
</customwidget>
<customwidget>
- <class>GoToComboBox</class>
+ <class>GoToSectionComboBox</class>
+ <extends>QComboBox</extends>
+ <header>gotocombobox.h</header>
+ </customwidget>
+ <customwidget>
+ <class>GoToRegisterComboBox</class>
<extends>QComboBox</extends>
<header>gotocombobox.h</header>
</customwidget>

Add "Go to register" in MemoryViewerWidget