From 05943e6f8adbd7628b0a137d7f9a41f88ad19d3c Mon Sep 17 00:00:00 2001 From: Nav Date: Wed, 12 Apr 2023 21:49:33 +0100 Subject: [PATCH] Fixed bug with copying byte addresses/values from hex viewer to clipboard - they were being copied in an incorrect order --- .../HexViewerWidget/ItemGraphicsScene.cpp | 22 ++++++++++++++++--- .../HexViewerWidget/ItemGraphicsScene.hpp | 1 + 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.cpp index 755198f3..8d92e103 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include "src/Insight/InsightWorker/InsightWorker.hpp" #include "src/Insight/InsightSignals.hpp" @@ -730,6 +732,20 @@ namespace Bloom::Widgets this->byteAddressContainer->invalidateChildItemCaches(); } + std::map ItemGraphicsScene::sortedByteItemsByAddress() { + auto sortedByteItemsByAddress = std::map(); + std::transform( + this->selectedByteItemsByAddress.begin(), + this->selectedByteItemsByAddress.end(), + std::inserter(sortedByteItemsByAddress, sortedByteItemsByAddress.end()), + [] (const decltype(this->selectedByteItemsByAddress)::value_type& pair) { + return pair; + } + ); + + return sortedByteItemsByAddress; + } + void ItemGraphicsScene::copyAddressesToClipboard(AddressType type) { if (this->selectedByteItemsByAddress.empty()) { return; @@ -738,7 +754,7 @@ namespace Bloom::Widgets auto data = QString(); const auto memoryStartAddress = this->state.memoryDescriptor.addressRange.startAddress; - for (const auto& [address, byteItem] : this->selectedByteItemsByAddress) { + for (const auto& [address, byteItem] : this->sortedByteItemsByAddress()) { data.append( "0x" + QString::number( type == AddressType::RELATIVE @@ -759,7 +775,7 @@ namespace Bloom::Widgets auto data = QString(); - for (const auto& [address, byteItem] : this->selectedByteItemsByAddress) { + for (const auto& [address, byteItem] : this->sortedByteItemsByAddress()) { const unsigned char byteValue = byteItem->excluded ? 0x00 : (*this->state.data)[byteItem->startAddress - this->state.memoryDescriptor.addressRange.startAddress]; @@ -776,7 +792,7 @@ namespace Bloom::Widgets auto data = QString(); - for (const auto& [address, byteItem] : this->selectedByteItemsByAddress) { + for (const auto& [address, byteItem] : this->sortedByteItemsByAddress()) { const unsigned char byteValue = byteItem->excluded ? 0x00 : (*this->state.data)[byteItem->startAddress - this->state.memoryDescriptor.addressRange.startAddress]; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.hpp index c6700401..9b262234 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.hpp @@ -146,6 +146,7 @@ namespace Bloom::Widgets void clearByteItemSelection(); void selectAllByteItems(); void setAddressType(AddressType type); + std::map sortedByteItemsByAddress(); void copyAddressesToClipboard(AddressType type); void copyHexValuesToClipboard(); void copyDecimalValuesToClipboard();