Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qpainterpath_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QPAINTERPATH_P_H
5#define QPAINTERPATH_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of other Qt classes. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtGui/private/qtguiglobal_p.h>
19#include "QtGui/qpainterpath.h"
20#include "QtGui/qregion.h"
21#include "QtCore/qlist.h"
22#include "QtCore/qshareddata.h"
23#include "QtCore/qvarlengtharray.h"
24
25#include <qdebug.h>
26
27#include <private/qvectorpath_p.h>
28#include <private/qstroker_p.h>
29
30#include <memory>
31
33
34class QPolygonF;
36
38{
39public:
41 : pathData(path, fillRule, convex),
43 {
44 }
45
47 return path;
48 }
49
52 : elements(path.size()), points(path.size() * 2), flags(0)
53 {
54 int ptsPos = 0;
55 bool isLines = true;
56 for (int i=0; i<path.size(); ++i) {
57 const QPainterPath::Element &e = path.at(i);
58 elements[i] = e.type;
59 points[ptsPos++] = e.x;
60 points[ptsPos++] = e.y;
63
64 // This is to check if the path contains only alternating lineTo/moveTo,
65 // in which case we can set the LinesHint in the path. MoveTo is 0 and
66 // LineTo is 1 so the i%2 gets us what we want cheaply.
67 isLines = isLines && e.type == (QPainterPath::ElementType) (i%2);
68 }
69
70 if (fillRule == Qt::WindingFill)
72 else
74
75 if (isLines)
77 else {
79 if (!convex)
81 }
82
83 }
87 };
88
91
92private:
93 Q_DISABLE_COPY_MOVE(QVectorPathConverter)
94};
95
97{
98public:
99 friend class QPainterPath;
102 friend class QTransform;
103 friend class QVectorPath;
105#ifndef QT_NO_DATASTREAM
106 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &);
107 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &);
108#endif
109
111 : QSharedData(),
112 cStart(0),
113 fillRule(Qt::OddEvenFill),
114 require_moveTo(false),
115 dirtyBounds(false),
116 dirtyControlBounds(false),
117 convex(false),
118 pathConverter(nullptr)
119 {
120 }
121
124 elements(other.elements),
125 cStart(other.cStart),
126 fillRule(other.fillRule),
127 bounds(other.bounds),
128 controlBounds(other.controlBounds),
129 require_moveTo(false),
130 dirtyBounds(other.dirtyBounds),
131 dirtyControlBounds(other.dirtyControlBounds),
132 convex(other.convex),
133 pathConverter(nullptr)
134 {
135 }
136
139
140 inline bool isClosed() const;
141 inline void close();
142 inline void maybeMoveTo();
143 inline void clear();
144
146 if (!pathConverter)
147 pathConverter.reset(new QVectorPathConverter(elements, fillRule, convex));
148 return pathConverter->path;
149 }
150
151private:
153
154 int cStart;
155 Qt::FillRule fillRule;
156
157 QRectF bounds;
158 QRectF controlBounds;
159
160 uint require_moveTo : 1;
161 uint dirtyBounds : 1;
162 uint dirtyControlBounds : 1;
163 uint convex : 1;
164
165 std::unique_ptr<QVectorPathConverter> pathConverter;
166};
167
169{
170public:
172
176};
177
179{
181 path.ensureData();
182 QPainterPathPrivate *data = path.d_func();
183 data->elements.reserve(m_count);
184 int index = 0;
185 data->elements[0].x = m_points[index++];
186 data->elements[0].y = m_points[index++];
187
188 if (m_elements) {
189 data->elements[0].type = m_elements[0];
190 for (int i=1; i<m_count; ++i) {
191 QPainterPath::Element element;
192 element.x = m_points[index++];
193 element.y = m_points[index++];
194 element.type = m_elements[i];
195 data->elements << element;
196 }
197 } else {
199 for (int i=1; i<m_count; ++i) {
200 QPainterPath::Element element;
201 element.x = m_points[index++];
202 element.y = m_points[index++];
204 data->elements << element;
205 }
206 }
207
208 if (m_hints & OddEvenFill)
209 data->fillRule = Qt::OddEvenFill;
210 else
211 data->fillRule = Qt::WindingFill;
212 return path;
213}
214
215void Q_GUI_EXPORT qt_find_ellipse_coords(const QRectF &r, qreal angle, qreal length,
216 QPointF* startPoint, QPointF *endPoint);
217
219{
220 const QPainterPath::Element &first = elements.at(cStart);
221 const QPainterPath::Element &last = elements.last();
222 return first.x == last.x && first.y == last.y;
223}
224
226{
227 Q_ASSERT(ref.loadRelaxed() == 1);
228 require_moveTo = true;
229 const QPainterPath::Element &first = elements.at(cStart);
230 QPainterPath::Element &last = elements.last();
231 if (first.x != last.x || first.y != last.y) {
232 if (qFuzzyCompare(first.x, last.x) && qFuzzyCompare(first.y, last.y)) {
233 last.x = first.x;
234 last.y = first.y;
235 } else {
237 elements << e;
238 }
239 }
240}
241
243{
244 if (require_moveTo) {
245 QPainterPath::Element e = elements.last();
247 elements.append(e);
248 require_moveTo = false;
249 }
250}
251
253{
254 Q_ASSERT(ref.loadRelaxed() == 1);
255
256 elements.clear();
257
258 cStart = 0;
259 bounds = {};
260 controlBounds = {};
261
262 require_moveTo = false;
263 dirtyBounds = false;
264 dirtyControlBounds = false;
265 convex = false;
266
267 pathConverter.reset();
268}
269#define KAPPA qreal(0.5522847498)
270
271
273
274#endif // QPAINTERPATH_P_H
\inmodule QtCore\reentrant
Definition qdatastream.h:30
Definition qlist.h:74
T & last()
Definition qlist.h:631
const_reference at(qsizetype i) const noexcept
Definition qlist.h:429
void reserve(qsizetype size)
Definition qlist.h:746
void append(parameter_type t)
Definition qlist.h:441
void clear()
Definition qlist.h:417
friend struct QPainterPathPrivateDeleter
friend Q_GUI_EXPORT QDataStream & operator<<(QDataStream &, const QPainterPath &)
QPainterPathPrivate(const QPainterPathPrivate &other) noexcept
QPainterPathPrivate & operator=(const QPainterPathPrivate &)=delete
const QVectorPath & vectorPath()
friend Q_GUI_EXPORT QDataStream & operator>>(QDataStream &, QPainterPath &)
~QPainterPathPrivate()=default
QPainterPathPrivate() noexcept
The QPainterPathStroker class is used to generate fillable outlines for a given painter path.
\inmodule QtGui
\inmodule QtGui
ElementType
This enum describes the types of elements used to connect vertices in subpaths.
\inmodule QtCore\reentrant
Definition qpoint.h:214
The QPolygonF class provides a list of points using floating point precision.
Definition qpolygon.h:96
\inmodule QtCore\reentrant
Definition qrect.h:483
\inmodule QtCore
Definition qshareddata.h:19
QSharedData() noexcept
Constructs a QSharedData object with a reference count of 0.
Definition qshareddata.h:23
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
QVectorPathConverter(const QList< QPainterPath::Element > &path, uint fillRule, bool convex)
QVectorPathData pathData
const QVectorPath & vectorPath()
const QPainterPath convertToPainterPath() const
double e
Combined button and popup list for selecting options.
@ WindingFill
@ OddEvenFill
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
Definition qfloat16.h:287
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint index
[2]
GLboolean r
[2]
GLenum GLuint GLenum GLsizei length
GLfloat angle
GLbitfield flags
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint ref
GLint first
GLfixed GLfixed GLint GLint GLfixed points
GLsizei const GLchar *const * path
void Q_GUI_EXPORT qt_find_ellipse_coords(const QRectF &r, qreal angle, qreal length, QPointF *startPoint, QPointF *endPoint)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
static const QTextHtmlElement elements[Html_NumElements]
unsigned int uint
Definition qtypes.h:29
double qreal
Definition qtypes.h:92
QSharedPointer< T > other(t)
[5]
QVectorPathData(const QList< QPainterPath::Element > &path, uint fillRule, bool convex)
QVarLengthArray< QPainterPath::ElementType > elements