/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include 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_model); 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 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()) { continue; } m_containerWizard->RegisterType(typeId); variableTypes.insert(typeId); } AZStd::intrusive_ptr settings = AZ::UserSettings::CreateFind(AZ_CRC("ScriptCanvasPreviewSettings", 0x1c5a2965), AZ::UserSettings::CT_LOCAL); for (const AZ::Uuid& objectId : objectTypes) { // 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()) { 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()) { 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 }