Skip to content
Permalink
Browse files

Respect painter clip region when rendering mesh layers

  • Loading branch information
nyalldawson committed Jul 2, 2020
1 parent bbd5d80 commit 3f7320d96a9fa25d40a16ef7a4f2b464506802da
@@ -39,6 +39,7 @@
#include "qgssettings.h"
#include "qgsstyle.h"
#include "qgsmeshdataprovidertemporalcapabilities.h"
#include "qgsmapclippingutils.h"

QgsMeshLayerRenderer::QgsMeshLayerRenderer(
QgsMeshLayer *layer,
@@ -69,6 +70,8 @@ QgsMeshLayerRenderer::QgsMeshLayerRenderer(
copyVectorDatasetValues( layer );

calculateOutputSize();

mClippingRegions = QgsMapClippingUtils::collectClippingRegionsForLayer( *renderContext(), layer );
}

void QgsMeshLayerRenderer::copyTriangularMeshes( QgsMeshLayer *layer, QgsRenderContext &context )
@@ -283,9 +286,20 @@ void QgsMeshLayerRenderer::copyVectorDatasetValues( QgsMeshLayer *layer )

bool QgsMeshLayerRenderer::render()
{
renderContext()->painter()->save();
if ( !mClippingRegions.empty() )
{
bool needsPainterClipPath = false;
const QPainterPath path = QgsMapClippingUtils::calculatePainterClipRegion( mClippingRegions, *renderContext(), QgsMapLayerType::MeshLayer, needsPainterClipPath );
if ( needsPainterClipPath )
renderContext()->painter()->setClipPath( path, Qt::IntersectClip );
}

renderScalarDataset();
renderMesh();
renderVectorDataset();

renderContext()->painter()->restore();
return true;
}

@@ -34,6 +34,7 @@ class QgsMeshLayer;
#include "qgssymbol.h"
#include "qgsmeshdataprovider.h"
#include "qgsmeshtracerenderer.h"
#include "qgsmapclippingregion.h"

class QgsRenderContext;

@@ -146,6 +147,8 @@ class QgsMeshLayerRenderer : public QgsMapLayerRenderer
// copy of rendering settings
QgsMeshRendererSettings mRendererSettings;

QList< QgsMapClippingRegion > mClippingRegions;

// output screen size
QSize mOutputSize;
};
@@ -70,6 +70,7 @@ class TestQgsMeshRenderer : public QObject


void test_native_mesh_rendering();
void test_native_mesh_renderingWithClipping();
void test_triangular_mesh_rendering();
void test_edge_mesh_rendering();

@@ -254,6 +255,28 @@ void TestQgsMeshRenderer::test_native_mesh_rendering()
QVERIFY( imageCheck( "quad_and_triangle_native_mesh", mMemoryLayer ) );
}

void TestQgsMeshRenderer::test_native_mesh_renderingWithClipping()
{
QgsMeshRendererSettings rendererSettings = mMemoryLayer->rendererSettings();
QgsMeshRendererMeshSettings settings = rendererSettings.nativeMeshSettings();
settings.setEnabled( true );
settings.setLineWidth( 1. );
rendererSettings.setNativeMeshSettings( settings );
mMemoryLayer->setRendererSettings( rendererSettings );

QgsMapClippingRegion region( QgsGeometry::fromWkt( "Polygon ((1706.47279549718587077 2907.78611632270212795, 1306.56660412757969425 2480.30018761726114462, 1665.10318949343354689 2123.73358348968167775, 2360.5065666041273289 2060.6941838649163401, 2640.24390243902416842 2669.41838649155761232, 2228.51782363977508794 2874.29643527204552811, 1706.47279549718587077 2907.78611632270212795))" ) );
region.setFeatureClip( QgsMapClippingRegion::FeatureClippingType::PainterClip );
QgsMapClippingRegion region2( QgsGeometry::fromWkt( "Polygon ((1966.51031894934340016 2925.51594746716773443, 1801.03189493433410462 2452.7204502814265652, 2057.12945590994377199 2027.20450281425951289, 2457.03564727954972113 2033.11444652908130593, 2380.20637898686709377 2957.03564727955017588, 1966.51031894934340016 2925.51594746716773443))" ) );
region2.setFeatureClip( QgsMapClippingRegion::FeatureClippingType::Intersect );
mMapSettings->addClippingRegion( region );
mMapSettings->addClippingRegion( region2 );

const bool res = imageCheck( "painterclip_region", mMemoryLayer );

mMapSettings->setClippingRegions( QList< QgsMapClippingRegion >() );
QVERIFY( res );
}

void TestQgsMeshRenderer::test_triangular_mesh_rendering()
{
QgsMeshRendererSettings rendererSettings = mMemoryLayer->rendererSettings();
Binary file not shown.

0 comments on commit 3f7320d

Please sign in to comment.
You can’t perform that action at this time.