/* * 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 namespace AZ { namespace SceneAPI { namespace UI { AZ_CLASS_ALLOCATOR_IMPL(HeaderWidget, SystemAllocator, 0) HeaderWidget::HeaderWidget(QWidget* parent) : QWidget(parent) , ui(new Ui::HeaderWidget()) , m_target(nullptr) , m_nameIsEditable(false) , m_sceneManifest(nullptr) { ui->setupUi(this); ui->m_icon->hide(); ui->m_deleteButton->setIcon(QIcon(":/PropertyEditor/Resources/cross-small.png")); connect(ui->m_deleteButton, &QToolButton::clicked, this, &HeaderWidget::DeleteObject); ui->m_deleteButton->hide(); ManifestWidget* root = ManifestWidget::FindRoot(this); AZ_Assert(root, "HeaderWidget is not a child of the ManifestWidget"); if (root) { m_sceneManifest = &root->GetScene()->GetManifest(); } } void HeaderWidget::SetManifestObject(const DataTypes::IManifestObject* target) { AZ_TraceContext("New target", GetSerializedName(target)); m_target = target; ui->m_nameLabel->setText(GetSerializedName(target)); UpdateDeletable(); SetIcon(target); } const DataTypes::IManifestObject* HeaderWidget::GetManifestObject() const { return m_target; } void HeaderWidget::DeleteObject() { AZ_TraceContext("Delete target", GetSerializedName(m_target)); if (m_sceneManifest) { Containers::SceneManifest::Index index = m_sceneManifest->FindIndex(m_target); if (index != Containers::SceneManifest::s_invalidIndex) { AZ_TraceContext("Manifest index", static_cast(index)); ManifestWidget* root = ManifestWidget::FindRoot(this); // The manifest object could be a root element at the manifest page level so it needs to be // removed from there as well in that case. if (root->RemoveObject(m_sceneManifest->GetValue(index)) && m_sceneManifest->RemoveEntry(m_target)) { m_target = nullptr; // Hide and disable the button so when users spam the delete button only a single click is recorded. ui->m_deleteButton->hide(); ui->m_deleteButton->setEnabled(false); return; } else { AZ_TracePrintf(Utilities::LogWindow, "Unable to delete manifest object from manifest."); } } } QObject* widget = this->parent(); while (widget != nullptr) { ManifestVectorWidget* manifestVectorWidget = qobject_cast(widget); if (manifestVectorWidget) { if (manifestVectorWidget->RemoveManifestObject(m_target)) { m_target = nullptr; // Hide and disable the button so when users spam the delete button only a single click is recorded. ui->m_deleteButton->hide(); ui->m_deleteButton->setEnabled(false); } else { AZ_TracePrintf(Utilities::WarningWindow, "Parent collection did not contain this ManifestObject"); } return; } widget = widget->parent(); } AZ_TracePrintf(Utilities::ErrorWindow, "No parent valid parent collection found."); } void HeaderWidget::UpdateDeletable() { ui->m_deleteButton->hide(); if (m_sceneManifest) { Containers::SceneManifest::Index index = m_sceneManifest->FindIndex(m_target); if (index != Containers::SceneManifest::s_invalidIndex) { ui->m_deleteButton->show(); return; } } QObject* widget = this->parent(); while(widget != nullptr) { ManifestVectorWidget* manifestVectorWidget = qobject_cast(widget); if (manifestVectorWidget && manifestVectorWidget->ContainsManifestObject(m_target)) { ui->m_deleteButton->show(); break; } widget = widget->parent(); } } const char* HeaderWidget::GetSerializedName(const DataTypes::IManifestObject* target) const { SerializeContext* context = nullptr; EBUS_EVENT_RESULT(context, ComponentApplicationBus, GetSerializeContext); if (context) { const SerializeContext::ClassData* classData = context->FindClassData(target->RTTI_GetType()); if (classData) { if (classData->m_editData) { return classData->m_editData->m_name; } return classData->m_name; } } return ""; } void HeaderWidget::SetIcon(const DataTypes::IManifestObject* target) { if (!target) { return; } AZStd::string iconPath; EBUS_EVENT(Events::ManifestMetaInfoBus, GetIconPath, iconPath, *target); if (iconPath.empty()) { ui->m_icon->hide(); } else { ui->m_icon->setPixmap(QPixmap(iconPath.c_str())); ui->m_icon->show(); } } } // UI } // SceneAPI } // AZ #include