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 QString fileName, QQuickVectorImageGenerator::GeneratorFlags flags)
24 : m_flags(flags)
25 , m_fileName(fileName)
26{
27}
28
29QQuickGenerator::~QQuickGenerator()
30{
31}
32
33void QQuickGenerator::setAnimationProvider(std::unique_ptr<QQuickGeneratorAnimationProvider>)
34{
35}
36
37void QQuickGenerator::setGeneratorFlags(QQuickVectorImageGenerator::GeneratorFlags flags)
38{
39 m_flags = flags;
40}
41
42QQuickVectorImageGenerator::GeneratorFlags QQuickGenerator::generatorFlags()
43{
44 return m_flags;
45}
46
47bool QQuickGenerator::generate()
48{
49 m_errorState = QQuickVectorImageGenerator::NoError;
50 QSvgVisitorImpl loader(m_fileName, this, m_flags.testFlag(QQuickVectorImageGenerator::AssumeTrustedSource));
51 return loader.doTraversal();
52}
53
54void QQuickGenerator::optimizePaths(const PathNodeInfo &info, const QRectF &overrideBoundingRect)
55{
56 if (Q_UNLIKELY(errorState()))
57 return;
58
59 QPainterPath pathCopy = info.path.defaultValue().value<QPainterPath>();
60 pathCopy.setFillRule(info.fillRule);
61
62 const QRectF &boundingRect = overrideBoundingRect.isNull() ? pathCopy.boundingRect() : overrideBoundingRect;
63 if (m_flags.testFlag(QQuickVectorImageGenerator::GeneratorFlag::OptimizePaths) && !info.path.isAnimated()) {
64 QQuadPath strokePath = QQuadPath::fromPainterPath(pathCopy);
65 bool fillPathNeededClose;
66 QQuadPath fillPath = strokePath.subPathsClosed(&fillPathNeededClose);
67 const bool intersectionsFound = QSGCurveProcessor::solveIntersections(fillPath, false);
68 fillPath.addCurvatureData();
69 QSGCurveProcessor::solveOverlaps(fillPath);
70 const bool compatibleStrokeAndFill = !fillPathNeededClose && !intersectionsFound;
71
72 if (compatibleStrokeAndFill || m_flags.testFlag(QQuickVectorImageGenerator::GeneratorFlag::OutlineStrokeMode)) {
73 outputShapePath(info, nullptr, &fillPath, QQuickVectorImageGenerator::FillAndStroke, boundingRect);
74 } else {
75 outputShapePath(info, nullptr, &fillPath, QQuickVectorImageGenerator::FillPath, boundingRect);
76 outputShapePath(info, nullptr, &strokePath, QQuickVectorImageGenerator::StrokePath, boundingRect);
77 }
78 } else {
79 outputShapePath(info, &pathCopy, nullptr, QQuickVectorImageGenerator::FillAndStroke, boundingRect);
80 }
81}
82
83bool QQuickGenerator::isNodeVisible(const NodeInfo &info)
84{
85 if (!info.isVisible || !info.isDisplayed)
86 return false;
87
88 return true;
89}
90
91void QQuickGenerator::checkSanityLimit_helper(quint64 limit, QLatin1StringView limitObject)
92{
93 qCWarning(lcQuickVectorImage) << "QML generation of untrusted source" << m_fileName
94 << "failed: exceeded sanity limit of" << limit << limitObject;
95 m_errorState = QQuickVectorImageGenerator::SanityLimitsExceeded;
96}
97
98QT_END_NAMESPACE
Combined button and popup list for selecting options.