Identify differences in snapshot diff window

This commit is contained in:
Nav
2023-05-07 00:55:47 +01:00
parent b80f6aad6c
commit db158a0eda
11 changed files with 131 additions and 2 deletions

View File

@@ -38,7 +38,7 @@ namespace Bloom::Widgets
);
virtual void init();
void updateValues();
virtual void updateValues();
void refreshRegions();
void setStackPointer(Targets::TargetStackPointer stackPointer);
void addExternalContextMenuAction(ContextMenuAction* action);

View File

@@ -1,9 +1,13 @@
#pragma once
#include <unordered_set>
namespace Bloom::Widgets
{
struct DifferentialHexViewerSharedState
{
std::unordered_set<Targets::TargetMemoryAddress> differences;
bool syncingSettings = false;
bool syncingScroll = false;
bool syncingHover = false;

View File

@@ -85,6 +85,13 @@ namespace Bloom::Widgets
this->byteItemGraphicsView->initScene();
}
void DifferentialHexViewerWidget::updateValues() {
if (this->differentialScene != nullptr) {
this->differentialScene->updateByteItemChangedStates();
this->differentialScene->refreshValues();
}
}
void DifferentialHexViewerWidget::setOther(DifferentialHexViewerWidget* other) {
assert(other->byteItemGraphicsView != nullptr);
assert(other->byteItemGraphicsScene != nullptr);

View File

@@ -28,6 +28,7 @@ namespace Bloom::Widgets
);
void init() override;
void updateValues() override;
void setOther(DifferentialHexViewerWidget* other);

View File

@@ -48,6 +48,14 @@ namespace Bloom::Widgets
return this->itemIndex->closestByteItem(this->getScrollbarValue());
}
void DifferentialItemGraphicsScene::updateByteItemChangedStates() {
for (auto& [address, byteItem] : this->topLevelGroup->byteItemsByAddress) {
byteItem.changed = !byteItem.excluded && this->diffHexViewerState.differences.contains(address);
}
this->update();
}
void DifferentialItemGraphicsScene::onOtherHoveredAddress(
const std::optional<Targets::TargetMemoryAddress>& address
) {

View File

@@ -26,6 +26,7 @@ namespace Bloom::Widgets
void setOther(DifferentialItemGraphicsScene* other);
ByteItem* byteItemAtViewportTop();
void updateByteItemChangedStates();
protected:
DifferentialHexViewerSharedState& diffHexViewerState;

View File

@@ -44,6 +44,7 @@ namespace Bloom::Widgets
&ItemGraphicsScene::ready,
this,
[this] {
this->differentialScene->updateByteItemChangedStates();
this->scene->setEnabled(this->isEnabled());
emit this->sceneReady();
}
@@ -65,6 +66,8 @@ namespace Bloom::Widgets
this->verticalScrollBar()->setValue(
std::max(static_cast<int>(byteItemPosition.y() - otherByteItemYOffset), 0)
);
this->update();
}
void DifferentialItemGraphicsView::scrollContentsBy(int dx, int dy) {

View File

@@ -2,6 +2,7 @@
#include <QFile>
#include <QVBoxLayout>
#include <QLocale>
#include <algorithm>
#include "src/Insight/InsightWorker/Tasks/WriteTargetMemory.hpp"
@@ -115,8 +116,11 @@ namespace Bloom::Widgets
this->hexViewerWidgetB->setStackPointer(this->stackPointerB);
}
this->refreshDifferences();
this->hexViewerWidgetB->refreshRegions();
this->hexViewerWidgetB->updateValues();
this->hexViewerWidgetA->updateValues();
}
void SnapshotDiff::showEvent(QShowEvent* event) {
@@ -219,8 +223,13 @@ namespace Bloom::Widgets
this->bottomBar = this->container->findChild<QWidget*>("bottom-bar");
this->bottomBarLayout = this->bottomBar->findChild<QHBoxLayout*>();
this->memoryCapacityLabel = this->bottomBar->findChild<Label*>("memory-capacity-label");
this->diffCountLabel = this->bottomBar->findChild<Label*>("diff-count-label");
this->memoryCapacityLabel->setText(QLocale(QLocale::English).toString(this->hexViewerDataA->size()) + " bytes");
this->taskProgressIndicator = new TaskProgressIndicator(this);
this->bottomBarLayout->insertWidget(0, this->taskProgressIndicator);
this->bottomBarLayout->insertWidget(5, this->taskProgressIndicator);
this->setSyncHexViewerSettingsEnabled(this->settings.syncHexViewerSettings);
this->setSyncHexViewerScrollEnabled(this->settings.syncHexViewerScroll);
@@ -266,6 +275,8 @@ namespace Bloom::Widgets
QObject::connect(this->hexViewerWidgetA, &HexViewerWidget::ready, this, &SnapshotDiff::onHexViewerAReady);
QObject::connect(this->hexViewerWidgetB, &HexViewerWidget::ready, this, &SnapshotDiff::onHexViewerBReady);
this->refreshDifferences();
this->hexViewerWidgetA->init();
this->hexViewerWidgetB->init();
@@ -292,6 +303,33 @@ namespace Bloom::Widgets
}
}
void SnapshotDiff::refreshDifferences() {
assert(this->hexViewerDataA.has_value());
assert(this->hexViewerDataB.has_value());
this->differentialHexViewerSharedState.differences.clear();
const auto& dataA = *(this->hexViewerDataA);
const auto& dataB = *(this->hexViewerDataB);
const auto& memoryStartAddress = this->memoryDescriptor.addressRange.startAddress;
for (Targets::TargetMemoryBuffer::size_type i = 0; i < dataA.size(); ++i) {
if (dataA[i] != dataB[i]) {
this->differentialHexViewerSharedState.differences.insert(
memoryStartAddress + static_cast<Targets::TargetMemoryAddress>(i)
);
}
}
const auto count = this->differentialHexViewerSharedState.differences.size();
this->diffCountLabel->setText(
count == 0
? "Contents are identical"
: QLocale(QLocale::English).toString(count) + (count == 1 ? " difference" : " differences")
);
}
void SnapshotDiff::setSyncHexViewerSettingsEnabled(bool enabled) {
this->settings.syncHexViewerSettings = enabled;
this->syncHexViewerSettingsButton->setChecked(this->settings.syncHexViewerSettings);
@@ -408,6 +446,8 @@ namespace Bloom::Widgets
);
}
this->refreshDifferences();
this->hexViewerWidgetA->updateValues();
this->hexViewerWidgetB->updateValues();
};

View File

@@ -97,6 +97,8 @@ namespace Bloom::Widgets
QWidget* bottomBar = nullptr;
QHBoxLayout* bottomBarLayout = nullptr;
Label* memoryCapacityLabel = nullptr;
Label* diffCountLabel = nullptr;
TaskProgressIndicator* taskProgressIndicator = nullptr;
@@ -105,6 +107,8 @@ namespace Bloom::Widgets
void onHexViewerAReady();
void onHexViewerBReady();
void refreshDifferences();
void setSyncHexViewerSettingsEnabled(bool enabled);
void setSyncHexViewerScrollEnabled(bool enabled);
void setSyncHexViewerHoverEnabled(bool enabled);

View File

@@ -70,3 +70,17 @@
#snapshot-diff #bottom-bar {
border-top: 1px solid #41423f;
}
#snapshot-diff #bottom-bar #separator {
background-color: transparent;
border-right: 1px solid #41423f;
padding: 0;
min-width: 1px;
max-width: 1px;
}
#snapshot-diff #memory-capacity-label,
#snapshot-diff #diff-count-label {
padding: 1px 5px;
color: #8a8a8d;
}

View File

@@ -301,6 +301,53 @@
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="Label" name="memory-capacity-label">
<property name="toolTip">
<string>Memory capacity</string>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"/>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="separator"/>
</item>
<item>
<widget class="Label" name="diff-count-label">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"/>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="separator"/>
</item>
<item>
<spacer name="horizontal-spacer">
<property name="sizeHint">
<size>
<width>2</width>
</size>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
</spacer>
</item>
<item>
<spacer name="horizontal-spacer">
<property name="sizeHint">
<size>
<width>10</width>
</size>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
</spacer>
</item>
</layout>
</widget>
</item>