CommandHierarchyItemReparent.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 CommandHierarchyItemReparent
  11. : public QUndoCommand
  12. {
  13. public:
  14. void undo() override;
  15. void redo() override;
  16. static void Push(UndoStack* stack,
  17. HierarchyWidget* hierarchy,
  18. const HierarchyItemRawPtrList& items,
  19. const QTreeWidgetItemRawPtrList& itemParents);
  20. private:
  21. CommandHierarchyItemReparent(UndoStack* stack,
  22. HierarchyWidget* hierarchy,
  23. const HierarchyItemRawPtrList& items);
  24. struct ChildItem
  25. {
  26. AZ::EntityId m_id;
  27. AZ::EntityId m_parentId;
  28. int m_row;
  29. };
  30. using ChildItemList = AZStd::list < ChildItem >;
  31. void Reparent(ChildItemList& sourceChildren, ChildItemList& destChildren, bool& childrenSorted);
  32. UndoStack* m_stack;
  33. HierarchyWidget* m_hierarchy;
  34. ChildItemList m_sourceChildren;
  35. ChildItemList m_destinationChildren;
  36. bool m_sourceChildrenSorted;
  37. bool m_destinationChildrenSorted;
  38. EntityHelpers::EntityIdList m_listToValidate;
  39. // The first execution of redo() is done in REACTION to a Qt
  40. // event that has ALREADY completed some necessary work. We ONLY
  41. // want to execute all of redo() on SUBSEQUENT calls.
  42. bool m_isFirstExecution;
  43. };