Fixed bug with copying byte addresses/values from hex viewer to clipboard - they were being copied in an incorrect order

This commit is contained in:
Nav
2023-04-12 21:49:33 +01:00
parent 61e3c1f02d
commit 05943e6f8a
2 changed files with 20 additions and 3 deletions

View File

@@ -5,6 +5,8 @@
#include <QApplication>
#include <QClipboard>
#include <QByteArray>
#include <map>
#include <algorithm>
#include "src/Insight/InsightWorker/InsightWorker.hpp"
#include "src/Insight/InsightSignals.hpp"
@@ -730,6 +732,20 @@ namespace Bloom::Widgets
this->byteAddressContainer->invalidateChildItemCaches();
}
std::map<Targets::TargetMemoryAddress, ByteItem*> ItemGraphicsScene::sortedByteItemsByAddress() {
auto sortedByteItemsByAddress = std::map<Targets::TargetMemoryAddress, ByteItem*>();
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];

View File

@@ -146,6 +146,7 @@ namespace Bloom::Widgets
void clearByteItemSelection();
void selectAllByteItems();
void setAddressType(AddressType type);
std::map<Targets::TargetMemoryAddress, ByteItem*> sortedByteItemsByAddress();
void copyAddressesToClipboard(AddressType type);
void copyHexValuesToClipboard();
void copyDecimalValuesToClipboard();