From 610bc978a8021ee34be33ca45ff90fb14ef444de Mon Sep 17 00:00:00 2001 From: huxingyi Date: Sun, 12 Apr 2020 09:55:53 +0930 Subject: [PATCH] Fix part tree UI - Add menu: Refresh QTreeWidgetItem sometimes discontine to refresh the widget, this is a fallback option to let user refresh the tree. - Remove the short menu Before, when left click on component, a short menu will popup, this make select nodes from part tree very difficult, so removed. - Fix part widget display at wrong place --- languages/dust3d_es_AR.ts | 4 ++++ languages/dust3d_it_IT.ts | 4 ++++ languages/dust3d_zh_CN.ts | 4 ++++ src/parttreewidget.cpp | 31 ++++++++++++++++++++----------- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/languages/dust3d_es_AR.ts b/languages/dust3d_es_AR.ts index c27b1ce7..5c2a2f38 100644 --- a/languages/dust3d_es_AR.ts +++ b/languages/dust3d_es_AR.ts @@ -705,6 +705,10 @@ Consejos: Select Seleccionar + + Refresh + + Copy Color Copiar Color diff --git a/languages/dust3d_it_IT.ts b/languages/dust3d_it_IT.ts index ac5ef3e0..76a58244 100755 --- a/languages/dust3d_it_IT.ts +++ b/languages/dust3d_it_IT.ts @@ -712,6 +712,10 @@ Suggerimenti: Select + + Refresh + + Copy Color diff --git a/languages/dust3d_zh_CN.ts b/languages/dust3d_zh_CN.ts index d3e26b2f..6cb2ed85 100644 --- a/languages/dust3d_zh_CN.ts +++ b/languages/dust3d_zh_CN.ts @@ -677,6 +677,10 @@ Tips: Select 选择 + + Refresh + 刷新 + Collapse All 收起所有 diff --git a/src/parttreewidget.cpp b/src/parttreewidget.cpp index c88e1334..cc3cfbb8 100644 --- a/src/parttreewidget.cpp +++ b/src/parttreewidget.cpp @@ -232,19 +232,19 @@ void PartTreeWidget::handleSingleClick(const QPoint &pos) } } } - showMenu(); + //showMenu(); return; } else { m_shiftStartComponentId = componentId; } selectComponent(componentId, multiple); - showMenu(); + //showMenu(); return; } if (!multiple) selectComponent(QUuid()); - showMenu(); + //showMenu(); } void PartTreeWidget::mousePressEvent(QMouseEvent *event) @@ -609,6 +609,7 @@ void PartTreeWidget::showContextMenu(const QPoint &pos, bool shorted) QAction unlockAction(tr("Unlock"), this); unlockAction.setIcon(Theme::awesome()->icon(fa::unlock)); QAction selectAction(tr("Select"), this); + QAction refreshAction(tr("Refresh"), this); QAction copyColorAction(tr("Copy Color"), this); QAction pasteColorAction(tr("Paste Color"), this); @@ -624,6 +625,11 @@ void PartTreeWidget::showContextMenu(const QPoint &pos, bool shorted) } } + connect(&refreshAction, &QAction::triggered, [=]() { + componentChildrenChanged(QUuid()); + }); + contextMenu.addAction(&refreshAction); + if (nullptr != component && nullptr != part) { connect(&selectAction, &QAction::triggered, [=]() { emit addPartToSelection(component->linkToPartId); @@ -1017,14 +1023,12 @@ void PartTreeWidget::addComponentChildrenToItem(QUuid componentId, QTreeWidgetIt if (nullptr == parentComponent) return; - const QTreeWidgetItem *scrollToItem = nullptr; for (const auto &childId: parentComponent->childrenIds) { const Component *component = m_document->findComponent(childId); if (nullptr == component) continue; if (!component->linkToPartId.isNull()) { QTreeWidgetItem *item = new QTreeWidgetItem(); - scrollToItem = item; parentItem->addChild(item); item->setData(0, Qt::UserRole, QVariant(component->id.toString())); item->setFlags(item->flags() & ~(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable)); @@ -1036,7 +1040,6 @@ void PartTreeWidget::addComponentChildrenToItem(QUuid componentId, QTreeWidgetIt m_partItemMap[partId] = item; } else { QTreeWidgetItem *item = new QTreeWidgetItem(QStringList(component->name)); - scrollToItem = item; parentItem->addChild(item); item->setData(0, Qt::UserRole, QVariant(component->id.toString())); item->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator); @@ -1047,9 +1050,6 @@ void PartTreeWidget::addComponentChildrenToItem(QUuid componentId, QTreeWidgetIt } updateComponentSelectState(childId, isComponentSelected(childId)); } - - if (nullptr != scrollToItem) - QTreeWidget::scrollToItem(scrollToItem); } void PartTreeWidget::partComponentChecked(QUuid partId) @@ -1100,8 +1100,8 @@ void PartTreeWidget::removeComponentDelayedTimer(const QUuid &componentId) { auto findTimer = m_delayedComponentTimers.find(componentId); if (findTimer != m_delayedComponentTimers.end()) { - delete findTimer->second; m_delayedComponentTimers.erase(findTimer); + findTimer->second->deleteLater(); } } @@ -1114,6 +1114,15 @@ void PartTreeWidget::reloadComponentChildren(const QUuid &componentId) } deleteItemChildren(parentItem); addComponentChildrenToItem(componentId, parentItem); + + // Fix the last item show in the wrong place sometimes + int childCount = invisibleRootItem()->childCount(); + if (childCount > 0) { + QTreeWidgetItem *lastItem = invisibleRootItem()->child(childCount - 1); + bool isExpanded = lastItem->isExpanded(); + lastItem->setExpanded(!isExpanded); + lastItem->setExpanded(isExpanded); + } } void PartTreeWidget::removeAllContent() @@ -1137,7 +1146,7 @@ void PartTreeWidget::componentRemoved(QUuid componentId) void PartTreeWidget::componentAdded(QUuid componentId) { - // ignore + // void } void PartTreeWidget::partRemoved(QUuid partId)