TrackViewFBXImportPreviewDialog.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 "EditorDefs.h"
  9. #include "TrackViewFBXImportPreviewDialog.h"
  10. // Qt
  11. #include <QAbstractListModel>
  12. AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
  13. #include <ui_TrackViewFBXImportPreviewDialog.h>
  14. AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
  15. class FBXImportModel
  16. : public QAbstractListModel
  17. {
  18. public:
  19. FBXImportModel(CTrackViewFBXImportPreviewDialog::TItemsMap& map, QObject* parent = nullptr)
  20. : QAbstractListModel(parent)
  21. , m_map(map)
  22. {
  23. }
  24. int rowCount(const QModelIndex& parent = QModelIndex()) const override
  25. {
  26. return parent.isValid() ? 0 : m_map.size();
  27. }
  28. Qt::ItemFlags flags(const QModelIndex& index) const override
  29. {
  30. return QAbstractListModel::flags(index) | Qt::ItemIsUserCheckable;
  31. }
  32. QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override
  33. {
  34. if (!index.isValid() || index.row() >= m_map.size())
  35. {
  36. return QVariant();
  37. }
  38. auto it = m_map.begin() + index.row();
  39. switch (role)
  40. {
  41. case Qt::DisplayRole:
  42. return it->name;
  43. case Qt::CheckStateRole:
  44. return it->checked ? Qt::Checked : Qt::Unchecked;
  45. default:
  46. return QVariant();
  47. }
  48. }
  49. bool setData(const QModelIndex& index, const QVariant& data, int role = Qt::EditRole) override
  50. {
  51. if (!index.isValid() || index.row() >= m_map.size())
  52. {
  53. return false;
  54. }
  55. auto it = m_map.begin() + index.row();
  56. switch (role)
  57. {
  58. case Qt::CheckStateRole:
  59. it->checked = (data.toInt() == Qt::Checked);
  60. emit dataChanged(index, index, QVector<int>(1, Qt::CheckStateRole));
  61. return true;
  62. default:
  63. return false;
  64. }
  65. }
  66. void setAllItemsChecked(bool checked)
  67. {
  68. if (m_map.empty())
  69. {
  70. return;
  71. }
  72. for (auto it : m_map)
  73. {
  74. it.checked = checked;
  75. }
  76. emit dataChanged(index(0, 0), index(m_map.size() - 1, 0), QVector<int>(1, Qt::CheckStateRole));
  77. }
  78. private:
  79. CTrackViewFBXImportPreviewDialog::TItemsMap& m_map;
  80. };
  81. //////////////////////////////////////////////////////////////////////////
  82. CTrackViewFBXImportPreviewDialog::CTrackViewFBXImportPreviewDialog(QWidget* parent)
  83. : QDialog(parent)
  84. , m_ui(new Ui::TrackViewFBXImportPreviewDialog)
  85. {
  86. m_ui->setupUi(this);
  87. setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
  88. setFixedSize(size());
  89. connect(m_ui->buttonSelectAll, &QPushButton::clicked, this, &CTrackViewFBXImportPreviewDialog::OnBnSelectAllClicked);
  90. connect(m_ui->buttonUnselectAll, &QPushButton::clicked, this, &CTrackViewFBXImportPreviewDialog::OnBnUnselectAllClicked);
  91. }
  92. CTrackViewFBXImportPreviewDialog::~CTrackViewFBXImportPreviewDialog()
  93. {
  94. }
  95. //////////////////////////////////////////////////////////////////////////
  96. int CTrackViewFBXImportPreviewDialog::exec()
  97. {
  98. m_ui->m_tree->setModel(new FBXImportModel(m_fBXItemNames, this));
  99. return QDialog::exec();
  100. }
  101. //////////////////////////////////////////////////////////////////////////
  102. void CTrackViewFBXImportPreviewDialog::AddTreeItem(const QString& objectName)
  103. {
  104. m_fBXItemNames.push_back(Item { objectName, true });
  105. }
  106. bool CTrackViewFBXImportPreviewDialog::IsObjectSelected(const QString& objectName) const
  107. {
  108. for (auto it : m_fBXItemNames)
  109. {
  110. if (it.name == objectName)
  111. {
  112. return it.checked;
  113. }
  114. }
  115. return false;
  116. };
  117. void CTrackViewFBXImportPreviewDialog::OnBnSelectAllClicked()
  118. {
  119. static_cast<FBXImportModel*>(m_ui->m_tree->model())->setAllItemsChecked(true);
  120. }
  121. void CTrackViewFBXImportPreviewDialog::OnBnUnselectAllClicked()
  122. {
  123. static_cast<FBXImportModel*>(m_ui->m_tree->model())->setAllItemsChecked(false);
  124. }
  125. #include <moc_TrackViewFBXImportPreviewDialog.cpp>