aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@qt.io>2018-07-16 10:03:16 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2018-08-16 04:46:44 +0000
commit5e5c9f7218422143827401c95dd60d0872d228aa (patch)
treea23c82d28a9f981c36f93afa0b278dac20be9a14 /src
parenta18ab2a3822e0d38e8ff19ccdf44d9fc802b5d02 (diff)
Modernize loops and simplify QQmlEasingValueType::setBezierCurve
Change-Id: I9b64ab9fb99b885ad66acebb82dd7b614401f143 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qml/qml/qqmlvaluetype.cpp60
1 files changed, 27 insertions, 33 deletions
diff --git a/src/qml/qml/qqmlvaluetype.cpp b/src/qml/qml/qqmlvaluetype.cpp
index 270414a676..2b21591017 100644
--- a/src/qml/qml/qqmlvaluetype.cpp
+++ b/src/qml/qml/qqmlvaluetype.cpp
@@ -67,8 +67,7 @@ struct QQmlValueTypeFactoryImpl
QQmlValueTypeFactoryImpl::QQmlValueTypeFactoryImpl()
{
- for (unsigned int ii = 0; ii < QVariant::UserType; ++ii)
- valueTypes[ii] = nullptr;
+ std::fill_n(valueTypes, int(QVariant::UserType), nullptr);
// See types wrapped in qqmlmodelindexvaluetype_p.h
qRegisterMetaType<QItemSelectionRange>();
@@ -521,38 +520,33 @@ void QQmlEasingValueType::setBezierCurve(const QVariantList &customCurveVariant)
if (customCurveVariant.isEmpty())
return;
- QVariantList variantList = customCurveVariant;
- if ((variantList.count() % 6) == 0) {
- bool allRealsOk = true;
- QVector<qreal> reals;
- const int variantListCount = variantList.count();
- reals.reserve(variantListCount);
- for (int i = 0; i < variantListCount; i++) {
- bool ok;
- const qreal real = variantList.at(i).toReal(&ok);
- reals.append(real);
- if (!ok)
- allRealsOk = false;
- }
- if (allRealsOk) {
- QEasingCurve newEasingCurve(QEasingCurve::BezierSpline);
- for (int i = 0; i < reals.count() / 6; i++) {
- const qreal c1x = reals.at(i * 6);
- const qreal c1y = reals.at(i * 6 + 1);
- const qreal c2x = reals.at(i * 6 + 2);
- const qreal c2y = reals.at(i * 6 + 3);
- const qreal c3x = reals.at(i * 6 + 4);
- const qreal c3y = reals.at(i * 6 + 5);
-
- const QPointF c1(c1x, c1y);
- const QPointF c2(c2x, c2y);
- const QPointF c3(c3x, c3y);
-
- newEasingCurve.addCubicBezierSegment(c1, c2, c3);
- v = newEasingCurve;
- }
- }
+ if ((customCurveVariant.count() % 6) != 0)
+ return;
+
+ auto convert = [](const QVariant &v, qreal &r) {
+ bool ok;
+ r = v.toReal(&ok);
+ return ok;
+ };
+
+ QEasingCurve newEasingCurve(QEasingCurve::BezierSpline);
+ for (int i = 0, ei = customCurveVariant.size(); i < ei; i += 6) {
+ qreal c1x, c1y, c2x, c2y, c3x, c3y;
+ if (!convert(customCurveVariant.at(i ), c1x)) return;
+ if (!convert(customCurveVariant.at(i + 1), c1y)) return;
+ if (!convert(customCurveVariant.at(i + 2), c2x)) return;
+ if (!convert(customCurveVariant.at(i + 3), c2y)) return;
+ if (!convert(customCurveVariant.at(i + 4), c3x)) return;
+ if (!convert(customCurveVariant.at(i + 5), c3y)) return;
+
+ const QPointF c1(c1x, c1y);
+ const QPointF c2(c2x, c2y);
+ const QPointF c3(c3x, c3y);
+
+ newEasingCurve.addCubicBezierSegment(c1, c2, c3);
}
+
+ v = newEasingCurve;
}
QVariantList QQmlEasingValueType::bezierCurve() const