Skip to content

Commit

Permalink
Add render context flag to use when a map render job is part of a 3d map
Browse files Browse the repository at this point in the history
(cherry picked from commit 9e1cdda)
  • Loading branch information
nyalldawson committed Jul 29, 2020
1 parent af2e51d commit cbfdf3b
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/core/auto_generated/qgsmapsettings.sip.in
Expand Up @@ -345,6 +345,7 @@ Gets color that is used for drawing of selected vector features
RenderPartialOutput,
RenderPreviewJob,
RenderBlocking,
Render3DMap,
// TODO: ignore scale-based visibility (overview)
};
typedef QFlags<QgsMapSettings::Flag> Flags;
Expand Down
1 change: 1 addition & 0 deletions python/core/auto_generated/qgsrendercontext.sip.in
Expand Up @@ -44,6 +44,7 @@ to be rendered etc.
RenderPreviewJob,
RenderBlocking,
RenderSymbolPreview,
Render3DMap,
};
typedef QFlags<QgsRenderContext::Flag> Flags;

Expand Down
1 change: 1 addition & 0 deletions src/3d/terrain/qgsterraintexturegenerator_p.cpp
Expand Up @@ -140,6 +140,7 @@ QgsMapSettings QgsTerrainTextureGenerator::baseMapSettings()
mapSettings.setDestinationCrs( mMap.crs() );
mapSettings.setBackgroundColor( mMap.backgroundColor() );
mapSettings.setFlag( QgsMapSettings::DrawLabeling, mMap.showLabels() );
mapSettings.setFlag( QgsMapSettings::Render3DMap );
mapSettings.setTransformContext( mMap.transformContext() );
mapSettings.setPathResolver( mMap.pathResolver() );

Expand Down
1 change: 1 addition & 0 deletions src/core/qgsmapsettings.h
Expand Up @@ -311,6 +311,7 @@ class CORE_EXPORT QgsMapSettings : public QgsTemporalRangeObject
RenderPartialOutput = 0x200, //!< Whether to make extra effort to update map image with partially rendered layers (better for interactive map canvas). Added in QGIS 3.0
RenderPreviewJob = 0x400, //!< Render is a 'canvas preview' render, and shortcuts should be taken to ensure fast rendering
RenderBlocking = 0x800, //!< Render and load remote sources in the same thread to ensure rendering remote sources (svg and images). WARNING: this flag must NEVER be used from GUI based applications (like the main QGIS application) or crashes will result. Only for use in external scripts or QGIS server.
Render3DMap = 0x2000, //!< Render is for a 3D map
// TODO: ignore scale-based visibility (overview)
};
Q_DECLARE_FLAGS( Flags, Flag )
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsrendercontext.cpp
Expand Up @@ -188,6 +188,7 @@ QgsRenderContext QgsRenderContext::fromMapSettings( const QgsMapSettings &mapSet
ctx.setFlag( RenderPartialOutput, mapSettings.testFlag( QgsMapSettings::RenderPartialOutput ) );
ctx.setFlag( RenderPreviewJob, mapSettings.testFlag( QgsMapSettings::RenderPreviewJob ) );
ctx.setFlag( RenderBlocking, mapSettings.testFlag( QgsMapSettings::RenderBlocking ) );
ctx.setFlag( Render3DMap, mapSettings.testFlag( QgsMapSettings::Render3DMap ) );
ctx.setScaleFactor( mapSettings.outputDpi() / 25.4 ); // = pixels per mm
ctx.setRendererScale( mapSettings.scale() );
ctx.setExpressionContext( mapSettings.expressionContext() );
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsrendercontext.h
Expand Up @@ -80,6 +80,7 @@ class CORE_EXPORT QgsRenderContext : public QgsTemporalRangeObject
RenderPreviewJob = 0x200, //!< Render is a 'canvas preview' render, and shortcuts should be taken to ensure fast rendering
RenderBlocking = 0x400, //!< Render and load remote sources in the same thread to ensure rendering remote sources (svg and images). WARNING: this flag must NEVER be used from GUI based applications (like the main QGIS application) or crashes will result. Only for use in external scripts or QGIS server.
RenderSymbolPreview = 0x800, //!< The render is for a symbol preview only and map based properties may not be available, so care should be taken to handle map unit based sizes in an appropriate way.
Render3DMap = 0x4000, //!< Render is for a 3D map
};
Q_DECLARE_FLAGS( Flags, Flag )

Expand Down
4 changes: 4 additions & 0 deletions tests/src/python/test_qgsrendercontext.py
Expand Up @@ -116,10 +116,14 @@ def testFromMapSettings(self):
ms.setOutputSize(QSize(1000, 1000))
ms.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:3111'))
ms.setExtent(QgsRectangle(10000, 20000, 30000, 40000))
ms.setFlag(QgsMapSettings.Antialiasing, True)
ms.setFlag(QgsMapSettings.Render3DMap, True)

ms.setTextRenderFormat(QgsRenderContext.TextFormatAlwaysText)
rc = QgsRenderContext.fromMapSettings(ms)
self.assertEqual(rc.textRenderFormat(), QgsRenderContext.TextFormatAlwaysText)
self.assertTrue(rc.testFlag(QgsRenderContext.Antialiasing))
self.assertTrue(rc.testFlag(QgsRenderContext.Render3DMap))

ms.setTextRenderFormat(QgsRenderContext.TextFormatAlwaysOutlines)
rc = QgsRenderContext.fromMapSettings(ms)
Expand Down

0 comments on commit cbfdf3b

Please sign in to comment.