summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2010-04-09 03:31:25 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2010-04-09 03:33:39 (GMT)
commit45ca7aff2c04c302906a1af0d9d671bb9cb452f0 (patch)
tree3d486beafbe66ec7fe0b6451abec652211c1328d /src
parent25f17fb8e566fca0838545941d3e0281698ec355 (diff)
downloadQt-45ca7aff2c04c302906a1af0d9d671bb9cb452f0.zip
Qt-45ca7aff2c04c302906a1af0d9d671bb9cb452f0.tar.gz
Qt-45ca7aff2c04c302906a1af0d9d671bb9cb452f0.tar.bz2
Use variant instead of var in QML
In QML "var"s are not the same as JavaScript vars - they are QVariants instead. However, as they behave in a similar enough fashion to native JavaScript it can be confusing to developers when they are called "var".
Diffstat (limited to 'src')
-rw-r--r--src/declarative/qml/qdeclarativebinding.cpp13
-rw-r--r--src/declarative/qml/qdeclarativeobjectscriptclass.cpp7
-rw-r--r--src/declarative/qml/qdeclarativescriptparser.cpp11
3 files changed, 10 insertions, 21 deletions
diff --git a/src/declarative/qml/qdeclarativebinding.cpp b/src/declarative/qml/qdeclarativebinding.cpp
index 6a99855..91eb915 100644
--- a/src/declarative/qml/qdeclarativebinding.cpp
+++ b/src/declarative/qml/qdeclarativebinding.cpp
@@ -170,19 +170,6 @@ void QDeclarativeBinding::update(QDeclarativePropertyPrivate::WriteFlags flags)
if (data->error.isValid()) {
- } else if (!scriptValue.isVariant() && value.userType() == QMetaType::QVariantList &&
- data->property.propertyType() == qMetaTypeId<QVariant>()) {
-
- // This case catches QtScript's automatic conversion to QVariantList for arrays
- QUrl url = QUrl(data->url);
- int line = data->line;
- if (url.isEmpty()) url = QUrl(QLatin1String("<Unknown File>"));
-
- data->error.setUrl(url);
- data->error.setLine(line);
- data->error.setColumn(-1);
- data->error.setDescription(QLatin1String("Unable to assign JavaScript array to QML variant property"));
-
} else if (isUndefined && data->property.isResettable()) {
data->property.reset();
diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp
index ec84da9..4601aaa 100644
--- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp
+++ b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp
@@ -361,12 +361,7 @@ void QDeclarativeObjectScriptClass::setProperty(QObject *obj,
else
v = enginePriv->scriptValueToVariant(value, lastData->propType);
- if (!value.isVariant() && v.userType() == QMetaType::QVariantList &&
- lastData->propType == qMetaTypeId<QVariant>()) {
-
- QString error = QLatin1String("Cannot assign JavaScript array to QML variant property");
- context->throwError(error);
- } else if (!QDeclarativePropertyPrivate::write(obj, *lastData, v, evalContext)) {
+ if (!QDeclarativePropertyPrivate::write(obj, *lastData, v, evalContext)) {
const char *valueType = 0;
if (v.userType() == QVariant::Invalid) valueType = "null";
else valueType = QMetaType::typeName(v.userType());
diff --git a/src/declarative/qml/qdeclarativescriptparser.cpp b/src/declarative/qml/qdeclarativescriptparser.cpp
index 507ff5b..92a10aa 100644
--- a/src/declarative/qml/qdeclarativescriptparser.cpp
+++ b/src/declarative/qml/qdeclarativescriptparser.cpp
@@ -535,7 +535,8 @@ bool ProcessAST::visit(AST::UiPublicMember *node)
// { "time", Object::DynamicProperty::Time, "QTime" },
// { "date", Object::DynamicProperty::Date, "QDate" },
{ "date", Object::DynamicProperty::DateTime, "QDateTime" },
- { "var", Object::DynamicProperty::Variant, "QVariant" }
+ { "var", Object::DynamicProperty::Variant, "QVariant" },
+ { "variant", Object::DynamicProperty::Variant, "QVariant" }
};
const int propTypeNameToTypesCount = sizeof(propTypeNameToTypes) /
sizeof(propTypeNameToTypes[0]);
@@ -563,7 +564,7 @@ bool ProcessAST::visit(AST::UiPublicMember *node)
_parser->_errors << error;
return false;
}
-
+
signal.parameterTypes << qtType;
signal.parameterNames << p->name->asString().toUtf8();
p = p->finish();
@@ -646,6 +647,11 @@ bool ProcessAST::visit(AST::UiPublicMember *node)
property.location = location(node->firstSourceLocation(),
node->lastSourceLocation());
+ if (memberType == QByteArray("var"))
+ qWarning().nospace() << qPrintable(_parser->_scriptFile) << ":" << property.location.start.line << ":"
+ << property.location.start.column << ": var type has been replaced by variant. "
+ << "Support will be removed entirely shortly.";
+
if (node->expression) { // default value
property.defaultValue = new Property;
property.defaultValue->parent = _stateStack.top().object;
@@ -909,6 +915,7 @@ bool QDeclarativeScriptParser::parse(const QByteArray &qmldata, const QUrl &url)
clear();
const QString fileName = url.toString();
+ _scriptFile = fileName;
QTextStream stream(qmldata, QIODevice::ReadOnly);
stream.setCodec("UTF-8");