StringDataInterface.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. // AZ
  9. #include <AzFramework/StringFunc/StringFunc.h>
  10. // Graph Model
  11. #include <GraphModel/GraphModelBus.h>
  12. #include <GraphModel/Integration/IntegrationBus.h>
  13. #include <GraphModel/Integration/StringDataInterface.h>
  14. namespace GraphModelIntegration
  15. {
  16. StringDataInterface::StringDataInterface(GraphModel::SlotPtr slot)
  17. : m_slot(slot)
  18. {
  19. }
  20. AZStd::string StringDataInterface::GetString() const
  21. {
  22. GraphModel::SlotPtr slot = m_slot.lock();
  23. return slot ? slot->GetValue<AZStd::string>() : AZStd::string();
  24. }
  25. void StringDataInterface::SetString(const AZStd::string& value)
  26. {
  27. if (GraphModel::SlotPtr slot = m_slot.lock())
  28. {
  29. AZStd::string trimValue = value;
  30. AzFramework::StringFunc::TrimWhiteSpace(trimValue, true, true);
  31. if (trimValue != slot->GetValue<AZStd::string>())
  32. {
  33. const GraphCanvas::GraphId graphCanvasSceneId = GetDisplay()->GetSceneId();
  34. GraphCanvas::ScopedGraphUndoBatch undoBatch(graphCanvasSceneId);
  35. slot->SetValue(trimValue);
  36. GraphControllerNotificationBus::Event(graphCanvasSceneId, &GraphControllerNotifications::OnGraphModelSlotModified, slot);
  37. GraphControllerNotificationBus::Event(graphCanvasSceneId, &GraphControllerNotifications::OnGraphModelGraphModified, slot->GetParentNode());
  38. }
  39. }
  40. }
  41. } // namespace GraphModelIntegration