summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2009-11-04 23:34:16 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2009-11-04 23:34:16 (GMT)
commit8fe5ffc002f6ce3c8d7b688ddb2a7f2f7fd45dda (patch)
treee8ed4f7df795fb8c5a393a3472788283d88d33d3 /src/declarative
parentcb48b1bd67e094446cf73d8a0940d25dc8334708 (diff)
parente68a0dafbff345eebb15cf6f1a5d88df37f0269a (diff)
downloadQt-8fe5ffc002f6ce3c8d7b688ddb2a7f2f7fd45dda.zip
Qt-8fe5ffc002f6ce3c8d7b688ddb2a7f2f7fd45dda.tar.gz
Qt-8fe5ffc002f6ce3c8d7b688ddb2a7f2f7fd45dda.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/qml/qmlcompiler.cpp33
-rw-r--r--src/declarative/qml/qmlmetaproperty.cpp112
-rw-r--r--src/declarative/qml/qmlmetaproperty.h6
-rw-r--r--src/declarative/qml/qmlmetaproperty_p.h5
-rw-r--r--src/declarative/qml/qmlvme.cpp6
5 files changed, 60 insertions, 102 deletions
diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp
index 3253e72..240f16c 100644
--- a/src/declarative/qml/qmlcompiler.cpp
+++ b/src/declarative/qml/qmlcompiler.cpp
@@ -814,8 +814,7 @@ void QmlCompiler::genObject(QmlParser::Object *obj)
create.create.type = obj->type;
if (!output->types.at(create.create.type).type &&
!obj->bindingBitmask.isEmpty()) {
- while (obj->bindingBitmask.size() % 4)
- obj->bindingBitmask.append(char(0));
+ Q_ASSERT(obj->bindingBitmask.size() % 4 == 0);
create.create.bindingBits =
output->indexForByteArray(obj->bindingBitmask);
} else {
@@ -1044,20 +1043,23 @@ bool QmlCompiler::buildComponent(QmlParser::Object *obj,
// Find, check and set the "id" property (if any)
Property *idProp = 0;
if (obj->properties.count() > 1 ||
- (obj->properties.count() == 1 && obj->properties.begin().key() != "id") ||
- !obj->scriptBlockObjects.isEmpty())
- COMPILE_EXCEPTION(obj, qApp->translate("QmlCompiler","Invalid component specification"));
+ (obj->properties.count() == 1 && obj->properties.begin().key() != "id"))
+ COMPILE_EXCEPTION(*obj->properties.begin(), qApp->translate("QmlCompiler","Invalid component specification"));
+
+ if (!obj->scriptBlockObjects.isEmpty())
+ COMPILE_EXCEPTION(obj->scriptBlockObjects.first(), qApp->translate("QmlCompiler","Invalid component specification"));
if (obj->properties.count())
idProp = *obj->properties.begin();
+
if (idProp && (idProp->value || idProp->values.count() > 1 || !isValidId(idProp->values.first()->primitive())))
- COMPILE_EXCEPTION(obj, qApp->translate("QmlCompiler","Invalid component id specification"));
+ COMPILE_EXCEPTION(idProp, qApp->translate("QmlCompiler","Invalid component id specification"));
if (idProp) {
QString idVal = idProp->values.first()->primitive();
if (compileState.ids.contains(idVal))
- COMPILE_EXCEPTION(obj, qApp->translate("QmlCompiler","id is not unique"));
+ COMPILE_EXCEPTION(idProp, qApp->translate("QmlCompiler","id is not unique"));
obj->id = idVal;
addId(idVal, obj);
@@ -1093,7 +1095,7 @@ bool QmlCompiler::buildScript(QmlParser::Object *obj, QmlParser::Object *script)
Property *source = *script->properties.begin();
if (script->defaultProperty)
- COMPILE_EXCEPTION(source, qApp->translate("QmlCompiler","Invalid Script block. Specify either the source property or inline script."));
+ COMPILE_EXCEPTION(source, qApp->translate("QmlCompiler","Invalid Script block. Specify either the source property or inline script"));
if (source->value || source->values.count() != 1 ||
source->values.at(0)->object || !source->values.at(0)->value.isString())
@@ -1180,12 +1182,10 @@ bool QmlCompiler::buildComponentFromRoot(QmlParser::Object *obj,
bool QmlCompiler::buildSubObject(Object *obj, const BindingContext &ctxt)
{
Q_ASSERT(obj->metatype);
+ Q_ASSERT(!obj->defaultProperty);
Q_ASSERT(ctxt.isSubContext()); // sub-objects must always be in a binding
// sub-context
- if (obj->defaultProperty)
- COMPILE_CHECK(buildProperty(obj->defaultProperty, obj, ctxt));
-
foreach(Property *prop, obj->properties) {
if (isSignalPropertyName(prop->name)) {
COMPILE_CHECK(buildSignal(prop, obj, ctxt));
@@ -1230,9 +1230,7 @@ bool QmlCompiler::buildSignal(QmlParser::Property *prop, QmlParser::Object *obj,
const BindingContext &ctxt)
{
Q_ASSERT(obj->metaObject());
-
- if (prop->isEmpty())
- COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Empty property assignment"));
+ Q_ASSERT(!prop->isEmpty());
QByteArray name = prop->name;
Q_ASSERT(name.startsWith("on"));
@@ -1261,6 +1259,10 @@ bool QmlCompiler::buildSignal(QmlParser::Property *prop, QmlParser::Object *obj,
prop->values.at(0)->type = Value::SignalObject;
} else {
prop->values.at(0)->type = Value::SignalExpression;
+
+ QString script = prop->values.at(0)->value.asScript().trimmed();
+ if (script.isEmpty())
+ COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Empty signal assignment"));
}
}
@@ -1701,6 +1703,9 @@ bool QmlCompiler::buildGroupedProperty(QmlParser::Property *prop,
Q_ASSERT(prop->type != 0);
Q_ASSERT(prop->index != -1);
+ if (prop->values.count())
+ COMPILE_EXCEPTION(prop->values.first(), qApp->translate("QmlCompiler", "Invalid value in grouped property"));
+
if (prop->type < (int)QVariant::UserType) {
QmlEnginePrivate *ep =
static_cast<QmlEnginePrivate *>(QObjectPrivate::get(engine));
diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp
index f340612..4ad9aac 100644
--- a/src/declarative/qml/qmlmetaproperty.cpp
+++ b/src/declarative/qml/qmlmetaproperty.cpp
@@ -111,27 +111,12 @@ void QmlMetaPropertyPrivate::initDefault(QObject *obj)
if (!obj)
return;
- object = obj;
QMetaProperty p = QmlMetaType::defaultProperty(obj);
core.load(p);
- if (core.isValid())
+ if (core.isValid()) {
isDefaultProperty = true;
-}
-
-/*!
- \internal
-
- Creates a QmlMetaProperty for the property at index \a idx of \a obj.
- */
-QmlMetaProperty::QmlMetaProperty(QObject *obj, int idx, QmlContext *ctxt)
-: d(new QmlMetaPropertyPrivate)
-{
- Q_ASSERT(obj);
-
- d->q = this;
- d->context = ctxt;
- d->object = obj;
- d->core.load(obj->metaObject()->property(idx));
+ object = obj;
+ }
}
/*!
@@ -142,6 +127,7 @@ QmlMetaProperty::QmlMetaProperty(QObject *obj, const QString &name)
{
d->q = this;
d->initProperty(obj, name);
+ if (!isValid()) d->object = 0;
}
/*!
@@ -154,6 +140,7 @@ QmlMetaProperty::QmlMetaProperty(QObject *obj, const QString &name, QmlContext *
d->q = this;
d->context = ctxt;
d->initProperty(obj, name);
+ if (!isValid()) { d->object = 0; d->context = 0; }
}
void QmlMetaPropertyPrivate::initProperty(QObject *obj, const QString &name)
@@ -425,12 +412,14 @@ bool QmlMetaProperty::isWritable() const
{
QmlMetaProperty::PropertyCategory category = propertyCategory();
+ if (!d->object)
+ return false;
if (category == List || category == QmlList)
return true;
else if (type() & SignalProperty)
- return true;
+ return false;
else if (d->core.isValid() && d->object)
- return d->object->metaObject()->property(d->core.coreIndex).isWritable();
+ return d->core.flags & QmlPropertyCache::Data::IsWritable;
else
return false;
}
@@ -456,25 +445,6 @@ bool QmlMetaProperty::isValid() const
}
/*!
- Returns all of \a obj's Qt properties.
-*/
-QStringList QmlMetaProperty::properties(QObject *obj)
-{
- // ### What is this used for?
- if (!obj)
- return QStringList();
-
- QStringList rv;
- const QMetaObject *mo = obj->metaObject();
- for (int ii = 0; ii < mo->propertyCount(); ++ii) {
- QMetaProperty prop = mo->property(ii);
- rv << QString::fromUtf8(prop.name());
- }
-
- return rv;
-}
-
-/*!
Return the name of this QML property.
*/
QString QmlMetaProperty::name() const
@@ -494,7 +464,13 @@ QString QmlMetaProperty::name() const
return rv;
} else {
- return d->core.name;
+ if (type() & SignalProperty) {
+ QString name = QLatin1String("on") + d->core.name;
+ name[2] = name.at(2).toUpper();
+ return name;
+ } else {
+ return d->core.name;
+ }
}
}
@@ -565,8 +541,10 @@ QmlAbstractBinding *QmlMetaProperty::binding() const
QmlAbstractBinding *
QmlMetaProperty::setBinding(QmlAbstractBinding *newBinding, QmlMetaProperty::WriteFlags flags) const
{
- if (!isProperty() || (type() & Attached) || !d->object)
+ if (!isProperty() || (type() & Attached) || !d->object) {
+ delete newBinding;
return 0;
+ }
return d->setBinding(d->object, d->core, newBinding, flags);
}
@@ -630,8 +608,10 @@ QmlExpression *QmlMetaProperty::signalExpression() const
*/
QmlExpression *QmlMetaProperty::setSignalExpression(QmlExpression *expr) const
{
- if (!(type() & SignalProperty))
+ if (!(type() & SignalProperty)) {
+ delete expr;
return 0;
+ }
const QObjectList &children = d->object->children();
@@ -686,13 +666,7 @@ QVariant QmlMetaProperty::read() const
if (type() & SignalProperty) {
- const QObjectList &children = object()->children();
-
- for (int ii = 0; ii < children.count(); ++ii) {
- QmlBoundSignal *sig = QmlBoundSignal::cast(children.at(ii));
- if (sig && sig->index() == d->core.coreIndex)
- return sig->expression()->expression();
- }
+ return QVariant();
} else if (type() & Property) {
@@ -857,7 +831,7 @@ bool QmlMetaPropertyPrivate::write(QObject *object, const QmlPropertyCache::Data
return false;
if (context && u.isRelative() && !u.isEmpty())
- u = context->baseUrl().resolved(u);
+ u = context->resolvedUrl(u);
int status = -1;
void *argv[] = { &u, 0, &status, &flags };
QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, argv);
@@ -990,7 +964,7 @@ bool QmlMetaProperty::write(const QVariant &value) const
bool QmlMetaProperty::write(const QVariant &value, QmlMetaProperty::WriteFlags flags) const
{
- if (d->object && type() & Property && d->core.isValid())
+ if (d->object && type() & Property && d->core.isValid() && isWritable())
return d->writeValueProperty(value, flags);
else
return false;
@@ -1083,27 +1057,6 @@ Q_GLOBAL_STATIC(QmlValueTypeFactory, qmlValueTypes);
Returns the property information serialized into a single integer.
QmlMetaProperty uses the bottom 24 bits only.
*/
-quint32 QmlMetaProperty::save() const
-{
- quint32 rv = 0;
- if (type() & Attached) {
- rv = d->attachedFunc;
- } else if (type() != Invalid) {
- rv = d->core.coreIndex;
- }
-
- Q_ASSERT(rv <= 0x7FF);
- Q_ASSERT(type() <= 0x3F);
- Q_ASSERT(d->valueTypeCoreIdx <= 0x7F);
-
- rv |= (type() << 18);
-
- if (type() & ValueTypeProperty)
- rv |= (d->valueTypeCoreIdx << 11);
-
- return rv;
-}
-
quint32 QmlMetaPropertyPrivate::saveValueType(int core, int valueType)
{
Q_ASSERT(core <= 0x7FF);
@@ -1130,8 +1083,11 @@ quint32 QmlMetaPropertyPrivate::saveProperty(int core)
to QmlMetaProperty::save(). Only the bottom 24-bits are
used, the high bits can be set to any value.
*/
-void QmlMetaProperty::restore(quint32 id, QObject *obj, QmlContext *ctxt)
+void QmlMetaPropertyPrivate::restore(QmlMetaProperty &prop, quint32 id,
+ QObject *obj, QmlContext *ctxt)
{
+ QmlMetaPropertyPrivate *d = prop.d;
+
QmlEnginePrivate *enginePrivate = 0;
if (ctxt && ctxt->engine())
enginePrivate = QmlEnginePrivate::get(ctxt->engine());
@@ -1143,9 +1099,9 @@ void QmlMetaProperty::restore(quint32 id, QObject *obj, QmlContext *ctxt)
uint type = id >> 18;
id &= 0xFFFF;
- if (type & Attached) {
+ if (type & QmlMetaProperty::Attached) {
d->attachedFunc = id;
- } else if (type & ValueTypeProperty) {
+ } else if (type & QmlMetaProperty::ValueTypeProperty) {
int coreIdx = id & 0x7FF;
int valueTypeIdx = id >> 11;
@@ -1159,7 +1115,7 @@ void QmlMetaProperty::restore(quint32 id, QObject *obj, QmlContext *ctxt)
d->core.load(p);
d->valueTypeCoreIdx = valueTypeIdx;
d->valueTypePropType = p2.userType();
- } else if (type & Property) {
+ } else if (type & QmlMetaProperty::Property) {
QmlPropertyCache *cache = enginePrivate?enginePrivate->cache(obj):0;
@@ -1171,12 +1127,12 @@ void QmlMetaProperty::restore(quint32 id, QObject *obj, QmlContext *ctxt)
d->core.load(p);
}
- } else if (type & SignalProperty) {
+ } else if (type & QmlMetaProperty::SignalProperty) {
QMetaMethod method = obj->metaObject()->method(id);
d->core.load(method);
} else {
- *this = QmlMetaProperty();
+ prop = QmlMetaProperty();
}
}
diff --git a/src/declarative/qml/qmlmetaproperty.h b/src/declarative/qml/qmlmetaproperty.h
index ce4ac1e..6db99c6 100644
--- a/src/declarative/qml/qmlmetaproperty.h
+++ b/src/declarative/qml/qmlmetaproperty.h
@@ -79,10 +79,8 @@ public:
QmlMetaProperty(QObject *, const QString &, QmlContext *);
QmlMetaProperty(const QmlMetaProperty &);
QmlMetaProperty &operator=(const QmlMetaProperty &);
- QmlMetaProperty(QObject *, int, QmlContext * = 0);
~QmlMetaProperty();
- static QStringList properties(QObject *);
QString name() const;
QVariant read() const;
@@ -96,9 +94,6 @@ public:
bool connectNotifier(QObject *dest, const char *slot) const;
bool connectNotifier(QObject *dest, int method) const;
- quint32 save() const;
- void restore(quint32, QObject *, QmlContext * = 0);
-
QMetaMethod method() const;
enum Type { Invalid = 0x00,
@@ -138,6 +133,7 @@ public:
int valueTypeCoreIndex() const;
private:
friend class QmlEnginePrivate;
+ friend class QmlMetaPropertyPrivate;;
QmlMetaPropertyPrivate *d;
};
typedef QList<QmlMetaProperty> QmlMetaProperties;
diff --git a/src/declarative/qml/qmlmetaproperty_p.h b/src/declarative/qml/qmlmetaproperty_p.h
index 925f1ea..d225afa 100644
--- a/src/declarative/qml/qmlmetaproperty_p.h
+++ b/src/declarative/qml/qmlmetaproperty_p.h
@@ -104,8 +104,9 @@ public:
static QmlAbstractBinding *setBinding(QObject *, const QmlPropertyCache::Data &, QmlAbstractBinding *,
QmlMetaProperty::WriteFlags flags = QmlMetaProperty::DontRemoveBinding);
- static quint32 saveValueType(int, int);
- static quint32 saveProperty(int);
+ static void Q_AUTOTEST_EXPORT restore(QmlMetaProperty &prop, quint32, QObject *, QmlContext * = 0);
+ static quint32 Q_AUTOTEST_EXPORT saveValueType(int, int);
+ static quint32 Q_AUTOTEST_EXPORT saveProperty(int);
static bool equal(const QMetaObject *, const QMetaObject *);
static bool canConvert(const QMetaObject *from, const QMetaObject *to);
diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp
index 62ec025..f3d0f65 100644
--- a/src/declarative/qml/qmlvme.cpp
+++ b/src/declarative/qml/qmlvme.cpp
@@ -591,7 +591,7 @@ QObject *QmlVME::run(QStack<QObject *> &stack, QmlContext *ctxt,
stack.at(stack.count() - 1 - instr.assignBinding.context);
QmlMetaProperty mp;
- mp.restore(instr.assignBinding.property, target, ctxt);
+ QmlMetaPropertyPrivate::restore(mp, instr.assignBinding.property, target, ctxt);
int coreIndex = mp.coreIndex();
@@ -648,7 +648,7 @@ QObject *QmlVME::run(QStack<QObject *> &stack, QmlContext *ctxt,
QmlPropertyValueSource *vs = reinterpret_cast<QmlPropertyValueSource *>(reinterpret_cast<char *>(obj) + instr.assignValueSource.castValue);
QObject *target = stack.at(stack.count() - 1 - instr.assignValueSource.owner);
QmlMetaProperty prop;
- prop.restore(instr.assignValueSource.property, target, ctxt);
+ QmlMetaPropertyPrivate::restore(prop, instr.assignValueSource.property, target, ctxt);
obj->setParent(target);
vs->setTarget(prop);
}
@@ -660,7 +660,7 @@ QObject *QmlVME::run(QStack<QObject *> &stack, QmlContext *ctxt,
QmlPropertyValueInterceptor *vi = reinterpret_cast<QmlPropertyValueInterceptor *>(reinterpret_cast<char *>(obj) + instr.assignValueInterceptor.castValue);
QObject *target = stack.at(stack.count() - 1 - instr.assignValueInterceptor.owner);
QmlMetaProperty prop;
- prop.restore(instr.assignValueInterceptor.property, target, ctxt);
+ QmlMetaPropertyPrivate::restore(prop, instr.assignValueInterceptor.property, target, ctxt);
obj->setParent(target);
vi->setTarget(prop);
QmlVMEMetaObject *mo = static_cast<QmlVMEMetaObject *>((QMetaObject*)target->metaObject());