#include "bone_preview_grid_widget.h" #include "bone_list_model.h" #include BonePreviewGridWidget::BonePreviewGridWidget(Document* document, QWidget* parent) : PreviewGridView(parent) , m_document(document) { m_boneListModel = std::make_unique(m_document); setModel(m_boneListModel.get()); connect(this, &BonePreviewGridWidget::doubleClicked, [this](const QModelIndex& index) { auto boneId = this->boneListModel()->modelIndexToBoneId(index); for (const auto& nodeIt : m_document->nodeMap) { if (nodeIt.second.boneIds.end() == nodeIt.second.boneIds.find(boneId)) continue; emit this->selectNodeOnCanvas(nodeIt.first); } }); } BoneListModel* BonePreviewGridWidget::boneListModel() { return m_boneListModel.get(); } std::vector BonePreviewGridWidget::getSelectedBones() const { std::vector bones; QModelIndexList selected = selectionModel()->selectedIndexes(); for (const auto& it : selected) { const auto& bone = m_boneListModel->modelIndexToBone(it); if (nullptr == bone) continue; bones.push_back(bone); } return bones; } std::vector BonePreviewGridWidget::getSelectedBoneIds() const { std::vector boneIds; QModelIndexList selected = selectionModel()->selectedIndexes(); for (const auto& it : selected) { const auto& boneId = m_boneListModel->modelIndexToBoneId(it); if (boneId.isNull()) continue; boneIds.push_back(boneId); } return boneIds; }