CommandHierarchyItemDelete.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 "EditorCommon.h"
  9. #include <Animation/UiEditorAnimationBus.h>
  10. CommandHierarchyItemDelete::CommandHierarchyItemDelete(UndoStack* stack,
  11. HierarchyWidget* hierarchy)
  12. : QUndoCommand()
  13. , m_stack(stack)
  14. , m_hierarchy(hierarchy)
  15. , m_entries()
  16. {
  17. // true: Put the serialized data in m_undoXml.
  18. HierarchyClipboard::Serialize(m_hierarchy, m_hierarchy->selectedItems(), nullptr, m_entries, true);
  19. AZ_Assert(!m_entries.empty(), "Failed to serialize");
  20. setText(QString("delete element") + (m_entries.empty() ? "" : "s"));
  21. }
  22. void CommandHierarchyItemDelete::undo()
  23. {
  24. UndoStackExecutionScope s(m_stack);
  25. HierarchyHelpers::CreateItemsAndElements(m_hierarchy, m_entries);
  26. UiEditorAnimListenerBus::Broadcast(&UiEditorAnimListenerBus::Events::OnUiElementsDeletedOrReAdded);
  27. }
  28. void CommandHierarchyItemDelete::redo()
  29. {
  30. UndoStackExecutionScope s(m_stack);
  31. HierarchyHelpers::Delete(m_hierarchy, m_entries);
  32. UiEditorAnimListenerBus::Broadcast(&UiEditorAnimListenerBus::Events::OnUiElementsDeletedOrReAdded);
  33. }
  34. void CommandHierarchyItemDelete::Push(UndoStack* stack,
  35. HierarchyWidget* hierarchy,
  36. const QTreeWidgetItemRawPtrQList& selectedItems)
  37. {
  38. if (stack->GetIsExecuting())
  39. {
  40. // This is a redundant Qt notification.
  41. // Nothing else to do.
  42. return;
  43. }
  44. if (selectedItems.empty())
  45. {
  46. // Nothing selected. Nothing to do.
  47. return;
  48. }
  49. stack->push(new CommandHierarchyItemDelete(stack, hierarchy));
  50. }