Code readability improvements

Signed-off-by: AMZN-Phil <pconroy@amazon.com>
monroegm-disable-blank-issue-2
AMZN-Phil 4 years ago
parent 393f08fc4b
commit c6e77f8e32

@ -45,7 +45,7 @@ namespace O3DE::ProjectManager
if (m_gemNames.size() == 1) if (m_gemNames.size() == 1)
{ {
m_worker->SetGemToDownload(m_gemNames[0], false); m_worker->SetGemToDownload(m_gemNames.front(), false);
m_workerThread.start(); m_workerThread.start();
} }
} }
@ -72,7 +72,7 @@ namespace O3DE::ProjectManager
void DownloadController::UpdateUIProgress(int progress) void DownloadController::UpdateUIProgress(int progress)
{ {
m_lastProgress = progress; m_lastProgress = progress;
emit GemDownloadProgress(*m_gemNames.begin(), progress); emit GemDownloadProgress(m_gemNames.front(), progress);
} }
void DownloadController::HandleResults(const QString& result) void DownloadController::HandleResults(const QString& result)
@ -85,13 +85,13 @@ namespace O3DE::ProjectManager
succeeded = false; succeeded = false;
} }
QString gemName = *m_gemNames.begin(); QString gemName = m_gemNames.front();
m_gemNames.erase(m_gemNames.begin()); m_gemNames.erase(m_gemNames.begin());
emit Done(gemName, succeeded); emit Done(gemName, succeeded);
if (!m_gemNames.empty()) if (!m_gemNames.empty())
{ {
emit StartGemDownload(m_gemNames[0]); emit StartGemDownload(m_gemNames.front());
} }
else else
{ {

@ -214,9 +214,9 @@ namespace O3DE::ProjectManager
// Setup gem download rows for gems that are already in the queue // Setup gem download rows for gems that are already in the queue
const AZStd::vector<QString>& downloadQueue = m_downloadController->GetDownloadQueue(); const AZStd::vector<QString>& 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) void CartOverlayWidget::GemDownloadAdded(const QString& gemName)
{ {
// Containing widget for the current download item
QWidget* newGemDownloadWidget = new QWidget(); QWidget* newGemDownloadWidget = new QWidget();
newGemDownloadWidget->setObjectName(gemName); newGemDownloadWidget->setObjectName(gemName);
QVBoxLayout* downloadingGemLayout = new QVBoxLayout(); QVBoxLayout* downloadingGemLayout = new QVBoxLayout(newGemDownloadWidget);
newGemDownloadWidget->setLayout(downloadingGemLayout); 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); nameProgressLayout->addWidget(newTag);
QLabel* progress = new QLabel(tr("Queued")); QLabel* progress = new QLabel(tr("Queued"), newGemDownloadWidget);
progress->setObjectName("DownloadProgressLabel"); progress->setObjectName("DownloadProgressLabel");
nameProgressLayout->addWidget(progress); nameProgressLayout->addWidget(progress);
QSpacerItem* spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); nameProgressLayout->addStretch();
nameProgressLayout->addSpacerItem(spacer); QLabel* cancelText = new QLabel(tr("<a href=\"%1\">Cancel</a>").arg(gemName), newGemDownloadWidget);
QLabel* cancelText = new QLabel(QString("<a href=\"%1\">Cancel</a>").arg(gemName));
cancelText->setTextInteractionFlags(Qt::LinksAccessibleByMouse); cancelText->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
connect(cancelText, &QLabel::linkActivated, this, &CartOverlayWidget::OnCancelDownloadActivated); connect(cancelText, &QLabel::linkActivated, this, &CartOverlayWidget::OnCancelDownloadActivated);
nameProgressLayout->addWidget(cancelText); nameProgressLayout->addWidget(cancelText);
downloadingGemLayout->addLayout(nameProgressLayout); downloadingGemLayout->addLayout(nameProgressLayout);
QProgressBar* downloadProgessBar = new QProgressBar();
// Progress bar
QProgressBar* downloadProgessBar = new QProgressBar(newGemDownloadWidget);
downloadProgessBar->setObjectName("DownloadProgressBar"); downloadProgessBar->setObjectName("DownloadProgressBar");
downloadingGemLayout->addWidget(downloadProgessBar); downloadingGemLayout->addWidget(downloadProgessBar);
downloadProgessBar->setValue(0); downloadProgessBar->setValue(0);
@ -265,31 +269,22 @@ namespace O3DE::ProjectManager
void CartOverlayWidget::GemDownloadRemoved(const QString& gemName) void CartOverlayWidget::GemDownloadRemoved(const QString& gemName)
{ {
QWidget* gemToRemove = m_downloadingListWidget->findChild<QWidget*>(gemName); QWidget* gemToRemove = m_downloadingListWidget->findChild<QWidget*>(gemName);
QLayout* gemToRemoveLayout = gemToRemove ? gemToRemove->layout() : nullptr; if (gemToRemove)
if (gemToRemoveLayout)
{ {
QLayoutItem* rowLayoutItem = nullptr;
while ((rowLayoutItem = gemToRemoveLayout->layout()->takeAt(0)) != nullptr)
{
rowLayoutItem->widget()->deleteLater();
}
gemToRemoveLayout->layout()->deleteLater();
gemToRemove->deleteLater(); gemToRemove->deleteLater();
} }
const AZStd::vector<QString>& downloadQueue = m_downloadController->GetDownloadQueue();
if (m_downloadController->IsDownloadQueueEmpty()) if (m_downloadController->IsDownloadQueueEmpty())
{ {
m_downloadSectionWidget->hide(); m_downloadSectionWidget->hide();
} }
else else
{ {
size_t downloadQueueSize = m_downloadController->GetDownloadQueue().size();
QLabel* numDownloads = m_downloadingListWidget->findChild<QLabel*>("NumDownloadsInProgressLabel"); QLabel* numDownloads = m_downloadingListWidget->findChild<QLabel*>("NumDownloadsInProgressLabel");
numDownloads->setText(QString("%1 %2") numDownloads->setText(QString("%1 %2")
.arg(downloadQueue.size()) .arg(downloadQueueSize)
.arg(downloadQueue.size() == 1 ? tr("download in progress...") : tr("downloads in progress..."))); .arg(downloadQueueSize == 1 ? tr("download in progress...") : tr("downloads in progress...")));
} }
} }

@ -175,7 +175,7 @@ namespace O3DE::ProjectManager
if (added && GemModel::GetDownloadStatus(modelIndex) == GemInfo::DownloadStatus::NotDownloaded) if (added && GemModel::GetDownloadStatus(modelIndex) == GemInfo::DownloadStatus::NotDownloaded)
{ {
m_downloadController->AddGemDownload(GemModel::GetName(modelIndex)); 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);
} }
} }

Loading…
Cancel
Save