Skip to content
Snippets Groups Projects
Commit cc0d2fe5 authored by Philip Scherer's avatar Philip Scherer
Browse files

Add copy as JSON action to MemoryViewer

parent e21049c2
No related branches found
No related tags found
1 merge request!200Resolve "ArMem Viewer: Export data to JSON via context menu"
......@@ -20,6 +20,7 @@
#include <ArmarXCore/core/exceptions/local/ExpressionException.h>
#include <RobotAPI/libraries/aron/converter/json/NLohmannJSONConverter.h>
#include <RobotAPI/libraries/aron/core/data/variant/complex/NDArray.h>
#include <RobotAPI/libraries/aron/core/type/variant/container/Object.h>
......@@ -325,6 +326,10 @@ namespace armarx::armem::gui::instance
}
}
if (const std::optional<aron::Path> path = getElementPath(item))
{
menu.addAction(makeActionCopyDataToClipboard(path.value()));
}
if (menu.actions().size() > 0)
{
......@@ -414,6 +419,30 @@ namespace armarx::armem::gui::instance
return action;
}
QAction* InstanceView::makeActionCopyDataToClipboard(const aron::Path& path)
{
QAction* action = new QAction("Copy data to clipboard as JSON");
connect(action, &QAction::triggered, [this, path]()
{
try
{
aron::data::VariantPtr element = currentInstance->data()->navigateAbsolute(path);
nlohmann::json json =
aron::converter::AronNlohmannJSONConverter::ConvertToNlohmannJSON(element);
QClipboard* clipboard = QApplication::clipboard();
clipboard->setText(QString::fromStdString(json.dump()));
QApplication::processEvents();
}
catch (const aron::error::AronException& e)
{
ARMARX_WARNING << "Could not convert Aron data to JSON: " << e.getReason();
}
});
return action;
}
void InstanceView::showImageView(const aron::Path& elementPath)
{
......
......@@ -79,6 +79,7 @@ namespace armarx::armem::gui::instance
QAction* makeActionResolveMemoryID(const MemoryID& id);
QAction* makeActionCopyMemoryID(const MemoryID& id);
QAction* makeActionCopyDataToClipboard(const aron::Path& path);
private:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment