summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-12-16 05:31:56 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-12-16 05:31:56 (GMT)
commit7ce189fa6371224c6801dd61191dff758d1ccc86 (patch)
tree96b3271046f42ce56743401bbf7f84a70f8436ba /src/declarative/qml
parent0bd5787e4d4c89fd860ff70bcdb0ddb9e4a4f8db (diff)
parentb9d7f819b7bf9f7c39735377ae2e3e4d4afa1cf7 (diff)
downloadQt-7ce189fa6371224c6801dd61191dff758d1ccc86.zip
Qt-7ce189fa6371224c6801dd61191dff758d1ccc86.tar.gz
Qt-7ce189fa6371224c6801dd61191dff758d1ccc86.tar.bz2
Merge branch 'kinetic-declarativeui' of scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src/declarative/qml')
-rw-r--r--src/declarative/qml/qmlcompiler.cpp56
-rw-r--r--src/declarative/qml/qmlcompiler_p.h4
-rw-r--r--src/declarative/qml/qmlcontext.cpp32
-rw-r--r--src/declarative/qml/qmlcontext.h2
-rw-r--r--src/declarative/qml/qmlscriptparser.cpp3
-rw-r--r--src/declarative/qml/qmlsqldatabase.cpp6
6 files changed, 100 insertions, 3 deletions
diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp
index f25f8b8..acfdda3 100644
--- a/src/declarative/qml/qmlcompiler.cpp
+++ b/src/declarative/qml/qmlcompiler.cpp
@@ -2037,6 +2037,14 @@ bool QmlCompiler::buildPropertyLiteralAssignment(QmlParser::Property *prop,
if (v->value.isScript()) {
+ //optimization for <Type>.<EnumValue> enum assignments
+ bool isEnumAssignment = false;
+ COMPILE_CHECK(testQualifiedEnumAssignment(obj->metaObject()->property(prop->index), obj, v, &isEnumAssignment));
+ if (isEnumAssignment) {
+ v->type = Value::Literal;
+ return true;
+ }
+
COMPILE_CHECK(buildBinding(v, prop, ctxt));
v->type = Value::PropertyBinding;
@@ -2051,6 +2059,50 @@ bool QmlCompiler::buildPropertyLiteralAssignment(QmlParser::Property *prop,
return true;
}
+bool QmlCompiler::testQualifiedEnumAssignment(const QMetaProperty &prop,
+ QmlParser::Object *obj,
+ QmlParser::Value *v,
+ bool *isAssignment)
+{
+ *isAssignment = false;
+ if (!prop.isEnumType())
+ return true;
+
+ if (!prop.isWritable())
+ COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop.name())));
+
+ QString string = v->value.asString();
+ if (!string.at(0).isUpper())
+ return true;
+
+ QStringList parts = string.split(QLatin1Char('.'));
+ if (parts.count() != 2)
+ return true;
+
+ QString typeName = parts.at(0);
+ QmlType *type = 0;
+ QmlEnginePrivate::get(engine)->resolveType(unit->imports, typeName.toUtf8(),
+ &type, 0, 0, 0, 0);
+
+ if (!type || obj->typeName != type->qmlTypeName())
+ return true;
+
+ QString enumValue = parts.at(1);
+ int value;
+ if (prop.isFlagType()) {
+ value = prop.enumerator().keysToValue(enumValue.toUtf8().constData());
+ } else
+ value = prop.enumerator().keyToValue(enumValue.toUtf8().constData());
+ if (value == -1)
+ return true;
+
+ v->type = Value::Literal;
+ v->value = QmlParser::Variant(enumValue);
+ *isAssignment = true;
+
+ return true;
+}
+
// Ensures that the dynamic meta specification on obj is valid
bool QmlCompiler::checkDynamicMeta(QmlParser::Object *obj)
{
@@ -2352,10 +2404,10 @@ bool QmlCompiler::compileAlias(QMetaObjectBuilder &builder,
QStringList alias = astNodeToStringList(node);
if (alias.count() != 1 && alias.count() != 2)
- COMPILE_EXCEPTION(prop.defaultValue, QCoreApplication::translate("QmlCompiler","Invalid alias location"));
+ COMPILE_EXCEPTION(prop.defaultValue, QCoreApplication::translate("QmlCompiler","Invalid alias reference. An alias reference must be specified as <id> or <id>.<property>"));
if (!compileState.ids.contains(alias.at(0)))
- COMPILE_EXCEPTION(prop.defaultValue, QCoreApplication::translate("QmlCompiler","Invalid alias location"));
+ COMPILE_EXCEPTION(prop.defaultValue, QCoreApplication::translate("QmlCompiler","Invalid alias reference. Unable to find id \"%1\"").arg(alias.at(0)));
Object *idObject = compileState.ids[alias.at(0)];
diff --git a/src/declarative/qml/qmlcompiler_p.h b/src/declarative/qml/qmlcompiler_p.h
index 3fcba15..740d97c 100644
--- a/src/declarative/qml/qmlcompiler_p.h
+++ b/src/declarative/qml/qmlcompiler_p.h
@@ -219,6 +219,10 @@ private:
bool doesPropertyExist(QmlParser::Property *prop, QmlParser::Object *obj);
bool testLiteralAssignment(const QMetaProperty &prop,
QmlParser::Value *value);
+ bool testQualifiedEnumAssignment(const QMetaProperty &prop,
+ QmlParser::Object *obj,
+ QmlParser::Value *value,
+ bool *isAssignment);
enum DynamicMetaMode { IgnoreAliases, ResolveAliases, ForceCreation };
bool mergeDynamicMetaProperties(QmlParser::Object *obj);
bool buildDynamicMeta(QmlParser::Object *obj, DynamicMetaMode mode);
diff --git a/src/declarative/qml/qmlcontext.cpp b/src/declarative/qml/qmlcontext.cpp
index c3971ae..49bb59c 100644
--- a/src/declarative/qml/qmlcontext.cpp
+++ b/src/declarative/qml/qmlcontext.cpp
@@ -442,6 +442,38 @@ void QmlContext::setContextProperty(const QString &name, QObject *value)
}
}
+QVariant QmlContext::contextProperty(const QString &name) const
+{
+ Q_D(const QmlContext);
+ QVariant value;
+ int idx = -1;
+ if (d->propertyNames)
+ idx = d->propertyNames->value(name);
+
+ if (idx == -1) {
+ QByteArray utf8Name = name.toUtf8();
+ for (int ii = d->defaultObjects.count() - 1; ii >= 0; --ii) {
+ QObject *obj = d->defaultObjects.at(ii);
+ QmlDeclarativeData *data = QmlDeclarativeData::get(obj);
+ if (data && data->propertyCache) {
+ QmlPropertyCache::Data *property = data->propertyCache->property(name);
+ if (property)
+ value = obj->metaObject()->property(property->coreIndex).read(obj);
+ } else {
+ value = obj->property(utf8Name);
+ }
+ if (value.isValid())
+ break;
+ }
+ if (!value.isValid() && parentContext())
+ value = parentContext()->contextProperty(name);
+ } else {
+ value = d->propertyValues[idx];
+ }
+
+ return value;
+}
+
/*!
Resolves the URL \a src relative to the URL of the
containing component.
diff --git a/src/declarative/qml/qmlcontext.h b/src/declarative/qml/qmlcontext.h
index de1d092..7547004 100644
--- a/src/declarative/qml/qmlcontext.h
+++ b/src/declarative/qml/qmlcontext.h
@@ -75,6 +75,8 @@ public:
void setContextProperty(const QString &, QObject *);
void setContextProperty(const QString &, const QVariant &);
+ QVariant contextProperty(const QString &) const;
+
QUrl resolvedUrl(const QUrl &);
void setBaseUrl(const QUrl &);
diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp
index 35234ec..a24ef51 100644
--- a/src/declarative/qml/qmlscriptparser.cpp
+++ b/src/declarative/qml/qmlscriptparser.cpp
@@ -600,6 +600,9 @@ bool ProcessAST::visit(AST::UiPublicMember *node)
if (node->expression) { // default value
property.defaultValue = new Property;
property.defaultValue->parent = _stateStack.top().object;
+ property.defaultValue->location =
+ location(node->expression->firstSourceLocation(),
+ node->expression->lastSourceLocation());
Value *value = new Value;
value->location = location(node->expression->firstSourceLocation(),
node->expression->lastSourceLocation());
diff --git a/src/declarative/qml/qmlsqldatabase.cpp b/src/declarative/qml/qmlsqldatabase.cpp
index c3c3ca3..4fa63cb 100644
--- a/src/declarative/qml/qmlsqldatabase.cpp
+++ b/src/declarative/qml/qmlsqldatabase.cpp
@@ -44,7 +44,7 @@
#include "qmlengine.h"
#include "qmlengine_p.h"
#include "qmlrefcount_p.h"
-#include "qmlengine_p.h"
+#include "qmlexpression_p.h"
#include <QtCore/qobject.h>
#include <QtScript/qscriptvalue.h>
@@ -319,6 +319,10 @@ static QScriptValue qmlsqldatabase_transaction_shared(QScriptContext *context, Q
instance.setProperty(QLatin1String("executeSql"),
engine->newFunction(qmlsqldatabase_executeSql_outsidetransaction));
if (engine->hasUncaughtException()) {
+ QmlError error;
+ QmlExpressionPrivate::exceptionToError(engine, error);
+ qWarning() << error;
+ engine->clearExceptions();
db.rollback();
} else {
if (!db.commit())