From d23113e204c4296bccc70ea06625813fb309f8ef Mon Sep 17 00:00:00 2001 From: Jeremy HU Date: Sun, 11 Dec 2022 00:51:17 +1100 Subject: [PATCH] Fix bone removing --- application/sources/bone_manage_widget.cc | 13 +++++++++++++ application/sources/bone_manage_widget.h | 4 ++++ application/sources/bone_property_widget.cc | 2 +- application/sources/document.cc | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/application/sources/bone_manage_widget.cc b/application/sources/bone_manage_widget.cc index 023eb10c..0fafeb0b 100644 --- a/application/sources/bone_manage_widget.cc +++ b/application/sources/bone_manage_widget.cc @@ -65,6 +65,7 @@ BoneManageWidget::BoneManageWidget(Document* document, QWidget* parent) connect(m_propertyButton, &QPushButton::clicked, this, &BoneManageWidget::showSelectedBoneProperties); connect(this, &BoneManageWidget::groupOperationAdded, m_document, &Document::saveSnapshot); + connect(this, &BoneManageWidget::removeBone, m_document, &Document::removeBone); connect(this, &BoneManageWidget::customContextMenuRequested, this, &BoneManageWidget::showContextMenu); @@ -130,6 +131,14 @@ void BoneManageWidget::updateToolButtons() m_propertyButton->setEnabled(enablePropertyButton); } +void BoneManageWidget::removeSelectedBones() +{ + auto selectedBoneIds = m_bonePreviewGridWidget->getSelectedBoneIds(); + for (const auto& boneId : selectedBoneIds) + emit removeBone(boneId); + emit groupOperationAdded(); +} + void BoneManageWidget::showContextMenu(const QPoint& pos) { auto selectedBoneIds = m_bonePreviewGridWidget->getSelectedBoneIds(); @@ -138,5 +147,9 @@ void BoneManageWidget::showContextMenu(const QPoint& pos) QMenu contextMenu(this); + QAction deleteAction(tr("Delete"), this); + connect(&deleteAction, &QAction::triggered, this, &BoneManageWidget::removeSelectedBones); + contextMenu.addAction(&deleteAction); + contextMenu.exec(mapToGlobal(pos)); } diff --git a/application/sources/bone_manage_widget.h b/application/sources/bone_manage_widget.h index 3bca6e22..35d6c1cd 100644 --- a/application/sources/bone_manage_widget.h +++ b/application/sources/bone_manage_widget.h @@ -16,12 +16,16 @@ class BoneManageWidget : public QWidget { signals: void unselectAllOnCanvas(); void selectNodeOnCanvas(const dust3d::Uuid& nodeId); + void removeBone(const dust3d::Uuid& boneId); void groupOperationAdded(); public slots: void selectBoneByBoneId(const dust3d::Uuid& boneId); void showSelectedBoneProperties(); void showContextMenu(const QPoint& pos); +private slots: + void removeSelectedBones(); + public: BoneManageWidget(Document* document, QWidget* parent = nullptr); diff --git a/application/sources/bone_property_widget.cc b/application/sources/bone_property_widget.cc index bbd5f5e1..ca0fd450 100644 --- a/application/sources/bone_property_widget.cc +++ b/application/sources/bone_property_widget.cc @@ -165,7 +165,7 @@ void BonePropertyWidget::updateBoneJointComboBox() m_parentJointComboBox->clear(); for (size_t i = 0; i < parentBone->joints.size(); ++i) { m_parentJointComboBox->addItem(QString::number(i + 1)); - if (i == m_bone->attachBoneJointIndex) + if (i == (size_t)m_bone->attachBoneJointIndex) m_parentJointComboBox->setCurrentIndex(m_parentJointComboBox->count() - 1); } m_parentJointComboBox->setVisible(true); diff --git a/application/sources/document.cc b/application/sources/document.cc index f5d00c08..5931e921 100644 --- a/application/sources/document.cc +++ b/application/sources/document.cc @@ -2966,7 +2966,7 @@ void Document::applyBoneJoints(const dust3d::Uuid& boneId, const std::vector