QGIS API Documentation 3.38.0-Grenoble (exported)
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
23#include <QPainterPath>
24#include <QPaintDevice>
25#include <QPaintEngine>
26#include <memory>
27
28class QgsLineString;
29
30#ifndef SIP_RUN
31
37class QgsGeometryPaintEngine: public QPaintEngine
38{
39
40 public:
41
48 QgsGeometryPaintEngine( bool usePathStroker = false );
49
55 void setStrokedPathSegments( int segments );
56
64 void setSimplificationTolerance( double tolerance );
65
66 bool begin( QPaintDevice * ) final;
67 bool end() final;
68 QPaintEngine::Type type() const final;
69 void updateState( const QPaintEngineState & ) final;
70
71 // no-op drawing methods. We don't want the base class methods to be called and unnecessary work performed
72 void drawImage( const QRectF &rectangle, const QImage &image, const QRectF &sr, Qt::ImageConversionFlags flags = Qt::AutoColor ) final;
73 void drawPixmap( const QRectF &, const QPixmap &, const QRectF & ) final;
74 void drawTiledPixmap( const QRectF &rect, const QPixmap &pixmap, const QPointF &p ) final;
75
76 // supported drawing operations. While we could rely on the base class methods to convert these operations
77 // to paths and then only implement drawPath, we instead want this class to be as FAST as possible
78 // and accordingly we implement the most optimised geometry conversion for each drawing primitive
79 void drawLines( const QLineF *lines, int lineCount ) final;
80 void drawLines( const QLine *lines, int lineCount ) final;
81 void drawPoints( const QPointF *points, int pointCount ) final;
82 void drawPoints( const QPoint *points, int pointCount ) final;
83 void drawPolygon( const QPointF *points, int pointCount, QPaintEngine::PolygonDrawMode mode ) final;
84 void drawPolygon( const QPoint *points, int pointCount, QPaintEngine::PolygonDrawMode mode ) final;
85 void drawRects( const QRectF *rects, int rectCount ) final;
86 void drawRects( const QRect *rects, int rectCount ) final;
87 void drawPath( const QPainterPath &path ) final;
88
89 // We can't represent an ellipse as a curved geometry, so let QPaintEngine base class convert this to a segmentized
90 // shape instead
91 // void drawEllipse(const QRectF &rect) final;
92
93 // We want Qt to handle text -> path conversion
94 // void drawTextItem(const QPointF &p, const QTextItem &textItem) final;
95
99 const QgsAbstractGeometry &geometry() const { return mGeometry; }
100
101 private:
102
103 void addSubpathGeometries( const QPainterPath &path, const QTransform &matrix );
104 void addStrokedLine( const QgsLineString *line, double penWidth, Qgis::EndCapStyle endCapStyle, Qgis::JoinStyle joinStyle, double miterLimit, const QTransform *matrix );
105 static Qgis::EndCapStyle penStyleToCapStyle( Qt::PenCapStyle style );
106 static Qgis::JoinStyle penStyleToJoinStyle( Qt::PenJoinStyle style );
107
108 bool mUsePathStroker = false;
109 QPen mPen;
110 QgsGeometryCollection mGeometry;
111 int mStrokedPathsSegments = 8;
112 double mSimplifyTolerance = 0;
113};
114
115#endif
116
117
123class CORE_EXPORT QgsGeometryPaintDevice: public QPaintDevice
124{
125
126 public:
127
134 QgsGeometryPaintDevice( bool usePathStroker = false );
135
141 void setStrokedPathSegments( int segments );
142
150 void setSimplificationTolerance( double tolerance );
151
152 QPaintEngine *paintEngine() const override;
153
154 int metric( PaintDeviceMetric metric ) const override;
155
159 const QgsAbstractGeometry &geometry() const;
160
161 private:
162
163 std::unique_ptr<QgsGeometryPaintEngine> mPaintEngine;
164
165 QSize mSize;
166
167};
168
169
170#endif // QGSGEOMETRYPAINTDEVICE_H
JoinStyle
Join styles for buffers.
Definition qgis.h:1788
EndCapStyle
End cap styles for buffers.
Definition qgis.h:1775
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.
Line string geometry type, with support for z-dimension and m-values.