PrefabInspectorOverrideTestFixture.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 <AzToolsFramework/Prefab/PrefabEditorPreferences.h>
  9. #include <AzToolsFramework/UI/PropertyEditor/ComponentEditor.hxx>
  10. #include <Prefab/Overrides/PrefabInspectorOverrideTestFixture.h>
  11. namespace UnitTest
  12. {
  13. void PrefabInspectorOverrideTestFixture::SetUpEditorFixtureImpl()
  14. {
  15. // Enable feature flags for DPE and InspectorOverrideManagement
  16. if (auto* console = AZ::Interface<AZ::IConsole>::Get(); console != nullptr)
  17. {
  18. console->GetCvarValue("ed_enableInspectorOverrideManagement", m_ed_enableInspectorOverrideManagement);
  19. console->GetCvarValue("ed_enableDPEInspector", m_ed_enableDPEInspector);
  20. console->PerformCommand("ed_enableInspectorOverrideManagement true");
  21. console->PerformCommand("ed_enableDPEInspector true");
  22. }
  23. PrefabOverrideTestFixture::SetUpEditorFixtureImpl();
  24. m_testEntityPropertyEditor = AZStd::make_unique<AzToolsFramework::EntityPropertyEditor>(nullptr, Qt::WindowFlags(), false);
  25. }
  26. void PrefabInspectorOverrideTestFixture::TearDownEditorFixtureImpl()
  27. {
  28. m_testEntityPropertyEditor.reset();
  29. PrefabOverrideTestFixture::TearDownEditorFixtureImpl();
  30. AZ::SettingsRegistryInterface* registry = AZ::SettingsRegistry::Get();
  31. registry->Set("/O3DE/Autoexec/ConsoleCommands/ed_enableDPEInspector", m_ed_enableDPEInspector);
  32. registry->Set("/O3DE/Autoexec/ConsoleCommands/ed_enableInspectorOverrideManagement", m_ed_enableInspectorOverrideManagement);
  33. }
  34. void PrefabInspectorOverrideTestFixture::GenerateComponentAdapterDoms(AZ::EntityId entityId)
  35. {
  36. // Calling UpdateContents will trigger the ReflectionAdapters of the components to build the DPE DOMs.
  37. AzToolsFramework::ToolsApplicationRequestBus::Broadcast(
  38. &AzToolsFramework::ToolsApplicationRequests::SetSelectedEntities, AzToolsFramework::EntityIdList{ entityId });
  39. QMetaObject::invokeMethod(m_testEntityPropertyEditor.get(), "UpdateContents", Qt::DirectConnection);
  40. }
  41. void PrefabInspectorOverrideTestFixture::ValidateComponentEditorDomContents(
  42. const AzToolsFramework::ComponentEditor::VisitComponentAdapterContentsCallback& callback)
  43. {
  44. AZStd::vector<const AzToolsFramework::ComponentEditor*> componentEditors;
  45. AzToolsFramework::EntityPropertyEditorRequestBus::Broadcast(
  46. &AzToolsFramework::EntityPropertyEditorRequestBus::Events::VisitComponentEditors,
  47. [&componentEditors](const AzToolsFramework::ComponentEditor* componentEditor)
  48. {
  49. componentEditors.push_back(componentEditor);
  50. return true;
  51. });
  52. ASSERT_EQ(componentEditors.size(), 1);
  53. componentEditors.front()->VisitComponentAdapterContents(callback);
  54. }
  55. } // namespace UnitTest