SeedListFileTableModel.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 <QDateTime>
  13. #include <QSharedPointer>
  14. namespace AssetBundler
  15. {
  16. class SeedListTableModel;
  17. class SeedTabWidget;
  18. struct SeedListFileInfo
  19. {
  20. /**
  21. * Stores information about a Seed List File on disk.
  22. *
  23. * @param absolutePath The absolute path of the Seed List File
  24. * @param fileName The name of the Seed List File. This does not include the ".seed" file extension
  25. * @param project The area of the codebase the Seed List File is from (ex: ProjectName, Engine, Gem)
  26. * @param loadFromFile Set to True if you wish to load an existing Seed List File into memory. Set to False if you are creating a new Seed List File.
  27. */
  28. SeedListFileInfo(
  29. const AZStd::string& absolutePath,
  30. const QString& fileName,
  31. const QString& project,
  32. bool loadFromFile,
  33. bool isDefaultSeedList = false,
  34. const AZStd::vector<AZStd::string>& defaultSeeds = AZStd::vector<AZStd::string>(),
  35. const AzFramework::PlatformFlags& platforms = AzFramework::PlatformFlags::Platform_NONE);
  36. bool SaveSeedFile();
  37. bool HasUnsavedChanges();
  38. AZStd::string m_absolutePath;
  39. bool m_isChecked = false;
  40. bool m_isDefaultSeedList = false;
  41. QString m_fileName;
  42. QString m_project;
  43. QDateTime m_fileModificationTime;
  44. QSharedPointer<SeedListTableModel> m_seedListModel;
  45. };
  46. using SeedListFileInfoPtr = AZStd::shared_ptr<SeedListFileInfo>;
  47. /// Stores SeedListFileInfo, using the absolute path (without the drive letter) of the Seed List file as the key
  48. using SeedListFileInfoMap = AZStd::unordered_map<AZStd::string, SeedListFileInfoPtr>;
  49. class SeedListFileTableModel
  50. : public AssetBundlerAbstractFileTableModel
  51. {
  52. public:
  53. explicit SeedListFileTableModel(SeedTabWidget* parentSeedTabWidget);
  54. virtual ~SeedListFileTableModel();
  55. void AddDefaultSeedsToInMemoryList(
  56. const AZStd::vector<AZStd::string>& defaultSeeds,
  57. const char* projectName,
  58. const AzFramework::PlatformFlags& platforms);
  59. AZStd::vector<AZStd::string> CreateNewFiles(
  60. const AZStd::string& absoluteFilePath,
  61. const AzFramework::PlatformFlags& platforms,
  62. const QString& project) override;
  63. bool DeleteFile(const QModelIndex& index) override;
  64. void Reload(
  65. const char* fileExtension,
  66. const QSet<QString>& watchedFolders,
  67. const QSet<QString>& watchedFiles = QSet<QString>(),
  68. const AZStd::unordered_map<AZStd::string, AZStd::string>& pathToProjectNameMap = AZStd::unordered_map<AZStd::string, AZStd::string>()) override;
  69. void LoadFile(
  70. const AZStd::string& absoluteFilePath,
  71. const AZStd::string& projectName = "",
  72. bool isDefaultFile = false) override;
  73. void SelectDefaultSeedLists(bool setSelected);
  74. AZStd::vector<AZStd::string> GenerateAssetLists(const AZStd::string& absoluteFilePath, const AzFramework::PlatformFlags& platforms);
  75. QSharedPointer<SeedListTableModel> GetSeedListFileContents(const QModelIndex& index);
  76. bool SetSeedPlatforms(const QModelIndex& seedFileIndex, const QModelIndex& seedIndex, const AzFramework::PlatformFlags& platforms);
  77. bool AddSeed(const QModelIndex& seedFileIndex, const AZStd::string& seedRelativePath, const AzFramework::PlatformFlags& platforms);
  78. bool RemoveSeed(const QModelIndex& seedFileIndex, const QModelIndex& seedIndex);
  79. bool WriteToDisk(const AZStd::string& key) override;
  80. AZStd::string GetFileAbsolutePath(const QModelIndex& index) const override;
  81. int GetFileNameColumnIndex() const override;
  82. int GetTimeStampColumnIndex() const override;
  83. //////////////////////////////////////////////////////////////////////////
  84. // QAbstractListModel overrides
  85. int columnCount(const QModelIndex& parent = QModelIndex()) const override;
  86. QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
  87. QVariant data(const QModelIndex& index, int role) const override;
  88. bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::CheckStateRole) override;
  89. Qt::ItemFlags flags(const QModelIndex& index) const override;
  90. //////////////////////////////////////////////////////////////////////////
  91. enum Column
  92. {
  93. ColumnCheckBox,
  94. ColumnFileName,
  95. ColumnProject,
  96. ColumnFileModificationTime,
  97. Max
  98. };
  99. private:
  100. AZ::Outcome<SeedListFileInfoPtr, void> GetSeedFileInfo(const QModelIndex& index) const;
  101. SeedListFileInfoMap m_seedListFileInfoMap;
  102. AZStd::unordered_set<AZStd::string> m_checkedSeedListFiles;
  103. AZStd::string m_inMemoryDefaultSeedListKey = "InMemoryDefaultKey";
  104. SeedListFileInfoPtr m_inMemoryDefaultSeedList;
  105. SeedTabWidget* m_seedTabWidget = nullptr;
  106. };
  107. } // namespace AssetBundler