QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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 <memory>
20
21#include "qgis_core.h"
22#include "qgis_sip.h"
23#include "qgsgeometry.h"
25
26#include <QPaintDevice>
27#include <QPaintEngine>
28#include <QPainterPath>
29
30class QgsLineString;
31
32#ifndef SIP_RUN
33
39class QgsGeometryPaintEngine : public QPaintEngine
40{
41 public:
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 void addSubpathGeometries( const QPainterPath &path, const QTransform &matrix );
103 void addStrokedLine( const QgsLineString *line, double penWidth, Qgis::EndCapStyle endCapStyle, Qgis::JoinStyle joinStyle, double miterLimit, const QTransform *matrix );
104
105 bool mUsePathStroker = false;
106 QPen mPen;
107 QgsGeometryCollection mGeometry;
108 int mStrokedPathsSegments = 8;
109 double mSimplifyTolerance = 0;
110};
111
112#endif
113
114
120class CORE_EXPORT QgsGeometryPaintDevice : public QPaintDevice
121{
122 public:
129 QgsGeometryPaintDevice( bool usePathStroker = false );
130
136 void setStrokedPathSegments( int segments );
137
145 void setSimplificationTolerance( double tolerance );
146
147 QPaintEngine *paintEngine() const override;
148
149 int metric( PaintDeviceMetric metric ) const override;
150
154 const QgsAbstractGeometry &geometry() const;
155
161 static QgsGeometry painterPathToGeometry( const QPainterPath &path );
162
163 private:
164 std::unique_ptr<QgsGeometryPaintEngine> mPaintEngine;
165
166 QSize mSize;
167};
168
169
170#endif // QGSGEOMETRYPAINTDEVICE_H
JoinStyle
Join styles for buffers.
Definition qgis.h:2201
EndCapStyle
End cap styles for buffers.
Definition qgis.h:2188
Abstract base class for all geometries.
QgsGeometryPaintDevice(bool usePathStroker=false)
Constructor for QgsGeometryPaintDevice.
void setStrokedPathSegments(int segments)
Sets the number of segments to use when drawing stroked paths with a rounded pen.
int metric(PaintDeviceMetric metric) const override
void setSimplificationTolerance(double tolerance)
Sets a simplification tolerance (in painter units) to use for on-the-fly simplification of geometries...
QPaintEngine * paintEngine() const override
static QgsGeometry painterPathToGeometry(const QPainterPath &path)
Converts a painter path to a QgsGeometry.
const QgsAbstractGeometry & geometry() const
Returns the rendered geometry.
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
QgsGeometryPaintEngine(bool usePathStroker=false)
Constructor for QgsGeometryPaintEngine.
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.