Project Manager Gem Dependencies (#4132)

* Fix engine API change and add gem dependencies

Signed-off-by: AMZN-alexpete <26804013+AMZN-alexpete@users.noreply.github.com>

* Add GemCatalog dependency test

Signed-off-by: AMZN-alexpete <26804013+AMZN-alexpete@users.noreply.github.com>

* Clarify display name and fix missing const

Signed-off-by: AMZN-alexpete <26804013+AMZN-alexpete@users.noreply.github.com>

* Moving a couple helper functions into private scope

Signed-off-by: AMZN-alexpete <26804013+AMZN-alexpete@users.noreply.github.com>

* Update gem count when unselecting a gem #4074

This addresses the following issue https://github.com/o3de/o3de/issues/4074

Signed-off-by: AMZN-alexpete <26804013+AMZN-alexpete@users.noreply.github.com>

* Active/Inactive filter and dependency tooltips

Signed-off-by: AMZN-alexpete <26804013+AMZN-alexpete@users.noreply.github.com>

* Accessors for previously added and dependencies

Signed-off-by: AMZN-alexpete <26804013+AMZN-alexpete@users.noreply.github.com>

* Cart displays gem dependency changes

Signed-off-by: AMZN-alexpete <26804013+AMZN-alexpete@users.noreply.github.com>

* Shorten titles to fit in summary popup

Signed-off-by: AMZN-alexpete <26804013+AMZN-alexpete@users.noreply.github.com>

* Remove QString::number

Signed-off-by: AMZN-alexpete <26804013+AMZN-alexpete@users.noreply.github.com>

* Remove extra space

Signed-off-by: AMZN-alexpete <26804013+AMZN-alexpete@users.noreply.github.com>

* Consolidate source model accesor helpers

Signed-off-by: AMZN-alexpete <26804013+AMZN-alexpete@users.noreply.github.com>

* Addressing minor feedback

Signed-off-by: AMZN-alexpete <26804013+AMZN-alexpete@users.noreply.github.com>

* Remove unused local variable

Signed-off-by: AMZN-alexpete <26804013+AMZN-alexpete@users.noreply.github.com>
This commit is contained in:
Alex Peterson
2021-09-24 09:01:17 -07:00
committed by GitHub
parent 4c0796f11e
commit 43244d30e1
18 changed files with 627 additions and 188 deletions
@@ -8,9 +8,14 @@
#include <GemCatalog/GemItemDelegate.h>
#include <GemCatalog/GemModel.h>
#include <GemCatalog/GemSortFilterProxyModel.h>
#include <QEvent>
#include <QAbstractItemView>
#include <QPainter>
#include <QMouseEvent>
#include <QHelpEvent>
#include <QToolTip>
#include <QHoverEvent>
namespace O3DE::ProjectManager
{
@@ -149,8 +154,7 @@ namespace O3DE::ProjectManager
return true;
}
}
if (event->type() == QEvent::MouseButtonPress)
else if (event->type() == QEvent::MouseButtonPress )
{
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
@@ -169,6 +173,69 @@ namespace O3DE::ProjectManager
return QStyledItemDelegate::editorEvent(event, model, option, modelIndex);
}
QString GetGemNameList(const QVector<QModelIndex> modelIndices)
{
QString gemNameList;
for (int i = 0; i < modelIndices.size(); ++i)
{
if (!gemNameList.isEmpty())
{
if (i == modelIndices.size() - 1)
{
gemNameList.append(" and ");
}
else
{
gemNameList.append(", ");
}
}
gemNameList.append(GemModel::GetDisplayName(modelIndices[i]));
}
return gemNameList;
}
bool GemItemDelegate::helpEvent(QHelpEvent* event, QAbstractItemView* view, const QStyleOptionViewItem& option, const QModelIndex& index)
{
if (event->type() == QEvent::ToolTip)
{
QRect fullRect, itemRect, contentRect;
CalcRects(option, fullRect, itemRect, contentRect);
const QRect buttonRect = CalcButtonRect(contentRect);
if (buttonRect.contains(event->pos()))
{
if (!QToolTip::isVisible())
{
if(GemModel::IsAddedDependency(index) && !GemModel::IsAdded(index))
{
const GemModel* gemModel = GemModel::GetSourceModel(index.model());
AZ_Assert(gemModel, "Failed to obtain GemModel");
// we only want to display the gems that must be de-selected to automatically
// disable this dependency, so don't include any that haven't been selected (added)
constexpr bool addedOnly = true;
QVector<QModelIndex> dependents = gemModel->GatherDependentGems(index, addedOnly);
QString nameList = GetGemNameList(dependents);
if (!nameList.isEmpty())
{
QToolTip::showText(event->globalPos(), tr("This gem is a dependency of %1.\nTo disable this gem, first disable %1.").arg(nameList));
}
}
}
return true;
}
else if (QToolTip::isVisible())
{
QToolTip::hideText();
event->ignore();
return true;
}
}
return QStyledItemDelegate::helpEvent(event, view, option, index);
}
void GemItemDelegate::CalcRects(const QStyleOptionViewItem& option, QRect& outFullRect, QRect& outItemRect, QRect& outContentRect) const
{
outFullRect = QRect(option.rect);
@@ -260,14 +327,20 @@ namespace O3DE::ProjectManager
const QRect buttonRect = CalcButtonRect(contentRect);
QPoint circleCenter;
const bool isAdded = GemModel::IsAdded(modelIndex);
if (isAdded)
if (GemModel::IsAdded(modelIndex))
{
painter->setBrush(m_buttonEnabledColor);
painter->setPen(m_buttonEnabledColor);
circleCenter = buttonRect.center() + QPoint(buttonRect.width() / 2 - s_buttonBorderRadius + 1, 1);
}
else if (GemModel::IsAddedDependency(modelIndex))
{
painter->setBrush(m_buttonImplicitlyEnabledColor);
painter->setPen(m_buttonImplicitlyEnabledColor);
circleCenter = buttonRect.center() + QPoint(buttonRect.width() / 2 - s_buttonBorderRadius + 1, 1);
}
else
{
circleCenter = buttonRect.center() + QPoint(-buttonRect.width() / 2 + s_buttonBorderRadius, 1);