diff options
author | Sean Harmer <[email protected]> | 2015-11-11 11:09:48 +0000 |
---|---|---|
committer | Sean Harmer <[email protected]> | 2015-11-11 22:12:38 +0000 |
commit | df4a57731ba9cc5aa56d29de0cd7701b07672c31 (patch) | |
tree | b8a30814cb5fc3d4647e0e3bdc456a7db30c17d9 /src | |
parent | ded64d03686268b9ead0f0b5c9299683859a1160 (diff) |
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 <[email protected]>
Reviewed-by: Lars Knoll <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/qml/v8/qqmlbuiltinfunctions.cpp | 5 | ||||
-rw-r--r-- | src/quick/util/qquickglobal.cpp | 6 |
2 files changed, 10 insertions, 1 deletions
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<const qreal*>(argv[0]); QMatrix4x4 m(vals[0], vals[1], vals[2], vals[3], vals[4], vals[5], vals[6], vals[7], |