Implemented data export via clipboard actions in the hex viewer widget
This commit is contained in:
@@ -28,10 +28,12 @@ namespace Bloom::Widgets
|
|||||||
|
|
||||||
std::size_t byteIndex;
|
std::size_t byteIndex;
|
||||||
Targets::TargetMemoryAddress address = 0x00;
|
Targets::TargetMemoryAddress address = 0x00;
|
||||||
|
|
||||||
QString addressHex;
|
QString addressHex;
|
||||||
QString relativeAddressHex;
|
QString relativeAddressHex;
|
||||||
|
|
||||||
|
unsigned char value = 0x00;
|
||||||
|
QString hexValue;
|
||||||
|
|
||||||
std::size_t currentRowIndex = 0;
|
std::size_t currentRowIndex = 0;
|
||||||
std::size_t currentColumnIndex = 0;
|
std::size_t currentColumnIndex = 0;
|
||||||
|
|
||||||
@@ -62,12 +64,9 @@ namespace Bloom::Widgets
|
|||||||
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
|
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned char value = 0x00;
|
|
||||||
bool valueInitialised = false;
|
bool valueInitialised = false;
|
||||||
|
|
||||||
const HexViewerWidgetSettings& settings;
|
const HexViewerWidgetSettings& settings;
|
||||||
|
|
||||||
QString hexValue;
|
|
||||||
std::optional<QString> asciiValue;
|
std::optional<QString> asciiValue;
|
||||||
|
|
||||||
ByteItem** hoveredByteItem;
|
ByteItem** hoveredByteItem;
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QClipboard>
|
||||||
|
#include <QByteArray>
|
||||||
|
|
||||||
#include "src/Insight/InsightWorker/InsightWorker.hpp"
|
#include "src/Insight/InsightWorker/InsightWorker.hpp"
|
||||||
#include "src/Insight/InsightSignals.hpp"
|
#include "src/Insight/InsightSignals.hpp"
|
||||||
@@ -62,6 +65,53 @@ namespace Bloom::Widgets
|
|||||||
this->setAddressType(AddressType::ABSOLUTE);
|
this->setAddressType(AddressType::ABSOLUTE);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
QObject::connect(
|
||||||
|
this->selectAllByteItemsAction,
|
||||||
|
&QAction::triggered,
|
||||||
|
this,
|
||||||
|
&ByteItemGraphicsScene::selectAllByteItems
|
||||||
|
);
|
||||||
|
|
||||||
|
QObject::connect(
|
||||||
|
this->deselectByteItemsAction,
|
||||||
|
&QAction::triggered,
|
||||||
|
this,
|
||||||
|
&ByteItemGraphicsScene::clearByteItemSelection
|
||||||
|
);
|
||||||
|
|
||||||
|
QObject::connect(
|
||||||
|
this->copyAbsoluteAddressAction,
|
||||||
|
&QAction::triggered,
|
||||||
|
this,
|
||||||
|
[this] {
|
||||||
|
this->copyAddressesToClipboard(AddressType::ABSOLUTE);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
QObject::connect(
|
||||||
|
this->copyRelativeAddressAction,
|
||||||
|
&QAction::triggered,
|
||||||
|
this,
|
||||||
|
[this] {
|
||||||
|
this->copyAddressesToClipboard(AddressType::RELATIVE);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
QObject::connect(
|
||||||
|
this->copyHexValuesAction,
|
||||||
|
&QAction::triggered,
|
||||||
|
this,
|
||||||
|
&ByteItemGraphicsScene::copyHexValuesToClipboard
|
||||||
|
);
|
||||||
|
|
||||||
|
QObject::connect(
|
||||||
|
this->copyDecimalValuesAction,
|
||||||
|
&QAction::triggered,
|
||||||
|
this,
|
||||||
|
&ByteItemGraphicsScene::copyDecimalValuesToClipboard
|
||||||
|
);
|
||||||
|
|
||||||
this->setSceneRect(0, 0, this->getSceneWidth(), 0);
|
this->setSceneRect(0, 0, this->getSceneWidth(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -433,6 +483,26 @@ namespace Bloom::Widgets
|
|||||||
menu->exec(event->screenPos());
|
menu->exec(event->screenPos());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto itemsSelected = !this->selectedByteItemsByAddress.empty();
|
||||||
|
|
||||||
|
auto* menu = new QMenu(this->parent);
|
||||||
|
menu->addAction(this->selectAllByteItemsAction);
|
||||||
|
menu->addAction(this->deselectByteItemsAction);
|
||||||
|
menu->addSeparator();
|
||||||
|
|
||||||
|
auto* copyMenu = new QMenu("Copy Selected", menu);
|
||||||
|
copyMenu->addAction(this->copyAbsoluteAddressAction);
|
||||||
|
copyMenu->addAction(this->copyRelativeAddressAction);
|
||||||
|
copyMenu->addSeparator();
|
||||||
|
copyMenu->addAction(this->copyHexValuesAction);
|
||||||
|
copyMenu->addAction(this->copyDecimalValuesAction);
|
||||||
|
|
||||||
|
copyMenu->setEnabled(itemsSelected);
|
||||||
|
this->deselectByteItemsAction->setEnabled(itemsSelected);
|
||||||
|
|
||||||
|
menu->addMenu(copyMenu);
|
||||||
|
menu->exec(event->screenPos());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ByteItemGraphicsScene::updateAnnotationValues(const Targets::TargetMemoryBuffer& buffer) {
|
void ByteItemGraphicsScene::updateAnnotationValues(const Targets::TargetMemoryBuffer& buffer) {
|
||||||
@@ -715,4 +785,46 @@ namespace Bloom::Widgets
|
|||||||
|
|
||||||
this->byteAddressContainer->invalidateChildItemCaches();
|
this->byteAddressContainer->invalidateChildItemCaches();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ByteItemGraphicsScene::copyAddressesToClipboard(AddressType type) {
|
||||||
|
if (this->selectedByteItemsByAddress.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto data = QString();
|
||||||
|
|
||||||
|
for (const auto& [address, byteItem] : this->selectedByteItemsByAddress) {
|
||||||
|
data.append((type == AddressType::ABSOLUTE ? byteItem->addressHex : byteItem->relativeAddressHex) + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
QApplication::clipboard()->setText(std::move(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ByteItemGraphicsScene::copyHexValuesToClipboard() {
|
||||||
|
if (this->selectedByteItemsByAddress.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto data = QString();
|
||||||
|
|
||||||
|
for (const auto& [address, byteItem] : this->selectedByteItemsByAddress) {
|
||||||
|
data.append("0x" + byteItem->hexValue + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
QApplication::clipboard()->setText(std::move(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ByteItemGraphicsScene::copyDecimalValuesToClipboard() {
|
||||||
|
if (this->selectedByteItemsByAddress.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto data = QString();
|
||||||
|
|
||||||
|
for (const auto& [address, byteItem] : this->selectedByteItemsByAddress) {
|
||||||
|
data.append(QString::number(byteItem->value, 10) + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
QApplication::clipboard()->setText(std::move(data));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,6 +110,13 @@ namespace Bloom::Widgets
|
|||||||
QGraphicsRectItem* rubberBandRectItem = nullptr;
|
QGraphicsRectItem* rubberBandRectItem = nullptr;
|
||||||
std::optional<QPointF> rubberBandInitPoint = std::nullopt;
|
std::optional<QPointF> rubberBandInitPoint = std::nullopt;
|
||||||
|
|
||||||
|
// Context menu actions
|
||||||
|
QAction* selectAllByteItemsAction = new QAction("Select All", this);
|
||||||
|
QAction* deselectByteItemsAction = new QAction("Deselect All", this);
|
||||||
|
QAction* copyAbsoluteAddressAction = new QAction("Copy Absolute Addresses", this);
|
||||||
|
QAction* copyRelativeAddressAction = new QAction("Copy Relative Addresses", this);
|
||||||
|
QAction* copyHexValuesAction = new QAction("Copy Hexadecimal Values", this);
|
||||||
|
QAction* copyDecimalValuesAction = new QAction("Copy Decimal Values", this);
|
||||||
|
|
||||||
// Address label container context menu actions
|
// Address label container context menu actions
|
||||||
QAction* displayRelativeAddressAction = new QAction("Relative", this);
|
QAction* displayRelativeAddressAction = new QAction("Relative", this);
|
||||||
@@ -140,5 +147,8 @@ namespace Bloom::Widgets
|
|||||||
void clearByteItemSelection();
|
void clearByteItemSelection();
|
||||||
void selectAllByteItems();
|
void selectAllByteItems();
|
||||||
void setAddressType(AddressType type);
|
void setAddressType(AddressType type);
|
||||||
|
void copyAddressesToClipboard(AddressType type);
|
||||||
|
void copyHexValuesToClipboard();
|
||||||
|
void copyDecimalValuesToClipboard();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user