Skip to content
Snippets Groups Projects
Commit 4334c8b8 authored by Christian Dreher's avatar Christian Dreher
Browse files

Merge branch '64-armem-viewer-export-data-to-json-via-context-menu' into 'master'

Resolve "ArMem Viewer: Export data to JSON via context menu"

Closes #64

See merge request ArmarX/RobotAPI!200
parents d4d695c7 f9237ef0
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>
......@@ -324,7 +325,12 @@ namespace armarx::armem::gui::instance
}
}
}
const std::optional<aron::Path> elementPath = getElementPath(item);
if (elementPath)
{
menu.addAction(makeActionCopyDataToClipboard(elementPath.value()));
}
if (menu.actions().size() > 0)
{
......@@ -414,6 +420,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(2)));
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