GemDependenciesDialog.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <GemCatalog/GemDependenciesDialog.h>
  9. #include <GemCatalog/GemModel.h>
  10. #include <AzQtComponents/Components/FlowLayout.h>
  11. #include <QVBoxLayout>
  12. #include <QLabel>
  13. #include <QDialogButtonBox>
  14. #include <QCheckBox>
  15. namespace O3DE::ProjectManager
  16. {
  17. GemDependenciesDialog::GemDependenciesDialog(GemModel* gemModel, QWidget *parent)
  18. : QDialog(parent)
  19. {
  20. setWindowTitle(tr("Dependent Gems"));
  21. setObjectName("GemDependenciesDialog");
  22. setAttribute(Qt::WA_DeleteOnClose);
  23. setModal(true);
  24. QVBoxLayout* layout = new QVBoxLayout();
  25. // layout margin/alignment cannot be set with qss
  26. layout->setMargin(15);
  27. layout->setAlignment(Qt::AlignTop);
  28. setLayout(layout);
  29. // message
  30. QLabel* instructionLabel = new QLabel(
  31. tr("The following gem dependencies are no longer needed and will be deactivated.<br><br>"
  32. "To keep these Gems enabled, select the checkbox next to it."));
  33. layout->addWidget(instructionLabel);
  34. // checkboxes
  35. FlowLayout* flowLayout = new FlowLayout();
  36. QVector<QModelIndex> gemsToRemove = gemModel->GatherGemsToBeRemoved(/*includeDependencies=*/true);
  37. for (const QModelIndex& gem : gemsToRemove)
  38. {
  39. if (GemModel::WasPreviouslyAddedDependency(gem))
  40. {
  41. QCheckBox* checkBox = new QCheckBox(GemModel::GetName(gem));
  42. connect(checkBox, &QCheckBox::stateChanged, this,
  43. [=](int state)
  44. {
  45. GemModel::SetIsAdded(*gemModel, gem, /*isAdded=*/state == Qt::Checked);
  46. });
  47. flowLayout->addWidget(checkBox);
  48. }
  49. }
  50. layout->addLayout(flowLayout);
  51. layout->addSpacing(10);
  52. layout->addStretch(1);
  53. // buttons
  54. QDialogButtonBox* dialogButtons = new QDialogButtonBox(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
  55. connect(dialogButtons, &QDialogButtonBox::accepted, this, &QDialog::accept);
  56. connect(dialogButtons, &QDialogButtonBox::rejected, this,
  57. [=]()
  58. {
  59. // de-select any Gems the user selected because they're canceling
  60. for (const QModelIndex& gem : gemsToRemove)
  61. {
  62. if (GemModel::WasPreviouslyAddedDependency(gem) && GemModel::IsAdded(gem))
  63. {
  64. GemModel::SetIsAdded(*gemModel, gem, /*isAdded=*/false);
  65. }
  66. }
  67. reject();
  68. });
  69. layout->addWidget(dialogButtons);
  70. }
  71. } // namespace O3DE::ProjectManager