diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressContainer.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressContainer.cpp index e039a90d..8d559b7e 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressContainer.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressContainer.cpp @@ -13,34 +13,30 @@ namespace Bloom::Widgets const auto rowIndex = static_cast(mappingPair.first); const auto& byteItems = mappingPair.second; - if (byteItems.empty()) { - continue; - } - ByteAddressItem* addressLabel = nullptr; if (static_cast(rowIndex) > layoutItemMaxIndex) { - addressLabel = new ByteAddressItem(this); - this->addressItemsByRowIndex.insert(std::pair(rowIndex, addressLabel)); + addressLabel = new ByteAddressItem(rowIndex, byteItemsByRowIndex, this); + this->addressItemsByRowIndex.emplace(rowIndex, addressLabel); } else { addressLabel = this->addressItemsByRowIndex.at(rowIndex); + addressLabel->update(); + addressLabel->setVisible(true); } const auto& firstByteItem = byteItems.front(); - addressLabel->setAddressHex(firstByteItem->relativeAddressHex); addressLabel->setPos( leftMargin, firstByteItem->pos().y() + 3 // +3 to have the address item and byte item align vertically, from center ); } - // Delete any address items we no longer need + // Hide any address items we no longer need const auto addressItemCount = this->addressItemsByRowIndex.size(); if (newRowCount > 0 && newRowCount < addressItemCount) { for (auto i = (addressItemCount - 1); i >= newRowCount; i--) { - delete this->addressItemsByRowIndex.at(i); - this->addressItemsByRowIndex.erase(i); + this->addressItemsByRowIndex.at(i)->setVisible(false); } } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressItem.cpp index 98ec2495..1c7eed8e 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressItem.cpp @@ -4,12 +4,19 @@ namespace Bloom::Widgets { - void ByteAddressItem::setAddressHex(const QString& addressHex) { + ByteAddressItem::ByteAddressItem( + std::size_t rowIndex, + const std::map>& byteItemsByRowIndex, + QGraphicsItem* parent + ) + : rowIndex(rowIndex) + , byteItemsByRowIndex(byteItemsByRowIndex) + , QGraphicsItem(parent) + { this->setCacheMode( QGraphicsItem::CacheMode::ItemCoordinateCache, QSize(ByteAddressItem::WIDTH, ByteAddressItem::HEIGHT) ); - this->addressHex = addressHex; } void ByteAddressItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { @@ -26,6 +33,10 @@ namespace Bloom::Widgets painter->setFont(font); painter->setPen(fontColor); - painter->drawText(widgetRect, Qt::AlignLeft, this->addressHex); + painter->drawText( + widgetRect, + Qt::AlignLeft, + this->byteItemsByRowIndex.at(this->rowIndex)[0]->relativeAddressHex + ); } } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressItem.hpp index aff7d55d..35202c7c 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressItem.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressItem.hpp @@ -1,9 +1,8 @@ #pragma once #include -#include #include -#include +#include #include "ByteItem.hpp" @@ -15,9 +14,13 @@ namespace Bloom::Widgets static constexpr int WIDTH = 75; static constexpr int HEIGHT = ByteItem::HEIGHT; - explicit ByteAddressItem(QGraphicsItem* parent): QGraphicsItem(parent) {}; + std::size_t rowIndex = 0; - void setAddressHex(const QString& address); + explicit ByteAddressItem( + std::size_t rowIndex, + const std::map>& byteItemsByRowIndex, + QGraphicsItem* parent + ); [[nodiscard]] QRectF boundingRect() const override { return { @@ -31,6 +34,6 @@ namespace Bloom::Widgets void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override; private: - QString addressHex; + const std::map>& byteItemsByRowIndex; }; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItem.cpp index b1f5f49f..dd7572cf 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItem.cpp @@ -22,9 +22,11 @@ namespace Bloom::Widgets , highlightedByteItems(highlightedByteItems) , settings(settings) { + static const auto cacheResolution = QSize(ByteItem::WIDTH, ByteItem::HEIGHT); + this->setCacheMode( QGraphicsItem::CacheMode::ItemCoordinateCache, - QSize(ByteItem::WIDTH, ByteItem::HEIGHT) + cacheResolution ); this->setAcceptHoverEvents(true); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemContainerGraphicsView.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemContainerGraphicsView.cpp index d872ded6..c872fbd1 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemContainerGraphicsView.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemContainerGraphicsView.cpp @@ -16,6 +16,9 @@ namespace Bloom::Widgets this->setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff); this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); this->setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate); + this->setOptimizationFlag(QGraphicsView::DontSavePainterState, true); + this->setOptimizationFlag(QGraphicsView::DontAdjustForAntialiasing, true); + this->setCacheMode(QGraphicsView::CacheBackground); } void ByteItemContainerGraphicsView::initScene( diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.cpp index dfe751d1..d9756a96 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.cpp @@ -44,7 +44,7 @@ namespace Bloom::Widgets settings ); - this->byteItemsByAddress.insert(std::pair( + this->byteItemsByAddress.emplace(std::pair( address, byteWidget ));