CommandHierarchyItemToggleIsExpanded.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. #pragma once
  9. #include <QUndoCommand>
  10. class CommandHierarchyItemToggleIsExpanded
  11. : public QUndoCommand
  12. {
  13. public:
  14. void undo() override;
  15. void redo() override;
  16. // IMPORTANT: We DON'T want this command to support mergeWith().
  17. // Otherwise we leave commands on the undo stack that have no
  18. // effect (NOOP).
  19. //
  20. // To avoid the NOOPs, we can either:
  21. //
  22. // (1) Delete the NOPs from the undo stack.
  23. // or
  24. // (2) NOT support mergeWith().
  25. //
  26. // The problem with (1) is that it only allows odd number of
  27. // state changes to be undoable. (2) is more consistent
  28. // by making all state changes undoable.
  29. static void Push(UndoStack* stack,
  30. HierarchyWidget* hierarchy,
  31. HierarchyItem* item);
  32. private:
  33. CommandHierarchyItemToggleIsExpanded(UndoStack* stack,
  34. HierarchyWidget* hierarchy,
  35. HierarchyItem* item);
  36. void SetIsExpanded(bool isExpanded);
  37. UndoStack* m_stack;
  38. HierarchyWidget* m_hierarchy;
  39. AZ::EntityId m_id;
  40. bool m_toIsExpanded;
  41. };