diff options
33 files changed, 701 insertions, 92 deletions
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<Person> BirthdayParty::guests() +{ + return QDeclarativeListProperty<Person>(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 <QObject> +#include <QDeclarativeListProperty> +#include "person.h" + +class BirthdayParty : public QObject +{ + Q_OBJECT + Q_PROPERTY(Person *host READ host WRITE setHost) + Q_PROPERTY(QDeclarativeListProperty<Person> guests READ guests) +public: + BirthdayParty(QObject *parent = 0); + + Person *host() const; + void setHost(Person *); + + QDeclarativeListProperty<Person> guests(); + int guestCount() const; + Person *guest(int) const; + +// ![0] + Q_INVOKABLE void invite(const QString &name); +// ![0] + +private: + Person *m_host; + QList<Person *> 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 <QCoreApplication> +#include <QDeclarativeEngine> +#include <QDeclarativeComponent> +#include <QDebug> +#include "birthdayparty.h" +#include "person.h" + +int main(int argc, char ** argv) +{ + QCoreApplication app(argc, argv); + + qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty"); + qmlRegisterType<Person>("People", 1,0, "Person"); + + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, QUrl("qrc:example.qml")); + BirthdayParty *party = qobject_cast<BirthdayParty *>(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 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>example.qml</file> +</qresource> +</RCC> 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 <QObject> + +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 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(); 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: 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/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/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; } 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<QDeclarativeData*>(p->declarativeData); if (d->ownContext && d->context) - d->context->clearExpressions(); + d->context->clearContext(); if (inPackage) { emit destroyingPackage(qobject_cast<QDeclarativePackage*>(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(); 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/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(); }; diff --git a/src/gui/kernel/qaction_p.h b/src/gui/kernel/qaction_p.h index 899b01b..5764318 100644 --- a/src/gui/kernel/qaction_p.h +++ b/src/gui/kernel/qaction_p.h @@ -112,12 +112,12 @@ public: //for soft keys management uint forceEnabledInSoftkeys : 1; uint menuActionSoftkeys : 1; - - QAction::MenuRole menuRole : 3; - QAction::SoftKeyRole softKeyRole : 2; - QAction::Priority priority : 14; int iconVisibleInMenu : 3; // Only has values -1, 0, and 1 + QAction::MenuRole menuRole; + QAction::SoftKeyRole softKeyRole; + QAction::Priority priority; + QList<QWidget *> widgets; #ifndef QT_NO_GRAPHICSVIEW QList<QGraphicsWidget *> graphicsWidgets; diff --git a/src/openvg/qpixmapdata_vg.cpp b/src/openvg/qpixmapdata_vg.cpp index cb413d0..e8ec333 100644 --- a/src/openvg/qpixmapdata_vg.cpp +++ b/src/openvg/qpixmapdata_vg.cpp @@ -47,6 +47,9 @@ #endif #include "qvg_p.h" #include "qvgimagepool_p.h" +#include <QBuffer> +#include <QImageReader> +#include <QtGui/private/qimage_p.h> QT_BEGIN_NAMESPACE @@ -152,11 +155,59 @@ void QVGPixmapData::resize(int wid, int ht) void QVGPixmapData::fromImage (const QImage &image, Qt::ImageConversionFlags flags) { + QImage img = image; + createPixmapForImage(img, flags, false); +} + +void QVGPixmapData::fromImageReader(QImageReader *imageReader, + Qt::ImageConversionFlags flags) +{ + QImage image = imageReader->read(); + if (image.isNull()) + return; + + createPixmapForImage(image, flags, true); +} + +bool QVGPixmapData::fromFile(const QString &filename, const char *format, + Qt::ImageConversionFlags flags) +{ + QImage image = QImageReader(filename, format).read(); + if (image.isNull()) + return false; + + createPixmapForImage(image, flags, true); + + return !isNull(); +} + +bool QVGPixmapData::fromData(const uchar *buffer, uint len, const char *format, + Qt::ImageConversionFlags flags) +{ + QByteArray a = QByteArray::fromRawData(reinterpret_cast<const char *>(buffer), len); + QBuffer b(&a); + b.open(QIODevice::ReadOnly); + QImage image = QImageReader(&b, format).read(); + if (image.isNull()) + return false; + + createPixmapForImage(image, flags, true); + + return !isNull(); +} + +void QVGPixmapData::createPixmapForImage(QImage &image, Qt::ImageConversionFlags flags, bool inPlace) +{ if (image.size() == QSize(w, h)) setSerialNumber(++qt_vg_pixmap_serial); else resize(image.width(), image.height()); - source = image.convertToFormat(sourceFormat(), flags); + + if (inPlace && image.data_ptr()->convertInPlace(sourceFormat(), flags)) + source = image; + else + source = image.convertToFormat(sourceFormat()); + recreate = true; } diff --git a/src/openvg/qpixmapdata_vg_p.h b/src/openvg/qpixmapdata_vg_p.h index c21b48f..114d545 100644 --- a/src/openvg/qpixmapdata_vg_p.h +++ b/src/openvg/qpixmapdata_vg_p.h @@ -64,6 +64,7 @@ QT_BEGIN_NAMESPACE class QEglContext; class QVGImagePool; +class QImageReader; #if !defined(QT_NO_EGL) class QVGPixmapData; @@ -87,6 +88,12 @@ public: void resize(int width, int height); void fromImage(const QImage &image, Qt::ImageConversionFlags flags); + void fromImageReader(QImageReader *imageReader, + Qt::ImageConversionFlags flags); + bool fromFile(const QString &filename, const char *format, + Qt::ImageConversionFlags flags); + bool fromData(const uchar *buffer, uint len, const char *format, + Qt::ImageConversionFlags flags); void fill(const QColor &color); bool hasAlphaChannel() const; @@ -126,6 +133,7 @@ public: protected: int metric(QPaintDevice::PaintDeviceMetric metric) const; + void createPixmapForImage(QImage &image, Qt::ImageConversionFlags flags, bool inPlace); #if defined(Q_OS_SYMBIAN) void cleanup(); 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); 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<QString>("fileName"); + QTest::addColumn<QString>("responseText"); + QTest::addColumn<QString>("xmlRootNodeValue"); + QString uc; uc.resize(3); uc[0] = QChar(0x10e3); uc[1] = QChar(' '); uc[2] = QChar(0x03a3); - QString xml = "<?xml version=\"1.0\" encoding=\"UTF-16\" standalone='yes'?>\n<root>\n" + uc + "\n</root>\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" << "<?xml version=\"1.0\" encoding=\"UTF-16\" standalone='yes'?>\n<root>\n" + uc + "\n</root>\n" << QString('\n' + uc + '\n'); } // Test that calling hte XMLHttpRequest methods on a non-XMLHttpRequest object diff --git a/tools/runonphone/ossignalconverter.h b/tools/runonphone/ossignalconverter.h index f53f3c1..398d0f6 100644 --- a/tools/runonphone/ossignalconverter.h +++ b/tools/runonphone/ossignalconverter.h @@ -43,6 +43,8 @@ #define OSSIGNALCONVERTER_H #include <QObject> +class OsSignalConverterPrivate; + class OsSignalConverter : public QObject { friend class OsSignalConverterPrivate; |