Fix block caused by delete operation

master
Jeremy Hu 2018-06-15 19:54:13 +08:00
parent e26095981b
commit 082b470f8a
2 changed files with 59 additions and 3 deletions

View File

@ -40,7 +40,8 @@ SkeletonGraphicsWidget::SkeletonGraphicsWidget(const SkeletonDocument *document)
m_hoveredOriginItem(nullptr), m_hoveredOriginItem(nullptr),
m_checkedOriginItem(nullptr), m_checkedOriginItem(nullptr),
m_ikMoveUpdateVersion(0), m_ikMoveUpdateVersion(0),
m_ikMover(nullptr) m_ikMover(nullptr),
m_deferredRemoveTimer(nullptr)
{ {
setRenderHint(QPainter::Antialiasing, false); setRenderHint(QPainter::Antialiasing, false);
setBackgroundBrush(QBrush(QWidget::palette().color(QWidget::backgroundRole()), Qt::SolidPattern)); setBackgroundBrush(QBrush(QWidget::palette().color(QWidget::backgroundRole()), Qt::SolidPattern));
@ -1180,8 +1181,58 @@ bool SkeletonGraphicsWidget::mouseDoubleClick(QMouseEvent *event)
return false; return false;
} }
void SkeletonGraphicsWidget::timeToRemoveDeferredNodesAndEdges()
{
delete m_deferredRemoveTimer;
m_deferredRemoveTimer = nullptr;
bool committed = false;
if (!committed && !m_deferredRemoveEdgeIds.empty()) {
const auto &it = m_deferredRemoveEdgeIds.begin();
const auto edgeId = *it;
m_deferredRemoveEdgeIds.erase(it);
emit removeEdge(edgeId);
committed = true;
}
if (!committed && !m_deferredRemoveNodeIds.empty()) {
const auto &it = m_deferredRemoveNodeIds.begin();
const auto nodeId = *it;
m_deferredRemoveNodeIds.erase(it);
emit removeNode(nodeId);
committed = true;
}
if (committed) {
m_deferredRemoveTimer = new QTimer(this);
connect(m_deferredRemoveTimer, &QTimer::timeout, this, &SkeletonGraphicsWidget::timeToRemoveDeferredNodesAndEdges);
m_deferredRemoveTimer->start(0);
} else {
emit groupOperationAdded();
}
}
void SkeletonGraphicsWidget::deleteSelected() void SkeletonGraphicsWidget::deleteSelected()
{ {
if (m_rangeSelectionSet.empty())
return;
std::set<QUuid> nodeIdSet;
std::set<QUuid> edgeIdSet;
readSkeletonNodeAndEdgeIdSetFromRangeSelection(&nodeIdSet, &edgeIdSet);
for (const auto &it: nodeIdSet) {
m_deferredRemoveNodeIds.insert(it);
}
for (const auto &it: edgeIdSet) {
m_deferredRemoveEdgeIds.insert(it);
}
if (nullptr == m_deferredRemoveTimer) {
timeToRemoveDeferredNodesAndEdges();
}
/*
if (!m_rangeSelectionSet.empty()) { if (!m_rangeSelectionSet.empty()) {
emit batchChangeBegin(); emit batchChangeBegin();
std::set<QUuid> nodeIdSet; std::set<QUuid> nodeIdSet;
@ -1195,7 +1246,7 @@ void SkeletonGraphicsWidget::deleteSelected()
} }
emit batchChangeEnd(); emit batchChangeEnd();
emit groupOperationAdded(); emit groupOperationAdded();
} }*/
} }
bool SkeletonGraphicsWidget::keyPress(QKeyEvent *event) bool SkeletonGraphicsWidget::keyPress(QKeyEvent *event)

View File

@ -11,6 +11,7 @@
#include <QThread> #include <QThread>
#include <cmath> #include <cmath>
#include <set> #include <set>
#include <QTimer>
#include "skeletondocument.h" #include "skeletondocument.h"
#include "turnaroundloader.h" #include "turnaroundloader.h"
#include "theme.h" #include "theme.h"
@ -461,6 +462,7 @@ public slots:
void ikMove(QUuid endEffectorId, QVector3D target); void ikMove(QUuid endEffectorId, QVector3D target);
void ikMoveReady(); void ikMoveReady();
void setSelectedNodesBoneMark(SkeletonBoneMark boneMark); void setSelectedNodesBoneMark(SkeletonBoneMark boneMark);
void timeToRemoveDeferredNodesAndEdges();
private slots: private slots:
void turnaroundImageReady(); void turnaroundImageReady();
private: private:
@ -509,14 +511,17 @@ private: //need initalize
SkeletonGraphicsOriginItem *m_checkedOriginItem; SkeletonGraphicsOriginItem *m_checkedOriginItem;
unsigned long long m_ikMoveUpdateVersion; unsigned long long m_ikMoveUpdateVersion;
SkeletonIkMover *m_ikMover; SkeletonIkMover *m_ikMover;
QTimer *m_deferredRemoveTimer;
private:
QVector3D m_ikMoveTarget; QVector3D m_ikMoveTarget;
QUuid m_ikMoveEndEffectorId; QUuid m_ikMoveEndEffectorId;
private:
std::set<QGraphicsItem *> m_rangeSelectionSet; std::set<QGraphicsItem *> m_rangeSelectionSet;
QPoint m_lastGlobalPos; QPoint m_lastGlobalPos;
QPointF m_lastScenePos; QPointF m_lastScenePos;
QPointF m_rangeSelectionStartPos; QPointF m_rangeSelectionStartPos;
QUuid m_lastCheckedPart; QUuid m_lastCheckedPart;
std::set<QUuid> m_deferredRemoveNodeIds;
std::set<QUuid> m_deferredRemoveEdgeIds;
}; };
class SkeletonGraphicsContainerWidget : public QWidget class SkeletonGraphicsContainerWidget : public QWidget