RCQueueSortModel.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #ifndef ASSETPROCESSOR_RCQUEUESORTMODEL_H
  9. #define ASSETPROCESSOR_RCQUEUESORTMODEL_H
  10. #if !defined(Q_MOC_RUN)
  11. #include <QSortFilterProxyModel>
  12. #include <QSet>
  13. #include <QString>
  14. #include "native/utilities/AssetUtilEBusHelper.h"
  15. #include <AzCore/std/containers/unordered_map.h>
  16. #include "native/assetprocessor.h"
  17. #endif
  18. class RCcontrollerUnitTests;
  19. namespace AssetProcessor
  20. {
  21. class QueueElementID;
  22. class RCJobListModel;
  23. class RCJob;
  24. //! This sort and filtering proxy model attaches to the raw RC job list
  25. //! And presents it in the optimal order for processing rather than display.
  26. //! The current desired order is
  27. //! * Critical (currently Copy) jobs for currently connected platforms
  28. //! * Jobs in Sync Compile Requests for currently connected platforms (with most recent requests first)
  29. //! * Jobs in Async Compile Lists for currently connected platforms
  30. //! * Remaining jobs in currently connected platforms, in priority order
  31. //! (The same, repeated, for unconnected platforms).
  32. class RCQueueSortModel
  33. : public QSortFilterProxyModel
  34. , protected AssetProcessorPlatformBus::Handler
  35. {
  36. Q_OBJECT
  37. friend class ::RCcontrollerUnitTests;
  38. public:
  39. explicit RCQueueSortModel(QObject* parent = 0);
  40. void AttachToModel(RCJobListModel* target);
  41. RCJob* GetNextPendingJob();
  42. void AddJobIdEntry(AssetProcessor::RCJob* rcJob);
  43. void RemoveJobIdEntry(AssetProcessor::RCJob* rcJob);
  44. // implement QSortFilteRProxyModel:
  45. bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
  46. bool lessThan(const QModelIndex& left, const QModelIndex& right) const override;
  47. // Debugging functions
  48. void DumpJobListInSortOrder();
  49. public Q_SLOTS:
  50. void OnEscalateJobs(AssetProcessor::JobIdEscalationList jobIdEscalationList);
  51. protected:
  52. typedef AZStd::unordered_map<AZ::s64, AssetProcessor::RCJob*> JobRunKeyToRCJobMap;
  53. JobRunKeyToRCJobMap m_currentJobRunKeyToJobEntries;
  54. QSet<QString> m_currentlyConnectedPlatforms;
  55. bool m_dirtyNeedsResort = false; // instead of constantly resorting, we resort only when someone wants to pull an element from us
  56. // ---------------------------------------------------------
  57. // AssetProcessorPlatformBus::Handler
  58. void AssetProcessorPlatformConnected(const AZStd::string platform) override;
  59. void AssetProcessorPlatformDisconnected(const AZStd::string platform) override;
  60. // -----------
  61. RCJobListModel* m_sourceModel;
  62. private Q_SLOTS:
  63. void ProcessPlatformChangeMessage(QString platformName, bool connected);
  64. };
  65. } // namespace AssetProcessor
  66. #endif //ASSETPROCESSOR_RCQUEUESORTMODEL_H