From 121a0f0f5ecc37f556acfbf861ba153a8a4652a7 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Sat, 23 Jul 2016 11:41:58 -0700 Subject: [PATCH] Allow atomic editing of multiple overlays from scripts --- interface/src/ui/overlays/Overlays.cpp | 23 +++++++++++++++++++++++ interface/src/ui/overlays/Overlays.h | 4 ++++ 2 files changed, 27 insertions(+) diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index e99ca3a9e0..0b4bcc8652 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -234,6 +234,29 @@ bool Overlays::editOverlay(unsigned int id, const QVariant& properties) { return false; } +bool Overlays::editOverlays(const QVariant& propertiesById) { + QVariantMap map = propertiesById.toMap(); + bool success = true; + QWriteLocker lock(&_lock); + for (const auto& key : map.keys()) { + bool convertSuccess; + unsigned int id = key.toUInt(&convertSuccess); + if (!convertSuccess) { + success = false; + continue; + } + + Overlay::Pointer thisOverlay = getOverlay(id); + if (!thisOverlay) { + success = false; + continue; + } + QVariant properties = map[key]; + thisOverlay->setProperties(properties.toMap()); + } + return success; +} + void Overlays::deleteOverlay(unsigned int id) { Overlay::Pointer overlayToDelete; diff --git a/interface/src/ui/overlays/Overlays.h b/interface/src/ui/overlays/Overlays.h index f47f8de153..99f74fa0f9 100644 --- a/interface/src/ui/overlays/Overlays.h +++ b/interface/src/ui/overlays/Overlays.h @@ -89,6 +89,10 @@ public slots: /// successful edit, if the input id is for an unknown overlay this function will have no effect bool editOverlay(unsigned int id, const QVariant& properties); + /// edits an overlay updating only the included properties, will return the identified OverlayID in case of + /// successful edit, if the input id is for an unknown overlay this function will have no effect + bool editOverlays(const QVariant& propertiesById); + /// deletes a particle void deleteOverlay(unsigned int id);