Commit 30ff6da8 authored by Fawzi Mohamed's avatar Fawzi Mohamed
Browse files

qmljs: add vector*d, quaternion, and matrix4x4 to code model



Added vector2d vector4d, quaternion and matrix4x4 to basic types
and extended completions related to them in the code model.

Task-number: QTCREATORBUG-9929
Change-Id: Iafdbdf5792f640e8eb29d866a372542ee07159a5
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
Reviewed-by: default avatarKai Koehne <kai.koehne@digia.com>
parent 8f19fd60
......@@ -887,8 +887,16 @@ bool Check::visit(UiPublicMember *ast)
preferedType = QLatin1String("'rect'");
else if (init == _context->valueOwner()->qmlSizeObject())
preferedType = QLatin1String("'size'");
else if (init == _context->valueOwner()->qmlVector2DObject())
preferedType = QLatin1String("'vector2d'");
else if (init == _context->valueOwner()->qmlVector3DObject())
preferedType = QLatin1String("'vector3d'");
else if (init == _context->valueOwner()->qmlVector4DObject())
preferedType = QLatin1String("'vector4d'");
else if (init == _context->valueOwner()->qmlQuaternionObject())
preferedType = QLatin1String("'quaternion'");
else if (init == _context->valueOwner()->qmlMatrix4x4Object())
preferedType = QLatin1String("'matrix4x4'");
if (!preferedType.isEmpty())
addMessage(HintPreferNonVarPropertyType, ast->typeToken, preferedType);
......
......@@ -63,7 +63,11 @@ public:
validBuiltinPropertyNames.insert(QLatin1String("url"));
validBuiltinPropertyNames.insert(QLatin1String("var"));
validBuiltinPropertyNames.insert(QLatin1String("variant")); // obsolete in Qt 5
validBuiltinPropertyNames.insert(QLatin1String("vector2d"));
validBuiltinPropertyNames.insert(QLatin1String("vector3d"));
validBuiltinPropertyNames.insert(QLatin1String("vector4d"));
validBuiltinPropertyNames.insert(QLatin1String("quaternion"));
validBuiltinPropertyNames.insert(QLatin1String("matrix4x4"));
validBuiltinPropertyNames.insert(QLatin1String("alias"));
}
......
......@@ -100,7 +100,11 @@ public:
ObjectValue *_qmlPointObject;
ObjectValue *_qmlSizeObject;
ObjectValue *_qmlRectObject;
ObjectValue *_qmlVector2DObject;
ObjectValue *_qmlVector3DObject;
ObjectValue *_qmlVector4DObject;
ObjectValue *_qmlQuaternionObject;
ObjectValue *_qmlMatrix4x4Object;
NullValue _nullValue;
UndefinedValue _undefinedValue;
......@@ -505,11 +509,72 @@ SharedValueOwner::SharedValueOwner(SharedValueOwnerKind kind)
_qmlRectObject->setMember(QLatin1String("width"), numberValue());
_qmlRectObject->setMember(QLatin1String("height"), numberValue());
_qmlVector2DObject = newObject(/*prototype =*/ 0);
_qmlVector2DObject->setClassName(QLatin1String("Vector2D"));
_qmlVector2DObject->setMember(QLatin1String("x"), realValue());
_qmlVector2DObject->setMember(QLatin1String("y"), realValue());
addFunction(_qmlVector2DObject, QLatin1String("plus"), _qmlVector2DObject, 1);
addFunction(_qmlVector2DObject, QLatin1String("minus"), _qmlVector2DObject, 1);
addFunction(_qmlVector2DObject, QLatin1String("times"), _qmlVector2DObject, 1);
addFunction(_qmlVector2DObject, QLatin1String("dotProduct"), realValue(), 1);
addFunction(_qmlVector2DObject, QLatin1String("length"), realValue(), 1);
addFunction(_qmlVector2DObject, QLatin1String("normalized"), _qmlVector2DObject, 0);
addFunction(_qmlVector2DObject, QLatin1String("toVector3d"), _qmlVector3DObject, 0);
addFunction(_qmlVector2DObject, QLatin1String("toVector4d"), _qmlVector4DObject, 0);
addFunction(_qmlVector2DObject, QLatin1String("fuzzyEquals"), booleanValue(), 1, 1);
_qmlVector3DObject = newObject(/*prototype =*/ 0);
_qmlVector3DObject->setClassName(QLatin1String("Vector3D"));
_qmlVector3DObject->setMember(QLatin1String("x"), realValue());
_qmlVector3DObject->setMember(QLatin1String("y"), realValue());
_qmlVector3DObject->setMember(QLatin1String("z"), realValue());
addFunction(_qmlVector3DObject, QLatin1String("plus"), _qmlVector3DObject, 1);
addFunction(_qmlVector3DObject, QLatin1String("minus"), _qmlVector3DObject, 1);
addFunction(_qmlVector3DObject, QLatin1String("times"), _qmlVector3DObject, 1);
addFunction(_qmlVector3DObject, QLatin1String("dotProduct"), realValue(), 1);
addFunction(_qmlVector3DObject, QLatin1String("length"), realValue(), 1);
addFunction(_qmlVector3DObject, QLatin1String("normalized"), _qmlVector3DObject, 0);
addFunction(_qmlVector3DObject, QLatin1String("toVector2d"), _qmlVector2DObject, 0);
addFunction(_qmlVector3DObject, QLatin1String("toVector4d"), _qmlVector4DObject, 0);
addFunction(_qmlVector3DObject, QLatin1String("fuzzyEquals"), booleanValue(), 1, 1);
_qmlVector4DObject = newObject(/*prototype =*/ 0);
_qmlVector4DObject->setClassName(QLatin1String("Vector4D"));
_qmlVector4DObject->setMember(QLatin1String("x"), realValue());
_qmlVector4DObject->setMember(QLatin1String("y"), realValue());
_qmlVector4DObject->setMember(QLatin1String("z"), realValue());
_qmlVector4DObject->setMember(QLatin1String("w"), realValue());
addFunction(_qmlVector4DObject, QLatin1String("plus"), _qmlVector4DObject, 1);
addFunction(_qmlVector4DObject, QLatin1String("minus"), _qmlVector4DObject, 1);
addFunction(_qmlVector4DObject, QLatin1String("times"), _qmlVector4DObject, 1);
addFunction(_qmlVector4DObject, QLatin1String("dotProduct"), realValue(), 1);
addFunction(_qmlVector4DObject, QLatin1String("length"), realValue(), 1);
addFunction(_qmlVector4DObject, QLatin1String("normalized"), _qmlVector4DObject, 0);
addFunction(_qmlVector4DObject, QLatin1String("toVector2d"), _qmlVector2DObject, 0);
addFunction(_qmlVector4DObject, QLatin1String("toVector3d"), _qmlVector3DObject, 0);
addFunction(_qmlVector4DObject, QLatin1String("fuzzyEquals"), booleanValue(), 1, 1);
_qmlQuaternionObject = newObject(/*prototype =*/ 0);
_qmlQuaternionObject->setClassName(QLatin1String("Quaternion"));
_qmlQuaternionObject->setMember(QLatin1String("scalar"), realValue());
_qmlQuaternionObject->setMember(QLatin1String("x"), realValue());
_qmlQuaternionObject->setMember(QLatin1String("y"), realValue());
_qmlQuaternionObject->setMember(QLatin1String("z"), realValue());
_qmlMatrix4x4Object = newObject(/*prototype =*/ 0);
_qmlMatrix4x4Object->setClassName(QLatin1String("Matrix4x4"));
for (int i = 1; i < 5; ++i)
for (int j = 1; j < 5; ++j)
_qmlMatrix4x4Object->setMember(QString::fromLatin1("m%1%2").arg(i).arg(j), realValue());
addFunction(_qmlMatrix4x4Object, QLatin1String("plus"), _qmlMatrix4x4Object, 1);
addFunction(_qmlMatrix4x4Object, QLatin1String("minus"), _qmlMatrix4x4Object, 1);
addFunction(_qmlMatrix4x4Object, QLatin1String("times"), _qmlMatrix4x4Object, 1); // could be matrix or vector
addFunction(_qmlMatrix4x4Object, QLatin1String("row"), _qmlVector4DObject, 1);
addFunction(_qmlMatrix4x4Object, QLatin1String("column"), _qmlMatrix4x4Object, 1);
addFunction(_qmlMatrix4x4Object, QLatin1String("determinant"), realValue(), 0);
addFunction(_qmlMatrix4x4Object, QLatin1String("inverted"), _qmlMatrix4x4Object, 1);
addFunction(_qmlMatrix4x4Object, QLatin1String("transposed"), _qmlMatrix4x4Object, 1);
addFunction(_qmlMatrix4x4Object, QLatin1String("fuzzyEquals"), booleanValue(), 1, 1);
// global Qt object, in alphabetic order
_qtObject = newObject(new QtObjectPrototypeReference(this));
......@@ -535,7 +600,11 @@ SharedValueOwner::SharedValueOwner(SharedValueOwnerKind kind)
addFunction(_qtObject, QLatin1String("rgba"), &_colorValue, 4);
addFunction(_qtObject, QLatin1String("size"), _qmlSizeObject, 2);
addFunction(_qtObject, QLatin1String("tint"), &_colorValue, 2);
addFunction(_qtObject, QLatin1String("vector2d"), _qmlVector2DObject, 2);
addFunction(_qtObject, QLatin1String("vector3d"), _qmlVector3DObject, 3);
addFunction(_qtObject, QLatin1String("vector4d"), _qmlVector4DObject, 4);
addFunction(_qtObject, QLatin1String("quaternion"), _qmlQuaternionObject, 4);
addFunction(_qtObject, QLatin1String("matrix4x4"), _qmlMatrix4x4Object, 16);
_globalObject->setMember(QLatin1String("Qt"), _qtObject);
// firebug/webkit compat
......@@ -821,11 +890,31 @@ const ObjectValue *ValueOwner::qmlRectObject()
return _shared->_qmlRectObject;
}
const ObjectValue *ValueOwner::qmlVector2DObject()
{
return _shared->_qmlVector2DObject;
}
const ObjectValue *ValueOwner::qmlVector3DObject()
{
return _shared->_qmlVector3DObject;
}
const ObjectValue *ValueOwner::qmlVector4DObject()
{
return _shared->_qmlVector4DObject;
}
const ObjectValue *ValueOwner::qmlQuaternionObject()
{
return _shared->_qmlQuaternionObject;
}
const ObjectValue *ValueOwner::qmlMatrix4x4Object()
{
return _shared->_qmlMatrix4x4Object;
}
const Value *ValueOwner::defaultValueForBuiltinType(const QString &name) const
{
// this list is defined in ProcessAST::visit(UiPublicMember) in qdeclarativescript.cpp
......
......@@ -91,7 +91,11 @@ public:
const ObjectValue *qmlPointObject();
const ObjectValue *qmlSizeObject();
const ObjectValue *qmlRectObject();
const ObjectValue *qmlVector2DObject();
const ObjectValue *qmlVector3DObject();
const ObjectValue *qmlVector4DObject();
const ObjectValue *qmlQuaternionObject();
const ObjectValue *qmlMatrix4x4Object();
// converts builtin types, such as int, string to a Value
const Value *defaultValueForBuiltinType(const QString &typeName) const;
......
......@@ -246,8 +246,12 @@ bool Highlighter::maybeQmlBuiltinType(const QStringRef &text) const
return true;
else if (ch == QLatin1Char('l') && text == QLatin1String("list"))
return true;
else if (ch == QLatin1Char('m') && text == QLatin1String("matrix4x4"))
return true;
else if (ch == QLatin1Char('p') && text == QLatin1String("point"))
return true;
else if (ch == QLatin1Char('q') && text == QLatin1String("quaternion"))
return true;
else if (ch == QLatin1Char('r') && text == QLatin1String("real"))
return true;
else if (ch == QLatin1Char('r') && text == QLatin1String("rect"))
......@@ -264,8 +268,12 @@ bool Highlighter::maybeQmlBuiltinType(const QStringRef &text) const
return true;
else if (ch == QLatin1Char('v') && text == QLatin1String("var"))
return true;
else if (ch == QLatin1Char('v') && text == QLatin1String("vector2d"))
return true;
else if (ch == QLatin1Char('v') && text == QLatin1String("vector3d"))
return true;
else if (ch == QLatin1Char('v') && text == QLatin1String("vector4d"))
return true;
else
return false;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment