1f9b284de2
Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> # Conflicts: # Code/Editor/Plugins/ComponentEntityEditorPlugin/ComponentEntityEditorPlugin_precompiled.h # Code/Editor/Plugins/EditorCommon/EditorCommon_precompiled.h # Code/Editor/Plugins/EditorCommon/stdafx.cpp # Code/Editor/Plugins/FFMPEGPlugin/FFMPEGPlugin_precompiled.h # Code/Editor/Plugins/PerforcePlugin/PerforcePlugin_precompiled.h # Code/Editor/Plugins/ProjectSettingsTool/ProjectSettingsTool_precompiled.h # Code/Framework/AzToolsFramework/AzToolsFramework/AzToolsFramework_precompiled.h # Code/Tools/AssetProcessor/native/precompiled.h # Code/Tools/Standalone/StandaloneTools_precompiled.h # Gems/AssetMemoryAnalyzer/Code/Source/AssetMemoryAnalyzer_precompiled.h # Gems/Atom/Asset/ImageProcessingAtom/Code/Source/ImageProcessing_precompiled.h # Gems/Atom/RHI/DX12/Code/Source/RHI/Atom_RHI_DX12_precompiled.h # Gems/Atom/RHI/Metal/Code/Include/Platform/Mac/Atom_RHI_Metal_precompiled_Platform.h # Gems/Atom/RHI/Metal/Code/Include/Platform/iOS/Atom_RHI_Metal_precompiled_Platform.h # Gems/Atom/RHI/Metal/Code/Source/Atom_RHI_Metal_precompiled.h # Gems/Atom/RHI/Metal/Code/atom_rhi_metal_common_files.cmake # Gems/Atom/RHI/Null/Code/Source/Atom_RHI_Null_precompiled.h # Gems/Atom/RHI/Null/Code/atom_rhi_null_common_files.cmake # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Android/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Linux/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Mac/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Windows/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Source/Atom_RHI_Vulkan_precompiled.h # Gems/Atom/RHI/Vulkan/Code/Source/RHI/SwapChain.cpp # Gems/Atom/RHI/Vulkan/Code/atom_rhi_vulkan_common_files.cmake # Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomFont_precompiled.h # Gems/Blast/Code/Source/StdAfx.cpp # Gems/Camera/Code/Source/Camera_precompiled.h # Gems/EMotionFX/Code/Source/EMotionFX_precompiled.h # Gems/FastNoise/Code/Source/FastNoise_precompiled.h # Gems/Gestures/Code/Source/Gestures_precompiled.h # Gems/GradientSignal/Code/Source/GradientSignal_precompiled.h # Gems/GraphCanvas/Code/precompiled.h # Gems/ImGui/Code/Source/ImGui_precompiled.h # Gems/InAppPurchases/Code/Source/InAppPurchases_precompiled.h # Gems/LmbrCentral/Code/Source/LmbrCentral_precompiled.h # Gems/LmbrCentral/Code/Tests/ShapeGeometryUtilTest.cpp # Gems/LyShine/Code/Editor/UiCanvasEditor_precompiled.h # Gems/LyShine/Code/Source/Animation/LyShine_precompiled.h # Gems/LyShine/Code/Source/LyShine_precompiled.h # Gems/LyShineExamples/Code/Source/LyShineExamples_precompiled.h # Gems/Maestro/Code/Source/Cinematics/Maestro_precompiled.h # Gems/Maestro/Code/Source/Maestro_precompiled.h # Gems/MessagePopup/Code/Source/MessagePopup_precompiled.h # Gems/Metastream/Code/Source/Metastream_precompiled.h # Gems/Microphone/Code/Source/Microphone_precompiled.h # Gems/Multiplayer/Code/Source/Multiplayer_precompiled.h # Gems/PhysX/Code/NumericalMethods/Source/NumericalMethods_precompiled.h # Gems/PhysX/Code/Source/PhysXUnsupported_precompiled.h # Gems/PhysX/Code/Source/PhysX_precompiled.h # Gems/PhysX/Code/physx_unsupported_files.cmake # Gems/PhysXDebug/Code/Source/PhysXDebugUnsupported_precompiled.h # Gems/PhysXDebug/Code/Source/PhysXDebug_precompiled.h # Gems/ScriptCanvas/Code/Editor/precompiled.h # Gems/ScriptCanvas/Code/Source/precompiled.h # Gems/ScriptCanvasDeveloper/Code/Source/precompiled.h # Gems/ScriptCanvasPhysics/Code/Source/ScriptCanvasPhysics_precompiled.h # Gems/ScriptEvents/Code/Source/precompiled.h # Gems/ScriptEvents/Code/Tests/Editor/EditorTests.cpp # Gems/ScriptedEntityTweener/Code/Source/ScriptedEntityTweener_precompiled.h # Gems/SliceFavorites/Code/Source/SliceFavorites_precompiled.h # Gems/StartingPointCamera/Code/Source/StartingPointCamera_precompiled.h # Gems/StartingPointInput/Code/Source/StartingPointInput_precompiled.h # Gems/StartingPointMovement/Code/Source/StartingPointMovement_precompiled.h # Gems/SurfaceData/Code/Source/SurfaceData_precompiled.h # Gems/TextureAtlas/Code/Source/TextureAtlas_precompiled.h # Gems/TickBusOrderViewer/Code/Source/TickBusOrderViewer_precompiled.h # Gems/Twitch/Code/Source/Twitch_precompiled.h # Gems/VirtualGamepad/Code/Source/VirtualGamepad_precompiled.h # Gems/WhiteBox/Code/Source/WhiteBoxUnsupported_precompiled.h # Gems/WhiteBox/Code/Source/WhiteBox_precompiled.h
257 lines
6.6 KiB
C++
257 lines
6.6 KiB
C++
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
#include "FindEntityItemModel.h"
|
|
|
|
#include <AzFramework/StringFunc/StringFunc.h>
|
|
|
|
#include <AzToolsFramework/Entity/EditorEntityHelpers.h>
|
|
|
|
#include <LyShine/Bus/UiElementBus.h>
|
|
#include <LyShine/Bus/UiCanvasBus.h>
|
|
|
|
#include <QObject>
|
|
#include <QWidget>
|
|
#include <QPalette>
|
|
#include <QBrush>
|
|
|
|
FindEntityItemModel::FindEntityItemModel(QObject* parent)
|
|
: QAbstractItemModel(parent)
|
|
, m_entityFilteredState()
|
|
, m_entityMatchState()
|
|
{
|
|
}
|
|
|
|
void FindEntityItemModel::Initialize(AZ::EntityId canvasEntityId)
|
|
{
|
|
beginResetModel();
|
|
|
|
m_canvasEntityId = canvasEntityId;
|
|
|
|
endResetModel();
|
|
}
|
|
|
|
int FindEntityItemModel::rowCount(const QModelIndex& parent) const
|
|
{
|
|
int childCount = 0;
|
|
|
|
auto parentId = GetEntityFromIndex(parent);
|
|
if (parentId.IsValid())
|
|
{
|
|
EBUS_EVENT_ID_RESULT(childCount, parentId, UiElementBus, GetNumChildElements);
|
|
}
|
|
else
|
|
{
|
|
// Root element
|
|
EBUS_EVENT_ID_RESULT(childCount, m_canvasEntityId, UiCanvasBus, GetNumChildElements);
|
|
}
|
|
|
|
return childCount;
|
|
}
|
|
|
|
int FindEntityItemModel::columnCount(const QModelIndex& /*parent*/) const
|
|
{
|
|
return ColumnCount;
|
|
}
|
|
|
|
QModelIndex FindEntityItemModel::index(int row, int column, const QModelIndex& parent) const
|
|
{
|
|
// sanity check
|
|
if (!hasIndex(row, column, parent) || (parent.isValid() && parent.column() != 0) || (row < 0 || row >= rowCount(parent)))
|
|
{
|
|
return QModelIndex();
|
|
}
|
|
|
|
auto parentId = GetEntityFromIndex(parent);
|
|
|
|
AZ::EntityId childId;
|
|
if (parentId.IsValid())
|
|
{
|
|
EBUS_EVENT_ID_RESULT(childId, parentId, UiElementBus, GetChildEntityId, row);
|
|
}
|
|
else
|
|
{
|
|
// Root element
|
|
EBUS_EVENT_ID_RESULT(childId, m_canvasEntityId, UiCanvasBus, GetChildElementEntityId, row);
|
|
}
|
|
|
|
return createIndex(row, column, static_cast<AZ::u64>(childId));
|
|
}
|
|
|
|
QVariant FindEntityItemModel::data(const QModelIndex& index, int role) const
|
|
{
|
|
auto id = GetEntityFromIndex(index);
|
|
if (id.IsValid())
|
|
{
|
|
switch (index.column())
|
|
{
|
|
case ColumnName:
|
|
return DataForName(index, role);
|
|
}
|
|
}
|
|
|
|
return QVariant();
|
|
}
|
|
|
|
QModelIndex FindEntityItemModel::parent(const QModelIndex& index) const
|
|
{
|
|
auto id = GetEntityFromIndex(index);
|
|
if (id.IsValid())
|
|
{
|
|
AZ::EntityId parentId;
|
|
EBUS_EVENT_ID_RESULT(parentId, id, UiElementBus, GetParentEntityId);
|
|
return GetIndexFromEntity(parentId, index.column());
|
|
}
|
|
return QModelIndex();
|
|
}
|
|
|
|
QModelIndex FindEntityItemModel::GetIndexFromEntity(const AZ::EntityId& entityId, int column) const
|
|
{
|
|
if (entityId.IsValid())
|
|
{
|
|
AZ::EntityId parentId;
|
|
EBUS_EVENT_ID_RESULT(parentId, entityId, UiElementBus, GetParentEntityId);
|
|
|
|
if (parentId.IsValid())
|
|
{
|
|
AZStd::size_t row = 0;
|
|
EBUS_EVENT_ID_RESULT(row, parentId, UiElementBus, GetIndexOfChildByEntityId, entityId);
|
|
return createIndex(static_cast<int>(row), column, static_cast<AZ::u64>(entityId));
|
|
}
|
|
}
|
|
return QModelIndex();
|
|
}
|
|
|
|
AZ::EntityId FindEntityItemModel::GetEntityFromIndex(const QModelIndex& index) const
|
|
{
|
|
return index.isValid() ? AZ::EntityId(static_cast<AZ::u64>(index.internalId())) : AZ::EntityId();
|
|
}
|
|
|
|
void FindEntityItemModel::SearchStringChanged(const AZStd::string& filter)
|
|
{
|
|
m_filterString = filter;
|
|
InvalidateFilter();
|
|
}
|
|
|
|
void FindEntityItemModel::SearchFilterChanged(const AZStd::vector<AZ::Uuid>& componentFilters)
|
|
{
|
|
m_componentFilters = AZStd::move(componentFilters);
|
|
InvalidateFilter();
|
|
}
|
|
|
|
QVariant FindEntityItemModel::DataForName(const QModelIndex& index, int role) const
|
|
{
|
|
auto id = GetEntityFromIndex(index);
|
|
|
|
switch (role)
|
|
{
|
|
case Qt::DisplayRole:
|
|
case Qt::EditRole:
|
|
{
|
|
AZStd::string name;
|
|
EBUS_EVENT_ID_RESULT(name, id, UiElementBus, GetName);
|
|
return QString(name.data());
|
|
}
|
|
|
|
case Qt::ForegroundRole:
|
|
{
|
|
const QColor notMatchedTextColor(130, 130, 130);
|
|
|
|
// We use the parent's palette because the GUI Application palette is returning the wrong colors
|
|
auto parentWidgetPtr = static_cast<QWidget*>(QObject::parent());
|
|
return QBrush(IsMatch(id) ? parentWidgetPtr->palette().color(QPalette::Text) : notMatchedTextColor);
|
|
}
|
|
|
|
case VisibilityRole:
|
|
{
|
|
return !IsFiltered(id);
|
|
}
|
|
}
|
|
|
|
return QVariant();
|
|
}
|
|
|
|
void FindEntityItemModel::InvalidateFilter()
|
|
{
|
|
FilterEntity(AZ::EntityId());
|
|
}
|
|
|
|
bool FindEntityItemModel::FilterEntity(const AZ::EntityId& entityId)
|
|
{
|
|
bool isFilterMatch = true;
|
|
|
|
if (m_filterString.size() > 0)
|
|
{
|
|
if (entityId.IsValid())
|
|
{
|
|
AZStd::string name;
|
|
EBUS_EVENT_ID_RESULT(name, entityId, UiElementBus, GetName);
|
|
|
|
if (AzFramework::StringFunc::Find(name.c_str(), m_filterString.c_str()) == AZStd::string::npos)
|
|
{
|
|
isFilterMatch = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
// If we matched the filter string and have any component filters, make sure we match those too
|
|
if (isFilterMatch && m_componentFilters.size() > 0)
|
|
{
|
|
if (entityId.IsValid())
|
|
{
|
|
bool hasMatchingComponent = false;
|
|
|
|
for (AZ::Uuid& componentType : m_componentFilters)
|
|
{
|
|
if (AzToolsFramework::EntityHasComponentOfType(entityId, componentType))
|
|
{
|
|
hasMatchingComponent = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
isFilterMatch &= hasMatchingComponent;
|
|
}
|
|
}
|
|
|
|
AzToolsFramework::EntityIdList children;
|
|
if (entityId.IsValid())
|
|
{
|
|
EBUS_EVENT_ID_RESULT(children, entityId, UiElementBus, GetChildEntityIds);
|
|
}
|
|
else
|
|
{
|
|
// Root element
|
|
EBUS_EVENT_ID_RESULT(children, m_canvasEntityId, UiCanvasBus, GetChildElementEntityIds);
|
|
}
|
|
|
|
m_entityMatchState[entityId] = isFilterMatch;
|
|
|
|
for (auto childId : children)
|
|
{
|
|
isFilterMatch |= FilterEntity(childId);
|
|
}
|
|
|
|
m_entityFilteredState[entityId] = !isFilterMatch;
|
|
|
|
return isFilterMatch;
|
|
}
|
|
|
|
bool FindEntityItemModel::IsFiltered(const AZ::EntityId& entityId) const
|
|
{
|
|
auto hiddenItr = m_entityFilteredState.find(entityId);
|
|
return hiddenItr != m_entityFilteredState.end() && hiddenItr->second;
|
|
}
|
|
|
|
bool FindEntityItemModel::IsMatch(const AZ::EntityId& entityId) const
|
|
{
|
|
auto matchItr = m_entityMatchState.find(entityId);
|
|
return matchItr == m_entityMatchState.end() || matchItr->second;
|
|
}
|
|
|
|
#include <moc_FindEntityItemModel.cpp>
|