From 5a8998add11b6657d6b365802943240086fae584 Mon Sep 17 00:00:00 2001 From: srikappa-amzn Date: Thu, 2 Sep 2021 23:35:28 -0700 Subject: [PATCH] Added function comments and nullptr checks Signed-off-by: srikappa-amzn --- Code/Editor/CryEdit.cpp | 28 ++-- Code/Editor/Style/Editor.qss | 9 +- .../Prefab/PrefabSystemComponent.cpp | 49 ++++--- .../Prefab/PrefabSystemComponentInterface.h | 10 ++ .../UI/Prefab/PrefabIntegrationInterface.h | 6 + .../UI/Prefab/PrefabIntegrationManager.cpp | 123 ++++++++++-------- .../UI/Prefab/PrefabIntegrationManager.h | 2 +- 7 files changed, 137 insertions(+), 90 deletions(-) diff --git a/Code/Editor/CryEdit.cpp b/Code/Editor/CryEdit.cpp index 4725101599..2e738a18c5 100644 --- a/Code/Editor/CryEdit.cpp +++ b/Code/Editor/CryEdit.cpp @@ -723,24 +723,22 @@ void CCryEditApp::OnFileSave() } const QScopedValueRollback rollback(m_savingLevel, true); - - bool usePrefabSystemForLevels = false; AzFramework::ApplicationRequests::Bus::BroadcastResult( usePrefabSystemForLevels, &AzFramework::ApplicationRequests::IsPrefabSystemForLevelsEnabled); - - if (!usePrefabSystemForLevels) { GetIEditor()->GetDocument()->DoFileSave(); } else { - auto prefabEditorEntityOwnershipService = AZ::Interface::Get(); - AzToolsFramework::Prefab::TemplateId rootPrefabTemplateId = prefabEditorEntityOwnershipService->GetRootPrefabTemplateId(); - auto prefabIntegrationInterface = AZ::Interface::Get(); + auto* prefabEditorEntityOwnershipInterface = AZ::Interface::Get(); + auto* prefabIntegrationInterface = AZ::Interface::Get(); + AZ_Assert(prefabEditorEntityOwnershipInterface != nullptr, "PrefabEditorEntityOwnershipInterface is not found."); + AZ_Assert(prefabIntegrationInterface != nullptr, "PrefabIntegrationInterface is not found."); + AzToolsFramework::Prefab::TemplateId rootPrefabTemplateId = prefabEditorEntityOwnershipInterface->GetRootPrefabTemplateId(); prefabIntegrationInterface->ExecuteSavePrefabDialog(rootPrefabTemplateId, true); } } @@ -3187,12 +3185,18 @@ bool CCryEditApp::CreateLevel(bool& wasCreateLevelOperationCancelled) } else { - auto prefabEditorEntityOwnershipInterface = AZ::Interface::Get(); - auto prefabIntegrationInterface = AZ::Interface::Get(); - AzToolsFramework::Prefab::TemplateId rootPrefabTemplateId = prefabEditorEntityOwnershipInterface->GetRootPrefabTemplateId(); + auto* prefabEditorEntityOwnershipInterface = AZ::Interface::Get(); + auto* prefabIntegrationInterface = AZ::Interface::Get(); + AZ_Assert(prefabEditorEntityOwnershipInterface != nullptr, "PrefabEditorEntityOwnershipInterface is not found."); + AZ_Assert(prefabIntegrationInterface != nullptr, "PrefabIntegrationInterface is not found."); - int prefabSaveSelection = - prefabIntegrationInterface->ExecuteClosePrefabDialog(rootPrefabTemplateId); + if (prefabEditorEntityOwnershipInterface == nullptr || prefabIntegrationInterface == nullptr) + { + return false; + } + + AzToolsFramework::Prefab::TemplateId rootPrefabTemplateId = prefabEditorEntityOwnershipInterface->GetRootPrefabTemplateId(); + int prefabSaveSelection = prefabIntegrationInterface->ExecuteClosePrefabDialog(rootPrefabTemplateId); // In order to get the accept and reject codes of QDialog and QDialogButtonBox aligned, we do (1-prefabSaveSelection) here. switch (1 - prefabSaveSelection) diff --git a/Code/Editor/Style/Editor.qss b/Code/Editor/Style/Editor.qss index 3bf92b4495..302b7703a5 100644 --- a/Code/Editor/Style/Editor.qss +++ b/Code/Editor/Style/Editor.qss @@ -245,7 +245,8 @@ QTableWidget#recentLevelTable::item { qproperty-iconSize: 16px 16px; } -#SavePrefabDialog, #SaveAllFilesDialog + +#ClosePrefabDialog, #SavePrefabDialog { min-width : 640px; } @@ -262,7 +263,7 @@ QTableWidget#recentLevelTable::item { padding: 5px 2px 5px 2px; } -#SavePrefabDialog #PrefabSaveWarningFrame +#ClosePrefabDialog #PrefabSaveWarningFrame { border: 1px solid orange; margin: 10px 15px 10px 15px; @@ -271,12 +272,12 @@ QTableWidget#recentLevelTable::item { color : white; } -#SaveAllFilesDialog #FooterSeparatorLine, #SavePrefabDialog #FooterSeparatorLine +#SavePrefabDialog #FooterSeparatorLine { color: gray; } -#SaveAllFilesDialog #PrefabSavePreferenceHint, #SavePrefabDialog #PrefabSavePreferenceHint +#SavePrefabDialog #PrefabSavePreferenceHint { font: italic; color: #999999; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp index e465e111aa..a2ef30d1f7 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp @@ -756,13 +756,20 @@ namespace AzToolsFramework bool PrefabSystemComponent::AreDirtyTemplatesPresent(TemplateId templateId) { - auto parentTemplate = FindTemplate(templateId); + auto prefabTemplate = FindTemplate(templateId); + + if (!prefabTemplate.has_value()) + { + AZ_Assert(false, "Template with id %llu is not found", templateId); + return false; + } + if (IsTemplateDirty(templateId)) { return true; } - auto linkIds = parentTemplate->get().GetLinks(); + auto linkIds = prefabTemplate->get().GetLinks(); for (auto linkId : linkIds) { @@ -777,31 +784,39 @@ namespace AzToolsFramework void PrefabSystemComponent::SaveAllDirtyTemplates(TemplateId templateId) { - auto parentTemplate = FindTemplate(templateId); - if (IsTemplateDirty(templateId)) - { - m_prefabLoader.SaveTemplate(templateId); - } - auto linkIds = parentTemplate->get().GetLinks(); + AZStd::set dirtyTemplatePaths; + GetDirtyTemplatePaths(templateId, dirtyTemplatePaths); - for (auto linkId : linkIds) + for (auto dirtyTemplatePath : dirtyTemplatePaths) { - auto linkIterator = m_linkIdMap.find(linkId); - if (linkIterator != m_linkIdMap.end()) + auto dirtyTemplateIterator = m_templateFilePathToIdMap.find(dirtyTemplatePath); + if (dirtyTemplateIterator == m_templateFilePathToIdMap.end()) { - SaveAllDirtyTemplates(linkIterator->second.GetSourceTemplateId()); + AZ_Assert(false, "Template id for template with path '%s' is not found.", dirtyTemplatePath); + } + else + { + m_prefabLoader.SaveTemplate(dirtyTemplateIterator->second); } } } - void PrefabSystemComponent::GetDirtyTemplatePaths(TemplateId parentTemplateId, AZStd::set& dirtyTemplatePaths) + void PrefabSystemComponent::GetDirtyTemplatePaths(TemplateId templateId, AZStd::set& dirtyTemplatePaths) { - auto parentTemplate = FindTemplate(parentTemplateId); - if (IsTemplateDirty(parentTemplateId)) + auto prefabTemplate = FindTemplate(templateId); + + if (!prefabTemplate.has_value()) { - dirtyTemplatePaths.emplace(parentTemplate->get().GetFilePath()); + AZ_Assert(false, "Template with id %llu is not found", templateId); + return; } - auto linkIds = parentTemplate->get().GetLinks(); + + if (IsTemplateDirty(templateId)) + { + dirtyTemplatePaths.emplace(prefabTemplate->get().GetFilePath()); + } + + auto linkIds = prefabTemplate->get().GetLinks(); for (auto linkId : linkIds) { diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponentInterface.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponentInterface.h index a5abf138f7..98e7719907 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponentInterface.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponentInterface.h @@ -50,8 +50,18 @@ namespace AzToolsFramework virtual bool IsTemplateDirty(const TemplateId& templateId) = 0; virtual void SetTemplateDirtyFlag(const TemplateId& templateId, bool dirty) = 0; + + //! Recursive function to check if the template is dirty or if any dirty templates are presents in the links of the template. + //! @param templateId The id of the template provided as the beginning template to check the outgoing links. virtual bool AreDirtyTemplatesPresent(TemplateId templateId) = 0; + + //! Recursive function to save if the template is dirty and save all the dirty templates in the links of the template. + //! @param templateId The id of the template provided as the beginning template to check the outgoing links. virtual void SaveAllDirtyTemplates(TemplateId templateId) = 0; + + //! Recursive function that fetches the set of dirty templates given a starting template to check for outgoing links. + //! @param templateId The id of the template provided as the beginning template to check the outgoing links. + //! @param[out] dirtyTemplatePaths The set of dirty template paths populated. virtual void GetDirtyTemplatePaths(TemplateId parentTemplateId, AZStd::set& dirtyTemplatePaths) = 0; virtual PrefabDom& FindTemplateDom(TemplateId templateId) = 0; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationInterface.h b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationInterface.h index f5f393f3b8..e92f08f9ff 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationInterface.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationInterface.h @@ -30,7 +30,13 @@ namespace AzToolsFramework */ virtual AZ::EntityId CreateNewEntityAtPosition(const AZ::Vector3& position, AZ::EntityId parentId) = 0; + //! Constructs and executes the close dialog on a prefab template corresponding to templateId. + //! @param templateId The id of the template the user chose to close. virtual int ExecuteClosePrefabDialog(TemplateId templateId) = 0; + + //! Constructs and executes the save dialog on a prefab template corresponding to templateId. + //! @param templateId The id of the template the user chose to save. + //! @param useSaveAllPrefabsPreference A flag indicating whether SaveAllPrefabsPreference should be used for saving templates. virtual void ExecuteSavePrefabDialog(TemplateId templateId, bool useSaveAllPrefabsPreference = false) = 0; }; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.cpp index 42d8ec80bf..ad3ac9e69f 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.cpp @@ -63,6 +63,16 @@ namespace AzToolsFramework PrefabSystemComponentInterface* PrefabIntegrationManager::s_prefabSystemComponentInterface = nullptr; const AZStd::string PrefabIntegrationManager::s_prefabFileExtension = ".prefab"; + + static constexpr char* const ClosePrefabDialog = "ClosePrefabDialog"; + static constexpr char* const FooterSeparatorLine = "FooterSeparatorLine"; + static constexpr char* const PrefabSavedMessageFrame = "PrefabSavedMessageFrame"; + static constexpr char* const PrefabSavePreferenceHint = "PrefabSavePreferenceHint"; + static constexpr char* const PrefabSaveWarningFrame = "PrefabSaveWarningFrame"; + static constexpr char* const SaveDependentPrefabsCard = "SaveDependentPrefabsCard"; + static constexpr char* const SavePrefabDialog = "SavePrefabDialog"; + static constexpr char* const UnsavedPrefabFileName = "UnsavedPrefabFileName"; + void PrefabUserSettings::Reflect(AZ::ReflectContext* context) { @@ -1100,7 +1110,7 @@ namespace AzToolsFramework { if (s_prefabLoaderInterface->SaveTemplate(templateId) == false) { - AZ_Error("Prefabs", false, "Template '%s' could not be saved successfully.", prefabTemplatePath.c_str()); + AZ_Error("Prefab", false, "Template '%s' could not be saved successfully.", prefabTemplatePath.c_str()); return; } } @@ -1134,7 +1144,7 @@ namespace AzToolsFramework void PrefabIntegrationManager::SavePrefabsInDialog(QDialog* unsavedPrefabsDialog) { - QList unsavedPrefabFileLabels = unsavedPrefabsDialog->findChildren("UnsavedPrefabFileName"); + QList unsavedPrefabFileLabels = unsavedPrefabsDialog->findChildren(UnsavedPrefabFileName); if (unsavedPrefabFileLabels.size() > 0) { for (const QLabel* unsavedPrefabFileLabel : unsavedPrefabFileLabels) @@ -1150,22 +1160,22 @@ namespace AzToolsFramework AZStd::unique_ptr PrefabIntegrationManager::ConstructSavePrefabDialog(TemplateId templateId, bool useSaveAllPrefabsPreference) { - AZStd::unique_ptr saveModifiedMessageBox = AZStd::make_unique(AzToolsFramework::GetActiveWindow()); + AZStd::unique_ptr savePrefabDialog = AZStd::make_unique(AzToolsFramework::GetActiveWindow()); - saveModifiedMessageBox->setWindowTitle("Unsaved files detected"); + savePrefabDialog->setWindowTitle("Unsaved files detected"); // Main Content section begins. - saveModifiedMessageBox->setObjectName("SaveAllFilesDialog"); - QBoxLayout* contentLayout = new QVBoxLayout(saveModifiedMessageBox.get()); + savePrefabDialog->setObjectName(SavePrefabDialog); + QBoxLayout* contentLayout = new QVBoxLayout(savePrefabDialog.get()); - QFrame* prefabSavedMessageFrame = new QFrame(saveModifiedMessageBox.get()); - QHBoxLayout* prefabSavedMessageLayout = new QHBoxLayout(saveModifiedMessageBox.get()); - prefabSavedMessageFrame->setObjectName("PrefabSavedMessageFrame"); + QFrame* prefabSavedMessageFrame = new QFrame(savePrefabDialog.get()); + QHBoxLayout* prefabSavedMessageLayout = new QHBoxLayout(savePrefabDialog.get()); + prefabSavedMessageFrame->setObjectName(PrefabSavedMessageFrame); prefabSavedMessageFrame->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); // Add a checkMark icon next to the level entities saved message. QPixmap checkMarkIcon(QString(":/Notifications/checkmark.svg")); - QLabel* prefabSavedSuccessfullyIconContainer = new QLabel(); + QLabel* prefabSavedSuccessfullyIconContainer = new QLabel(savePrefabDialog.get()); prefabSavedSuccessfullyIconContainer->setPixmap(checkMarkIcon); prefabSavedSuccessfullyIconContainer->setFixedWidth(checkMarkIcon.width()); @@ -1174,69 +1184,71 @@ namespace AzToolsFramework auto prefabTemplate = s_prefabSystemComponentInterface->FindTemplate(templateId); AZ::IO::Path prefabTemplatePath = prefabTemplate->get().GetFilePath(); QLabel* prefabSavedSuccessfullyLabel = new QLabel( - QString("Prefab %1 has been saved. Do you want to save the below dependent prefabs too?").arg(prefabTemplatePath.c_str())); - prefabSavedSuccessfullyLabel->setObjectName("PrefabSavedSuccessfullyLabel"); + QString("Prefab %1 has been saved. Do you want to save the below dependent prefabs too?").arg(prefabTemplatePath.c_str()), + savePrefabDialog.get()); prefabSavedMessageLayout->addWidget(prefabSavedSuccessfullyIconContainer); prefabSavedMessageLayout->addWidget(prefabSavedSuccessfullyLabel); prefabSavedMessageFrame->setLayout(prefabSavedMessageLayout); contentLayout->addWidget(prefabSavedMessageFrame); - AzQtComponents::Card* unsavedPrefabsContainer = ConstructUnsavedPrefabsCard(templateId); - contentLayout->addWidget(unsavedPrefabsContainer); + AZStd::unique_ptr unsavedPrefabsContainer = ConstructUnsavedPrefabsCard(templateId); + contentLayout->addWidget(unsavedPrefabsContainer.release()); contentLayout->addStretch(); // Footer section begins. - QHBoxLayout* footerLayout = new QHBoxLayout(saveModifiedMessageBox.get()); + QHBoxLayout* footerLayout = new QHBoxLayout(savePrefabDialog.get()); if (useSaveAllPrefabsPreference) { - QFrame* footerSeparatorLine = new QFrame(); - footerSeparatorLine->setObjectName("FooterSeparatorLine"); + QFrame* footerSeparatorLine = new QFrame(savePrefabDialog.get()); + footerSeparatorLine->setObjectName(FooterSeparatorLine); footerSeparatorLine->setFrameShape(QFrame::HLine); contentLayout->addWidget(footerSeparatorLine); - QLabel* prefabSavePreferenceHint = - new QLabel("You can prevent this window from showing in the future by updating your global save preferences."); + QLabel* prefabSavePreferenceHint = new QLabel( + "You can prevent this window from showing in the future by updating your global save preferences.", + savePrefabDialog.get()); prefabSavePreferenceHint->setToolTip( "Go to 'Edit > Editor Settings > Global Preferences... > Global save preferences' to update your preference"); - prefabSavePreferenceHint->setObjectName("PrefabSavePreferenceHint"); + prefabSavePreferenceHint->setObjectName(PrefabSavePreferenceHint); footerLayout->addWidget(prefabSavePreferenceHint); } - QDialogButtonBox* prefabSaveConfirmationButtons = new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::No); + QDialogButtonBox* prefabSaveConfirmationButtons = + new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::No, savePrefabDialog.get()); footerLayout->addWidget(prefabSaveConfirmationButtons); contentLayout->addLayout(footerLayout); - connect(prefabSaveConfirmationButtons, &QDialogButtonBox::accepted, saveModifiedMessageBox.get(), &QDialog::accept); - connect(prefabSaveConfirmationButtons, &QDialogButtonBox::rejected, saveModifiedMessageBox.get(), &QDialog::reject); - AzQtComponents::StyleManager::setStyleSheet(saveModifiedMessageBox->parentWidget(), QStringLiteral("style:Editor.qss")); + connect(prefabSaveConfirmationButtons, &QDialogButtonBox::accepted, savePrefabDialog.get(), &QDialog::accept); + connect(prefabSaveConfirmationButtons, &QDialogButtonBox::rejected, savePrefabDialog.get(), &QDialog::reject); + AzQtComponents::StyleManager::setStyleSheet(savePrefabDialog->parentWidget(), QStringLiteral("style:Editor.qss")); - return AZStd::move(saveModifiedMessageBox); + return AZStd::move(savePrefabDialog); } AZStd::shared_ptr PrefabIntegrationManager::ConstructClosePrefabDialog(TemplateId templateId) { - AZStd::shared_ptr saveModifiedMessageBox = AZStd::make_shared(AzToolsFramework::GetActiveWindow()); - saveModifiedMessageBox->setWindowTitle("Unsaved files detected"); - AZStd::weak_ptr saveModifiedMessageBoxWeakPtr(saveModifiedMessageBox); - saveModifiedMessageBox->setObjectName("SavePrefabDialog"); + AZStd::shared_ptr closePrefabDialog = AZStd::make_shared(AzToolsFramework::GetActiveWindow()); + closePrefabDialog->setWindowTitle("Unsaved files detected"); + AZStd::weak_ptr closePrefabDialogWeakPtr(closePrefabDialog); + closePrefabDialog->setObjectName(ClosePrefabDialog); // Main Content section begins. - QVBoxLayout* contentLayout = new QVBoxLayout(saveModifiedMessageBox.get()); - QFrame* prefabSaveWarningFrame = new QFrame(saveModifiedMessageBox.get()); - QHBoxLayout* levelEntitiesSaveQuestionLayout = new QHBoxLayout(saveModifiedMessageBox.get()); - prefabSaveWarningFrame->setObjectName("PrefabSaveWarningFrame"); + QVBoxLayout* contentLayout = new QVBoxLayout(closePrefabDialog.get()); + QFrame* prefabSaveWarningFrame = new QFrame(closePrefabDialog.get()); + QHBoxLayout* levelEntitiesSaveQuestionLayout = new QHBoxLayout(closePrefabDialog.get()); + prefabSaveWarningFrame->setObjectName(PrefabSaveWarningFrame); // Add a warning icon next to save prefab warning. prefabSaveWarningFrame->setLayout(levelEntitiesSaveQuestionLayout); QPixmap warningIcon(QString(":/Notifications/warning.svg")); - QLabel* warningIconContainer = new QLabel(); + QLabel* warningIconContainer = new QLabel(closePrefabDialog.get()); warningIconContainer->setPixmap(warningIcon); warningIconContainer->setFixedWidth(warningIcon.width()); levelEntitiesSaveQuestionLayout->addWidget(warningIconContainer); // Ask user if they want to save entities in level. - QLabel* prefabSaveQuestionLabel = new QLabel("Do you want to save the below unsaved prefabs?", saveModifiedMessageBox.get()); + QLabel* prefabSaveQuestionLabel = new QLabel("Do you want to save the below unsaved prefabs?", closePrefabDialog.get()); levelEntitiesSaveQuestionLayout->addWidget(prefabSaveQuestionLabel); contentLayout->addWidget(prefabSaveWarningFrame); @@ -1244,60 +1256,59 @@ namespace AzToolsFramework s_prefabSystemComponentInterface->GetDirtyTemplatePaths(templateId, dirtyTemplatePaths); auto templateToSave = s_prefabSystemComponentInterface->FindTemplate(templateId); AZ::IO::Path templateToSaveFilePath = templateToSave->get().GetFilePath(); - AzQtComponents::Card* unsavedPrefabsCard = ConstructUnsavedPrefabsCard(templateId); - contentLayout->addWidget(unsavedPrefabsCard); + AZStd::unique_ptr unsavedPrefabsCard = ConstructUnsavedPrefabsCard(templateId); + contentLayout->addWidget(unsavedPrefabsCard.release()); contentLayout->addStretch(); - QHBoxLayout* footerLayout = new QHBoxLayout(saveModifiedMessageBox.get()); + QHBoxLayout* footerLayout = new QHBoxLayout(closePrefabDialog.get()); - QDialogButtonBox* prefabSaveConfirmationButtons = - new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Discard | QDialogButtonBox::Cancel); + QDialogButtonBox* prefabSaveConfirmationButtons = new QDialogButtonBox( + QDialogButtonBox::Save | QDialogButtonBox::Discard | QDialogButtonBox::Cancel, closePrefabDialog.get()); footerLayout->addWidget(prefabSaveConfirmationButtons); contentLayout->addLayout(footerLayout); - QObject::connect(prefabSaveConfirmationButtons, &QDialogButtonBox::accepted, saveModifiedMessageBox.get(), &QDialog::accept); - QObject::connect(prefabSaveConfirmationButtons, &QDialogButtonBox::rejected, saveModifiedMessageBox.get(), &QDialog::reject); + QObject::connect(prefabSaveConfirmationButtons, &QDialogButtonBox::accepted, closePrefabDialog.get(), &QDialog::accept); + QObject::connect(prefabSaveConfirmationButtons, &QDialogButtonBox::rejected, closePrefabDialog.get(), &QDialog::reject); QObject::connect( - prefabSaveConfirmationButtons, &QDialogButtonBox::clicked, saveModifiedMessageBox.get(), - [saveModifiedMessageBoxWeakPtr, prefabSaveConfirmationButtons](QAbstractButton* button) + prefabSaveConfirmationButtons, &QDialogButtonBox::clicked, closePrefabDialog.get(), + [closePrefabDialogWeakPtr, prefabSaveConfirmationButtons](QAbstractButton* button) { int prefabSaveSelection = prefabSaveConfirmationButtons->buttonRole(button); - saveModifiedMessageBoxWeakPtr.lock()->done(prefabSaveSelection); + closePrefabDialogWeakPtr.lock()->done(prefabSaveSelection); }); - AzQtComponents::StyleManager::setStyleSheet(saveModifiedMessageBox.get(), QStringLiteral("style:Editor.qss")); - return saveModifiedMessageBox; + AzQtComponents::StyleManager::setStyleSheet(closePrefabDialog.get(), QStringLiteral("style:Editor.qss")); + return closePrefabDialog; } - AzQtComponents::Card* PrefabIntegrationManager::ConstructUnsavedPrefabsCard(TemplateId templateId) + AZStd::unique_ptr PrefabIntegrationManager::ConstructUnsavedPrefabsCard(TemplateId templateId) { - FlowLayout* unsavedPrefabsLayout = new FlowLayout; + FlowLayout* unsavedPrefabsLayout = new FlowLayout(AzToolsFramework::GetActiveWindow()); AZStd::set dirtyTemplatePaths; s_prefabSystemComponentInterface->GetDirtyTemplatePaths(templateId, dirtyTemplatePaths); for (AZ::IO::PathView dirtyTemplatePath : dirtyTemplatePaths) { - QLabel* prefabNameLabel = new QLabel(QString("%1").arg(dirtyTemplatePath.Filename().Native().data())); - prefabNameLabel->setObjectName("UnsavedPrefabFileName"); + QLabel* prefabNameLabel = + new QLabel(QString("%1").arg(dirtyTemplatePath.Filename().Native().data()), AzToolsFramework::GetActiveWindow()); + prefabNameLabel->setObjectName(UnsavedPrefabFileName); prefabNameLabel->setWordWrap(true); prefabNameLabel->setToolTip(dirtyTemplatePath.Native().data()); prefabNameLabel->setProperty("FilePath", dirtyTemplatePath.Native().data()); unsavedPrefabsLayout->addWidget(prefabNameLabel); } - AzQtComponents::Card* unsavedPrefabsContainer = new AzQtComponents::Card; + AZStd::unique_ptr unsavedPrefabsContainer = AZStd::make_unique(AzToolsFramework::GetActiveWindow()); unsavedPrefabsContainer->setObjectName("SaveDependentPrefabsCard"); unsavedPrefabsContainer->setTitle("Unsaved Prefabs"); unsavedPrefabsContainer->header()->setHasContextMenu(false); unsavedPrefabsContainer->header()->setIcon(QIcon(QStringLiteral(":/Entity/prefab_edit.svg"))); - QFrame* unsavedPrefabsFrame = new QFrame(unsavedPrefabsContainer); + QFrame* unsavedPrefabsFrame = new QFrame(unsavedPrefabsContainer.get()); unsavedPrefabsFrame->setLayout(unsavedPrefabsLayout); - QScrollArea* unsavedPrefabsScrollArea = new QScrollArea(); + QScrollArea* unsavedPrefabsScrollArea = new QScrollArea(unsavedPrefabsContainer.get()); unsavedPrefabsScrollArea->setWidget(unsavedPrefabsFrame); - //unsavedPrefabsScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); unsavedPrefabsScrollArea->setWidgetResizable(true); - unsavedPrefabsScrollArea->setObjectName("SavePrefabsCardContent"); unsavedPrefabsContainer->setContentWidget(unsavedPrefabsScrollArea); return AZStd::move(unsavedPrefabsContainer); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.h b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.h index 64d3b652fc..3e66350932 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.h @@ -131,7 +131,7 @@ namespace AzToolsFramework static AZ::u32 GetSliceFlags(const AZ::Edit::ElementData* editData, const AZ::Edit::ClassData* classData); AZStd::shared_ptr ConstructClosePrefabDialog(TemplateId templateId); - AzQtComponents::Card* ConstructUnsavedPrefabsCard(TemplateId templateId); + AZStd::unique_ptr ConstructUnsavedPrefabsCard(TemplateId templateId); AZStd::unique_ptr ConstructSavePrefabDialog(TemplateId templateId, bool useSaveAllPrefabsPreference); void SavePrefabsInDialog(QDialog* unsavedPrefabsDialog);