Commit 3bf071a0 authored by Denis Steckelmacher's avatar Denis Steckelmacher

Support QML built-in types like rect, point, Font, etc

REVIEW: 118918
parent 1926595a
......@@ -217,6 +217,15 @@ void QmlCompletionTest::testContainsDeclaration_data()
// This declaration must be in QtQuick 2.2 but not 2.0 (tested in testDoesNotContainDeclaration)
QTest::newRow("qml_module_version_2.2") << "import QtQuick 2.2\n Item { id: a\n %INVOKE }" << "%CURSOR" << "OpacityAnimator" << true;
// Built-in QML types
QTest::newRow("qml_builtin_types") <<
"import QtQuick 2.0\n"
"\n"
"Text {\n"
" id: foo\n"
" %INVOKE\n"
"}\n" << "font.%CURSOR" << "family" << true;
}
void QmlCompletionTest::testDoesNotContainDeclaration()
......
......@@ -1100,7 +1100,9 @@ void DeclarationBuilder::closeAndAssignType()
AbstractType::Ptr DeclarationBuilder::typeFromName(const QString& name)
{
auto type = IntegralType::TypeNone;
QString realName = name;
// Built-in types
if (name == QLatin1String("string")) {
type = IntegralType::TypeString;
} else if (name == QLatin1String("bool")) {
......@@ -1109,17 +1111,40 @@ AbstractType::Ptr DeclarationBuilder::typeFromName(const QString& name)
type = IntegralType::TypeInt;
} else if (name == QLatin1String("float")) {
type = IntegralType::TypeFloat;
} else if (name == QLatin1String("double")) {
} else if (name == QLatin1String("double") || name == QLatin1String("real")) {
type = IntegralType::TypeDouble;
} else if (name == QLatin1String("void")) {
type = IntegralType::TypeVoid;
} else if (name == QLatin1String("var")) {
} else if (name == QLatin1String("var") || name == QLatin1String("variant")) {
type = IntegralType::TypeMixed;
} else if (m_session->language() == QmlJS::Language::Qml) {
// In QML files, some Qt type names need to be renamed to the QML equivalent
if (name == QLatin1String("QFont")) {
realName = QLatin1String("Font");
} else if (name == QLatin1String("QColor")) {
realName = QLatin1String("color");
} else if (name == QLatin1String("QDateTime")) {
realName = QLatin1String("date");
} else if (name == QLatin1String("QDate")) {
realName = QLatin1String("date");
} else if (name == QLatin1String("QTime")) {
realName = QLatin1String("time");
} else if (name == QLatin1String("QRect") || name == QLatin1String("QRectF")) {
realName = QLatin1String("rect");
} else if (name == QLatin1String("QPoint") || name == QLatin1String("QPointF")) {
realName = QLatin1String("point");
} else if (name == QLatin1String("QSize") || name == QLatin1String("QSizeF")) {
realName = QLatin1String("size");
} else if (name == QLatin1String("QUrl")) {
realName = QLatin1String("url");
} else if (name == QLatin1String("QVector3D")) {
realName = QLatin1String("vector3d");
}
}
if (type == IntegralType::TypeNone) {
// Not a built-in type, but a class
return typeFromClassName(name);
return typeFromClassName(realName);
} else {
return AbstractType::Ptr(new IntegralType(type));
}
......
import builtins 1.0
// This file describes the plugin-supplied types contained in the library.
// It is used for QML tooling purposes only.
//
......
import builtins 1.0
// This file describes the plugin-supplied types contained in the library.
// It is used for QML tooling purposes only.
//
......
/*************************************************************************************
* Copyright (C) 2014 by Denis Steckelmacher <steckdenis@yahoo.fr> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
*************************************************************************************/
Module {
// These declarations are normally provided by the QML runtime
Component {
name: "color"
exports: ["color 1.0"]
}
Component {
name: "date"
exports: ["date 1.0"]
}
Component {
name: "time"
exports: ["time 1.0"]
}
Component {
name: "rect"
exports: ["rect 1.0"]
prototype: "Rectangle"
}
Component {
name: "font"
exports: ["font 1.0"]
prototype: "Font"
}
Component {
name: "point"
exports: ["point 1.0"]
Property { name: "x"; type: "double" }
Property { name: "y"; type: "double" }
}
Component {
name: "size"
exports: ["size 1.0"]
Property { name: "width"; type: "double" }
Property { name: "height"; type: "double" }
}
Component {
name: "url"
exports: ["url 1.0"]
}
Component {
name: "vector2d"
exports: ["vector2d 1.0"]
Property { name: "x"; type: "double" }
Property { name: "y"; type: "double" }
}
Component {
name: "vector3d"
exports: ["vector3d 1.0"]
Property { name: "x"; type: "double" }
Property { name: "y"; type: "double" }
Property { name: "z"; type: "double" }
}
Component {
name: "vector4d"
exports: ["vector4d 1.0"]
Property { name: "x"; type: "double" }
Property { name: "y"; type: "double" }
Property { name: "z"; type: "double" }
Property { name: "w"; type: "double" }
}
Component {
name: "quaternion"
exports: ["quaternion 1.0"]
Property { name: "x"; type: "double" }
Property { name: "y"; type: "double" }
Property { name: "z"; type: "double" }
Property { name: "scalar"; type: "double" }
}
}
\ No newline at end of file
......@@ -38,6 +38,11 @@ Text {
*/
property var bar: "I can contain anything"
/**
* "toString" : "mixed baz"
*/
property variant baz
/**
* "toString" : "int[] ints"
*/
......
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