QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
qgsgeometrypaintdevice.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsgeometrypaintdevice.h
3 --------------------------------------
4 Date : May 2024
5 Copyright : (C) 2024 by Nyall Dawson
6 Email : nyall dot dawson at gmail 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#ifndef QGSGEOMETRYPAINTDEVICE_H
17#define QGSGEOMETRYPAINTDEVICE_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
22#include "qgsgeometry.h"
23
24#include <QPainterPath>
25#include <QPaintDevice>
26#include <QPaintEngine>
27#include <memory>
28
29class QgsLineString;
30
31#ifndef SIP_RUN
32
38class QgsGeometryPaintEngine: public QPaintEngine
39{
40
41 public:
42
49 QgsGeometryPaintEngine( bool usePathStroker = false );
50
56 void setStrokedPathSegments( int segments );
57
65 void setSimplificationTolerance( double tolerance );
66
67 bool begin( QPaintDevice * ) final;
68 bool end() final;
69 QPaintEngine::Type type() const final;
70 void updateState( const QPaintEngineState & ) final;
71
72 // no-op drawing methods. We don't want the base class methods to be called and unnecessary work performed
73 void drawImage( const QRectF &rectangle, const QImage &image, const QRectF &sr, Qt::ImageConversionFlags flags = Qt::AutoColor ) final;
74 void drawPixmap( const QRectF &, const QPixmap &, const QRectF & ) final;
75 void drawTiledPixmap( const QRectF &rect, const QPixmap &pixmap, const QPointF &p ) final;
76
77 // supported drawing operations. While we could rely on the base class methods to convert these operations
78 // to paths and then only implement drawPath, we instead want this class to be as FAST as possible
79 // and accordingly we implement the most optimised geometry conversion for each drawing primitive
80 void drawLines( const QLineF *lines, int lineCount ) final;
81 void drawLines( const QLine *lines, int lineCount ) final;
82 void drawPoints( const QPointF *points, int pointCount ) final;
83 void drawPoints( const QPoint *points, int pointCount ) final;
84 void drawPolygon( const QPointF *points, int pointCount, QPaintEngine::PolygonDrawMode mode ) final;
85 void drawPolygon( const QPoint *points, int pointCount, QPaintEngine::PolygonDrawMode mode ) final;
86 void drawRects( const QRectF *rects, int rectCount ) final;
87 void drawRects( const QRect *rects, int rectCount ) final;
88 void drawPath( const QPainterPath &path ) final;
89
90 // We can't represent an ellipse as a curved geometry, so let QPaintEngine base class convert this to a segmentized
91 // shape instead
92 // void drawEllipse(const QRectF &rect) final;
93
94 // We want Qt to handle text -> path conversion
95 // void drawTextItem(const QPointF &p, const QTextItem &textItem) final;
96
100 const QgsAbstractGeometry &geometry() const { return mGeometry; }
101
102 private:
103
104 void addSubpathGeometries( const QPainterPath &path, const QTransform &matrix );
105 void addStrokedLine( const QgsLineString *line, double penWidth, Qgis::EndCapStyle endCapStyle, Qgis::JoinStyle joinStyle, double miterLimit, const QTransform *matrix );
106 static Qgis::EndCapStyle penStyleToCapStyle( Qt::PenCapStyle style );
107 static Qgis::JoinStyle penStyleToJoinStyle( Qt::PenJoinStyle style );
108
109 bool mUsePathStroker = false;
110 QPen mPen;
111 QgsGeometryCollection mGeometry;
112 int mStrokedPathsSegments = 8;
113 double mSimplifyTolerance = 0;
114};
115
116#endif
117
118
124class CORE_EXPORT QgsGeometryPaintDevice: public QPaintDevice
125{
126
127 public:
128
135 QgsGeometryPaintDevice( bool usePathStroker = false );
136
142 void setStrokedPathSegments( int segments );
143
151 void setSimplificationTolerance( double tolerance );
152
153 QPaintEngine *paintEngine() const override;
154
155 int metric( PaintDeviceMetric metric ) const override;
156
160 const QgsAbstractGeometry &geometry() const;
161
167 static QgsGeometry painterPathToGeometry( const QPainterPath &path );
168
169 private:
170
171 std::unique_ptr<QgsGeometryPaintEngine> mPaintEngine;
172
173 QSize mSize;
174
175};
176
177
178#endif // QGSGEOMETRYPAINTDEVICE_H
JoinStyle
Join styles for buffers.
Definition qgis.h:1968
EndCapStyle
End cap styles for buffers.
Definition qgis.h:1955
Abstract base class for all geometries.
A paint device which converts everything renderer to a QgsGeometry representation of the rendered sha...
A paint engine which converts everything renderer to a QgsGeometry representation of the rendered sha...
void setSimplificationTolerance(double tolerance)
Sets a simplification tolerance (in painter units) to use for on-the-fly simplification of geometries...
void drawImage(const QRectF &rectangle, const QImage &image, const QRectF &sr, Qt::ImageConversionFlags flags=Qt::AutoColor) final
void drawRects(const QRectF *rects, int rectCount) final
void drawPolygon(const QPointF *points, int pointCount, QPaintEngine::PolygonDrawMode mode) final
const QgsAbstractGeometry & geometry() const
Returns the rendered geometry.
void drawPixmap(const QRectF &, const QPixmap &, const QRectF &) final
void drawPoints(const QPointF *points, int pointCount) final
bool begin(QPaintDevice *) final
void drawLines(const QLineF *lines, int lineCount) final
QPaintEngine::Type type() const final
void drawTiledPixmap(const QRectF &rect, const QPixmap &pixmap, const QPointF &p) final
void updateState(const QPaintEngineState &) final
void drawPath(const QPainterPath &path) final
void setStrokedPathSegments(int segments)
Sets the number of segments to use when drawing stroked paths with a rounded pen.
A geometry is the spatial representation of a feature.
Line string geometry type, with support for z-dimension and m-values.