diff --git a/src/SeerArrayVisualizerWidget.cpp b/src/SeerArrayVisualizerWidget.cpp index f3022c8..58380ad 100644 --- a/src/SeerArrayVisualizerWidget.cpp +++ b/src/SeerArrayVisualizerWidget.cpp @@ -154,23 +154,35 @@ QString SeerArrayVisualizerWidget::aVariableName () const { void SeerArrayVisualizerWidget::setAVariableAddress (const QString& address) { - if (address.startsWith("0x")) { + unsigned long offset = 0; + bool ok = false; - bool ok = false; + if (address == "") { - address.toULong(&ok, 16); - - if (ok == true) { - aVariableAddressLineEdit->setText(address); - }else{ - aVariableAddressLineEdit->setText("not an address"); - } + aVariableAddressLineEdit->setText(""); + offset = 0; }else{ - if (aVariableAddressLineEdit->text() != "") { + + // Test for base10 + if (ok == false) { + offset = address.toULong(&ok, 10); + if (ok) { + aVariableAddressLineEdit->setText(QString("0x%1").arg(offset, 0, 16, QLatin1Char( '0' ))); + } + } + + // Test for base16 + if (ok == false) { + offset = address.toULong(&ok, 16); + if (ok) { + aVariableAddressLineEdit->setText(QString("0x%1").arg(offset, 0, 16, QLatin1Char( '0' ))); + } + } + + if (ok == false) { aVariableAddressLineEdit->setText("not an address"); - }else{ - aVariableAddressLineEdit->setText(""); + offset = 0; } } @@ -234,23 +246,35 @@ QString SeerArrayVisualizerWidget::bVariableName () const { void SeerArrayVisualizerWidget::setBVariableAddress (const QString& address) { - if (address.startsWith("0x")) { + unsigned long offset = 0; + bool ok = false; - bool ok = false; + if (address == "") { - address.toULong(&ok, 16); - - if (ok == true) { - bVariableAddressLineEdit->setText(address); - }else{ - bVariableAddressLineEdit->setText("not an address"); - } + bVariableAddressLineEdit->setText(""); + offset = 0; }else{ - if (bVariableAddressLineEdit->text() != "") { + + // Test for base10 + if (ok == false) { + offset = address.toULong(&ok, 10); + if (ok) { + bVariableAddressLineEdit->setText(QString("0x%1").arg(offset, 0, 16, QLatin1Char( '0' ))); + } + } + + // Test for base16 + if (ok == false) { + offset = address.toULong(&ok, 16); + if (ok) { + bVariableAddressLineEdit->setText(QString("0x%1").arg(offset, 0, 16, QLatin1Char( '0' ))); + } + } + + if (ok == false) { bVariableAddressLineEdit->setText("not an address"); - }else{ - bVariableAddressLineEdit->setText(""); + offset = 0; } } diff --git a/src/SeerMemoryVisualizerWidget.cpp b/src/SeerMemoryVisualizerWidget.cpp index e755b54..6478689 100644 --- a/src/SeerMemoryVisualizerWidget.cpp +++ b/src/SeerMemoryVisualizerWidget.cpp @@ -91,30 +91,39 @@ QString SeerMemoryVisualizerWidget::variableName () const { void SeerMemoryVisualizerWidget::setVariableAddress (const QString& address) { - unsigned long offset = 0; - bool refresh = false; + unsigned long offset = 0; + bool ok = false; + bool refresh = false; - if (address.startsWith("0x")) { + if (address == "") { - bool ok = false; - - offset = address.toULong(&ok, 16); - - if (ok == true) { - variableAddressLineEdit->setText(address); - refresh = true; - }else{ - variableAddressLineEdit->setText("not an address"); - offset = 0; - } - - }else if (address != "") { - variableAddressLineEdit->setText("not an address"); + variableAddressLineEdit->setText(""); offset = 0; }else{ - variableAddressLineEdit->setText(""); - offset = 0; + + // Test for base10 + if (ok == false) { + offset = address.toULong(&ok, 10); + if (ok) { + variableAddressLineEdit->setText(QString("0x%1").arg(offset, 0, 16, QLatin1Char( '0' ))); + refresh = true; + } + } + + // Test for base16 + if (ok == false) { + offset = address.toULong(&ok, 16); + if (ok) { + variableAddressLineEdit->setText(QString("0x%1").arg(offset, 0, 16, QLatin1Char( '0' ))); + refresh = true; + } + } + + if (ok == false) { + variableAddressLineEdit->setText("not an address"); + offset = 0; + } } memoryHexEditor->setAddressOffset(offset);