aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEirik Aavitsland <[email protected]>2025-05-23 09:15:41 +0200
committerEskil Abrahamsen Blomfeldt <[email protected]>2025-06-01 16:59:50 +0200
commit5f9eafcf3999829aca39ba233aadb74bfa264beb (patch)
treeb03e3e5367662ca4359379513dcc8b078a15e892
parentf55deac59a66c424bda83c3dfc3a789b20c9bed5 (diff)
Work around component name clash for multiple VectorImagesHEADdev
The qml generator would create a child component to group the animation properties. This now causes qml engine failures if there are multiple VectorImage items. Work around by dropping the grouping component and just place the animation properties in the top level item directly if the QML generator is going to be used from VectorImage. Change-Id: I77ac9029093f3259aef9357c056da42f09974763 Reviewed-by: Eskil Abrahamsen Blomfeldt <[email protected]> Reviewed-by: Eirik Aavitsland <[email protected]>
-rw-r--r--src/quickvectorimage/generator/qquickqmlgenerator.cpp39
-rw-r--r--src/quickvectorimage/generator/qquickqmlgenerator_p.h5
-rw-r--r--src/quickvectorimage/qquickvectorimage.cpp18
3 files changed, 35 insertions, 27 deletions
diff --git a/src/quickvectorimage/generator/qquickqmlgenerator.cpp b/src/quickvectorimage/generator/qquickqmlgenerator.cpp
index f2f557a185..b420dcde03 100644
--- a/src/quickvectorimage/generator/qquickqmlgenerator.cpp
+++ b/src/quickvectorimage/generator/qquickqmlgenerator.cpp
@@ -290,11 +290,13 @@ void QQuickQmlGenerator::generateGradient(const QGradient *grad)
void QQuickQmlGenerator::generateAnimationBindings()
{
- stream() << "loops: " << m_topLevelIdString << ".animations.loops";
- stream() << "paused: " << m_topLevelIdString << ".animations.paused";
- stream() << "running: true";
+ QString prefix;
+ if (Q_UNLIKELY(!isRuntimeGenerator()))
+ prefix = QStringLiteral(".animations");
- stream() << "property bool wasRunning: false";
+ stream() << "loops: " << m_topLevelIdString << prefix << ".loops";
+ stream() << "paused: " << m_topLevelIdString << prefix << ".paused";
+ stream() << "running: true";
// We need to reset the animation when the loop count changes
stream() << "onLoopsChanged: { if (running) { restart() } }";
@@ -314,7 +316,11 @@ void QQuickQmlGenerator::generatePropertyAnimation(const QQuickAnimatedProperty
+ QStringLiteral("_animation");
mainAnimationId.replace(QLatin1Char('.'), QLatin1Char('_'));
- stream() << "Connections { target: " << m_topLevelIdString << ".animations; function onRestart() {" << mainAnimationId << ".restart() } }";
+ QString prefix;
+ if (Q_UNLIKELY(!isRuntimeGenerator()))
+ prefix = QStringLiteral(".animations");
+
+ stream() << "Connections { target: " << m_topLevelIdString << prefix << "; function onRestart() {" << mainAnimationId << ".restart() } }";
stream() << "ParallelAnimation {";
m_indentLevel++;
@@ -722,7 +728,11 @@ void QQuickQmlGenerator::generateAnimateTransform(const QString &targetName, con
const QString mainAnimationId = targetName
+ QStringLiteral("_transform_animation");
- stream() << "Connections { target: " << m_topLevelIdString << ".animations; function onRestart() {" << mainAnimationId << ".restart() } }";
+
+ QString prefix;
+ if (Q_UNLIKELY(!isRuntimeGenerator()))
+ prefix = QStringLiteral(".animations");
+ stream() << "Connections { target: " << m_topLevelIdString << prefix << "; function onRestart() {" << mainAnimationId << ".restart() } }";
stream() << "ParallelAnimation {";
m_indentLevel++;
@@ -1030,18 +1040,21 @@ bool QQuickQmlGenerator::generateRootNode(const StructureNodeInfo &info)
if (h > 0)
stream() << "implicitHeight: " << h;
- stream() << "component AnimationsInfo : QtObject";
- stream() << "{";
- m_indentLevel++;
+ if (Q_UNLIKELY(!isRuntimeGenerator())) {
+ stream() << "component AnimationsInfo : QtObject";
+ stream() << "{";
+ m_indentLevel++;
+ }
stream() << "property bool paused: false";
stream() << "property int loops: 1";
stream() << "signal restart()";
- m_indentLevel--;
- stream() << "}";
-
- stream() << "property AnimationsInfo animations : AnimationsInfo {}";
+ if (Q_UNLIKELY(!isRuntimeGenerator())) {
+ m_indentLevel--;
+ stream() << "}";
+ stream() << "property AnimationsInfo animations : AnimationsInfo {}";
+ }
if (!info.viewBox.isEmpty()) {
stream() << "transform: [";
diff --git a/src/quickvectorimage/generator/qquickqmlgenerator_p.h b/src/quickvectorimage/generator/qquickqmlgenerator_p.h
index df8ec13c39..e5350c9b25 100644
--- a/src/quickvectorimage/generator/qquickqmlgenerator_p.h
+++ b/src/quickvectorimage/generator/qquickqmlgenerator_p.h
@@ -89,6 +89,11 @@ public:
return m_extraImports;
}
+ bool isRuntimeGenerator() const
+ {
+ return !m_urlPrefix.isEmpty();
+ }
+
protected:
QString generateNodeBase(const NodeInfo &info) override;
bool generateDefsNode(const NodeInfo &info) override;
diff --git a/src/quickvectorimage/qquickvectorimage.cpp b/src/quickvectorimage/qquickvectorimage.cpp
index d3d0dc7945..bcddf810d9 100644
--- a/src/quickvectorimage/qquickvectorimage.cpp
+++ b/src/quickvectorimage/qquickvectorimage.cpp
@@ -197,12 +197,9 @@ void QQuickVectorImage::updateAnimationProperties()
return;
QQuickItem *childItem = d->svgItem->childItems().first();
- if (Q_UNLIKELY(d->animations != nullptr)) {
- QObject *animationsInfo = childItem->property("animations").value<QObject*>();
- if (Q_UNLIKELY(animationsInfo != nullptr)) {
- animationsInfo->setProperty("loops", d->animations->loops());
- animationsInfo->setProperty("paused", d->animations->paused());
- }
+ if (Q_LIKELY(d->animations != nullptr)) {
+ childItem->setProperty("loops", d->animations->loops());
+ childItem->setProperty("paused", d->animations->paused());
}
}
@@ -371,14 +368,7 @@ void QQuickVectorImageAnimations::restart()
return;
QQuickItem *childItem = d->svgItem->childItems().first();
- QObject *animationsInfo = childItem->property("animations").value<QObject*>();
-
- if (Q_UNLIKELY(animationsInfo == nullptr)) {
- qCWarning(lcQuickVectorImage) << Q_FUNC_INFO << "Item does not have animations property";
- return;
- }
-
- QMetaObject::invokeMethod(animationsInfo, "restart");
+ QMetaObject::invokeMethod(childItem, "restart");
}
QT_END_NAMESPACE