2
0

ProductDependencyTreeModel.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 <AssetDatabase/AssetDatabase.h>
  10. #include <AzCore/std/smart_ptr/unique_ptr.h>
  11. #include <QAbstractItemModel>
  12. #include <QIcon>
  13. #include "AssetTreeFilterModel.h"
  14. namespace AssetProcessor
  15. {
  16. class ProductDependencyTreeItem;
  17. class ProductDependencyTreeItemData;
  18. enum class DependencyTreeType
  19. {
  20. Incoming,
  21. Outgoing
  22. };
  23. class ProductDependencyTreeModel
  24. : public QAbstractItemModel
  25. {
  26. public:
  27. ProductDependencyTreeModel(
  28. AZStd::shared_ptr<AzToolsFramework::AssetDatabase::AssetDatabaseConnection> sharedDbConnection,
  29. AssetTreeFilterModel* productFilterModel,
  30. DependencyTreeType treeType,
  31. QObject* parent = nullptr);
  32. virtual ~ProductDependencyTreeModel();
  33. // QAbstractItemModel
  34. QModelIndex index(int row, int column, const QModelIndex& parent) const override;
  35. int rowCount(const QModelIndex& parent = QModelIndex()) const override;
  36. int columnCount(const QModelIndex& parent = QModelIndex()) const override;
  37. QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
  38. bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
  39. QModelIndex parent(const QModelIndex& index) const override;
  40. bool hasChildren(const QModelIndex& parent) const override;
  41. Qt::ItemFlags flags(const QModelIndex& index) const override;
  42. public Q_SLOTS:
  43. void AssetDataSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
  44. protected:
  45. // visitedDependencies is intentionally a copy because we need to independently track the chain for each branch in the graph
  46. void PopulateOutgoingProductDependencies(ProductDependencyTreeItem* parent, AZ::s64 parentProductId, QSet<AZ::s64> visitedDependencies);
  47. void PopulateIncomingProductDependencies(ProductDependencyTreeItem* parent, AZ::s64 parentProductId, QSet<AZ::s64> visitedDependencies);
  48. AZStd::shared_ptr<AzToolsFramework::AssetDatabase::AssetDatabaseConnection> m_sharedDbConnection;
  49. // Note that the following pointer is passed in down from the main window.
  50. // We cache the raw pointer here as this window does not own it and is not
  51. // responsible for destroying it (the main window will).
  52. AssetTreeFilterModel* m_productFilterModel = nullptr;
  53. AZStd::unique_ptr<ProductDependencyTreeItem> m_root;
  54. AZStd::unordered_set<AZ::s64> m_trackedProductIds;
  55. DependencyTreeType m_treeType;
  56. QIcon m_fileIcon;
  57. };
  58. }