BuilderDataItem.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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/std/containers/vector.h>
  10. #include <AzCore/std/containers/unordered_map.h>
  11. #include <AzCore/std/smart_ptr/shared_ptr.h>
  12. #include <AzCore/std/smart_ptr/weak_ptr.h>
  13. #include <AzCore/std/string/string.h>
  14. #include <QMetaType>
  15. namespace AssetProcessor
  16. {
  17. class BuilderDataItem
  18. {
  19. public:
  20. enum class TaskType
  21. {
  22. CreateJobs,
  23. ProcessJob,
  24. Max
  25. };
  26. enum class ItemType
  27. {
  28. InvisibleRoot, // Items of this type serve as the root of the tree view. It will not be shown.
  29. Builder,
  30. TaskType,
  31. Entry,
  32. Max
  33. };
  34. BuilderDataItem(
  35. ItemType itemType, AZStd::string name, AZ::s64 jobCount, AZ::s64 totalDuration, AZStd::weak_ptr<BuilderDataItem> parent);
  36. //! Metric getters
  37. const AZStd::string& GetName() const;
  38. AZ::s64 GetJobCount() const;
  39. AZ::s64 GetTotalDuration() const;
  40. ItemType GetItemType() const;
  41. //! methods querying the tree structure
  42. int ChildCount() const;
  43. AZStd::shared_ptr<BuilderDataItem> GetChild(int row) const;
  44. AZStd::weak_ptr<BuilderDataItem> GetParent() const;
  45. //! Returns this item's row number in its parent's children list.
  46. int GetRow() const;
  47. //! methods that adds children to this item
  48. //! This method is only called on InvisibleRoot: set itemToBeInserted as a child, and update m_childNameToIndex.
  49. //! itemToBeInserted can only be of ItemType::InvisibleRoot or ItemType::Builder. Returns the inserted item.
  50. AZStd::shared_ptr<BuilderDataItem> InsertChild(AZStd::shared_ptr<BuilderDataItem>&& itemToBeInserted);
  51. //! This method is only called on Builder: create TaskType children. Returns whether the insertion succeeds.
  52. bool InsertTaskTypesAsChildren(AZStd::weak_ptr<BuilderDataItem> builderWeakPointer);
  53. //! This method is only called on Builder: inserts the entry as a child of entryTaskType in the tree. Returns the inserted item.
  54. AZStd::shared_ptr<BuilderDataItem> UpdateOrInsertEntry(
  55. TaskType entryTaskType, const AZStd::string& entryName, AZ::s64 entryJobCount, AZ::s64 entryTotalDuration);
  56. private:
  57. void UpdateMetrics(AZ::s64 jobCountDiff, AZ::s64 totalDurationDiff);
  58. AZStd::vector<AZStd::shared_ptr<BuilderDataItem>> m_children;
  59. AZStd::weak_ptr<BuilderDataItem> m_parent;
  60. AZStd::unordered_map<AZStd::string, int> m_childNameToIndex;
  61. AZStd::string m_name;
  62. AZ::s64 m_jobCount = 0;
  63. AZ::s64 m_totalDuration = 0;
  64. ItemType m_itemType = ItemType::Max;
  65. };
  66. }
  67. Q_DECLARE_METATYPE(AssetProcessor::BuilderDataItem*)