diff --git a/src/skeletongraphicswidget.cpp b/src/skeletongraphicswidget.cpp index 6aea4302..0191addd 100644 --- a/src/skeletongraphicswidget.cpp +++ b/src/skeletongraphicswidget.cpp @@ -40,7 +40,8 @@ SkeletonGraphicsWidget::SkeletonGraphicsWidget(const SkeletonDocument *document) m_hoveredOriginItem(nullptr), m_checkedOriginItem(nullptr), m_ikMoveUpdateVersion(0), - m_ikMover(nullptr) + m_ikMover(nullptr), + m_deferredRemoveTimer(nullptr) { setRenderHint(QPainter::Antialiasing, false); setBackgroundBrush(QBrush(QWidget::palette().color(QWidget::backgroundRole()), Qt::SolidPattern)); @@ -1180,8 +1181,58 @@ bool SkeletonGraphicsWidget::mouseDoubleClick(QMouseEvent *event) 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() { + if (m_rangeSelectionSet.empty()) + return; + + std::set nodeIdSet; + std::set 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()) { emit batchChangeBegin(); std::set nodeIdSet; @@ -1195,7 +1246,7 @@ void SkeletonGraphicsWidget::deleteSelected() } emit batchChangeEnd(); emit groupOperationAdded(); - } + }*/ } bool SkeletonGraphicsWidget::keyPress(QKeyEvent *event) diff --git a/src/skeletongraphicswidget.h b/src/skeletongraphicswidget.h index 70855606..09c3aaf9 100644 --- a/src/skeletongraphicswidget.h +++ b/src/skeletongraphicswidget.h @@ -11,6 +11,7 @@ #include #include #include +#include #include "skeletondocument.h" #include "turnaroundloader.h" #include "theme.h" @@ -461,6 +462,7 @@ public slots: void ikMove(QUuid endEffectorId, QVector3D target); void ikMoveReady(); void setSelectedNodesBoneMark(SkeletonBoneMark boneMark); + void timeToRemoveDeferredNodesAndEdges(); private slots: void turnaroundImageReady(); private: @@ -509,14 +511,17 @@ private: //need initalize SkeletonGraphicsOriginItem *m_checkedOriginItem; unsigned long long m_ikMoveUpdateVersion; SkeletonIkMover *m_ikMover; + QTimer *m_deferredRemoveTimer; +private: QVector3D m_ikMoveTarget; QUuid m_ikMoveEndEffectorId; -private: std::set m_rangeSelectionSet; QPoint m_lastGlobalPos; QPointF m_lastScenePos; QPointF m_rangeSelectionStartPos; QUuid m_lastCheckedPart; + std::set m_deferredRemoveNodeIds; + std::set m_deferredRemoveEdgeIds; }; class SkeletonGraphicsContainerWidget : public QWidget