From c6e77f8e32c35d33fa639a00c6aea819b360ffbc Mon Sep 17 00:00:00 2001 From: AMZN-Phil Date: Fri, 5 Nov 2021 14:21:10 -0700 Subject: [PATCH] Code readability improvements Signed-off-by: AMZN-Phil --- .../Source/DownloadController.cpp | 8 ++-- .../GemCatalog/GemCatalogHeaderWidget.cpp | 41 ++++++++----------- .../Source/GemCatalog/GemCatalogScreen.cpp | 2 +- 3 files changed, 23 insertions(+), 28 deletions(-) diff --git a/Code/Tools/ProjectManager/Source/DownloadController.cpp b/Code/Tools/ProjectManager/Source/DownloadController.cpp index 00a7db5318..6326b2fc11 100644 --- a/Code/Tools/ProjectManager/Source/DownloadController.cpp +++ b/Code/Tools/ProjectManager/Source/DownloadController.cpp @@ -45,7 +45,7 @@ namespace O3DE::ProjectManager if (m_gemNames.size() == 1) { - m_worker->SetGemToDownload(m_gemNames[0], false); + m_worker->SetGemToDownload(m_gemNames.front(), false); m_workerThread.start(); } } @@ -72,7 +72,7 @@ namespace O3DE::ProjectManager void DownloadController::UpdateUIProgress(int progress) { m_lastProgress = progress; - emit GemDownloadProgress(*m_gemNames.begin(), progress); + emit GemDownloadProgress(m_gemNames.front(), progress); } void DownloadController::HandleResults(const QString& result) @@ -85,13 +85,13 @@ namespace O3DE::ProjectManager succeeded = false; } - QString gemName = *m_gemNames.begin(); + QString gemName = m_gemNames.front(); m_gemNames.erase(m_gemNames.begin()); emit Done(gemName, succeeded); if (!m_gemNames.empty()) { - emit StartGemDownload(m_gemNames[0]); + emit StartGemDownload(m_gemNames.front()); } else { diff --git a/Code/Tools/ProjectManager/Source/GemCatalog/GemCatalogHeaderWidget.cpp b/Code/Tools/ProjectManager/Source/GemCatalog/GemCatalogHeaderWidget.cpp index cfe69283ff..b0729c0047 100644 --- a/Code/Tools/ProjectManager/Source/GemCatalog/GemCatalogHeaderWidget.cpp +++ b/Code/Tools/ProjectManager/Source/GemCatalog/GemCatalogHeaderWidget.cpp @@ -214,9 +214,9 @@ namespace O3DE::ProjectManager // Setup gem download rows for gems that are already in the queue const AZStd::vector& downloadQueue = m_downloadController->GetDownloadQueue(); - for (int downloadingGemNumber = 0; downloadingGemNumber < downloadQueue.size(); ++downloadingGemNumber) + for (const QString& gemName : downloadQueue) { - GemDownloadAdded(downloadQueue[downloadingGemNumber]); + GemDownloadAdded(gemName); } } @@ -229,24 +229,28 @@ namespace O3DE::ProjectManager void CartOverlayWidget::GemDownloadAdded(const QString& gemName) { + // Containing widget for the current download item QWidget* newGemDownloadWidget = new QWidget(); newGemDownloadWidget->setObjectName(gemName); - QVBoxLayout* downloadingGemLayout = new QVBoxLayout(); + QVBoxLayout* downloadingGemLayout = new QVBoxLayout(newGemDownloadWidget); newGemDownloadWidget->setLayout(downloadingGemLayout); - QHBoxLayout* nameProgressLayout = new QHBoxLayout(); - TagWidget* newTag = new TagWidget(gemName); + + // Gem name, progress string, cancel + QHBoxLayout* nameProgressLayout = new QHBoxLayout(newGemDownloadWidget); + TagWidget* newTag = new TagWidget(gemName, newGemDownloadWidget); nameProgressLayout->addWidget(newTag); - QLabel* progress = new QLabel(tr("Queued")); + QLabel* progress = new QLabel(tr("Queued"), newGemDownloadWidget); progress->setObjectName("DownloadProgressLabel"); nameProgressLayout->addWidget(progress); - QSpacerItem* spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); - nameProgressLayout->addSpacerItem(spacer); - QLabel* cancelText = new QLabel(QString("Cancel").arg(gemName)); + nameProgressLayout->addStretch(); + QLabel* cancelText = new QLabel(tr("Cancel").arg(gemName), newGemDownloadWidget); cancelText->setTextInteractionFlags(Qt::LinksAccessibleByMouse); connect(cancelText, &QLabel::linkActivated, this, &CartOverlayWidget::OnCancelDownloadActivated); nameProgressLayout->addWidget(cancelText); downloadingGemLayout->addLayout(nameProgressLayout); - QProgressBar* downloadProgessBar = new QProgressBar(); + + // Progress bar + QProgressBar* downloadProgessBar = new QProgressBar(newGemDownloadWidget); downloadProgessBar->setObjectName("DownloadProgressBar"); downloadingGemLayout->addWidget(downloadProgessBar); downloadProgessBar->setValue(0); @@ -265,31 +269,22 @@ namespace O3DE::ProjectManager void CartOverlayWidget::GemDownloadRemoved(const QString& gemName) { QWidget* gemToRemove = m_downloadingListWidget->findChild(gemName); - QLayout* gemToRemoveLayout = gemToRemove ? gemToRemove->layout() : nullptr; - - if (gemToRemoveLayout) + if (gemToRemove) { - QLayoutItem* rowLayoutItem = nullptr; - while ((rowLayoutItem = gemToRemoveLayout->layout()->takeAt(0)) != nullptr) - { - rowLayoutItem->widget()->deleteLater(); - } - gemToRemoveLayout->layout()->deleteLater(); gemToRemove->deleteLater(); } - const AZStd::vector& downloadQueue = m_downloadController->GetDownloadQueue(); - if (m_downloadController->IsDownloadQueueEmpty()) { m_downloadSectionWidget->hide(); } else { + size_t downloadQueueSize = m_downloadController->GetDownloadQueue().size(); QLabel* numDownloads = m_downloadingListWidget->findChild("NumDownloadsInProgressLabel"); numDownloads->setText(QString("%1 %2") - .arg(downloadQueue.size()) - .arg(downloadQueue.size() == 1 ? tr("download in progress...") : tr("downloads in progress..."))); + .arg(downloadQueueSize) + .arg(downloadQueueSize == 1 ? tr("download in progress...") : tr("downloads in progress..."))); } } diff --git a/Code/Tools/ProjectManager/Source/GemCatalog/GemCatalogScreen.cpp b/Code/Tools/ProjectManager/Source/GemCatalog/GemCatalogScreen.cpp index 9f5d4a70f2..f3e1da011a 100644 --- a/Code/Tools/ProjectManager/Source/GemCatalog/GemCatalogScreen.cpp +++ b/Code/Tools/ProjectManager/Source/GemCatalog/GemCatalogScreen.cpp @@ -175,7 +175,7 @@ namespace O3DE::ProjectManager if (added && GemModel::GetDownloadStatus(modelIndex) == GemInfo::DownloadStatus::NotDownloaded) { m_downloadController->AddGemDownload(GemModel::GetName(modelIndex)); - GemModel::SetDownloadStatus(*m_proxyModel, modelIndex, GemInfo::DownloadStatus::Downloading); + GemModel::SetDownloadStatus(*m_proxyModel, m_proxyModel->mapFromSource(modelIndex), GemInfo::DownloadStatus::Downloading); } }