diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-11-03 08:31:56 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-11-03 08:31:56 (GMT) |
commit | 1cb4f7af901aab2d774731183123cd898561b13a (patch) | |
tree | 205513a2dac1f35bf9af500b0171b6f72b02c199 | |
parent | 0cda0d00f95cbcd292f4b1f5ed4a47d43e0ac825 (diff) | |
parent | 3550d1b22b3a5f8f974ca2ba17a3d4f5d52b3743 (diff) | |
download | Qt-1cb4f7af901aab2d774731183123cd898561b13a.zip Qt-1cb4f7af901aab2d774731183123cd898561b13a.tar.gz Qt-1cb4f7af901aab2d774731183123cd898561b13a.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
19 files changed, 789 insertions, 81 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicsitem.cpp b/src/declarative/graphicsitems/qmlgraphicsitem.cpp index 0e741c4..5083f43 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsitem.cpp @@ -2918,5 +2918,5 @@ QML_DECLARE_TYPE(QmlGraphicsKeysAttached) QML_DECLARE_TYPEINFO(QmlGraphicsKeysAttached, QML_HAS_ATTACHED_PROPERTIES) QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Keys,QmlGraphicsKeysAttached) QML_DECLARE_TYPE(QmlGraphicsKeyNavigationAttached) +QML_DECLARE_TYPEINFO(QmlGraphicsKeyNavigationAttached, QML_HAS_ATTACHED_PROPERTIES) QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,KeyNavigation,QmlGraphicsKeyNavigationAttached) - diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 7242a1d..c562e02 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -181,8 +181,6 @@ QmlEnginePrivate::~QmlEnginePrivate() typeNameClass = 0; delete listClass; listClass = 0; - delete networkAccessManager; - networkAccessManager = 0; delete nodeListClass; nodeListClass = 0; delete namedNodeMapClass; @@ -336,14 +334,16 @@ QmlContext *QmlEngine::rootContext() Sets the common QNetworkAccessManager, \a network, used by all QML elements instantiated by this engine. - Any previously set manager is deleted and \a network is owned by the - QmlEngine. This method should only be called before any QmlComponents are - instantiated. + If the parent of \a network is this engine, the engine takes ownership and + will delete it as needed. Otherwise, ownership remains with the caller. + + This method should only be called before any QmlComponents are instantiated. */ void QmlEngine::setNetworkAccessManager(QNetworkAccessManager *network) { Q_D(QmlEngine); - delete d->networkAccessManager; + if (d->networkAccessManager && d->networkAccessManager->parent() == this) + delete d->networkAccessManager; d->networkAccessManager = network; } @@ -358,7 +358,7 @@ QNetworkAccessManager *QmlEngine::networkAccessManager() const { Q_D(const QmlEngine); if (!d->networkAccessManager) - d->networkAccessManager = new QNetworkAccessManager; + d->networkAccessManager = new QNetworkAccessManager(const_cast<QmlEngine*>(this)); return d->networkAccessManager; } diff --git a/src/declarative/util/qmltimer.cpp b/src/declarative/util/qmltimer.cpp index 268d5ec..2e844be 100644 --- a/src/declarative/util/qmltimer.cpp +++ b/src/declarative/util/qmltimer.cpp @@ -57,12 +57,12 @@ public: : interval(1000), running(false), repeating(false), triggeredOnStart(false) , classBegun(false), componentComplete(false) {} int interval; - bool running; - bool repeating; - bool triggeredOnStart; QPauseAnimation pause; - bool classBegun; - bool componentComplete; + bool running : 1; + bool repeating : 1; + bool triggeredOnStart : 1; + bool classBegun : 1; + bool componentComplete : 1; }; /*! @@ -82,6 +82,9 @@ public: } \endqml + QmlTimer is synchronized with the animation timer. Since the animation + timer is usually set to 60fps, the resolution of QmlTimer will be + at best 16ms. */ QmlTimer::QmlTimer(QObject *parent) @@ -89,7 +92,6 @@ QmlTimer::QmlTimer(QObject *parent) { Q_D(QmlTimer); connect(&d->pause, SIGNAL(currentLoopChanged(int)), this, SLOT(ticked())); - connect(&d->pause, SIGNAL(finished()), this, SLOT(ticked())); connect(&d->pause, SIGNAL(stateChanged(QAbstractAnimation::State,QAbstractAnimation::State)) , this, SLOT(stateChanged(QAbstractAnimation::State,QAbstractAnimation::State))); d->pause.setLoopCount(1); @@ -259,7 +261,9 @@ void QmlTimer::componentComplete() */ void QmlTimer::ticked() { - emit triggered(); + Q_D(QmlTimer); + if (d->running) + emit triggered(); } void QmlTimer::stateChanged(QAbstractAnimation::State, QAbstractAnimation::State state) @@ -267,6 +271,7 @@ void QmlTimer::stateChanged(QAbstractAnimation::State, QAbstractAnimation::State Q_D(QmlTimer); if (d->running && state != QAbstractAnimation::Running) { d->running = false; + emit triggered(); emit runningChanged(); } } diff --git a/tests/auto/declarative/behaviors/data/simple.qml b/tests/auto/declarative/behaviors/data/simple.qml index a715f7b..37c3915 100644 --- a/tests/auto/declarative/behaviors/data/simple.qml +++ b/tests/auto/declarative/behaviors/data/simple.qml @@ -6,7 +6,10 @@ Rectangle { id: rect objectName: "MyRect" width: 100; height: 100; color: "green" - x: Behavior { NumberAnimation { duration: 200; } } + x: Behavior { + objectName: "MyBehavior"; + NumberAnimation { duration: 200; } + } } MouseRegion { id: clicker diff --git a/tests/auto/declarative/behaviors/tst_behaviors.cpp b/tests/auto/declarative/behaviors/tst_behaviors.cpp index 9803a9d..29c631d 100644 --- a/tests/auto/declarative/behaviors/tst_behaviors.cpp +++ b/tests/auto/declarative/behaviors/tst_behaviors.cpp @@ -43,6 +43,7 @@ #include <QtDeclarative/qmlcomponent.h> #include <QtDeclarative/qmlview.h> #include <private/qmlgraphicsrectangle_p.h> +#include <private/qmlbehavior_p.h> #include <private/qmlanimation_p.h> class tst_behaviors : public QObject @@ -60,6 +61,9 @@ private slots: void replaceBinding(); //void transitionOverrides(); void group(); + void emptyBehavior(); + void nonSelectingBehavior(); + void reassignedAnimation(); }; void tst_behaviors::simpleBehavior() @@ -68,6 +72,7 @@ void tst_behaviors::simpleBehavior() QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/simple.qml")); QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create()); QVERIFY(rect); + QVERIFY(qobject_cast<QmlBehavior*>(rect->findChild<QmlBehavior*>("MyBehavior"))->animation()); rect->setState("moved"); QTest::qWait(100); @@ -189,6 +194,44 @@ void tst_behaviors::group() } } +void tst_behaviors::emptyBehavior() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/empty.qml")); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create()); + QVERIFY(rect); + + rect->setState("moved"); + qreal x = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect"))->x(); + QCOMPARE(x, qreal(200)); //should change immediately +} + +void tst_behaviors::nonSelectingBehavior() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/nonSelecting.qml")); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create()); + QVERIFY(rect); + + rect->setState("moved"); + qreal x = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect"))->x(); + QCOMPARE(x, qreal(200)); //should change immediately +} + +void tst_behaviors::reassignedAnimation() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/reassignedAnimation.qml")); + QTest::ignoreMessage(QtWarningMsg, "QML QmlBehavior (file://" SRCDIR "/data/reassignedAnimation.qml:9:12) Can't change the animation assigned to a Behavior."); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create()); + QVERIFY(rect); + + rect->setState("moved"); + QTest::qWait(200 + 100); + qreal x = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect"))->x(); + QCOMPARE(x, qreal(200)); //i.e. the right behavior has been triggered +} + QTEST_MAIN(tst_behaviors) #include "tst_behaviors.moc" diff --git a/tests/auto/declarative/examples/data/webbrowser/webbrowser.qml b/tests/auto/declarative/examples/data/webbrowser/webbrowser.qml new file mode 100644 index 0000000..bdf3290 --- /dev/null +++ b/tests/auto/declarative/examples/data/webbrowser/webbrowser.qml @@ -0,0 +1,6 @@ +import Qt.VisualTest 4.6 + +VisualTest { + Frame { msec: 0 } + Frame { msec: 1000 } +} diff --git a/tests/auto/declarative/examples/tst_examples.cpp b/tests/auto/declarative/examples/tst_examples.cpp index ac12204..d758101 100644 --- a/tests/auto/declarative/examples/tst_examples.cpp +++ b/tests/auto/declarative/examples/tst_examples.cpp @@ -42,6 +42,7 @@ #include <QLibraryInfo> #include <QDir> #include <QProcess> +#include <QDebug> class tst_examples : public QObject { @@ -179,9 +180,12 @@ void tst_examples::examples() { QFETCH(QString, file); + QFileInfo fi(file); + QFileInfo dir(fi.path()); + QFileInfo testdata("data/"+dir.baseName()+"/"+fi.baseName()); QStringList arguments; - arguments << "-script" << "data/dummytest" - << "-scriptopts" << "play,exitoncomplete,exitonfailure" + arguments << "-script" << (testdata.exists() ? testdata.filePath() : QLatin1String("data/dummytest")) + << "-scriptopts" << "play,testerror,exitoncomplete,exitonfailure" << file; QProcess p; p.start(qmlviewer, arguments); diff --git a/tests/auto/declarative/qmlfontloader/data/Fontin-Bold.ttf b/tests/auto/declarative/qmlfontloader/data/Fontin-Bold.ttf Binary files differnew file mode 100644 index 0000000..f6a33b0 --- /dev/null +++ b/tests/auto/declarative/qmlfontloader/data/Fontin-Bold.ttf diff --git a/tests/auto/declarative/qfxtext/qfxtext.pro b/tests/auto/declarative/qmlfontloader/qmlfontloader.pro index 1f3fe37..0ecfde0 100644 --- a/tests/auto/declarative/qfxtext/qfxtext.pro +++ b/tests/auto/declarative/qmlfontloader/qmlfontloader.pro @@ -2,4 +2,4 @@ load(qttest_p4) contains(QT_CONFIG,declarative): QT += declarative gui macx:CONFIG -= app_bundle -SOURCES += tst_qfxtext.cpp +SOURCES += tst_qmlfontloader.cpp diff --git a/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp b/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp new file mode 100644 index 0000000..a65ecf4 --- /dev/null +++ b/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** 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/qmlfontloader_p.h> + +class tst_qmlfontloader : public QObject + +{ + Q_OBJECT +public: + tst_qmlfontloader(); + +private slots: + void namedfont(); + void localfont(); + +private slots: + +private: + QmlEngine engine; +}; + +tst_qmlfontloader::tst_qmlfontloader() +{ +} + +void tst_qmlfontloader::namedfont() +{ + QString componentStr = "import Qt 4.6\nFontLoader { name: \"Helvetica\" }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlFontLoader *fontObject = qobject_cast<QmlFontLoader*>(component.create()); + + QVERIFY(fontObject != 0); + QCOMPARE(fontObject->name(), QString("Helvetica")); +} + +void tst_qmlfontloader::localfont() +{ + QString componentStr = "import Qt 4.6\nFontLoader { source: \"data/Fontin-Bold.ttf\" }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlFontLoader *fontObject = qobject_cast<QmlFontLoader*>(component.create()); + + QVERIFY(fontObject != 0); + QCOMPARE(fontObject->name(), QString("Fontin")); +} + +QTEST_MAIN(tst_qmlfontloader) + +#include "tst_qmlfontloader.moc" diff --git a/tests/auto/declarative/qmlgraphicstext/qmlgraphicstext.pro b/tests/auto/declarative/qmlgraphicstext/qmlgraphicstext.pro new file mode 100644 index 0000000..1d8c59f --- /dev/null +++ b/tests/auto/declarative/qmlgraphicstext/qmlgraphicstext.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative gui +macx:CONFIG -= app_bundle + +SOURCES += tst_qmlgraphicstext.cpp diff --git a/tests/auto/declarative/qfxtext/tst_qfxtext.cpp b/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp index 173a3b4..d53de59 100644 --- a/tests/auto/declarative/qfxtext/tst_qfxtext.cpp +++ b/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp @@ -45,12 +45,12 @@ #include <private/qmlgraphicstext_p.h> #include <QFontMetrics> -class tst_qfxtext : public QObject +class tst_qmlgraphicstext : public QObject { Q_OBJECT public: - tst_qfxtext(); + tst_qmlgraphicstext(); private slots: void text(); @@ -64,6 +64,7 @@ private slots: void font(); void style(); void color(); + void smooth(); private: QStringList standard; @@ -83,7 +84,7 @@ private: QmlEngine engine; }; -tst_qfxtext::tst_qfxtext() +tst_qmlgraphicstext::tst_qmlgraphicstext() { standard << "the quick brown fox jumped over the lazy dog" << "the quick brown fox\n jumped over the lazy dog"; @@ -136,7 +137,7 @@ tst_qfxtext::tst_qfxtext() // } -void tst_qfxtext::text() +void tst_qmlgraphicstext::text() { { QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"\" }", QUrl("file://")); @@ -168,7 +169,7 @@ void tst_qfxtext::text() } } -void tst_qfxtext::width() +void tst_qmlgraphicstext::width() { // uses Font metrics to find the width for standard and document to find the width for rich { @@ -207,39 +208,41 @@ void tst_qfxtext::width() } } -void tst_qfxtext::wrap() +void tst_qmlgraphicstext::wrap() { - // XXX Poor coverage - should at least be testing an expected height. - + int textHeight = 0; // for specified width and wrap set true { - QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"\"; wrap: true; width: 300 }", QUrl("file://")); + QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"Hello\"; wrap: true; width: 300 }", QUrl("file://")); QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create()); + textHeight = textObject->height(); QCOMPARE(textObject->width(), 300.); } for (int i = 0; i < standard.size(); i++) { - QString componentStr = "import Qt 4.6\nText { wrap: true; width: 300; text: \"" + standard.at(i) + "\" }"; + QString componentStr = "import Qt 4.6\nText { wrap: true; width: 30; text: \"" + standard.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create()); - QCOMPARE(textObject->width(), 300.); + QCOMPARE(textObject->width(), 30.); + QVERIFY(textObject->height() > textHeight); } for (int i = 0; i < richText.size(); i++) { - QString componentStr = "import Qt 4.6\nText { wrap: true; width: 300; text: \"" + richText.at(i) + "\" }"; + QString componentStr = "import Qt 4.6\nText { wrap: true; width: 30; text: \"" + richText.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create()); - QCOMPARE(textObject->width(), 300.); + QCOMPARE(textObject->width(), 30.); + QVERIFY(textObject->height() > textHeight); } } -void tst_qfxtext::elide() +void tst_qmlgraphicstext::elide() { for (Qt::TextElideMode m = Qt::ElideLeft; m<=Qt::ElideNone; m=Qt::TextElideMode(int(m)+1)) { const char* elidename[]={"ElideLeft", "ElideRight", "ElideMiddle", "ElideNone"}; @@ -276,7 +279,7 @@ void tst_qfxtext::elide() } //the alignment tests may be trivial o.oa -void tst_qfxtext::horizontalAlignment() +void tst_qmlgraphicstext::horizontalAlignment() { //test one align each, and then test if two align fails. @@ -306,7 +309,7 @@ void tst_qfxtext::horizontalAlignment() } -void tst_qfxtext::verticalAlignment() +void tst_qmlgraphicstext::verticalAlignment() { //test one align each, and then test if two align fails. @@ -317,7 +320,6 @@ void tst_qfxtext::verticalAlignment() QString componentStr = "import Qt 4.6\nText { verticalAlignment: \"" + verticalAlignmentmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create()); - QCOMPARE((int)textObject->vAlign(), (int)verticalAlignmentments.at(j)); } } @@ -336,10 +338,10 @@ void tst_qfxtext::verticalAlignment() } -void tst_qfxtext::font() +void tst_qmlgraphicstext::font() { //test size, then bold, then italic, then family - { + { QString componentStr = "import Qt 4.6\nText { font.pointSize: 40; text: \"Hello World\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create()); @@ -349,6 +351,16 @@ void tst_qfxtext::font() QCOMPARE(textObject->font().italic(), false); } + { + QString componentStr = "import Qt 4.6\nText { font.pixelSize: 40; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create()); + + QCOMPARE(textObject->font().pixelSize(), 40); + QCOMPARE(textObject->font().bold(), false); + QCOMPARE(textObject->font().italic(), false); + } + { QString componentStr = "import Qt 4.6\nText { font.bold: true; text: \"Hello World\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); @@ -386,21 +398,21 @@ void tst_qfxtext::font() } } -void tst_qfxtext::style() +void tst_qmlgraphicstext::style() { //test style for (int i = 0; i < styles.size(); i++) { - QString componentStr = "import Qt 4.6\nText { style: \"" + styleStrings.at(i) + "\"; text: \"Hello World\" }"; + QString componentStr = "import Qt 4.6\nText { style: \"" + styleStrings.at(i) + "\"; styleColor: \"white\"; text: \"Hello World\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create()); QCOMPARE((int)textObject->style(), (int)styles.at(i)); - QCOMPARE(textObject->styleColor(), QColor()); + QCOMPARE(textObject->styleColor(), QColor("white")); } } -void tst_qfxtext::color() +void tst_qmlgraphicstext::color() { //test style for (int i = 0; i < colorStrings.size(); i++) @@ -448,6 +460,41 @@ void tst_qfxtext::color() QCOMPARE(textObject->color(), testColor); } } -QTEST_MAIN(tst_qfxtext) -#include "tst_qfxtext.moc" +void tst_qmlgraphicstext::smooth() +{ + for (int i = 0; i < standard.size(); i++) + { + { + QString componentStr = "import Qt 4.6\nText { smooth: true; text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), true); + } + { + QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), false); + } + } + for (int i = 0; i < richText.size(); i++) + { + { + QString componentStr = "import Qt 4.6\nText { smooth: true; text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), true); + } + { + QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), false); + } + } +} + +QTEST_MAIN(tst_qmlgraphicstext) + +#include "tst_qmlgraphicstext.moc" diff --git a/tests/auto/declarative/visual/selftest_noimages/data/selftest_noimages.qml b/tests/auto/declarative/visual/selftest_noimages/data/selftest_noimages.qml new file mode 100644 index 0000000..3104906 --- /dev/null +++ b/tests/auto/declarative/visual/selftest_noimages/data/selftest_noimages.qml @@ -0,0 +1,470 @@ +import Qt.VisualTest 4.6 + +VisualTest { + Frame { + msec: 0 + } + Frame { + msec: 16 + } + Frame { + msec: 32 + } + Frame { + msec: 48 + } + Frame { + msec: 64 + } + Frame { + msec: 80 + } + Frame { + msec: 96 + } + Frame { + msec: 112 + } + Frame { + msec: 128 + } + Frame { + msec: 144 + } + Frame { + msec: 160 + } + Frame { + msec: 176 + } + Frame { + msec: 192 + } + Frame { + msec: 208 + } + Frame { + msec: 224 + } + Frame { + msec: 240 + } + Frame { + msec: 256 + } + Frame { + msec: 272 + } + Frame { + msec: 288 + } + Frame { + msec: 304 + } + Frame { + msec: 320 + } + Frame { + msec: 336 + } + Frame { + msec: 352 + } + Frame { + msec: 368 + } + Frame { + msec: 384 + } + Frame { + msec: 400 + } + Frame { + msec: 416 + } + Frame { + msec: 432 + } + Frame { + msec: 448 + } + Frame { + msec: 464 + } + Frame { + msec: 480 + } + Frame { + msec: 496 + } + Frame { + msec: 512 + } + Frame { + msec: 528 + } + Frame { + msec: 544 + } + Frame { + msec: 560 + } + Frame { + msec: 576 + } + Frame { + msec: 592 + } + Frame { + msec: 608 + } + Frame { + msec: 624 + } + Frame { + msec: 640 + } + Frame { + msec: 656 + } + Frame { + msec: 672 + } + Frame { + msec: 688 + } + Frame { + msec: 704 + } + Frame { + msec: 720 + } + Frame { + msec: 736 + } + Frame { + msec: 752 + } + Frame { + msec: 768 + } + Frame { + msec: 784 + } + Frame { + msec: 800 + } + Frame { + msec: 816 + } + Frame { + msec: 832 + } + Frame { + msec: 848 + } + Frame { + msec: 864 + } + Frame { + msec: 880 + } + Frame { + msec: 896 + } + Frame { + msec: 912 + } + Frame { + msec: 928 + } + Frame { + msec: 944 + } + Frame { + msec: 960 + } + Frame { + msec: 976 + } + Frame { + msec: 992 + } + Frame { + msec: 1008 + } + Frame { + msec: 1024 + } + Frame { + msec: 1040 + } + Frame { + msec: 1056 + } + Frame { + msec: 1072 + } + Frame { + msec: 1088 + } + Frame { + msec: 1104 + } + Frame { + msec: 1120 + } + Frame { + msec: 1136 + } + Frame { + msec: 1152 + } + Frame { + msec: 1168 + } + Frame { + msec: 1184 + } + Frame { + msec: 1200 + } + Frame { + msec: 1216 + } + Frame { + msec: 1232 + } + Frame { + msec: 1248 + } + Frame { + msec: 1264 + } + Frame { + msec: 1280 + } + Frame { + msec: 1296 + } + Frame { + msec: 1312 + } + Frame { + msec: 1328 + } + Frame { + msec: 1344 + } + Frame { + msec: 1360 + } + Mouse { + type: 2 + button: 1 + buttons: 1 + x: 77; y: 7 + modifiers: 0 + sendToViewport: true + } + Frame { + msec: 1376 + } + Frame { + msec: 1392 + } + Frame { + msec: 1408 + } + Frame { + msec: 1424 + } + Frame { + msec: 1440 + } + Mouse { + type: 3 + button: 1 + buttons: 0 + x: 77; y: 7 + modifiers: 0 + sendToViewport: true + } + Frame { + msec: 1456 + } + Frame { + msec: 1472 + } + Frame { + msec: 1488 + } + Frame { + msec: 1504 + } + Frame { + msec: 1520 + } + Frame { + msec: 1536 + } + Frame { + msec: 1552 + } + Frame { + msec: 1568 + } + Frame { + msec: 1584 + } + Frame { + msec: 1600 + } + Frame { + msec: 1616 + } + Frame { + msec: 1632 + } + Frame { + msec: 1648 + } + Frame { + msec: 1664 + } + Frame { + msec: 1680 + } + Frame { + msec: 1696 + } + Frame { + msec: 1712 + } + Frame { + msec: 1728 + } + Frame { + msec: 1744 + } + Frame { + msec: 1760 + } + Frame { + msec: 1776 + } + Frame { + msec: 1792 + } + Frame { + msec: 1808 + } + Frame { + msec: 1824 + } + Frame { + msec: 1840 + } + Frame { + msec: 1856 + } + Frame { + msec: 1872 + } + Frame { + msec: 1888 + } + Frame { + msec: 1904 + } + Frame { + msec: 1920 + } + Frame { + msec: 1936 + } + Frame { + msec: 1952 + } + Frame { + msec: 1968 + } + Frame { + msec: 1984 + } + Frame { + msec: 2000 + } + Frame { + msec: 2016 + } + Frame { + msec: 2032 + } + Frame { + msec: 2048 + } + Frame { + msec: 2064 + } + Frame { + msec: 2080 + } + Frame { + msec: 2096 + } + Frame { + msec: 2112 + } + Frame { + msec: 2128 + } + Frame { + msec: 2144 + } + Frame { + msec: 2160 + } + Frame { + msec: 2176 + } + Frame { + msec: 2192 + } + Frame { + msec: 2208 + } + Frame { + msec: 2224 + } + Frame { + msec: 2240 + } + Frame { + msec: 2256 + } + Frame { + msec: 2272 + } + Frame { + msec: 2288 + } + Frame { + msec: 2304 + } + Frame { + msec: 2320 + } + Frame { + msec: 2336 + } + Frame { + msec: 2352 + } + Frame { + msec: 2368 + } + Frame { + msec: 2384 + } +} diff --git a/tests/auto/declarative/visual/selftest_noimages/selftest_noimages.qml b/tests/auto/declarative/visual/selftest_noimages/selftest_noimages.qml new file mode 100644 index 0000000..21a19bc --- /dev/null +++ b/tests/auto/declarative/visual/selftest_noimages/selftest_noimages.qml @@ -0,0 +1,9 @@ +import Qt 4.6 +Text { + property string error: "not pressed" + text: (new Date()).valueOf() + MouseRegion { + anchors.fill: parent + onPressed: error="" + } +} diff --git a/tests/auto/declarative/visual/tst_visual.cpp b/tests/auto/declarative/visual/tst_visual.cpp index a79b6f9..0cd712b 100644 --- a/tests/auto/declarative/visual/tst_visual.cpp +++ b/tests/auto/declarative/visual/tst_visual.cpp @@ -47,7 +47,7 @@ #include <QProcess> #include <QFile> -enum Mode { Record, Play, TestVisuals, UpdateVisuals, UpdatePlatformVisuals, Test }; +enum Mode { Record, RecordNoVisuals, Play, TestVisuals, RemoveVisuals, UpdateVisuals, UpdatePlatformVisuals, Test }; static QString testdir; class tst_visual : public QObject @@ -115,7 +115,7 @@ void tst_visual::visual() QStringList arguments; arguments << "-script" << testdata - << "-scriptopts" << "play,testimages,exitoncomplete,exitonfailure" + << "-scriptopts" << "play,testimages,testerror,exitoncomplete,exitonfailure" << file; QProcess p; p.start(qmlviewer, arguments); @@ -208,38 +208,44 @@ void action(Mode mode, const QString &file) QString testdata = tst_visual::toTestScript(file,mode); - if (Record == mode) { - QStringList arguments; - arguments << "-script" << testdata + QStringList arguments; + switch (mode) { + case Test: + // Don't run qmlviewer + break; + case Record: + arguments << "-script" << testdata + << "-scriptopts" << "record,testimages,saveonexit" + << file; + break; + case RecordNoVisuals: + arguments << "-script" << testdata << "-scriptopts" << "record,saveonexit" << file; - QProcess p; - p.setProcessChannelMode(QProcess::ForwardedChannels); - p.start(tst_visual::viewer(), arguments); - p.waitForFinished(); - } else if (Play == mode) { - QStringList arguments; - arguments << "-script" << testdata - << "-scriptopts" << "play,testimages,exitoncomplete" + break; + case Play: + arguments << "-script" << testdata + << "-scriptopts" << "play,testimages,testerror,exitoncomplete" << file; - QProcess p; - p.setProcessChannelMode(QProcess::ForwardedChannels); - p.start(tst_visual::viewer(), arguments); - p.waitForFinished(); - } else if (TestVisuals == mode) { - QStringList arguments; + break; + case TestVisuals: arguments << "-script" << testdata << "-scriptopts" << "play" << file; - QProcess p; - p.setProcessChannelMode(QProcess::ForwardedChannels); - p.start(tst_visual::viewer(), arguments); - p.waitForFinished(); - } else if (UpdateVisuals == mode || UpdatePlatformVisuals == mode) { - QStringList arguments; - arguments << "-script" << testdata + break; + case UpdateVisuals: + case UpdatePlatformVisuals: + arguments << "-script" << testdata + << "-scriptopts" << "play,record,testimages,exitoncomplete,saveonexit" + << file; + break; + case RemoveVisuals: + arguments << "-script" << testdata << "-scriptopts" << "play,record,exitoncomplete,saveonexit" << file; + break; + } + if (!arguments.isEmpty()) { QProcess p; p.setProcessChannelMode(QProcess::ForwardedChannels); p.start(tst_visual::viewer(), arguments); @@ -278,9 +284,15 @@ int main(int argc, char **argv) } else if (arg == "-record" && (ii + 1) < argc) { mode = Record; file = argv[++ii]; + } else if (arg == "-recordnovisuals" && (ii + 1) < argc) { + mode = RecordNoVisuals; + file = argv[++ii]; } else if (arg == "-testvisuals" && (ii + 1) < argc) { mode = TestVisuals; file = argv[++ii]; + } else if (arg == "-removevisuals" && (ii + 1) < argc) { + mode = RemoveVisuals; + file = argv[++ii]; } else if (arg == "-updatevisuals" && (ii + 1) < argc) { mode = UpdateVisuals; file = argv[++ii]; diff --git a/tools/qmlviewer/main.cpp b/tools/qmlviewer/main.cpp index 23194b2..ac0d732 100644 --- a/tools/qmlviewer/main.cpp +++ b/tools/qmlviewer/main.cpp @@ -87,7 +87,8 @@ void scriptOptsUsage() qWarning(" options:"); qWarning(" record ................................... record a new script"); qWarning(" play ..................................... playback an existing script"); - qWarning(" testimages ............................... compare images on playback"); + qWarning(" testimages ............................... record images or compare images on playback"); + qWarning(" testerror ................................ test 'error' property of root item on playback"); qWarning(" exitoncomplete ........................... cleanly exit the viewer on script completion"); qWarning(" exitonfailure ............................ immediately exit the viewer on script failure"); qWarning(" saveonexit ............................... save recording on viewer exit"); @@ -235,6 +236,8 @@ int main(int argc, char ** argv) scriptOptions |= QmlViewer::Record; } else if (option == QLatin1String("testimages")) { scriptOptions |= QmlViewer::TestImages; + } else if (option == QLatin1String("testerror")) { + scriptOptions |= QmlViewer::TestErrorProperty; } else if (option == QLatin1String("exitoncomplete")) { scriptOptions |= QmlViewer::ExitOnComplete; } else if (option == QLatin1String("exitonfailure")) { diff --git a/tools/qmlviewer/qfxtester.cpp b/tools/qmlviewer/qfxtester.cpp index 77e8124..287771b 100644 --- a/tools/qmlviewer/qfxtester.cpp +++ b/tools/qmlviewer/qfxtester.cpp @@ -146,6 +146,13 @@ void QmlGraphicsTester::imagefailure() void QmlGraphicsTester::complete() { + if ((options & QmlViewer::TestErrorProperty) && !hasFailed) { + QString e = m_view->root()->property("error").toString(); + if (!e.isEmpty()) { + qWarning() << "Test failed:" << e; + hasFailed = true; + } + } if (options & QmlViewer::ExitOnComplete) QApplication::exit(hasFailed?-1:0); @@ -240,13 +247,15 @@ void QmlGraphicsTester::updateCurrentTime(int msec) QImage img(m_view->width(), m_view->height(), QImage::Format_RGB32); - QPainter p(&img); - m_view->render(&p); + if (options & QmlViewer::TestImages) { + QPainter p(&img); + m_view->render(&p); + } FrameEvent fe; fe.msec = msec; - if (msec == 0) { - // Skip first frame + if (msec == 0 || !(options & QmlViewer::TestImages)) { + // Skip first frame, skip if not doing images } else if (0 == (m_savedFrameEvents.count() % 60)) { fe.image = img; } else { @@ -297,6 +306,8 @@ void QmlGraphicsTester::updateCurrentTime(int msec) QObject *event = testscript->event(testscriptidx); if (QmlGraphicsVisualTestFrame *frame = qobject_cast<QmlGraphicsVisualTestFrame *>(event)) { + if ((options & QmlViewer::TestImages) && (options & QmlViewer::Record)) + break; // recording and playing, no point "testing" results if (frame->msec() < msec) { if (options & QmlViewer::TestImages) { qWarning() << "QmlGraphicsTester: Extra frame. Seen:" @@ -304,7 +315,7 @@ void QmlGraphicsTester::updateCurrentTime(int msec) imagefailure(); } } else if (frame->msec() == msec) { - if (frame->hash().toUtf8() != fe.hash.toHex()) { + if (!frame->hash().isEmpty() && frame->hash().toUtf8() != fe.hash.toHex()) { if (options & QmlViewer::TestImages) { qWarning() << "QmlGraphicsTester: Mismatched frame hash. Seen:" << fe.hash.toHex() << "Expected:" diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index 248ff24..b9f3e67 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -249,7 +249,7 @@ private: class ConfiguredNetworkAccessManager : public QNetworkAccessManager { public: - ConfiguredNetworkAccessManager() { } + ConfiguredNetworkAccessManager(QObject *parent) : QNetworkAccessManager(parent) { } QNetworkReply *createRequest (Operation op, const QNetworkRequest &req, QIODevice * outgoingData) { @@ -334,7 +334,7 @@ QmlViewer::QmlViewer(QWidget *parent, Qt::WindowFlags flags) canvas->setAttribute(Qt::WA_OpaquePaintEvent); canvas->setAttribute(Qt::WA_NoSystemBackground); canvas->setContentResizable(!skin || !scaleSkin); - canvas->engine()->setNetworkAccessManager(new ConfiguredNetworkAccessManager); + canvas->engine()->setNetworkAccessManager(new ConfiguredNetworkAccessManager(canvas->engine())); canvas->setFocus(); QObject::connect(canvas, SIGNAL(sceneResized(QSize)), this, SLOT(sceneResized(QSize))); diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h index a63b938..b366401 100644 --- a/tools/qmlviewer/qmlviewer.h +++ b/tools/qmlviewer/qmlviewer.h @@ -66,9 +66,10 @@ public: Play = 0x00000001, Record = 0x00000002, TestImages = 0x00000004, - SaveOnExit = 0x00000008, - ExitOnComplete = 0x00000010, - ExitOnFailure = 0x00000020 + TestErrorProperty = 0x00000008, + SaveOnExit = 0x00000010, + ExitOnComplete = 0x00000020, + ExitOnFailure = 0x00000040 }; Q_DECLARE_FLAGS(ScriptOptions, ScriptOption) void setScript(const QString &s) { m_script = s; } |