Skip to content

Commit 7daf594

Browse files
author
Ulf Hermann
committed
Properly wire up change signal for QQuick3DRepeater's model
If the model contents change we need to notify. Pick-to: 6.10 Task-number: QTBUG-139941 Change-Id: I455deb52fa97d0459cb0989ac3676c2861816650 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
1 parent 2237311 commit 7daf594

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/quick3d/qquick3drepeater.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,13 @@ void QQuick3DRepeater::connectModel(QQmlDelegateModelPointer *model)
9494
QObject::connect(
9595
dataModel, &QQmlDelegateModel::delegateChanged,
9696
this, &QQuick3DRepeater::applyDelegateChange);
97+
if (m_ownModel) {
98+
QObject::connect(
99+
dataModel, &QQmlDelegateModel::modelChanged,
100+
this, &QQuick3DRepeater::modelChanged);
101+
}
97102
}
103+
98104
regenerate();
99105
}
100106

@@ -114,6 +120,11 @@ void QQuick3DRepeater::disconnectModel(QQmlDelegateModelPointer *model)
114120
QObject::disconnect(
115121
delegateModel, &QQmlDelegateModel::delegateChanged,
116122
this, &QQuick3DRepeater::applyDelegateChange);
123+
if (m_ownModel) {
124+
QObject::disconnect(
125+
delegateModel, &QQmlDelegateModel::modelChanged,
126+
this, &QQuick3DRepeater::modelChanged);
127+
}
117128
}
118129
}
119130

tests/auto/quick3d/qquick3drepeater/tst_qquick3drepeater.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <QtQml/qqmlengine.h>
55
#include <QtQml/qqmlcomponent.h>
66

7+
#include <QtTest/qsignalspy.h>
8+
79
#include <QtQmlModels/private/qqmldelegatemodel_p.h>
810
#include <QtQuick3D/private/qquick3drepeater_p.h>
911

@@ -126,6 +128,8 @@ void tst_qquick3drepeater::delegateModelAccess()
126128
QQuick3DRepeater *repeater = qvariant_cast<QQuick3DRepeater *>(object->property("repeater"));
127129
QVERIFY(repeater);
128130

131+
QSignalSpy modelChangedSpy(repeater, &QQuick3DRepeater::modelChanged);
132+
129133
if (delegateKind == Delegate::Untyped && modelKind == Model::Array)
130134
QSKIP("Properties of objects in arrays are not exposed as context properties");
131135

@@ -150,20 +154,34 @@ void tst_qquick3drepeater::delegateModelAccess()
150154
? access != QQmlDelegateModel::ReadOnly
151155
: access == QQmlDelegateModel::ReadWrite;
152156

157+
// Only the array is actually updated itself. The other models are pointers
158+
const bool writeShouldSignal = modelKind == Model::Kind::Array;
159+
153160
double expected = 11;
154161

162+
// Initial setting of the model, signals one update
163+
int expectedModelUpdates = 1;
164+
QCOMPARE(modelChangedSpy.count(), expectedModelUpdates);
165+
155166
QCOMPARE(delegate->property("immediateX").toDouble(), expected);
156167
QCOMPARE(delegate->property("modelX").toDouble(), expected);
157168

158-
if (modelWritable)
169+
if (modelWritable) {
159170
expected = 3;
171+
if (writeShouldSignal)
172+
++expectedModelUpdates;
173+
}
160174

161175
QMetaObject::invokeMethod(delegate, "writeThroughModel");
162176
QCOMPARE(delegate->property("immediateX").toDouble(), expected);
163177
QCOMPARE(delegate->property("modelX").toDouble(), expected);
178+
QCOMPARE(modelChangedSpy.count(), expectedModelUpdates);
164179

165-
if (immediateWritable)
180+
if (immediateWritable) {
166181
expected = 1;
182+
if (writeShouldSignal)
183+
++expectedModelUpdates;
184+
}
167185

168186
QMetaObject::invokeMethod(delegate, "writeImmediate");
169187

@@ -172,6 +190,7 @@ void tst_qquick3drepeater::delegateModelAccess()
172190
delegateKind == Delegate::Untyped ? expected : 1);
173191

174192
QCOMPARE(delegate->property("modelX").toDouble(), expected);
193+
QCOMPARE(modelChangedSpy.count(), expectedModelUpdates);
175194
}
176195

177196
QTEST_MAIN(tst_qquick3drepeater)

0 commit comments

Comments
 (0)