4
4
#include < QtQml/qqmlengine.h>
5
5
#include < QtQml/qqmlcomponent.h>
6
6
7
+ #include < QtTest/qsignalspy.h>
8
+
7
9
#include < QtQmlModels/private/qqmldelegatemodel_p.h>
8
10
#include < QtQuick3D/private/qquick3drepeater_p.h>
9
11
@@ -126,6 +128,8 @@ void tst_qquick3drepeater::delegateModelAccess()
126
128
QQuick3DRepeater *repeater = qvariant_cast<QQuick3DRepeater *>(object->property (" repeater" ));
127
129
QVERIFY (repeater);
128
130
131
+ QSignalSpy modelChangedSpy (repeater, &QQuick3DRepeater::modelChanged);
132
+
129
133
if (delegateKind == Delegate::Untyped && modelKind == Model::Array)
130
134
QSKIP (" Properties of objects in arrays are not exposed as context properties" );
131
135
@@ -150,20 +154,34 @@ void tst_qquick3drepeater::delegateModelAccess()
150
154
? access != QQmlDelegateModel::ReadOnly
151
155
: access == QQmlDelegateModel::ReadWrite;
152
156
157
+ // Only the array is actually updated itself. The other models are pointers
158
+ const bool writeShouldSignal = modelKind == Model::Kind::Array;
159
+
153
160
double expected = 11 ;
154
161
162
+ // Initial setting of the model, signals one update
163
+ int expectedModelUpdates = 1 ;
164
+ QCOMPARE (modelChangedSpy.count (), expectedModelUpdates);
165
+
155
166
QCOMPARE (delegate->property (" immediateX" ).toDouble (), expected);
156
167
QCOMPARE (delegate->property (" modelX" ).toDouble (), expected);
157
168
158
- if (modelWritable)
169
+ if (modelWritable) {
159
170
expected = 3 ;
171
+ if (writeShouldSignal)
172
+ ++expectedModelUpdates;
173
+ }
160
174
161
175
QMetaObject::invokeMethod (delegate, " writeThroughModel" );
162
176
QCOMPARE (delegate->property (" immediateX" ).toDouble (), expected);
163
177
QCOMPARE (delegate->property (" modelX" ).toDouble (), expected);
178
+ QCOMPARE (modelChangedSpy.count (), expectedModelUpdates);
164
179
165
- if (immediateWritable)
180
+ if (immediateWritable) {
166
181
expected = 1 ;
182
+ if (writeShouldSignal)
183
+ ++expectedModelUpdates;
184
+ }
167
185
168
186
QMetaObject::invokeMethod (delegate, " writeImmediate" );
169
187
@@ -172,6 +190,7 @@ void tst_qquick3drepeater::delegateModelAccess()
172
190
delegateKind == Delegate::Untyped ? expected : 1 );
173
191
174
192
QCOMPARE (delegate->property (" modelX" ).toDouble (), expected);
193
+ QCOMPARE (modelChangedSpy.count (), expectedModelUpdates);
175
194
}
176
195
177
196
QTEST_MAIN (tst_qquick3drepeater)
0 commit comments