GemListHeaderWidget.cpp 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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/GemItemDelegate.h>
  9. #include <GemCatalog/GemListHeaderWidget.h>
  10. #include <AzQtComponents/Components/TagSelector.h>
  11. #include <QAbstractItemModel>
  12. #include <QItemSelectionModel>
  13. #include <QLabel>
  14. #include <QSpacerItem>
  15. #include <QStandardItemModel>
  16. #include <QVBoxLayout>
  17. namespace O3DE::ProjectManager
  18. {
  19. GemListHeaderWidget::GemListHeaderWidget(GemSortFilterProxyModel* proxyModel, QWidget* parent)
  20. : QFrame(parent)
  21. {
  22. QVBoxLayout* vLayout = new QVBoxLayout();
  23. vLayout->setMargin(0);
  24. setLayout(vLayout);
  25. setStyleSheet("background-color: #333333;");
  26. vLayout->addSpacing(13);
  27. // Top section
  28. QHBoxLayout* topLayout = new QHBoxLayout();
  29. topLayout->addSpacing(16);
  30. topLayout->setMargin(0);
  31. auto* tagWidget = new FilterTagWidgetContainer();
  32. // Adjust the proxy model and disable the given feature used for filtering.
  33. connect(tagWidget, &FilterTagWidgetContainer::TagRemoved, this, [=](QString tagName)
  34. {
  35. QSet<QString> filteredFeatureTags = proxyModel->GetFeatures();
  36. filteredFeatureTags.remove(tagName);
  37. proxyModel->SetFeatures(filteredFeatureTags);
  38. });
  39. // Reinitialize the tag widget in case the filter in the proxy model got invalided.
  40. connect(proxyModel, &GemSortFilterProxyModel::OnInvalidated, this, [=]
  41. {
  42. const QSet<QString>& tagSet = proxyModel->GetFeatures();
  43. QVector<QString> sortedTags(tagSet.begin(), tagSet.end());
  44. std::sort(sortedTags.begin(), sortedTags.end());
  45. tagWidget->Reinit(sortedTags);
  46. });
  47. topLayout->addWidget(tagWidget);
  48. topLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Expanding));
  49. QLabel* showCountLabel = new QLabel();
  50. showCountLabel->setObjectName("GemCatalogHeaderShowCountLabel");
  51. topLayout->addWidget(showCountLabel);
  52. QPushButton* refreshButton = new QPushButton();
  53. refreshButton->setObjectName("RefreshButton");
  54. connect(refreshButton, &QPushButton::clicked, [this] { emit OnRefresh(/*refreshRemoteRepos*/true); });
  55. topLayout->addWidget(refreshButton);
  56. auto refreshGemCountUI = [=]() {
  57. const int numGemsShown = proxyModel->rowCount();
  58. showCountLabel->setText(QString(tr("showing %1 Gems")).arg(numGemsShown));
  59. };
  60. connect(proxyModel, &GemSortFilterProxyModel::OnInvalidated, this, refreshGemCountUI);
  61. connect(proxyModel->GetSourceModel(), &GemModel::dataChanged, this, refreshGemCountUI);
  62. topLayout->addSpacing(GemItemDelegate::s_contentMargins.right() + GemItemDelegate::s_borderWidth);
  63. vLayout->addLayout(topLayout);
  64. vLayout->addSpacing(13);
  65. // Separating line
  66. QFrame* hLine = new QFrame();
  67. hLine->setFrameShape(QFrame::HLine);
  68. hLine->setObjectName("horizontalSeparatingLine");
  69. vLayout->addWidget(hLine);
  70. vLayout->addSpacing(GemItemDelegate::s_contentMargins.top());
  71. }
  72. } // namespace O3DE::ProjectManager