Fully Replaces Remote Gems in Model and Selects Them When Downloading and Deleting (#5593)

Signed-off-by: Alex Peterson <26804013+AMZN-alexpete@users.noreply.github.com>
monroegm-disable-blank-issue-2
AMZN-nggieber 4 years ago committed by GitHub
parent 5ec5824849
commit 76b7e73f6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -126,7 +126,8 @@ namespace O3DE::ProjectManager
// Select the first entry after everything got correctly sized // Select the first entry after everything got correctly sized
QTimer::singleShot(200, [=]{ QTimer::singleShot(200, [=]{
QModelIndex firstModelIndex = m_gemModel->index(0, 0); QModelIndex firstModelIndex = m_gemModel->index(0, 0);
m_gemModel->GetSelectionModel()->select(firstModelIndex, QItemSelectionModel::ClearAndSelect); QModelIndex proxyIndex = m_proxyModel->mapFromSource(firstModelIndex);
m_proxyModel->GetSelectionModel()->setCurrentIndex(proxyIndex, QItemSelectionModel::ClearAndSelect);
}); });
} }
@ -209,7 +210,7 @@ namespace O3DE::ProjectManager
const bool gemFound = gemInfoHash.contains(gemName); const bool gemFound = gemInfoHash.contains(gemName);
if (!gemFound && !m_gemModel->IsAdded(index) && !m_gemModel->IsAddedDependency(index)) if (!gemFound && !m_gemModel->IsAdded(index) && !m_gemModel->IsAddedDependency(index))
{ {
m_gemModel->removeRow(i); m_gemModel->RemoveGem(index);
} }
else else
{ {
@ -239,7 +240,7 @@ namespace O3DE::ProjectManager
m_filterWidget->ResetAllFilters(); m_filterWidget->ResetAllFilters();
// Reselect the same selection to proc UI updates // Reselect the same selection to proc UI updates
m_proxyModel->GetSelectionModel()->select(m_proxyModel->GetSelectionModel()->selection(), QItemSelectionModel::Select); m_proxyModel->GetSelectionModel()->setCurrentIndex(m_proxyModel->GetSelectionModel()->currentIndex(), QItemSelectionModel::Select);
} }
void GemCatalogScreen::OnGemStatusChanged(const QString& gemName, uint32_t numChangedDependencies) void GemCatalogScreen::OnGemStatusChanged(const QString& gemName, uint32_t numChangedDependencies)
@ -268,7 +269,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, m_proxyModel->mapFromSource(modelIndex), GemInfo::DownloadStatus::Downloading); GemModel::SetDownloadStatus(*m_gemModel, modelIndex, GemInfo::DownloadStatus::Downloading);
} }
} }
@ -300,7 +301,7 @@ namespace O3DE::ProjectManager
} }
QModelIndex proxyIndex = m_proxyModel->mapFromSource(modelIndex); QModelIndex proxyIndex = m_proxyModel->mapFromSource(modelIndex);
m_proxyModel->GetSelectionModel()->select(proxyIndex, QItemSelectionModel::ClearAndSelect); m_proxyModel->GetSelectionModel()->setCurrentIndex(proxyIndex, QItemSelectionModel::ClearAndSelect);
m_gemListView->scrollTo(proxyIndex); m_gemListView->scrollTo(proxyIndex);
} }
@ -362,6 +363,9 @@ namespace O3DE::ProjectManager
{ {
const QString selectedGemPath = m_gemModel->GetPath(modelIndex); const QString selectedGemPath = m_gemModel->GetPath(modelIndex);
// Remove gem from gems to be added
GemModel::SetIsAdded(*m_gemModel, modelIndex, false);
// Unregister the gem // Unregister the gem
auto unregisterResult = PythonBindingsInterface::Get()->UnregisterGem(selectedGemPath); auto unregisterResult = PythonBindingsInterface::Get()->UnregisterGem(selectedGemPath);
if (!unregisterResult) if (!unregisterResult)
@ -370,8 +374,10 @@ namespace O3DE::ProjectManager
} }
else else
{ {
const QString selectedGemName = m_gemModel->GetName(modelIndex);
// Remove gem from model // Remove gem from model
m_gemModel->removeRow(modelIndex.row()); m_gemModel->RemoveGem(modelIndex);
// Delete uninstalled gem directory // Delete uninstalled gem directory
if (!ProjectUtils::DeleteProjectFiles(selectedGemPath, /*force*/true)) if (!ProjectUtils::DeleteProjectFiles(selectedGemPath, /*force*/true))
@ -382,6 +388,11 @@ namespace O3DE::ProjectManager
// Show undownloaded remote gem again // Show undownloaded remote gem again
Refresh(); Refresh();
// Select remote gem
QModelIndex remoteGemIndex = m_gemModel->FindIndexByNameString(selectedGemName);
QModelIndex proxyIndex = m_proxyModel->mapFromSource(remoteGemIndex);
m_proxyModel->GetSelectionModel()->setCurrentIndex(proxyIndex, QItemSelectionModel::ClearAndSelect);
} }
} }
} }
@ -564,7 +575,8 @@ namespace O3DE::ProjectManager
if (succeeded) if (succeeded)
{ {
// refresh the information for downloaded gems // refresh the information for downloaded gems
const AZ::Outcome<QVector<GemInfo>, AZStd::string>& allGemInfosResult = PythonBindingsInterface::Get()->GetAllGemInfos(m_projectPath); const AZ::Outcome<QVector<GemInfo>, AZStd::string>& allGemInfosResult =
PythonBindingsInterface::Get()->GetAllGemInfos(m_projectPath);
if (allGemInfosResult.IsSuccess()) if (allGemInfosResult.IsSuccess())
{ {
// we should find the gem name now in all gem infos // we should find the gem name now in all gem infos
@ -572,15 +584,33 @@ namespace O3DE::ProjectManager
{ {
if (gemInfo.m_name == gemName) if (gemInfo.m_name == gemName)
{ {
QModelIndex index = m_gemModel->FindIndexByNameString(gemName); QModelIndex oldIndex = m_gemModel->FindIndexByNameString(gemName);
if (index.isValid()) if (oldIndex.isValid())
{
// Check if old gem is selected
bool oldGemSelected = false;
if (m_gemModel->GetSelectionModel()->currentIndex() == oldIndex)
{ {
m_proxyModel->setData(m_proxyModel->mapFromSource(index), GemInfo::DownloadSuccessful, GemModel::RoleDownloadStatus); oldGemSelected = true;
m_gemModel->setData(index, gemInfo.m_path, GemModel::RolePath);
m_gemModel->setData(index, gemInfo.m_path, GemModel::RoleDirectoryLink);
} }
return; // Remove old remote gem
m_gemModel->RemoveGem(oldIndex);
// Add new downloaded version of gem
QModelIndex newIndex = m_gemModel->AddGem(gemInfo);
GemModel::SetDownloadStatus(*m_gemModel, newIndex, GemInfo::DownloadSuccessful);
GemModel::SetIsAdded(*m_gemModel, newIndex, true);
// Select new version of gem if it was previously selected
if (oldGemSelected)
{
QModelIndex proxyIndex = m_proxyModel->mapFromSource(newIndex);
m_proxyModel->GetSelectionModel()->setCurrentIndex(proxyIndex, QItemSelectionModel::ClearAndSelect);
}
}
break;
} }
} }
} }
@ -590,7 +620,7 @@ namespace O3DE::ProjectManager
QModelIndex index = m_gemModel->FindIndexByNameString(gemName); QModelIndex index = m_gemModel->FindIndexByNameString(gemName);
if (index.isValid()) if (index.isValid())
{ {
m_proxyModel->setData(m_proxyModel->mapFromSource(index), GemInfo::DownloadFailed, GemModel::RoleDownloadStatus); GemModel::SetDownloadStatus(*m_gemModel, index, GemInfo::DownloadFailed);
} }
} }
} }

@ -26,14 +26,14 @@ namespace O3DE::ProjectManager
return m_selectionModel; return m_selectionModel;
} }
void GemModel::AddGem(const GemInfo& gemInfo) QModelIndex GemModel::AddGem(const GemInfo& gemInfo)
{ {
if (FindIndexByNameString(gemInfo.m_name).isValid()) if (FindIndexByNameString(gemInfo.m_name).isValid())
{ {
// do not add gems with duplicate names // do not add gems with duplicate names
// this can happen by mistake or when a gem repo has a gem with the same name as a local gem // this can happen by mistake or when a gem repo has a gem with the same name as a local gem
AZ_TracePrintf("GemModel", "Ignoring duplicate gem: %s", gemInfo.m_name.toUtf8().constData()); AZ_TracePrintf("GemModel", "Ignoring duplicate gem: %s", gemInfo.m_name.toUtf8().constData());
return; return QModelIndex();
} }
QStandardItem* item = new QStandardItem(); QStandardItem* item = new QStandardItem();
@ -67,6 +67,22 @@ namespace O3DE::ProjectManager
const QModelIndex modelIndex = index(rowCount()-1, 0); const QModelIndex modelIndex = index(rowCount()-1, 0);
m_nameToIndexMap[gemInfo.m_name] = modelIndex; m_nameToIndexMap[gemInfo.m_name] = modelIndex;
return modelIndex;
}
void GemModel::RemoveGem(const QModelIndex& modelIndex)
{
removeRow(modelIndex.row());
}
void GemModel::RemoveGem(const QString& gemName)
{
auto nameFind = m_nameToIndexMap.find(gemName);
if (nameFind != m_nameToIndexMap.end())
{
removeRow(nameFind->row());
}
} }
void GemModel::Clear() void GemModel::Clear()
@ -395,7 +411,7 @@ namespace O3DE::ProjectManager
{ {
if (index.isValid()) if (index.isValid())
{ {
GetSelectionModel()->select(index, QItemSelectionModel::ClearAndSelect); GetSelectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);
break; break;
} }
} }

@ -55,7 +55,9 @@ namespace O3DE::ProjectManager
RoleRepoUri RoleRepoUri
}; };
void AddGem(const GemInfo& gemInfo); QModelIndex AddGem(const GemInfo& gemInfo);
void RemoveGem(const QModelIndex& modelIndex);
void RemoveGem(const QString& gemName);
void Clear(); void Clear();
void UpdateGemDependencies(); void UpdateGemDependencies();

@ -75,7 +75,7 @@ namespace O3DE::ProjectManager
// Select the first entry after everything got correctly sized // Select the first entry after everything got correctly sized
QTimer::singleShot(200, [=]{ QTimer::singleShot(200, [=]{
QModelIndex firstModelIndex = m_gemRepoListView->model()->index(0,0); QModelIndex firstModelIndex = m_gemRepoListView->model()->index(0,0);
m_gemRepoListView->selectionModel()->select(firstModelIndex, QItemSelectionModel::ClearAndSelect); m_gemRepoListView->selectionModel()->setCurrentIndex(firstModelIndex, QItemSelectionModel::ClearAndSelect);
}); });
} }

Loading…
Cancel
Save