tab切换,改变LayerTreeModel的setCurrentIndex
This commit is contained in:
@ -1334,6 +1334,41 @@ void HPPA::onTabWidgetCurrentChanged(int index)//代码新建一个tab,会调
|
|||||||
{
|
{
|
||||||
canvas->setMapTool(activeTool);
|
canvas->setMapTool(activeTool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sync layer tree view selection with the current tab
|
||||||
|
if (m_MapLayerStore && m_layerTreeView && m_LayerTreeModel && m_RasterGroup)
|
||||||
|
{
|
||||||
|
MapLayer* layer = m_MapLayerStore->layerForWidget(currentWidget);
|
||||||
|
if (layer)
|
||||||
|
{
|
||||||
|
// Find the LayerTreeLayer node in m_RasterGroup that matches this layer
|
||||||
|
for (int i = 0; i < m_RasterGroup->childCount(); ++i)
|
||||||
|
{
|
||||||
|
LayerTreeNode* child = m_RasterGroup->childAt(i);
|
||||||
|
if (child && child->type() == LayerTreeNode::Type::Layer)
|
||||||
|
{
|
||||||
|
auto* layerNode = static_cast<LayerTreeLayer*>(child);
|
||||||
|
if (layerNode->mapLayer() == layer)
|
||||||
|
{
|
||||||
|
QModelIndex nodeIndex = m_LayerTreeModel->index(i, 0,
|
||||||
|
m_LayerTreeModel->index(m_RasterGroup->rowInParent(), 0));
|
||||||
|
// Block signals to avoid infinite loop with onLayerTreeSelectionChanged
|
||||||
|
m_layerTreeView->selectionModel()->blockSignals(true);
|
||||||
|
m_layerTreeView->setCurrentIndex(nodeIndex);
|
||||||
|
m_layerTreeView->selectionModel()->blockSignals(false);
|
||||||
|
|
||||||
|
// Manually update ImageControl since we blocked the signal
|
||||||
|
RasterLayer* rl = qobject_cast<RasterLayer*>(layer);
|
||||||
|
if (rl)
|
||||||
|
{
|
||||||
|
m_ic->setActiveLayer(rl);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HPPA::onActionOpenDirectory()
|
void HPPA::onActionOpenDirectory()
|
||||||
|
|||||||
@ -81,3 +81,12 @@ QWidget* MapLayerStore::widgetForLayer(const QString& absolutePath) const
|
|||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MapLayer* MapLayerStore::layerForWidget(QWidget* widget) const
|
||||||
|
{
|
||||||
|
if (!widget) return nullptr;
|
||||||
|
for (const auto& kv : m_layerWidgets) {
|
||||||
|
if (kv.second == widget) return kv.first;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|||||||
@ -35,6 +35,9 @@ public slots:
|
|||||||
// Get associated widget by layer absolute data path
|
// Get associated widget by layer absolute data path
|
||||||
QWidget* widgetForLayer(const QString& absolutePath) const;
|
QWidget* widgetForLayer(const QString& absolutePath) const;
|
||||||
|
|
||||||
|
// Reverse lookup: find the MapLayer associated with a given widget (or nullptr)
|
||||||
|
MapLayer* layerForWidget(QWidget* widget) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void layerAdded(MapLayer* layer);
|
void layerAdded(MapLayer* layer);
|
||||||
// Emitted just before the layer is destroyed/removed from store
|
// Emitted just before the layer is destroyed/removed from store
|
||||||
|
|||||||
Reference in New Issue
Block a user