aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMitch Curtis <[email protected]>2025-04-18 16:21:58 +0800
committerShawn Rutledge <[email protected]>2025-04-23 09:00:03 +0200
commit9bebb7017b15da1dc9ee6401106a0d92620f4a33 (patch)
tree095329b97ae868f8bbaa1c360432ef7fbbff4e2c /src
parent2a424a02946bd99c265ff0610bb401816e819aec (diff)
QQuickVisualTestUtils: fix bug in forEachStep
The calculation for progress was wrong. With enough steps moving towards a position that's centered over an item, this wouldn't have been noticeable. However, with only a couple of steps, it will fail to reach its target. Before: i=0, progress=0 i=1, progress=0.333333 i=2, progress=0.666667 After: i=0, progress=0 i=1, progress=0.5 i=2, progress=1 forEachStep(1, func) is silly: then there is just one step, so we only call func(1.0) once, and avoid divide-by-zero. Task-number: QTBUG-105856 Task-number: QTBUG-136031 Pick-to: 6.5 6.8 6.9 Change-Id: Ia8e37e3810ab3e94a17bab6d40087e521f1abde0 Reviewed-by: Shawn Rutledge <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/quicktestutils/quick/visualtestutils_p.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/quicktestutils/quick/visualtestutils_p.h b/src/quicktestutils/quick/visualtestutils_p.h
index 6255222313..edb3b2b56f 100644
--- a/src/quicktestutils/quick/visualtestutils_p.h
+++ b/src/quicktestutils/quick/visualtestutils_p.h
@@ -41,8 +41,16 @@ namespace QQuickVisualTestUtils
template<typename F>
void forEachStep(int steps, F &&func)
{
+ if (steps == 1) {
+ // that's odd usage, but cut to the chase then
+ func(qreal(1));
+ return;
+ }
+
for (int i = 0; i < steps; ++i) {
- const qreal progress = qreal(i) / steps;
+ // - 1 because that gives us {0, 0.5, 1} for progress (if steps == 3),
+ // rather than {0, 0.33, 0.66}.
+ const qreal progress = qreal(i) / (steps - 1);
func(progress);
}
}