Navigation Menu

Skip to content

Commit

Permalink
Correctly load flags for binding properties
Browse files Browse the repository at this point in the history
Change-Id: I80e79ff7de8d879f700f9f4fe96d796de0f17aff
Reviewed-on: http://codereview.qt.nokia.com/2055
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
  • Loading branch information
Aaron Kennedy authored and Qt by Nokia committed Jul 25, 2011
1 parent e826e57 commit 9cb3889
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 13 deletions.
14 changes: 8 additions & 6 deletions src/declarative/qml/qdeclarativecompiler.cpp
Expand Up @@ -2910,18 +2910,20 @@ int QDeclarativeCompiler::genContextCache()
int QDeclarativeCompiler::genValueTypeData(QDeclarativeParser::Property *valueTypeProp,
QDeclarativeParser::Property *prop)
{
QByteArray data =
QDeclarativePropertyPrivate::saveValueType(prop->parent->metaObject(), prop->index,
enginePrivate->valueTypes[prop->type]->metaObject(),
valueTypeProp->index);
// valueTypeProp->index, valueTypeProp->type);
typedef QDeclarativePropertyPrivate QDPP;
QByteArray data = QDPP::saveValueType(prop->parent->metaObject(), prop->index,
enginePrivate->valueTypes[prop->type]->metaObject(),
valueTypeProp->index, engine);

return output->indexForByteArray(data);
}

int QDeclarativeCompiler::genPropertyData(QDeclarativeParser::Property *prop)
{
return output->indexForByteArray(QDeclarativePropertyPrivate::saveProperty(prop->parent->metaObject(), prop->index));
typedef QDeclarativePropertyPrivate QDPP;
QByteArray data = QDPP::saveProperty(prop->parent->metaObject(), prop->index, engine);

return output->indexForByteArray(data);
}

bool QDeclarativeCompiler::completeComponentBuild()
Expand Down
12 changes: 7 additions & 5 deletions src/declarative/qml/qdeclarativeproperty.cpp
Expand Up @@ -1095,8 +1095,8 @@ bool QDeclarativePropertyPrivate::writeValueProperty(const QVariant &value, Writ
}

bool QDeclarativePropertyPrivate::write(QObject *object, const QDeclarativePropertyCache::Data &property,
const QVariant &value, QDeclarativeContextData *context,
WriteFlags flags)
const QVariant &value, QDeclarativeContextData *context,
WriteFlags flags)
{
int coreIdx = property.coreIndex;
int status = -1; //for dbus
Expand Down Expand Up @@ -1549,7 +1549,8 @@ struct ValueTypeSerializedData : public SerializedData {
};

QByteArray QDeclarativePropertyPrivate::saveValueType(const QMetaObject *metaObject, int index,
const QMetaObject *subObject, int subIndex)
const QMetaObject *subObject, int subIndex,
QDeclarativeEngine *)
{
QMetaProperty prop = metaObject->property(index);
QMetaProperty subProp = subObject->property(subIndex);
Expand All @@ -1567,12 +1568,13 @@ QByteArray QDeclarativePropertyPrivate::saveValueType(const QMetaObject *metaObj
return rv;
}

QByteArray QDeclarativePropertyPrivate::saveProperty(const QMetaObject *metaObject, int index)
QByteArray QDeclarativePropertyPrivate::saveProperty(const QMetaObject *metaObject, int index,
QDeclarativeEngine *engine)
{
SerializedData sd;
memset(&sd, 0, sizeof(sd));
sd.isValueType = false;
sd.core.load(metaObject->property(index));
sd.core.load(metaObject->property(index), engine);

QByteArray rv((const char *)&sd, sizeof(sd));
return rv;
Expand Down
6 changes: 4 additions & 2 deletions src/declarative/qml/qdeclarativeproperty_p.h
Expand Up @@ -111,8 +111,10 @@ class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativePropertyPrivate : public QDeclara
static QDeclarativeAbstractBinding *binding(QObject *, int coreIndex, int valueTypeIndex /* -1 */);

static QByteArray saveValueType(const QMetaObject *, int,
const QMetaObject *, int);
static QByteArray saveProperty(const QMetaObject *, int);
const QMetaObject *, int,
QDeclarativeEngine *);
static QByteArray saveProperty(const QMetaObject *, int,
QDeclarativeEngine *);

static QDeclarativeProperty restore(const QByteArray &, QObject *, QDeclarativeContextData *);
static QDeclarativeProperty restore(const QDeclarativePropertyCache::Data &,
Expand Down
@@ -0,0 +1,5 @@
import QtQuick 1.0

QtObject {
property int value
}
@@ -0,0 +1,10 @@
import QtQuick 1.0

QtObject {
id: root

property bool test: bound.value == 1923

property ElementAssignType element: ElementAssignType { value: 1923 }
property ElementAssignType bound: root.element
}
Expand Up @@ -148,6 +148,7 @@ private slots:
void importScripts();
void scarceResources();
void propertyChangeSlots();
void elementAssign();

void bug1();
void bug2();
Expand Down Expand Up @@ -189,6 +190,7 @@ private slots:

void revisionErrors();
void revision();

private:
QDeclarativeEngine engine;
};
Expand Down Expand Up @@ -2909,6 +2911,19 @@ void tst_qdeclarativeecmascript::propertyChangeSlots()
delete object;
}

// Ensure that QObject type conversion works on binding assignment
void tst_qdeclarativeecmascript::elementAssign()
{
QDeclarativeComponent component(&engine, TEST_FILE("elementAssign.qml"));

QObject *object = component.create();
QVERIFY(object != 0);

QCOMPARE(object->property("test").toBool(), true);

delete object;
}

// Test that assigning a null object works
// Regressed with: df1788b4dbbb2826ae63f26bdf166342595343f4
void tst_qdeclarativeecmascript::nullObjectBinding()
Expand Down

0 comments on commit 9cb3889

Please sign in to comment.