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

Mesh Layer Rendering with Updated Canvas Fix #59987

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
6 changes: 0 additions & 6 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17184,12 +17184,6 @@ void QgisApp::handleRenderedLayerStatistics() const
QgsMeshLayer *meshLayer = qobject_cast<QgsMeshLayer *>( QgsProject::instance()->mapLayer( layerStatistics->layerId() ) );
if ( meshLayer )
{
QgsMeshRendererSettings rendererSettings = meshLayer->rendererSettings();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this logic applied now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is applied in step of renderer creation. Basically, this part of the logic was applied twice, which caused issue (double rendering).

There is significant difference between mesh and raster renderer - mesh renderer is not stored at all, only the settings and mesh renderer is always created when it is needed. Thus there is no refresh of it.

I am not 100% sure that I properly understand the approach that was introduced with QgsRenderedLayerStatistics. Should the layer statistics be only applied on the renderer from this part of the code? And if rendered from anywhere else, just stick with data that are already set in mesh render settings?

QgsMeshRendererScalarSettings scalarRendererSettings = rendererSettings.scalarSettings( rendererSettings.activeScalarDatasetGroup() );
scalarRendererSettings.setClassificationMinimumMaximum( layerStatistics->minimum( 0 ), layerStatistics->maximum( 0 ) );
rendererSettings.setScalarSettings( rendererSettings.activeScalarDatasetGroup(), scalarRendererSettings );
meshLayer->setRendererSettings( rendererSettings );

meshLayer->emitStyleChanged();
emit meshLayer->rendererChanged();
emit meshLayer->legendChanged();
Expand Down
5 changes: 5 additions & 0 deletions src/core/mesh/qgsmeshlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1704,6 +1704,11 @@ bool QgsMeshLayer::minimumMaximumActiveScalarDataset( const QgsRectangle &extent

QgsTriangularMesh *tMesh = triangularMesh();

if ( ! tMesh )
{
return false;
}

QVector<double> scalarDatasetValues;
const QgsMeshDatasetGroupMetadata metadata = datasetGroupMetadata( datasetIndex.group() );

Expand Down
9 changes: 4 additions & 5 deletions src/core/mesh/qgsmeshlayerrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,6 @@ QgsMeshLayerRenderer::QgsMeshLayerRenderer(
double previousMin = scalarRendererSettings.classificationMinimum();
double previousMax = scalarRendererSettings.classificationMaximum();

QgsRenderedLayerStatistics *layerStatistics = new QgsRenderedLayerStatistics( layer->id(), previousMin, previousMax );
layerStatistics->setBoundingBox( layer->extent() );

if ( scalarRendererSettings.extent() == Qgis::MeshRangeExtent::UpdatedCanvas &&
scalarRendererSettings.limits() == Qgis::MeshRangeLimit::MinimumMaximum )
{
Expand All @@ -185,17 +182,19 @@ QgsMeshLayerRenderer::QgsMeshLayerRenderer(
{
if ( previousMin != min || previousMax != max )
{
QgsRenderedLayerStatistics *layerStatistics = new QgsRenderedLayerStatistics( layer->id(), previousMin, previousMax );

layerStatistics->setBoundingBox( context.extent() );
layerStatistics->setMaximum( 0, max );
layerStatistics->setMinimum( 0, min );

scalarRendererSettings.setClassificationMinimumMaximum( min, max );
mRendererSettings.setScalarSettings( activeDatasetIndex.group(), scalarRendererSettings );

appendRenderedItemDetails( layerStatistics );
}
}
}

appendRenderedItemDetails( layerStatistics );
}
}

Expand Down
9 changes: 8 additions & 1 deletion tests/src/core/testqgsmeshlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2423,10 +2423,17 @@ void TestQgsMeshLayer::testMinimumMaximumActiveScalarDataset()
QStringLiteral( "mdal" )
);
QVERIFY( layer.isValid() );
layer.updateTriangularMesh();

datasetIndex = QgsMeshDatasetIndex( 0, 0 );

// if triangular mesh does not exist cannot extract values
extent = layer.extent();
found = layer.minimumMaximumActiveScalarDataset( extent, datasetIndex, min, max );
QCOMPARE( found, false );

// crete triangular mesh for layer
layer.updateTriangularMesh();

// tests for basic dataset
extent = layer.extent();
found = layer.minimumMaximumActiveScalarDataset( extent, datasetIndex, min, max );
Expand Down
Loading