Skip to content

Commit

Permalink
Fix bone removing
Browse files Browse the repository at this point in the history
  • Loading branch information
huxingyi committed Dec 10, 2022
1 parent 6b41921 commit d23113e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
13 changes: 13 additions & 0 deletions application/sources/bone_manage_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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();
Expand All @@ -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));
}
4 changes: 4 additions & 0 deletions application/sources/bone_manage_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion application/sources/bone_property_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion application/sources/document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2966,7 +2966,7 @@ void Document::applyBoneJoints(const dust3d::Uuid& boneId, const std::vector<dus

void Document::removeBone(const dust3d::Uuid& boneId)
{
if (boneMap.end() != boneMap.find(boneId))
if (boneMap.end() == boneMap.find(boneId))
return;

for (auto& it : nodeMap)
Expand Down

0 comments on commit d23113e

Please sign in to comment.