NodeTreeSelectionHandler.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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/SceneCore/Containers/SceneGraph.h>
  11. #include <SceneAPI/SceneUI/RowWidgets/NodeTreeSelectionHandler.h>
  12. namespace AZ
  13. {
  14. namespace SceneAPI
  15. {
  16. namespace UI
  17. {
  18. AZ_CLASS_ALLOCATOR_IMPL(NodeTreeSelectionHandler, SystemAllocator);
  19. NodeTreeSelectionHandler* NodeTreeSelectionHandler::s_instance = nullptr;
  20. QWidget* NodeTreeSelectionHandler::CreateGUI(QWidget* parent)
  21. {
  22. NodeTreeSelectionWidget* instance = aznew NodeTreeSelectionWidget(parent);
  23. connect(instance, &NodeTreeSelectionWidget::valueChanged, this,
  24. [instance]()
  25. {
  26. EBUS_EVENT(AzToolsFramework::PropertyEditorGUIMessages::Bus, RequestWrite, instance);
  27. });
  28. return instance;
  29. }
  30. u32 NodeTreeSelectionHandler::GetHandlerName() const
  31. {
  32. return AZ_CRC_CE("NodeTreeSelection");
  33. }
  34. bool NodeTreeSelectionHandler::AutoDelete() const
  35. {
  36. return false;
  37. }
  38. bool NodeTreeSelectionHandler::IsDefaultHandler() const
  39. {
  40. return true;
  41. }
  42. void NodeTreeSelectionHandler::ConsumeAttribute(NodeTreeSelectionWidget* widget, u32 attrib,
  43. AzToolsFramework::PropertyAttributeReader* attrValue, const char* debugName)
  44. {
  45. AZ_TraceContext("Attribute name", debugName);
  46. if (attrib == AZ_CRC_CE("FilterName"))
  47. {
  48. ConsumeFilterNameAttribute(widget, attrValue);
  49. }
  50. else if (attrib == AZ_CRC_CE("FilterType"))
  51. {
  52. ConsumeFilterTypeAttribute(widget, attrValue);
  53. }
  54. else if (attrib == AZ_CRC_CE("FilterVirtualType"))
  55. {
  56. ConsumeFilterVirtualTypeAttribute(widget, attrValue);
  57. }
  58. else if (attrib == AZ_CRC_CE("NarrowSelection"))
  59. {
  60. ConsumeNarrowSelectionAttribute(widget, attrValue);
  61. }
  62. }
  63. void NodeTreeSelectionHandler::WriteGUIValuesIntoProperty(size_t /*index*/, NodeTreeSelectionWidget* GUI,
  64. property_t& instance, AzToolsFramework::InstanceDataNode* /*node*/)
  65. {
  66. GUI->CopyListTo(instance);
  67. GUI->UpdateSelectionLabel();
  68. }
  69. bool NodeTreeSelectionHandler::ReadValuesIntoGUI(size_t /*index*/, NodeTreeSelectionWidget* GUI, const property_t& instance,
  70. AzToolsFramework::InstanceDataNode* /*node*/)
  71. {
  72. GUI->SetList(instance);
  73. GUI->UpdateSelectionLabel();
  74. return false;
  75. }
  76. void NodeTreeSelectionHandler::Register()
  77. {
  78. if (!s_instance)
  79. {
  80. s_instance = aznew NodeTreeSelectionHandler();
  81. EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, s_instance);
  82. }
  83. }
  84. void NodeTreeSelectionHandler::Unregister()
  85. {
  86. if (s_instance)
  87. {
  88. EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, UnregisterPropertyType, s_instance);
  89. delete s_instance;
  90. s_instance = nullptr;
  91. }
  92. }
  93. void NodeTreeSelectionHandler::ConsumeFilterNameAttribute(NodeTreeSelectionWidget* widget, AzToolsFramework::PropertyAttributeReader* attrValue)
  94. {
  95. AZStd::string filterName;
  96. if (attrValue->Read<AZStd::string>(filterName))
  97. {
  98. widget->SetFilterName(AZStd::move(filterName));
  99. }
  100. else
  101. {
  102. AZ_Assert(false, "Failed to read string from 'FilterName' attribute.");
  103. }
  104. }
  105. void NodeTreeSelectionHandler::ConsumeFilterTypeAttribute(NodeTreeSelectionWidget* widget, AzToolsFramework::PropertyAttributeReader* attrValue)
  106. {
  107. Uuid filterType;
  108. if (attrValue->Read<Uuid>(filterType))
  109. {
  110. widget->AddFilterType(filterType);
  111. }
  112. else
  113. {
  114. AZ_Assert(false, "Failed to read Uuid from 'FilterType' attribute.");
  115. }
  116. }
  117. void NodeTreeSelectionHandler::ConsumeFilterVirtualTypeAttribute(NodeTreeSelectionWidget* widget, AzToolsFramework::PropertyAttributeReader* attrValue)
  118. {
  119. Crc32 filterVirtualType;
  120. if (!attrValue->Read<Crc32>(filterVirtualType))
  121. {
  122. AZStd::string filterFilterTypeName;
  123. if (attrValue->Read<AZStd::string>(filterFilterTypeName))
  124. {
  125. filterVirtualType = Crc32(filterFilterTypeName.c_str());
  126. }
  127. else
  128. {
  129. AZ_Assert(false, "Failed to read crc value or string from 'VirtualFilterName' attribute.");
  130. return;
  131. }
  132. }
  133. widget->AddFilterVirtualType(filterVirtualType);
  134. }
  135. void NodeTreeSelectionHandler::ConsumeNarrowSelectionAttribute(NodeTreeSelectionWidget* widget, AzToolsFramework::PropertyAttributeReader* attrValue)
  136. {
  137. bool narrowSelection;
  138. if (attrValue->Read<bool>(narrowSelection))
  139. {
  140. widget->UseNarrowSelection(narrowSelection);
  141. }
  142. else
  143. {
  144. AZ_Assert(false, "Failed to read boolean from 'NarrowSelection' attribute.");
  145. }
  146. }
  147. } // UI
  148. } // SceneAPI
  149. } // AZ
  150. #include <RowWidgets/moc_NodeTreeSelectionHandler.cpp>