From 1a2621707da2d41653e9fd2cbf92002fd55b11c5 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 13 May 2009 14:03:43 +1000 Subject: Literal signal property assignment test --- .../qmlparser/assignLiteralSignalProperty.txt | 3 + tests/auto/declarative/qmlparser/qmlparser.pro | 4 +- tests/auto/declarative/qmlparser/testtypes.cpp | 9 + tests/auto/declarative/qmlparser/testtypes.h | 372 +++++++++++++++++++++ tests/auto/declarative/qmlparser/tst_qmlparser.cpp | 372 +-------------------- 5 files changed, 396 insertions(+), 364 deletions(-) create mode 100644 tests/auto/declarative/qmlparser/assignLiteralSignalProperty.txt create mode 100644 tests/auto/declarative/qmlparser/testtypes.cpp create mode 100644 tests/auto/declarative/qmlparser/testtypes.h diff --git a/tests/auto/declarative/qmlparser/assignLiteralSignalProperty.txt b/tests/auto/declarative/qmlparser/assignLiteralSignalProperty.txt new file mode 100644 index 0000000..f3a7ac7 --- /dev/null +++ b/tests/auto/declarative/qmlparser/assignLiteralSignalProperty.txt @@ -0,0 +1,3 @@ +MyQmlObject { + onLiteralSignal: 10 +} diff --git a/tests/auto/declarative/qmlparser/qmlparser.pro b/tests/auto/declarative/qmlparser/qmlparser.pro index 42e157f..b2fc490 100644 --- a/tests/auto/declarative/qmlparser/qmlparser.pro +++ b/tests/auto/declarative/qmlparser/qmlparser.pro @@ -1,6 +1,8 @@ load(qttest_p4) contains(QT_CONFIG,declarative): QT += declarative -SOURCES += tst_qmlparser.cpp +SOURCES += tst_qmlparser.cpp \ + testtypes.cpp +HEADERS = testtypes.h macx:CONFIG -= app_bundle # QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage diff --git a/tests/auto/declarative/qmlparser/testtypes.cpp b/tests/auto/declarative/qmlparser/testtypes.cpp new file mode 100644 index 0000000..69df5c3 --- /dev/null +++ b/tests/auto/declarative/qmlparser/testtypes.cpp @@ -0,0 +1,9 @@ +#include "testtypes.h" + +QML_DEFINE_INTERFACE(MyInterface); +QML_DEFINE_TYPE(MyQmlObject,MyQmlObject); +QML_DEFINE_TYPE(MyTypeObject,MyTypeObject); +QML_DEFINE_TYPE(MyContainer,MyContainer); +QML_DEFINE_TYPE(MyPropertyValueSource,MyPropertyValueSource); +QML_DEFINE_TYPE(MyDotPropertyObject,MyDotPropertyObject); + diff --git a/tests/auto/declarative/qmlparser/testtypes.h b/tests/auto/declarative/qmlparser/testtypes.h new file mode 100644 index 0000000..190611f --- /dev/null +++ b/tests/auto/declarative/qmlparser/testtypes.h @@ -0,0 +1,372 @@ +#ifndef TESTTYPES_H +#define TESTTYPES_H + +#include +#include +#include +#include +#include +#include +#include +#include + +class MyInterface +{ +public: + MyInterface() : id(913) {} + int id; +}; +Q_DECLARE_INTERFACE(MyInterface, "com.trolltech.Qt.Test.MyInterface"); +QML_DECLARE_INTERFACE(MyInterface); + +class MyQmlObject : public QObject, public MyInterface, public QmlParserStatus +{ + Q_OBJECT + Q_PROPERTY(int value READ value WRITE setValue) + Q_PROPERTY(QString readOnlyString READ readOnlyString) + Q_PROPERTY(bool enabled READ enabled WRITE setEnabled) + Q_PROPERTY(QRect rect READ rect WRITE setRect) + Q_PROPERTY(QMatrix matrix READ matrix WRITE setMatrix) //assumed to be unsupported by QML + Q_PROPERTY(MyInterface *interface READ interface WRITE setInterface) + Q_PROPERTY(int onLiteralSignal READ onLiteralSignal WRITE setOnLiteralSignal); + Q_INTERFACES(MyInterface QmlParserStatus) +public: + MyQmlObject() : m_value(-1), m_interface(0) {} + + int value() const { return m_value; } + void setValue(int v) { m_value = v; } + + QString readOnlyString() const { return QLatin1String(""); } + + bool enabled() const { return false; } + void setEnabled(bool) {} + + QRect rect() const { return QRect(); } + void setRect(const QRect&) {} + + QMatrix matrix() const { return QMatrix(); } + void setMatrix(const QMatrix&) {} + + MyInterface *interface() const { return m_interface; } + void setInterface(MyInterface *iface) { m_interface = iface; } + + static QObject *qmlAttachedProperties(QObject *other) { + MyQmlObject *rv = new MyQmlObject; + rv->setParent(other); + return rv; + } + Q_CLASSINFO("DefaultMethod", "basicSlot()"); + + int onLiteralSignal() const { return m_value; } + void setOnLiteralSignal(int v) { m_value = v; } + +public slots: + void basicSlot() { qWarning("MyQmlObject::basicSlot"); } + +signals: + void basicSignal(); + +private: + friend class tst_qmlparser; + int m_value; + MyInterface *m_interface; +}; +QML_DECLARE_TYPE(MyQmlObject); + +class MyTypeObject : public QObject +{ + Q_OBJECT + Q_ENUMS(MyEnum) + Q_FLAGS(MyFlags) + + Q_PROPERTY(QString id READ id WRITE setId); + Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty); + Q_PROPERTY(QmlComponent *componentProperty READ componentProperty WRITE setComponentProperty); + Q_PROPERTY(MyFlags flagProperty READ flagProperty WRITE setFlagProperty); + Q_PROPERTY(MyEnum enumProperty READ enumProperty WRITE setEnumProperty); + Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty); + Q_PROPERTY(uint uintProperty READ uintProperty WRITE setUintProperty); + Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty); + Q_PROPERTY(qreal realProperty READ realProperty WRITE setRealProperty); + Q_PROPERTY(double doubleProperty READ doubleProperty WRITE setDoubleProperty); + Q_PROPERTY(QColor colorProperty READ colorProperty WRITE setColorProperty); + Q_PROPERTY(QDate dateProperty READ dateProperty WRITE setDateProperty); + Q_PROPERTY(QTime timeProperty READ timeProperty WRITE setTimeProperty); + Q_PROPERTY(QDateTime dateTimeProperty READ dateTimeProperty WRITE setDateTimeProperty); + Q_PROPERTY(QPoint pointProperty READ pointProperty WRITE setPointProperty); + Q_PROPERTY(QPointF pointFProperty READ pointFProperty WRITE setPointFProperty); + Q_PROPERTY(QSize sizeProperty READ sizeProperty WRITE setSizeProperty); + Q_PROPERTY(QSizeF sizeFProperty READ sizeFProperty WRITE setSizeFProperty); + Q_PROPERTY(QRect rectProperty READ rectProperty WRITE setRectProperty); + Q_PROPERTY(QRectF rectFProperty READ rectFProperty WRITE setRectFProperty); + Q_PROPERTY(bool boolProperty READ boolProperty WRITE setBoolProperty); + Q_PROPERTY(QVariant variantProperty READ variantProperty WRITE setVariantProperty); + +public: + MyTypeObject() + : objectPropertyValue(0), componentPropertyValue(0) {} + + QString idValue; + QString id() const { + return idValue; + } + void setId(const QString &v) { + idValue = v; + } + + QObject *objectPropertyValue; + QObject *objectProperty() const { + return objectPropertyValue; + } + void setObjectProperty(QObject *v) { + objectPropertyValue = v; + } + + QmlComponent *componentPropertyValue; + QmlComponent *componentProperty() const { + return componentPropertyValue; + } + void setComponentProperty(QmlComponent *v) { + componentPropertyValue = v; + } + + enum MyFlag { FlagVal1 = 0x01, FlagVal2 = 0x02, FlagVal3 = 0x04 }; + Q_DECLARE_FLAGS(MyFlags, MyFlag) + MyFlags flagPropertyValue; + MyFlags flagProperty() const { + return flagPropertyValue; + } + void setFlagProperty(MyFlags v) { + flagPropertyValue = v; + } + + enum MyEnum { EnumVal1, EnumVal2 }; + MyEnum enumPropertyValue; + MyEnum enumProperty() const { + return enumPropertyValue; + } + void setEnumProperty(MyEnum v) { + enumPropertyValue = v; + } + + QString stringPropertyValue; + QString stringProperty() const { + return stringPropertyValue; + } + void setStringProperty(const QString &v) { + stringPropertyValue = v; + } + + uint uintPropertyValue; + uint uintProperty() const { + return uintPropertyValue; + } + void setUintProperty(const uint &v) { + uintPropertyValue = v; + } + + int intPropertyValue; + int intProperty() const { + return intPropertyValue; + } + void setIntProperty(const int &v) { + intPropertyValue = v; + } + + qreal realPropertyValue; + qreal realProperty() const { + return realPropertyValue; + } + void setRealProperty(const qreal &v) { + realPropertyValue = v; + } + + double doublePropertyValue; + double doubleProperty() const { + return doublePropertyValue; + } + void setDoubleProperty(const double &v) { + doublePropertyValue = v; + } + + QColor colorPropertyValue; + QColor colorProperty() const { + return colorPropertyValue; + } + void setColorProperty(const QColor &v) { + colorPropertyValue = v; + } + + QDate datePropertyValue; + QDate dateProperty() const { + return datePropertyValue; + } + void setDateProperty(const QDate &v) { + datePropertyValue = v; + } + + QTime timePropertyValue; + QTime timeProperty() const { + return timePropertyValue; + } + void setTimeProperty(const QTime &v) { + timePropertyValue = v; + } + + QDateTime dateTimePropertyValue; + QDateTime dateTimeProperty() const { + return dateTimePropertyValue; + } + void setDateTimeProperty(const QDateTime &v) { + dateTimePropertyValue = v; + } + + QPoint pointPropertyValue; + QPoint pointProperty() const { + return pointPropertyValue; + } + void setPointProperty(const QPoint &v) { + pointPropertyValue = v; + } + + QPointF pointFPropertyValue; + QPointF pointFProperty() const { + return pointFPropertyValue; + } + void setPointFProperty(const QPointF &v) { + pointFPropertyValue = v; + } + + QSize sizePropertyValue; + QSize sizeProperty() const { + return sizePropertyValue; + } + void setSizeProperty(const QSize &v) { + sizePropertyValue = v; + } + + QSizeF sizeFPropertyValue; + QSizeF sizeFProperty() const { + return sizeFPropertyValue; + } + void setSizeFProperty(const QSizeF &v) { + sizeFPropertyValue = v; + } + + QRect rectPropertyValue; + QRect rectProperty() const { + return rectPropertyValue; + } + void setRectProperty(const QRect &v) { + rectPropertyValue = v; + } + + QRectF rectFPropertyValue; + QRectF rectFProperty() const { + return rectFPropertyValue; + } + void setRectFProperty(const QRectF &v) { + rectFPropertyValue = v; + } + + bool boolPropertyValue; + bool boolProperty() const { + return boolPropertyValue; + } + void setBoolProperty(const bool &v) { + boolPropertyValue = v; + } + + QVariant variantPropertyValue; + QVariant variantProperty() const { + return variantPropertyValue; + } + void setVariantProperty(const QVariant &v) { + variantPropertyValue = v; + } +}; +Q_DECLARE_OPERATORS_FOR_FLAGS(MyTypeObject::MyFlags) +QML_DECLARE_TYPE(MyTypeObject); + +class MyContainer : public QObject +{ + Q_OBJECT + Q_PROPERTY(QList* children READ children) + Q_PROPERTY(QList* qlistInterfaces READ qlistInterfaces) + Q_PROPERTY(QmlList* qmllistInterfaces READ qmllistInterfaces) + Q_CLASSINFO("DefaultProperty", "children"); +public: + MyContainer() {} + + QList *children() { return &m_children; } + QList *qlistInterfaces() { return &m_interfaces; } + QmlList *qmllistInterfaces() { return &m_qmlinterfaces; } + const QmlConcreteList &qmllistAccessor() const { return m_qmlinterfaces; } + +private: + QList m_children; + QList m_interfaces; + QmlConcreteList m_qmlinterfaces; +}; + +QML_DECLARE_TYPE(MyContainer); + +class MyPropertyValueSource : public QmlPropertyValueSource +{ + Q_OBJECT +public: + MyPropertyValueSource() + : QmlPropertyValueSource(0) {} + + QmlMetaProperty prop; + virtual void setTarget(const QmlMetaProperty &p) + { + prop = p; + } +}; +QML_DECLARE_TYPE(MyPropertyValueSource); + +class MyDotPropertyObject : public QObject +{ + Q_OBJECT + Q_PROPERTY(MyQmlObject *obj READ obj) + Q_PROPERTY(MyQmlObject *readWriteObj READ readWriteObj WRITE setReadWriteObj) +public: + MyDotPropertyObject() : m_rwobj(0), m_ownRWObj(false) {} + ~MyDotPropertyObject() + { + if (m_ownRWObj) + delete m_rwobj; + } + + MyQmlObject *obj() { return 0; } + + MyQmlObject *readWriteObj() + { + if (!m_rwobj) { + m_rwobj = new MyQmlObject; + m_ownRWObj = true; + } + return m_rwobj; + } + + void setReadWriteObj(MyQmlObject *obj) + { + if (m_ownRWObj) { + delete m_rwobj; + m_ownRWObj = false; + } + + m_rwobj = obj; + } + +private: + MyQmlObject *m_rwobj; + bool m_ownRWObj; +}; + +QML_DECLARE_TYPE(MyDotPropertyObject); + + + +#endif // TESTTYPES_H diff --git a/tests/auto/declarative/qmlparser/tst_qmlparser.cpp b/tests/auto/declarative/qmlparser/tst_qmlparser.cpp index b27d5d5..5af75c4 100644 --- a/tests/auto/declarative/qmlparser/tst_qmlparser.cpp +++ b/tests/auto/declarative/qmlparser/tst_qmlparser.cpp @@ -1,371 +1,9 @@ #include #include #include -#include #include #include - -class MyInterface -{ -public: - MyInterface() : id(913) {} - int id; -}; - -Q_DECLARE_INTERFACE(MyInterface, "com.trolltech.Qt.Test.MyInterface"); -QML_DECLARE_INTERFACE(MyInterface); -QML_DEFINE_INTERFACE(MyInterface); - -class MyQmlObject : public QObject, public MyInterface, public QmlParserStatus -{ - Q_OBJECT - Q_PROPERTY(int value READ value WRITE setValue) - Q_PROPERTY(QString readOnlyString READ readOnlyString) - Q_PROPERTY(bool enabled READ enabled WRITE setEnabled) - Q_PROPERTY(QRect rect READ rect WRITE setRect) - Q_PROPERTY(QMatrix matrix READ matrix WRITE setMatrix) //assumed to be unsupported by QML - Q_PROPERTY(MyInterface *interface READ interface WRITE setInterface) - Q_INTERFACES(MyInterface QmlParserStatus) -public: - MyQmlObject() : m_value(-1), m_interface(0) {} - - int value() const { return m_value; } - void setValue(int v) { m_value = v; } - - QString readOnlyString() const { return QLatin1String(""); } - - bool enabled() const { return false; } - void setEnabled(bool) {} - - QRect rect() const { return QRect(); } - void setRect(const QRect&) {} - - QMatrix matrix() const { return QMatrix(); } - void setMatrix(const QMatrix&) {} - - MyInterface *interface() const { return m_interface; } - void setInterface(MyInterface *iface) { m_interface = iface; } - - static QObject *qmlAttachedProperties(QObject *other) { - MyQmlObject *rv = new MyQmlObject; - rv->setParent(other); - return rv; - } - Q_CLASSINFO("DefaultMethod", "basicSlot()"); - -public slots: - void basicSlot() { qWarning("MyQmlObject::basicSlot"); } - -signals: - void basicSignal(); - -private: - friend class tst_qmlparser; - int m_value; - MyInterface *m_interface; -}; - -QML_DECLARE_TYPE(MyQmlObject); -QML_DEFINE_TYPE(MyQmlObject,MyQmlObject); - -class MyTypeObject : public QObject -{ - Q_OBJECT - Q_ENUMS(MyEnum) - Q_FLAGS(MyFlags) - - Q_PROPERTY(QString id READ id WRITE setId); - Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty); - Q_PROPERTY(QmlComponent *componentProperty READ componentProperty WRITE setComponentProperty); - Q_PROPERTY(MyFlags flagProperty READ flagProperty WRITE setFlagProperty); - Q_PROPERTY(MyEnum enumProperty READ enumProperty WRITE setEnumProperty); - Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty); - Q_PROPERTY(uint uintProperty READ uintProperty WRITE setUintProperty); - Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty); - Q_PROPERTY(qreal realProperty READ realProperty WRITE setRealProperty); - Q_PROPERTY(double doubleProperty READ doubleProperty WRITE setDoubleProperty); - Q_PROPERTY(QColor colorProperty READ colorProperty WRITE setColorProperty); - Q_PROPERTY(QDate dateProperty READ dateProperty WRITE setDateProperty); - Q_PROPERTY(QTime timeProperty READ timeProperty WRITE setTimeProperty); - Q_PROPERTY(QDateTime dateTimeProperty READ dateTimeProperty WRITE setDateTimeProperty); - Q_PROPERTY(QPoint pointProperty READ pointProperty WRITE setPointProperty); - Q_PROPERTY(QPointF pointFProperty READ pointFProperty WRITE setPointFProperty); - Q_PROPERTY(QSize sizeProperty READ sizeProperty WRITE setSizeProperty); - Q_PROPERTY(QSizeF sizeFProperty READ sizeFProperty WRITE setSizeFProperty); - Q_PROPERTY(QRect rectProperty READ rectProperty WRITE setRectProperty); - Q_PROPERTY(QRectF rectFProperty READ rectFProperty WRITE setRectFProperty); - Q_PROPERTY(bool boolProperty READ boolProperty WRITE setBoolProperty); - Q_PROPERTY(QVariant variantProperty READ variantProperty WRITE setVariantProperty); - -public: - MyTypeObject() - : objectPropertyValue(0), componentPropertyValue(0) {} - - QString idValue; - QString id() const { - return idValue; - } - void setId(const QString &v) { - idValue = v; - } - - QObject *objectPropertyValue; - QObject *objectProperty() const { - return objectPropertyValue; - } - void setObjectProperty(QObject *v) { - objectPropertyValue = v; - } - - QmlComponent *componentPropertyValue; - QmlComponent *componentProperty() const { - return componentPropertyValue; - } - void setComponentProperty(QmlComponent *v) { - componentPropertyValue = v; - } - - enum MyFlag { FlagVal1 = 0x01, FlagVal2 = 0x02, FlagVal3 = 0x04 }; - Q_DECLARE_FLAGS(MyFlags, MyFlag) - MyFlags flagPropertyValue; - MyFlags flagProperty() const { - return flagPropertyValue; - } - void setFlagProperty(MyFlags v) { - flagPropertyValue = v; - } - - enum MyEnum { EnumVal1, EnumVal2 }; - MyEnum enumPropertyValue; - MyEnum enumProperty() const { - return enumPropertyValue; - } - void setEnumProperty(MyEnum v) { - enumPropertyValue = v; - } - - QString stringPropertyValue; - QString stringProperty() const { - return stringPropertyValue; - } - void setStringProperty(const QString &v) { - stringPropertyValue = v; - } - - uint uintPropertyValue; - uint uintProperty() const { - return uintPropertyValue; - } - void setUintProperty(const uint &v) { - uintPropertyValue = v; - } - - int intPropertyValue; - int intProperty() const { - return intPropertyValue; - } - void setIntProperty(const int &v) { - intPropertyValue = v; - } - - qreal realPropertyValue; - qreal realProperty() const { - return realPropertyValue; - } - void setRealProperty(const qreal &v) { - realPropertyValue = v; - } - - double doublePropertyValue; - double doubleProperty() const { - return doublePropertyValue; - } - void setDoubleProperty(const double &v) { - doublePropertyValue = v; - } - - QColor colorPropertyValue; - QColor colorProperty() const { - return colorPropertyValue; - } - void setColorProperty(const QColor &v) { - colorPropertyValue = v; - } - - QDate datePropertyValue; - QDate dateProperty() const { - return datePropertyValue; - } - void setDateProperty(const QDate &v) { - datePropertyValue = v; - } - - QTime timePropertyValue; - QTime timeProperty() const { - return timePropertyValue; - } - void setTimeProperty(const QTime &v) { - timePropertyValue = v; - } - - QDateTime dateTimePropertyValue; - QDateTime dateTimeProperty() const { - return dateTimePropertyValue; - } - void setDateTimeProperty(const QDateTime &v) { - dateTimePropertyValue = v; - } - - QPoint pointPropertyValue; - QPoint pointProperty() const { - return pointPropertyValue; - } - void setPointProperty(const QPoint &v) { - pointPropertyValue = v; - } - - QPointF pointFPropertyValue; - QPointF pointFProperty() const { - return pointFPropertyValue; - } - void setPointFProperty(const QPointF &v) { - pointFPropertyValue = v; - } - - QSize sizePropertyValue; - QSize sizeProperty() const { - return sizePropertyValue; - } - void setSizeProperty(const QSize &v) { - sizePropertyValue = v; - } - - QSizeF sizeFPropertyValue; - QSizeF sizeFProperty() const { - return sizeFPropertyValue; - } - void setSizeFProperty(const QSizeF &v) { - sizeFPropertyValue = v; - } - - QRect rectPropertyValue; - QRect rectProperty() const { - return rectPropertyValue; - } - void setRectProperty(const QRect &v) { - rectPropertyValue = v; - } - - QRectF rectFPropertyValue; - QRectF rectFProperty() const { - return rectFPropertyValue; - } - void setRectFProperty(const QRectF &v) { - rectFPropertyValue = v; - } - - bool boolPropertyValue; - bool boolProperty() const { - return boolPropertyValue; - } - void setBoolProperty(const bool &v) { - boolPropertyValue = v; - } - - QVariant variantPropertyValue; - QVariant variantProperty() const { - return variantPropertyValue; - } - void setVariantProperty(const QVariant &v) { - variantPropertyValue = v; - } -}; -Q_DECLARE_OPERATORS_FOR_FLAGS(MyTypeObject::MyFlags) - -QML_DECLARE_TYPE(MyTypeObject); -QML_DEFINE_TYPE(MyTypeObject,MyTypeObject); - -class MyContainer : public QObject -{ - Q_OBJECT - Q_PROPERTY(QList* children READ children) - Q_PROPERTY(QList* qlistInterfaces READ qlistInterfaces) - Q_PROPERTY(QmlList* qmllistInterfaces READ qmllistInterfaces) - Q_CLASSINFO("DefaultProperty", "children"); -public: - MyContainer() {} - - QList *children() { return &m_children; } - QList *qlistInterfaces() { return &m_interfaces; } - QmlList *qmllistInterfaces() { return &m_qmlinterfaces; } - const QmlConcreteList &qmllistAccessor() const { return m_qmlinterfaces; } - -private: - QList m_children; - QList m_interfaces; - QmlConcreteList m_qmlinterfaces; -}; - -QML_DECLARE_TYPE(MyContainer); -QML_DEFINE_TYPE(MyContainer,MyContainer); - -class MyPropertyValueSource : public QmlPropertyValueSource -{ - Q_OBJECT -public: - MyPropertyValueSource() - : QmlPropertyValueSource(0) {} - - QmlMetaProperty prop; - virtual void setTarget(const QmlMetaProperty &p) - { - prop = p; - } -}; -QML_DECLARE_TYPE(MyPropertyValueSource); -QML_DEFINE_TYPE(MyPropertyValueSource,MyPropertyValueSource); - -class MyDotPropertyObject : public QObject -{ - Q_OBJECT - Q_PROPERTY(MyQmlObject *obj READ obj) - Q_PROPERTY(MyQmlObject *readWriteObj READ readWriteObj WRITE setReadWriteObj) -public: - MyDotPropertyObject() : m_rwobj(0), m_ownRWObj(false) {} - ~MyDotPropertyObject() - { - if (m_ownRWObj) - delete m_rwobj; - } - - MyQmlObject *obj() { return 0; } - - MyQmlObject *readWriteObj() - { - if (!m_rwobj) { - m_rwobj = new MyQmlObject; - m_ownRWObj = true; - } - return m_rwobj; - } - - void setReadWriteObj(MyQmlObject *obj) - { - if (m_ownRWObj) { - delete m_rwobj; - m_ownRWObj = false; - } - - m_rwobj = obj; - } - -private: - MyQmlObject *m_rwobj; - bool m_ownRWObj; -}; - -QML_DECLARE_TYPE(MyDotPropertyObject); -QML_DEFINE_TYPE(MyDotPropertyObject,MyDotPropertyObject); +#include "testtypes.h" class tst_qmlparser : public QObject { @@ -384,6 +22,7 @@ private slots: void interfaceQmlList(); void interfaceQList(); void assignObjectToSignal(); + void assignLiteralSignalProperty(); void assignQmlComponent(); void assignBasicTypes(); void assignTypeExtremes(); @@ -556,6 +195,13 @@ void tst_qmlparser::assignObjectToSignal() emit object->basicSignal(); } +void tst_qmlparser::assignLiteralSignalProperty() +{ + QmlComponent component(&engine, TEST_FILE("assignLiteralSignalProperty.txt")); + MyQmlObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + QCOMPARE(object->onLiteralSignal(), 10); +} // Test is an external component can be loaded and assigned (to a qlist) void tst_qmlparser::assignQmlComponent() -- cgit v0.12 From 852f899318e6c50b46ece61c075846c266bd4107 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 13 May 2009 14:14:28 +1000 Subject: Remove AssignSignal instruction --- src/declarative/qml/qmlcompiler.cpp | 83 +++++++++++++++------- src/declarative/qml/qmlcompiler_p.h | 1 + src/declarative/qml/qmlinstruction.cpp | 3 - src/declarative/qml/qmlinstruction_p.h | 7 -- src/declarative/qml/qmlvme.cpp | 33 --------- .../declarative/qmlparser/missingSignal.errors.txt | 2 +- 6 files changed, 59 insertions(+), 70 deletions(-) diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index ed520c1..b205efb 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -725,51 +725,82 @@ bool QmlCompiler::compileFetchedObject(Object *obj, int ctxt) return true; } +int QmlCompiler::signalByName(const QMetaObject *mo, const QByteArray &name) +{ + int methods = mo->methodCount(); + for (int ii = methods - 1; ii >= 0; --ii) { + QMetaMethod method = mo->method(ii); + QByteArray methodName = method.signature(); + int idx = methodName.indexOf('('); + methodName = methodName.left(idx); + + if (methodName == name) + return ii; + } + return -1; +} + bool QmlCompiler::compileSignal(Property *prop, Object *obj) { + Q_ASSERT(obj->metaObject()); + if (prop->values.isEmpty() && !prop->value) return true; if (prop->value || prop->values.count() > 1) COMPILE_EXCEPTION("Incorrectly specified signal"); - if (prop->values.at(0)->object) { - int pr = output->indexForByteArray(prop->name); + QByteArray name = prop->name; + Q_ASSERT(name.startsWith("on")); + name = name.mid(2); + if(name[0] >= 'A' && name[0] <= 'Z') + name[0] = name[0] - 'A' + 'a'; - bool rv = compileObject(prop->values.at(0)->object, 0); + int sigIdx = signalByName(obj->metaObject(), name); - if (rv) { - QmlInstruction assign; - assign.type = QmlInstruction::AssignSignalObject; - assign.line = prop->values.at(0)->location.start.line; - assign.assignSignalObject.signal = pr; + if (sigIdx == -1) { - output->bytecode << assign; + COMPILE_CHECK(compileProperty(prop, obj, 0)); - prop->values.at(0)->type = Value::SignalObject; - } + } else { - return rv; + if (prop->values.at(0)->object) { + int pr = output->indexForByteArray(prop->name); - } else { - QString script = prop->values.at(0)->value.asScript().trimmed(); - if (script.isEmpty()) - return true; + bool rv = compileObject(prop->values.at(0)->object, 0); + + if (rv) { + QmlInstruction assign; + assign.type = QmlInstruction::AssignSignalObject; + assign.line = prop->values.at(0)->location.start.line; + assign.assignSignalObject.signal = pr; - int idx = output->indexForString(script); - int pr = output->indexForByteArray(prop->name); + output->bytecode << assign; - QmlInstruction assign; - assign.type = QmlInstruction::AssignSignal; - assign.line = prop->values.at(0)->location.start.line; - assign.assignSignal.signal = pr; - assign.assignSignal.value = idx; + prop->values.at(0)->type = Value::SignalObject; + } - output->bytecode << assign; + return rv; - prop->values.at(0)->type = Value::SignalExpression; - } + } else { + QString script = prop->values.at(0)->value.asScript().trimmed(); + if (script.isEmpty()) + return true; + int idx = output->indexForString(script); + + QmlInstruction store; + store.line = prop->values.at(0)->location.start.line; + store.type = QmlInstruction::StoreSignal; + store.storeSignal.signalIndex = sigIdx; + store.storeSignal.value = idx; + + output->bytecode << store; + + prop->values.at(0)->type = Value::SignalExpression; + } + } + return true; } diff --git a/src/declarative/qml/qmlcompiler_p.h b/src/declarative/qml/qmlcompiler_p.h index 246dd70..64400c5 100644 --- a/src/declarative/qml/qmlcompiler_p.h +++ b/src/declarative/qml/qmlcompiler_p.h @@ -139,6 +139,7 @@ private: bool compileFetchedObject(QmlParser::Object *obj, int); bool compileSignal(QmlParser::Property *prop, QmlParser::Object *obj); bool testProperty(QmlParser::Property *prop, QmlParser::Object *obj); + int signalByName(const QMetaObject *, const QByteArray &name); bool compileProperty(QmlParser::Property *prop, QmlParser::Object *obj, int); bool compileIdProperty(QmlParser::Property *prop, QmlParser::Object *obj); diff --git a/src/declarative/qml/qmlinstruction.cpp b/src/declarative/qml/qmlinstruction.cpp index 0617913..6b49359 100644 --- a/src/declarative/qml/qmlinstruction.cpp +++ b/src/declarative/qml/qmlinstruction.cpp @@ -127,9 +127,6 @@ void QmlCompiledComponent::dump(QmlInstruction *instr, int idx) case QmlInstruction::AssignConstant: qWarning() << idx << "\t" << line << "\t" << "ASSIGN_CONSTANT\t" << instr->assignConstant.property << "\t" << instr->assignConstant.constant << "\t\t" << datas.at(instr->assignConstant.property) << primitives.at(instr->assignConstant.constant); break; - case QmlInstruction::AssignSignal: - qWarning() << idx << "\t" << line << "\t" << "ASSIGN_SIGNAL\t\t" << instr->assignSignal.signal << "\t" << instr->assignSignal.value << "\t\t" << datas.at(instr->assignSignal.signal) << primitives.at(instr->assignSignal.value); - break; case QmlInstruction::AssignSignalObject: qWarning() << idx << "\t" << line << "\t" << "ASSIGN_SIGNAL_OBJECT\t" << instr->assignSignalObject.signal << "\t\t\t" << datas.at(instr->assignSignalObject.signal); break; diff --git a/src/declarative/qml/qmlinstruction_p.h b/src/declarative/qml/qmlinstruction_p.h index f465e9f..f06f0e6 100644 --- a/src/declarative/qml/qmlinstruction_p.h +++ b/src/declarative/qml/qmlinstruction_p.h @@ -112,10 +112,7 @@ public: // // AssignConstant - Store a value in a property. Will resolve into // a Store* instruction. - // AssignSignal - Set a signal handler on the property. Will resolve - // into a Store*Signal instruction. AssignConstant, /* assignConstant */ - AssignSignal, /* assignSignal */ AssignSignalObject, /* assignSignalObject */ AssignCustomType, /* assignCustomType */ @@ -273,10 +270,6 @@ public: } storeSignal; struct { int signal; - int value; - } assignSignal; - struct { - int signal; } assignSignalObject; struct { int count; diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp index dc9ef06..51534e7 100644 --- a/src/declarative/qml/qmlvme.cpp +++ b/src/declarative/qml/qmlvme.cpp @@ -88,7 +88,6 @@ Q_DECLARE_PERFORMANCE_LOG(QFxCompiler) { Q_DECLARE_PERFORMANCE_METRIC(InstrStoreSignal); Q_DECLARE_PERFORMANCE_METRIC(InstrStoreObjectQmlList); Q_DECLARE_PERFORMANCE_METRIC(InstrAssignConstant); - Q_DECLARE_PERFORMANCE_METRIC(InstrAssignSignal); Q_DECLARE_PERFORMANCE_METRIC(InstrAssignSignalObject); Q_DECLARE_PERFORMANCE_METRIC(InstrAssignBinding); Q_DECLARE_PERFORMANCE_METRIC(InstrAssignCompiledBinding); @@ -138,7 +137,6 @@ Q_DEFINE_PERFORMANCE_LOG(QFxCompiler, "QFxCompiler") { Q_DEFINE_PERFORMANCE_METRIC(InstrStoreSignal, "StoreSignal"); Q_DEFINE_PERFORMANCE_METRIC(InstrStoreObjectQmlList, "StoreObjectQmlList"); Q_DEFINE_PERFORMANCE_METRIC(InstrAssignConstant, "AssignConstant"); - Q_DEFINE_PERFORMANCE_METRIC(InstrAssignSignal, "AssignSignal"); Q_DEFINE_PERFORMANCE_METRIC(InstrAssignSignalObject, "AssignSignalObject"); Q_DEFINE_PERFORMANCE_METRIC(InstrAssignBinding, "AssignBinding"); Q_DEFINE_PERFORMANCE_METRIC(InstrAssignCompiledBinding, "AssignCompiledBinding"); @@ -356,37 +354,6 @@ QObject *QmlVME::run(QmlContext *ctxt, QmlCompiledComponent *comp, int start, in } break; - case QmlInstruction::AssignSignal: - { -#ifdef Q_ENABLE_PERFORMANCE_LOG - QFxCompilerTimer cc; -#endif - // Fixup instruction - QObject *target = stack.top(); - int sigIdx = instr.assignSignal.signal; - const QByteArray &pr = datas.at(sigIdx); - - QmlMetaProperty prop(target, QLatin1String(pr)); - if (prop.type() & QmlMetaProperty::SignalProperty) { - int coreIdx = prop.coreIndex(); - int primRef = instr.assignSignal.value; - instr.type = QmlInstruction::StoreSignal; - instr.storeSignal.signalIndex = coreIdx; - instr.storeSignal.value = primRef; - --ii; - } else if (prop.type() & QmlMetaProperty::Property) { - int prop = sigIdx; - int primRef = instr.assignSignal.value; - instr.type = QmlInstruction::AssignConstant; - instr.assignConstant.property = prop; - instr.assignConstant.constant = primRef; - --ii; - } else { - VME_EXCEPTION("Cannot assign a signal to property" << pr); - } - } - break; - case QmlInstruction::AssignSignalObject: { #ifdef Q_ENABLE_PERFORMANCE_LOG diff --git a/tests/auto/declarative/qmlparser/missingSignal.errors.txt b/tests/auto/declarative/qmlparser/missingSignal.errors.txt index 8ae1bbe4..9815b99 100644 --- a/tests/auto/declarative/qmlparser/missingSignal.errors.txt +++ b/tests/auto/declarative/qmlparser/missingSignal.errors.txt @@ -1 +1 @@ -2:-1:Cannot assign a signal to property "onClicked" +2:-1:Unknown property "onClicked" -- cgit v0.12 From c8ecc6c73065b0cef11b5d3e3f53af6d9ac60c7d Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 14 May 2009 12:40:43 +1000 Subject: Fixup gcov lib lines --- src/declarative/declarative.pro | 1 + tests/auto/declarative/qmlparser/qmlparser.pro | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/declarative/declarative.pro b/src/declarative/declarative.pro index e960f0f..0c51fc3 100644 --- a/src/declarative/declarative.pro +++ b/src/declarative/declarative.pro @@ -10,6 +10,7 @@ solaris-cc*:QMAKE_CXXFLAGS_RELEASE -= -O2 unix:QMAKE_PKGCONFIG_REQUIRES = QtCore QtGui QtXml # QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage +# LIBS += -lgcov include(../qbase.pri) diff --git a/tests/auto/declarative/qmlparser/qmlparser.pro b/tests/auto/declarative/qmlparser/qmlparser.pro index b2fc490..dda5c61 100644 --- a/tests/auto/declarative/qmlparser/qmlparser.pro +++ b/tests/auto/declarative/qmlparser/qmlparser.pro @@ -6,4 +6,4 @@ HEADERS = testtypes.h macx:CONFIG -= app_bundle # QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage -LIBS += -lgcov +# LIBS += -lgcov -- cgit v0.12 From 46e7c3f7132aac3838bca4510675f8ad7f70a115 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 14 May 2009 13:10:22 +1000 Subject: Custom string converter test --- .../declarative/qmlparser/customVariantTypes.txt | 3 +++ tests/auto/declarative/qmlparser/testtypes.h | 20 +++++++++++++++++++- tests/auto/declarative/qmlparser/tst_qmlparser.cpp | 14 +++++++++++++- 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 tests/auto/declarative/qmlparser/customVariantTypes.txt diff --git a/tests/auto/declarative/qmlparser/customVariantTypes.txt b/tests/auto/declarative/qmlparser/customVariantTypes.txt new file mode 100644 index 0000000..dc5031e --- /dev/null +++ b/tests/auto/declarative/qmlparser/customVariantTypes.txt @@ -0,0 +1,3 @@ +MyQmlObject { + customType: "10" +} diff --git a/tests/auto/declarative/qmlparser/testtypes.h b/tests/auto/declarative/qmlparser/testtypes.h index 190611f..0dc91b2 100644 --- a/tests/auto/declarative/qmlparser/testtypes.h +++ b/tests/auto/declarative/qmlparser/testtypes.h @@ -19,6 +19,20 @@ public: Q_DECLARE_INTERFACE(MyInterface, "com.trolltech.Qt.Test.MyInterface"); QML_DECLARE_INTERFACE(MyInterface); +struct MyCustomVariantType +{ + MyCustomVariantType() : a(0) {} + int a; +}; +Q_DECLARE_METATYPE(MyCustomVariantType); + +static QVariant myCustomVariantTypeConverter(const QString &data) +{ + MyCustomVariantType rv; + rv.a = data.toInt(); + return QVariant::fromValue(rv); +} + class MyQmlObject : public QObject, public MyInterface, public QmlParserStatus { Q_OBJECT @@ -29,9 +43,10 @@ class MyQmlObject : public QObject, public MyInterface, public QmlParserStatus Q_PROPERTY(QMatrix matrix READ matrix WRITE setMatrix) //assumed to be unsupported by QML Q_PROPERTY(MyInterface *interface READ interface WRITE setInterface) Q_PROPERTY(int onLiteralSignal READ onLiteralSignal WRITE setOnLiteralSignal); + Q_PROPERTY(MyCustomVariantType customType READ customType WRITE setCustomType); Q_INTERFACES(MyInterface QmlParserStatus) public: - MyQmlObject() : m_value(-1), m_interface(0) {} + MyQmlObject() : m_value(-1), m_interface(0) { qRegisterMetaType("MyCustomVariantType"); } int value() const { return m_value; } void setValue(int v) { m_value = v; } @@ -60,6 +75,8 @@ public: int onLiteralSignal() const { return m_value; } void setOnLiteralSignal(int v) { m_value = v; } + MyCustomVariantType customType() const { return m_custom; } + void setCustomType(const MyCustomVariantType &v) { m_custom = v; } public slots: void basicSlot() { qWarning("MyQmlObject::basicSlot"); } @@ -70,6 +87,7 @@ private: friend class tst_qmlparser; int m_value; MyInterface *m_interface; + MyCustomVariantType m_custom; }; QML_DECLARE_TYPE(MyQmlObject); diff --git a/tests/auto/declarative/qmlparser/tst_qmlparser.cpp b/tests/auto/declarative/qmlparser/tst_qmlparser.cpp index 5af75c4..65ee5e2 100644 --- a/tests/auto/declarative/qmlparser/tst_qmlparser.cpp +++ b/tests/auto/declarative/qmlparser/tst_qmlparser.cpp @@ -9,7 +9,9 @@ class tst_qmlparser : public QObject { Q_OBJECT public: - tst_qmlparser() {} + tst_qmlparser() { + QmlMetaType::registerCustomStringConverter(qMetaTypeId(), myCustomVariantTypeConverter); + } private slots: @@ -38,6 +40,7 @@ private slots: void propertyValueSource(); void attachedProperties(); void dynamicObjects(); + void customVariantTypes(); // regression tests for crashes void crash1(); @@ -398,6 +401,15 @@ void tst_qmlparser::dynamicObjects() QVERIFY(object != 0); } +// Tests the registration of custom variant string converters +void tst_qmlparser::customVariantTypes() +{ + QmlComponent component(&engine, TEST_FILE("customVariantTypes.txt")); + MyQmlObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + QCOMPARE(object->customType().a, 10); +} + void tst_qmlparser::crash1() { QmlComponent component(&engine, "Component {}"); -- cgit v0.12 From 514fff516a1b4a6f2cb0d648c5fcfa29514ea211 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 14 May 2009 13:12:32 +1000 Subject: Add gcov flags --- tests/auto/declarative/qmlbindengine/qmlbindengine.pro | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/auto/declarative/qmlbindengine/qmlbindengine.pro b/tests/auto/declarative/qmlbindengine/qmlbindengine.pro index 6d84931..800d9a0 100644 --- a/tests/auto/declarative/qmlbindengine/qmlbindengine.pro +++ b/tests/auto/declarative/qmlbindengine/qmlbindengine.pro @@ -1,3 +1,7 @@ load(qttest_p4) contains(QT_CONFIG,declarative): QT += declarative +macx:CONFIG -= app_bundle SOURCES += tst_qmlbindengine.cpp + +# QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage +# LIBS += -lgcov -- cgit v0.12 From 875c4af96f094dad9158d77e926049dbf9a75475 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 14 May 2009 13:38:20 +1000 Subject: GridView shall not crash when given a broken delegate. --- src/declarative/fx/qfxgridview.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp index 5156d06..e745b24 100644 --- a/src/declarative/fx/qfxgridview.cpp +++ b/src/declarative/fx/qfxgridview.cpp @@ -409,7 +409,8 @@ void QFxGridViewPrivate::refill(qreal from, qreal to) FxGridItem *item = 0; while (modelIndex < model->count() && rowPos <= to) { //qDebug() << "refill: append item" << modelIndex; - item = getItem(modelIndex); + if (!(item = getItem(modelIndex))) + break; item->setPosition(colPos, rowPos); visibleItems.append(item); colPos += colSize(); @@ -431,7 +432,8 @@ void QFxGridViewPrivate::refill(qreal from, qreal to) } while (visibleIndex > 0 && rowPos + rowSize() - 1 >= from){ //qDebug() << "refill: prepend item" << visibleIndex-1 << "top pos" << rowPos << colPos; - item = getItem(visibleIndex-1); + if (!(item = getItem(visibleIndex-1))) + break; --visibleIndex; item->setPosition(colPos, rowPos); visibleItems.prepend(item); @@ -629,14 +631,17 @@ void QFxGridViewPrivate::updateCurrent(int modelIndex) currentItem = visibleItem(modelIndex); if (!currentItem) { currentItem = getItem(modelIndex); - currentItem->setPosition(colPosAt(modelIndex), rowPosAt(modelIndex)); + if (currentItem) + currentItem->setPosition(colPosAt(modelIndex), rowPosAt(modelIndex)); } currentIndex = modelIndex; fixCurrentVisibility = true; - if (oldCurrentItem && oldCurrentItem->item != currentItem->item) + if (oldCurrentItem && (!currentItem || oldCurrentItem->item != currentItem->item)) oldCurrentItem->attached->setIsCurrentItem(false); - currentItem->item->setFocus(true); - currentItem->attached->setIsCurrentItem(true); + if (currentItem) { + currentItem->item->setFocus(true); + currentItem->attached->setIsCurrentItem(true); + } updateHighlight(); emit q->currentIndexChanged(); // Release the old current item -- cgit v0.12 From 8ac395b4293433d3d98e4e8d9825f86d6a351d69 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 14 May 2009 13:38:25 +1000 Subject: Cleanup testcase --- .../auto/declarative/qmlbindengine/bindingLoop.txt | 12 ++++++++++++ .../boolPropertiesEvaluateAsBool.1.txt | 3 +++ .../boolPropertiesEvaluateAsBool.2.txt | 3 +++ tests/auto/declarative/qmlbindengine/methods.1.txt | 4 ++++ tests/auto/declarative/qmlbindengine/methods.2.txt | 4 ++++ .../qmlbindengine/signalAssignment.1.txt | 3 +++ .../qmlbindengine/signalAssignment.2.txt | 3 +++ .../qmlbindengine/tst_qmlbindengine.cpp | 22 +++++++++++----------- 8 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 tests/auto/declarative/qmlbindengine/bindingLoop.txt create mode 100644 tests/auto/declarative/qmlbindengine/boolPropertiesEvaluateAsBool.1.txt create mode 100644 tests/auto/declarative/qmlbindengine/boolPropertiesEvaluateAsBool.2.txt create mode 100644 tests/auto/declarative/qmlbindengine/methods.1.txt create mode 100644 tests/auto/declarative/qmlbindengine/methods.2.txt create mode 100644 tests/auto/declarative/qmlbindengine/signalAssignment.1.txt create mode 100644 tests/auto/declarative/qmlbindengine/signalAssignment.2.txt diff --git a/tests/auto/declarative/qmlbindengine/bindingLoop.txt b/tests/auto/declarative/qmlbindengine/bindingLoop.txt new file mode 100644 index 0000000..e27a76c --- /dev/null +++ b/tests/auto/declarative/qmlbindengine/bindingLoop.txt @@ -0,0 +1,12 @@ +MyQmlContainer { + children : [ + MyQmlObject { + id: Object1 + stringProperty: "hello" + Object2.stringProperty + }, + MyQmlObject { + id: Object2 + stringProperty: "hello" + Object1.stringProperty + } + ] +} diff --git a/tests/auto/declarative/qmlbindengine/boolPropertiesEvaluateAsBool.1.txt b/tests/auto/declarative/qmlbindengine/boolPropertiesEvaluateAsBool.1.txt new file mode 100644 index 0000000..7368ff6 --- /dev/null +++ b/tests/auto/declarative/qmlbindengine/boolPropertiesEvaluateAsBool.1.txt @@ -0,0 +1,3 @@ +MyQmlObject { + stringProperty: trueProperty?'pass':'fail' +} diff --git a/tests/auto/declarative/qmlbindengine/boolPropertiesEvaluateAsBool.2.txt b/tests/auto/declarative/qmlbindengine/boolPropertiesEvaluateAsBool.2.txt new file mode 100644 index 0000000..c74493e --- /dev/null +++ b/tests/auto/declarative/qmlbindengine/boolPropertiesEvaluateAsBool.2.txt @@ -0,0 +1,3 @@ +MyQmlObject { + stringProperty: falseProperty?'fail':'pass' +} diff --git a/tests/auto/declarative/qmlbindengine/methods.1.txt b/tests/auto/declarative/qmlbindengine/methods.1.txt new file mode 100644 index 0000000..35279e0 --- /dev/null +++ b/tests/auto/declarative/qmlbindengine/methods.1.txt @@ -0,0 +1,4 @@ +MyQmlObject { + id: MyObject + onBasicSignal: MyObject.method() +} diff --git a/tests/auto/declarative/qmlbindengine/methods.2.txt b/tests/auto/declarative/qmlbindengine/methods.2.txt new file mode 100644 index 0000000..352913a --- /dev/null +++ b/tests/auto/declarative/qmlbindengine/methods.2.txt @@ -0,0 +1,4 @@ +MyQmlObject { + id: MyObject + onBasicSignal: MyObject.method(163) +} diff --git a/tests/auto/declarative/qmlbindengine/signalAssignment.1.txt b/tests/auto/declarative/qmlbindengine/signalAssignment.1.txt new file mode 100644 index 0000000..ca682fa --- /dev/null +++ b/tests/auto/declarative/qmlbindengine/signalAssignment.1.txt @@ -0,0 +1,3 @@ +MyQmlObject { + onBasicSignal: setString('pass') +} diff --git a/tests/auto/declarative/qmlbindengine/signalAssignment.2.txt b/tests/auto/declarative/qmlbindengine/signalAssignment.2.txt new file mode 100644 index 0000000..5efd583 --- /dev/null +++ b/tests/auto/declarative/qmlbindengine/signalAssignment.2.txt @@ -0,0 +1,3 @@ +MyQmlObject { + onArgumentSignal: setString('pass ' + a + ' ' + b + ' ' + c) +} diff --git a/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp b/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp index 9a14abb..251bce4 100644 --- a/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp +++ b/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp @@ -66,6 +66,9 @@ private: QML_DECLARE_TYPE(MyQmlContainer); QML_DEFINE_TYPE(MyQmlContainer,MyQmlContainer); +#define TEST_FILE(filename) \ + QUrl::fromLocalFile(QApplication::applicationDirPath() + "/" + filename) + class tst_qmlbindengine : public QObject { Q_OBJECT @@ -86,13 +89,13 @@ private: void tst_qmlbindengine::boolPropertiesEvaluateAsBool() { { - QmlComponent component(&engine, "MyQmlObject { stringProperty: trueProperty?'pass':'fail' }"); + QmlComponent component(&engine, TEST_FILE("boolPropertiesEvaluateAsBool.1.txt")); MyQmlObject *object = qobject_cast(component.create()); QVERIFY(object != 0); QCOMPARE(object->stringProperty(), QLatin1String("pass")); } { - QmlComponent component(&engine, "MyQmlObject { stringProperty: falseProperty?'fail':'pass' }"); + QmlComponent component(&engine, TEST_FILE("boolPropertiesEvaluateAsBool.2.txt")); MyQmlObject *object = qobject_cast(component.create()); QVERIFY(object != 0); QCOMPARE(object->stringProperty(), QLatin1String("pass")); @@ -102,7 +105,7 @@ void tst_qmlbindengine::boolPropertiesEvaluateAsBool() void tst_qmlbindengine::signalAssignment() { { - QmlComponent component(&engine, "MyQmlObject { onBasicSignal: setString('pass') }"); + QmlComponent component(&engine, TEST_FILE("signalAssignment.1.txt")); MyQmlObject *object = qobject_cast(component.create()); QVERIFY(object != 0); QCOMPARE(object->string(), QString()); @@ -111,7 +114,7 @@ void tst_qmlbindengine::signalAssignment() } { - QmlComponent component(&engine, "MyQmlObject { onArgumentSignal: setString('pass ' + a + ' ' + b + ' ' + c) }"); + QmlComponent component(&engine, TEST_FILE("signalAssignment.2.txt")); MyQmlObject *object = qobject_cast(component.create()); QVERIFY(object != 0); QCOMPARE(object->string(), QString()); @@ -123,7 +126,7 @@ void tst_qmlbindengine::signalAssignment() void tst_qmlbindengine::methods() { { - QmlComponent component(&engine, "MyQmlObject { id: MyObject; onBasicSignal: MyObject.method() }"); + QmlComponent component(&engine, TEST_FILE("methods.1.txt")); MyQmlObject *object = qobject_cast(component.create()); QVERIFY(object != 0); QCOMPARE(object->methodCalled(), false); @@ -134,7 +137,7 @@ void tst_qmlbindengine::methods() } { - QmlComponent component(&engine, "MyQmlObject { id: MyObject; onBasicSignal: MyObject.method(163) }"); + QmlComponent component(&engine, TEST_FILE("methods.2.txt")); MyQmlObject *object = qobject_cast(component.create()); QVERIFY(object != 0); QCOMPARE(object->methodCalled(), false); @@ -147,11 +150,8 @@ void tst_qmlbindengine::methods() void tst_qmlbindengine::bindingLoop() { - QmlComponent component(&engine, "MyQmlContainer { children : [ "\ - "MyQmlObject { id: Object1; stringProperty: \"hello\" + Object2.stringProperty }, "\ - "MyQmlObject { id: Object2; stringProperty: \"hello\" + Object1.stringProperty } ] }"); - //### ignoreMessage doesn't seem to work here - //QTest::ignoreMessage(QtWarningMsg, "QML MyQmlObject (unknown location): Binding loop detected for property \"stringProperty\""); + QmlComponent component(&engine, TEST_FILE("bindingLoop.txt")); + QTest::ignoreMessage(QtWarningMsg, "QML MyQmlObject (unknown location): Binding loop detected for property \"stringProperty\" "); QObject *object = component.create(); QVERIFY(object != 0); } -- cgit v0.12 From b1008e6a4f660866265083f6f4bd321a85cff377 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 14 May 2009 14:12:29 +1000 Subject: Add some expression tests --- .../qmlbindengine/tst_qmlbindengine.cpp | 95 ++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp b/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp index 251bce4..72c8953 100644 --- a/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp +++ b/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp @@ -80,6 +80,8 @@ private slots: void methods(); void signalAssignment(); void bindingLoop(); + void basicExpressions(); + void basicExpressions_data(); void contextPropertiesTriggerReeval(); private: @@ -170,6 +172,99 @@ public: bool changed; }; + +class MyDefaultObject1 : public QObject +{ + Q_OBJECT + Q_PROPERTY(int horseLegs READ horseLegs); + Q_PROPERTY(int antLegs READ antLegs); +public: + int horseLegs() const { return 4; } + int antLegs() const { return 6; } +}; + +class MyDefaultObject2 : public QObject +{ + Q_OBJECT + Q_PROPERTY(int antLegs READ antLegs); + Q_PROPERTY(int emuLegs READ emuLegs); +public: + int antLegs() const { return 5; } // Had an accident + int emuLegs() const { return 2; } +}; + +class MyDefaultObject3 : public QObject +{ + Q_OBJECT + Q_PROPERTY(int antLegs READ antLegs); + Q_PROPERTY(int humanLegs READ humanLegs); +public: + int antLegs() const { return 7; } // Mutant + int humanLegs() const { return 2; } + int millipedeLegs() const { return 1000; } +}; + +void tst_qmlbindengine::basicExpressions_data() +{ + QTest::addColumn("expression"); + QTest::addColumn("result"); + QTest::addColumn("nest"); + + QTest::newRow("Context property") << "a" << QVariant(1944) << false; + QTest::newRow("Context property") << "a" << QVariant(1944) << true; + QTest::newRow("Context property expression") << "a * 2" << QVariant(3888) << false; + QTest::newRow("Context property expression") << "a * 2" << QVariant(3888) << true; + QTest::newRow("Overridden context property") << "b" << QVariant("Milk") << false; + QTest::newRow("Overridden context property") << "b" << QVariant("Cow") << true; + QTest::newRow("Object property") << "object.stringProperty" << QVariant("Object1") << false; + QTest::newRow("Object property") << "object.stringProperty" << QVariant("Object1") << true; + QTest::newRow("Overridden object property") << "objectOverride.stringProperty" << QVariant("Object2") << false; + QTest::newRow("Overridden object property") << "objectOverride.stringProperty" << QVariant("Object3") << true; + QTest::newRow("Default object property") << "horseLegs" << QVariant(4) << false; + QTest::newRow("Default object property") << "antLegs" << QVariant(6) << false; + QTest::newRow("Default object property") << "emuLegs" << QVariant(2) << false; + QTest::newRow("Nested default object property") << "horseLegs" << QVariant(4) << true; + QTest::newRow("Nested default object property") << "antLegs" << QVariant(7) << true; + QTest::newRow("Nested default object property") << "emuLegs" << QVariant(2) << true; + QTest::newRow("Nested default object property") << "humanLegs" << QVariant(2) << true; + QTest::newRow("Context property override default object property") << "millipedeLegs" << QVariant(100) << true; +} + +void tst_qmlbindengine::basicExpressions() +{ + QFETCH(QString, expression); + QFETCH(QVariant, result); + QFETCH(bool, nest); + + MyQmlObject object1; + MyQmlObject object2; + MyQmlObject object3; + MyDefaultObject1 default1; + MyDefaultObject2 default2; + MyDefaultObject3 default3; + object1.setStringProperty("Object1"); + object2.setStringProperty("Object2"); + object3.setStringProperty("Object3"); + + QmlContext context(engine.rootContext()); + QmlContext nestedContext(&context); + + context.addDefaultObject(&default1); + context.addDefaultObject(&default2); + context.setContextProperty("a", QVariant(1944)); + context.setContextProperty("b", QVariant("Milk")); + context.setContextProperty("object", &object1); + context.setContextProperty("objectOverride", &object2); + nestedContext.addDefaultObject(&default3); + nestedContext.setContextProperty("b", QVariant("Cow")); + nestedContext.setContextProperty("objectOverride", &object3); + nestedContext.setContextProperty("millipedeLegs", QVariant(100)); + + MyExpression expr(nest?&nestedContext:&context, expression); + QCOMPARE(expr.value(), result); +} + +// Tests that modifying a context property will reevaluate expressions void tst_qmlbindengine::contextPropertiesTriggerReeval() { QmlContext context(engine.rootContext()); -- cgit v0.12 From 309e8a96af899c612ea26b73fc97d9d377bc9819 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 14 May 2009 15:41:14 +1000 Subject: Flickr demo: Scale the image about the center of the visible area. --- demos/declarative/flickr/content/ImageDetails.qml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/demos/declarative/flickr/content/ImageDetails.qml b/demos/declarative/flickr/content/ImageDetails.qml index d575be9..b8091f2 100644 --- a/demos/declarative/flickr/content/ImageDetails.qml +++ b/demos/declarative/flickr/content/ImageDetails.qml @@ -12,6 +12,7 @@ Flipable { property string photoDate property string photoUrl property int rating: 2 + property var prevScale: 1.0 signal closed @@ -93,7 +94,8 @@ Flipable { // Default scale shows the entire image. if (status == 0 && width != 0) { Slider.minimum = Math.min(Flick.width / width, Flick.height / height); - Slider.value = Math.min(Slider.minimum, 1); + prevScale = Math.min(Slider.minimum, 1); + Slider.value = prevScale; } } } @@ -109,7 +111,20 @@ Flipable { anchors.centeredIn: parent; color: "white"; font.bold: true } - Slider { id: Slider; x: 25; y: 374; visible: { BigImage.status == 0 && maximum > minimum } } + Slider { + id: Slider; x: 25; y: 374; visible: { BigImage.status == 0 && maximum > minimum } + onValueChanged: { + if (BigImage.width * value > Flick.width) { + var xoff = (Flick.width/2 + Flick.xPosition) * value / prevScale; + Flick.xPosition = xoff - Flick.width/2; + } + if (BigImage.height * value > Flick.height) { + var yoff = (Flick.height/2 + Flick.yPosition) * value / prevScale; + Flick.yPosition = yoff - Flick.height/2; + } + prevScale = value; + } + } } states: [ -- cgit v0.12