Used a signal for updating hovered address label in hex viewer

This commit is contained in:
Nav
2023-03-16 18:42:39 +00:00
parent f3cd27ee82
commit c79dfa1967
7 changed files with 38 additions and 27 deletions

View File

@@ -84,7 +84,6 @@ namespace Bloom::Widgets
this->focusedMemoryRegions,
this->excludedMemoryRegions,
this->settings,
this->hoveredAddressLabel,
this->container
);
@@ -181,6 +180,14 @@ namespace Bloom::Widgets
this,
[this] {
this->byteItemGraphicsScene = this->byteItemGraphicsView->getScene();
QObject::connect(
this->byteItemGraphicsScene,
&ItemGraphicsScene::hoveredAddress,
this,
&HexViewerWidget::onHoveredAddress
);
this->loadingHexViewerLabel->hide();
this->byteItemGraphicsView->show();
@@ -288,4 +295,26 @@ namespace Bloom::Widgets
this->byteItemGraphicsScene->selectByteItems({});
}
void HexViewerWidget::onHoveredAddress(const std::optional<Targets::TargetMemoryAddress>& address) {
if (!address.has_value()) {
this->hoveredAddressLabel->setText("Relative address / Absolute address:");
return;
}
const auto addressHex = "0x" + QString::number(
*address,
16
).rightJustified(8, '0').toUpper();
const auto relativeAddress = *address - this->targetMemoryDescriptor.addressRange.startAddress;
const auto relativeAddressHex = "0x" + QString::number(
relativeAddress,
16
).rightJustified(8, '0').toUpper();
this->hoveredAddressLabel->setText(
"Relative address / Absolute address: " + relativeAddressHex + " / " + addressHex
);
}
}

View File

@@ -4,6 +4,7 @@
#include <QResizeEvent>
#include <QShowEvent>
#include <vector>
#include <optional>
#include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetState.hpp"
@@ -82,5 +83,6 @@ namespace Bloom::Widgets
void setAnnotationsEnabled(bool enabled);
void setDisplayAsciiEnabled(bool enabled);
void onGoToAddressInputChanged();
void onHoveredAddress(const std::optional<Targets::TargetMemoryAddress>& address);
};
}

View File

@@ -19,7 +19,6 @@ namespace Bloom::Widgets
std::vector<FocusedMemoryRegion>& focusedMemoryRegions,
std::vector<ExcludedMemoryRegion>& excludedMemoryRegions,
HexViewerWidgetSettings& settings,
Label* hoveredAddressLabel,
QGraphicsView* parent
)
: state(
@@ -31,7 +30,6 @@ namespace Bloom::Widgets
)
, focusedMemoryRegions(focusedMemoryRegions)
, excludedMemoryRegions(excludedMemoryRegions)
, hoveredAddressLabel(hoveredAddressLabel)
, parent(parent)
, QGraphicsScene(parent)
{
@@ -602,21 +600,6 @@ namespace Bloom::Widgets
this->state.hoveredByteItem = &byteItem;
const auto addressHex = "0x" + QString::number(
byteItem.startAddress,
16
).rightJustified(8, '0').toUpper();
const auto relativeAddress = byteItem.startAddress - this->state.memoryDescriptor.addressRange.startAddress;
const auto relativeAddressHex = "0x" + QString::number(
relativeAddress,
16
).rightJustified(8, '0').toUpper();
this->hoveredAddressLabel->setText(
"Relative Address / Absolute Address: " + relativeAddressHex + " / " + addressHex
);
if (this->state.settings.highlightHoveredRowAndCol) {
const auto byteItemScenePos = byteItem.position();
this->hoverRectX->setPos(0, byteItemScenePos.y());
@@ -630,6 +613,7 @@ namespace Bloom::Widgets
}
this->update();
emit this->hoveredAddress(byteItem.startAddress);
}
void ItemGraphicsScene::onByteItemLeave() {
@@ -637,11 +621,11 @@ namespace Bloom::Widgets
this->state.hoveredByteItem = nullptr;
}
this->hoveredAddressLabel->setText("Relative Address / Absolute Address:");
this->hoverRectX->setVisible(false);
this->hoverRectY->setVisible(false);
this->update();
emit this->hoveredAddress(std::nullopt);
}
void ItemGraphicsScene::clearSelectionRectItem() {

View File

@@ -48,7 +48,6 @@ namespace Bloom::Widgets
std::vector<FocusedMemoryRegion>& focusedMemoryRegions,
std::vector<ExcludedMemoryRegion>& excludedMemoryRegions,
HexViewerWidgetSettings& settings,
Label* hoveredAddressLabel,
QGraphicsView* parent
);
@@ -64,6 +63,7 @@ namespace Bloom::Widgets
signals:
void ready();
void hoveredAddress(const std::optional<Targets::TargetMemoryAddress>& address);
protected:
bool event(QEvent* event) override;
@@ -96,7 +96,6 @@ namespace Bloom::Widgets
Targets::TargetState targetState = Targets::TargetState::UNKNOWN;
QGraphicsView* parent = nullptr;
Label* hoveredAddressLabel = nullptr;
ByteAddressContainer* byteAddressContainer = nullptr;

View File

@@ -12,7 +12,6 @@ namespace Bloom::Widgets
std::vector<FocusedMemoryRegion>& focusedMemoryRegions,
std::vector<ExcludedMemoryRegion>& excludedMemoryRegions,
HexViewerWidgetSettings& settings,
Label* hoveredAddressLabel,
QWidget* parent
)
: QGraphicsView(parent)
@@ -34,7 +33,6 @@ namespace Bloom::Widgets
focusedMemoryRegions,
excludedMemoryRegions,
settings,
hoveredAddressLabel,
this
);

View File

@@ -23,7 +23,6 @@ namespace Bloom::Widgets
std::vector<FocusedMemoryRegion>& focusedMemoryRegions,
std::vector<ExcludedMemoryRegion>& excludedMemoryRegions,
HexViewerWidgetSettings& settings,
Label* hoveredAddressLabel,
QWidget* parent
);

View File

@@ -207,7 +207,7 @@
</property>
<layout class="QHBoxLayout">
<property name="spacing">
<number>3</number>
<number>0</number>
</property>
<property name="margin">
<number>0</number>
@@ -215,7 +215,7 @@
<item>
<widget class="Label" name="byte-address-label">
<property name="text">
<string>Relative Address / Absolute Address:</string>
<string>Relative address / Absolute address:</string>
</property>
</widget>
</item>