Use source model data instead of filtered (#5071)

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

@ -145,10 +145,11 @@ namespace O3DE::ProjectManager
} }
} }
void GemCatalogScreen::OnGemStatusChanged(const QModelIndex& modelIndex, uint32_t numChangedDependencies) void GemCatalogScreen::OnGemStatusChanged(const QString& gemName, uint32_t numChangedDependencies)
{ {
if (m_notificationsEnabled) if (m_notificationsEnabled)
{ {
QModelIndex modelIndex = m_gemModel->FindIndexByNameString(gemName);
bool added = GemModel::IsAdded(modelIndex); bool added = GemModel::IsAdded(modelIndex);
bool dependency = GemModel::IsAddedDependency(modelIndex); bool dependency = GemModel::IsAddedDependency(modelIndex);
@ -233,7 +234,11 @@ namespace O3DE::ProjectManager
const QVector<GemInfo> allRepoGemInfos = allRepoGemInfosResult.GetValue(); const QVector<GemInfo> allRepoGemInfos = allRepoGemInfosResult.GetValue();
for (const GemInfo& gemInfo : allRepoGemInfos) for (const GemInfo& gemInfo : allRepoGemInfos)
{ {
m_gemModel->AddGem(gemInfo); // do not add gems that have already been downloaded
if (!m_gemModel->FindIndexByNameString(gemInfo.m_name).isValid())
{
m_gemModel->AddGem(gemInfo);
}
} }
} }
else else
@ -257,7 +262,8 @@ namespace O3DE::ProjectManager
GemModel::SetWasPreviouslyAdded(*m_gemModel, modelIndex, true); GemModel::SetWasPreviouslyAdded(*m_gemModel, modelIndex, true);
GemModel::SetIsAdded(*m_gemModel, modelIndex, true); GemModel::SetIsAdded(*m_gemModel, modelIndex, true);
} }
else // ${Name} is a special name used in templates and is not really an error
else if (enabledGemName != "${Name}")
{ {
AZ_Warning("ProjectManager::GemCatalog", false, AZ_Warning("ProjectManager::GemCatalog", false,
"Cannot find entry for gem with name '%s'. The CMake target name probably does not match the specified name in the gem.json.", "Cannot find entry for gem with name '%s'. The CMake target name probably does not match the specified name in the gem.json.",

@ -46,7 +46,7 @@ namespace O3DE::ProjectManager
DownloadController* GetDownloadController() const { return m_downloadController; } DownloadController* GetDownloadController() const { return m_downloadController; }
public slots: public slots:
void OnGemStatusChanged(const QModelIndex& modelIndex, uint32_t numChangedDependencies); void OnGemStatusChanged(const QString& gemName, uint32_t numChangedDependencies);
void OnAddGemClicked(); void OnAddGemClicked();
protected: protected:

@ -276,9 +276,11 @@ namespace O3DE::ProjectManager
void GemModel::SetIsAdded(QAbstractItemModel& model, const QModelIndex& modelIndex, bool isAdded) void GemModel::SetIsAdded(QAbstractItemModel& model, const QModelIndex& modelIndex, bool isAdded)
{ {
// get the gemName first, because the modelIndex data change after adding because of filters
QString gemName = modelIndex.data(RoleName).toString();
model.setData(modelIndex, isAdded, RoleIsAdded); model.setData(modelIndex, isAdded, RoleIsAdded);
UpdateDependencies(model, modelIndex); UpdateDependencies(model, gemName, isAdded);
} }
bool GemModel::HasDependentGems(const QModelIndex& modelIndex) const bool GemModel::HasDependentGems(const QModelIndex& modelIndex) const
@ -294,15 +296,17 @@ namespace O3DE::ProjectManager
return false; return false;
} }
void GemModel::UpdateDependencies(QAbstractItemModel& model, const QModelIndex& modelIndex) void GemModel::UpdateDependencies(QAbstractItemModel& model, const QString& gemName, bool isAdded)
{ {
GemModel* gemModel = GetSourceModel(&model); GemModel* gemModel = GetSourceModel(&model);
AZ_Assert(gemModel, "Failed to obtain GemModel"); AZ_Assert(gemModel, "Failed to obtain GemModel");
QModelIndex modelIndex = gemModel->FindIndexByNameString(gemName);
QVector<QModelIndex> dependencies = gemModel->GatherGemDependencies(modelIndex); QVector<QModelIndex> dependencies = gemModel->GatherGemDependencies(modelIndex);
uint32_t numChangedDependencies = 0; uint32_t numChangedDependencies = 0;
if (IsAdded(modelIndex)) if (isAdded)
{ {
for (const QModelIndex& dependency : dependencies) for (const QModelIndex& dependency : dependencies)
{ {
@ -324,7 +328,7 @@ namespace O3DE::ProjectManager
bool hasDependentGems = gemModel->HasDependentGems(modelIndex); bool hasDependentGems = gemModel->HasDependentGems(modelIndex);
if (IsAddedDependency(modelIndex) != hasDependentGems) if (IsAddedDependency(modelIndex) != hasDependentGems)
{ {
SetIsAddedDependency(model, modelIndex, hasDependentGems); SetIsAddedDependency(*gemModel, modelIndex, hasDependentGems);
} }
for (const QModelIndex& dependency : dependencies) for (const QModelIndex& dependency : dependencies)
@ -343,7 +347,7 @@ namespace O3DE::ProjectManager
} }
} }
gemModel->emit gemStatusChanged(modelIndex, numChangedDependencies); gemModel->emit gemStatusChanged(gemName, numChangedDependencies);
} }
void GemModel::SetIsAddedDependency(QAbstractItemModel& model, const QModelIndex& modelIndex, bool isAdded) void GemModel::SetIsAddedDependency(QAbstractItemModel& model, const QModelIndex& modelIndex, bool isAdded)

@ -64,7 +64,7 @@ namespace O3DE::ProjectManager
static bool NeedsToBeAdded(const QModelIndex& modelIndex, bool includeDependencies = false); static bool NeedsToBeAdded(const QModelIndex& modelIndex, bool includeDependencies = false);
static bool NeedsToBeRemoved(const QModelIndex& modelIndex, bool includeDependencies = false); static bool NeedsToBeRemoved(const QModelIndex& modelIndex, bool includeDependencies = false);
static bool HasRequirement(const QModelIndex& modelIndex); static bool HasRequirement(const QModelIndex& modelIndex);
static void UpdateDependencies(QAbstractItemModel& model, const QModelIndex& modelIndex); static void UpdateDependencies(QAbstractItemModel& model, const QString& gemName, bool isAdded);
static void SetDownloadStatus(QAbstractItemModel& model, const QModelIndex& modelIndex, GemInfo::DownloadStatus status); static void SetDownloadStatus(QAbstractItemModel& model, const QModelIndex& modelIndex, GemInfo::DownloadStatus status);
bool DoGemsToBeAddedHaveRequirements() const; bool DoGemsToBeAddedHaveRequirements() const;
@ -78,7 +78,7 @@ namespace O3DE::ProjectManager
int TotalAddedGems(bool includeDependencies = false) const; int TotalAddedGems(bool includeDependencies = false) const;
signals: signals:
void gemStatusChanged(const QModelIndex& modelIndex, uint32_t numChangedDependencies); void gemStatusChanged(const QString& gemName, uint32_t numChangedDependencies);
private: private:
void FindGemDisplayNamesByNameStrings(QStringList& inOutGemNames); void FindGemDisplayNamesByNameStrings(QStringList& inOutGemNames);

Loading…
Cancel
Save