summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/src/declarative/globalobject.qdoc3
-rw-r--r--src/declarative/qml/qmlengine.cpp20
-rw-r--r--src/declarative/qml/qmlengine_p.h1
-rw-r--r--src/declarative/qml/qmlmetaproperty.cpp3
-rw-r--r--tests/auto/declarative/declarative.pro3
-rw-r--r--tests/auto/declarative/qmlpixmapcache/data/exists.png (renamed from tests/auto/declarative/qfxpixmapcache/data/exists.png)bin2738 -> 2738 bytes
-rw-r--r--tests/auto/declarative/qmlpixmapcache/data/exists1.png (renamed from tests/auto/declarative/qfxpixmapcache/data/exists1.png)bin2738 -> 2738 bytes
-rw-r--r--tests/auto/declarative/qmlpixmapcache/data/exists2.png (renamed from tests/auto/declarative/qfxpixmapcache/data/exists2.png)bin2738 -> 2738 bytes
-rw-r--r--tests/auto/declarative/qmlpixmapcache/qmlpixmapcache.pro (renamed from tests/auto/declarative/qfxpixmapcache/qfxpixmapcache.pro)2
-rw-r--r--tests/auto/declarative/qmlpixmapcache/tst_qmlpixmapcache.cpp (renamed from tests/auto/declarative/qfxpixmapcache/tst_qfxpixmapcache.cpp)40
-rw-r--r--tests/auto/declarative/qmlqt/data/closestangle.qml12
-rw-r--r--tests/auto/declarative/qmlqt/tst_qmlqt.cpp18
-rw-r--r--tests/auto/declarative/qmlxmllistmodel/data/model.qml10
-rw-r--r--tests/auto/declarative/qmlxmllistmodel/data/model.xml56
-rw-r--r--tests/auto/declarative/qmlxmllistmodel/qmlxmllistmodel.pro7
-rw-r--r--tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp80
16 files changed, 233 insertions, 22 deletions
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/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
diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro
index 321e91b..f09d6cf 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 \
@@ -28,6 +28,7 @@ SUBDIRS += anchors \
qmlmetatype \
qmlpropertymap \
qmltimer \
+ qmlxmllistmodel \
repeater \
sql \
states \
diff --git a/tests/auto/declarative/qfxpixmapcache/data/exists.png b/tests/auto/declarative/qmlpixmapcache/data/exists.png
index 399bd0b..399bd0b 100644
--- a/tests/auto/declarative/qfxpixmapcache/data/exists.png
+++ b/tests/auto/declarative/qmlpixmapcache/data/exists.png
Binary files differ
diff --git a/tests/auto/declarative/qfxpixmapcache/data/exists1.png b/tests/auto/declarative/qmlpixmapcache/data/exists1.png
index 399bd0b..399bd0b 100644
--- a/tests/auto/declarative/qfxpixmapcache/data/exists1.png
+++ b/tests/auto/declarative/qmlpixmapcache/data/exists1.png
Binary files differ
diff --git a/tests/auto/declarative/qfxpixmapcache/data/exists2.png b/tests/auto/declarative/qmlpixmapcache/data/exists2.png
index 399bd0b..399bd0b 100644
--- a/tests/auto/declarative/qfxpixmapcache/data/exists2.png
+++ b/tests/auto/declarative/qmlpixmapcache/data/exists2.png
Binary files differ
diff --git a/tests/auto/declarative/qfxpixmapcache/qfxpixmapcache.pro b/tests/auto/declarative/qmlpixmapcache/qmlpixmapcache.pro
index 218eeff..423fa2f 100644
--- a/tests/auto/declarative/qfxpixmapcache/qfxpixmapcache.pro
+++ b/tests/auto/declarative/qmlpixmapcache/qmlpixmapcache.pro
@@ -3,7 +3,7 @@ contains(QT_CONFIG,declarative): QT += declarative
QT += network
macx:CONFIG -= app_bundle
-SOURCES += tst_qfxpixmapcache.cpp
+SOURCES += tst_qmlpixmapcache.cpp
# QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage
# LIBS += -lgcov
diff --git a/tests/auto/declarative/qfxpixmapcache/tst_qfxpixmapcache.cpp b/tests/auto/declarative/qmlpixmapcache/tst_qmlpixmapcache.cpp
index 88fbdab..88d9df5 100644
--- a/tests/auto/declarative/qfxpixmapcache/tst_qfxpixmapcache.cpp
+++ b/tests/auto/declarative/qmlpixmapcache/tst_qmlpixmapcache.cpp
@@ -40,18 +40,18 @@
****************************************************************************/
#include <qtest.h>
#include <QtTest/QtTest>
-#include <private/qmlgraphicspixmapcache_p.h>
+#include <private/qmlpixmapcache_p.h>
#include <QtDeclarative/qmlengine.h>
#include <QNetworkReply>
// These don't let normal people run tests!
//#include "../network-settings.h"
-class tst_qfxpixmapcache : public QObject
+class tst_qmlpixmapcache : public QObject
{
Q_OBJECT
public:
- tst_qfxpixmapcache() :
+ tst_qmlpixmapcache() :
thisfile("file://" __FILE__)
{
}
@@ -97,9 +97,9 @@ static const bool localfile_optimized = true;
static const bool localfile_optimized = false;
#endif
-void tst_qfxpixmapcache::single_data()
+void tst_qmlpixmapcache::single_data()
{
- // Note, since QmlGraphicsPixmapCache is shared, tests affect each other!
+ // Note, since QmlPixmapCache is shared, tests affect each other!
// so use different files fore all test functions.
QTest::addColumn<QUrl>("target");
@@ -114,7 +114,7 @@ void tst_qfxpixmapcache::single_data()
QTest::newRow("remote") << QUrl("http://qt.nokia.com/thereisnologo.png") << false << false << true;
}
-void tst_qfxpixmapcache::single()
+void tst_qmlpixmapcache::single()
{
QFETCH(QUrl, target);
QFETCH(bool, incache);
@@ -130,7 +130,7 @@ void tst_qfxpixmapcache::single()
QPixmap pixmap;
QVERIFY(pixmap.width() <= 0); // Check Qt assumption
- QNetworkReply *reply= QmlGraphicsPixmapCache::get(&engine, target, &pixmap);
+ QNetworkReply *reply= QmlPixmapCache::get(&engine, target, &pixmap);
if (incache) {
QVERIFY(!reply);
@@ -148,20 +148,20 @@ void tst_qfxpixmapcache::single()
QVERIFY(!QTestEventLoop::instance().timeout());
QVERIFY(getter.gotslot);
if (exists) {
- QVERIFY(QmlGraphicsPixmapCache::find(target, &pixmap));
+ QVERIFY(QmlPixmapCache::find(target, &pixmap));
QVERIFY(pixmap.width() > 0);
} else {
- QVERIFY(!QmlGraphicsPixmapCache::find(target, &pixmap));
+ QVERIFY(!QmlPixmapCache::find(target, &pixmap));
QVERIFY(pixmap.width() <= 0);
}
}
- QCOMPARE(QmlGraphicsPixmapCache::pendingRequests(), 0);
+ QCOMPARE(QmlPixmapCache::pendingRequests(), 0);
}
-void tst_qfxpixmapcache::parallel_data()
+void tst_qmlpixmapcache::parallel_data()
{
- // Note, since QmlGraphicsPixmapCache is shared, tests affect each other!
+ // Note, since QmlPixmapCache is shared, tests affect each other!
// so use different files fore all test functions.
QTest::addColumn<QUrl>("target1");
@@ -211,7 +211,7 @@ void tst_qfxpixmapcache::parallel_data()
;
}
-void tst_qfxpixmapcache::parallel()
+void tst_qmlpixmapcache::parallel()
{
QFETCH(QUrl, target1);
QFETCH(QUrl, target2);
@@ -227,7 +227,7 @@ void tst_qfxpixmapcache::parallel()
for (int i=0; i<targets.count(); ++i) {
QUrl target = targets.at(i);
QPixmap pixmap;
- QNetworkReply *reply = QmlGraphicsPixmapCache::get(&engine, target, &pixmap);
+ QNetworkReply *reply = QmlPixmapCache::get(&engine, target, &pixmap);
replies.append(reply);
if (!reply) {
QVERIFY(pixmap.width() > 0);
@@ -240,10 +240,10 @@ void tst_qfxpixmapcache::parallel()
}
QCOMPARE(incache+slotters, targets.count());
- QCOMPARE(QmlGraphicsPixmapCache::pendingRequests(), requests);
+ QCOMPARE(QmlPixmapCache::pendingRequests(), requests);
if (cancel >= 0) {
- QmlGraphicsPixmapCache::cancelGet(targets.at(cancel), getters[cancel]);
+ QmlPixmapCache::cancelGet(targets.at(cancel), getters[cancel]);
slotters--;
}
@@ -260,16 +260,16 @@ void tst_qfxpixmapcache::parallel()
} else {
QVERIFY(getters[i]->gotslot);
QPixmap pixmap;
- QVERIFY(QmlGraphicsPixmapCache::find(targets[i], &pixmap));
+ QVERIFY(QmlPixmapCache::find(targets[i], &pixmap));
QVERIFY(pixmap.width() > 0);
}
delete getters[i];
}
}
- QCOMPARE(QmlGraphicsPixmapCache::pendingRequests(), 0);
+ QCOMPARE(QmlPixmapCache::pendingRequests(), 0);
}
-QTEST_MAIN(tst_qfxpixmapcache)
+QTEST_MAIN(tst_qmlpixmapcache)
-#include "tst_qfxpixmapcache.moc"
+#include "tst_qmlpixmapcache.moc"
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<qreal>(object->property("testSame")), 1.0);
+ QCOMPARE(qvariant_cast<qreal>(object->property("testLess")), 1.0);
+ QCOMPARE(qvariant_cast<qreal>(object->property("testMore")), 1.0);
+ QCOMPARE(qvariant_cast<qreal>(object->property("testFail")), 0.0);
+ QCOMPARE(qvariant_cast<qreal>(object->property("test5")), 1.0);
+ QCOMPARE(qvariant_cast<qreal>(object->property("test6")), 1.11);
+ QCOMPARE(qvariant_cast<qreal>(object->property("test7")), 1.11);
+
+ delete object;
+}
+
void tst_qmlqt::playSound()
{
QEXPECT_FAIL("", "How do we test this?", Abort);
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 @@
+<ListModel>
+ <ListElement>
+ <name>Polly</name>
+ <type>Parrot</type>
+ <age>12</age>
+ <size>Small</size>
+ </ListElement>
+ <ListElement>
+ <name>Penny</name>
+ <type>Turtle</type>
+ <age>4</age>
+ <size>Small</size>
+ </ListElement>
+ <ListElement>
+ <name>Warren</name>
+ <type>Rabbit</type>
+ <age>2</age>
+ <size>Small</size>
+ </ListElement>
+ <ListElement>
+ <name>Spot</name>
+ <type>Dog</type>
+ <age>9</age>
+ <size>Medium</size>
+ </ListElement>
+ <ListElement>
+ <name>Whiskers</name>
+ <type>Cat</type>
+ <age>2</age>
+ <size>Medium</size>
+ </ListElement>
+ <ListElement>
+ <name>Joey</name>
+ <type>Kangaroo</type>
+ <age>1</age>
+ <size>Medium</size>
+ </ListElement>
+ <ListElement>
+ <name>Kimba</name>
+ <type>Bunny</type>
+ <age>65</age>
+ <size>Large</size>
+ </ListElement>
+ <ListElement>
+ <name>Rover</name>
+ <type>Dog</type>
+ <age>5</age>
+ <size>Large</size>
+ </ListElement>
+ <ListElement>
+ <name>Tiny</name>
+ <type>Elephant</type>
+ <age>15</age>
+ <size>Large</size>
+ </ListElement>
+</ListModel>
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 <qtest.h>
+#include <QtDeclarative/qmlengine.h>
+#include <QtDeclarative/qmlcomponent.h>
+#include <private/qmlxmllistmodel_p.h>
+#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<QmlXmlListModel*>(component.create());
+ QVERIFY(listModel != 0);
+ QTRY_COMPARE(listModel->count(), 9);
+
+ QList<int> roles;
+ roles << Qt::UserRole << Qt::UserRole + 1 << Qt::UserRole + 2 << Qt::UserRole + 3;
+ QHash<int, QVariant> 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"