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->focusedMemoryRegions,
this->excludedMemoryRegions, this->excludedMemoryRegions,
this->settings, this->settings,
this->hoveredAddressLabel,
this->container this->container
); );
@@ -181,6 +180,14 @@ namespace Bloom::Widgets
this, this,
[this] { [this] {
this->byteItemGraphicsScene = this->byteItemGraphicsView->getScene(); this->byteItemGraphicsScene = this->byteItemGraphicsView->getScene();
QObject::connect(
this->byteItemGraphicsScene,
&ItemGraphicsScene::hoveredAddress,
this,
&HexViewerWidget::onHoveredAddress
);
this->loadingHexViewerLabel->hide(); this->loadingHexViewerLabel->hide();
this->byteItemGraphicsView->show(); this->byteItemGraphicsView->show();
@@ -288,4 +295,26 @@ namespace Bloom::Widgets
this->byteItemGraphicsScene->selectByteItems({}); 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 <QResizeEvent>
#include <QShowEvent> #include <QShowEvent>
#include <vector> #include <vector>
#include <optional>
#include "src/Targets/TargetMemory.hpp" #include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetState.hpp" #include "src/Targets/TargetState.hpp"
@@ -82,5 +83,6 @@ namespace Bloom::Widgets
void setAnnotationsEnabled(bool enabled); void setAnnotationsEnabled(bool enabled);
void setDisplayAsciiEnabled(bool enabled); void setDisplayAsciiEnabled(bool enabled);
void onGoToAddressInputChanged(); 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<FocusedMemoryRegion>& focusedMemoryRegions,
std::vector<ExcludedMemoryRegion>& excludedMemoryRegions, std::vector<ExcludedMemoryRegion>& excludedMemoryRegions,
HexViewerWidgetSettings& settings, HexViewerWidgetSettings& settings,
Label* hoveredAddressLabel,
QGraphicsView* parent QGraphicsView* parent
) )
: state( : state(
@@ -31,7 +30,6 @@ namespace Bloom::Widgets
) )
, focusedMemoryRegions(focusedMemoryRegions) , focusedMemoryRegions(focusedMemoryRegions)
, excludedMemoryRegions(excludedMemoryRegions) , excludedMemoryRegions(excludedMemoryRegions)
, hoveredAddressLabel(hoveredAddressLabel)
, parent(parent) , parent(parent)
, QGraphicsScene(parent) , QGraphicsScene(parent)
{ {
@@ -602,21 +600,6 @@ namespace Bloom::Widgets
this->state.hoveredByteItem = &byteItem; 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) { if (this->state.settings.highlightHoveredRowAndCol) {
const auto byteItemScenePos = byteItem.position(); const auto byteItemScenePos = byteItem.position();
this->hoverRectX->setPos(0, byteItemScenePos.y()); this->hoverRectX->setPos(0, byteItemScenePos.y());
@@ -630,6 +613,7 @@ namespace Bloom::Widgets
} }
this->update(); this->update();
emit this->hoveredAddress(byteItem.startAddress);
} }
void ItemGraphicsScene::onByteItemLeave() { void ItemGraphicsScene::onByteItemLeave() {
@@ -637,11 +621,11 @@ namespace Bloom::Widgets
this->state.hoveredByteItem = nullptr; this->state.hoveredByteItem = nullptr;
} }
this->hoveredAddressLabel->setText("Relative Address / Absolute Address:");
this->hoverRectX->setVisible(false); this->hoverRectX->setVisible(false);
this->hoverRectY->setVisible(false); this->hoverRectY->setVisible(false);
this->update(); this->update();
emit this->hoveredAddress(std::nullopt);
} }
void ItemGraphicsScene::clearSelectionRectItem() { void ItemGraphicsScene::clearSelectionRectItem() {

View File

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

View File

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

View File

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

View File

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