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)); }