From df4a57731ba9cc5aa56d29de0cd7701b07672c31 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Wed, 11 Nov 2015 11:09:48 +0000 Subject: Introduce a more sane "default constructor" for Qt.matrix4x4() If no arguments are specified, create an identity matrix. This is by far the most common use case. This change avoids having to type in the 16 arguments of the identity matrix. Change-Id: I9e0d71897c5368d19ae87cff936df4b9e5e9b84a Reviewed-by: Laszlo Agocs Reviewed-by: Lars Knoll --- src/qml/qml/v8/qqmlbuiltinfunctions.cpp | 5 +++++ src/quick/util/qquickglobal.cpp | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp index 72a3fe1537..ca488021c8 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp +++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp @@ -434,11 +434,16 @@ Returns a Matrix4x4 with the specified values. Alternatively, the function may be called with a single argument where that argument is a JavaScript array which contains the sixteen matrix values. +Finally, the function may be called with no arguments and the resulting +matrix will be the identity matrix. */ ReturnedValue QtObject::method_matrix4x4(QV4::CallContext *ctx) { QV4::ExecutionEngine *v4 = ctx->d()->engine; + if (ctx->argc() == 0) + return ctx->engine()->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QMatrix4x4, 0, Q_NULLPTR)); + if (ctx->argc() == 1 && ctx->args()[0].isObject()) { bool ok = false; QVariant v = QQml_valueTypeProvider()->createVariantFromJsObject(QMetaType::QMatrix4x4, QQmlV4Handle(ctx->args()[0]), v4, &ok); diff --git a/src/quick/util/qquickglobal.cpp b/src/quick/util/qquickglobal.cpp index 25dd09c01f..2ea1a062d8 100644 --- a/src/quick/util/qquickglobal.cpp +++ b/src/quick/util/qquickglobal.cpp @@ -466,7 +466,11 @@ public: } break; case QMetaType::QMatrix4x4: - if (argc == 1) { + if (argc == 0) { + QMatrix4x4 m; + *v = QVariant(m); + return true; + } else if (argc == 1) { const qreal *vals = reinterpret_cast(argv[0]); QMatrix4x4 m(vals[0], vals[1], vals[2], vals[3], vals[4], vals[5], vals[6], vals[7], -- cgit v1.2.3