ObjectEditor.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 <Editor/ObjectEditor.h>
  9. #include <AzToolsFramework/UI/PropertyEditor/ReflectedPropertyEditor.hxx>
  10. #include <QVBoxLayout>
  11. namespace EMotionFX
  12. {
  13. const int ObjectEditor::s_propertyLabelWidth = 160;
  14. ObjectEditor::ObjectEditor(AZ::SerializeContext* serializeContext, QWidget* parent)
  15. : ObjectEditor(serializeContext, nullptr, parent)
  16. {
  17. }
  18. ObjectEditor::ObjectEditor(AZ::SerializeContext* serializeContext, AzToolsFramework::IPropertyEditorNotify* notify, QWidget* parent)
  19. : QFrame(parent)
  20. , m_object(nullptr)
  21. , m_propertyEditor(nullptr)
  22. {
  23. setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
  24. m_propertyEditor = aznew AzToolsFramework::ReflectedPropertyEditor(this);
  25. m_propertyEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
  26. m_propertyEditor->setObjectName("PropertyEditor");
  27. m_propertyEditor->Setup(serializeContext, notify, false/*enableScrollbars*/, s_propertyLabelWidth);
  28. QVBoxLayout* mainLayout = new QVBoxLayout(this);
  29. mainLayout->setSizeConstraint(QLayout::SetMinimumSize);
  30. mainLayout->setMargin(0);
  31. mainLayout->setContentsMargins(0, 0, 0, 0);
  32. mainLayout->addWidget(m_propertyEditor);
  33. setLayout(mainLayout);
  34. }
  35. void ObjectEditor::AddInstance(void* object, const AZ::TypeId& objectTypeId, void* aggregateInstance, void* compareInstance)
  36. {
  37. m_object = object;
  38. m_propertyEditor->AddInstance(object, objectTypeId, aggregateInstance, compareInstance);
  39. m_propertyEditor->InvalidateAll();
  40. }
  41. void ObjectEditor::ClearInstances(bool invalidateImmediately)
  42. {
  43. m_propertyEditor->ClearInstances();
  44. if (invalidateImmediately)
  45. {
  46. m_propertyEditor->InvalidateAll();
  47. }
  48. m_object = nullptr;
  49. }
  50. void ObjectEditor::SetFilterString(QString filterString)
  51. {
  52. m_propertyEditor->SetFilterString(AZStd::string{filterString.toLatin1().data()});
  53. InvalidateAll();
  54. }
  55. bool ObjectEditor::HasDisplayedNodes() const
  56. {
  57. return !m_propertyEditor->HasFilteredOutNodes() || m_propertyEditor->HasVisibleNodes();
  58. }
  59. void ObjectEditor::InvalidateAll()
  60. {
  61. // If we Invalidate without giving the Search string, filtering Colliders will not work
  62. // properly (nothing will be filtered out, instead only highlighted)
  63. // If we pass an empty filterString, the Motion Id Picker will not be shown
  64. if (m_propertyEditor->GetFilterString().size() > 0)
  65. {
  66. m_propertyEditor->InvalidateAll(m_propertyEditor->GetFilterString().c_str());
  67. }
  68. else
  69. {
  70. m_propertyEditor->InvalidateAll();
  71. }
  72. }
  73. void ObjectEditor::InvalidateValues()
  74. {
  75. m_propertyEditor->InvalidateValues();
  76. }
  77. } // namespace EMotionFX