Files
o3de/Gems/ScriptCanvas/Code/Editor/View/Widgets/VariablePanel/VariablePaletteTableView.cpp
T
Esteban Papp 1f9b284de2 Merge branch 'development' into cmake/SPEC-7179
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
2021-07-16 15:42:37 -07:00

281 lines
9.4 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 <qaction.h>
#include <qevent.h>
#include <qheaderview.h>
#include <qitemselectionmodel.h>
#include <qscrollbar.h>
#include <AzCore/Component/ComponentApplicationBus.h>
#include <AzCore/Serialization/Utils.h>
#include <AzCore/UserSettings/UserSettings.h>
#include <AzToolsFramework/ToolsComponents/EditorComponentBase.h>
#include <GraphCanvas/Types/TranslationTypes.h>
#include <GraphCanvas/Components/SceneBus.h>
#include <GraphCanvas/Components/StyleBus.h>
#include <Editor/GraphCanvas/GraphCanvasEditorNotificationBusId.h>
#include <Editor/View/Widgets/VariablePanel/VariablePaletteTableView.h>
#include <Editor/View/Widgets/DataTypePalette/DataTypePaletteModel.h>
#include <Editor/View/Dialogs/ContainerWizard/ContainerWizard.h>
#include <Editor/Settings.h>
#include <Editor/Translation/TranslationHelper.h>
#include <Editor/QtMetaTypes.h>
#include <ScriptCanvas/Data/DataRegistry.h>
namespace ScriptCanvasEditor
{
/////////////////////////////
// VariablePaletteTableView
/////////////////////////////
VariablePaletteTableView::VariablePaletteTableView(QWidget* parent)
: QTableView(parent)
{
m_containerWizard = aznew ContainerWizard(parent);
m_model = aznew DataTypePaletteModel(parent);
m_proxyModel = aznew DataTypePaletteSortFilterProxyModel(parent);
m_proxyModel->setSourceModel(m_model);
m_proxyModel->sort(DataTypePaletteModel::ColumnIndex::Type);
setModel(m_proxyModel);
setItemDelegateForColumn(DataTypePaletteModel::Type, aznew GraphCanvas::IconDecoratedNameDelegate(this));
viewport()->installEventFilter(this);
horizontalHeader()->setSectionResizeMode(DataTypePaletteModel::ColumnIndex::Pinned, QHeaderView::ResizeMode::ResizeToContents);
horizontalHeader()->setSectionResizeMode(DataTypePaletteModel::ColumnIndex::Type, QHeaderView::ResizeMode::Stretch);
QObject::connect(this, &QAbstractItemView::clicked, this, &VariablePaletteTableView::OnClicked);
QObject::connect(m_containerWizard, &ContainerWizard::CreateContainerVariable, this, &VariablePaletteTableView::OnCreateContainerVariable);
QObject::connect(m_containerWizard, &ContainerWizard::ContainerPinned, this, &VariablePaletteTableView::OnContainerPinned);
m_completer = new QCompleter();
m_completer->setModel(m_proxyModel);
m_completer->setCompletionColumn(DataTypePaletteModel::ColumnIndex::Type);
m_completer->setCompletionMode(QCompleter::CompletionMode::InlineCompletion);
m_completer->setCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive);
setMinimumSize(0,0);
}
VariablePaletteTableView::~VariablePaletteTableView()
{
m_model->SubmitPendingPinChanges();
}
void VariablePaletteTableView::SetActiveScene(const ScriptCanvas::ScriptCanvasId& scriptCanvasId)
{
m_containerWizard->SetActiveScriptCanvasId(scriptCanvasId);
}
void VariablePaletteTableView::PopulateVariablePalette(const AZStd::unordered_set< AZ::Uuid >& objectTypes)
{
clearSelection();
m_model->ClearTypes();
AZStd::unordered_set<AZ::Uuid> variableTypes;
auto dataRegistry = ScriptCanvas::GetDataRegistry();
for (const auto& dataTraitsPair : dataRegistry->m_typeIdTraitMap)
{
// Object type isn't valid on it's own. Need to skip that in order. Passed in types will all be
// processed as an object type.
if (dataTraitsPair.first == ScriptCanvas::Data::eType::BehaviorContextObject)
{
continue;
}
AZ::Uuid typeId = dataTraitsPair.second.m_dataTraits.GetAZType();
if (typeId.IsNull() || typeId == azrtti_typeid<void>())
{
continue;
}
m_containerWizard->RegisterType(typeId);
variableTypes.insert(typeId);
}
AZStd::intrusive_ptr<EditorSettings::ScriptCanvasEditorSettings> settings = AZ::UserSettings::CreateFind<EditorSettings::ScriptCanvasEditorSettings>(AZ_CRC("ScriptCanvasPreviewSettings", 0x1c5a2965), AZ::UserSettings::CT_LOCAL);
for (const AZ::Uuid& objectId : objectTypes)
{
ScriptCanvas::Data::Type type = dataRegistry->m_typeIdTraitMap[ScriptCanvas::Data::eType::BehaviorContextObject].m_dataTraits.GetSCType(objectId);
if (!type.IsValid() || !dataRegistry->m_creatableTypes.contains(type))
{
continue;
}
// For now, we need to register all of the objectId's with the container wizard
// in order to properly populate the list of valid container configurations.
m_containerWizard->RegisterType(objectId);
// Sanitize containers so we only put in information about the generic container type
if (AZ::Utils::IsContainerType(objectId))
{
variableTypes.insert(AZ::Utils::GetGenericContainerType(objectId));
}
else
{
variableTypes.insert(objectId);
}
}
// Since we gated containers to make them genrealized buckets, we now need to go through
// and register in the custom defined types for each of the container types that we created.
for (const AZ::Uuid& pinnedTypeId : settings->m_pinnedDataTypes)
{
if (variableTypes.find(pinnedTypeId) == variableTypes.end())
{
variableTypes.insert(pinnedTypeId);
}
}
m_model->PopulateVariablePalette(variableTypes);
}
void VariablePaletteTableView::SetFilter(const QString& filter)
{
m_model->SubmitPendingPinChanges();
clearSelection();
m_proxyModel->SetFilter(filter);
}
QCompleter* VariablePaletteTableView::GetVariableCompleter()
{
return m_completer;
}
void VariablePaletteTableView::TryCreateVariableByTypeName(const AZStd::string& typeName)
{
AZ::TypeId typeId = m_model->FindTypeIdForTypeName(typeName);
// Only want to go into the wizard, if we have a generic type.
if (AZ::Utils::IsGenericContainerType(typeId))
{
m_containerWizard->ShowWizard(typeId);
}
else if (!typeId.IsNull() && typeId != azrtti_typeid<void>())
{
emit CreateVariable(ScriptCanvas::Data::FromAZType(typeId));
}
}
void VariablePaletteTableView::hideEvent(QHideEvent* hideEvent)
{
m_model->SubmitPendingPinChanges();
clearSelection();
QTableView::hideEvent(hideEvent);
}
void VariablePaletteTableView::showEvent(QShowEvent* showEvent)
{
QTableView::showEvent(showEvent);
clearSelection();
scrollToTop();
m_proxyModel->invalidate();
}
const DataTypePaletteModel* VariablePaletteTableView::GetVariableTypePaletteModel() const
{
return m_model;
}
AZStd::vector< AZ::TypeId > VariablePaletteTableView::GetArrayTypes() const
{
AZStd::vector< AZ::TypeId > arrayTypes;
const auto& finalTypeMapping = m_containerWizard->GetFinalTypeMapping();
for (auto typePair : finalTypeMapping)
{
if (ScriptCanvas::Data::IsVectorContainerType(ScriptCanvas::Data::FromAZType(typePair.second)))
{
arrayTypes.emplace_back(typePair.second);
}
}
return arrayTypes;
}
AZStd::vector< AZ::TypeId > VariablePaletteTableView::GetMapTypes() const
{
AZStd::vector< AZ::TypeId > mapTypes;
const auto& finalTypeMapping = m_containerWizard->GetFinalTypeMapping();
for (auto typePair : finalTypeMapping)
{
if (ScriptCanvas::Data::IsMapContainerType(ScriptCanvas::Data::FromAZType(typePair.second)))
{
mapTypes.emplace_back(typePair.second);
}
}
return mapTypes;
}
void VariablePaletteTableView::OnClicked(const QModelIndex& index)
{
AZ::TypeId typeId;
QModelIndex sourceIndex = m_proxyModel->mapToSource(index);
if (sourceIndex.isValid())
{
typeId = m_model->FindTypeIdForIndex(sourceIndex);
}
if (!typeId.IsNull() && typeId != azrtti_typeid<void>())
{
if (index.column() == DataTypePaletteModel::ColumnIndex::Pinned)
{
m_model->TogglePendingPinChange(typeId);
m_model->dataChanged(sourceIndex, sourceIndex);
}
else if (AZ::Utils::IsGenericContainerType(typeId))
{
m_containerWizard->ShowWizard(typeId);
}
else
{
emit CreateVariable(ScriptCanvas::Data::FromAZType(typeId));
}
}
}
void VariablePaletteTableView::OnContainerPinned(const AZ::TypeId& typeId)
{
m_model->AddDataType(typeId);
}
void VariablePaletteTableView::OnCreateContainerVariable(const AZStd::string& variableName, const AZ::TypeId& typeId)
{
ScriptCanvas::Data::Type dataType = ScriptCanvas::Data::FromAZType(typeId);
emit CreateNamedVariable(variableName, dataType);
}
#include <Editor/View/Widgets/VariablePanel/moc_VariablePaletteTableView.cpp>
}