2
0

SeedListTableModel.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 <source/models/AssetBundlerAbstractFileTableModel.h>
  10. #include <AzToolsFramework/Asset/AssetSeedManager.h>
  11. #include <AzFramework/Platform/PlatformDefaults.h>
  12. #include <QIcon>
  13. #include <QSharedPointer>
  14. namespace AssetBundler
  15. {
  16. struct AdditionalSeedInfo
  17. {
  18. AdditionalSeedInfo(const QString& relativePath, const QString& platformList);
  19. QString m_relativePath;
  20. QString m_platformList;
  21. QString m_errorMessage; // If the asset isn't available, this will contain an error message to display instead.
  22. };
  23. using AdditionalSeedInfoPtr = AZStd::shared_ptr<AdditionalSeedInfo>;
  24. using AdditionalSeedInfoMap = AZStd::unordered_map<AZ::Data::AssetId, AdditionalSeedInfoPtr>;
  25. class SeedListTableModel
  26. : public QAbstractTableModel
  27. {
  28. public:
  29. explicit SeedListTableModel(
  30. QObject* parent = nullptr,
  31. const AZStd::string& absolutePath = AZStd::string(),
  32. const AZStd::vector<AZStd::string>& defaultSeeds = AZStd::vector<AZStd::string>(),
  33. const AzFramework::PlatformFlags& platforms = AzFramework::PlatformFlags::Platform_NONE);
  34. virtual ~SeedListTableModel() {}
  35. AZStd::shared_ptr<AzToolsFramework::AssetSeedManager> GetSeedListManager() { return m_seedListManager; }
  36. bool HasUnsavedChanges() { return m_hasUnsavedChanges && m_isFileOnDisk; }
  37. void SetHasUnsavedChanges(bool hasUnsavedChanges) { m_hasUnsavedChanges = hasUnsavedChanges; }
  38. bool Save(const AZStd::string& absolutePath);
  39. AZ::Outcome<AzFramework::PlatformFlags, void> GetSeedPlatforms(const QModelIndex& index) const;
  40. bool SetSeedPlatforms(const QModelIndex& index, const AzFramework::PlatformFlags& platforms);
  41. bool AddSeed(const AZStd::string& seedRelativePath, const AzFramework::PlatformFlags& platforms);
  42. bool RemoveSeed(const QModelIndex& seedIndex);
  43. //////////////////////////////////////////////////////////////////////////
  44. // QAbstractListModel overrides
  45. int rowCount(const QModelIndex& parent = QModelIndex()) const override;
  46. int columnCount(const QModelIndex& parent = QModelIndex()) const override;
  47. QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
  48. QVariant data(const QModelIndex& index, int role) const override;
  49. //////////////////////////////////////////////////////////////////////////
  50. enum Column
  51. {
  52. ColumnRelativePath,
  53. ColumnPlatformList,
  54. Max
  55. };
  56. private:
  57. AZ::Outcome<AZStd::reference_wrapper<const AzFramework::SeedInfo>, void> GetSeedInfo(const QModelIndex& index) const;
  58. AZ::Outcome<AdditionalSeedInfoPtr, void> GetAdditionalSeedInfo(const QModelIndex& index) const;
  59. AZStd::shared_ptr<AzToolsFramework::AssetSeedManager> m_seedListManager;
  60. AdditionalSeedInfoMap m_additionalSeedInfoMap;
  61. QIcon m_errorImage;
  62. bool m_hasUnsavedChanges = false;
  63. bool m_isFileOnDisk = true;
  64. };
  65. } // namespace AssetBundler