Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickgenerator.cpp
Go to the documentation of this file.
1// Copyright (C) 2024 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#include <QVarLengthArray>
5
10
11#include <private/qsgcurveprocessor_p.h>
12#include <private/qquickshape_p.h>
13#include <private/qquadpath_p.h>
14#include <private/qquickitem_p.h>
15#include <private/qquickimagebase_p_p.h>
16
17#include <QtCore/qloggingcategory.h>
18
20
21Q_LOGGING_CATEGORY(lcQuickVectorImage, "qt.quick.vectorimage", QtWarningMsg)
22
23QQuickGenerator::QQuickGenerator(const QQuickVectorImageSource &source,
24 QQuickVectorImageGenerator::GeneratorFlags flags)
25 : m_flags(flags)
26 , m_source(source)
27{
28}
29
30QQuickGenerator::~QQuickGenerator()
31{
32}
33
34void QQuickGenerator::setAnimationProvider(std::unique_ptr<QQuickGeneratorAnimationProvider>)
35{
36}
37
38void QQuickGenerator::setGeneratorFlags(QQuickVectorImageGenerator::GeneratorFlags flags)
39{
40 m_flags = flags;
41}
42
43QQuickVectorImageGenerator::GeneratorFlags QQuickGenerator::generatorFlags()
44{
45 return m_flags;
46}
47
48bool QQuickGenerator::generate()
49{
50 m_errorState = QQuickVectorImageGenerator::NoError;
51 QSvgVisitorImpl loader(m_source, this, m_flags.testFlag(QQuickVectorImageGenerator::AssumeTrustedSource));
52 if (!loader.doTraversal())
53 m_errorState = QQuickVectorImageGenerator::LoadFailed;
54 return m_errorState == QQuickVectorImageGenerator::NoError;
55}
56
57void QQuickGenerator::optimizePaths(const PathNodeInfo &info, const QRectF &overrideBoundingRect)
58{
59 if (Q_UNLIKELY(errorState()))
60 return;
61
62 QPainterPath pathCopy = info.path.defaultValue().value<QPainterPath>();
63 pathCopy.setFillRule(info.fillRule);
64
65 const QRectF &boundingRect = overrideBoundingRect.isNull() ? pathCopy.boundingRect() : overrideBoundingRect;
66 if (m_flags.testFlag(QQuickVectorImageGenerator::GeneratorFlag::OptimizePaths) && !info.path.isAnimated()) {
67 QQuadPath strokePath = QQuadPath::fromPainterPath(pathCopy);
68 bool fillPathNeededClose;
69 QQuadPath fillPath = strokePath.subPathsClosed(&fillPathNeededClose);
70 const bool intersectionsFound = QSGCurveProcessor::solveIntersections(fillPath, false);
71 fillPath.addCurvatureData();
72 QSGCurveProcessor::solveOverlaps(fillPath);
73 const bool compatibleStrokeAndFill = !fillPathNeededClose && !intersectionsFound;
74
75 if (compatibleStrokeAndFill || m_flags.testFlag(QQuickVectorImageGenerator::GeneratorFlag::OutlineStrokeMode)) {
76 outputShapePath(info, nullptr, &fillPath, QQuickVectorImageGenerator::FillAndStroke, boundingRect);
77 } else {
78 outputShapePath(info, nullptr, &fillPath, QQuickVectorImageGenerator::FillPath, boundingRect);
79 outputShapePath(info, nullptr, &strokePath, QQuickVectorImageGenerator::StrokePath, boundingRect);
80 }
81 } else {
82 outputShapePath(info, &pathCopy, nullptr, QQuickVectorImageGenerator::FillAndStroke, boundingRect);
83 }
84}
85
86bool QQuickGenerator::isNodeVisible(const NodeInfo &info)
87{
88 if (!info.isVisible || !info.isDisplayed)
89 return false;
90
91 return true;
92}
93
94void QQuickGenerator::checkSanityLimit_helper(quint64 limit, QLatin1StringView limitObject)
95{
96 qCWarning(lcQuickVectorImage) << "QML generation of untrusted source" << m_source
97 << "failed: exceeded sanity limit of" << limit << limitObject;
98 m_errorState = QQuickVectorImageGenerator::SanityLimitsExceeded;
99}
100
101QT_END_NAMESPACE
Combined button and popup list for selecting options.