Removed DifferentialHexViewerItemRenderer - was only needed for painting the diff polygons which I've decided to remove.

This commit is contained in:
Nav
2023-07-14 22:12:07 +01:00
parent f56fb72894
commit 1723ce331e
5 changed files with 0 additions and 240 deletions

View File

@@ -115,7 +115,6 @@ target_sources(
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialHexViewerWidget.cpp
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialItemGraphicsView.cpp
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialItemGraphicsScene.cpp
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialHexViewerItemRenderer.cpp
# Memory region manager window
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/MemoryRegionManagerWindow.cpp

View File

@@ -1,176 +0,0 @@
#include "DifferentialHexViewerItemRenderer.hpp"
#include <QScrollBar>
#include <QPointF>
#include <array>
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressContainer.hpp"
namespace Widgets
{
DifferentialHexViewerItemRenderer::DifferentialHexViewerItemRenderer(
DifferentialHexViewerWidgetType differentialHexViewerWidgetType,
const HexViewerSharedState& hexViewerState,
const HexViewerItemIndex& itemIndex,
const QGraphicsView* view
)
: HexViewerItemRenderer(
hexViewerState,
itemIndex,
view
)
, differentialHexViewerWidgetType(differentialHexViewerWidgetType)
{}
void DifferentialHexViewerItemRenderer::setOther(const DifferentialHexViewerItemRenderer* other) {
this->other = other;
}
void DifferentialHexViewerItemRenderer::paint(
QPainter* painter,
const QStyleOptionGraphicsItem* option,
QWidget* widget
) {
if (this->other == nullptr) {
return;
}
const auto vScrollBarValue = this->view->verticalScrollBar()->value();
const auto otherVScrollBarValue = this->other->view->verticalScrollBar()->value();
const auto viewportHeight = this->view->viewport()->height();
const auto visibleItems = this->itemIndex.items(
vScrollBarValue,
vScrollBarValue + viewportHeight + (ByteItem::HEIGHT * 2)
);
painter->setRenderHints(QPainter::RenderHint::Antialiasing, false);
// Paint the ancestors of the first visible item
const auto& firstItem = *(visibleItems.begin());
auto* parentItem = firstItem->parent;
while (parentItem != nullptr) {
painter->setOpacity(1);
this->paintItem(parentItem, painter);
parentItem = parentItem->parent;
}
const ByteItem* previousLineFirstByteItem = nullptr;
const ByteItem* previousLineLastByteItem = nullptr;
auto changedByteOnCurrentLine = false;
const auto& byteItemYPosByAddress = this->itemIndex.byteItemYStartPositionsByAddress;
painter->setOpacity(1);
for (auto& item : visibleItems) {
const auto* byteItem = dynamic_cast<const ByteItem*>(item);
if (byteItem != nullptr) {
if (
previousLineLastByteItem == nullptr
|| previousLineLastByteItem->position().y() != byteItemYPosByAddress.at(byteItem->startAddress)
) {
if (changedByteOnCurrentLine) {
this->paintChangedLinePolygon(
previousLineFirstByteItem,
previousLineLastByteItem,
viewportHeight,
vScrollBarValue,
otherVScrollBarValue,
painter
);
changedByteOnCurrentLine = false;
}
previousLineFirstByteItem = byteItem;
}
changedByteOnCurrentLine = changedByteOnCurrentLine || byteItem->changed;
previousLineLastByteItem = byteItem;
}
}
if (changedByteOnCurrentLine) {
this->paintChangedLinePolygon(
previousLineFirstByteItem,
previousLineLastByteItem,
viewportHeight,
vScrollBarValue,
otherVScrollBarValue,
painter
);
}
for (auto& item : visibleItems) {
painter->setOpacity(1);
this->paintItem(item, painter);
}
}
void DifferentialHexViewerItemRenderer::paintChangedLinePolygon(
const ByteItem* firstByteItem,
const ByteItem* lastByteItem,
int viewportHeight,
int vScrollBarValue,
int otherVScrollBarValue,
QPainter* painter
) {
static constexpr auto backgroundColor = QColor(0x3A, 0x37, 0x39, 255);
painter->setBrush(backgroundColor);
painter->setPen(Qt::NoPen);
const auto firstByteItemYPos = this->itemIndex.byteItemYStartPositionsByAddress.at(firstByteItem->startAddress);
if (this->differentialHexViewerWidgetType == DifferentialHexViewerWidgetType::SECONDARY) {
painter->drawRect(
ByteAddressContainer::WIDTH,
firstByteItemYPos - (ByteItem::BOTTOM_MARGIN / 2) + 1,
this->size.width(),
ByteItem::HEIGHT + ByteItem::BOTTOM_MARGIN - 1
);
return;
}
static constexpr auto rightSpacing = 20;
const auto vScrollDifference = otherVScrollBarValue - vScrollBarValue;
const auto& otherByteItemYPosByAddress = this->other->itemIndex.byteItemYStartPositionsByAddress;
const auto otherFirstByteItemYPos = otherByteItemYPosByAddress.at(
firstByteItem->startAddress
) - vScrollDifference;
const auto otherLastByteItemYPos = otherByteItemYPosByAddress.at(
lastByteItem->startAddress
) - vScrollDifference;
const auto otherYStart = std::max(
vScrollBarValue,
std::min(
otherFirstByteItemYPos - (ByteItem::BOTTOM_MARGIN / 2) + 1,
vScrollBarValue + viewportHeight
)
);
const auto otherYEnd = std::max(
vScrollBarValue,
std::min(
otherLastByteItemYPos + ByteItem::HEIGHT + (ByteItem::BOTTOM_MARGIN / 2),
vScrollBarValue + viewportHeight
)
);
const auto points = std::array{
QPointF(ByteAddressContainer::WIDTH, firstByteItemYPos - (ByteItem::BOTTOM_MARGIN / 2) + 1),
QPointF(this->size.width() - rightSpacing, firstByteItemYPos - (ByteItem::BOTTOM_MARGIN / 2) + 1),
QPointF(this->size.width(), otherYStart),
QPointF(this->size.width(), otherYEnd),
QPointF(this->size.width() - rightSpacing, firstByteItemYPos + ByteItem::HEIGHT + (ByteItem::BOTTOM_MARGIN / 2)),
QPointF(ByteAddressContainer::WIDTH, firstByteItemYPos + ByteItem::HEIGHT + (ByteItem::BOTTOM_MARGIN / 2)),
};
painter->drawPolygon(points.data(), points.size());
}
}

View File

@@ -1,35 +0,0 @@
#pragma once
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerItemRenderer.hpp"
#include "DifferentialHexViewerWidgetType.hpp"
namespace Widgets
{
class DifferentialHexViewerItemRenderer: public HexViewerItemRenderer
{
public:
DifferentialHexViewerItemRenderer(
DifferentialHexViewerWidgetType differentialHexViewerWidgetType,
const HexViewerSharedState& hexViewerState,
const HexViewerItemIndex& itemIndex,
const QGraphicsView* view
);
void setOther(const DifferentialHexViewerItemRenderer* other);
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
protected:
DifferentialHexViewerWidgetType differentialHexViewerWidgetType;
const DifferentialHexViewerItemRenderer* other = nullptr;
inline void paintChangedLinePolygon(
const ByteItem* firstByteItem,
const ByteItem* lastByteItem,
int viewportHeight,
int vScrollBarValue,
int otherVScrollBarValue,
QPainter* painter
) __attribute__((__always_inline__));
};
}

View File

@@ -2,8 +2,6 @@
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsView.hpp"
#include "DifferentialHexViewerItemRenderer.hpp"
namespace Widgets
{
DifferentialItemGraphicsScene::DifferentialItemGraphicsScene(
@@ -33,12 +31,6 @@ namespace Widgets
void DifferentialItemGraphicsScene::setOther(DifferentialItemGraphicsScene* other) {
this->other = other;
assert(this->other->differentialHexViewerItemRenderer != nullptr);
if (this->differentialHexViewerItemRenderer != nullptr) {
this->differentialHexViewerItemRenderer->setOther(this->other->differentialHexViewerItemRenderer);
}
QObject::connect(
this->other,
&DifferentialItemGraphicsScene::hoveredAddress,
@@ -66,23 +58,6 @@ namespace Widgets
this->update();
}
void DifferentialItemGraphicsScene::initRenderer() {
this->differentialHexViewerItemRenderer = new DifferentialHexViewerItemRenderer(
this->differentialHexViewerWidgetType,
this->state,
*(this->itemIndex.get()),
this->views().first()
);
if (this->other != nullptr && this->other->differentialHexViewerItemRenderer != nullptr) {
this->differentialHexViewerItemRenderer->setOther(this->other->differentialHexViewerItemRenderer);
}
this->renderer = this->differentialHexViewerItemRenderer;
this->renderer->setPos(0, 0);
this->addItem(this->renderer);
}
QMargins DifferentialItemGraphicsScene::margins() {
auto margins = ItemGraphicsScene::margins();
margins.setRight(DifferentialItemGraphicsScene::CENTER_WIDTH / 2);

View File

@@ -4,7 +4,6 @@
#include "DifferentialHexViewerWidgetType.hpp"
#include "DifferentialHexViewerSharedState.hpp"
#include "DifferentialHexViewerItemRenderer.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/SnapshotDiffSettings.hpp"
@@ -37,10 +36,8 @@ namespace Widgets
DifferentialHexViewerWidgetType differentialHexViewerWidgetType;
DifferentialHexViewerSharedState& diffHexViewerState;
const SnapshotDiffSettings& snapshotDiffSettings;
DifferentialHexViewerItemRenderer* differentialHexViewerItemRenderer = nullptr;
DifferentialItemGraphicsScene* other = nullptr;
void initRenderer() override;
QMargins margins() override;
void onOtherHoveredAddress(const std::optional<Targets::TargetMemoryAddress>& address);