BundleListTabWidget.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. #include <source/ui/BundleListTabWidget.h>
  9. #include <source/ui/ui_BundleListTabWidget.h>
  10. #include <source/models/BundleFileListModel.h>
  11. #include <source/utils/GUIApplicationManager.h>
  12. #include <AzQtComponents/Components/FilteredSearchWidget.h>
  13. #include <QFileDialog>
  14. #include <QItemSelectionModel>
  15. const double BytesToMegabytes = 1024.0 * 1024.0;
  16. namespace AssetBundler
  17. {
  18. BundleListTabWidget::BundleListTabWidget(QWidget* parent, GUIApplicationManager* guiApplicationManager)
  19. : AssetBundlerTabWidget(parent, guiApplicationManager)
  20. {
  21. m_ui.reset(new Ui::BundleListTabWidget);
  22. m_ui->setupUi(this);
  23. m_ui->mainVerticalLayout->setContentsMargins(MarginSize, MarginSize, MarginSize, MarginSize);
  24. m_fileTableModel.reset(new BundleFileListModel);
  25. m_fileTableFilterModel.reset(new AssetBundlerFileTableFilterModel(
  26. this,
  27. m_fileTableModel->GetFileNameColumnIndex(),
  28. m_fileTableModel->GetTimeStampColumnIndex()));
  29. m_fileTableFilterModel->setSourceModel(m_fileTableModel.data());
  30. m_ui->fileTableView->setModel(m_fileTableFilterModel.data());
  31. connect(m_ui->fileFilteredSearchWidget,
  32. &AzQtComponents::FilteredSearchWidget::TextFilterChanged,
  33. m_fileTableFilterModel.data(),
  34. static_cast<void (QSortFilterProxyModel::*)(const QString&)>(&AssetBundlerFileTableFilterModel::FilterChanged));
  35. connect(m_ui->fileTableView->selectionModel(),
  36. &QItemSelectionModel::selectionChanged,
  37. this,
  38. &BundleListTabWidget::FileSelectionChanged);
  39. m_ui->fileTableView->setIndentation(0);
  40. m_relatedBundlesListModel.reset(new QStringListModel);
  41. m_ui->relatedBundlesListView->setModel(m_relatedBundlesListModel.data());
  42. m_ui->bundleFileContentsVerticalLayout->setContentsMargins(MarginSize, MarginSize, MarginSize, MarginSize);
  43. SetModelDataSource();
  44. }
  45. void BundleListTabWidget::Reload()
  46. {
  47. // The act of cracking open paks kicks off a DirectoryChanged event. We need to temporarily remove the Bundles
  48. // directory from our watched paths to prevent an infinite loop of events.
  49. m_guiApplicationManager->RemoveWatchedPaths(m_watchedFolders);
  50. // Reload all the bundle files
  51. m_fileTableModel->Reload(AzToolsFramework::AssetBundleSettings::GetBundleFileExtension(), m_watchedFolders, m_watchedFiles);
  52. // Update the selected row
  53. FileSelectionChanged();
  54. // Start recieving DirectoryChanged events for these folders again
  55. m_guiApplicationManager->AddWatchedPaths(m_watchedFolders);
  56. }
  57. void BundleListTabWidget::SetModelDataSource()
  58. {
  59. // Remove the current watched folders and files
  60. m_guiApplicationManager->RemoveWatchedPaths(m_watchedFolders + m_watchedFiles);
  61. // Set the new watched folder for the model
  62. m_watchedFolders.clear();
  63. m_watchedFiles.clear();
  64. m_watchedFolders.insert(m_guiApplicationManager->GetBundlesFolder().c_str());
  65. ReadScanPathsFromAssetBundlerSettings(AssetBundlingFileType::BundleFileType);
  66. m_guiApplicationManager->AddWatchedPaths(m_watchedFolders + m_watchedFiles);
  67. }
  68. AzQtComponents::TableView* BundleListTabWidget::GetFileTableView()
  69. {
  70. return m_ui->fileTableView;
  71. }
  72. QModelIndex BundleListTabWidget::GetSelectedFileTableIndex()
  73. {
  74. return m_selectedFileTableIndex;
  75. }
  76. AssetBundlerAbstractFileTableModel* BundleListTabWidget::GetFileTableModel()
  77. {
  78. return m_fileTableModel.get();
  79. }
  80. void BundleListTabWidget::SetActiveProjectLabel(const QString& labelText)
  81. {
  82. m_ui->activeProjectLabel->setText(labelText);
  83. }
  84. void BundleListTabWidget::ApplyConfig()
  85. {
  86. const GUIApplicationManager::Config& config = m_guiApplicationManager->GetConfig();
  87. m_ui->fileTableFrame->setFixedWidth(config.fileTableWidth);
  88. m_ui->fileTableView->header()->resizeSection(BundleFileListModel::Column::ColumnFileName, config.fileNameColumnWidth);
  89. }
  90. void BundleListTabWidget::FileSelectionChanged(const QItemSelection& /*selected*/, const QItemSelection& /*deselected*/)
  91. {
  92. if (m_ui->fileTableView->selectionModel()->selectedRows().size() == 0)
  93. {
  94. m_selectedFileTableIndex = QModelIndex();
  95. ClearDisplayedBundleValues();
  96. return;
  97. }
  98. m_selectedFileTableIndex = m_fileTableFilterModel->mapToSource(m_ui->fileTableView->selectionModel()->selectedRows()[0]);
  99. AZ::Outcome< BundleFileInfoPtr, void> fileInfoOutcome = m_fileTableModel->GetBundleInfo(m_selectedFileTableIndex);
  100. if (!fileInfoOutcome.IsSuccess())
  101. {
  102. ClearDisplayedBundleValues();
  103. return;
  104. }
  105. BundleFileInfoPtr fileInfoPtr = fileInfoOutcome.GetValue();
  106. m_ui->absolutePathLabel->setText(fileInfoPtr->m_absolutePath.c_str());
  107. QString sizeFormat("%1 MB");
  108. double compressedSize = (double)fileInfoPtr->m_compressedSize / BytesToMegabytes;
  109. m_ui->compressedSizeValueLabel->setText(sizeFormat.arg(compressedSize, 6, 'f', 3));
  110. bool hasRelatedBundles = !fileInfoPtr->m_relatedBundles.isEmpty();
  111. if (hasRelatedBundles)
  112. {
  113. m_relatedBundlesListModel->setStringList(fileInfoPtr->m_relatedBundles);
  114. }
  115. m_ui->relatedBundlesLabel->setVisible(hasRelatedBundles);
  116. m_ui->relatedBundlesListView->setVisible(hasRelatedBundles);
  117. }
  118. void BundleListTabWidget::ClearDisplayedBundleValues()
  119. {
  120. m_ui->absolutePathLabel->clear();
  121. m_ui->compressedSizeValueLabel->clear();
  122. m_ui->relatedBundlesLabel->setVisible(false);
  123. m_ui->relatedBundlesListView->setVisible(false);
  124. m_relatedBundlesListModel->setStringList({});
  125. }
  126. }
  127. #include <source/ui/moc_BundleListTabWidget.cpp>