QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
painting
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
18
#include "
qgspainting.h
"
19
21
22
QgsMaskPaintEngine::QgsMaskPaintEngine(
bool
usePathStroker )
23
: QPaintEngine( QPaintEngine::AllFeatures )
24
, mUsePathStroker( usePathStroker )
25
{}
26
27
QPainterPath QgsMaskPaintEngine::maskPainterPath()
const
28
{
29
return
mMaskPainterPath;
30
}
31
32
void
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
47
void
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
62
QgsMaskPaintDevice::QgsMaskPaintDevice
(
bool
usePathStroker )
63
{
64
mPaintEngine = std::make_unique<QgsMaskPaintEngine>( usePathStroker );
65
}
66
67
QPaintEngine *
QgsMaskPaintDevice::paintEngine
()
const
68
{
69
return
mPaintEngine.get();
70
}
71
72
int
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:
92
val =
QgsPainting::qtDefaultDpiX
();
93
break
;
94
case
PdmDpiY:
95
case
PdmPhysicalDpiY:
96
val =
QgsPainting::qtDefaultDpiY
();
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
117
QPainterPath
QgsMaskPaintDevice::maskPainterPath
()
const
118
{
119
return
mPaintEngine->maskPainterPath();
120
}
QgsMaskPaintDevice::QgsMaskPaintDevice
Q_DECL_DEPRECATED QgsMaskPaintDevice(bool usePathStroker=false)
Definition
qgsmaskpaintdevice.cpp:62
QgsMaskPaintDevice::maskPainterPath
Q_DECL_DEPRECATED QPainterPath maskPainterPath() const
Returns the mask painter path painted on this paint device.
Definition
qgsmaskpaintdevice.cpp:117
QgsMaskPaintDevice::metric
int metric(PaintDeviceMetric metric) const override
Definition
qgsmaskpaintdevice.cpp:72
QgsMaskPaintDevice::paintEngine
QPaintEngine * paintEngine() const override
Definition
qgsmaskpaintdevice.cpp:67
QgsPainting::qtDefaultDpiY
static int qtDefaultDpiY()
Returns the default Qt vertical DPI.
Definition
qgspainting.cpp:238
QgsPainting::qtDefaultDpiX
static int qtDefaultDpiX()
Returns the default Qt horizontal DPI.
Definition
qgspainting.cpp:233
qgsmaskpaintdevice.h
qgspainting.h
Generated on
for QGIS API Documentation by
1.17.0