#include "LayerTreeViewMenuProvider.h" #include "LayerTreeView.h" #include "LayerTreeModel.h" #include "LayerTreeNode.h" #include "HPPA.h" #include #include LayerTreeViewMenuProvider::LayerTreeViewMenuProvider(LayerTreeView* view, QObject* parent) : QObject(parent), m_view(view) { } QMenu* LayerTreeViewMenuProvider::createContextMenu() { m_contextIndex = m_view->currentIndex(); QMenu* menu = new QMenu(); if (!m_contextIndex.isValid()) { return menu; } const LayerTreeModel* model = static_cast(m_contextIndex.model()); if (!model) { return menu; } LayerTreeNode* node = static_cast(m_contextIndex.internalPointer()); if (!node) { return menu; } if (node->type() == LayerTreeNode::Type::Layer) { QAction* removeLayerAction = new QAction(QStringLiteral("移除图层"), menu); connect(removeLayerAction, &QAction::triggered, HPPA::instance(), &HPPA::removeLayerByTreeIndex); QAction* showColorImageAction = new QAction(QStringLiteral("显示彩色图像"), menu); connect(showColorImageAction, &QAction::triggered, HPPA::instance(), &HPPA::showColorImageByTreeIndex); menu->addAction(removeLayerAction); menu->addAction(showColorImageAction); } else if (node->type() == LayerTreeNode::Type::Image) { QAction* removeImageAction = new QAction(QStringLiteral("移除图像"), menu); connect(removeImageAction, &QAction::triggered, HPPA::instance(), &HPPA::removeImageByTreeIndex); menu->addAction(removeImageAction); } else if (node->type() == LayerTreeNode::Type::Group) { HPPA* app = HPPA::instance(); if (app && node == app->rasterGroupNode()) { QAction* removeAllAction = new QAction(QStringLiteral("移除所有图层"), menu); connect(removeAllAction, &QAction::triggered, app, &HPPA::removeAllLayersInRasterGroup); menu->addAction(removeAllAction); } } return menu; }