summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/qml')
-rw-r--r--src/declarative/qml/qdeclarativecomponent.cpp26
-rw-r--r--src/declarative/qml/qdeclarativescriptparser.cpp7
-rw-r--r--src/declarative/qml/qdeclarativetypenamescriptclass.cpp2
-rw-r--r--src/declarative/qml/qdeclarativevme.cpp63
-rw-r--r--src/declarative/qml/qdeclarativeworkerscript.cpp2
5 files changed, 88 insertions, 12 deletions
diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp
index b3aaec7..c284307 100644
--- a/src/declarative/qml/qdeclarativecomponent.cpp
+++ b/src/declarative/qml/qdeclarativecomponent.cpp
@@ -615,10 +615,11 @@ QDeclarativeComponent::QDeclarativeComponent(QDeclarativeComponentPrivate &dd, Q
}
/*!
- \qmlmethod object Component::createObject(Item parent, Script valuemap = null)
+ \qmlmethod object Component::createObject(Item parent, object properties)
- Creates and returns an object instance of this component that will have the given
- \a parent. Returns null if object creation fails.
+ Creates and returns an object instance of this component that will have
+ the given \a parent and \a properties. The \a properties argument is optional.
+ Returns null if object creation fails.
The object will be created in the same context as the one in which the component
was created. This function will always return null when called on components
@@ -630,14 +631,23 @@ QDeclarativeComponent::QDeclarativeComponent(QDeclarativeComponentPrivate &dd, Q
property, or else the object will not be visible.
If a \a parent is not provided to createObject(), a reference to the returned object must be held so that
- it is not destroyed by the garbage collector. This is regardless of Item.parent being set afterwards,
+ it is not destroyed by the garbage collector. This is true regardless of whether \l{Item::parent} is set afterwards,
since setting the Item parent does not change object ownership; only the graphical parent is changed.
- Since QtQuick 1.1, a map of property values can be optionally passed to the method that applies values to the object's properties
- before its creation is finalised. This will avoid binding issues that can occur when the object is
- instantiated before property bindings have been set. For example:
+ As of QtQuick 1.1, this method accepts an optional \a properties argument that specifies a
+ map of initial property values for the created object. These values are applied before object
+ creation is finalized. (This is more efficient than setting property values after object creation,
+ particularly where large sets of property values are defined, and also allows property bindings
+ to be set up before the object is created.)
- \code component.createObject(parent, {"x": 100, "y": 100, "specialProperty": someObject}); \endcode
+ The \a properties argument is specified as a map of property-value items. For example, the code
+ below creates an object with initial \c x and \c y values of 100 and 200, respectively:
+
+ \qml
+ var component = Qt.createComponent("Button.qml");
+ if (component.status == Component.Ready)
+ component.createObject(parent, {"x": 100, "y": 100});
+ \endqml
Dynamically created instances can be deleted with the \c destroy() method.
See \l {Dynamic Object Management in QML} for more information.
diff --git a/src/declarative/qml/qdeclarativescriptparser.cpp b/src/declarative/qml/qdeclarativescriptparser.cpp
index 996920a..d9e3ebf 100644
--- a/src/declarative/qml/qdeclarativescriptparser.cpp
+++ b/src/declarative/qml/qdeclarativescriptparser.cpp
@@ -776,7 +776,10 @@ bool ProcessAST::visit(AST::UiSourceElement *node)
f = f->finish();
}
- QString body = textAt(funDecl->lbraceToken, funDecl->rbraceToken);
+ AST::SourceLocation loc = funDecl->rparenToken;
+ loc.offset = loc.end();
+ loc.startColumn += 1;
+ QString body = textAt(loc, funDecl->rbraceToken);
slot.name = funDecl->name->asString().toUtf8();
slot.body = body;
obj->dynamicSlots << slot;
@@ -937,7 +940,7 @@ QDeclarativeParser::Object::ScriptBlock::Pragmas QDeclarativeScriptParser::extra
if (l.currentLineNo() == startLine)
return rv;
- if (pragmaValue == QLatin1String("library")) {
+ if (pragmaValue == library) {
rv |= QDeclarativeParser::Object::ScriptBlock::Shared;
replaceWithSpace(script, startOffset, endOffset - startOffset);
} else {
diff --git a/src/declarative/qml/qdeclarativetypenamescriptclass.cpp b/src/declarative/qml/qdeclarativetypenamescriptclass.cpp
index d3e2025..0314a7a 100644
--- a/src/declarative/qml/qdeclarativetypenamescriptclass.cpp
+++ b/src/declarative/qml/qdeclarativetypenamescriptclass.cpp
@@ -158,7 +158,7 @@ void QDeclarativeTypeNameScriptClass::setProperty(Object *o, const Identifier &n
Q_ASSERT(!type);
QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
- ep->objectClass->setProperty(((TypeNameData *)o)->object, n, v, context());
+ ep->objectClass->setProperty(object, n, v, context());
}
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativevme.cpp b/src/declarative/qml/qdeclarativevme.cpp
index 2d551f2..781e1b8 100644
--- a/src/declarative/qml/qdeclarativevme.cpp
+++ b/src/declarative/qml/qdeclarativevme.cpp
@@ -127,6 +127,22 @@ void QDeclarativeVME::runDeferred(QObject *object)
run(stack, ctxt, comp, start, count, QBitField());
}
+inline bool fastHasBinding(QObject *o, int index)
+{
+ QDeclarativeData *ddata = static_cast<QDeclarativeData *>(QObjectPrivate::get(o)->declarativeData);
+
+ return ddata && (ddata->bindingBitsSize > index) &&
+ (ddata->bindingBits[index / 32] & (1 << (index % 32)));
+}
+
+static void removeBindingOnProperty(QObject *o, int index)
+{
+ QDeclarativeAbstractBinding *binding = QDeclarativePropertyPrivate::setBinding(o, index, -1, 0);
+ if (binding) binding->destroy();
+}
+
+#define CLEAN_PROPERTY(o, index) if (fastHasBinding(o, index)) removeBindingOnProperty(o, index)
+
QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
QDeclarativeContextData *ctxt,
QDeclarativeCompiledData *comp,
@@ -336,6 +352,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
case QDeclarativeInstruction::StoreVariant:
{
QObject *target = stack.top();
+ CLEAN_PROPERTY(target, instr.storeString.propertyIndex);
+
// XXX - can be more efficient
QVariant v = QDeclarativeStringConverters::variantFromString(primitives.at(instr.storeString.value));
void *a[] = { &v, 0, &status, &flags };
@@ -347,6 +365,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
case QDeclarativeInstruction::StoreVariantInteger:
{
QObject *target = stack.top();
+ CLEAN_PROPERTY(target, instr.storeString.propertyIndex);
+
QVariant v(instr.storeInteger.value);
void *a[] = { &v, 0, &status, &flags };
QMetaObject::metacall(target, QMetaObject::WriteProperty,
@@ -357,6 +377,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
case QDeclarativeInstruction::StoreVariantDouble:
{
QObject *target = stack.top();
+ CLEAN_PROPERTY(target, instr.storeString.propertyIndex);
+
QVariant v(instr.storeDouble.value);
void *a[] = { &v, 0, &status, &flags };
QMetaObject::metacall(target, QMetaObject::WriteProperty,
@@ -367,6 +389,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
case QDeclarativeInstruction::StoreVariantBool:
{
QObject *target = stack.top();
+ CLEAN_PROPERTY(target, instr.storeString.propertyIndex);
+
QVariant v(instr.storeBool.value);
void *a[] = { &v, 0, &status, &flags };
QMetaObject::metacall(target, QMetaObject::WriteProperty,
@@ -377,6 +401,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
case QDeclarativeInstruction::StoreString:
{
QObject *target = stack.top();
+ CLEAN_PROPERTY(target, instr.storeString.propertyIndex);
+
void *a[] = { (void *)&primitives.at(instr.storeString.value), 0, &status, &flags };
QMetaObject::metacall(target, QMetaObject::WriteProperty,
instr.storeString.propertyIndex, a);
@@ -386,6 +412,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
case QDeclarativeInstruction::StoreUrl:
{
QObject *target = stack.top();
+ CLEAN_PROPERTY(target, instr.storeUrl.propertyIndex);
+
void *a[] = { (void *)&urls.at(instr.storeUrl.value), 0, &status, &flags };
QMetaObject::metacall(target, QMetaObject::WriteProperty,
instr.storeUrl.propertyIndex, a);
@@ -395,6 +423,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
case QDeclarativeInstruction::StoreFloat:
{
QObject *target = stack.top();
+ CLEAN_PROPERTY(target, instr.storeFloat.propertyIndex);
+
float f = instr.storeFloat.value;
void *a[] = { &f, 0, &status, &flags };
QMetaObject::metacall(target, QMetaObject::WriteProperty,
@@ -405,6 +435,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
case QDeclarativeInstruction::StoreDouble:
{
QObject *target = stack.top();
+ CLEAN_PROPERTY(target, instr.storeDouble.propertyIndex);
+
double d = instr.storeDouble.value;
void *a[] = { &d, 0, &status, &flags };
QMetaObject::metacall(target, QMetaObject::WriteProperty,
@@ -415,6 +447,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
case QDeclarativeInstruction::StoreBool:
{
QObject *target = stack.top();
+ CLEAN_PROPERTY(target, instr.storeBool.propertyIndex);
+
void *a[] = { (void *)&instr.storeBool.value, 0, &status, &flags };
QMetaObject::metacall(target, QMetaObject::WriteProperty,
instr.storeBool.propertyIndex, a);
@@ -424,6 +458,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
case QDeclarativeInstruction::StoreInteger:
{
QObject *target = stack.top();
+ CLEAN_PROPERTY(target, instr.storeInteger.propertyIndex);
+
void *a[] = { (void *)&instr.storeInteger.value, 0, &status, &flags };
QMetaObject::metacall(target, QMetaObject::WriteProperty,
instr.storeInteger.propertyIndex, a);
@@ -433,6 +469,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
case QDeclarativeInstruction::StoreColor:
{
QObject *target = stack.top();
+ CLEAN_PROPERTY(target, instr.storeColor.propertyIndex);
+
QColor c = QColor::fromRgba(instr.storeColor.value);
void *a[] = { &c, 0, &status, &flags };
QMetaObject::metacall(target, QMetaObject::WriteProperty,
@@ -443,6 +481,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
case QDeclarativeInstruction::StoreDate:
{
QObject *target = stack.top();
+ CLEAN_PROPERTY(target, instr.storeDate.propertyIndex);
+
QDate d = QDate::fromJulianDay(instr.storeDate.value);
void *a[] = { &d, 0, &status, &flags };
QMetaObject::metacall(target, QMetaObject::WriteProperty,
@@ -453,6 +493,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
case QDeclarativeInstruction::StoreTime:
{
QObject *target = stack.top();
+ CLEAN_PROPERTY(target, instr.storeTime.propertyIndex);
+
QTime t;
t.setHMS(intData.at(instr.storeTime.valueIndex),
intData.at(instr.storeTime.valueIndex+1),
@@ -467,6 +509,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
case QDeclarativeInstruction::StoreDateTime:
{
QObject *target = stack.top();
+ CLEAN_PROPERTY(target, instr.storeDateTime.propertyIndex);
+
QTime t;
t.setHMS(intData.at(instr.storeDateTime.valueIndex+1),
intData.at(instr.storeDateTime.valueIndex+2),
@@ -482,6 +526,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
case QDeclarativeInstruction::StorePoint:
{
QObject *target = stack.top();
+ CLEAN_PROPERTY(target, instr.storeRealPair.propertyIndex);
+
QPoint p = QPointF(floatData.at(instr.storeRealPair.valueIndex),
floatData.at(instr.storeRealPair.valueIndex+1)).toPoint();
void *a[] = { &p, 0, &status, &flags };
@@ -493,6 +539,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
case QDeclarativeInstruction::StorePointF:
{
QObject *target = stack.top();
+ CLEAN_PROPERTY(target, instr.storeRealPair.propertyIndex);
+
QPointF p(floatData.at(instr.storeRealPair.valueIndex),
floatData.at(instr.storeRealPair.valueIndex+1));
void *a[] = { &p, 0, &status, &flags };
@@ -504,6 +552,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
case QDeclarativeInstruction::StoreSize:
{
QObject *target = stack.top();
+ CLEAN_PROPERTY(target, instr.storeRealPair.propertyIndex);
+
QSize p = QSizeF(floatData.at(instr.storeRealPair.valueIndex),
floatData.at(instr.storeRealPair.valueIndex+1)).toSize();
void *a[] = { &p, 0, &status, &flags };
@@ -515,6 +565,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
case QDeclarativeInstruction::StoreSizeF:
{
QObject *target = stack.top();
+ CLEAN_PROPERTY(target, instr.storeRealPair.propertyIndex);
+
QSizeF s(floatData.at(instr.storeRealPair.valueIndex),
floatData.at(instr.storeRealPair.valueIndex+1));
void *a[] = { &s, 0, &status, &flags };
@@ -526,6 +578,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
case QDeclarativeInstruction::StoreRect:
{
QObject *target = stack.top();
+ CLEAN_PROPERTY(target, instr.storeRect.propertyIndex);
+
QRect r = QRectF(floatData.at(instr.storeRect.valueIndex),
floatData.at(instr.storeRect.valueIndex+1),
floatData.at(instr.storeRect.valueIndex+2),
@@ -539,6 +593,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
case QDeclarativeInstruction::StoreRectF:
{
QObject *target = stack.top();
+ CLEAN_PROPERTY(target, instr.storeRect.propertyIndex);
+
QRectF r(floatData.at(instr.storeRect.valueIndex),
floatData.at(instr.storeRect.valueIndex+1),
floatData.at(instr.storeRect.valueIndex+2),
@@ -552,6 +608,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
case QDeclarativeInstruction::StoreVector3D:
{
QObject *target = stack.top();
+ CLEAN_PROPERTY(target, instr.storeVector3D.propertyIndex);
+
QVector3D p(floatData.at(instr.storeVector3D.valueIndex),
floatData.at(instr.storeVector3D.valueIndex+1),
floatData.at(instr.storeVector3D.valueIndex+2));
@@ -565,6 +623,7 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
{
QObject *assignObj = stack.pop();
QObject *target = stack.top();
+ CLEAN_PROPERTY(target, instr.storeObject.propertyIndex);
void *a[] = { (void *)&assignObj, 0, &status, &flags };
QMetaObject::metacall(target, QMetaObject::WriteProperty,
@@ -576,6 +635,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
case QDeclarativeInstruction::AssignCustomType:
{
QObject *target = stack.top();
+ CLEAN_PROPERTY(target, instr.assignCustomType.propertyIndex);
+
QDeclarativeCompiledData::CustomTypeData data = customTypeData.at(instr.assignCustomType.valueIndex);
const QString &primitive = primitives.at(data.index);
QDeclarativeMetaType::StringConverter converter =
@@ -780,6 +841,7 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
{
QObject *assign = stack.pop();
QObject *target = stack.top();
+ CLEAN_PROPERTY(target, instr.storeObject.propertyIndex);
QVariant v = QVariant::fromValue(assign);
void *a[] = { &v, 0, &status, &flags };
@@ -792,6 +854,7 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
{
QObject *assign = stack.pop();
QObject *target = stack.top();
+ CLEAN_PROPERTY(target, instr.storeObject.propertyIndex);
int coreIdx = instr.storeObject.propertyIndex;
QMetaProperty prop = target->metaObject()->property(coreIdx);
diff --git a/src/declarative/qml/qdeclarativeworkerscript.cpp b/src/declarative/qml/qdeclarativeworkerscript.cpp
index f8d52b5..1ff0caa 100644
--- a/src/declarative/qml/qdeclarativeworkerscript.cpp
+++ b/src/declarative/qml/qdeclarativeworkerscript.cpp
@@ -313,7 +313,7 @@ void QDeclarativeWorkerScriptEnginePrivate::processLoad(int id, const QUrl &url)
QScriptContext *ctxt = QScriptDeclarativeClass::pushCleanContext(workerEngine);
QScriptValue urlContext = workerEngine->newObject();
- urlContext.setData(QScriptValue(workerEngine, fileName));
+ urlContext.setData(QScriptValue(workerEngine, url.toString()));
ctxt->pushScope(urlContext);
ctxt->pushScope(activation);
ctxt->setActivationObject(activation);