132 lines
4.8 KiB
C++
132 lines
4.8 KiB
C++
|
|
#include "windLayerTreeViewMenuProvider.h"
|
|||
|
|
#include "qgslayertreeviewdefaultactions.h"
|
|||
|
|
#include <QMenu>
|
|||
|
|
#include <QAction>
|
|||
|
|
#include "qgslayertreenode.h"
|
|||
|
|
#include "qgslayertree.h"
|
|||
|
|
#include "qgsvectorlayer.h"
|
|||
|
|
#include "qgsmapcanvas.h"
|
|||
|
|
#include "qgsrasterlayerproperties.h"
|
|||
|
|
#include "qgsgui.h"
|
|||
|
|
#include "qgsproviderguiregistry.h"
|
|||
|
|
#include "qgsmeshlayerproperties.h"
|
|||
|
|
|
|||
|
|
|
|||
|
|
windLayerTreeViewMenuProvider::windLayerTreeViewMenuProvider(QgsLayerTreeView* view, QgsMapCanvas* canvas, QObject* parent)
|
|||
|
|
: QObject(parent)
|
|||
|
|
, mLayerTreeView(view)
|
|||
|
|
, mMapCanvas(canvas)
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
QMenu* windLayerTreeViewMenuProvider::createContextMenu()
|
|||
|
|
{
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>յIJ˵<C4B2>
|
|||
|
|
QMenu* menu = new QMenu();
|
|||
|
|
|
|||
|
|
// <20><>ȡͼ<C8A1><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>Ĭ<EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><CFA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ೣ<EFBFBD>õIJ˵<C4B2><CBB5><EFBFBD>ʵ<EFBFBD><CAB5>
|
|||
|
|
QgsLayerTreeViewDefaultActions* actions = mLayerTreeView->defaultActions();
|
|||
|
|
|
|||
|
|
// <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>λ<EFBFBD>ö<EFBFBD>Ӧ<EFBFBD><D3A6>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
QModelIndex index = mLayerTreeView->currentIndex();
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD>ڿհ״<D5B0><D7B4>Ҽ<EFBFBD><D2BC><EFBFBD>δѡ<CEB4><D1A1><EFBFBD>κνڵ㣩
|
|||
|
|
if (!index.isValid()) {
|
|||
|
|
|
|||
|
|
menu->addAction(actions->actionAddGroup(menu));
|
|||
|
|
menu->addAction(tr("&Expand All"), mLayerTreeView, &QgsLayerTreeView::expandAll);
|
|||
|
|
menu->addAction(tr("&Collapse All"), mLayerTreeView, &QgsLayerTreeView::collapseAll);
|
|||
|
|
return menu;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊͼ<CEAA><CDBC><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>
|
|||
|
|
QgsLayerTreeNode* node = mLayerTreeView->index2node(index);
|
|||
|
|
if (!node) {
|
|||
|
|
return menu; // <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD>ؿղ˵<D5B2>
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD>Ҽ<EFBFBD><D2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>
|
|||
|
|
if (QgsLayerTree::isGroup(node)) {
|
|||
|
|
menu->addAction(actions->actionZoomToGroup(mMapCanvas, menu));
|
|||
|
|
menu->addAction(actions->actionRemoveGroupOrLayer(menu));
|
|||
|
|
menu->addAction(actions->actionRenameGroupOrLayer(menu));
|
|||
|
|
}
|
|||
|
|
else if (QgsLayerTree::isLayer(node)) {
|
|||
|
|
|
|||
|
|
menu->addAction(actions->actionZoomToLayers(mMapCanvas, menu));
|
|||
|
|
menu->addAction(actions->actionZoomToSelection(mMapCanvas, menu));
|
|||
|
|
menu->addAction(actions->actionRenameGroupOrLayer(menu));
|
|||
|
|
menu->addAction(actions->actionShowInOverview(menu));
|
|||
|
|
menu->addAction(actions->actionRemoveGroupOrLayer(menu));
|
|||
|
|
|
|||
|
|
|
|||
|
|
QgsMapLayer* mapLayer = QgsLayerTree::toLayer(node)->layer();
|
|||
|
|
if (mapLayer) {
|
|||
|
|
// <20><><EFBFBD><EFBFBD>"<22><><EFBFBD>ŵ<EFBFBD>ͼ<EFBFBD><CDBC>"<22><><EFBFBD><EFBFBD>
|
|||
|
|
menu->addAction(actions->actionZoomToLayers(mMapCanvas, menu));
|
|||
|
|
// <20><><EFBFBD><EFBFBD>"ɾ<><C9BE>ͼ<EFBFBD><CDBC>"<22><>"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>"<22><><EFBFBD><EFBFBD>
|
|||
|
|
menu->addAction(actions->actionRemoveGroupOrLayer(menu));
|
|||
|
|
menu->addAction(actions->actionRenameGroupOrLayer(menu));
|
|||
|
|
|
|||
|
|
menu->addSeparator();
|
|||
|
|
|
|||
|
|
|
|||
|
|
if (mapLayer->type() == Qgis::LayerType::Raster) {
|
|||
|
|
QAction* rasterLayerPropertyAction = menu->addAction(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|||
|
|
QObject::connect(rasterLayerPropertyAction, &QAction::triggered, this, &windLayerTreeViewMenuProvider::showlayerpropertyDialog);
|
|||
|
|
}
|
|||
|
|
else if (mapLayer->type() == Qgis::LayerType::Mesh) {
|
|||
|
|
QAction* meshLayerPropertyAction = menu->addAction(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|||
|
|
QObject::connect(meshLayerPropertyAction, &QAction::triggered, this, &windLayerTreeViewMenuProvider::showlayerpropertyDialog);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return menu; // <20><><EFBFBD>ع<EFBFBD><D8B9><EFBFBD><EFBFBD>õIJ˵<C4B2>
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void windLayerTreeViewMenuProvider::showlayerpropertyDialog(bool flag)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
|
|||
|
|
QgsMapLayer* mapLayer = mLayerTreeView->currentLayer();
|
|||
|
|
if (!mapLayer) {
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
if (mapLayer->type()==Qgis::LayerType::Raster) {
|
|||
|
|
// collect factories from registered data providers
|
|||
|
|
QList<const QgsMapLayerConfigWidgetFactory*> providerFactories = QgsGui::providerGuiRegistry()->mapLayerConfigWidgetFactories(mapLayer);
|
|||
|
|
QgsRasterLayerProperties* rasterLayerPropertiesDialog = new QgsRasterLayerProperties(mapLayer, mMapCanvas, mMapCanvas);
|
|||
|
|
for (const QgsMapLayerConfigWidgetFactory* factory : std::as_const(providerFactories))
|
|||
|
|
{
|
|||
|
|
rasterLayerPropertiesDialog->addPropertiesPageFactory(factory);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
rasterLayerPropertiesDialog->restoreLastPage();
|
|||
|
|
|
|||
|
|
rasterLayerPropertiesDialog->setModal(true);
|
|||
|
|
rasterLayerPropertiesDialog->show();
|
|||
|
|
connect(rasterLayerPropertiesDialog, &QgsRasterLayerProperties::accepted, [rasterLayerPropertiesDialog] {
|
|||
|
|
rasterLayerPropertiesDialog->deleteLater();
|
|||
|
|
});
|
|||
|
|
connect(rasterLayerPropertiesDialog, &QgsRasterLayerProperties::rejected, [rasterLayerPropertiesDialog] {
|
|||
|
|
rasterLayerPropertiesDialog->deleteLater();
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
else if (mapLayer->type() == Qgis::LayerType::Mesh) {
|
|||
|
|
QList<const QgsMapLayerConfigWidgetFactory*> providerFactories = QgsGui::providerGuiRegistry()->mapLayerConfigWidgetFactories(mapLayer);
|
|||
|
|
|
|||
|
|
QgsMeshLayerProperties meshLayerPropertiesDialog(mapLayer, mMapCanvas, mMapCanvas);
|
|||
|
|
|
|||
|
|
for (const QgsMapLayerConfigWidgetFactory* factory : std::as_const(providerFactories))
|
|||
|
|
{
|
|||
|
|
meshLayerPropertiesDialog.addPropertiesPageFactory(factory);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
meshLayerPropertiesDialog.restoreLastPage();
|
|||
|
|
meshLayerPropertiesDialog.exec();
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|