HierarchyItem.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #if !defined(Q_MOC_RUN)
  10. #include <QTreeWidgetItem>
  11. #include "EditorCommon.h"
  12. #endif
  13. class HierarchyItem
  14. : public QObject
  15. , public QTreeWidgetItem
  16. {
  17. Q_OBJECT
  18. public:
  19. static constexpr int RttiType = ItemType::UserType + 1;
  20. static HierarchyItem* RttiCast(QTreeWidgetItem* treeItem)
  21. {
  22. if (treeItem && treeItem->type() == RttiType)
  23. {
  24. return static_cast<HierarchyItem*>(treeItem);
  25. }
  26. return nullptr;
  27. }
  28. explicit HierarchyItem(EditorWindow* editWindow,
  29. QTreeWidgetItem& parent,
  30. int childIndex,
  31. const QString label,
  32. AZ::Entity* optionalElement);
  33. virtual ~HierarchyItem();
  34. //! This should NEVER return a nullptr.
  35. AZ::Entity* GetElement() const;
  36. AZ::EntityId GetEntityId() const;
  37. //! This is ONLY ever called when the HierarchyWidget is being destroyed
  38. void ClearEntityId();
  39. void SetMouseIsHovering(bool isHovering);
  40. void SetIsExpanded(bool isExpanded);
  41. void ApplyElementIsExpanded();
  42. void SetIsSelectable(bool isSelectable);
  43. void SetIsSelected(bool isSelected);
  44. void SetIsVisible(bool isVisible);
  45. HierarchyItem* Parent() const;
  46. HierarchyItem* Child(int i) const;
  47. //! This is a generic marker, for use by any algorithm.
  48. void SetMark(bool m);
  49. bool GetMark();
  50. //! This is ephemeral data used for snapping.
  51. //@{
  52. void SetNonSnappedOffsets(UiTransform2dInterface::Offsets offsets);
  53. UiTransform2dInterface::Offsets GetNonSnappedOffsets();
  54. void SetNonSnappedZRotation(float rotation);
  55. float GetNonSnappedZRotation();
  56. //@}
  57. //! This is our PREVIOUS parent and childRow.
  58. //! This is used to undo reparenting.
  59. void SetPreMove(AZ::EntityId parentId, int childRow);
  60. AZ::EntityId GetPreMoveParentId();
  61. int GetPreMoveChildRow();
  62. void ReplaceElement(const AZStd::string& buffer, const AZStd::unordered_set<AZ::Data::AssetId>& referencedSliceAssets);
  63. //! Update the visual look of the element to show slice information
  64. void UpdateSliceInfo();
  65. //! Update the visual look of the element to show whether it's editor only
  66. void UpdateEditorOnlyInfo();
  67. signals:
  68. void SignalItemAdd(HierarchyItem* item);
  69. void SignalItemRemove(HierarchyItem* item);
  70. private:
  71. void DeleteElement();
  72. void UpdateIcon();
  73. void UpdateChildIcon();
  74. //! Update the visual look of the element and its descendants to show whether they're editor only
  75. void UpdateEditorOnlyInfoRecursive();
  76. EditorWindow* m_editorWindow;
  77. AZ::EntityId m_elementId;
  78. // IMPORTANT: This is used for searching and culling items.
  79. // This ISN'T thread-safe. This ISN'T persistent.
  80. bool m_mark;
  81. AZ::EntityId m_preMoveParentId;
  82. int m_preMoveChildRow;
  83. bool m_mouseIsHovering;
  84. UiTransform2dInterface::Offsets m_nonSnappedOffsets;
  85. float m_nonSnappedZRotation;
  86. };