MainWindow.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. #if !defined(Q_MOC_RUN)
  10. #include <QMainWindow>
  11. #include <QStringList>
  12. #include <QStringListModel>
  13. #include "native/utilities/LogPanel.h"
  14. #include <QPointer>
  15. #include "native/assetprocessor.h"
  16. #include <AzQtComponents/Components/FilteredSearchWidget.h>
  17. #include <QElapsedTimer>
  18. #include <ui/BuilderListModel.h>
  19. #include <native/utilities/AssetUtilEBusHelper.h>
  20. #include <native/utilities/PlatformConfiguration.h>
  21. #include <native/ui/CacheServerData.h>
  22. #endif
  23. namespace AzToolsFramework
  24. {
  25. namespace AssetDatabase
  26. {
  27. class AssetDatabaseConnection;
  28. }
  29. }
  30. namespace Ui {
  31. class MainWindow;
  32. }
  33. class GUIApplicationManager;
  34. class QListWidgetItem;
  35. class QFileSystemWatcher;
  36. class QSettings;
  37. namespace AssetProcessor
  38. {
  39. class AssetTreeFilterModel;
  40. class JobSortFilterProxyModel;
  41. class JobsModel;
  42. class AssetTreeItem;
  43. class ProductAssetTreeModel;
  44. class SourceAssetTreeModel;
  45. class ProductDependencyTreeItem;
  46. class JobEntry;
  47. class BuilderData;
  48. class BuilderInfoPatternsModel;
  49. class BuilderInfoMetricsModel;
  50. class BuilderInfoMetricsSortModel;
  51. class EnabledRelocationTypesModel;
  52. }
  53. class MainWindow
  54. : public QMainWindow
  55. {
  56. Q_OBJECT
  57. public:
  58. // Tracks which asset tab the asset page is on.
  59. enum class AssetTabIndex
  60. {
  61. Source = 0,
  62. Intermediate = 1,
  63. Product = 2
  64. };
  65. // This order is actually driven by the layout in the UI file.
  66. // If the order is changed in the UI file, it should be changed here, too.
  67. enum class DialogStackIndex
  68. {
  69. Welcome, // The welcome screen provides some basic info on the Asset Processor.
  70. Jobs,
  71. Assets,
  72. Logs,
  73. Connections,
  74. Builders,
  75. Tools,
  76. AssetRelocation
  77. };
  78. struct Config
  79. {
  80. // These default values are used if the values can't be read from AssetProcessorConfig.ini,
  81. // and the call to defaultConfig fails.
  82. // Asset Status
  83. int jobStatusColumnWidth = -1;
  84. int jobSourceColumnWidth = -1;
  85. int jobPlatformColumnWidth = -1;
  86. int jobKeyColumnWidth = -1;
  87. int jobCompletedColumnWidth = -1;
  88. // Event Log Details
  89. int logTypeColumnWidth = -1;
  90. // Event Log Line Details
  91. int contextDetailsTableMaximumRows = -1;
  92. };
  93. /*!
  94. * Loads the button config data from a settings object.
  95. */
  96. static Config loadConfig(QSettings& settings);
  97. /*!
  98. * Returns default button config data.
  99. */
  100. static Config defaultConfig();
  101. explicit MainWindow(GUIApplicationManager* guiApplicationManager, QWidget* parent = 0);
  102. void Activate();
  103. ~MainWindow() override;
  104. public Q_SLOTS:
  105. void ShowWindow();
  106. void SyncAllowedListAndRejectedList(QStringList allowedList, QStringList rejectedList);
  107. void FirstTimeAddedToRejectedList(QString ipAddress);
  108. void SaveLogPanelState();
  109. void OnAssetProcessorStatusChanged(const AssetProcessor::AssetProcessorStatusEntry entry);
  110. void OnRescanButtonClicked();
  111. void HighlightAsset(QString assetPath);
  112. void OnAssetTabChange(int index);
  113. void BuilderTabSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
  114. protected Q_SLOTS:
  115. void ApplyConfig();
  116. protected:
  117. bool eventFilter(QObject* obj, QEvent* event) override;
  118. private:
  119. class LogSortFilterProxy : public QSortFilterProxyModel
  120. {
  121. public:
  122. LogSortFilterProxy(QObject* parentOjbect);
  123. bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
  124. void onTypeFilterChanged(const AzQtComponents::SearchTypeFilterList& activeTypeFilters);
  125. private:
  126. QSet<AzToolsFramework::Logging::LogLine::LogType> m_logTypes;
  127. };
  128. Ui::MainWindow* ui;
  129. GUIApplicationManager* m_guiApplicationManager;
  130. AzToolsFramework::Logging::LogTableModel* m_logsModel;
  131. AssetProcessor::JobSortFilterProxyModel* m_jobSortFilterProxy;
  132. LogSortFilterProxy* m_logSortFilterProxy;
  133. AssetProcessor::JobsModel* m_jobsModel;
  134. AssetProcessor::SourceAssetTreeModel* m_sourceModel = nullptr;
  135. AssetProcessor::SourceAssetTreeModel* m_intermediateModel = nullptr;
  136. AssetProcessor::ProductAssetTreeModel* m_productModel = nullptr;
  137. AssetProcessor::AssetTreeFilterModel* m_sourceAssetTreeFilterModel = nullptr;
  138. AssetProcessor::AssetTreeFilterModel* m_intermediateAssetTreeFilterModel = nullptr;
  139. AssetProcessor::AssetTreeFilterModel* m_productAssetTreeFilterModel = nullptr;
  140. QPointer<AssetProcessor::LogPanel> m_loggingPanel;
  141. int m_processJobsCount = 0;
  142. int m_createJobCount = 0;
  143. QFileSystemWatcher* m_fileSystemWatcher;
  144. Config m_config;
  145. AssetProcessor::BuilderData* m_builderData = nullptr;
  146. BuilderListModel* m_builderList = nullptr;
  147. BuilderListSortFilterProxy* m_builderListSortFilterProxy = nullptr;
  148. AssetProcessor::BuilderInfoPatternsModel* m_builderInfoPatterns = nullptr;
  149. AssetProcessor::BuilderInfoMetricsModel* m_builderInfoMetrics = nullptr;
  150. AssetProcessor::BuilderInfoMetricsSortModel* m_builderInfoMetricsSort = nullptr;
  151. AssetProcessor::CacheServerData m_cacheServerData;
  152. AssetProcessor::EnabledRelocationTypesModel* m_enabledRelocationTypesModel = nullptr;
  153. void SetContextLogDetails(const QMap<QString, QString>& details);
  154. void ClearContextLogDetails();
  155. void EditConnection(const QModelIndex& index);
  156. void OnConnectionContextMenu(const QPoint& point);
  157. void OnEditConnection(bool checked);
  158. void OnAddConnection(bool checked);
  159. void OnRemoveConnection(bool checked);
  160. void OnSupportClicked(bool checked);
  161. void OnConnectionSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
  162. QStringListModel m_rejectedAddresses;
  163. QStringListModel m_allowedListAddresses;
  164. void OnAllowedListConnectionsListViewClicked();
  165. void OnRejectedConnectionsListViewClicked();
  166. void OnAllowedListCheckBoxToggled();
  167. void OnAddHostNameAllowedListButtonClicked();
  168. void OnAddIPAllowedListButtonClicked();
  169. void OnToAllowedListButtonClicked();
  170. void OnToRejectedListButtonClicked();
  171. void UpdateJobLogView(QModelIndex selectedIndex);
  172. void JobSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
  173. void JobStatusChanged(AssetProcessor::JobEntry entry, AzToolsFramework::AssetSystem::JobStatus status);
  174. void JobLogSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
  175. void DesktopOpenJobLogs();
  176. // Switches to the Job tab of the Asset Processor, clears any current searches, scroll to, and select the job at the given index.
  177. void SelectJobAndMakeVisible(const QModelIndex& index);
  178. void ResetLoggingPanel();
  179. void ShowJobViewContextMenu(const QPoint& pos);
  180. void ShowLogLineContextMenu(const QPoint& pos);
  181. void ShowJobLogContextMenu(const QPoint& pos);
  182. void ShowProductAssetContextMenu(const QPoint& pos);
  183. void ShowSourceAssetContextMenu(const QPoint& pos);
  184. void ShowIntermediateAssetContextMenu(const QPoint& pos);
  185. void BuildSourceAssetTreeContextMenu(QMenu& menu, const AssetProcessor::AssetTreeItem& sourceAssetTreeItem);
  186. // Helper function that retrieves the item selected in outgoing/incoming dependency TreeView
  187. AssetProcessor::ProductDependencyTreeItem* GetProductAssetFromDependencyTreeView(bool isOutgoing, const QPoint& pos);
  188. void ShowOutgoingProductDependenciesContextMenu(const QPoint& pos);
  189. void ShowIncomingProductDependenciesContextMenu(const QPoint& pos);
  190. void ResetTimers();
  191. void CheckStartAnalysisTimers();
  192. void CheckEndAnalysisTimer();
  193. void CheckStartProcessTimers();
  194. void CheckEndProcessTimer();
  195. QString FormatStringTime(qint64 timeMs) const;
  196. /// Refreshes the filter in the Asset Tab at a set time interval.
  197. /// TreeView filters can be expensive to refresh every time an item is added, so refreshing on a set schedule
  198. /// keeps the view up-to-date without causing a performance bottleneck.
  199. void IntervalAssetTabFilterRefresh();
  200. /// Fires off one final refresh before invalidating the filter refresh timer.
  201. void ShutdownAssetTabFilterRefresh();
  202. void SetupAssetServerTab();
  203. void AddPatternRow(AZStd::string_view name, AssetBuilderSDK::AssetBuilderPattern::PatternType type, AZStd::string_view pattern, bool enable);
  204. void AssembleAssetPatterns();
  205. void CheckAssetServerStates();
  206. void ResetAssetServerView();
  207. void SetServerAddress(AZStd::string_view serverAddress);
  208. void SetupAssetSelectionCaching();
  209. QElapsedTimer m_scanTimer;
  210. QElapsedTimer m_analysisTimer;
  211. QElapsedTimer m_processTimer;
  212. QElapsedTimer m_filterRefreshTimer;
  213. qint64 m_scanTime{ 0 };
  214. qint64 m_analysisTime{ 0 };
  215. qint64 m_processTime{ 0 };
  216. AZStd::shared_ptr<AzToolsFramework::AssetDatabase::AssetDatabaseConnection> m_sharedDbConnection;
  217. AssetProcessor::SourceAndScanID m_cachedSourceAssetSelection;
  218. AZStd::string m_cachedProductAssetSelection;
  219. QMetaObject::Connection m_connectionForResettingAssetsView;
  220. };