QGIS API Documentation 3.39.0-Master (3aed037ce22)
Loading...
Searching...
No Matches
qgsmaskpaintdevice.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaskpaintdevice.h
3 --------------------------------------
4 Date : February 2022
5 Copyright : (C) 2022 by Julien Cabieces
6 Email : julien dot cabieces at oslandia dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#include "qgsmaskpaintdevice.h"
17#include "qgspainting.h"
18
20
21QgsMaskPaintEngine::QgsMaskPaintEngine( bool usePathStroker )
22 : QPaintEngine( QPaintEngine::AllFeatures )
23 , mUsePathStroker( usePathStroker )
24{
25}
26
27QPainterPath QgsMaskPaintEngine::maskPainterPath() const
28{
29 return mMaskPainterPath;
30}
31
32void QgsMaskPaintEngine::drawPath( const QPainterPath &path )
33{
34 QPainterPath realPath = path;
35 if ( mUsePathStroker )
36 {
37 QPen pen = painter()->pen();
38 QPainterPathStroker stroker( pen );
39 QPainterPath strokedPath = stroker.createStroke( path );
40 realPath = strokedPath;
41 }
42
43 const QTransform transform = painter()->combinedTransform();
44 mMaskPainterPath.addPath( transform.map( realPath ) );
45}
46
47void QgsMaskPaintEngine::drawPolygon( const QPointF *points, int numPoints, QPaintEngine::PolygonDrawMode mode )
48{
49 Q_UNUSED( mode );
50
51 QPolygonF polygon;
52 polygon.reserve( numPoints );
53 for ( int i = 0; i < numPoints; ++i )
54 polygon << points[i];
55
56 const QTransform transform = painter()->transform();
57 mMaskPainterPath.addPolygon( transform.map( polygon ) );
58}
59
61
63{
64 mPaintEngine = std::make_unique<QgsMaskPaintEngine>( usePathStroker );
65}
66
68{
69 return mPaintEngine.get();
70}
71
72int QgsMaskPaintDevice::metric( PaintDeviceMetric m ) const
73{
74 // copy/paste from qpicture.cpp
75 int val;
76 switch ( m )
77 {
78 case PdmWidth:
79 val = static_cast< int >( mPaintEngine->maskPainterPath().boundingRect().width() );
80 break;
81 case PdmHeight:
82 val = static_cast< int >( mPaintEngine->maskPainterPath().boundingRect().height() );
83 break;
84 case PdmWidthMM:
85 val = static_cast< int >( 25.4 / QgsPainting::qtDefaultDpiX() * mPaintEngine->maskPainterPath().boundingRect().width() );
86 break;
87 case PdmHeightMM:
88 val = static_cast< int >( 25.4 / QgsPainting::qtDefaultDpiY() * mPaintEngine->maskPainterPath().boundingRect().height() );
89 break;
90 case PdmDpiX:
91 case PdmPhysicalDpiX:
93 break;
94 case PdmDpiY:
95 case PdmPhysicalDpiY:
97 break;
98 case PdmNumColors:
99 val = 16777216;
100 break;
101 case PdmDepth:
102 val = 24;
103 break;
104 case PdmDevicePixelRatio:
105 val = 1;
106 break;
107 case PdmDevicePixelRatioScaled:
108 val = static_cast< int >( 1 * QPaintDevice::devicePixelRatioFScale() );
109 break;
110 default:
111 val = 0;
112 qWarning( "QPicture::metric: Invalid metric command" );
113 }
114 return val;
115}
116
118{
119 return mPaintEngine->maskPainterPath();
120}
Q_DECL_DEPRECATED QgsMaskPaintDevice(bool usePathStroker=false)
Q_DECL_DEPRECATED QPainterPath maskPainterPath() const
Returns the mask painter path painted on this paint device.
int metric(PaintDeviceMetric metric) const override
QPaintEngine * paintEngine() const override
static int qtDefaultDpiY()
Returns the default Qt vertical DPI.
static int qtDefaultDpiX()
Returns the default Qt horizontal DPI.