Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickvaluetypefromstringcheck.cpp
Go to the documentation of this file.
1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
5
6#include <private/qqmlstringconverters_p.h>
7
9
10using namespace Qt::StringLiterals;
11
13 const QString &value)
14{
15 if (typeName == u"QVector2D") {
16 std::array<double, 2> parameters;
17 if (!QQmlStringConverters::isValidNumberString<2, u','>(value, &parameters))
19
21 u"({ x: %1, y: %2 })"_s.arg(parameters[0]).arg(parameters[1]));
22 return result;
23 } else if (typeName == u"QVector3D") {
24 std::array<double, 3> parameters;
25 if (!QQmlStringConverters::isValidNumberString<3, u',', u','>(value, &parameters))
27
29 u"({ x: %1, y: %2, z: %3 })"_s.arg(parameters[0])
30 .arg(parameters[1])
31 .arg(parameters[2]));
32 return result;
33 } else if (typeName == u"QVector4D") {
34 std::array<double, 4> parameters;
35 if (!QQmlStringConverters::isValidNumberString<4, u',', u',', u','>(value, &parameters))
37
39 u"({ x: %1, y: %2, z: %3, w: %4 })"_s.arg(parameters[0])
40 .arg(parameters[1])
41 .arg(parameters[2])
42 .arg(parameters[3]));
43 return result;
44 } else if (typeName == u"QQuaternion") {
45 std::array<double, 4> parameters;
46 if (!QQmlStringConverters::isValidNumberString<4, u',', u',', u','>(value, &parameters))
48
50 u"({ scalar: %1, x: %2, y: %3, z: %4 })"_s.arg(parameters[0])
51 .arg(parameters[1])
52 .arg(parameters[2])
53 .arg(parameters[3]));
54 return result;
55 } else if (typeName == u"QMatrix4x4") {
56 std::array<double, 16> parameters;
57 if (!QQmlStringConverters::isValidNumberString<16, u',', u',', u',', u',', u',', u',', u',',
58 u',', u',', u',', u',', u',', u',', u',',
59 u','>(value, &parameters)) {
61 }
62
63 QString construction = u"({ "_s;
64 for (int i = 0; i < 4; ++i) {
65 for (int j = 0; j < 4; ++j) {
66 construction.append(
67 u"m%1%2: %3"_s.arg(i + 1).arg(j + 1).arg(parameters[i * 4 + j]));
68 if (!(i == 3 && j == 3))
69 construction.append(u", "_s);
70 }
71 }
72 construction.append(u" })"_s);
73
75 return result;
76 }
77
79}
80
static QQmlJSStructuredTypeError check(const QString &typeName, const QString &value)
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QString & append(QChar c)
Definition qstring.cpp:3254
bool isValidNumberString(const QString &s, std::array< double, NumParams > *numbers=nullptr)
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
const char * typeName
GLuint64EXT * result
[6]
static QQmlJSStructuredTypeError withValidString()
static QQmlJSStructuredTypeError withInvalidString()
static QQmlJSStructuredTypeError fromSuggestedString(const QString &enhancedString)