/* * 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. * */ // Original file Copyright Crytek GMBH or its affiliates, used under license. #include "StdAfx.h" #include "TrackViewFBXImportPreviewDialog.h" #include #include class FBXImportModel : public QAbstractListModel { public: FBXImportModel(CTrackViewFBXImportPreviewDialog::TItemsMap& map, QObject* parent = nullptr) : QAbstractListModel(parent) , m_map(map) { } int rowCount(const QModelIndex& parent = QModelIndex()) const override { return parent.isValid() ? 0 : m_map.size(); } Qt::ItemFlags flags(const QModelIndex& index) const override { return QAbstractListModel::flags(index) | Qt::ItemIsUserCheckable; } QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override { if (!index.isValid() || index.row() >= m_map.size()) { return QVariant(); } auto it = m_map.begin() + index.row(); switch (role) { case Qt::DisplayRole: return it->name; case Qt::CheckStateRole: return it->checked ? Qt::Checked : Qt::Unchecked; default: return QVariant(); } } bool setData(const QModelIndex& index, const QVariant& data, int role = Qt::EditRole) override { if (!index.isValid() || index.row() >= m_map.size()) { return false; } auto it = m_map.begin() + index.row(); switch (role) { case Qt::CheckStateRole: it->checked = (data.toInt() == Qt::Checked); emit dataChanged(index, index, QVector(1, Qt::CheckStateRole)); return true; default: return false; } } void setAllItemsChecked(bool checked) { if (m_map.empty()) { return; } for (auto it : m_map) { it.checked = checked; } emit dataChanged(index(0, 0), index(m_map.size() - 1, 0), QVector(1, Qt::CheckStateRole)); } private: CTrackViewFBXImportPreviewDialog::TItemsMap& m_map; }; ////////////////////////////////////////////////////////////////////////// CTrackViewFBXImportPreviewDialog::CTrackViewFBXImportPreviewDialog(QWidget* parent) : QDialog(parent) , m_ui(new Ui::TrackViewFBXImportPreviewDialog) { m_ui->setupUi(this); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); setFixedSize(size()); connect(m_ui->buttonSelectAll, &QPushButton::clicked, this, &CTrackViewFBXImportPreviewDialog::OnBnSelectAllClicked); connect(m_ui->buttonUnselectAll, &QPushButton::clicked, this, &CTrackViewFBXImportPreviewDialog::OnBnUnselectAllClicked); } CTrackViewFBXImportPreviewDialog::~CTrackViewFBXImportPreviewDialog() { } ////////////////////////////////////////////////////////////////////////// int CTrackViewFBXImportPreviewDialog::exec() { m_ui->m_tree->setModel(new FBXImportModel(m_fBXItemNames, this)); return QDialog::exec(); } ////////////////////////////////////////////////////////////////////////// void CTrackViewFBXImportPreviewDialog::AddTreeItem(const QString& objectName) { m_fBXItemNames.push_back(Item { objectName, true }); } bool CTrackViewFBXImportPreviewDialog::IsObjectSelected(const QString& objectName) const { for (auto it : m_fBXItemNames) { if (it.name == objectName) { return it.checked; } } return false; }; void CTrackViewFBXImportPreviewDialog::OnBnSelectAllClicked() { static_cast(m_ui->m_tree->model())->setAllItemsChecked(true); } void CTrackViewFBXImportPreviewDialog::OnBnUnselectAllClicked() { static_cast(m_ui->m_tree->model())->setAllItemsChecked(false); } #include