ScriptCanvasEnumComboBoxPropertyDataInterface.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #pragma once
  9. #include "ScriptCanvasPropertyDataInterface.h"
  10. namespace ScriptCanvasEditor
  11. {
  12. class ScriptCanvasEnumComboBoxPropertyDataInterface
  13. : public ScriptCanvasComboBoxPropertyDataInterface<int>
  14. {
  15. public:
  16. AZ_CLASS_ALLOCATOR(ScriptCanvasEnumComboBoxPropertyDataInterface, AZ::SystemAllocator);
  17. ScriptCanvasEnumComboBoxPropertyDataInterface(AZ::EntityId scriptCanvasNodeId, ScriptCanvas::EnumComboBoxNodePropertyInterface* propertyInterface)
  18. : ScriptCanvasComboBoxPropertyDataInterface<int>(scriptCanvasNodeId, propertyInterface)
  19. , m_propertyInterface(propertyInterface)
  20. {
  21. const auto& displaySet = m_propertyInterface->GetValueSet();
  22. for (const auto& displayPair : displaySet)
  23. {
  24. QString displayString = displayPair.first.c_str();
  25. m_comboBoxModel.AddElement(displayPair.second, displayString);
  26. }
  27. }
  28. ~ScriptCanvasEnumComboBoxPropertyDataInterface() = default;
  29. // GraphCanvas::ComboBoxDataInterface
  30. GraphCanvas::ComboBoxItemModelInterface* GetItemInterface() override
  31. {
  32. return &m_comboBoxModel;
  33. }
  34. void AssignIndex(const QModelIndex& index) override
  35. {
  36. int32_t dataValue = m_comboBoxModel.GetValueForIndex(index);
  37. SetValue(dataValue);
  38. }
  39. QModelIndex GetAssignedIndex() const override
  40. {
  41. int32_t dataValue = GetValue();
  42. return m_comboBoxModel.GetIndexForValue(dataValue);
  43. }
  44. QString GetDisplayString() const override
  45. {
  46. int32_t dataValue = GetValue();
  47. return m_comboBoxModel.GetNameForValue(dataValue);
  48. }
  49. ////
  50. private:
  51. ScriptCanvas::TypedComboBoxNodePropertyInterface<int>* m_propertyInterface;
  52. GraphCanvas::GraphCanvasListComboBoxModel<int> m_comboBoxModel;
  53. };
  54. }