diff --git a/python/PyQt6/core/auto_generated/mesh/qgsmeshlayer.sip.in b/python/PyQt6/core/auto_generated/mesh/qgsmeshlayer.sip.in index 6a2cafa579ac..6a5b6bb46558 100644 --- a/python/PyQt6/core/auto_generated/mesh/qgsmeshlayer.sip.in +++ b/python/PyQt6/core/auto_generated/mesh/qgsmeshlayer.sip.in @@ -234,9 +234,13 @@ Gets native mesh and updates (creates if it doesn't exist) the base triangular m %Docstring Returns renderer settings %End - void setRendererSettings( const QgsMeshRendererSettings &settings ); + + void setRendererSettings( const QgsMeshRendererSettings &settings, const bool repaint = true ); %Docstring Sets new renderer settings + +:param settings: +:param repaint: should the update of renderer settings trigger repaint and emit rendererChanged signal %End QgsMeshTimeSettings timeSettings() const; diff --git a/python/core/auto_generated/mesh/qgsmeshlayer.sip.in b/python/core/auto_generated/mesh/qgsmeshlayer.sip.in index 6a2cafa579ac..6a5b6bb46558 100644 --- a/python/core/auto_generated/mesh/qgsmeshlayer.sip.in +++ b/python/core/auto_generated/mesh/qgsmeshlayer.sip.in @@ -234,9 +234,13 @@ Gets native mesh and updates (creates if it doesn't exist) the base triangular m %Docstring Returns renderer settings %End - void setRendererSettings( const QgsMeshRendererSettings &settings ); + + void setRendererSettings( const QgsMeshRendererSettings &settings, const bool repaint = true ); %Docstring Sets new renderer settings + +:param settings: +:param repaint: should the update of renderer settings trigger repaint and emit rendererChanged signal %End QgsMeshTimeSettings timeSettings() const; diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index ab4ef5664a8d..039ccef3c595 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -17326,13 +17326,12 @@ void QgisApp::handleRenderedLayerStatistics() const { QgsMeshRendererSettings rendererSettings = meshLayer->rendererSettings(); QgsMeshRendererScalarSettings scalarRendererSettings = rendererSettings.scalarSettings( rendererSettings.activeScalarDatasetGroup() ); + scalarRendererSettings.setClassificationMinimumMaximum( layerStatistics->minimum( 0 ), layerStatistics->maximum( 0 ) ); rendererSettings.setScalarSettings( rendererSettings.activeScalarDatasetGroup(), scalarRendererSettings ); - meshLayer->setRendererSettings( rendererSettings ); + meshLayer->setRendererSettings( rendererSettings, false ); meshLayer->emitStyleChanged(); - emit meshLayer->rendererChanged(); - emit meshLayer->legendChanged(); } } } diff --git a/src/core/mesh/qgsmeshlayer.cpp b/src/core/mesh/qgsmeshlayer.cpp index 56ffea5a6e52..c7bbcc789196 100644 --- a/src/core/mesh/qgsmeshlayer.cpp +++ b/src/core/mesh/qgsmeshlayer.cpp @@ -418,7 +418,7 @@ QgsMeshRendererSettings QgsMeshLayer::rendererSettings() const return mRendererSettings; } -void QgsMeshLayer::setRendererSettings( const QgsMeshRendererSettings &settings ) +void QgsMeshLayer::setRendererSettings( const QgsMeshRendererSettings &settings, const bool repaint ) { QGIS_PROTECT_QOBJECT_THREAD_ACCESS @@ -433,7 +433,11 @@ void QgsMeshLayer::setRendererSettings( const QgsMeshRendererSettings &settings emit activeVectorDatasetGroupChanged( mRendererSettings.activeVectorDatasetGroup() ); emit rendererChanged(); - triggerRepaint(); + + if ( repaint ) + { + triggerRepaint(); + } } QgsMeshTimeSettings QgsMeshLayer::timeSettings() const @@ -1704,6 +1708,11 @@ bool QgsMeshLayer::minimumMaximumActiveScalarDataset( const QgsRectangle &extent QgsTriangularMesh *tMesh = triangularMesh(); + if ( ! tMesh ) + { + return false; + } + QVector scalarDatasetValues; const QgsMeshDatasetGroupMetadata metadata = datasetGroupMetadata( datasetIndex.group() ); diff --git a/src/core/mesh/qgsmeshlayer.h b/src/core/mesh/qgsmeshlayer.h index 311694ee75c5..49c22a1e6ac1 100644 --- a/src/core/mesh/qgsmeshlayer.h +++ b/src/core/mesh/qgsmeshlayer.h @@ -309,8 +309,14 @@ class CORE_EXPORT QgsMeshLayer : public QgsMapLayer, public QgsAbstractProfileSo //! Returns renderer settings QgsMeshRendererSettings rendererSettings() const; - //! Sets new renderer settings - void setRendererSettings( const QgsMeshRendererSettings &settings ); + + /** + * Sets new renderer settings + * + * \param settings + * \param repaint should the update of renderer settings trigger repaint and emit rendererChanged signal + */ + void setRendererSettings( const QgsMeshRendererSettings &settings, const bool repaint = true ); /** * Returns time format settings diff --git a/src/core/mesh/qgsmeshlayerrenderer.cpp b/src/core/mesh/qgsmeshlayerrenderer.cpp index 479340761377..7ad75073fb99 100644 --- a/src/core/mesh/qgsmeshlayerrenderer.cpp +++ b/src/core/mesh/qgsmeshlayerrenderer.cpp @@ -161,41 +161,42 @@ QgsMeshLayerRenderer::QgsMeshLayerRenderer( mClippingRegions = QgsMapClippingUtils::collectClippingRegionsForLayer( *renderContext(), layer ); - if ( !context.testFlag( Qgis::RenderContextFlag::RenderPreviewJob ) ) + if ( !context.testFlag( Qgis::RenderContextFlag::RenderPreviewJob ) + && !( context.flags() & Qgis::RenderContextFlag::Render3DMap ) ) { - QgsMeshDatasetIndex activeDatasetIndex = layer->activeScalarDatasetIndex( context ); + const QgsMeshDatasetIndex activeDatasetIndex = layer->activeScalarDatasetIndex( context ); if ( activeDatasetIndex.isValid() ) { QgsMeshRendererScalarSettings scalarRendererSettings = mRendererSettings.scalarSettings( activeDatasetIndex.group() ); - double previousMin = scalarRendererSettings.classificationMinimum(); - double previousMax = scalarRendererSettings.classificationMaximum(); - - QgsRenderedLayerStatistics *layerStatistics = new QgsRenderedLayerStatistics( layer->id(), previousMin, previousMax ); - layerStatistics->setBoundingBox( layer->extent() ); + const double previousMin = scalarRendererSettings.classificationMinimum(); + const double previousMax = scalarRendererSettings.classificationMaximum(); if ( scalarRendererSettings.extent() == Qgis::MeshRangeExtent::UpdatedCanvas && scalarRendererSettings.limits() == Qgis::MeshRangeLimit::MinimumMaximum ) { double min, max; - bool found = layer->minimumMaximumActiveScalarDataset( context.extent(), activeDatasetIndex, min, max ); + const bool found = layer->minimumMaximumActiveScalarDataset( context.extent(), activeDatasetIndex, min, max ); if ( found ) { if ( previousMin != min || previousMax != max ) { + + scalarRendererSettings.setClassificationMinimumMaximum( min, max ); + mRendererSettings.setScalarSettings( activeDatasetIndex.group(), scalarRendererSettings ); + + 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 ); } } diff --git a/src/gui/mesh/qgsmeshrendererscalarsettingswidget.cpp b/src/gui/mesh/qgsmeshrendererscalarsettingswidget.cpp index ebcf1e598973..fc1ee2ac43d2 100644 --- a/src/gui/mesh/qgsmeshrendererscalarsettingswidget.cpp +++ b/src/gui/mesh/qgsmeshrendererscalarsettingswidget.cpp @@ -147,7 +147,7 @@ void QgsMeshRendererScalarSettingsWidget::syncToLayer() whileBlocking( mScalarMinSpinBox )->setValue( min ); whileBlocking( mScalarMaxSpinBox )->setValue( max ); - mMinMaxValueTypeComboBox->setCurrentIndex( mMinMaxValueTypeComboBox->findData( QVariant::fromValue( settings.extent() ) ) ); + whileBlocking( mMinMaxValueTypeComboBox )->setCurrentIndex( mMinMaxValueTypeComboBox->findData( QVariant::fromValue( settings.extent() ) ) ); if ( settings.limits() == Qgis::MeshRangeLimit::MinimumMaximum ) { diff --git a/tests/src/core/testqgsmeshlayer.cpp b/tests/src/core/testqgsmeshlayer.cpp index 7b1e8980ab99..2ec1da0b630f 100644 --- a/tests/src/core/testqgsmeshlayer.cpp +++ b/tests/src/core/testqgsmeshlayer.cpp @@ -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 ); diff --git a/tests/src/core/testqgsmeshlayerrenderer.cpp b/tests/src/core/testqgsmeshlayerrenderer.cpp index e2ebc536cc77..bb70e4acfec0 100644 --- a/tests/src/core/testqgsmeshlayerrenderer.cpp +++ b/tests/src/core/testqgsmeshlayerrenderer.cpp @@ -886,7 +886,11 @@ void TestQgsMeshRenderer::test_color_scale_based_on_canvas_extent() layer.temporalProperties()->setIsActive( false ); int groupIndex = 0; - layer.setStaticScalarDatasetIndex( QgsMeshDatasetIndex( groupIndex, 0 ) ); + QgsMeshDatasetIndex meshDatasetIndex = QgsMeshDatasetIndex( groupIndex, 0 ); + layer.setStaticScalarDatasetIndex( meshDatasetIndex ); + + double min, max; + bool found; QgsProject::instance()->addMapLayer( &layer ); mMapSettings->setLayers( QList() << &layer ); @@ -894,31 +898,52 @@ void TestQgsMeshRenderer::test_color_scale_based_on_canvas_extent() mMapSettings->setOutputDpi( 96 ); mMapSettings->setRotation( 0 ); + QgsMeshRendererSettings defaultRendererSettings = layer.rendererSettings(); + // min max from current canvas settings for group QgsMeshRendererSettings rendererSettings = layer.rendererSettings(); QgsMeshRendererScalarSettings scalarRendererSettings = rendererSettings.scalarSettings( groupIndex ); scalarRendererSettings.setLimits( Qgis::MeshRangeLimit::MinimumMaximum ); scalarRendererSettings.setExtent( Qgis::MeshRangeExtent::UpdatedCanvas ); - rendererSettings.setScalarSettings( groupIndex, scalarRendererSettings ); - layer.setRendererSettings( rendererSettings ); QgsRectangle extent = layer.extent(); extent.grow( 0.1 ); + + found = layer.minimumMaximumActiveScalarDataset( extent, meshDatasetIndex, min, max ); + QVERIFY( found ); + scalarRendererSettings.setClassificationMinimumMaximum( min, max ); + rendererSettings.setScalarSettings( groupIndex, scalarRendererSettings ); + layer.setRendererSettings( rendererSettings ); + mMapSettings->setExtent( extent ); QGSRENDERMAPSETTINGSCHECK( "scale_interactive_from_canvas_1", "scale_interactive_from_canvas_1", *mMapSettings, 0, 5 ); extent = QgsRectangle( 0, 8, 2, 10 ); extent.grow( 0.1 ); + + found = layer.minimumMaximumActiveScalarDataset( extent, meshDatasetIndex, min, max ); + QVERIFY( found ); + scalarRendererSettings.setClassificationMinimumMaximum( min, max ); + rendererSettings.setScalarSettings( groupIndex, scalarRendererSettings ); + layer.setRendererSettings( rendererSettings ); + mMapSettings->setExtent( extent ); QGSRENDERMAPSETTINGSCHECK( "scale_interactive_from_canvas_2", "scale_interactive_from_canvas_2", *mMapSettings, 0, 5 ); extent = QgsRectangle( 8, 8, 10, 10 ); extent.grow( 0.1 ); + + found = layer.minimumMaximumActiveScalarDataset( extent, meshDatasetIndex, min, max ); + QVERIFY( found ); + scalarRendererSettings.setClassificationMinimumMaximum( min, max ); + rendererSettings.setScalarSettings( groupIndex, scalarRendererSettings ); + layer.setRendererSettings( rendererSettings ); + mMapSettings->setExtent( extent ); QGSRENDERMAPSETTINGSCHECK( "scale_interactive_from_canvas_3", "scale_interactive_from_canvas_3", *mMapSettings, 0, 5 ); // min max from whole mesh settings for group - rendererSettings = layer.rendererSettings(); + rendererSettings = defaultRendererSettings; scalarRendererSettings = rendererSettings.scalarSettings( groupIndex ); scalarRendererSettings.setLimits( Qgis::MeshRangeLimit::MinimumMaximum ); scalarRendererSettings.setExtent( Qgis::MeshRangeExtent::WholeMesh );