From 113a5ee20d682e3377634854571554b8af7cf4ae Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 25 Aug 2010 10:52:06 +1000 Subject: Document calling QObject methods from QML in Extending QML in C++ docs. --- doc/src/declarative/extending.qdoc | 17 +++++ doc/src/examples/qml-examples.qdoc | 1 + doc/src/examples/qml-extending.qdoc | 14 ++++ .../referenceexamples/methods/birthdayparty.cpp | 80 ++++++++++++++++++++++ .../referenceexamples/methods/birthdayparty.h | 71 +++++++++++++++++++ .../referenceexamples/methods/example.qml | 58 ++++++++++++++++ .../referenceexamples/methods/main.cpp | 68 ++++++++++++++++++ .../referenceexamples/methods/methods.pro | 18 +++++ .../referenceexamples/methods/methods.qrc | 5 ++ .../referenceexamples/methods/person.cpp | 66 ++++++++++++++++++ .../referenceexamples/methods/person.h | 63 +++++++++++++++++ .../referenceexamples/referenceexamples.pro | 3 +- 12 files changed, 463 insertions(+), 1 deletion(-) create mode 100644 examples/declarative/cppextensions/referenceexamples/methods/birthdayparty.cpp create mode 100644 examples/declarative/cppextensions/referenceexamples/methods/birthdayparty.h create mode 100644 examples/declarative/cppextensions/referenceexamples/methods/example.qml create mode 100644 examples/declarative/cppextensions/referenceexamples/methods/main.cpp create mode 100644 examples/declarative/cppextensions/referenceexamples/methods/methods.pro create mode 100644 examples/declarative/cppextensions/referenceexamples/methods/methods.qrc create mode 100644 examples/declarative/cppextensions/referenceexamples/methods/person.cpp create mode 100644 examples/declarative/cppextensions/referenceexamples/methods/person.h diff --git a/doc/src/declarative/extending.qdoc b/doc/src/declarative/extending.qdoc index 3acfbdf..5c4d5e7 100644 --- a/doc/src/declarative/extending.qdoc +++ b/doc/src/declarative/extending.qdoc @@ -434,6 +434,23 @@ NOTIFY signal in C++. See also \l {Extending types from QML}. +\section1 Methods + +Slots and methods marked Q_INVOKABLE may be called as functions in QML. + +\snippet examples/declarative/cppextensions/referenceexamples/methods/example.qml 0 + +In this example an invitation is added via an \c {invite()} invokable method of +the BirthdayParty element. This function is available in QML by marking the \c {invite()} +method with Q_INVOKABLE in the BirthdayParty class: + +\snippet examples/declarative/cppextensions/referenceexamples/methods/birthdayparty.h 0 + +\l {Extending QML - Methods Example} shows the complete code used to +implement the invite() method. + +The \c {invite()} method is similarly available if it is declared as a slot. + \section1 Property Value Sources \snippet examples/declarative/cppextensions/referenceexamples/valuesource/example.qml 0 diff --git a/doc/src/examples/qml-examples.qdoc b/doc/src/examples/qml-examples.qdoc index 0d191c9..b140562 100644 --- a/doc/src/examples/qml-examples.qdoc +++ b/doc/src/examples/qml-examples.qdoc @@ -137,6 +137,7 @@ \o \l {declarative/cppextensions/referenceexamples/grouped}{Grouped Properties} \o \l {declarative/cppextensions/referenceexamples/attached}{Attached Properties} \o \l {declarative/cppextensions/referenceexamples/signal}{Signal Support} + \o \l {declarative/cppextensions/referenceexamples/methods}{Methods Support} \o \l {declarative/cppextensions/referenceexamples/valuesource}{Property Value Source} \o \l {declarative/cppextensions/referenceexamples/binding}{Binding} \endlist diff --git a/doc/src/examples/qml-extending.qdoc b/doc/src/examples/qml-extending.qdoc index b419fe4..21ec3bb 100644 --- a/doc/src/examples/qml-extending.qdoc +++ b/doc/src/examples/qml-extending.qdoc @@ -253,6 +253,20 @@ This example builds on: */ /*! +\example declarative/cppextensions/referenceexamples/methods +\title Extending QML - Methods Example + +This example builds on: +\list +\o \l {Extending QML - Default Property Example} +\o \l {Extending QML - Inheritance and Coercion Example} +\o \l {Extending QML - Object and List Property Types Example} +\o \l {Extending QML - Adding Types Example} +\endlist + +*/ + +/*! \example declarative/cppextensions/referenceexamples/valuesource \title Extending QML - Property Value Source Example diff --git a/examples/declarative/cppextensions/referenceexamples/methods/birthdayparty.cpp b/examples/declarative/cppextensions/referenceexamples/methods/birthdayparty.cpp new file mode 100644 index 0000000..801c7ba --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/methods/birthdayparty.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "birthdayparty.h" + +BirthdayParty::BirthdayParty(QObject *parent) +: QObject(parent), m_host(0) +{ +} + +// ![0] +Person *BirthdayParty::host() const +{ + return m_host; +} + +void BirthdayParty::setHost(Person *c) +{ + m_host = c; +} + +QDeclarativeListProperty BirthdayParty::guests() +{ + return QDeclarativeListProperty(this, m_guests); +} + +int BirthdayParty::guestCount() const +{ + return m_guests.count(); +} + +Person *BirthdayParty::guest(int index) const +{ + return m_guests.at(index); +} + +void BirthdayParty::invite(const QString &name) +{ + Person *person = new Person(this); + person->setName(name); + m_guests.append(person); +} +// ![0] + diff --git a/examples/declarative/cppextensions/referenceexamples/methods/birthdayparty.h b/examples/declarative/cppextensions/referenceexamples/methods/birthdayparty.h new file mode 100644 index 0000000..b89a30e --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/methods/birthdayparty.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef BIRTHDAYPARTY_H +#define BIRTHDAYPARTY_H + +#include +#include +#include "person.h" + +class BirthdayParty : public QObject +{ + Q_OBJECT + Q_PROPERTY(Person *host READ host WRITE setHost) + Q_PROPERTY(QDeclarativeListProperty guests READ guests) +public: + BirthdayParty(QObject *parent = 0); + + Person *host() const; + void setHost(Person *); + + QDeclarativeListProperty guests(); + int guestCount() const; + Person *guest(int) const; + +// ![0] + Q_INVOKABLE void invite(const QString &name); +// ![0] + +private: + Person *m_host; + QList m_guests; +}; + +#endif // BIRTHDAYPARTY_H diff --git a/examples/declarative/cppextensions/referenceexamples/methods/example.qml b/examples/declarative/cppextensions/referenceexamples/methods/example.qml new file mode 100644 index 0000000..c4698a2 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/methods/example.qml @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt 4.7 +import People 1.0 + +// ![0] +BirthdayParty { + host: Person { + name: "Bob Jones" + shoeSize: 12 + } + guests: [ + Person { name: "Leo Hodges" }, + Person { name: "Jack Smith" }, + Person { name: "Anne Brown" } + ] + + Component.onCompleted: invite("William Green") +} +// ![0] diff --git a/examples/declarative/cppextensions/referenceexamples/methods/main.cpp b/examples/declarative/cppextensions/referenceexamples/methods/main.cpp new file mode 100644 index 0000000..d974647 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/methods/main.cpp @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include +#include "birthdayparty.h" +#include "person.h" + +int main(int argc, char ** argv) +{ + QCoreApplication app(argc, argv); + + qmlRegisterType("People", 1,0, "BirthdayParty"); + qmlRegisterType("People", 1,0, "Person"); + + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, QUrl("qrc:example.qml")); + BirthdayParty *party = qobject_cast(component.create()); + + if (party && party->host()) { + qWarning() << party->host()->name() << "is having a birthday!"; + qWarning() << "They are inviting:"; + for (int ii = 0; ii < party->guestCount(); ++ii) + qWarning() << " " << party->guest(ii)->name(); + } else { + qWarning() << component.errors(); + } + + return 0; +} diff --git a/examples/declarative/cppextensions/referenceexamples/methods/methods.pro b/examples/declarative/cppextensions/referenceexamples/methods/methods.pro new file mode 100644 index 0000000..a62927e --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/methods/methods.pro @@ -0,0 +1,18 @@ +TEMPLATE = app +TARGET = methods +DEPENDPATH += . +INCLUDEPATH += . +QT += declarative + +# Input +SOURCES += main.cpp \ + person.cpp \ + birthdayparty.cpp +HEADERS += person.h \ + birthdayparty.h +RESOURCES += methods.qrc + +target.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/methods +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS methods.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/methods +INSTALLS += target sources diff --git a/examples/declarative/cppextensions/referenceexamples/methods/methods.qrc b/examples/declarative/cppextensions/referenceexamples/methods/methods.qrc new file mode 100644 index 0000000..e2fa01d --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/methods/methods.qrc @@ -0,0 +1,5 @@ + + + example.qml + + diff --git a/examples/declarative/cppextensions/referenceexamples/methods/person.cpp b/examples/declarative/cppextensions/referenceexamples/methods/person.cpp new file mode 100644 index 0000000..beffe78 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/methods/person.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "person.h" + +Person::Person(QObject *parent) +: QObject(parent), m_shoeSize(0) +{ +} + +QString Person::name() const +{ + return m_name; +} + +void Person::setName(const QString &n) +{ + m_name = n; +} + +int Person::shoeSize() const +{ + return m_shoeSize; +} + +void Person::setShoeSize(int s) +{ + m_shoeSize = s; +} + diff --git a/examples/declarative/cppextensions/referenceexamples/methods/person.h b/examples/declarative/cppextensions/referenceexamples/methods/person.h new file mode 100644 index 0000000..8c950da --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/methods/person.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef PERSON_H +#define PERSON_H + +#include + +class Person : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize) +public: + Person(QObject *parent = 0); + + QString name() const; + void setName(const QString &); + + int shoeSize() const; + void setShoeSize(int); +private: + QString m_name; + int m_shoeSize; +}; + +#endif // PERSON_H diff --git a/examples/declarative/cppextensions/referenceexamples/referenceexamples.pro b/examples/declarative/cppextensions/referenceexamples/referenceexamples.pro index 169c7ab..505cefd 100644 --- a/examples/declarative/cppextensions/referenceexamples/referenceexamples.pro +++ b/examples/declarative/cppextensions/referenceexamples/referenceexamples.pro @@ -10,4 +10,5 @@ SUBDIRS += \ grouped \ properties \ signal \ - valuesource + valuesource \ + methods -- cgit v0.12 From b4bf4f754ba65da3ea751dd5508d29244a4b4db2 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 25 Aug 2010 15:31:00 +1000 Subject: Setting one dimension of the sourceSize should set the other dimension. The implicit width and height should also be set to the sourceSize. Task-number: 13002 --- .../graphicsitems/qdeclarativeimagebase.cpp | 48 ++++++++-------------- .../qdeclarativeimage/tst_qdeclarativeimage.cpp | 14 +++---- .../tst_qdeclarativeimageprovider.cpp | 4 +- 3 files changed, 26 insertions(+), 40 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp index ba40443..d6b935b 100644 --- a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp @@ -147,10 +147,15 @@ void QDeclarativeImageBase::load() setImplicitWidth(0); setImplicitHeight(0); emit statusChanged(d->status); + d->sourcesize.setWidth(0); + d->sourcesize.setHeight(0); + emit sourceSizeChanged(); pixmapChange(); update(); } else { + d->status = Loading; + emit statusChanged(d->status); d->pix.load(qmlEngine(this), d->url, d->sourcesize, d->async); @@ -169,53 +174,34 @@ void QDeclarativeImageBase::load() d->pix.connectDownloadProgress(this, thisRequestProgress); } else { - QSize impsize = d->pix.implicitSize(); - setImplicitWidth(impsize.width()); - setImplicitHeight(impsize.height()); - - if (d->pix.isReady()) { - d->status = Ready; - - if (!d->sourcesize.isValid()) - emit sourceSizeChanged(); - - } else { - d->status = Error; - qmlInfo(this) << d->pix.error(); - } - d->progress = 1.0; - emit statusChanged(d->status); - emit progressChanged(d->progress); - pixmapChange(); - update(); + requestFinished(); } - } - - emit statusChanged(d->status); } void QDeclarativeImageBase::requestFinished() { Q_D(QDeclarativeImageBase); - QSize impsize = d->pix.implicitSize(); - if (d->pix.isError()) { d->status = Error; qmlInfo(this) << d->pix.error(); + } else { + d->status = Ready; } + emit statusChanged(d->status); - setImplicitWidth(impsize.width()); - setImplicitHeight(impsize.height()); + setImplicitWidth(d->pix.width()); + setImplicitHeight(d->pix.height()); - if (d->status == Loading) - d->status = Ready; d->progress = 1.0; - emit statusChanged(d->status); - emit progressChanged(1.0); - if (!d->sourcesize.isValid()) + emit progressChanged(d->progress); + + if (d->sourcesize.width() != d->pix.width() || d->sourcesize.height() != d->pix.height()) { + d->sourcesize.setWidth(d->pix.width()); + d->sourcesize.setHeight(d->pix.height()); emit sourceSizeChanged(); + } pixmapChange(); update(); } diff --git a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp index 0f1050e..8cfb487 100644 --- a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp +++ b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp @@ -272,8 +272,8 @@ void tst_qdeclarativeimage::svg() QVERIFY(obj != 0); QCOMPARE(obj->pixmap().width(), 300); QCOMPARE(obj->pixmap().height(), 300); - QCOMPARE(obj->width(), 550.0); - QCOMPARE(obj->height(), 500.0); + QCOMPARE(obj->width(), 300.0); + QCOMPARE(obj->height(), 300.0); #if defined(Q_OS_LINUX) QCOMPARE(obj->pixmap(), QPixmap(SRCDIR "/data/heart.png")); #elif defined(Q_OS_WIN32) @@ -284,8 +284,8 @@ void tst_qdeclarativeimage::svg() QCOMPARE(obj->pixmap().width(), 200); QCOMPARE(obj->pixmap().height(), 200); - QCOMPARE(obj->width(), 550.0); - QCOMPARE(obj->height(), 500.0); + QCOMPARE(obj->width(), 200.0); + QCOMPARE(obj->height(), 200.0); #if defined(Q_OS_LINUX) QCOMPARE(obj->pixmap(), QPixmap(SRCDIR "/data/heart200.png")); #elif defined(Q_OS_WIN32) @@ -300,7 +300,7 @@ void tst_qdeclarativeimage::big() // have to build a 400 MB image. That would be a bug in the JPEG loader. QString src = QUrl::fromLocalFile(SRCDIR "/data/big.jpeg").toString(); - QString componentStr = "import Qt 4.7\nImage { source: \"" + src + "\"; sourceSize.width: 256; sourceSize.height: 256 }"; + QString componentStr = "import Qt 4.7\nImage { source: \"" + src + "\"; width: 100; sourceSize.height: 256 }"; QDeclarativeComponent component(&engine); component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); @@ -308,8 +308,8 @@ void tst_qdeclarativeimage::big() QVERIFY(obj != 0); QCOMPARE(obj->pixmap().width(), 256); QCOMPARE(obj->pixmap().height(), 256); - QCOMPARE(obj->width(), 10240.0); - QCOMPARE(obj->height(), 10240.0); + QCOMPARE(obj->width(), 100.0); + QCOMPARE(obj->height(), 256.0); QCOMPARE(obj->pixmap(), QPixmap(SRCDIR "/data/big256.png")); delete obj; diff --git a/tests/auto/declarative/qdeclarativeimageprovider/tst_qdeclarativeimageprovider.cpp b/tests/auto/declarative/qdeclarativeimageprovider/tst_qdeclarativeimageprovider.cpp index 4a9224e..6d5a357 100644 --- a/tests/auto/declarative/qdeclarativeimageprovider/tst_qdeclarativeimageprovider.cpp +++ b/tests/auto/declarative/qdeclarativeimageprovider/tst_qdeclarativeimageprovider.cpp @@ -221,8 +221,8 @@ void tst_qdeclarativeimageprovider::runTest(bool async, QDeclarativeImageProvide TRY_WAIT(obj->status() == QDeclarativeImage::Ready); else QVERIFY(obj->status() == QDeclarativeImage::Ready); - QCOMPARE(obj->width(), 100.0); - QCOMPARE(obj->height(), 100.0); + QCOMPARE(obj->width(), qreal(size.width())); + QCOMPARE(obj->height(), qreal(size.height())); QCOMPARE(obj->pixmap().width(), size.width()); QCOMPARE(obj->pixmap().height(), size.height()); QCOMPARE(obj->fillMode(), QDeclarativeImage::Stretch); -- cgit v0.12 From 0700370cb4f49483c24887d6bd8175df730954ed Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 25 Aug 2010 15:52:26 +1000 Subject: typo --- src/declarative/graphicsitems/qdeclarativeimage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp index 47a410c..1cc5f81 100644 --- a/src/declarative/graphicsitems/qdeclarativeimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp @@ -331,7 +331,7 @@ qreal QDeclarativeImage::paintedHeight() const Unlike the \l {Item::}{width} and \l {Item::}{height} properties, which scale the painting of the image, this property sets the actual number of pixels stored for the loaded image so that large images do not use more - memory than necessary. For example, this ensures the image is memory is no + memory than necessary. For example, this ensures the image in memory is no larger than 1024x1024 pixels, regardless of the Image's \l {Item::}{width} and \l {Item::}{height} values: -- cgit v0.12 From 36223d1aeb079a9628d403f87112da3b59652ba0 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 25 Aug 2010 16:08:50 +1000 Subject: Alignment of shadow for rich text is broken when using text styles Task-number: QTBUG-13142 --- src/declarative/graphicsitems/qdeclarativetext.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index b96b43c..e5ad743 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -1047,10 +1047,10 @@ QPixmap QDeclarativeTextPrivate::richTextImage(bool drawStyle) QAbstractTextDocumentLayout::PaintContext context; + QTextOption oldOption(doc->defaultTextOption()); if (drawStyle) { context.palette.setColor(QPalette::Text, styleColor); - // ### Do we really want this? - QTextOption colorOption; + QTextOption colorOption(doc->defaultTextOption()); colorOption.setFlags(QTextOption::SuppressColors); doc->setDefaultTextOption(colorOption); } else { @@ -1058,7 +1058,7 @@ QPixmap QDeclarativeTextPrivate::richTextImage(bool drawStyle) } doc->documentLayout()->draw(&p, context); if (drawStyle) - doc->setDefaultTextOption(QTextOption()); + doc->setDefaultTextOption(oldOption); return img; } -- cgit v0.12 From c86fc55faa28551f06ca569d3fcc26b101efc90c Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 25 Aug 2010 16:15:18 +1000 Subject: Fix poor flicking behavior with slower flicks. We had a very low minimum velocity flick threshold, but upon deciding to flick we increased that velocity considerably. This resulted in a slow dragging movement generating a fast flick. Now we just have a higher minimum flick velocity threshold, and the correct velocity is used. Task-number: QTBUG-13078 Reviewed-by: Michael Brasser --- .../graphicsitems/qdeclarativeflickable.cpp | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index 7fee44e..a6e8c85 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -54,7 +54,7 @@ QT_BEGIN_NAMESPACE static const int FlickThreshold = 20; // Really slow flicks can be annoying. -static const int minimumFlickVelocity = 200; +static const int MinimumFlickVelocity = 75; QDeclarativeFlickableVisibleArea::QDeclarativeFlickableVisibleArea(QDeclarativeFlickable *parent) : QObject(parent), flickable(parent), m_xPosition(0.), m_widthRatio(0.) @@ -779,23 +779,15 @@ void QDeclarativeFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEv } vTime = timeline.time(); - if (qAbs(vData.velocity) > 10 && qAbs(event->pos().y() - pressPos.y()) > FlickThreshold) { - qreal velocity = vData.velocity; - if (qAbs(velocity) < minimumFlickVelocity) // Minimum velocity to avoid annoyingly slow flicks. - velocity = velocity < 0 ? -minimumFlickVelocity : minimumFlickVelocity; - flickY(velocity); - } else { + if (qAbs(vData.velocity) > MinimumFlickVelocity && qAbs(event->pos().y() - pressPos.y()) > FlickThreshold) + flickY(vData.velocity); + else fixupY(); - } - if (qAbs(hData.velocity) > 10 && qAbs(event->pos().x() - pressPos.x()) > FlickThreshold) { - qreal velocity = hData.velocity; - if (qAbs(velocity) < minimumFlickVelocity) // Minimum velocity to avoid annoyingly slow flicks. - velocity = velocity < 0 ? -minimumFlickVelocity : minimumFlickVelocity; - flickX(velocity); - } else { + if (qAbs(hData.velocity) > MinimumFlickVelocity && qAbs(event->pos().x() - pressPos.x()) > FlickThreshold) + flickX(hData.velocity); + else fixupX(); - } lastPosTime.invalidate(); -- cgit v0.12 From a662c0014a55ac3bf57c6e861334a125f6af07aa Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 24 Aug 2010 13:46:24 +1000 Subject: Re-insert and emit the correct NOTIFY signals following the removal of some NOTIFY parameters in d31e3bd3e27e9249df451b4b2a3a3a16e9160fa4 --- src/declarative/graphicsitems/qdeclarativepath.cpp | 1 + src/declarative/graphicsitems/qdeclarativepath_p.h | 5 ++++- src/declarative/util/qdeclarativefontloader.cpp | 1 + src/declarative/util/qdeclarativefontloader_p.h | 3 ++- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativepath.cpp b/src/declarative/graphicsitems/qdeclarativepath.cpp index 62e03e7..0c069ce 100644 --- a/src/declarative/graphicsitems/qdeclarativepath.cpp +++ b/src/declarative/graphicsitems/qdeclarativepath.cpp @@ -893,6 +893,7 @@ void QDeclarativePathPercent::setValue(qreal value) { if (_value != value) { _value = value; + emit valueChanged(); emit changed(); } } diff --git a/src/declarative/graphicsitems/qdeclarativepath_p.h b/src/declarative/graphicsitems/qdeclarativepath_p.h index 195057c..21e1b24 100644 --- a/src/declarative/graphicsitems/qdeclarativepath_p.h +++ b/src/declarative/graphicsitems/qdeclarativepath_p.h @@ -190,13 +190,16 @@ private: class Q_AUTOTEST_EXPORT QDeclarativePathPercent : public QDeclarativePathElement { Q_OBJECT - Q_PROPERTY(qreal value READ value WRITE setValue) + Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged) public: QDeclarativePathPercent(QObject *parent=0) : QDeclarativePathElement(parent) {} qreal value() const; void setValue(qreal value); +signals: + void valueChanged(); + private: qreal _value; }; diff --git a/src/declarative/util/qdeclarativefontloader.cpp b/src/declarative/util/qdeclarativefontloader.cpp index 291583c..1755855 100644 --- a/src/declarative/util/qdeclarativefontloader.cpp +++ b/src/declarative/util/qdeclarativefontloader.cpp @@ -130,6 +130,7 @@ void QDeclarativeFontLoader::setSource(const QUrl &url) d->status = Loading; emit statusChanged(); + emit sourceChanged(); #ifndef QT_NO_LOCALFILE_OPTIMIZED_QML QString lf = QDeclarativeEnginePrivate::urlToLocalFileOrQrc(d->url); if (!lf.isEmpty()) { diff --git a/src/declarative/util/qdeclarativefontloader_p.h b/src/declarative/util/qdeclarativefontloader_p.h index a5fbb8f..0344d99 100644 --- a/src/declarative/util/qdeclarativefontloader_p.h +++ b/src/declarative/util/qdeclarativefontloader_p.h @@ -60,7 +60,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeFontLoader : public QObject Q_DECLARE_PRIVATE(QDeclarativeFontLoader) Q_ENUMS(Status) - Q_PROPERTY(QUrl source READ source WRITE setSource) + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) Q_PROPERTY(Status status READ status NOTIFY statusChanged) @@ -82,6 +82,7 @@ private Q_SLOTS: void replyFinished(); Q_SIGNALS: + void sourceChanged(); void nameChanged(); void statusChanged(); }; -- cgit v0.12 From 185fabb154e387dce7e331558008f7ecaeb1ed50 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 24 Aug 2010 16:21:51 +1000 Subject: Fix responseText to check the charset encoding field and also to not assume that the data is xml. The change also follows the w3c spec more closely (e.g. check the mime type field as well for encoding, for both responseText and responseXML). Task-number: QTBUG-13117 --- src/declarative/qml/qdeclarativexmlhttprequest.cpp | 87 +++++++++++++++++++--- .../qdeclarativexmlhttprequest/data/utf16.html | 1 + .../qdeclarativexmlhttprequest/data/utf16.qml | 5 +- .../tst_qdeclarativexmlhttprequest.cpp | 38 +++++++--- 4 files changed, 110 insertions(+), 21 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.html diff --git a/src/declarative/qml/qdeclarativexmlhttprequest.cpp b/src/declarative/qml/qdeclarativexmlhttprequest.cpp index ff1a0e9..d832638 100644 --- a/src/declarative/qml/qdeclarativexmlhttprequest.cpp +++ b/src/declarative/qml/qdeclarativexmlhttprequest.cpp @@ -965,8 +965,9 @@ public: QScriptValue send(QScriptValue *me, const QByteArray &); QScriptValue abort(QScriptValue *me); - QString responseBody() const; + QString responseBody(); const QByteArray & rawResponseBody() const; + bool receivedXml() const; private slots: void downloadProgress(qint64); void error(QNetworkReply::NetworkError); @@ -989,6 +990,15 @@ private: HeadersList m_headersList; void fillHeadersList(); + bool m_gotXml; + QByteArray m_mime; + QByteArray m_charset; + QTextCodec *m_textCodec; +#ifndef QT_NO_TEXTCODEC + QTextCodec* findTextCodec() const; +#endif + void readEncoding(); + QScriptValue m_me; // Set to the data object while a send() is ongoing (to access the callback) QScriptValue dispatchCallback(QScriptValue *me); @@ -1006,7 +1016,7 @@ private: QDeclarativeXMLHttpRequest::QDeclarativeXMLHttpRequest(QNetworkAccessManager *manager) : m_state(Unsent), m_errorFlag(false), m_sendFlag(false), - m_redirectCount(0), m_network(0), m_nam(manager) + m_redirectCount(0), m_gotXml(false), m_textCodec(0), m_network(0), m_nam(manager) { } @@ -1277,6 +1287,7 @@ void QDeclarativeXMLHttpRequest::finished() if (cbv.isError()) printError(cbv); } m_responseEntityBody.append(m_network->readAll()); + readEncoding(); if (xhrDump()) { qWarning().nospace() << "XMLHttpRequest: RESPONSE " << qPrintable(m_url.toString()); @@ -1302,15 +1313,72 @@ void QDeclarativeXMLHttpRequest::finished() } -QString QDeclarativeXMLHttpRequest::responseBody() const +void QDeclarativeXMLHttpRequest::readEncoding() +{ + foreach (const HeaderPair &header, m_headersList) { + if (header.first == "content-type") { + int separatorIdx = header.second.indexOf(';'); + if (separatorIdx == -1) { + m_mime == header.second; + } else { + m_mime = header.second.mid(0, separatorIdx); + int charsetIdx = header.second.indexOf("charset="); + if (charsetIdx != -1) { + charsetIdx += 8; + separatorIdx = header.second.indexOf(';', charsetIdx); + m_charset = header.second.mid(charsetIdx, separatorIdx >= 0 ? separatorIdx : header.second.length()); + } + } + break; + } + } + + if (m_mime.isEmpty() || m_mime == "text/xml" || m_mime == "application/xml" || m_mime.endsWith("+xml")) + m_gotXml = true; +} + +bool QDeclarativeXMLHttpRequest::receivedXml() const +{ + return m_gotXml; +} + + +#ifndef QT_NO_TEXTCODEC +QTextCodec* QDeclarativeXMLHttpRequest::findTextCodec() const +{ + QTextCodec *codec = 0; + + if (!m_charset.isEmpty()) + codec = QTextCodec::codecForName(m_charset); + + if (!codec && m_gotXml) { + QXmlStreamReader reader(m_responseEntityBody); + reader.readNext(); + codec = QTextCodec::codecForName(reader.documentEncoding().toString().toUtf8()); + } + + if (!codec && m_mime == "text/html") + codec = QTextCodec::codecForHtml(m_responseEntityBody, 0); + + if (!codec) + codec = QTextCodec::codecForUtfText(m_responseEntityBody, 0); + + if (!codec) + codec = QTextCodec::codecForName("UTF-8"); + return codec; +} +#endif + + +QString QDeclarativeXMLHttpRequest::responseBody() { - QXmlStreamReader reader(m_responseEntityBody); - reader.readNext(); #ifndef QT_NO_TEXTCODEC - QTextCodec *codec = QTextCodec::codecForName(reader.documentEncoding().toString().toUtf8()); - if (codec) - return codec->toUnicode(m_responseEntityBody); + if (!m_textCodec) + m_textCodec = findTextCodec(); + if (m_textCodec) + return m_textCodec->toUnicode(m_responseEntityBody); #endif + return QString::fromUtf8(m_responseEntityBody); } @@ -1571,7 +1639,8 @@ static QScriptValue qmlxmlhttprequest_responseXML(QScriptContext *context, QScri if (!request) THROW_REFERENCE("Not an XMLHttpRequest object"); - if (request->readyState() != QDeclarativeXMLHttpRequest::Loading && + if (!request->receivedXml() || + request->readyState() != QDeclarativeXMLHttpRequest::Loading && request->readyState() != QDeclarativeXMLHttpRequest::Done) return engine->nullValue(); else diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.html b/tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.html new file mode 100644 index 0000000..b640733 --- /dev/null +++ b/tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.html @@ -0,0 +1 @@ +უ Σ diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.qml b/tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.qml index a54ef4a..85bff29 100644 --- a/tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.qml +++ b/tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.qml @@ -3,13 +3,14 @@ import Qt 4.7 QtObject { property bool dataOK: false + property string fileName property string responseText property string responseXmlRootNodeValue - Component.onCompleted: { + function startRequest() { var x = new XMLHttpRequest; - x.open("GET", "utf16.xml"); + x.open("GET", fileName); // Test to the end x.onreadystatechange = function() { diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp b/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp index 8141fcb..ecce349 100644 --- a/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp +++ b/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp @@ -104,6 +104,7 @@ private slots: void invalidMethodUsage(); void redirects(); void nonUtf8(); + void nonUtf8_data(); // Attributes void document(); @@ -919,26 +920,43 @@ void tst_qdeclarativexmlhttprequest::responseText_data() void tst_qdeclarativexmlhttprequest::nonUtf8() { + QFETCH(QString, fileName); + QFETCH(QString, responseText); + QFETCH(QString, xmlRootNodeValue); + QDeclarativeComponent component(&engine, TEST_FILE("utf16.qml")); QObject *object = component.create(); QVERIFY(object != 0); + object->setProperty("fileName", fileName); + QMetaObject::invokeMethod(object, "startRequest"); + + TRY_WAIT(object->property("dataOK").toBool() == true); + + QCOMPARE(object->property("responseText").toString(), responseText); + + if (!xmlRootNodeValue.isEmpty()) { + QString rootNodeValue = object->property("responseXmlRootNodeValue").toString(); + QCOMPARE(rootNodeValue, xmlRootNodeValue); + } + + delete object; +} + +void tst_qdeclarativexmlhttprequest::nonUtf8_data() +{ + QTest::addColumn("fileName"); + QTest::addColumn("responseText"); + QTest::addColumn("xmlRootNodeValue"); + QString uc; uc.resize(3); uc[0] = QChar(0x10e3); uc[1] = QChar(' '); uc[2] = QChar(0x03a3); - QString xml = "\n\n" + uc + "\n\n"; - TRY_WAIT(object->property("dataOK").toBool() == true); - - QString responseText = object->property("responseText").toString(); - QCOMPARE(responseText, xml); - - QString responseXmlText = object->property("responseXmlRootNodeValue").toString(); - QCOMPARE(responseXmlText, '\n' + uc + '\n'); - - delete object; + QTest::newRow("responseText") << "utf16.html" << uc + '\n' << ""; + QTest::newRow("responseXML") << "utf16.xml" << "\n\n" + uc + "\n\n" << QString('\n' + uc + '\n'); } // Test that calling hte XMLHttpRequest methods on a non-XMLHttpRequest object -- cgit v0.12 From 57e6192785db1617e233fc4a321da82e5e06ec81 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 25 Aug 2010 17:24:03 +1000 Subject: Don't circumvent onDestruction handlers when clearing expression in delegate cleanup We clear all expressions when removing a delegate in order to avoid spurious warnings. This also removed onDestruction handlers. Ensure the onDestruction handlers are called before the expressions are cleared. Task-number: QTBUG-12946 Reviewed-by: Aaron Kennedy --- .../graphicsitems/qdeclarativevisualitemmodel.cpp | 2 +- src/declarative/qml/qdeclarativecontext.cpp | 17 +++++++++++++++-- src/declarative/qml/qdeclarativecontext_p.h | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index 50a0a33..65b14cf 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -966,7 +966,7 @@ QDeclarativeVisualDataModel::ReleaseFlags QDeclarativeVisualDataModel::release(Q Q_ASSERT(p->declarativeData); QDeclarativeData *d = static_cast(p->declarativeData); if (d->ownContext && d->context) - d->context->clearExpressions(); + d->context->clearContext(); if (inPackage) { emit destroyingPackage(qobject_cast(obj)); diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp index a58dc6c..a3b16d9 100644 --- a/src/declarative/qml/qdeclarativecontext.cpp +++ b/src/declarative/qml/qdeclarativecontext.cpp @@ -533,8 +533,21 @@ void QDeclarativeContextData::invalidate() parent = 0; } -void QDeclarativeContextData::clearExpressions() +void QDeclarativeContextData::clearContext() { + if (engine) { + while (componentAttached) { + QDeclarativeComponentAttached *a = componentAttached; + componentAttached = a->next; + if (componentAttached) componentAttached->prev = &componentAttached; + + a->next = 0; + a->prev = 0; + + emit a->destruction(); + } + } + QDeclarativeAbstractExpression *expression = expressions; while (expression) { QDeclarativeAbstractExpression *nextExpression = expression->m_nextExpression; @@ -555,7 +568,7 @@ void QDeclarativeContextData::destroy() if (engine) invalidate(); - clearExpressions(); + clearContext(); while (contextObjects) { QDeclarativeData *co = contextObjects; diff --git a/src/declarative/qml/qdeclarativecontext_p.h b/src/declarative/qml/qdeclarativecontext_p.h index c5a039a..6c14feb 100644 --- a/src/declarative/qml/qdeclarativecontext_p.h +++ b/src/declarative/qml/qdeclarativecontext_p.h @@ -113,7 +113,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeContextData public: QDeclarativeContextData(); QDeclarativeContextData(QDeclarativeContext *); - void clearExpressions(); + void clearContext(); void destroy(); void invalidate(); -- cgit v0.12