From d654f87319408e3d9754fa5a8ad376c3eaef4489 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 25 Feb 2010 10:38:43 +1000 Subject: Automatically connect to signals "onFooChanged" if property is "foo". This follows on from a2a8cea2835ef24104fe784b6ce0f508cc5637c0 to make it work for PropertyChanges and QDeclarativeMetaProperty as well. Task-number: QT-2783 --- src/declarative/qml/qdeclarativecompiler.cpp | 16 ++- src/declarative/qml/qdeclarativecompiler_p.h | 3 +- src/declarative/qml/qdeclarativemetaproperty.cpp | 20 +-- .../tst_qdeclarativemetaproperty.cpp | 149 +++++++++++++++++++++ .../qdeclarativestates/data/basicChanges4.qml | 19 +++ .../qdeclarativestates/tst_qdeclarativestates.cpp | 67 ++++++--- 6 files changed, 232 insertions(+), 42 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativestates/data/basicChanges4.qml diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index b6ebd60..0e54d45 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -1314,8 +1314,9 @@ int QDeclarativeCompiler::componentTypeRef() return output->types.count() - 1; } -int QDeclarativeCompiler::findSignalByName(const QMetaObject *mo, const QByteArray &name) +QMetaMethod QDeclarativeCompiler::findSignalByName(const QMetaObject *mo, const QByteArray &name) { + Q_ASSERT(mo); int methods = mo->methodCount(); for (int ii = methods - 1; ii >= 0; --ii) { QMetaMethod method = mo->method(ii); @@ -1324,7 +1325,7 @@ int QDeclarativeCompiler::findSignalByName(const QMetaObject *mo, const QByteArr methodName = methodName.left(idx); if (methodName == name) - return ii; + return method; } // If no signal is found, but the signal is of the form "onBlahChanged", @@ -1332,11 +1333,14 @@ int QDeclarativeCompiler::findSignalByName(const QMetaObject *mo, const QByteArr if (name.endsWith("Changed")) { QByteArray propName = name.mid(0, name.length() - 7); int propIdx = mo->indexOfProperty(propName.constData()); - if (propIdx >= 0) - return mo->property(propIdx).notifySignalIndex(); + if (propIdx >= 0) { + QMetaProperty prop = mo->property(propIdx); + if (prop.hasNotifySignal()) + return prop.notifySignal(); + } } - return -1; + return QMetaMethod(); } bool QDeclarativeCompiler::buildSignal(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj, @@ -1351,7 +1355,7 @@ bool QDeclarativeCompiler::buildSignal(QDeclarativeParser::Property *prop, QDecl if(name[0] >= 'A' && name[0] <= 'Z') name[0] = name[0] - 'A' + 'a'; - int sigIdx = findSignalByName(obj->metaObject(), name); + int sigIdx = findSignalByName(obj->metaObject(), name).methodIndex(); if (sigIdx == -1) { diff --git a/src/declarative/qml/qdeclarativecompiler_p.h b/src/declarative/qml/qdeclarativecompiler_p.h index 627490d..2ea3366 100644 --- a/src/declarative/qml/qdeclarativecompiler_p.h +++ b/src/declarative/qml/qdeclarativecompiler_p.h @@ -159,6 +159,8 @@ public: static bool isAttachedPropertyName(const QByteArray &); static bool isSignalPropertyName(const QByteArray &); + static QMetaMethod findSignalByName(const QMetaObject *, const QByteArray &name); + private: static void reset(QDeclarativeCompiledData *); @@ -263,7 +265,6 @@ private: int componentTypeRef(); - static int findSignalByName(const QMetaObject *, const QByteArray &name); static QDeclarativeType *toQmlType(QDeclarativeParser::Object *from); bool canCoerce(int to, QDeclarativeParser::Object *from); bool canCoerce(int to, int from); diff --git a/src/declarative/qml/qdeclarativemetaproperty.cpp b/src/declarative/qml/qdeclarativemetaproperty.cpp index e94ce8c..253174d 100644 --- a/src/declarative/qml/qdeclarativemetaproperty.cpp +++ b/src/declarative/qml/qdeclarativemetaproperty.cpp @@ -53,6 +53,7 @@ #include "qdeclarativedeclarativedata_p.h" #include "qdeclarativestringconverters_p.h" #include "qdeclarativelist_p.h" +#include "qdeclarativecompiler_p.h" #include #include @@ -177,7 +178,7 @@ void QDeclarativeMetaPropertyPrivate::initProperty(QObject *obj, const QString & QString signalName = name.mid(2); signalName[0] = signalName.at(0).toLower(); - QMetaMethod method = findSignal(obj, signalName); + QMetaMethod method = QDeclarativeCompiler::findSignalByName(obj->metaObject(), signalName.toLatin1().constData()); if (method.signature()) { core.load(method); return; @@ -631,23 +632,6 @@ QDeclarativeExpression *QDeclarativeMetaProperty::setSignalExpression(QDeclarati } } -QMetaMethod QDeclarativeMetaPropertyPrivate::findSignal(QObject *obj, const QString &name) -{ - const QMetaObject *mo = obj->metaObject(); - - int methods = mo->methodCount(); - for (int ii = methods - 1; ii >= 0; --ii) { - QMetaMethod method = mo->method(ii); - QString methodName = QString::fromUtf8(method.signature()); - int idx = methodName.indexOf(QLatin1Char('(')); - methodName = methodName.left(idx); - - if (methodName == name) - return method; - } - return QMetaMethod(); -} - QObject *QDeclarativeMetaPropertyPrivate::attachedObject() const { if (attachedFunc == -1) diff --git a/tests/auto/declarative/qdeclarativemetaproperty/tst_qdeclarativemetaproperty.cpp b/tests/auto/declarative/qdeclarativemetaproperty/tst_qdeclarativemetaproperty.cpp index e19bea0..028d8c4 100644 --- a/tests/auto/declarative/qdeclarativemetaproperty/tst_qdeclarativemetaproperty.cpp +++ b/tests/auto/declarative/qdeclarativemetaproperty/tst_qdeclarativemetaproperty.cpp @@ -180,6 +180,7 @@ class PropertyObject : public QObject Q_PROPERTY(QRect wrectProperty READ wrectProperty WRITE setWRectProperty); Q_PROPERTY(QUrl url READ url WRITE setUrl); Q_PROPERTY(int resettableProperty READ resettableProperty WRITE setResettableProperty RESET resetProperty); + Q_PROPERTY(int propertyWithNotify READ propertyWithNotify WRITE setPropertyWithNotify NOTIFY oddlyNamedNotifySignal) Q_CLASSINFO("DefaultProperty", "defaultProperty"); public: @@ -198,13 +199,18 @@ public: void setResettableProperty(int r) { m_resetProperty = r; } void resetProperty() { m_resetProperty = 9; } + int propertyWithNotify() const { return m_propertyWithNotify; } + void setPropertyWithNotify(int i) { m_propertyWithNotify = i; emit oddlyNamedNotifySignal(); } + signals: void clicked(); + void oddlyNamedNotifySignal(); private: int m_resetProperty; QRect m_rect; QUrl m_url; + int m_propertyWithNotify; }; QML_DECLARE_TYPE(PropertyObject); @@ -457,6 +463,54 @@ void tst_qdeclarativemetaproperty::qmlmetaproperty_object_string() delete obj; } + + { + QDeclarativeMetaProperty prop(&dobject, QString("onPropertyWithNotifyChanged")); + + QGuard binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext())); + binding->setTarget(prop); + QVERIFY(binding != 0); + QGuard expression(new QDeclarativeExpression()); + QVERIFY(expression != 0); + + QObject *obj = new QObject; + + QCOMPARE(prop.name(), QString("onOddlyNamedNotifySignal")); + QCOMPARE(prop.read(), QVariant()); + QCOMPARE(prop.write(QVariant("Hello")), false); + QCOMPARE(prop.hasChangedNotifier(), false); + QCOMPARE(prop.needsChangedNotifier(), false); + QCOMPARE(prop.connectNotifier(0, SLOT(deleteLater())), false); + QCOMPARE(prop.connectNotifier(obj, SLOT(deleteLater())), false); + QCOMPARE(prop.connectNotifier(obj, 0), false); + QCOMPARE(prop.connectNotifier(0, obj->metaObject()->indexOfMethod("deleteLater()")), false); + QCOMPARE(prop.connectNotifier(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false); + QCOMPARE(prop.connectNotifier(obj, -1), false); + QCOMPARE(QString(prop.method().signature()), QString("oddlyNamedNotifySignal()")); + QCOMPARE(prop.type(), QDeclarativeMetaProperty::SignalProperty); + QCOMPARE(prop.isProperty(), false); + QCOMPARE(prop.isDefault(), false); + QCOMPARE(prop.isWritable(), false); + QCOMPARE(prop.isDesignable(), false); + QCOMPARE(prop.isResettable(), false); + QCOMPARE(prop.isValid(), true); + QCOMPARE(prop.object(), &dobject); + QCOMPARE(prop.propertyCategory(), QDeclarativeMetaProperty::InvalidProperty); + QCOMPARE(prop.propertyType(), 0); + QCOMPARE(prop.propertyTypeName(), (const char *)0); + QCOMPARE(prop.property().name(), (const char *)0); + QVERIFY(prop.binding() == 0); + QVERIFY(prop.setBinding(binding) == 0); + QVERIFY(binding == 0); + QVERIFY(prop.signalExpression() == 0); + QVERIFY(prop.setSignalExpression(expression) == 0); + QVERIFY(expression != 0); + QVERIFY(prop.signalExpression() == expression); + QCOMPARE(prop.coreIndex(), dobject.metaObject()->indexOfMethod("oddlyNamedNotifySignal()")); + QCOMPARE(prop.valueTypeCoreIndex(), -1); + + delete obj; + } } void tst_qdeclarativemetaproperty::qmlmetaproperty_object_context() @@ -707,6 +761,54 @@ void tst_qdeclarativemetaproperty::qmlmetaproperty_object_string_context() delete obj; } + + { + QDeclarativeMetaProperty prop(&dobject, QString("onPropertyWithNotifyChanged"), engine.rootContext()); + + QGuard binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext())); + binding->setTarget(prop); + QVERIFY(binding != 0); + QGuard expression(new QDeclarativeExpression()); + QVERIFY(expression != 0); + + QObject *obj = new QObject; + + QCOMPARE(prop.name(), QString("onOddlyNamedNotifySignal")); + QCOMPARE(prop.read(), QVariant()); + QCOMPARE(prop.write(QVariant("Hello")), false); + QCOMPARE(prop.hasChangedNotifier(), false); + QCOMPARE(prop.needsChangedNotifier(), false); + QCOMPARE(prop.connectNotifier(0, SLOT(deleteLater())), false); + QCOMPARE(prop.connectNotifier(obj, SLOT(deleteLater())), false); + QCOMPARE(prop.connectNotifier(obj, 0), false); + QCOMPARE(prop.connectNotifier(0, obj->metaObject()->indexOfMethod("deleteLater()")), false); + QCOMPARE(prop.connectNotifier(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false); + QCOMPARE(prop.connectNotifier(obj, -1), false); + QCOMPARE(QString(prop.method().signature()), QString("oddlyNamedNotifySignal()")); + QCOMPARE(prop.type(), QDeclarativeMetaProperty::SignalProperty); + QCOMPARE(prop.isProperty(), false); + QCOMPARE(prop.isDefault(), false); + QCOMPARE(prop.isWritable(), false); + QCOMPARE(prop.isDesignable(), false); + QCOMPARE(prop.isResettable(), false); + QCOMPARE(prop.isValid(), true); + QCOMPARE(prop.object(), &dobject); + QCOMPARE(prop.propertyCategory(), QDeclarativeMetaProperty::InvalidProperty); + QCOMPARE(prop.propertyType(), 0); + QCOMPARE(prop.propertyTypeName(), (const char *)0); + QCOMPARE(prop.property().name(), (const char *)0); + QVERIFY(prop.binding() == 0); + QVERIFY(prop.setBinding(binding) == 0); + QVERIFY(binding == 0); + QVERIFY(prop.signalExpression() == 0); + QVERIFY(prop.setSignalExpression(expression) == 0); + QVERIFY(expression != 0); + QVERIFY(prop.signalExpression() == expression); + QCOMPARE(prop.coreIndex(), dobject.metaObject()->indexOfMethod("oddlyNamedNotifySignal()")); + QCOMPARE(prop.valueTypeCoreIndex(), -1); + + delete obj; + } } void tst_qdeclarativemetaproperty::name() @@ -741,6 +843,18 @@ void tst_qdeclarativemetaproperty::name() } { + PropertyObject o; + QDeclarativeMetaProperty p(&o, "onPropertyWithNotifyChanged"); + QCOMPARE(p.name(), QString("onOddlyNamedNotifySignal")); + } + + { + QObject o; + QDeclarativeMetaProperty p(&o, "onPropertyWithNotifyChanged"); + QCOMPARE(p.name(), QString()); + } + + { QObject o; QDeclarativeMetaProperty p(&o, "foo"); QCOMPARE(p.name(), QString()); @@ -830,6 +944,18 @@ void tst_qdeclarativemetaproperty::read() QCOMPARE(p.read(), QVariant()); } + // Automatic signal property + { + PropertyObject o; + QDeclarativeMetaProperty p(&o, "onPropertyWithNotifyChanged"); + QCOMPARE(p.read(), QVariant()); + + QVERIFY(0 == p.setSignalExpression(new QDeclarativeExpression())); + QVERIFY(0 != p.signalExpression()); + + QCOMPARE(p.read(), QVariant()); + } + // Deleted object { PropertyObject *o = new PropertyObject; @@ -936,6 +1062,20 @@ void tst_qdeclarativemetaproperty::write() QVERIFY(0 != p.signalExpression()); } + // Automatic signal property + { + PropertyObject o; + QDeclarativeMetaProperty p(&o, "onPropertyWithNotifyChanged"); + QCOMPARE(p.write(QVariant("console.log(1921)")), false); + + QVERIFY(0 == p.setSignalExpression(new QDeclarativeExpression())); + QVERIFY(0 != p.signalExpression()); + + QCOMPARE(p.write(QVariant("console.log(1921)")), false); + + QVERIFY(0 != p.signalExpression()); + } + // Value-type property { PropertyObject o; @@ -1065,6 +1205,15 @@ void tst_qdeclarativemetaproperty::reset() QCOMPARE(p.isResettable(), false); QCOMPARE(p.reset(), false); } + + // Automatic signal property + { + PropertyObject o; + QDeclarativeMetaProperty p(&o, "onPropertyWithNotifyChanged"); + + QCOMPARE(p.isResettable(), false); + QCOMPARE(p.reset(), false); + } } void tst_qdeclarativemetaproperty::writeObjectToList() diff --git a/tests/auto/declarative/qdeclarativestates/data/basicChanges4.qml b/tests/auto/declarative/qdeclarativestates/data/basicChanges4.qml new file mode 100644 index 0000000..a373cfc --- /dev/null +++ b/tests/auto/declarative/qdeclarativestates/data/basicChanges4.qml @@ -0,0 +1,19 @@ +import Qt.test 1.0 +import Qt 4.6 + +MyRectangle { + id: rect + width: 100; height: 100 + color: "red" + + states: State { + name: "aBlueDay" + PropertyChanges { + target: rect + onPropertyWithNotifyChanged: { rect.color = "blue"; } + } + } + + Component.onCompleted: rect.state = "aBlueDay" +} + diff --git a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp index 44fb51f..feac9c2 100644 --- a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp +++ b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp @@ -46,6 +46,29 @@ #include #include + +class MyRect : public QDeclarativeRectangle +{ + Q_OBJECT + Q_PROPERTY(int propertyWithNotify READ propertyWithNotify WRITE setPropertyWithNotify NOTIFY oddlyNamedNotifySignal) +public: + MyRect() {} + + void doSomething() { emit didSomething(); } + + int propertyWithNotify() const { return m_prop; } + void setPropertyWithNotify(int i) { m_prop = i; emit oddlyNamedNotifySignal(); } +Q_SIGNALS: + void didSomething(); + void oddlyNamedNotifySignal(); + +private: + int m_prop; +}; + +QML_DECLARE_TYPE(MyRect) + + class tst_qdeclarativestates : public QObject { Q_OBJECT @@ -83,6 +106,11 @@ private slots: void nonExistantProperty(); }; +void tst_qdeclarativestates::initTestCase() +{ + QML_REGISTER_TYPE(Qt.test, 1, 0, MyRectangle,MyRect); +} + QByteArray tst_qdeclarativestates::fullDataPath(const QString &path) { return QUrl::fromLocalFile(SRCDIR + path).toString().toUtf8(); @@ -156,6 +184,28 @@ void tst_qdeclarativestates::basicChanges() QCOMPARE(rect->border()->width(),1); } + + { + // Test basicChanges4.qml can magically connect to propertyWithNotify's notify + // signal using 'onPropertyWithNotifyChanged' even though the signal name is + // actually 'oddlyNamedNotifySignal' + + QDeclarativeComponent component(&engine, SRCDIR "/data/basicChanges4.qml"); + QVERIFY(component.isReady()); + + MyRect *rect = qobject_cast(component.create()); + QVERIFY(rect != 0); + + QMetaProperty prop = rect->metaObject()->property(rect->metaObject()->indexOfProperty("propertyWithNotify")); + QVERIFY(prop.hasNotifySignal()); + QString notifySignal = QByteArray(prop.notifySignal().signature()); + QVERIFY(!notifySignal.startsWith("propertyWithNotifyChanged(")); + + QCOMPARE(rect->color(), QColor(Qt::red)); + + rect->setPropertyWithNotify(100); + QCOMPARE(rect->color(), QColor(Qt::blue)); + } } void tst_qdeclarativestates::basicExtension() @@ -335,23 +385,6 @@ void tst_qdeclarativestates::basicBinding() } } -class MyRect : public QDeclarativeRectangle -{ - Q_OBJECT -public: - MyRect() {} - void doSomething() { emit didSomething(); } -Q_SIGNALS: - void didSomething(); -}; - -QML_DECLARE_TYPE(MyRect) - -void tst_qdeclarativestates::initTestCase() -{ - QML_REGISTER_TYPE(Qt.test, 1, 0, MyRectangle,MyRect); -} - void tst_qdeclarativestates::signalOverride() { QDeclarativeEngine engine; -- cgit v0.12 From bb6ec109475f68829bb7b62ba4c13e7486eed5cf Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Fri, 26 Feb 2010 10:54:05 +1000 Subject: Make compile following recent QDeclarativeProperty changes --- .../tst_qdeclarativeproperty.cpp | 56 +++++++++++----------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/tests/auto/declarative/qdeclarativeproperty/tst_qdeclarativeproperty.cpp b/tests/auto/declarative/qdeclarativeproperty/tst_qdeclarativeproperty.cpp index a3aefe3..c72c9e7 100644 --- a/tests/auto/declarative/qdeclarativeproperty/tst_qdeclarativeproperty.cpp +++ b/tests/auto/declarative/qdeclarativeproperty/tst_qdeclarativeproperty.cpp @@ -466,7 +466,7 @@ void tst_qdeclarativeproperty::qmlmetaproperty_object_string() } { - QDeclarativeMetaProperty prop(&dobject, QString("onPropertyWithNotifyChanged")); + QDeclarativeProperty prop(&dobject, QString("onPropertyWithNotifyChanged")); QGuard binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext())); binding->setTarget(prop); @@ -488,7 +488,7 @@ void tst_qdeclarativeproperty::qmlmetaproperty_object_string() QCOMPARE(prop.connectNotifier(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false); QCOMPARE(prop.connectNotifier(obj, -1), false); QCOMPARE(QString(prop.method().signature()), QString("oddlyNamedNotifySignal()")); - QCOMPARE(prop.type(), QDeclarativeMetaProperty::SignalProperty); + QCOMPARE(prop.type(), QDeclarativeProperty::SignalProperty); QCOMPARE(prop.isProperty(), false); QCOMPARE(prop.isDefault(), false); QCOMPARE(prop.isWritable(), false); @@ -496,19 +496,19 @@ void tst_qdeclarativeproperty::qmlmetaproperty_object_string() QCOMPARE(prop.isResettable(), false); QCOMPARE(prop.isValid(), true); QCOMPARE(prop.object(), &dobject); - QCOMPARE(prop.propertyCategory(), QDeclarativeMetaProperty::InvalidProperty); + QCOMPARE(prop.propertyTypeCategory(), QDeclarativeProperty::InvalidCategory); QCOMPARE(prop.propertyType(), 0); QCOMPARE(prop.propertyTypeName(), (const char *)0); QCOMPARE(prop.property().name(), (const char *)0); - QVERIFY(prop.binding() == 0); - QVERIFY(prop.setBinding(binding) == 0); + QVERIFY(QDeclarativePropertyPrivate::binding(prop) == 0); + QVERIFY(QDeclarativePropertyPrivate::setBinding(prop, binding) == 0); QVERIFY(binding == 0); - QVERIFY(prop.signalExpression() == 0); - QVERIFY(prop.setSignalExpression(expression) == 0); + QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == 0); + QVERIFY(QDeclarativePropertyPrivate::setSignalExpression(prop, expression) == 0); QVERIFY(expression != 0); - QVERIFY(prop.signalExpression() == expression); + QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == expression); QCOMPARE(prop.coreIndex(), dobject.metaObject()->indexOfMethod("oddlyNamedNotifySignal()")); - QCOMPARE(prop.valueTypeCoreIndex(), -1); + QCOMPARE(QDeclarativePropertyPrivate::valueTypeCoreIndex(prop), -1); delete obj; } @@ -764,7 +764,7 @@ void tst_qdeclarativeproperty::qmlmetaproperty_object_string_context() } { - QDeclarativeMetaProperty prop(&dobject, QString("onPropertyWithNotifyChanged"), engine.rootContext()); + QDeclarativeProperty prop(&dobject, QString("onPropertyWithNotifyChanged"), engine.rootContext()); QGuard binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext())); binding->setTarget(prop); @@ -786,7 +786,7 @@ void tst_qdeclarativeproperty::qmlmetaproperty_object_string_context() QCOMPARE(prop.connectNotifier(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false); QCOMPARE(prop.connectNotifier(obj, -1), false); QCOMPARE(QString(prop.method().signature()), QString("oddlyNamedNotifySignal()")); - QCOMPARE(prop.type(), QDeclarativeMetaProperty::SignalProperty); + QCOMPARE(prop.type(), QDeclarativeProperty::SignalProperty); QCOMPARE(prop.isProperty(), false); QCOMPARE(prop.isDefault(), false); QCOMPARE(prop.isWritable(), false); @@ -794,19 +794,19 @@ void tst_qdeclarativeproperty::qmlmetaproperty_object_string_context() QCOMPARE(prop.isResettable(), false); QCOMPARE(prop.isValid(), true); QCOMPARE(prop.object(), &dobject); - QCOMPARE(prop.propertyCategory(), QDeclarativeMetaProperty::InvalidProperty); + QCOMPARE(prop.propertyTypeCategory(), QDeclarativeProperty::InvalidCategory); QCOMPARE(prop.propertyType(), 0); QCOMPARE(prop.propertyTypeName(), (const char *)0); QCOMPARE(prop.property().name(), (const char *)0); - QVERIFY(prop.binding() == 0); - QVERIFY(prop.setBinding(binding) == 0); + QVERIFY(QDeclarativePropertyPrivate::binding(prop) == 0); + QVERIFY(QDeclarativePropertyPrivate::setBinding(prop, binding) == 0); QVERIFY(binding == 0); - QVERIFY(prop.signalExpression() == 0); - QVERIFY(prop.setSignalExpression(expression) == 0); + QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == 0); + QVERIFY(QDeclarativePropertyPrivate::setSignalExpression(prop, expression) == 0); QVERIFY(expression != 0); - QVERIFY(prop.signalExpression() == expression); + QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == expression); QCOMPARE(prop.coreIndex(), dobject.metaObject()->indexOfMethod("oddlyNamedNotifySignal()")); - QCOMPARE(prop.valueTypeCoreIndex(), -1); + QCOMPARE(QDeclarativePropertyPrivate::valueTypeCoreIndex(prop), -1); delete obj; } @@ -845,13 +845,13 @@ void tst_qdeclarativeproperty::name() { PropertyObject o; - QDeclarativeMetaProperty p(&o, "onPropertyWithNotifyChanged"); + QDeclarativeProperty p(&o, "onPropertyWithNotifyChanged"); QCOMPARE(p.name(), QString("onOddlyNamedNotifySignal")); } { QObject o; - QDeclarativeMetaProperty p(&o, "onPropertyWithNotifyChanged"); + QDeclarativeProperty p(&o, "onPropertyWithNotifyChanged"); QCOMPARE(p.name(), QString()); } @@ -948,11 +948,11 @@ void tst_qdeclarativeproperty::read() // Automatic signal property { PropertyObject o; - QDeclarativeMetaProperty p(&o, "onPropertyWithNotifyChanged"); + QDeclarativeProperty p(&o, "onPropertyWithNotifyChanged"); QCOMPARE(p.read(), QVariant()); - QVERIFY(0 == p.setSignalExpression(new QDeclarativeExpression())); - QVERIFY(0 != p.signalExpression()); + QVERIFY(0 == QDeclarativePropertyPrivate::setSignalExpression(p, new QDeclarativeExpression())); + QVERIFY(0 != QDeclarativePropertyPrivate::signalExpression(p)); QCOMPARE(p.read(), QVariant()); } @@ -1066,15 +1066,15 @@ void tst_qdeclarativeproperty::write() // Automatic signal property { PropertyObject o; - QDeclarativeMetaProperty p(&o, "onPropertyWithNotifyChanged"); + QDeclarativeProperty p(&o, "onPropertyWithNotifyChanged"); QCOMPARE(p.write(QVariant("console.log(1921)")), false); - QVERIFY(0 == p.setSignalExpression(new QDeclarativeExpression())); - QVERIFY(0 != p.signalExpression()); + QVERIFY(0 == QDeclarativePropertyPrivate::setSignalExpression(p, new QDeclarativeExpression())); + QVERIFY(0 != QDeclarativePropertyPrivate::signalExpression(p)); QCOMPARE(p.write(QVariant("console.log(1921)")), false); - QVERIFY(0 != p.signalExpression()); + QVERIFY(0 != QDeclarativePropertyPrivate::signalExpression(p)); } // Value-type property @@ -1210,7 +1210,7 @@ void tst_qdeclarativeproperty::reset() // Automatic signal property { PropertyObject o; - QDeclarativeMetaProperty p(&o, "onPropertyWithNotifyChanged"); + QDeclarativeProperty p(&o, "onPropertyWithNotifyChanged"); QCOMPARE(p.isResettable(), false); QCOMPARE(p.reset(), false); -- cgit v0.12 From e1abb8b075c8fc24bc768619ca2dbe1204431101 Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Fri, 26 Feb 2010 11:23:10 +1000 Subject: Fix qdatastream::compatibility_Qt3 autotest failure --- src/corelib/kernel/qvariant.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 384a3cd..227a60d 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -1936,13 +1936,13 @@ static const ushort map_from_three[MapFromThreeCount] = QVariant::Date, QVariant::Time, QVariant::DateTime, - QVariant::EasingCurve, QVariant::ByteArray, QVariant::BitArray, QVariant::KeySequence, QVariant::Pen, QVariant::LongLong, - QVariant::ULongLong + QVariant::ULongLong, + QVariant::EasingCurve }; /*! -- cgit v0.12 From 71412e3d9b9152cbbc42245751fc197672fc7b08 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 26 Feb 2010 11:44:51 +1000 Subject: Remove unnecessary QDeclarativeProperty::Type enum values --- src/declarative/qml/qdeclarativeproperty.cpp | 61 +++++++++++++++++++--------- src/declarative/qml/qdeclarativeproperty.h | 3 +- src/declarative/qml/qdeclarativeproperty_p.h | 1 + 3 files changed, 43 insertions(+), 22 deletions(-) diff --git a/src/declarative/qml/qdeclarativeproperty.cpp b/src/declarative/qml/qdeclarativeproperty.cpp index 7ead1b5..fbea6ac 100644 --- a/src/declarative/qml/qdeclarativeproperty.cpp +++ b/src/declarative/qml/qdeclarativeproperty.cpp @@ -63,10 +63,30 @@ QT_BEGIN_NAMESPACE /*! - \class QDeclarativeProperty - \brief The QDeclarativeProperty class abstracts accessing QML properties. - \internal - */ +\class QDeclarativeProperty +\brief The QDeclarativeProperty class abstracts accessing properties on objects created from QML. + +As QML uses Qt's meta-type system all of the existing QMetaObject classes can be used to introspect +and interact with objects created by QML. However, some of the new features provided by QML - such +as type safety and attached properties - are most easily used through the QDeclarativeProperty class +that simplifies some of their natural complexity. + +Unlike QMetaProperty which represents a property on a class type, QDeclarativeProperty encapsulates +a property on a specific object instance. To read a property's value, programmers create a +QDeclarativeProperty instance and call the read() method. Likewise to write a property value the +write() method is used. + +\code + +QObject *object = declarativeComponent.create(); + +QDeclarativeProperty property(object, "font.pixelSize"); +qWarning() << "Current pixel size:" << property.read().toInt(); +property.write(24); +qWarning() << "Pixel size should now be 24:" << property.read().toInt(); + +\endcode +*/ /*! Create an invalid QDeclarativeProperty. @@ -298,7 +318,7 @@ QDeclarativePropertyPrivate::propertyTypeCategory() const { uint type = q->type(); - if (type & QDeclarativeProperty::ValueTypeProperty) { + if (isValueType()) { return QDeclarativeProperty::Normal; } else if (type & QDeclarativeProperty::Property) { int type = propertyType(); @@ -323,7 +343,7 @@ QDeclarativePropertyPrivate::propertyTypeCategory() const */ const char *QDeclarativeProperty::propertyTypeName() const { - if (type() & ValueTypeProperty) { + if (d->isValueType()) { QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(d->context); QDeclarativeValueType *valueType = 0; @@ -365,10 +385,15 @@ int QDeclarativeProperty::propertyType() const return d->propertyType(); } +bool QDeclarativePropertyPrivate::isValueType() const +{ + return valueType.valueTypeCoreIdx != -1; +} + int QDeclarativePropertyPrivate::propertyType() const { uint type = q->type(); - if (type & QDeclarativeProperty::ValueTypeProperty) { + if (isValueType()) { return valueType.valueTypePropType; } else if (type & QDeclarativeProperty::Property) { if (core.propType == (int)QVariant::LastType) @@ -387,8 +412,6 @@ QDeclarativeProperty::Type QDeclarativeProperty::type() const { if (d->core.flags & QDeclarativePropertyCache::Data::IsFunction) return SignalProperty; - else if (d->valueType.valueTypeCoreIdx != -1) - return (Type)(Property | ValueTypeProperty); else if (d->core.isValid()) return (Type)(Property | ((d->isDefaultProperty)?Default:0)); else @@ -495,7 +518,7 @@ QString QDeclarativeProperty::name() const if (!d->isNameCached) { // ### if (!d->object) { - } else if (type() & ValueTypeProperty) { + } else if (d->isValueType()) { QString rv = d->core.name(d->object) + QLatin1Char('.'); QDeclarativeEnginePrivate *ep = d->context?QDeclarativeEnginePrivate::get(d->context->engine()):0; @@ -709,8 +732,7 @@ QVariant QDeclarativeProperty::read() const QVariant QDeclarativePropertyPrivate::readValueProperty() { - uint type = q->type(); - if(type & QDeclarativeProperty::ValueTypeProperty) { + if(isValueType()) { QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(context); QDeclarativeValueType *valueType = 0; @@ -789,8 +811,7 @@ bool QDeclarativePropertyPrivate::writeValueProperty(const QVariant &value, Writ } bool rv = false; - uint type = q->type(); - if (type & QDeclarativeProperty::ValueTypeProperty) { + if (isValueType()) { QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(context); QDeclarativeValueType *writeBack = 0; @@ -1097,7 +1118,7 @@ int QDeclarativePropertyPrivate::valueTypeCoreIndex(const QDeclarativeProperty & } struct SerializedData { - QDeclarativeProperty::Type type; + bool isValueType; QDeclarativePropertyCache::Data core; }; @@ -1112,7 +1133,7 @@ QByteArray QDeclarativePropertyPrivate::saveValueType(const QMetaObject *metaObj QMetaProperty subProp = subObject->property(subIndex); ValueTypeSerializedData sd; - sd.type = QDeclarativeProperty::ValueTypeProperty; + sd.isValueType = true; sd.core.load(metaObject->property(index)); sd.valueType.flags = QDeclarativePropertyCache::Data::flagsForProperty(subProp); sd.valueType.valueTypeCoreIdx = subIndex; @@ -1126,7 +1147,7 @@ QByteArray QDeclarativePropertyPrivate::saveValueType(const QMetaObject *metaObj QByteArray QDeclarativePropertyPrivate::saveProperty(const QMetaObject *metaObject, int index) { SerializedData sd; - sd.type = QDeclarativeProperty::Property; + sd.isValueType = false; sd.core.load(metaObject->property(index)); QByteArray rv((const char *)&sd, sizeof(sd)); @@ -1145,12 +1166,12 @@ QDeclarativePropertyPrivate::restore(const QByteArray &data, QObject *object, QD prop.d->context = ctxt; const SerializedData *sd = (const SerializedData *)data.constData(); - if (sd->type == QDeclarativeProperty::Property) { - prop.d->core = sd->core; - } else if(sd->type == QDeclarativeProperty::ValueTypeProperty) { + if (sd->isValueType) { const ValueTypeSerializedData *vt = (const ValueTypeSerializedData *)sd; prop.d->core = vt->core; prop.d->valueType = vt->valueType; + } else { + prop.d->core = sd->core; } return prop; diff --git a/src/declarative/qml/qdeclarativeproperty.h b/src/declarative/qml/qdeclarativeproperty.h index be1065e..3504a15 100644 --- a/src/declarative/qml/qdeclarativeproperty.h +++ b/src/declarative/qml/qdeclarativeproperty.h @@ -73,8 +73,7 @@ public: enum Type { Invalid = 0x00, Property = 0x01, SignalProperty = 0x02, - Default = 0x08, - ValueTypeProperty = 0x10 + Default = 0x08 }; QDeclarativeProperty(); diff --git a/src/declarative/qml/qdeclarativeproperty_p.h b/src/declarative/qml/qdeclarativeproperty_p.h index d0ad09c..eb5fa9a 100644 --- a/src/declarative/qml/qdeclarativeproperty_p.h +++ b/src/declarative/qml/qdeclarativeproperty_p.h @@ -97,6 +97,7 @@ public: QMetaMethod findSignal(QObject *, const QString &); + bool isValueType() const; int propertyType() const; QDeclarativeProperty::PropertyTypeCategory propertyTypeCategory() const; -- cgit v0.12 From e3d78a41a7d0533972169aeb6ca00b5655c5c404 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 26 Feb 2010 12:05:50 +1000 Subject: Rebuild since -declarative auto detection changed. --- configure.exe | Bin 1221632 -> 1223680 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/configure.exe b/configure.exe index f937ea2..39a1747 100755 Binary files a/configure.exe and b/configure.exe differ -- cgit v0.12