SceneGraphInspectWidget.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 <QSplitter>
  9. #include <AzCore/Component/ComponentApplicationBus.h>
  10. #include <SceneWidgets/ui_SceneGraphInspectWidget.h>
  11. #include <SceneAPI/SceneCore/DataTypes/IGraphObject.h>
  12. #include <SceneAPI/SceneCore/Events/GraphMetaInfoBus.h>
  13. #include <SceneAPI/SceneUI/SceneWidgets/SceneGraphWidget.h>
  14. #include <SceneAPI/SceneUI/SceneWidgets/SceneGraphInspectWidget.h>
  15. #include <AzToolsFramework/UI/PropertyEditor/ReflectedPropertyEditor.hxx>
  16. namespace AZ
  17. {
  18. namespace SceneAPI
  19. {
  20. namespace UI
  21. {
  22. AZ_CLASS_ALLOCATOR_IMPL(SceneGraphInspectWidget, SystemAllocator);
  23. SceneGraphInspectWidget::SceneGraphInspectWidget(const Containers::Scene& scene, QWidget* parent, SerializeContext* context)
  24. : QWidget(parent)
  25. , ui(new Ui::SceneGraphInspectWidget())
  26. , m_graphView(aznew SceneGraphWidget(scene, this))
  27. , m_propertyEditor(aznew AzToolsFramework::ReflectedPropertyEditor(this))
  28. , m_context(context)
  29. {
  30. ui->setupUi(this);
  31. if (!m_context)
  32. {
  33. ComponentApplicationBus::BroadcastResult(m_context, &ComponentApplicationBus::Events::GetSerializeContext);
  34. }
  35. m_propertyEditor->Setup(m_context, nullptr, true, 100);
  36. m_propertyEditor->setEnabled(false);
  37. m_graphView->Build();
  38. ui->m_splitter->insertWidget(0, m_graphView.data());
  39. ui->m_propertyEditorLayout->addWidget(m_propertyEditor.data());
  40. connect(m_graphView.data(), &SceneGraphWidget::SelectionChanged, this, &SceneGraphInspectWidget::OnSelectionChanged);
  41. }
  42. SceneGraphInspectWidget::~SceneGraphInspectWidget() = default;
  43. void SceneGraphInspectWidget::OnSelectionChanged(AZStd::shared_ptr<const DataTypes::IGraphObject> item)
  44. {
  45. using namespace AZ::SceneAPI::Events;
  46. if (item)
  47. {
  48. if (m_context)
  49. {
  50. // Only try to show if there's a registered editor for the class.
  51. const SerializeContext::ClassData* classData = m_context->FindClassData(item->RTTI_GetType());
  52. if (classData && classData->m_editData)
  53. {
  54. // The reflected property editor is made for editing (as the name suggest) not inspecting,
  55. // therefore it only accepts objects it can modify.
  56. DataTypes::IGraphObject* mutableItem = const_cast<DataTypes::IGraphObject*>(item.get());
  57. m_propertyEditor->ClearInstances();
  58. m_propertyEditor->AddInstance(mutableItem, item->RTTI_GetType());
  59. m_propertyEditor->InvalidateAll();
  60. m_propertyEditor->ExpandAll();
  61. ui->m_infoStack->setCurrentIndex(1);
  62. return;
  63. }
  64. }
  65. AZStd::string description = "<html><head/><body><p>";
  66. if (item->RTTI_GetTypeName())
  67. {
  68. description += "<b>";
  69. description += item->RTTI_GetTypeName();
  70. description += "</b></p><p>";
  71. }
  72. AZStd::string tooltip;
  73. GraphMetaInfoBus::Broadcast(&GraphMetaInfoBus::Events::GetToolTip, tooltip, item.get());
  74. description += tooltip.empty() ? "No information found for this node." : tooltip;
  75. description += "</p></body></html>";
  76. ui->m_noSelectionLabel->setText(description.c_str());
  77. }
  78. else
  79. {
  80. ui->m_noSelectionLabel->setText("Empty node selected.");
  81. }
  82. ui->m_infoStack->setCurrentIndex(0);
  83. }
  84. } // UI
  85. } // SceneAPI
  86. } // AZ
  87. #include <SceneWidgets/moc_SceneGraphInspectWidget.cpp>