NodeLayoutComponent.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 <AzCore/Component/Component.h>
  10. #include <GraphCanvas/Components/Nodes/NodeBus.h>
  11. #include <GraphCanvas/Components/Nodes/NodeLayoutBus.h>
  12. #include <GraphCanvas/Components/SceneBus.h>
  13. class QGraphicsLayout;
  14. namespace GraphCanvas
  15. {
  16. //! Base class for internal Node Layouts to help deal with some book keeping
  17. class NodeLayoutComponent
  18. : public AZ::Component
  19. , public NodeLayoutRequestBus::Handler
  20. {
  21. public:
  22. AZ_COMPONENT(NodeLayoutComponent, "{D3152CCC-1C6D-4E95-829D-0441002440AB}");
  23. static void Reflect(AZ::ReflectContext* context)
  24. {
  25. AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
  26. if (serializeContext)
  27. {
  28. serializeContext->Class<NodeLayoutComponent, AZ::Component>()
  29. ->Version(1)
  30. ;
  31. }
  32. }
  33. NodeLayoutComponent()
  34. : m_layout(nullptr)
  35. {
  36. }
  37. virtual ~NodeLayoutComponent()
  38. {
  39. }
  40. // AZ::Component
  41. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  42. {
  43. provided.push_back(NodeLayoutServiceCrc);
  44. }
  45. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  46. {
  47. incompatible.push_back(NodeLayoutServiceCrc);
  48. }
  49. static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
  50. {
  51. dependent.push_back(NodeLayoutServiceCrc);
  52. }
  53. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  54. {
  55. required.push_back(AZ_CRC("GraphCanvas_NodeService", 0xcc0f32cc));
  56. required.push_back(AZ_CRC("GraphCanvas_StyledGraphicItemService", 0xeae4cdf4));
  57. }
  58. void Init() override
  59. {
  60. }
  61. void Activate() override
  62. {
  63. NodeLayoutRequestBus::Handler::BusConnect(GetEntityId());
  64. }
  65. void Deactivate() override
  66. {
  67. NodeLayoutRequestBus::Handler::BusDisconnect();
  68. }
  69. ////
  70. // NodeLayoutRequestBus
  71. QGraphicsLayout* GetLayout() override
  72. {
  73. return m_layout;
  74. }
  75. ////
  76. protected:
  77. // Methods to simplify casting in other components
  78. template<class T>
  79. T* GetLayoutAs()
  80. {
  81. return static_cast<T*>(m_layout);
  82. }
  83. template<class T>
  84. const T* GetLayoutAs() const
  85. {
  86. return static_cast<const T*>(m_layout);
  87. }
  88. QGraphicsLayout* m_layout;
  89. };
  90. }