From ef990cd4b41247857c77f82d93d180a9ef661feb Mon Sep 17 00:00:00 2001 From: karlis <2995621482@qq.com> Date: Thu, 9 Mar 2023 16:32:00 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E7=BD=AE=E4=BA=86LayerTree=E7=9A=84?= =?UTF-8?q?=E5=8F=B3=E9=94=AE=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Editor/RightBar/LayerTreeWidget.cpp | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp index 9424203..f309ba4 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp @@ -35,32 +35,31 @@ void LayerTreeWidget::popMenu(const QPoint &pos) QMenu menu; QTreeWidgetItem *item = itemAt(pos); this->selectedItem = item; - // TODO - menu.addAction(QString::fromLocal8Bit("创建子节点"), this, &LayerTreeWidget::onRenameEvent); - //if (item != root->getQTreeItem()) - //{ - menu.addAction(QString::fromLocal8Bit("重命名"), this, &LayerTreeWidget::onRenameEvent); - // menu.addAction("Copy", this, &LayerTreeWidget::onRenameEvent); - if (item != nullptr && item->childCount() > 0) - menu.addAction(QString::fromLocal8Bit("删除(保留子节点)"), this, [this]() { - if (this->selectedItem == nullptr) - return; - auto layer = this->selectedItem->data(0, Qt::UserRole).value(); + if (item != nullptr) { + auto layer = this->selectedItem->data(0, Qt::UserRole).value(); + if (layer != nullptr) { + if (typeid(*layer) == typeid(FolderLayerWrapper)) { + menu.addAction(QString::fromLocal8Bit("创建子节点"), this, &LayerTreeWidget::onRenameEvent); + menu.addAction(QString::fromLocal8Bit("删除(保留子节点)"), this, [this]() { + auto layer = this->selectedItem->data(0, Qt::UserRole).value(); layer->delSelf(); layer->getParent()->removeChild(layer); this->refresh(); emit requireRefreshPreview(); - }); - menu.addAction(QString::fromLocal8Bit("删除"), this, [this]() { - if (this->selectedItem == nullptr) - return; - auto layer = this->selectedItem->data(0, Qt::UserRole).value(); - layer->del(); - layer->getParent()->removeChild(layer); - this->refresh(); - emit requireRefreshPreview(); - }); - //} + }); + } + if (layer != root) { + menu.addAction(QString::fromLocal8Bit("删除"), this, [this]() { + auto layer = this->selectedItem->data(0, Qt::UserRole).value(); + layer->del(); + layer->getParent()->removeChild(layer); + this->refresh(); + emit requireRefreshPreview(); + }); + menu.addAction(QString::fromLocal8Bit("重命名"), this, &LayerTreeWidget::onRenameEvent); + } + } + } menu.exec(mapToGlobal(pos)); }