chore: simplify logic for handling expanding entries in Outliner (#5219) (#5394)

* chore: simplify logic for handling expanding entries in Outliner

Signed-off-by: Michael Pollind <mpollind@gmail.com>

* bugfix: fix bottom border for collapsed prefabs.

issue: https://github.com/o3de/o3de/issues/5219

Signed-off-by: Michael Pollind <mpollind@gmail.com>

* chore: revert changes for expanding entities

Signed-off-by: Michael Pollind <mpollind@gmail.com>
monroegm-disable-blank-issue-2
Michael Pollind 4 years ago committed by GitHub
parent 79f4fee960
commit d7b3d33711
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -80,7 +80,6 @@ namespace AzToolsFramework
EntityOutlinerListModel::EntityOutlinerListModel(QObject* parent) EntityOutlinerListModel::EntityOutlinerListModel(QObject* parent)
: QAbstractItemModel(parent) : QAbstractItemModel(parent)
, m_entitySelectQueue() , m_entitySelectQueue()
, m_entityExpandQueue()
, m_entityChangeQueue() , m_entityChangeQueue()
, m_entityChangeQueued(false) , m_entityChangeQueued(false)
, m_entityLayoutQueued(false) , m_entityLayoutQueued(false)
@ -1275,7 +1274,6 @@ namespace AzToolsFramework
void EntityOutlinerListModel::QueueEntityToExpand(AZ::EntityId entityId, bool expand) void EntityOutlinerListModel::QueueEntityToExpand(AZ::EntityId entityId, bool expand)
{ {
m_entityExpansionState[entityId] = expand; m_entityExpansionState[entityId] = expand;
m_entityExpandQueue.insert(entityId);
QueueEntityUpdate(entityId); QueueEntityUpdate(entityId);
} }
@ -1300,16 +1298,7 @@ namespace AzToolsFramework
{ {
return; return;
} }
{
AZ_PROFILE_SCOPE(Editor, "EntityOutlinerListModel::ProcessEntityUpdates:ExpandQueue");
for (auto entityId : m_entityExpandQueue)
{
emit ExpandEntity(entityId, IsExpanded(entityId));
};
m_entityExpandQueue.clear();
}
{ {
AZ_PROFILE_SCOPE(Editor, "EntityOutlinerListModel::ProcessEntityUpdates:SelectQueue"); AZ_PROFILE_SCOPE(Editor, "EntityOutlinerListModel::ProcessEntityUpdates:SelectQueue");
for (auto entityId : m_entitySelectQueue) for (auto entityId : m_entitySelectQueue)

@ -156,7 +156,6 @@ namespace AzToolsFramework
void ProcessEntityUpdates(); void ProcessEntityUpdates();
Q_SIGNALS: Q_SIGNALS:
void ExpandEntity(const AZ::EntityId& entityId, bool expand);
void SelectEntity(const AZ::EntityId& entityId, bool select); void SelectEntity(const AZ::EntityId& entityId, bool select);
void EnableSelectionUpdates(bool enable); void EnableSelectionUpdates(bool enable);
void ResetFilter(); void ResetFilter();
@ -190,7 +189,6 @@ namespace AzToolsFramework
void QueueEntityToExpand(AZ::EntityId entityId, bool expand); void QueueEntityToExpand(AZ::EntityId entityId, bool expand);
void ProcessEntityInfoResetEnd(); void ProcessEntityInfoResetEnd();
AZStd::unordered_set<AZ::EntityId> m_entitySelectQueue; AZStd::unordered_set<AZ::EntityId> m_entitySelectQueue;
AZStd::unordered_set<AZ::EntityId> m_entityExpandQueue;
AZStd::unordered_set<AZ::EntityId> m_entityChangeQueue; AZStd::unordered_set<AZ::EntityId> m_entityChangeQueue;
bool m_entityChangeQueued; bool m_entityChangeQueued;
bool m_entityLayoutQueued; bool m_entityLayoutQueued;

@ -81,6 +81,61 @@ namespace AzToolsFramework
update(); update();
} }
void EntityOutlinerTreeView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles)
{
AzQtComponents::StyledTreeView::dataChanged(topLeft, bottomRight, roles);
if (topLeft.isValid() && topLeft.parent() == bottomRight.parent() && topLeft.row() <= bottomRight.row() &&
topLeft.column() <= bottomRight.column())
{
for (int i = topLeft.row(); i <= bottomRight.row(); i++)
{
auto modelRow = topLeft.sibling(i, EntityOutlinerListModel::ColumnName);
if (modelRow.isValid())
{
checkExpandedState(modelRow);
}
}
}
}
void EntityOutlinerTreeView::rowsInserted(const QModelIndex& parent, int start, int end)
{
if (parent.isValid())
{
for (int i = start; i <= end; i++)
{
auto modelRow = model()->index(i, EntityOutlinerListModel::ColumnName, parent);
if (modelRow.isValid())
{
checkExpandedState(modelRow);
recursiveCheckExpandedStates(modelRow);
}
}
}
AzQtComponents::StyledTreeView::rowsInserted(parent, start, end);
}
void EntityOutlinerTreeView::recursiveCheckExpandedStates(const QModelIndex& current)
{
const int rowCount = model()->rowCount(current);
for (int i = 0; i < rowCount; i++)
{
auto modelRow = model()->index(i, EntityOutlinerListModel::ColumnName, current);
if (modelRow.isValid())
{
checkExpandedState(modelRow);
recursiveCheckExpandedStates(modelRow);
}
}
}
void EntityOutlinerTreeView::checkExpandedState(const QModelIndex& current)
{
const bool expandState = current.data(EntityOutlinerListModel::ExpandedRole).template value<bool>();
setExpanded(current, expandState);
}
void EntityOutlinerTreeView::mousePressEvent(QMouseEvent* event) void EntityOutlinerTreeView::mousePressEvent(QMouseEvent* event)
{ {
//postponing normal mouse pressed logic until mouse is released or dragged //postponing normal mouse pressed logic until mouse is released or dragged

@ -51,6 +51,10 @@ namespace AzToolsFramework
Q_SIGNALS: Q_SIGNALS:
void ItemDropped(); void ItemDropped();
protected Q_SLOTS:
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>()) override;
void rowsInserted(const QModelIndex &parent, int start, int end) override;
protected: protected:
// Qt overrides // Qt overrides
void mousePressEvent(QMouseEvent* event) override; void mousePressEvent(QMouseEvent* event) override;
@ -75,6 +79,8 @@ namespace AzToolsFramework
void ClearQueuedMouseEvent(); void ClearQueuedMouseEvent();
void processQueuedMousePressedEvent(QMouseEvent* event); void processQueuedMousePressedEvent(QMouseEvent* event);
void recursiveCheckExpandedStates(const QModelIndex& parent);
void checkExpandedState(const QModelIndex& current);
void StartCustomDrag(const QModelIndexList& indexList, Qt::DropActions supportedActions) override; void StartCustomDrag(const QModelIndexList& indexList, Qt::DropActions supportedActions) override;

@ -224,7 +224,6 @@ namespace AzToolsFramework
connect(m_gui->m_objectTree, &QTreeView::expanded, this, &EntityOutlinerWidget::OnTreeItemExpanded); connect(m_gui->m_objectTree, &QTreeView::expanded, this, &EntityOutlinerWidget::OnTreeItemExpanded);
connect(m_gui->m_objectTree, &QTreeView::collapsed, this, &EntityOutlinerWidget::OnTreeItemCollapsed); connect(m_gui->m_objectTree, &QTreeView::collapsed, this, &EntityOutlinerWidget::OnTreeItemCollapsed);
connect(m_gui->m_objectTree, &EntityOutlinerTreeView::ItemDropped, this, &EntityOutlinerWidget::OnDropEvent); connect(m_gui->m_objectTree, &EntityOutlinerTreeView::ItemDropped, this, &EntityOutlinerWidget::OnDropEvent);
connect(m_listModel, &EntityOutlinerListModel::ExpandEntity, this, &EntityOutlinerWidget::OnExpandEntity);
connect(m_listModel, &EntityOutlinerListModel::SelectEntity, this, &EntityOutlinerWidget::OnSelectEntity); connect(m_listModel, &EntityOutlinerListModel::SelectEntity, this, &EntityOutlinerWidget::OnSelectEntity);
connect(m_listModel, &EntityOutlinerListModel::EnableSelectionUpdates, this, &EntityOutlinerWidget::OnEnableSelectionUpdates); connect(m_listModel, &EntityOutlinerListModel::EnableSelectionUpdates, this, &EntityOutlinerWidget::OnEnableSelectionUpdates);
connect(m_listModel, &EntityOutlinerListModel::ResetFilter, this, &EntityOutlinerWidget::ClearFilter); connect(m_listModel, &EntityOutlinerListModel::ResetFilter, this, &EntityOutlinerWidget::ClearFilter);
@ -972,10 +971,6 @@ namespace AzToolsFramework
m_listModel->OnEntityCollapsed(entityId); m_listModel->OnEntityCollapsed(entityId);
} }
void EntityOutlinerWidget::OnExpandEntity(const AZ::EntityId& entityId, bool expand)
{
m_gui->m_objectTree->setExpanded(GetIndexFromEntityId(entityId), expand);
}
void EntityOutlinerWidget::OnSelectEntity(const AZ::EntityId& entityId, bool selected) void EntityOutlinerWidget::OnSelectEntity(const AZ::EntityId& entityId, bool selected)
{ {

@ -155,7 +155,6 @@ namespace AzToolsFramework
void OnTreeItemDoubleClicked(const QModelIndex& index); void OnTreeItemDoubleClicked(const QModelIndex& index);
void OnTreeItemExpanded(const QModelIndex& index); void OnTreeItemExpanded(const QModelIndex& index);
void OnTreeItemCollapsed(const QModelIndex& index); void OnTreeItemCollapsed(const QModelIndex& index);
void OnExpandEntity(const AZ::EntityId& entityId, bool expand);
void OnSelectEntity(const AZ::EntityId& entityId, bool selected); void OnSelectEntity(const AZ::EntityId& entityId, bool selected);
void OnEnableSelectionUpdates(bool enable); void OnEnableSelectionUpdates(bool enable);
void OnDropEvent(); void OnDropEvent();

Loading…
Cancel
Save