StringDataInterface.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. if (GraphModel::SlotPtr slot = m_slot.lock())
  23. {
  24. return slot->GetValue<AZStd::string>();
  25. }
  26. else
  27. {
  28. return "";
  29. }
  30. }
  31. void StringDataInterface::SetString(const AZStd::string& value)
  32. {
  33. if (GraphModel::SlotPtr slot = m_slot.lock())
  34. {
  35. AZStd::string trimValue = value;
  36. AzFramework::StringFunc::TrimWhiteSpace(trimValue, true, true);
  37. if (trimValue != slot->GetValue<AZStd::string>())
  38. {
  39. const GraphCanvas::GraphId graphCanvasSceneId = GetDisplay()->GetSceneId();
  40. GraphCanvas::ScopedGraphUndoBatch undoBatch(graphCanvasSceneId);
  41. slot->SetValue(trimValue);
  42. GraphControllerNotificationBus::Event(
  43. graphCanvasSceneId, &GraphControllerNotifications::OnGraphModelSlotModified, slot);
  44. GraphControllerNotificationBus::Event(
  45. graphCanvasSceneId, &GraphControllerNotifications::OnGraphModelGraphModified, slot->GetParentNode());
  46. }
  47. }
  48. }
  49. }