NodeListSelectionHandler.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. #include <AzCore/EBus/EBus.h>
  9. #include <AzToolsFramework/Debug/TraceContext.h>
  10. #include <SceneAPI/SceneUI/RowWidgets/NodeListSelectionHandler.h>
  11. namespace AZ
  12. {
  13. namespace SceneAPI
  14. {
  15. namespace UI
  16. {
  17. AZ_CLASS_ALLOCATOR_IMPL(NodeListSelectionHandler, SystemAllocator);
  18. NodeListSelectionHandler* NodeListSelectionHandler::s_instance = nullptr;
  19. QWidget* NodeListSelectionHandler::CreateGUI(QWidget* parent)
  20. {
  21. NodeListSelectionWidget* instance = aznew NodeListSelectionWidget(parent);
  22. connect(instance, &NodeListSelectionWidget::valueChanged, this,
  23. [instance]()
  24. {
  25. EBUS_EVENT(AzToolsFramework::PropertyEditorGUIMessages::Bus, RequestWrite, instance);
  26. });
  27. return instance;
  28. }
  29. u32 NodeListSelectionHandler::GetHandlerName() const
  30. {
  31. return AZ_CRC_CE("NodeListSelection");
  32. }
  33. bool NodeListSelectionHandler::AutoDelete() const
  34. {
  35. return false;
  36. }
  37. void NodeListSelectionHandler::ConsumeAttribute(NodeListSelectionWidget* widget, u32 attrib,
  38. AzToolsFramework::PropertyAttributeReader* attrValue, const char* debugName)
  39. {
  40. AZ_TraceContext("Attribute name", debugName);
  41. if (attrib == AZ_CRC_CE("DisabledOption"))
  42. {
  43. ConsumeDisabledOptionAttribute(widget, attrValue);
  44. }
  45. else if (attrib == AZ_CRC_CE("ClassTypeIdFilter"))
  46. {
  47. ConsumeClassTypeIdAttribute(widget, attrValue);
  48. }
  49. else if (attrib == AZ_CRC_CE("RequiresExactTypeId"))
  50. {
  51. ConsumeRequiredExactTypeIdAttribute(widget, attrValue);
  52. }
  53. else if (attrib == AZ_CRC_CE("UseShortNames"))
  54. {
  55. ConsumeUseShortNameAttribute(widget, attrValue);
  56. }
  57. else if (attrib == AZ_CRC_CE("ExcludeEndPoints"))
  58. {
  59. ConsumeExcludeEndPointsAttribute(widget, attrValue);
  60. }
  61. else if (attrib == AZ_CRC_CE("DefaultToDisabled"))
  62. {
  63. ConsumeDefaultToDisabledAttribute(widget, attrValue);
  64. }
  65. else if (attrib == AZ_CRC_CE("ComboBoxEditable"))
  66. {
  67. bool editable;
  68. if (attrValue->Read<bool>(editable))
  69. {
  70. widget->setEditable(editable);
  71. }
  72. }
  73. }
  74. void NodeListSelectionHandler::WriteGUIValuesIntoProperty(size_t /*index*/, NodeListSelectionWidget* GUI,
  75. property_t& instance, AzToolsFramework::InstanceDataNode* /*node*/)
  76. {
  77. instance = static_cast<property_t>(GUI->GetCurrentSelection());
  78. }
  79. bool NodeListSelectionHandler::ReadValuesIntoGUI(size_t /*index*/, NodeListSelectionWidget* GUI, const property_t& instance,
  80. AzToolsFramework::InstanceDataNode* /*node*/)
  81. {
  82. GUI->SetCurrentSelection(instance);
  83. return false;
  84. }
  85. void NodeListSelectionHandler::Register()
  86. {
  87. if (!s_instance)
  88. {
  89. s_instance = aznew NodeListSelectionHandler();
  90. EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, s_instance);
  91. }
  92. }
  93. void NodeListSelectionHandler::Unregister()
  94. {
  95. if (s_instance)
  96. {
  97. EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, UnregisterPropertyType, s_instance);
  98. delete s_instance;
  99. s_instance = nullptr;
  100. }
  101. }
  102. void NodeListSelectionHandler::ConsumeDisabledOptionAttribute(NodeListSelectionWidget* widget, AzToolsFramework::PropertyAttributeReader* attrValue)
  103. {
  104. AZStd::string disabledOption;
  105. if (attrValue->Read<AZStd::string>(disabledOption))
  106. {
  107. widget->AddDisabledOption(AZStd::move(disabledOption));
  108. }
  109. else
  110. {
  111. AZ_Assert(false, "Failed to read string from 'DisabledOption' attribute.");
  112. }
  113. }
  114. void NodeListSelectionHandler::ConsumeClassTypeIdAttribute(NodeListSelectionWidget* widget, AzToolsFramework::PropertyAttributeReader* attrValue)
  115. {
  116. Uuid classTypeId;
  117. if (attrValue->Read<Uuid>(classTypeId))
  118. {
  119. widget->SetClassTypeId(classTypeId);
  120. }
  121. else
  122. {
  123. AZ_Assert(false, "Failed to read uuid from 'ClassTypeIdFilter' attribute.");
  124. }
  125. }
  126. void NodeListSelectionHandler::ConsumeRequiredExactTypeIdAttribute(NodeListSelectionWidget* widget, AzToolsFramework::PropertyAttributeReader* attrValue)
  127. {
  128. bool exactMatch;
  129. if (attrValue->Read<bool>(exactMatch))
  130. {
  131. widget->UseExactClassTypeMatch(exactMatch);
  132. }
  133. else
  134. {
  135. AZ_Assert(false, "Failed to read boolean from 'RequiresExactTypeId' attribute.");
  136. }
  137. }
  138. void NodeListSelectionHandler::ConsumeUseShortNameAttribute(NodeListSelectionWidget* widget, AzToolsFramework::PropertyAttributeReader* attrValue)
  139. {
  140. bool use;
  141. if (attrValue->Read<bool>(use))
  142. {
  143. widget->UseShortNames(use);
  144. }
  145. else
  146. {
  147. AZ_Assert(false, "Failed to read boolean from 'UseShortNames' attribute.");
  148. }
  149. }
  150. void NodeListSelectionHandler::ConsumeExcludeEndPointsAttribute(NodeListSelectionWidget* widget, AzToolsFramework::PropertyAttributeReader* attrValue)
  151. {
  152. bool exclude;
  153. if (attrValue->Read<bool>(exclude))
  154. {
  155. widget->ExcludeEndPoints(exclude);
  156. }
  157. else
  158. {
  159. AZ_Assert(false, "Failed to read boolean from 'ExcludeEndPoints' attribute.");
  160. }
  161. }
  162. void NodeListSelectionHandler::ConsumeDefaultToDisabledAttribute(NodeListSelectionWidget* widget, AzToolsFramework::PropertyAttributeReader* attrValue)
  163. {
  164. bool defaultToDisabled;
  165. if (attrValue->Read<bool>(defaultToDisabled))
  166. {
  167. widget->DefaultToDisabled(defaultToDisabled);
  168. }
  169. else
  170. {
  171. AZ_Assert(false, "Failed to read boolean from 'DefaultToDisabled' attribute.");
  172. }
  173. }
  174. } // UI
  175. } // SceneAPI
  176. } // AZ
  177. #include <RowWidgets/moc_NodeListSelectionHandler.cpp>