From 630d3b9ba9da12331c72406c311ca26f88c6061a Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 4 Nov 2009 13:21:38 +1000 Subject: Fix test after rename. --- tests/auto/declarative/declarative.pro | 2 +- .../declarative/qfxpixmapcache/data/exists.png | Bin 2738 -> 0 bytes .../declarative/qfxpixmapcache/data/exists1.png | Bin 2738 -> 0 bytes .../declarative/qfxpixmapcache/data/exists2.png | Bin 2738 -> 0 bytes .../declarative/qfxpixmapcache/qfxpixmapcache.pro | 9 - .../qfxpixmapcache/tst_qfxpixmapcache.cpp | 275 --------------------- .../declarative/qmlpixmapcache/data/exists.png | Bin 0 -> 2738 bytes .../declarative/qmlpixmapcache/data/exists1.png | Bin 0 -> 2738 bytes .../declarative/qmlpixmapcache/data/exists2.png | Bin 0 -> 2738 bytes .../declarative/qmlpixmapcache/qmlpixmapcache.pro | 9 + .../qmlpixmapcache/tst_qmlpixmapcache.cpp | 275 +++++++++++++++++++++ 11 files changed, 285 insertions(+), 285 deletions(-) delete mode 100644 tests/auto/declarative/qfxpixmapcache/data/exists.png delete mode 100644 tests/auto/declarative/qfxpixmapcache/data/exists1.png delete mode 100644 tests/auto/declarative/qfxpixmapcache/data/exists2.png delete mode 100644 tests/auto/declarative/qfxpixmapcache/qfxpixmapcache.pro delete mode 100644 tests/auto/declarative/qfxpixmapcache/tst_qfxpixmapcache.cpp create mode 100644 tests/auto/declarative/qmlpixmapcache/data/exists.png create mode 100644 tests/auto/declarative/qmlpixmapcache/data/exists1.png create mode 100644 tests/auto/declarative/qmlpixmapcache/data/exists2.png create mode 100644 tests/auto/declarative/qmlpixmapcache/qmlpixmapcache.pro create mode 100644 tests/auto/declarative/qmlpixmapcache/tst_qmlpixmapcache.cpp diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 321e91b..7e3bf1e 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -10,7 +10,7 @@ SUBDIRS += anchors \ numberformatter \ pathview \ qfxloader \ - qfxpixmapcache \ + qmlpixmapcache \ qfxtextedit \ qfxtextinput \ qfxwebview \ diff --git a/tests/auto/declarative/qfxpixmapcache/data/exists.png b/tests/auto/declarative/qfxpixmapcache/data/exists.png deleted file mode 100644 index 399bd0b..0000000 Binary files a/tests/auto/declarative/qfxpixmapcache/data/exists.png and /dev/null differ diff --git a/tests/auto/declarative/qfxpixmapcache/data/exists1.png b/tests/auto/declarative/qfxpixmapcache/data/exists1.png deleted file mode 100644 index 399bd0b..0000000 Binary files a/tests/auto/declarative/qfxpixmapcache/data/exists1.png and /dev/null differ diff --git a/tests/auto/declarative/qfxpixmapcache/data/exists2.png b/tests/auto/declarative/qfxpixmapcache/data/exists2.png deleted file mode 100644 index 399bd0b..0000000 Binary files a/tests/auto/declarative/qfxpixmapcache/data/exists2.png and /dev/null differ diff --git a/tests/auto/declarative/qfxpixmapcache/qfxpixmapcache.pro b/tests/auto/declarative/qfxpixmapcache/qfxpixmapcache.pro deleted file mode 100644 index 218eeff..0000000 --- a/tests/auto/declarative/qfxpixmapcache/qfxpixmapcache.pro +++ /dev/null @@ -1,9 +0,0 @@ -load(qttest_p4) -contains(QT_CONFIG,declarative): QT += declarative -QT += network -macx:CONFIG -= app_bundle - -SOURCES += tst_qfxpixmapcache.cpp - -# QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage -# LIBS += -lgcov diff --git a/tests/auto/declarative/qfxpixmapcache/tst_qfxpixmapcache.cpp b/tests/auto/declarative/qfxpixmapcache/tst_qfxpixmapcache.cpp deleted file mode 100644 index 88fbdab..0000000 --- a/tests/auto/declarative/qfxpixmapcache/tst_qfxpixmapcache.cpp +++ /dev/null @@ -1,275 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include -#include -#include -#include -#include - -// These don't let normal people run tests! -//#include "../network-settings.h" - -class tst_qfxpixmapcache : public QObject -{ - Q_OBJECT -public: - tst_qfxpixmapcache() : - thisfile("file://" __FILE__) - { - } - -private slots: - void single(); - void single_data(); - void parallel(); - void parallel_data(); - -private: - QmlEngine engine; - QUrl thisfile; -}; - - -static int slotters=0; - -class Slotter : public QObject -{ - Q_OBJECT -public: - Slotter() - { - gotslot = false; - slotters++; - } - bool gotslot; - -public slots: - void got() - { - gotslot = true; - --slotters; - if (slotters==0) - QTestEventLoop::instance().exitLoop(); - } -}; - -#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML -static const bool localfile_optimized = true; -#else -static const bool localfile_optimized = false; -#endif - -void tst_qfxpixmapcache::single_data() -{ - // Note, since QmlGraphicsPixmapCache is shared, tests affect each other! - // so use different files fore all test functions. - - QTest::addColumn("target"); - QTest::addColumn("incache"); - QTest::addColumn("exists"); - QTest::addColumn("neterror"); - - // File URLs are optimized - QTest::newRow("local") << thisfile.resolved(QUrl("data/exists.png")) << localfile_optimized << true << false; - QTest::newRow("local") << thisfile.resolved(QUrl("data/notexists.png")) << localfile_optimized << false << false; - QTest::newRow("remote") << QUrl("http://qt.nokia.com/logo.png") << false << true << false; - QTest::newRow("remote") << QUrl("http://qt.nokia.com/thereisnologo.png") << false << false << true; -} - -void tst_qfxpixmapcache::single() -{ - QFETCH(QUrl, target); - QFETCH(bool, incache); - QFETCH(bool, exists); - QFETCH(bool, neterror); - - if (neterror) { - QString expected = "Network error loading QUrl( \"" - +target.toString()+"\" ) \"Error downloading " - +target.toString()+" - server replied: Not Found\" "; - QTest::ignoreMessage(QtWarningMsg, expected.toLatin1()); - } - - QPixmap pixmap; - QVERIFY(pixmap.width() <= 0); // Check Qt assumption - QNetworkReply *reply= QmlGraphicsPixmapCache::get(&engine, target, &pixmap); - - if (incache) { - QVERIFY(!reply); - if (exists) - QVERIFY(pixmap.width() > 0); - else - QVERIFY(pixmap.width() <= 0); - } else { - QVERIFY(reply); - QVERIFY(pixmap.width() <= 0); - - Slotter getter; - connect(reply, SIGNAL(finished()), &getter, SLOT(got())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); - QVERIFY(getter.gotslot); - if (exists) { - QVERIFY(QmlGraphicsPixmapCache::find(target, &pixmap)); - QVERIFY(pixmap.width() > 0); - } else { - QVERIFY(!QmlGraphicsPixmapCache::find(target, &pixmap)); - QVERIFY(pixmap.width() <= 0); - } - } - - QCOMPARE(QmlGraphicsPixmapCache::pendingRequests(), 0); -} - -void tst_qfxpixmapcache::parallel_data() -{ - // Note, since QmlGraphicsPixmapCache is shared, tests affect each other! - // so use different files fore all test functions. - - QTest::addColumn("target1"); - QTest::addColumn("target2"); - QTest::addColumn("incache"); - QTest::addColumn("cancel"); // which one to cancel - QTest::addColumn("requests"); - - QTest::newRow("local") - << thisfile.resolved(QUrl("data/exists1.png")) - << thisfile.resolved(QUrl("data/exists2.png")) - << (localfile_optimized ? 2 : 0) - << -1 - << (localfile_optimized ? 0 : 2) - ; - - QTest::newRow("remote") - << QUrl("http://qt.nokia.com/images/template/checkbox-on.png") - << QUrl("http://qt.nokia.com/images/products/qt-logo/image_tile") - << 0 - << -1 - << 2 - ; - - QTest::newRow("remoteagain") - << QUrl("http://qt.nokia.com/images/template/checkbox-on.png") - << QUrl("http://qt.nokia.com/images/products/qt-logo/image_tile") - << 2 - << -1 - << 0 - ; - - QTest::newRow("remotecopy") - << QUrl("http://qt.nokia.com/images/template/checkbox-off.png") - << QUrl("http://qt.nokia.com/images/template/checkbox-off.png") - << 0 - << -1 - << 1 - ; - - QTest::newRow("remotecopycancel") - << QUrl("http://qt.nokia.com/rounded_block_bg.png") - << QUrl("http://qt.nokia.com/rounded_block_bg.png") - << 0 - << 0 - << 1 - ; -} - -void tst_qfxpixmapcache::parallel() -{ - QFETCH(QUrl, target1); - QFETCH(QUrl, target2); - QFETCH(int, incache); - QFETCH(int, cancel); - QFETCH(int, requests); - - QList targets; - targets << target1 << target2; - - QList replies; - QList getters; - for (int i=0; i 0); - getters.append(0); - } else { - QVERIFY(pixmap.width() <= 0); - getters.append(new Slotter); - connect(reply, SIGNAL(finished()), getters[i], SLOT(got())); - } - } - - QCOMPARE(incache+slotters, targets.count()); - QCOMPARE(QmlGraphicsPixmapCache::pendingRequests(), requests); - - if (cancel >= 0) { - QmlGraphicsPixmapCache::cancelGet(targets.at(cancel), getters[cancel]); - slotters--; - } - - if (slotters) { - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); - } - - for (int i=0; igotslot); - } else { - QVERIFY(getters[i]->gotslot); - QPixmap pixmap; - QVERIFY(QmlGraphicsPixmapCache::find(targets[i], &pixmap)); - QVERIFY(pixmap.width() > 0); - } - delete getters[i]; - } - } - - QCOMPARE(QmlGraphicsPixmapCache::pendingRequests(), 0); -} - -QTEST_MAIN(tst_qfxpixmapcache) - -#include "tst_qfxpixmapcache.moc" diff --git a/tests/auto/declarative/qmlpixmapcache/data/exists.png b/tests/auto/declarative/qmlpixmapcache/data/exists.png new file mode 100644 index 0000000..399bd0b Binary files /dev/null and b/tests/auto/declarative/qmlpixmapcache/data/exists.png differ diff --git a/tests/auto/declarative/qmlpixmapcache/data/exists1.png b/tests/auto/declarative/qmlpixmapcache/data/exists1.png new file mode 100644 index 0000000..399bd0b Binary files /dev/null and b/tests/auto/declarative/qmlpixmapcache/data/exists1.png differ diff --git a/tests/auto/declarative/qmlpixmapcache/data/exists2.png b/tests/auto/declarative/qmlpixmapcache/data/exists2.png new file mode 100644 index 0000000..399bd0b Binary files /dev/null and b/tests/auto/declarative/qmlpixmapcache/data/exists2.png differ diff --git a/tests/auto/declarative/qmlpixmapcache/qmlpixmapcache.pro b/tests/auto/declarative/qmlpixmapcache/qmlpixmapcache.pro new file mode 100644 index 0000000..423fa2f --- /dev/null +++ b/tests/auto/declarative/qmlpixmapcache/qmlpixmapcache.pro @@ -0,0 +1,9 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +QT += network +macx:CONFIG -= app_bundle + +SOURCES += tst_qmlpixmapcache.cpp + +# QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage +# LIBS += -lgcov diff --git a/tests/auto/declarative/qmlpixmapcache/tst_qmlpixmapcache.cpp b/tests/auto/declarative/qmlpixmapcache/tst_qmlpixmapcache.cpp new file mode 100644 index 0000000..88d9df5 --- /dev/null +++ b/tests/auto/declarative/qmlpixmapcache/tst_qmlpixmapcache.cpp @@ -0,0 +1,275 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include +#include + +// These don't let normal people run tests! +//#include "../network-settings.h" + +class tst_qmlpixmapcache : public QObject +{ + Q_OBJECT +public: + tst_qmlpixmapcache() : + thisfile("file://" __FILE__) + { + } + +private slots: + void single(); + void single_data(); + void parallel(); + void parallel_data(); + +private: + QmlEngine engine; + QUrl thisfile; +}; + + +static int slotters=0; + +class Slotter : public QObject +{ + Q_OBJECT +public: + Slotter() + { + gotslot = false; + slotters++; + } + bool gotslot; + +public slots: + void got() + { + gotslot = true; + --slotters; + if (slotters==0) + QTestEventLoop::instance().exitLoop(); + } +}; + +#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML +static const bool localfile_optimized = true; +#else +static const bool localfile_optimized = false; +#endif + +void tst_qmlpixmapcache::single_data() +{ + // Note, since QmlPixmapCache is shared, tests affect each other! + // so use different files fore all test functions. + + QTest::addColumn("target"); + QTest::addColumn("incache"); + QTest::addColumn("exists"); + QTest::addColumn("neterror"); + + // File URLs are optimized + QTest::newRow("local") << thisfile.resolved(QUrl("data/exists.png")) << localfile_optimized << true << false; + QTest::newRow("local") << thisfile.resolved(QUrl("data/notexists.png")) << localfile_optimized << false << false; + QTest::newRow("remote") << QUrl("http://qt.nokia.com/logo.png") << false << true << false; + QTest::newRow("remote") << QUrl("http://qt.nokia.com/thereisnologo.png") << false << false << true; +} + +void tst_qmlpixmapcache::single() +{ + QFETCH(QUrl, target); + QFETCH(bool, incache); + QFETCH(bool, exists); + QFETCH(bool, neterror); + + if (neterror) { + QString expected = "Network error loading QUrl( \"" + +target.toString()+"\" ) \"Error downloading " + +target.toString()+" - server replied: Not Found\" "; + QTest::ignoreMessage(QtWarningMsg, expected.toLatin1()); + } + + QPixmap pixmap; + QVERIFY(pixmap.width() <= 0); // Check Qt assumption + QNetworkReply *reply= QmlPixmapCache::get(&engine, target, &pixmap); + + if (incache) { + QVERIFY(!reply); + if (exists) + QVERIFY(pixmap.width() > 0); + else + QVERIFY(pixmap.width() <= 0); + } else { + QVERIFY(reply); + QVERIFY(pixmap.width() <= 0); + + Slotter getter; + connect(reply, SIGNAL(finished()), &getter, SLOT(got())); + QTestEventLoop::instance().enterLoop(10); + QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(getter.gotslot); + if (exists) { + QVERIFY(QmlPixmapCache::find(target, &pixmap)); + QVERIFY(pixmap.width() > 0); + } else { + QVERIFY(!QmlPixmapCache::find(target, &pixmap)); + QVERIFY(pixmap.width() <= 0); + } + } + + QCOMPARE(QmlPixmapCache::pendingRequests(), 0); +} + +void tst_qmlpixmapcache::parallel_data() +{ + // Note, since QmlPixmapCache is shared, tests affect each other! + // so use different files fore all test functions. + + QTest::addColumn("target1"); + QTest::addColumn("target2"); + QTest::addColumn("incache"); + QTest::addColumn("cancel"); // which one to cancel + QTest::addColumn("requests"); + + QTest::newRow("local") + << thisfile.resolved(QUrl("data/exists1.png")) + << thisfile.resolved(QUrl("data/exists2.png")) + << (localfile_optimized ? 2 : 0) + << -1 + << (localfile_optimized ? 0 : 2) + ; + + QTest::newRow("remote") + << QUrl("http://qt.nokia.com/images/template/checkbox-on.png") + << QUrl("http://qt.nokia.com/images/products/qt-logo/image_tile") + << 0 + << -1 + << 2 + ; + + QTest::newRow("remoteagain") + << QUrl("http://qt.nokia.com/images/template/checkbox-on.png") + << QUrl("http://qt.nokia.com/images/products/qt-logo/image_tile") + << 2 + << -1 + << 0 + ; + + QTest::newRow("remotecopy") + << QUrl("http://qt.nokia.com/images/template/checkbox-off.png") + << QUrl("http://qt.nokia.com/images/template/checkbox-off.png") + << 0 + << -1 + << 1 + ; + + QTest::newRow("remotecopycancel") + << QUrl("http://qt.nokia.com/rounded_block_bg.png") + << QUrl("http://qt.nokia.com/rounded_block_bg.png") + << 0 + << 0 + << 1 + ; +} + +void tst_qmlpixmapcache::parallel() +{ + QFETCH(QUrl, target1); + QFETCH(QUrl, target2); + QFETCH(int, incache); + QFETCH(int, cancel); + QFETCH(int, requests); + + QList targets; + targets << target1 << target2; + + QList replies; + QList getters; + for (int i=0; i 0); + getters.append(0); + } else { + QVERIFY(pixmap.width() <= 0); + getters.append(new Slotter); + connect(reply, SIGNAL(finished()), getters[i], SLOT(got())); + } + } + + QCOMPARE(incache+slotters, targets.count()); + QCOMPARE(QmlPixmapCache::pendingRequests(), requests); + + if (cancel >= 0) { + QmlPixmapCache::cancelGet(targets.at(cancel), getters[cancel]); + slotters--; + } + + if (slotters) { + QTestEventLoop::instance().enterLoop(10); + QVERIFY(!QTestEventLoop::instance().timeout()); + } + + for (int i=0; igotslot); + } else { + QVERIFY(getters[i]->gotslot); + QPixmap pixmap; + QVERIFY(QmlPixmapCache::find(targets[i], &pixmap)); + QVERIFY(pixmap.width() > 0); + } + delete getters[i]; + } + } + + QCOMPARE(QmlPixmapCache::pendingRequests(), 0); +} + +QTEST_MAIN(tst_qmlpixmapcache) + +#include "tst_qmlpixmapcache.moc" -- cgit v0.12 From 684fe7af0b6d8133973132fd5b6b01cc16957a10 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 4 Nov 2009 13:47:40 +1000 Subject: Add closestAngle function to Qt object to help with rotation animations. Includes test and doc. --- doc/src/declarative/globalobject.qdoc | 3 +++ src/declarative/qml/qmlengine.cpp | 20 ++++++++++++++++++++ src/declarative/qml/qmlengine_p.h | 1 + tests/auto/declarative/qmlqt/data/closestangle.qml | 12 ++++++++++++ tests/auto/declarative/qmlqt/tst_qmlqt.cpp | 18 ++++++++++++++++++ 5 files changed, 54 insertions(+) create mode 100644 tests/auto/declarative/qmlqt/data/closestangle.qml diff --git a/doc/src/declarative/globalobject.qdoc b/doc/src/declarative/globalobject.qdoc index f1d440f..06f6bdc 100644 --- a/doc/src/declarative/globalobject.qdoc +++ b/doc/src/declarative/globalobject.qdoc @@ -114,6 +114,9 @@ This function returns a color 50% darker than \c baseColor. See QColor::lighter( \image declarative-rect_tint.png Tint is most useful when a subtle change is intended to be conveyed due to some event; you can then use tinting to more effectively tune the visible color. +\section3 Qt.closestAngle(number fromAngle, number toAngle) +This function returns an equivalent angle to toAngle, such that the difference between fromAngle and toAngle is never more than 180 degrees. This is useful when animating angles using a NumberAnimation, which does not know about equivalent angles, when you always want to take the shortest path. + \section3 Qt.playSound(url soundLocation) This function plays the audio file located at \c soundLocation. Only .wav files are supported. diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index c562e02..2926791 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -147,6 +147,7 @@ QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) qtObject.setProperty(QLatin1String("tint"), scriptEngine.newFunction(QmlEnginePrivate::tint, 2)); //misc methods + qtObject.setProperty(QLatin1String("closestAngle"), scriptEngine.newFunction(QmlEnginePrivate::closestAngle, 2)); qtObject.setProperty(QLatin1String("playSound"), scriptEngine.newFunction(QmlEnginePrivate::playSound, 1)); qtObject.setProperty(QLatin1String("openUrlExternally"),scriptEngine.newFunction(desktopOpenUrl, 1)); @@ -810,6 +811,25 @@ QScriptValue QmlEnginePrivate::desktopOpenUrl(QScriptContext *ctxt, QScriptEngin return e->newVariant(QVariant(ret)); } +QScriptValue QmlEnginePrivate::closestAngle(QScriptContext *ctxt, QScriptEngine *e) +{ + if(ctxt->argumentCount() < 2) + return e->newVariant(QVariant(0.0)); + qreal a = ctxt->argument(0).toNumber(); + qreal b = ctxt->argument(1).toNumber(); + qreal ret = b; + qreal diff = b-a; + while(diff > 180.0){ + ret -= 360.0; + diff -= 360.0; + } + while(diff < -180.0){ + ret += 360.0; + diff += 360.0; + } + return e->newVariant(QVariant(ret)); +} + QScriptValue QmlEnginePrivate::tint(QScriptContext *ctxt, QScriptEngine *engine) { if(ctxt->argumentCount() != 2) diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index b050ef6..3c60b5c 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -269,6 +269,7 @@ public: static QScriptValue darker(QScriptContext*, QScriptEngine*); static QScriptValue tint(QScriptContext*, QScriptEngine*); + static QScriptValue closestAngle(QScriptContext*, QScriptEngine*); static QScriptValue playSound(QScriptContext*, QScriptEngine*); static QScriptValue desktopOpenUrl(QScriptContext*, QScriptEngine*); diff --git a/tests/auto/declarative/qmlqt/data/closestangle.qml b/tests/auto/declarative/qmlqt/data/closestangle.qml new file mode 100644 index 0000000..8f999e3 --- /dev/null +++ b/tests/auto/declarative/qmlqt/data/closestangle.qml @@ -0,0 +1,12 @@ +import Qt 4.6 + +Object { + property var testSame: Qt.closestAngle(0,1) + property var testLess: Qt.closestAngle(0,-359) + property var testMore: Qt.closestAngle(0,361) + property var testFail: Qt.closestAngle(0) + property var test5: Qt.closestAngle(0,1,2) + property var test6: Qt.closestAngle(123.45465768,1.11) + property var test7: Qt.closestAngle(-3.1415,1.11) +} + diff --git a/tests/auto/declarative/qmlqt/tst_qmlqt.cpp b/tests/auto/declarative/qmlqt/tst_qmlqt.cpp index 10402ae..cc9b94d 100644 --- a/tests/auto/declarative/qmlqt/tst_qmlqt.cpp +++ b/tests/auto/declarative/qmlqt/tst_qmlqt.cpp @@ -64,6 +64,7 @@ private slots: void lighter(); void darker(); void tint(); + void closestAngle(); void playSound(); void openUrlExternally(); @@ -249,6 +250,23 @@ void tst_qmlqt::tint() delete object; } +void tst_qmlqt::closestAngle() +{ + QmlComponent component(&engine, TEST_FILE("closestangle.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(qvariant_cast(object->property("testSame")), 1.0); + QCOMPARE(qvariant_cast(object->property("testLess")), 1.0); + QCOMPARE(qvariant_cast(object->property("testMore")), 1.0); + QCOMPARE(qvariant_cast(object->property("testFail")), 0.0); + QCOMPARE(qvariant_cast(object->property("test5")), 1.0); + QCOMPARE(qvariant_cast(object->property("test6")), 1.11); + QCOMPARE(qvariant_cast(object->property("test7")), 1.11); + + delete object; +} + void tst_qmlqt::playSound() { QEXPECT_FAIL("", "How do we test this?", Abort); -- cgit v0.12 From 99fe55b3b4c031f1288f9e1c16455ca08663059c Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 4 Nov 2009 14:15:20 +1000 Subject: Start on QmlXmlListModel autotest. --- tests/auto/declarative/declarative.pro | 1 + .../declarative/qmlxmllistmodel/data/model.qml | 10 +++ .../declarative/qmlxmllistmodel/data/model.xml | 56 +++++++++++++++ .../qmlxmllistmodel/qmlxmllistmodel.pro | 7 ++ .../qmlxmllistmodel/tst_qmlxmllistmodel.cpp | 80 ++++++++++++++++++++++ 5 files changed, 154 insertions(+) create mode 100644 tests/auto/declarative/qmlxmllistmodel/data/model.qml create mode 100644 tests/auto/declarative/qmlxmllistmodel/data/model.xml create mode 100644 tests/auto/declarative/qmlxmllistmodel/qmlxmllistmodel.pro create mode 100644 tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 7e3bf1e..f09d6cf 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -28,6 +28,7 @@ SUBDIRS += anchors \ qmlmetatype \ qmlpropertymap \ qmltimer \ + qmlxmllistmodel \ repeater \ sql \ states \ diff --git a/tests/auto/declarative/qmlxmllistmodel/data/model.qml b/tests/auto/declarative/qmlxmllistmodel/data/model.qml new file mode 100644 index 0000000..199a447 --- /dev/null +++ b/tests/auto/declarative/qmlxmllistmodel/data/model.qml @@ -0,0 +1,10 @@ +import Qt 4.6 + +XmlListModel { + source: "model.xml" + query: "/ListModel/ListElement" + XmlRole { name: "name"; query: "name/string()" } + XmlRole { name: "type"; query: "type/string()" } + XmlRole { name: "age"; query: "age/number()" } + XmlRole { name: "size"; query: "size/string()" } +} diff --git a/tests/auto/declarative/qmlxmllistmodel/data/model.xml b/tests/auto/declarative/qmlxmllistmodel/data/model.xml new file mode 100644 index 0000000..f1fe742 --- /dev/null +++ b/tests/auto/declarative/qmlxmllistmodel/data/model.xml @@ -0,0 +1,56 @@ + + + Polly + Parrot + 12 + Small + + + Penny + Turtle + 4 + Small + + + Warren + Rabbit + 2 + Small + + + Spot + Dog + 9 + Medium + + + Whiskers + Cat + 2 + Medium + + + Joey + Kangaroo + 1 + Medium + + + Kimba + Bunny + 65 + Large + + + Rover + Dog + 5 + Large + + + Tiny + Elephant + 15 + Large + + diff --git a/tests/auto/declarative/qmlxmllistmodel/qmlxmllistmodel.pro b/tests/auto/declarative/qmlxmllistmodel/qmlxmllistmodel.pro new file mode 100644 index 0000000..462723e --- /dev/null +++ b/tests/auto/declarative/qmlxmllistmodel/qmlxmllistmodel.pro @@ -0,0 +1,7 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative gui +macx:CONFIG -= app_bundle + +SOURCES += tst_qmlxmllistmodel.cpp + +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp b/tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp new file mode 100644 index 0000000..0fc9006 --- /dev/null +++ b/tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include +#include "../../../shared/util.h" + +class tst_qmlxmllistmodel : public QObject + +{ + Q_OBJECT +public: + tst_qmlxmllistmodel() {} + +private slots: + void buildModel(); + +private: + QmlEngine engine; +}; + +void tst_qmlxmllistmodel::buildModel() +{ + QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/model.qml")); + QmlXmlListModel *listModel = qobject_cast(component.create()); + QVERIFY(listModel != 0); + QTRY_COMPARE(listModel->count(), 9); + + QList roles; + roles << Qt::UserRole << Qt::UserRole + 1 << Qt::UserRole + 2 << Qt::UserRole + 3; + QHash data = listModel->data(3, roles); + QVERIFY(data.count() == 4); + QCOMPARE(data.value(Qt::UserRole).toString(), QLatin1String("Spot")); + QCOMPARE(data.value(Qt::UserRole+1).toString(), QLatin1String("Dog")); + QCOMPARE(data.value(Qt::UserRole+2).toInt(), 9); + QCOMPARE(data.value(Qt::UserRole+3).toString(), QLatin1String("Medium")); +} + +QTEST_MAIN(tst_qmlxmllistmodel) + +#include "tst_qmlxmllistmodel.moc" -- cgit v0.12 From 2c6d4485b7a0c8c819a225e56ca9a43ab4fcccf4 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 4 Nov 2009 14:15:46 +1000 Subject: Doc. --- src/declarative/qml/qmlmetaproperty.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index 8385352..f340612 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -558,6 +558,9 @@ QmlAbstractBinding *QmlMetaProperty::binding() const Ownership of \a newBinding transfers to QML. Ownership of the return value is assumed by the caller. + + \a flags is passed through to the binding and is used for the initial update (when + the binding sets the intial value, it will use these flags for the write). */ QmlAbstractBinding * QmlMetaProperty::setBinding(QmlAbstractBinding *newBinding, QmlMetaProperty::WriteFlags flags) const -- cgit v0.12