From de0075bab4f2972a0c9e7870d6c5b027afeb45ad Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Mon, 9 Apr 2018 13:22:25 +0800 Subject: [PATCH] Add select all; fix undo. --- src/skeletondocument.cpp | 3 +++ src/skeletongraphicswidget.cpp | 49 ++++++++++++++++++++++++++++++++++ src/skeletongraphicswidget.h | 1 + 3 files changed, 53 insertions(+) diff --git a/src/skeletondocument.cpp b/src/skeletondocument.cpp index 544cf7ec..990e812c 100644 --- a/src/skeletondocument.cpp +++ b/src/skeletondocument.cpp @@ -596,6 +596,9 @@ void SkeletonDocument::fromSnapshot(const SkeletonSnapshot &snapshot) part.subdived = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "subdived")); partMap[part.id] = part; } + for (const auto &nodeIt: nodeMap) { + partMap[nodeIt.second.partId].nodeIds.push_back(nodeIt.first); + } for (const auto &partIdIt: snapshot.partIdList) { partIds.push_back(QUuid(partIdIt)); } diff --git a/src/skeletongraphicswidget.cpp b/src/skeletongraphicswidget.cpp index f9f4ef64..8738af46 100644 --- a/src/skeletongraphicswidget.cpp +++ b/src/skeletongraphicswidget.cpp @@ -92,6 +92,11 @@ void SkeletonGraphicsWidget::showContextMenu(const QPoint &pos) selectAllAction.setEnabled(!nodeItemMap.empty()); contextMenu.addAction(&selectAllAction); + QAction selectPartAllAction("Select Part", this); + connect(&selectPartAllAction, &QAction::triggered, this, &SkeletonGraphicsWidget::selectPartAll); + selectPartAllAction.setEnabled(!nodeItemMap.empty()); + contextMenu.addAction(&selectPartAllAction); + QAction unselectAllAction("Unselect All", this); connect(&unselectAllAction, &QAction::triggered, this, &SkeletonGraphicsWidget::unselectAll); unselectAllAction.setEnabled(!m_rangeSelectionSet.empty()); @@ -903,6 +908,50 @@ void SkeletonGraphicsWidget::readSkeletonNodeAndEdgeIdSetFromRangeSelection(std: } } +void SkeletonGraphicsWidget::selectPartAll() +{ + unselectAll(); + SkeletonProfile choosenProfile = SkeletonProfile::Main; + QUuid choosenPartId; + if (m_hoveredNodeItem) { + choosenProfile = m_hoveredNodeItem->profile(); + const SkeletonNode *node = m_document->findNode(m_hoveredNodeItem->id()); + if (node) + choosenPartId = node->partId; + } else if (m_hoveredEdgeItem) { + choosenProfile = m_hoveredEdgeItem->profile(); + const SkeletonEdge *edge = m_document->findEdge(m_hoveredEdgeItem->id()); + if (edge) + choosenPartId = edge->partId; + } + for (const auto &it: nodeItemMap) { + SkeletonGraphicsNodeItem *item = SkeletonProfile::Main == choosenProfile ? it.second.first : it.second.second; + const SkeletonNode *node = m_document->findNode(item->id()); + if (!node) + continue; + if (choosenPartId.isNull()) { + choosenPartId = node->partId; + } + if (node->partId != choosenPartId) + continue; + checkSkeletonItem(item, true); + m_rangeSelectionSet.insert(item); + } + for (const auto &it: edgeItemMap) { + SkeletonGraphicsEdgeItem *item = SkeletonProfile::Main == choosenProfile ? it.second.first : it.second.second; + const SkeletonEdge *edge = m_document->findEdge(item->id()); + if (!edge) + continue; + if (choosenPartId.isNull()) { + choosenPartId = edge->partId; + } + if (edge->partId != choosenPartId) + continue; + checkSkeletonItem(item, true); + m_rangeSelectionSet.insert(item); + } +} + void SkeletonGraphicsWidget::selectAll() { unselectAll(); diff --git a/src/skeletongraphicswidget.h b/src/skeletongraphicswidget.h index 04ebd4f0..10e5b28a 100644 --- a/src/skeletongraphicswidget.h +++ b/src/skeletongraphicswidget.h @@ -300,6 +300,7 @@ public slots: void deleteSelected(); void selectAll(); void unselectAll(); + void selectPartAll(); private slots: void turnaroundImageReady(); private: