SceneGraphWidget.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 <string>
  11. #include <QWidget>
  12. #include <AzCore/Math/Uuid.h>
  13. #include <AzCore/std/smart_ptr/unique_ptr.h>
  14. #include <AzCore/std/smart_ptr/shared_ptr.h>
  15. #include <AzCore/std/containers/set.h>
  16. #include <AzCore/std/containers/vector.h>
  17. #include <AzCore/Memory/SystemAllocator.h>
  18. #include <SceneAPI/SceneCore/Containers/SceneGraph.h>
  19. #include <SceneAPI/SceneUI/SceneUIConfiguration.h>
  20. #endif
  21. class QStandardItem;
  22. class QStandardItemModel;
  23. class QCheckBox;
  24. class QTreeView;
  25. namespace AZ
  26. {
  27. namespace SceneAPI
  28. {
  29. namespace Containers
  30. {
  31. class Scene;
  32. }
  33. namespace DataTypes
  34. {
  35. class IGraphObject;
  36. class ISceneNodeSelectionList;
  37. }
  38. namespace UI
  39. {
  40. // QT space
  41. namespace Ui
  42. {
  43. class SceneGraphWidget;
  44. }
  45. class SCENE_UI_API SceneGraphWidget
  46. : public QWidget
  47. {
  48. public:
  49. Q_OBJECT
  50. public:
  51. AZ_CLASS_ALLOCATOR_DECL
  52. // Sets default settings for the widget. Content will not be constructed until "Build" is called.
  53. SceneGraphWidget(const Containers::Scene& scene, QWidget* parent = nullptr);
  54. // Sets default settings for the widget. Content will not be constructed until "Build" is called.
  55. SceneGraphWidget(const Containers::Scene& scene, const DataTypes::ISceneNodeSelectionList& targetList,
  56. QWidget* parent = nullptr);
  57. ~SceneGraphWidget() override;
  58. AZStd::unique_ptr<DataTypes::ISceneNodeSelectionList>&& ClaimTargetList();
  59. enum class EndPointOption
  60. {
  61. AlwaysShow, // End points are always shown.
  62. NeverShow, // End points are never shown.
  63. OnlyShowFilterTypes // End points are only shown if its type is in the filter type list.
  64. };
  65. // Updates the tree to include/exclude end points. Call "BuildTree()" to rebuild the tree.
  66. virtual void IncludeEndPoints(EndPointOption option);
  67. enum class CheckableOption
  68. {
  69. AllCheckable, // All nodes in the tree can be checked.
  70. NoneCheckable, // No nodes can be checked.
  71. OnlyFilterTypesCheckable // Only nodes in the filter type list can be checked.
  72. };
  73. // Updates the tree to include/exclude check boxes and the primary selection. Call "BuildTree()" to rebuild the tree.
  74. virtual void MakeCheckable(CheckableOption option);
  75. // Add a type to filter for. Filter types are used to determine if a check box is added and/or to be shown if
  76. // the type is an end point. See "IncludeEndPoints" and "MakeCheckable" for more details.
  77. // Call "Build()" to rebuild the tree.
  78. virtual void AddFilterType(const Uuid& id);
  79. // Add a virtual type to filter for. Filter types are used to determine if a check box is added and/or to be shown if
  80. // the type is an end point. See "IncludeEndPoints" and "MakeCheckable" for more details.
  81. // Call "Build()" to rebuild the tree.
  82. virtual void AddVirtualFilterType(Crc32 name);
  83. // Constructs the widget's content. Call this after making one or more changes to the settings.
  84. virtual void Build();
  85. Q_SIGNALS:
  86. void SelectionChanged(AZStd::shared_ptr<const DataTypes::IGraphObject> item);
  87. protected:
  88. virtual void SetupUI();
  89. virtual bool IsFilteredType(const AZStd::shared_ptr<const DataTypes::IGraphObject>& object,
  90. Containers::SceneGraph::NodeIndex index) const;
  91. virtual QStandardItem* BuildTreeItem(const AZStd::shared_ptr<const DataTypes::IGraphObject>& object,
  92. const Containers::SceneGraph::Name& name, bool isCheckable, bool isEndPoint) const;
  93. virtual void OnSelectAllCheckboxStateChanged();
  94. virtual void OnTreeItemStateChanged(QStandardItem* item);
  95. virtual void OnTreeItemChanged(const QModelIndex& current, const QModelIndex& previous);
  96. virtual void UpdateSelectAllStatus();
  97. /// If you are calling this on a lot of elements in quick succession (like in a Build function), set
  98. /// updateNodeSelection to false for increased performance.
  99. virtual bool IsSelected(const Containers::SceneGraph::Name& name, bool updateNodeSelection = true) const;
  100. virtual bool AddSelection(const QStandardItem* item);
  101. virtual bool RemoveSelection(const QStandardItem* item);
  102. QCheckBox* GetQCheckBox();
  103. QTreeView* GetQTreeView();
  104. AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
  105. AZStd::vector<QStandardItem*> m_treeItems;
  106. AZStd::set<Uuid> m_filterTypes;
  107. AZStd::set<Crc32> m_filterVirtualTypes;
  108. QScopedPointer<Ui::SceneGraphWidget> ui;
  109. QScopedPointer<QStandardItemModel> m_treeModel;
  110. AZStd::unique_ptr<DataTypes::ISceneNodeSelectionList> m_targetList;
  111. AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
  112. const Containers::Scene& m_scene;
  113. size_t m_selectedCount;
  114. size_t m_totalCount;
  115. EndPointOption m_endPointOption;
  116. CheckableOption m_checkableOption;
  117. private:
  118. bool IsSelectedInSelectionList(const Containers::SceneGraph::Name& name, const DataTypes::ISceneNodeSelectionList& targetList) const;
  119. };
  120. } // namespace UI
  121. } // namespace SceneAPI
  122. } // namespace AZ