Refine combobox selections for data display types
MODIFY
src/defines.h
src/defines.h
#include <vector>
enum displayTypeN { Hex = 1, Binary = 2, Decimal = 3, Unsigned = 4, ASCII = 5 };
+Q_DECLARE_METATYPE(displayTypeN)
namespace {
static QMap<QString, displayTypeN> initDisplayTypes() {

MODIFY
src/memorydisplaydelegate.cpp
src/memorydisplaydelegate.cpp
@@ -33,10 +33,7 @@ QString MemoryDisplayDelegate::displayText(const QVariant &value,
return retVal;
}
-void MemoryDisplayDelegate::setDisplayType(const QString &type) {
+void MemoryDisplayDelegate::setDisplayType(displayTypeN type) {
// Given a display type "type", sets validators for the input.
- auto iter = displayTypes.find(type);
- if (iter != displayTypes.end()) {
- m_displayType = iter.value();
- }
+ m_displayType = type;
}

MODIFY
src/memorydisplaydelegate.h
src/memorydisplaydelegate.h
@@ -13,7 +13,7 @@ public:
const QLocale &locale) const override;
public slots:
- void setDisplayType(const QString &type);
+ void setDisplayType(displayTypeN type);
private:
displayTypeN m_displayType = displayTypeN::Hex;

MODIFY
src/memorytab.cpp
src/memorytab.cpp
@@ -12,8 +12,8 @@ MemoryTab::MemoryTab(QWidget *parent)
// Add display types to display comboboxes
for (const auto &type : displayTypes.keys()) {
- m_ui->registerdisplaytype->insertItem(0, type);
- m_ui->memorydisplaytype->insertItem(0, type);
+ m_ui->registerdisplaytype->insertItem(0, type, displayTypes[type]);
+ m_ui->memorydisplaytype->insertItem(0, type, displayTypes[type]);
}
// Add goto values to goto combobox
@@ -106,10 +106,14 @@ void MemoryTab::initializeRegisterView() {
reg->setAlias(ABInames[i]);
reg->setNumber(i);
reg->setToolTip(descriptions[i]);
- reg->setDisplayType(m_ui->registerdisplaytype->currentText());
+ reg->setDisplayType(
+ qvariant_cast<displayTypeN>(m_ui->registerdisplaytype->currentData()));
connect(m_ui->registerdisplaytype,
- QOverload<const QString &>::of(&QComboBox::currentTextChanged), reg,
- &RegisterWidget::setDisplayType);
+ QOverload<const QString &>::of(&QComboBox::currentTextChanged),
+ [=] {
+ reg->setDisplayType(qvariant_cast<displayTypeN>(
+ m_ui->registerdisplaytype->currentData()));
+ });
m_ui->registerLayout->addWidget(reg);
}
m_regWidgetPtrs[0]->setEnabled(false);
@@ -127,15 +131,23 @@ void MemoryTab::initializeMemoryView() {
m_ui->memoryView->setModel(m_model);
m_ui->memoryView->horizontalHeader()->setStretchLastSection(true);
m_ui->memoryView->verticalHeader()->hide();
+
// Only set delegate on byte columns
m_ui->memoryView->setItemDelegateForColumn(1, m_delegate);
m_ui->memoryView->setItemDelegateForColumn(2, m_delegate);
m_ui->memoryView->setItemDelegateForColumn(3, m_delegate);
m_ui->memoryView->setItemDelegateForColumn(4, m_delegate);
+
+ // Memory display type
connect(m_ui->memorydisplaytype, &QComboBox::currentTextChanged, m_delegate,
- &MemoryDisplayDelegate::setDisplayType);
- connect(m_ui->memorydisplaytype, &QComboBox::currentTextChanged,
- [=] { m_ui->memoryView->viewport()->repaint(); });
+ [=] {
+ m_delegate->setDisplayType(qvariant_cast<displayTypeN>(
+ m_ui->memorydisplaytype->currentData()));
+ m_ui->memoryView->viewport()->repaint();
+ });
+ m_delegate->setDisplayType(
+ qvariant_cast<displayTypeN>(m_ui->memorydisplaytype->currentData()));
+
connect(m_ui->memoryUp, &QPushButton::clicked, [=] {
m_model->offsetCentralAddress(4);
m_ui->memoryView->viewport()->repaint();

MODIFY
src/registerwidget.cpp
src/registerwidget.cpp
@@ -65,14 +65,10 @@ void RegisterWidget::setNumber(int number) {
m_ui->number->setText(QString("x(%1)").arg(number));
}
-void RegisterWidget::setDisplayType(const QString &type) {
+void RegisterWidget::setDisplayType(displayTypeN type) {
// Given a display type "type", sets validators for the input.
- auto iter = displayTypes.find(type);
- if (iter == displayTypes.end()) {
- return;
- }
- m_displayType = *iter;
+ m_displayType = type;
if (m_displayType == displayTypeN::Hex) {
m_displayBase = 16;
m_ui->value->setInputMask("hhhhhhhh");

MODIFY
src/registerwidget.h
src/registerwidget.h
@@ -32,7 +32,7 @@ public:
public slots:
void setText();
- void setDisplayType(const QString &type);
+ void setDisplayType(displayTypeN type);
private slots:
void validateInput();
@@ -40,7 +40,7 @@ private slots:
private:
Ui::RegisterWidget *m_ui;
QIntValidator m_validator;
- int m_displayType;
+ displayTypeN m_displayType;
int m_displayBase = 10;
uint32_t *m_regPtr;

Refine combobox selections for data display types