summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2009-11-09 03:07:49 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2009-11-09 03:07:49 (GMT)
commit58e1842aa9703f81c2f55758ba186315524027d8 (patch)
tree617ab67b149e9e35b6dbd19e90f8044f078ca899 /src/declarative/qml
parentd96ec3cff51b952a2db9dd016ca5b21d9bb21adf (diff)
parent7620586aa79c027e5dfd246d53232826333ce715 (diff)
downloadQt-58e1842aa9703f81c2f55758ba186315524027d8.zip
Qt-58e1842aa9703f81c2f55758ba186315524027d8.tar.gz
Qt-58e1842aa9703f81c2f55758ba186315524027d8.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src/declarative/qml')
-rw-r--r--src/declarative/qml/qmlcompiler.cpp13
-rw-r--r--src/declarative/qml/qmlcontext_p.h2
-rw-r--r--src/declarative/qml/qmldom.cpp7
-rw-r--r--src/declarative/qml/qmlengine.cpp17
-rw-r--r--src/declarative/qml/qmlparser.cpp94
-rw-r--r--src/declarative/qml/qmlparser_p.h6
-rw-r--r--src/declarative/qml/qmlvaluetypescriptclass.cpp101
-rw-r--r--src/declarative/qml/qmlvaluetypescriptclass_p.h18
8 files changed, 65 insertions, 193 deletions
diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp
index 240f16c..8e92eb4 100644
--- a/src/declarative/qml/qmlcompiler.cpp
+++ b/src/declarative/qml/qmlcompiler.cpp
@@ -1714,7 +1714,7 @@ bool QmlCompiler::buildGroupedProperty(QmlParser::Property *prop,
prop->value, obj, ctxt.incr()));
obj->addValueTypeProperty(prop);
} else {
- COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid property access"));
+ COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid grouped property access"));
}
} else {
@@ -1722,7 +1722,7 @@ bool QmlCompiler::buildGroupedProperty(QmlParser::Property *prop,
prop->value->metatype =
QmlEnginePrivate::get(engine)->metaObjectForType(prop->type);
if (!prop->value->metatype)
- COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Cannot nest non-QObject property \"%1\"").arg(QString::fromUtf8(prop->name)));
+ COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid grouped property access"));
obj->addGroupedProperty(prop);
@@ -1749,8 +1749,11 @@ bool QmlCompiler::buildValueTypeProperty(QObject *type,
prop->index = idx;
prop->type = p.userType();
- if (prop->value || prop->values.count() != 1)
- COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid property use"));
+ if (prop->value)
+ COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Property assignment expected"));
+
+ if (prop->values.count() != 1)
+ COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Single property assignment expected"));
Value *value = prop->values.at(0);
@@ -1758,7 +1761,7 @@ bool QmlCompiler::buildValueTypeProperty(QObject *type,
bool isPropertyValue = output->types.at(value->object->type).type->propertyValueSourceCast() != -1;
bool isPropertyInterceptor = output->types.at(value->object->type).type->propertyValueInterceptorCast() != -1;
if (!isPropertyValue && !isPropertyInterceptor) {
- COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid property use"));
+ COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Unexpected object assignment"));
} else {
COMPILE_CHECK(buildObject(value->object, ctxt));
diff --git a/src/declarative/qml/qmlcontext_p.h b/src/declarative/qml/qmlcontext_p.h
index 7f9be0f..22d981f 100644
--- a/src/declarative/qml/qmlcontext_p.h
+++ b/src/declarative/qml/qmlcontext_p.h
@@ -74,7 +74,7 @@ class QmlExpressionPrivate;
class QmlAbstractExpression;
class QmlBinding_Id;
-class QmlContextPrivate : public QObjectPrivate
+class Q_DECLARATIVE_EXPORT QmlContextPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QmlContext)
public:
diff --git a/src/declarative/qml/qmldom.cpp b/src/declarative/qml/qmldom.cpp
index b6e794b..39d6730 100644
--- a/src/declarative/qml/qmldom.cpp
+++ b/src/declarative/qml/qmldom.cpp
@@ -52,8 +52,6 @@
QT_BEGIN_NAMESPACE
-DEFINE_BOOL_CONFIG_OPTION(compilerDump, QML_COMPILER_DUMP)
-
QmlDomDocumentPrivate::QmlDomDocumentPrivate()
: root(0)
{
@@ -191,11 +189,6 @@ bool QmlDomDocument::load(QmlEngine *engine, const QByteArray &data, const QUrl
}
if (td->data.tree()) {
- if (compilerDump()) {
- qWarning() << "-AST------------------------------------------------------------------------------";
- td->data.tree()->dump();
- qWarning() << "----------------------------------------------------------------------------------";
- }
d->root = td->data.tree();
d->root->addref();
}
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index e46205d..177818f 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -908,7 +908,7 @@ QVariant QmlEnginePrivate::scriptValueToVariant(const QScriptValue &val)
else if (dc == contextClass)
return QVariant();
- QScriptClass *sc = val.scriptClass();
+ QScriptDeclarativeClass *sc = QScriptDeclarativeClass::scriptClass(val);
if (!sc) {
return val.toVariant();
} else if (sc == valueTypeClass) {
@@ -929,20 +929,7 @@ QVariant QmlScriptClass::toVariant(QmlEngine *engine, const QScriptValue &val)
QmlEnginePrivate *ep =
static_cast<QmlEnginePrivate *>(QObjectPrivate::get(engine));
- QScriptDeclarativeClass *dc = QScriptDeclarativeClass::scriptClass(val);
- if (dc == ep->objectClass)
- return QVariant::fromValue(ep->objectClass->toQObject(val));
- else if (dc == ep->contextClass)
- return QVariant();
-
- QScriptClass *sc = val.scriptClass();
- if (!sc) {
- return val.toVariant();
- } else if (sc == ep->valueTypeClass) {
- return ep->valueTypeClass->toVariant(val);
- }
-
- return QVariant();
+ return ep->scriptValueToVariant(val);
}
// XXX this beyonds in QUrl::toLocalFile()
diff --git a/src/declarative/qml/qmlparser.cpp b/src/declarative/qml/qmlparser.cpp
index 7fd57f3..ee69b14 100644
--- a/src/declarative/qml/qmlparser.cpp
+++ b/src/declarative/qml/qmlparser.cpp
@@ -200,28 +200,6 @@ QmlParser::Object::DynamicSlot::DynamicSlot(const DynamicSlot &o)
{
}
-void QmlParser::Object::dump(int indent) const
-{
- QByteArray ba(indent * 4, ' ');
- if (type != -1) {
- qWarning() << ba.constData() << "Object:" << typeName;
- } else {
- qWarning() << ba.constData() << "Object: fetched";
- }
-
- for (QHash<QByteArray, Property *>::ConstIterator iter = properties.begin();
- iter != properties.end();
- ++iter) {
- qWarning() << ba.constData() << " Property" << iter.key();
- (*iter)->dump(indent + 1);
- }
-
- if (defaultProperty) {
- qWarning() << ba.constData() << " Default property";
- defaultProperty->dump(indent + 1);
- }
-}
-
QmlParser::Property::Property()
: parent(0), type(0), index(-1), value(0), isDefault(true), isDeferred(false)
{
@@ -256,15 +234,6 @@ bool QmlParser::Property::isEmpty() const
return !value && values.isEmpty();
}
-void QmlParser::Property::dump(int indent) const
-{
- QByteArray ba(indent * 4, ' ');
- for (int ii = 0; ii < values.count(); ++ii)
- values.at(ii)->dump(indent);
- if (value)
- value->dump(indent);
-}
-
QmlParser::Value::Value()
: type(Unknown), object(0)
{
@@ -275,69 +244,6 @@ QmlParser::Value::~Value()
if (object) object->release();
}
-void QmlParser::Value::dump(int indent) const
-{
- QByteArray type;
- switch(this->type) {
- default:
- case Value::Unknown:
- type = "Unknown";
- break;
- case Value::Literal:
- type = "Literal";
- break;
- case Value::PropertyBinding:
- type = "PropertyBinding";
- break;
- case Value::ValueSource:
- type = "ValueSource";
- break;
- case Value::ValueInterceptor:
- type = "ValueInterceptor";
- break;
- case Value::CreatedObject:
- type = "CreatedObject";
- break;
- case Value::SignalObject:
- type = "SignalObject";
- break;
- case Value::SignalExpression:
- type = "SignalExpression";
- break;
- case Value::Id:
- type = "Id";
- break;
- }
-
- QByteArray primType;
- switch(this->value.type()) {
- default:
- case Variant::Invalid:
- primType = "Invalid";
- break;
- case Variant::Boolean:
- primType = "Boolean";
- break;
- case Variant::Number:
- primType = "Number";
- break;
- case Variant::String:
- primType = "String";
- break;
- case Variant::Script:
- primType = "Script";
- break;
- }
-
- QByteArray ba(indent * 4, ' ');
- if (object) {
- qWarning() << ba.constData() << "Value (" << type << "):";
- object->dump(indent + 1);
- } else {
- qWarning() << ba.constData() << "Value (" << type << "):" << primType.constData() << primitive();
- }
-}
-
QmlParser::Variant::Variant()
: t(Invalid) {}
diff --git a/src/declarative/qml/qmlparser_p.h b/src/declarative/qml/qmlparser_p.h
index 5bffff2..4f080e5 100644
--- a/src/declarative/qml/qmlparser_p.h
+++ b/src/declarative/qml/qmlparser_p.h
@@ -216,8 +216,6 @@ namespace QmlParser
QList<DynamicSignal> dynamicSignals;
// The list of dynamic slots
QList<DynamicSlot> dynamicSlots;
-
- void dump(int = 0) const;
};
class Variant
@@ -299,8 +297,6 @@ namespace QmlParser
Object *object;
LocationSpan location;
-
- void dump(int = 0) const;
};
class Property : public QmlRefCount
@@ -342,8 +338,6 @@ namespace QmlParser
LocationSpan location;
LocationRange listValueRange;
QList<int> listCommaPositions;
-
- void dump(int = 0) const;
};
}
diff --git a/src/declarative/qml/qmlvaluetypescriptclass.cpp b/src/declarative/qml/qmlvaluetypescriptclass.cpp
index 0c30992..e939e80 100644
--- a/src/declarative/qml/qmlvaluetypescriptclass.cpp
+++ b/src/declarative/qml/qmlvaluetypescriptclass.cpp
@@ -44,15 +44,14 @@
QT_BEGIN_NAMESPACE
-struct QmlValueTypeReference {
+struct QmlValueTypeReference : public QScriptDeclarativeClass::Object {
QmlValueType *type;
QGuard<QObject> object;
int property;
};
-Q_DECLARE_METATYPE(QmlValueTypeReference);
QmlValueTypeScriptClass::QmlValueTypeScriptClass(QmlEngine *bindEngine)
-: QScriptClass(QmlEnginePrivate::getScriptEngine(bindEngine)), engine(bindEngine)
+: QScriptDeclarativeClass(QmlEnginePrivate::getScriptEngine(bindEngine)), engine(bindEngine)
{
}
@@ -62,89 +61,83 @@ QmlValueTypeScriptClass::~QmlValueTypeScriptClass()
QScriptValue QmlValueTypeScriptClass::newObject(QObject *object, int coreIndex, QmlValueType *type)
{
- QmlValueTypeReference ref = { type, object, coreIndex };
- QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine);
- return scriptEngine->newObject(this, scriptEngine->newVariant(qVariantFromValue(ref)));
+ QmlValueTypeReference *ref = new QmlValueTypeReference;
+ ref->type = type;
+ ref->object = object;
+ ref->property = coreIndex;
+ return QScriptDeclarativeClass::newObject(QmlEnginePrivate::getScriptEngine(engine), this, ref);
}
-QmlValueTypeScriptClass::QueryFlags
-QmlValueTypeScriptClass::queryProperty(const QScriptValue &object,
- const QScriptString &name,
- QueryFlags flags, uint *id)
+QScriptClass::QueryFlags
+QmlValueTypeScriptClass::queryProperty(Object *obj, const Identifier &name,
+ QScriptClass::QueryFlags)
{
- Q_UNUSED(flags);
- QmlValueTypeReference ref =
- qvariant_cast<QmlValueTypeReference>(object.data().toVariant());
+ QmlValueTypeReference *ref = static_cast<QmlValueTypeReference *>(obj);
- if (!ref.object)
+ m_lastIndex = -1;
+
+ if (!ref->object)
return 0;
- QByteArray propName = name.toString().toUtf8();
+ QByteArray propName = toString(name).toUtf8();
- int idx = ref.type->metaObject()->indexOfProperty(propName.constData());
- if (idx == -1)
+ m_lastIndex = ref->type->metaObject()->indexOfProperty(propName.constData());
+ if (m_lastIndex == -1)
return 0;
- *id = idx;
- QMetaProperty prop = ref.object->metaObject()->property(idx);
+ QMetaProperty prop = ref->object->metaObject()->property(m_lastIndex);
- QmlValueTypeScriptClass::QueryFlags rv =
- QmlValueTypeScriptClass::HandlesReadAccess;
+ QScriptClass::QueryFlags rv =
+ QScriptClass::HandlesReadAccess;
if (prop.isWritable())
- rv |= QmlValueTypeScriptClass::HandlesWriteAccess;
+ rv |= QScriptClass::HandlesWriteAccess;
return rv;
}
-QScriptValue QmlValueTypeScriptClass::property(const QScriptValue &object,
- const QScriptString &name,
- uint id)
+QScriptValue QmlValueTypeScriptClass::property(Object *obj, const Identifier &)
{
- Q_UNUSED(name);
- QmlValueTypeReference ref =
- qvariant_cast<QmlValueTypeReference>(object.data().toVariant());
-
- if (!ref.object)
- return QScriptValue();
+ QmlValueTypeReference *ref = static_cast<QmlValueTypeReference *>(obj);
- ref.type->read(ref.object, ref.property);
-
- QMetaProperty p = ref.type->metaObject()->property(id);
- QVariant rv = p.read(ref.type);
+ QMetaProperty p = ref->type->metaObject()->property(m_lastIndex);
+ ref->type->read(ref->object, ref->property);
+ QVariant rv = p.read(ref->type);
return static_cast<QmlEnginePrivate *>(QObjectPrivate::get(engine))->scriptValueFromVariant(rv);
}
-void QmlValueTypeScriptClass::setProperty(QScriptValue &object,
- const QScriptString &name,
- uint id,
+void QmlValueTypeScriptClass::setProperty(Object *obj, const Identifier &,
const QScriptValue &value)
{
- Q_UNUSED(name);
- QmlValueTypeReference ref =
- qvariant_cast<QmlValueTypeReference>(object.data().toVariant());
-
- if (!ref.object)
- return;
+ QmlValueTypeReference *ref = static_cast<QmlValueTypeReference *>(obj);
QVariant v = QmlScriptClass::toVariant(engine, value);
- ref.type->read(ref.object, ref.property);
- QMetaProperty p = ref.type->metaObject()->property(id);
- p.write(ref.type, v);
- ref.type->write(ref.object, ref.property, 0);
+ ref->type->read(ref->object, ref->property);
+ QMetaProperty p = ref->type->metaObject()->property(m_lastIndex);
+ p.write(ref->type, v);
+ ref->type->write(ref->object, ref->property, 0);
}
-QVariant QmlValueTypeScriptClass::toVariant(const QScriptValue &val)
+QVariant QmlValueTypeScriptClass::toVariant(Object *obj, bool *ok)
{
- QmlValueTypeReference ref =
- qvariant_cast<QmlValueTypeReference>(val.data().toVariant());
+ QmlValueTypeReference *ref = static_cast<QmlValueTypeReference *>(obj);
- if (!ref.object)
+ if (ok) *ok = true;
+
+ if (ref->object) {
+ ref->type->read(ref->object, ref->property);
+ return ref->type->value();
+ } else {
return QVariant();
+ }
+}
+
+QVariant QmlValueTypeScriptClass::toVariant(const QScriptValue &value)
+{
+ Q_ASSERT(scriptClass(value) == this);
- QMetaProperty p = ref.object->metaObject()->property(ref.property);
- return p.read(ref.object);
+ return toVariant(object(value), 0);
}
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qmlvaluetypescriptclass_p.h b/src/declarative/qml/qmlvaluetypescriptclass_p.h
index bd31ec1..19020b2 100644
--- a/src/declarative/qml/qmlvaluetypescriptclass_p.h
+++ b/src/declarative/qml/qmlvaluetypescriptclass_p.h
@@ -59,7 +59,7 @@ QT_BEGIN_NAMESPACE
class QmlEngine;
class QmlValueType;
-class QmlValueTypeScriptClass : public QScriptClass
+class QmlValueTypeScriptClass : public QScriptDeclarativeClass
{
public:
QmlValueTypeScriptClass(QmlEngine *);
@@ -67,20 +67,16 @@ public:
QScriptValue newObject(QObject *object, int coreIndex, QmlValueType *);
- virtual QueryFlags queryProperty(const QScriptValue &object,
- const QScriptString &name,
- QueryFlags flags, uint *id);
- virtual QScriptValue property(const QScriptValue &object,
- const QScriptString &name,
- uint id);
- virtual void setProperty(QScriptValue &object,
- const QScriptString &name,
- uint id,
- const QScriptValue &value);
+ virtual QScriptClass::QueryFlags queryProperty(Object *, const Identifier &,
+ QScriptClass::QueryFlags flags);
+ virtual QScriptValue property(Object *, const Identifier &);
+ virtual void setProperty(Object *, const Identifier &name, const QScriptValue &);
+ virtual QVariant toVariant(Object *, bool *ok = 0);
QVariant toVariant(const QScriptValue &);
private:
QmlEngine *engine;
+ int m_lastIndex;
};
QT_END_NAMESPACE