Add select by component

master
Jeremy Hu 2018-09-01 10:17:26 +08:00
parent b945ab9725
commit 717c8ef266
5 changed files with 49 additions and 0 deletions

View File

@ -603,6 +603,8 @@ SkeletonDocumentWindow::SkeletonDocumentWindow() :
connect(partTreeWidget, &SkeletonPartTreeWidget::lockDescendantComponents, m_document, &SkeletonDocument::lockDescendantComponents); connect(partTreeWidget, &SkeletonPartTreeWidget::lockDescendantComponents, m_document, &SkeletonDocument::lockDescendantComponents);
connect(partTreeWidget, &SkeletonPartTreeWidget::unlockDescendantComponents, m_document, &SkeletonDocument::unlockDescendantComponents); connect(partTreeWidget, &SkeletonPartTreeWidget::unlockDescendantComponents, m_document, &SkeletonDocument::unlockDescendantComponents);
connect(partTreeWidget, &SkeletonPartTreeWidget::addPartToSelection, graphicsWidget, &SkeletonGraphicsWidget::addPartToSelection);
connect(m_document, &SkeletonDocument::componentNameChanged, partTreeWidget, &SkeletonPartTreeWidget::componentNameChanged); connect(m_document, &SkeletonDocument::componentNameChanged, partTreeWidget, &SkeletonPartTreeWidget::componentNameChanged);
connect(m_document, &SkeletonDocument::componentChildrenChanged, partTreeWidget, &SkeletonPartTreeWidget::componentChildrenChanged); connect(m_document, &SkeletonDocument::componentChildrenChanged, partTreeWidget, &SkeletonPartTreeWidget::componentChildrenChanged);
connect(m_document, &SkeletonDocument::componentRemoved, partTreeWidget, &SkeletonPartTreeWidget::componentRemoved); connect(m_document, &SkeletonDocument::componentRemoved, partTreeWidget, &SkeletonPartTreeWidget::componentRemoved);

View File

@ -1939,6 +1939,41 @@ void SkeletonGraphicsWidget::addSelectEdge(QUuid edgeId)
hoverPart(QUuid()); hoverPart(QUuid());
} }
void SkeletonGraphicsWidget::addPartToSelection(QUuid partId)
{
SkeletonProfile choosenProfile = SkeletonProfile::Main;
if (m_hoveredNodeItem) {
choosenProfile = m_hoveredNodeItem->profile();
} else if (m_hoveredEdgeItem) {
choosenProfile = m_hoveredEdgeItem->profile();
}
QUuid choosenPartId = 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;
addItemToRangeSelection(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;
addItemToRangeSelection(item);
}
}
void SkeletonGraphicsWidget::selectPartAll() void SkeletonGraphicsWidget::selectPartAll()
{ {
unselectAll(); unselectAll();

View File

@ -433,6 +433,7 @@ public slots:
void selectAll(); void selectAll();
void unselectAll(); void unselectAll();
void selectPartAll(); void selectPartAll();
void addPartToSelection(QUuid partId);
void cut(); void cut();
void copy(); void copy();
void flipHorizontally(); void flipHorizontally();

View File

@ -97,6 +97,7 @@ void SkeletonPartTreeWidget::showContextMenu(const QPoint &pos)
QAction unlockAction(tr("Unlock"), this); QAction unlockAction(tr("Unlock"), this);
QAction invertAction(tr("Invert"), this); QAction invertAction(tr("Invert"), this);
QAction cancelInverseAction(tr("Cancel Inverse"), this); QAction cancelInverseAction(tr("Cancel Inverse"), this);
QAction selectAction(tr("Select"), this);
if (!component->linkToPartId.isNull()) { if (!component->linkToPartId.isNull()) {
emit checkPart(component->linkToPartId); emit checkPart(component->linkToPartId);
@ -128,6 +129,15 @@ void SkeletonPartTreeWidget::showContextMenu(const QPoint &pos)
} }
} else { } else {
if (!component->childrenIds.empty()) { if (!component->childrenIds.empty()) {
connect(&selectAction, &QAction::triggered, [=]() {
std::vector<QUuid> partIds;
m_document->collectComponentDescendantParts(componentId, partIds);
for (const auto &partId: partIds) {
emit addPartToSelection(partId);
}
});
contextMenu.addAction(&selectAction);
connect(&showAction, &QAction::triggered, [=]() { connect(&showAction, &QAction::triggered, [=]() {
emit showDescendantComponents(componentId); emit showDescendantComponents(componentId);
}); });

View File

@ -37,6 +37,7 @@ signals:
void showDescendantComponents(QUuid componentId); void showDescendantComponents(QUuid componentId);
void lockDescendantComponents(QUuid componentId); void lockDescendantComponents(QUuid componentId);
void unlockDescendantComponents(QUuid componentId); void unlockDescendantComponents(QUuid componentId);
void addPartToSelection(QUuid partId);
public: public:
SkeletonPartTreeWidget(const SkeletonDocument *document, QWidget *parent); SkeletonPartTreeWidget(const SkeletonDocument *document, QWidget *parent);
QTreeWidgetItem *findComponentItem(QUuid componentId); QTreeWidgetItem *findComponentItem(QUuid componentId);