CommandPropertiesChange.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. CommandPropertiesChange::CommandPropertiesChange(UndoStack* stack,
  10. HierarchyWidget* hierarchy,
  11. SerializeHelpers::SerializedEntryList& preValueChanges,
  12. const char* commandName)
  13. : QUndoCommand()
  14. , m_stack(stack)
  15. , m_isFirstExecution(true)
  16. , m_hasPreviouslyFailed(false)
  17. , m_hierarchy(hierarchy)
  18. , m_entryList(HierarchyClipboard::Serialize(m_hierarchy, m_hierarchy->selectedItems(), nullptr, preValueChanges, false))
  19. {
  20. AZ_Assert(!m_entryList.empty(), "Entry list is empty");
  21. setText(commandName);
  22. }
  23. void CommandPropertiesChange::undo()
  24. {
  25. UndoStackExecutionScope s(m_stack);
  26. Recreate(true);
  27. }
  28. void CommandPropertiesChange::redo()
  29. {
  30. UndoStackExecutionScope s(m_stack);
  31. Recreate(false);
  32. }
  33. void CommandPropertiesChange::Recreate(bool isUndo)
  34. {
  35. if (m_hasPreviouslyFailed)
  36. {
  37. // Disable this command.
  38. // Nothing else to do.
  39. return;
  40. }
  41. if (m_isFirstExecution)
  42. {
  43. m_isFirstExecution = false;
  44. // Nothing else to do.
  45. }
  46. else
  47. {
  48. // HierarchyClipboard::Unserialize() takes care of both the editor-side and the runtime-side.
  49. m_hasPreviouslyFailed = (!HierarchyClipboard::Unserialize(m_hierarchy, m_entryList, isUndo));
  50. }
  51. }
  52. void CommandPropertiesChange::Push(UndoStack* stack,
  53. HierarchyWidget* hierarchy,
  54. SerializeHelpers::SerializedEntryList& preValueChanges,
  55. const char* commandName)
  56. {
  57. if (stack->GetIsExecuting())
  58. {
  59. // This is a redundant Qt notification.
  60. // Nothing else to do.
  61. return;
  62. }
  63. stack->push(new CommandPropertiesChange(stack,
  64. hierarchy,
  65. preValueChanges,
  66. commandName));
  67. }