From 1723ce331ec42bccccd51c089933cf333b140b4a Mon Sep 17 00:00:00 2001 From: Nav Date: Fri, 14 Jul 2023 22:12:07 +0100 Subject: [PATCH] Removed `DifferentialHexViewerItemRenderer` - was only needed for painting the diff polygons which I've decided to remove. --- src/Insight/CMakeLists.txt | 1 - .../DifferentialHexViewerItemRenderer.cpp | 176 ------------------ .../DifferentialHexViewerItemRenderer.hpp | 35 ---- .../DifferentialItemGraphicsScene.cpp | 25 --- .../DifferentialItemGraphicsScene.hpp | 3 - 5 files changed, 240 deletions(-) delete mode 100644 src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialHexViewerItemRenderer.cpp delete mode 100644 src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialHexViewerItemRenderer.hpp diff --git a/src/Insight/CMakeLists.txt b/src/Insight/CMakeLists.txt index eb33c632..ce56a03f 100755 --- a/src/Insight/CMakeLists.txt +++ b/src/Insight/CMakeLists.txt @@ -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 diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialHexViewerItemRenderer.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialHexViewerItemRenderer.cpp deleted file mode 100644 index c2d8f1be..00000000 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialHexViewerItemRenderer.cpp +++ /dev/null @@ -1,176 +0,0 @@ -#include "DifferentialHexViewerItemRenderer.hpp" - -#include -#include -#include - -#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(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()); - } -} diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialHexViewerItemRenderer.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialHexViewerItemRenderer.hpp deleted file mode 100644 index 06e22345..00000000 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialHexViewerItemRenderer.hpp +++ /dev/null @@ -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__)); - }; -} diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialItemGraphicsScene.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialItemGraphicsScene.cpp index 823f95f5..1a628494 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialItemGraphicsScene.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialItemGraphicsScene.cpp @@ -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); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialItemGraphicsScene.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialItemGraphicsScene.hpp index ad922485..b0e1c85d 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialItemGraphicsScene.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialItemGraphicsScene.hpp @@ -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& address);