PivotTreeWidget.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 <AzCore/PlatformDef.h>
  11. // qbrush.h(118): warning C4251: 'QBrush::d': class 'QScopedPointer<QBrushData,QBrushDataPointerDeleter>' needs to have dll-interface to be used by clients of class 'QBrush'
  12. // qwidget.h(858): warning C4800: 'uint': forcing value to bool 'true' or 'false' (performance warning)
  13. AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option")
  14. #include <QTimer>
  15. #include <QTreeView>
  16. #include <QSortFilterProxyModel>
  17. AZ_POP_DISABLE_WARNING
  18. #include <AzCore/std/smart_ptr/unique_ptr.h>
  19. #include <GraphCanvas/Widgets/GraphCanvasTreeItem.h>
  20. #include <GraphCanvas/Widgets/GraphCanvasTreeModel.h>
  21. #include <Editor/View/Widgets/LoggingPanel/LoggingWindowSession.h>
  22. #endif
  23. namespace Ui
  24. {
  25. class PivotTreeWidget;
  26. }
  27. namespace ScriptCanvasEditor
  28. {
  29. class PivotTreeItem
  30. : public GraphCanvas::GraphCanvasTreeItem
  31. {
  32. public:
  33. AZ_CLASS_ALLOCATOR(PivotTreeItem, AZ::SystemAllocator);
  34. AZ_RTTI(PivotTreeItem, "{F310C0EA-9CFE-4A8F-9CDA-46E24673B01A}", GraphCanvas::GraphCanvasTreeItem);
  35. enum Column
  36. {
  37. IndexForce = -1,
  38. Name,
  39. // Seriously. Returning 1 causes the data to only ask for the tool tip.
  40. // No idea why.
  41. QT_NEEDS_A_SECOND_COLUMN_FOR_THIS_MODEL_TO_WORK_FOR_SOME_REASON,
  42. Count
  43. };
  44. PivotTreeItem();
  45. ~PivotTreeItem();
  46. const LoggingDataId& GetLoggingDataId() const;
  47. // GraphCanvasTreeItem
  48. int GetColumnCount() const override final;
  49. Qt::ItemFlags Flags(const QModelIndex& index) const override final;
  50. QVariant Data(const QModelIndex& index, int role) const override final;
  51. bool SetData(const QModelIndex& index, const QVariant& value, int role) override final;
  52. void OnChildAdded(GraphCanvasTreeItem* treeItem) override final;
  53. ////
  54. virtual Qt::CheckState GetCheckState() const = 0;
  55. virtual void SetCheckState(Qt::CheckState checkState) = 0;
  56. protected:
  57. virtual AZStd::string GetDisplayName() const = 0;
  58. virtual void OnLoggingDataIdSet();
  59. void SetLoggingDataId(const LoggingDataId& dataId);
  60. void SetIsPivotedElement(bool isPivotedElement);
  61. private:
  62. bool m_isPivotElement;
  63. LoggingDataId m_loggingDataId;
  64. };
  65. class PivotTreeEntityItem
  66. : public PivotTreeItem
  67. {
  68. public:
  69. AZ_CLASS_ALLOCATOR(PivotTreeEntityItem, AZ::SystemAllocator);
  70. AZ_RTTI(PivotTreeEntityItem, "{67725865-7004-441D-84BB-D38FF491A3FD}", PivotTreeItem);
  71. PivotTreeEntityItem(const AZ::NamedEntityId& entityId);
  72. const AZ::NamedEntityId& GetNamedEntityId() const;
  73. protected:
  74. AZStd::string GetDisplayName() const override final;
  75. const AZ::EntityId& GetEntityId() const;
  76. private:
  77. AZ::NamedEntityId m_namedEntityId;
  78. };
  79. class PivotTreeGraphItem
  80. : public PivotTreeItem
  81. {
  82. public:
  83. AZ_CLASS_ALLOCATOR(PivotTreeGraphItem, AZ::SystemAllocator);
  84. AZ_RTTI(PivotTreeGraphItem, "{37FCAC77-DE32-4B1B-97FD-66852EC31CAB}", PivotTreeItem);
  85. PivotTreeGraphItem(const AZ::Data::AssetId& assetId);
  86. const AZ::Data::AssetId& GetAssetId() const;
  87. protected:
  88. AZStd::string GetDisplayName() const override final;
  89. AZStd::string_view GetAssetPath() const;
  90. private:
  91. AZ::Data::AssetId m_assetId;
  92. AZStd::string m_assetPath;
  93. AZStd::string m_assetName;
  94. };
  95. class PivotTreeRoot
  96. : public PivotTreeItem
  97. {
  98. public:
  99. AZ_CLASS_ALLOCATOR(PivotTreeRoot, AZ::SystemAllocator);
  100. AZ_RTTI(PivotTreeRoot, "{E172AB89-49BA-429F-AC83-9CCBD6A3B1B9}", PivotTreeItem);
  101. PivotTreeRoot() = default;
  102. void SwitchDataSource(const LoggingDataId& aggregateDataSource);
  103. protected:
  104. Qt::CheckState GetCheckState() const override final;
  105. void SetCheckState(Qt::CheckState checkState) override final;
  106. AZStd::string GetDisplayName() const override final;
  107. virtual void OnDataSourceChanged(const LoggingDataId& aggregateDataSource) = 0;
  108. private:
  109. LoggingDataId m_loggingDataId;
  110. };
  111. class PivotTreeSortProxyModel
  112. : public QSortFilterProxyModel
  113. {
  114. public:
  115. AZ_CLASS_ALLOCATOR(PivotTreeSortProxyModel, AZ::SystemAllocator);
  116. bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override;
  117. bool HasFilter() const;
  118. void SetFilter(const QString& filter);
  119. void ClearFilter();
  120. private:
  121. QString m_filter;
  122. QRegExp m_filterRegex;
  123. };
  124. class PivotTreeWidget
  125. : public QWidget
  126. {
  127. Q_OBJECT
  128. public:
  129. ~PivotTreeWidget();
  130. void DisplayTree();
  131. void SwitchDataSource(const LoggingDataId& aggregateDataSource);
  132. public Q_SLOT:
  133. void OnFilterChanged(const QString& activeTextFilter);
  134. protected:
  135. PivotTreeWidget(PivotTreeRoot* pivotRoot, const AZ::Crc32& savingId, QWidget* parent);
  136. PivotTreeRoot* GetTreeRoot();
  137. virtual void OnTreeDisplayed();
  138. private:
  139. void OnItemDoubleClicked(const QModelIndex& modelIndex);
  140. AZStd::unique_ptr<Ui::PivotTreeWidget> m_ui;
  141. PivotTreeRoot* m_pivotRoot;
  142. GraphCanvas::GraphCanvasTreeModel* m_treeModel;
  143. PivotTreeSortProxyModel* m_proxyModel;
  144. };
  145. }