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

[Backport release-3_38] Remove old QPainterPath mask backend #57869

Merged
merged 4 commits into from
Jul 5, 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 @@ -58,6 +58,13 @@ Set ``tolerance`` to 0 to disable simplification. (No simplification is the defa
const QgsAbstractGeometry &geometry() const;
%Docstring
Returns the rendered geometry.
%End

static QgsGeometry painterPathToGeometry( const QPainterPath &path );
%Docstring
Converts a painter ``path`` to a :py:class:`QgsGeometry`.

.. versionadded:: 3.38.1
%End

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,24 @@ class QgsMaskPaintDevice: QPaintDevice
Mask painter device that can be used to register everything painted into a QPainterPath
used later as clip path

.. versionadded:: 3.26
.. deprecated::
QGIS 3.38, use :py:class:`QgsGeometryPaintDevice` instead
%End

%TypeHeaderCode
#include "qgsmaskpaintdevice.h"
%End
public:

QgsMaskPaintDevice( bool usePathStroker = false );
QgsMaskPaintDevice( bool usePathStroker = false ) /Deprecated/;
%Docstring
!
Constructor
If ``usePathStroker`` is ``True``, path will be considered with a stroke regarding QPainter
pen configuration

.. deprecated::
QGIS 3.38, use :py:class:`QgsGeometryPaintDevice` instead
%End

virtual QPaintEngine *paintEngine() const;
Expand All @@ -39,9 +43,12 @@ pen configuration
virtual int metric( PaintDeviceMetric metric ) const;


QPainterPath maskPainterPath() const;
QPainterPath maskPainterPath() const /Deprecated/;
%Docstring
Returns the mask painter path painted on this paint device

.. deprecated::
Use :py:class:`QgsGeometryPaintDevice` instead
%End

};
Expand Down
10 changes: 6 additions & 4 deletions python/PyQt6/core/auto_generated/qgsrendercontext.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -972,22 +972,24 @@ are drawn and behave during render operations.
.. versionadded:: 3.38
%End

void addSymbolLayerClipPath( const QString &symbolLayerId, QPainterPath path );
void addSymbolLayerClipPath( const QString &symbolLayerId, QPainterPath path ) /Deprecated/;
%Docstring
Add a clip ``path`` to be applied to the ``symbolLayer`` before rendering

.. seealso:: :py:func:`addSymbolLayerClipGeometry`

.. versionadded:: 3.26
.. deprecated::
QGIS 3.38, use :py:func:`~QgsRenderContext.addSymbolLayerClipGeometry` instead.
%End

QList<QPainterPath> symbolLayerClipPaths( const QString &symbolLayerId ) const;
QList<QPainterPath> symbolLayerClipPaths( const QString &symbolLayerId ) const /Deprecated/;
%Docstring
Returns clip paths to be applied to the ``symbolLayer`` before rendering

.. seealso:: :py:func:`symbolLayerClipGeometries`

.. versionadded:: 3.26
.. deprecated::
QGIS 3.38, use :py:func:`~QgsRenderContext.symbolLayerClipGeometries` instead.
%End

void addSymbolLayerClipGeometry( const QString &symbolLayerId, const QgsGeometry &geometry );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ Set ``tolerance`` to 0 to disable simplification. (No simplification is the defa
const QgsAbstractGeometry &geometry() const;
%Docstring
Returns the rendered geometry.
%End

static QgsGeometry painterPathToGeometry( const QPainterPath &path );
%Docstring
Converts a painter ``path`` to a :py:class:`QgsGeometry`.

.. versionadded:: 3.38.1
%End

};
Expand Down
13 changes: 10 additions & 3 deletions python/core/auto_generated/painting/qgsmaskpaintdevice.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,24 @@ class QgsMaskPaintDevice: QPaintDevice
Mask painter device that can be used to register everything painted into a QPainterPath
used later as clip path

.. versionadded:: 3.26
.. deprecated::
QGIS 3.38, use :py:class:`QgsGeometryPaintDevice` instead
%End

%TypeHeaderCode
#include "qgsmaskpaintdevice.h"
%End
public:

QgsMaskPaintDevice( bool usePathStroker = false );
QgsMaskPaintDevice( bool usePathStroker = false ) /Deprecated/;
%Docstring
!
Constructor
If ``usePathStroker`` is ``True``, path will be considered with a stroke regarding QPainter
pen configuration

.. deprecated::
QGIS 3.38, use :py:class:`QgsGeometryPaintDevice` instead
%End

virtual QPaintEngine *paintEngine() const;
Expand All @@ -39,9 +43,12 @@ pen configuration
virtual int metric( PaintDeviceMetric metric ) const;


QPainterPath maskPainterPath() const;
QPainterPath maskPainterPath() const /Deprecated/;
%Docstring
Returns the mask painter path painted on this paint device

.. deprecated::
Use :py:class:`QgsGeometryPaintDevice` instead
%End

};
Expand Down
10 changes: 6 additions & 4 deletions python/core/auto_generated/qgsrendercontext.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -972,22 +972,24 @@ are drawn and behave during render operations.
.. versionadded:: 3.38
%End

void addSymbolLayerClipPath( const QString &symbolLayerId, QPainterPath path );
void addSymbolLayerClipPath( const QString &symbolLayerId, QPainterPath path ) /Deprecated/;
%Docstring
Add a clip ``path`` to be applied to the ``symbolLayer`` before rendering

.. seealso:: :py:func:`addSymbolLayerClipGeometry`

.. versionadded:: 3.26
.. deprecated::
QGIS 3.38, use :py:func:`~QgsRenderContext.addSymbolLayerClipGeometry` instead.
%End

QList<QPainterPath> symbolLayerClipPaths( const QString &symbolLayerId ) const;
QList<QPainterPath> symbolLayerClipPaths( const QString &symbolLayerId ) const /Deprecated/;
%Docstring
Returns clip paths to be applied to the ``symbolLayer`` before rendering

.. seealso:: :py:func:`symbolLayerClipGeometries`

.. versionadded:: 3.26
.. deprecated::
QGIS 3.38, use :py:func:`~QgsRenderContext.symbolLayerClipGeometries` instead.
%End

void addSymbolLayerClipGeometry( const QString &symbolLayerId, const QgsGeometry &geometry );
Expand Down
44 changes: 9 additions & 35 deletions src/core/maprenderer/qgsmaprendererjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include "qgsmaplayerstyle.h"
#include "qgsvectorlayerrenderer.h"
#include "qgsrendereditemresults.h"
#include "qgsmaskpaintdevice.h"
#include "qgsgeometrypaintdevice.h"
#include "qgsrasterrenderer.h"
#include "qgselevationmap.h"
Expand Down Expand Up @@ -686,8 +685,6 @@ std::vector<LayerRenderJob> QgsMapRendererJob::prepareJobs( QPainter *painter, Q

std::vector< LayerRenderJob > QgsMapRendererJob::prepareSecondPassJobs( std::vector< LayerRenderJob > &firstPassJobs, LabelRenderJob &labelJob )
{
const bool useGeometryBackend = settingsMaskBackend->value().compare( QLatin1String( "geometry" ), Qt::CaseInsensitive ) == 0;

std::vector< LayerRenderJob > secondPassJobs;

// We will need to quickly access the associated rendering job of a layer
Expand Down Expand Up @@ -817,17 +814,10 @@ std::vector< LayerRenderJob > QgsMapRendererJob::prepareSecondPassJobs( std::vec
if ( forceVector && !labelHasEffects[ maskId ] )
{
// set a painter to get all masking instruction in order to later clip masked symbol layer
if ( useGeometryBackend )
{
std::unique_ptr< QgsGeometryPaintDevice > geomPaintDevice = std::make_unique< QgsGeometryPaintDevice >( true );
geomPaintDevice->setStrokedPathSegments( 4 );
geomPaintDevice->setSimplificationTolerance( labelJob.context.maskSettings().simplifyTolerance() );
maskPaintDevice = geomPaintDevice.release();
}
else
{
maskPaintDevice = new QgsMaskPaintDevice( true );
}
std::unique_ptr< QgsGeometryPaintDevice > geomPaintDevice = std::make_unique< QgsGeometryPaintDevice >( true );
geomPaintDevice->setStrokedPathSegments( 4 );
geomPaintDevice->setSimplificationTolerance( labelJob.context.maskSettings().simplifyTolerance() );
maskPaintDevice = geomPaintDevice.release();
maskPainter = new QPainter( maskPaintDevice );
}
else
Expand Down Expand Up @@ -902,18 +892,10 @@ std::vector< LayerRenderJob > QgsMapRendererJob::prepareSecondPassJobs( std::vec
if ( forceVector && !maskLayerHasEffects[ job.layerId ] )
{
// set a painter to get all masking instruction in order to later clip masked symbol layer
if ( useGeometryBackend )
{
std::unique_ptr< QgsGeometryPaintDevice > geomPaintDevice = std::make_unique< QgsGeometryPaintDevice >( );
geomPaintDevice->setStrokedPathSegments( 4 );
geomPaintDevice->setSimplificationTolerance( job.context()->maskSettings().simplifyTolerance() );
maskPaintDevice = geomPaintDevice.release();
}
else
{
maskPaintDevice = new QgsMaskPaintDevice();
}

std::unique_ptr< QgsGeometryPaintDevice > geomPaintDevice = std::make_unique< QgsGeometryPaintDevice >( );
geomPaintDevice->setStrokedPathSegments( 4 );
geomPaintDevice->setSimplificationTolerance( job.context()->maskSettings().simplifyTolerance() );
maskPaintDevice = geomPaintDevice.release();
maskPainter = new QPainter( maskPaintDevice );
}
else
Expand Down Expand Up @@ -1018,15 +1000,7 @@ void QgsMapRendererJob::initSecondPassJobs( std::vector< LayerRenderJob > &secon
QPainter *maskPainter = p.first ? p.first->maskPainter.get() : labelJob.maskPainters[p.second].get();

const QSet<QString> layers = job.context()->disabledSymbolLayersV2();
if ( QgsMaskPaintDevice *maskDevice = dynamic_cast<QgsMaskPaintDevice *>( maskPainter->device() ) )
{
QPainterPath path = maskDevice->maskPainterPath();
for ( const QString &symbolLayerId : layers )
{
job.context()->addSymbolLayerClipPath( symbolLayerId, path );
}
}
else if ( QgsGeometryPaintDevice *geometryDevice = dynamic_cast<QgsGeometryPaintDevice *>( maskPainter->device() ) )
if ( QgsGeometryPaintDevice *geometryDevice = dynamic_cast<QgsGeometryPaintDevice *>( maskPainter->device() ) )
{
QgsGeometry geometry( geometryDevice->geometry().clone() );

Expand Down
10 changes: 10 additions & 0 deletions src/core/painting/qgsgeometrypaintdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ void QgsGeometryPaintEngine::drawPath( const QPainterPath &path )
addSubpathGeometries( path, transform );
}


//
// QgsGeometryPaintDevice
//
Expand Down Expand Up @@ -688,3 +689,12 @@ const QgsAbstractGeometry &QgsGeometryPaintDevice::geometry() const
return mPaintEngine->geometry();
}

QgsGeometry QgsGeometryPaintDevice::painterPathToGeometry( const QPainterPath &path )
{
QgsGeometryPaintDevice device;
QPainter painter( &device );
painter.drawPath( path );
painter.end();
return QgsGeometry( device.geometry().clone() );
}

8 changes: 8 additions & 0 deletions src/core/painting/qgsgeometrypaintdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "qgis_core.h"
#include "qgis_sip.h"
#include "qgsgeometrycollection.h"
#include "qgsgeometry.h"

#include <QPainterPath>
#include <QPaintDevice>
Expand Down Expand Up @@ -158,6 +159,13 @@ class CORE_EXPORT QgsGeometryPaintDevice: public QPaintDevice
*/
const QgsAbstractGeometry &geometry() const;

/**
* Converts a painter \a path to a QgsGeometry.
*
* \since QGIS 3.38.1
*/
static QgsGeometry painterPathToGeometry( const QPainterPath &path );

private:

std::unique_ptr<QgsGeometryPaintEngine> mPaintEngine;
Expand Down
11 changes: 7 additions & 4 deletions src/core/painting/qgsmaskpaintdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class QgsMaskPaintEngine: public QPaintEngine

public:

QgsMaskPaintEngine( bool usePathStroker = false );
Q_DECL_DEPRECATED QgsMaskPaintEngine( bool usePathStroker = false );

bool begin( QPaintDevice * ) override { return true; };
bool end() override { return true; };
Expand All @@ -58,7 +58,7 @@ class QgsMaskPaintEngine: public QPaintEngine
* \ingroup core
* \brief Mask painter device that can be used to register everything painted into a QPainterPath
* used later as clip path
* \since QGIS 3.26
* \deprecated QGIS 3.38, use QgsGeometryPaintDevice instead
*/
class CORE_EXPORT QgsMaskPaintDevice: public QPaintDevice
{
Expand All @@ -69,17 +69,20 @@ class CORE_EXPORT QgsMaskPaintDevice: public QPaintDevice
* Constructor
* If \a usePathStroker is TRUE, path will be considered with a stroke regarding QPainter
* pen configuration
* \deprecated QGIS 3.38, use QgsGeometryPaintDevice instead
*/
QgsMaskPaintDevice( bool usePathStroker = false );
Q_DECL_DEPRECATED QgsMaskPaintDevice( bool usePathStroker = false ) SIP_DEPRECATED;

QPaintEngine *paintEngine() const override;

int metric( PaintDeviceMetric metric ) const override;

/**
* Returns the mask painter path painted on this paint device
*
* \deprecated Use QgsGeometryPaintDevice instead
*/
QPainterPath maskPainterPath() const;
Q_DECL_DEPRECATED QPainterPath maskPainterPath() const SIP_DEPRECATED;

private:

Expand Down
16 changes: 12 additions & 4 deletions src/core/qgsrendercontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "qgselevationmap.h"
#include "qgsunittypes.h"
#include "qgssymbollayer.h"
#include "qgsgeometrypaintdevice.h"

#define POINTS_TO_MM 2.83464567
#define INCH_TO_MM 25.4
Expand Down Expand Up @@ -82,7 +83,6 @@ QgsRenderContext::QgsRenderContext( const QgsRenderContext &rh )
, mRendererUsage( rh.mRendererUsage )
, mFrameRate( rh.mFrameRate )
, mCurrentFrame( rh.mCurrentFrame )
, mSymbolLayerClipPaths( rh.mSymbolLayerClipPaths )
, mSymbolLayerClippingGeometries( rh.mSymbolLayerClippingGeometries )
, mMaskRenderSettings( rh.mMaskRenderSettings )
#ifdef QGISDEBUG
Expand Down Expand Up @@ -135,7 +135,6 @@ QgsRenderContext &QgsRenderContext::operator=( const QgsRenderContext &rh )
mRendererUsage = rh.mRendererUsage;
mFrameRate = rh.mFrameRate;
mCurrentFrame = rh.mCurrentFrame;
mSymbolLayerClipPaths = rh.mSymbolLayerClipPaths;
mSymbolLayerClippingGeometries = rh.mSymbolLayerClippingGeometries;
mMaskRenderSettings = rh.mMaskRenderSettings;
if ( isTemporal() )
Expand Down Expand Up @@ -736,12 +735,21 @@ void QgsRenderContext::setElevationMap( QgsElevationMap *map )

void QgsRenderContext::addSymbolLayerClipPath( const QString &symbolLayerId, QPainterPath path )
{
mSymbolLayerClipPaths[ symbolLayerId ].append( path );
const QgsGeometry geometry = QgsGeometryPaintDevice::painterPathToGeometry( path );
if ( !geometry.isEmpty() )
addSymbolLayerClipGeometry( symbolLayerId, geometry );
}

QList<QPainterPath> QgsRenderContext::symbolLayerClipPaths( const QString &symbolLayerId ) const
{
return mSymbolLayerClipPaths[ symbolLayerId ];
const QVector<QgsGeometry> geometries = symbolLayerClipGeometries( symbolLayerId );
QList<QPainterPath> res;
res.reserve( geometries.size() );
for ( const QgsGeometry &geometry : geometries )
{
res << geometry.constGet()->asQPainterPath();
}
return res;
}

void QgsRenderContext::addSymbolLayerClipGeometry( const QString &symbolLayerId, const QgsGeometry &geometry )
Expand Down
Loading
Loading