Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[elevation Profile] Correcly add a raster layer to an existing elevation profile widget #59809

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ Updates model when node's name has changed

void layerFlagsChanged();
%Docstring
Emitted when layer flags have changed.
Triggered when layer flags have changed.

.. versionadded:: 3.18
%End
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ Updates model when node's name has changed

void layerFlagsChanged();
%Docstring
Emitted when layer flags have changed.
Triggered when layer flags have changed.

.. versionadded:: 3.18
%End
Expand Down
26 changes: 26 additions & 0 deletions src/core/layertree/qgslayertreemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "qgsapplication.h"
#include "qgslayertree.h"
#include "qgslayertreemodellegendnode.h"
#include "qgsmaplayerelevationproperties.h"
#include "qgsproject.h"
#include "qgsmaphittest.h"
#include "qgsmaplayer.h"
Expand Down Expand Up @@ -992,6 +993,11 @@ void QgsLayerTreeModel::connectToLayer( QgsLayerTreeLayer *nodeLayer )
connect( layer, &QgsMapLayer::legendChanged, this, &QgsLayerTreeModel::layerLegendChanged, Qt::UniqueConnection );
connect( layer, &QgsMapLayer::flagsChanged, this, &QgsLayerTreeModel::layerFlagsChanged, Qt::UniqueConnection );

if ( QgsMapLayerElevationProperties *elevationProperties = layer->elevationProperties() )
{
connect( elevationProperties, &QgsMapLayerElevationProperties::profileGenerationPropertyChanged, this, &QgsLayerTreeModel::layerProfileGenerationPropertyChanged, Qt::UniqueConnection );
}

// using unique connection because there may be temporarily more nodes for a layer than just one
// which would create multiple connections, however disconnect() would disconnect all multiple connections
// even if we wanted to disconnect just one connection in each call.
Expand Down Expand Up @@ -1781,5 +1787,25 @@ void QgsLayerTreeModel::invalidateLegendMapBasedData()
mInvalidatedNodes.clear();
}

void QgsLayerTreeModel::layerProfileGenerationPropertyChanged()
{
if ( !mRootNode )
return;

QgsMapLayerElevationProperties *elevationProperties = qobject_cast<QgsMapLayerElevationProperties *>( sender() );
if ( !elevationProperties )
return;

if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( elevationProperties->parent() ) )
{
QgsLayerTreeLayer *nodeLayer = mRootNode->findLayer( layer->id() );
if ( !nodeLayer )
return;

QModelIndex index = node2index( nodeLayer );
emit dataChanged( index, index );
}
}

// Legend nodes routines - end
///////////////////////////////////////////////////////////////////////////////
10 changes: 9 additions & 1 deletion src/core/layertree/qgslayertreemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ class CORE_EXPORT QgsLayerTreeModel : public QAbstractItemModel
void layerLegendChanged();

/**
* Emitted when layer flags have changed.
* Triggered when layer flags have changed.
* \since QGIS 3.18
*/
void layerFlagsChanged();
Expand All @@ -394,6 +394,14 @@ class CORE_EXPORT QgsLayerTreeModel : public QAbstractItemModel

void invalidateLegendMapBasedData();

private slots:

/**
* Triggered when layer elevation properties have changed.
* \since QGIS 3.42
*/
void layerProfileGenerationPropertyChanged();

protected:
void removeLegendFromLayer( QgsLayerTreeLayer *nodeLayer );
void addLegendToLayer( QgsLayerTreeLayer *nodeL );
Expand Down
Loading