From 564baee7e729f1c6f766cecabc4fcc62291e0d0f Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 4 Mar 2010 11:06:04 +1000 Subject: Removed unused variable --- src/declarative/graphicsitems/qdeclarativeflickable.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index 2fdd720..63c97e0 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -154,7 +154,6 @@ void QDeclarativeFlickablePrivate::init() */ qreal QDeclarativeFlickablePrivate::overShootDistance(qreal velocity, qreal size) { - Q_Q(QDeclarativeFlickable); if (maxVelocity <= 0) return 0.0; -- cgit v0.12 From 81952293be3328dc2f62f557478042d1e8d04e0d Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Fri, 5 Mar 2010 09:46:34 +1000 Subject: Add mapFromItem() and mapToItem() in QDeclarativeItem. Task-number: QT-2385 --- src/declarative/graphicsitems/qdeclarativeitem.cpp | 54 ++++++++++++++++++++ src/declarative/graphicsitems/qdeclarativeitem.h | 3 ++ .../qdeclarativeitem/data/mapCoordinates.qml | 43 ++++++++++++++++ .../qdeclarativeitem/tst_qdeclarativeitem.cpp | 58 ++++++++++++++++++++++ 4 files changed, 158 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativeitem/data/mapCoordinates.qml diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 5014fd8..cb3f542 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -43,6 +43,7 @@ #include "qdeclarativeitem.h" #include "qdeclarativeevents_p_p.h" +#include #include #include @@ -51,6 +52,7 @@ #include #include #include +#include #include #include @@ -2162,6 +2164,58 @@ void QDeclarativeItem::setKeepMouseGrab(bool keep) } /*! + \qmlmethod object Item::mapFromItem(Item item, int x, int y) + + Maps the point (\a x, \a y), which is in \a item's coordinate system, to + this item's coordinate system, and returns an object with \c x and \c y + properties matching the mapped cooordinate. + + If \a item is a \c null value, this maps the point from the coordinate + system of the root QML view. +*/ +QScriptValue QDeclarativeItem::mapFromItem(const QScriptValue &item, int x, int y) const +{ + QScriptValue sv = QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(this))->newObject(); + QDeclarativeItem *itemObj = qobject_cast(item.toQObject()); + if (!itemObj && !item.isNull()) { + qWarning().nospace() << "mapFromItem() given argument " << item.toString() << " which is neither null nor an Item"; + return 0; + } + + // If QGraphicsItem::mapFromItem() is called with 0, behaves the same as mapFromScene() + QPointF p = qobject_cast(this)->mapFromItem(itemObj, x, y); + sv.setProperty("x", p.x()); + sv.setProperty("y", p.y()); + return sv; +} + +/*! + \qmlmethod object Item::mapToItem(Item item, int x, int y) + + Maps the point (\a x, \a y), which is in this item's coordinate system, to + \a item's coordinate system, and returns an object with \c x and \c y + properties matching the mapped cooordinate. + + If \a item is a \c null value, this maps \a x and \a y to the coordinate + system of the root QML view. +*/ +QScriptValue QDeclarativeItem::mapToItem(const QScriptValue &item, int x, int y) const +{ + QScriptValue sv = QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(this))->newObject(); + QDeclarativeItem *itemObj = qobject_cast(item.toQObject()); + if (!itemObj && !item.isNull()) { + qWarning().nospace() << "mapToItem() given argument " << item.toString() << " which is neither null nor an Item"; + return 0; + } + + // If QGraphicsItem::mapToItem() is called with 0, behaves the same as mapToScene() + QPointF p = qobject_cast(this)->mapToItem(itemObj, x, y); + sv.setProperty("x", p.x()); + sv.setProperty("y", p.y()); + return sv; +} + +/*! \internal This function emits the \e focusChanged signal. diff --git a/src/declarative/graphicsitems/qdeclarativeitem.h b/src/declarative/graphicsitems/qdeclarativeitem.h index 3ae404d..f6fedc7 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.h +++ b/src/declarative/graphicsitems/qdeclarativeitem.h @@ -159,6 +159,9 @@ public: bool keepMouseGrab() const; void setKeepMouseGrab(bool); + Q_INVOKABLE QScriptValue mapFromItem(const QScriptValue &item, int x, int y) const; + Q_INVOKABLE QScriptValue mapToItem(const QScriptValue &item, int x, int y) const; + QDeclarativeAnchorLine left() const; QDeclarativeAnchorLine right() const; QDeclarativeAnchorLine horizontalCenter() const; diff --git a/tests/auto/declarative/qdeclarativeitem/data/mapCoordinates.qml b/tests/auto/declarative/qdeclarativeitem/data/mapCoordinates.qml new file mode 100644 index 0000000..40a2106 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeitem/data/mapCoordinates.qml @@ -0,0 +1,43 @@ +import Qt 4.6 + +Item { + id: root; objectName: "root" + width: 200; height: 200 + + Item { id: itemA; objectName: "itemA"; x: 50; y: 50 } + + Item { + x: 50; y: 50 + Item { id: itemB; objectName: "itemB"; x: 100; y: 100 } + } + + function mapAToB(x, y) { + var pos = itemA.mapToItem(itemB, x, y) + return Qt.point(pos.x, pos.y) + } + + function mapAFromB(x, y) { + var pos = itemA.mapFromItem(itemB, x, y) + return Qt.point(pos.x, pos.y) + } + + function mapAToNull(x, y) { + var pos = itemA.mapToItem(null, x, y) + return Qt.point(pos.x, pos.y) + } + + function mapAFromNull(x, y) { + var pos = itemA.mapFromItem(null, x, y) + return Qt.point(pos.x, pos.y) + } + + function checkMapAToInvalid(x, y) { + var pos = itemA.mapToItem(1122, x, y) + return pos.x == undefined && pos.y == undefined + } + + function checkMapAFromInvalid(x, y) { + var pos = itemA.mapFromItem(1122, x, y) + return pos.x == undefined && pos.y == undefined + } +} diff --git a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp index 36dcf1f..3e69db9 100644 --- a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp +++ b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp @@ -58,6 +58,8 @@ private slots: void keyNavigation(); void smooth(); void clip(); + void mapCoordinates(); + void mapCoordinates_data(); private: template @@ -288,6 +290,62 @@ void tst_QDeclarativeItem::clip() QCOMPARE(spy.count(),2); } +void tst_QDeclarativeItem::mapCoordinates() +{ + QFETCH(int, x); + QFETCH(int, y); + + QDeclarativeView *canvas = new QDeclarativeView(0); + canvas->setFixedSize(300, 300); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/mapCoordinates.qml")); + canvas->show(); + qApp->processEvents(); + + QDeclarativeItem *root = qobject_cast(canvas->rootObject()); + QVERIFY(root != 0); + QDeclarativeItem *a = findItem(canvas->rootObject(), "itemA"); + QVERIFY(a != 0); + QDeclarativeItem *b = findItem(canvas->rootObject(), "itemB"); + QVERIFY(b != 0); + + QVariant result; + + QVERIFY(QMetaObject::invokeMethod(root, "mapAToB", + Q_RETURN_ARG(QVariant, result), Q_ARG(QVariant, x), Q_ARG(QVariant, y))); + QCOMPARE(result.value(), qobject_cast(a)->mapToItem(b, x, y)); + + QVERIFY(QMetaObject::invokeMethod(root, "mapAFromB", + Q_RETURN_ARG(QVariant, result), Q_ARG(QVariant, x), Q_ARG(QVariant, y))); + QCOMPARE(result.value(), qobject_cast(a)->mapFromItem(b, x, y)); + + QVERIFY(QMetaObject::invokeMethod(root, "mapAToNull", + Q_RETURN_ARG(QVariant, result), Q_ARG(QVariant, x), Q_ARG(QVariant, y))); + QCOMPARE(result.value(), qobject_cast(a)->mapToScene(x, y)); + + QVERIFY(QMetaObject::invokeMethod(root, "mapAFromNull", + Q_RETURN_ARG(QVariant, result), Q_ARG(QVariant, x), Q_ARG(QVariant, y))); + QCOMPARE(result.value(), qobject_cast(a)->mapFromScene(x, y)); + + QTest::ignoreMessage(QtWarningMsg, "mapToItem() given argument \"1122\" which is neither null nor an Item"); + QVERIFY(QMetaObject::invokeMethod(root, "checkMapAToInvalid", + Q_RETURN_ARG(QVariant, result), Q_ARG(QVariant, x), Q_ARG(QVariant, y))); + QVERIFY(result.toBool()); + + QTest::ignoreMessage(QtWarningMsg, "mapFromItem() given argument \"1122\" which is neither null nor an Item"); + QVERIFY(QMetaObject::invokeMethod(root, "checkMapAFromInvalid", + Q_RETURN_ARG(QVariant, result), Q_ARG(QVariant, x), Q_ARG(QVariant, y))); + QVERIFY(result.toBool()); +} + +void tst_QDeclarativeItem::mapCoordinates_data() +{ + QTest::addColumn("x"); + QTest::addColumn("y"); + + for (int i=-20; i<=20; i+=10) + QTest::newRow(QTest::toString(i)) << i << i; +} + template T *tst_QDeclarativeItem::findItem(QGraphicsObject *parent, const QString &objectName) { -- cgit v0.12 From 8274de2d952181d27f24ec9bee7e353e35dc39db Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 5 Mar 2010 09:53:09 +1000 Subject: RotationAnimation docs + test. Task-number: QTBUG-8613 --- doc/src/declarative/elements.qdoc | 1 + src/declarative/util/qdeclarativeanimation.cpp | 22 ++++---- .../qdeclarativeanimations/data/rotation.qml | 48 ++++++++++++++++++ .../tst_qdeclarativeanimations.cpp | 58 ++++++++++++++++++++++ 4 files changed, 119 insertions(+), 10 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativeanimations/data/rotation.qml diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc index 6cca39b..22810e3 100644 --- a/doc/src/declarative/elements.qdoc +++ b/doc/src/declarative/elements.qdoc @@ -71,6 +71,7 @@ The following table lists the QML elements provided by the Qt Declarative module \o \l PropertyAnimation \o \l NumberAnimation \o \l ColorAnimation +\o \l RotationAnimation \o \l SequentialAnimation \o \l ParallelAnimation \o \l PauseAnimation diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index 76b6a58..d1a3770 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -1341,24 +1341,26 @@ void QDeclarativeVector3dAnimation::setTo(QVector3D t) \brief The RotationAnimation element allows you to animate rotations. RotationAnimation is a specialized PropertyAnimation that gives control - over the direction of rotation. + over the direction of rotation. By default, it will rotate + via the shortest path; for example, a rotation from 20 to 340 degrees will + rotation 40 degrees counterclockwise. - The RotationAnimation in the following example ensures that we always take - the shortest rotation path when switching between our states. + When used in a transition RotationAnimation will rotate all + properties named "rotation" or "angle". You can override this by providing + your own properties via \c properties or \c property. + + In the following example we use RotationAnimation to animate the rotation + between states via the shortest path. \qml states: { State { name: "180"; PropertyChanges { target: myItem; rotation: 180 } } - State { name: "-180"; PropertyChanges { target: myItem; rotation: -180 } } - State { name: "180"; PropertyChanges { target: myItem; rotation: 270 } } + State { name: "90"; PropertyChanges { target: myItem; rotation: 90 } } + State { name: "-90"; PropertyChanges { target: myItem; rotation: -90 } } } transition: Transition { - RotationAnimation { direction: RotationAnimation.Shortest } + RotationAnimation { } } \endqml - - By default, when used in a transition RotationAnimation will rotate all - properties named "rotation" or "angle". You can override this by providing - your own properties via \c properties or \c property. */ /*! diff --git a/tests/auto/declarative/qdeclarativeanimations/data/rotation.qml b/tests/auto/declarative/qdeclarativeanimations/data/rotation.qml new file mode 100644 index 0000000..e9c57d4 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeanimations/data/rotation.qml @@ -0,0 +1,48 @@ +import Qt 4.6 + +Rectangle { + width: 600; height: 200 + + Row { + spacing: 5 + Rectangle { + id: rr + objectName: "rr" + color: "red" + width: 100; height: 100 + } + Rectangle { + id: rr2 + objectName: "rr2" + color: "red" + width: 100; height: 100 + } + Rectangle { + id: rr3 + objectName: "rr3" + color: "red" + width: 100; height: 100 + } + Rectangle { + id: rr4 + objectName: "rr4" + color: "red" + width: 100; height: 100 + } + } + + states: State { + name: "state1" + PropertyChanges { target: rr; rotation: 370 } + PropertyChanges { target: rr2; rotation: 370 } + PropertyChanges { target: rr3; rotation: 370 } + PropertyChanges { target: rr4; rotation: 370 } + } + + transitions: Transition { + RotationAnimation { target: rr; direction: RotationAnimation.Numerical; duration: 1000 } + RotationAnimation { target: rr2; direction: RotationAnimation.Clockwise; duration: 1000 } + RotationAnimation { target: rr3; direction: RotationAnimation.Counterclockwise; duration: 1000 } + RotationAnimation { target: rr4; direction: RotationAnimation.Shortest; duration: 1000 } + } +} diff --git a/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp b/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp index f5e15fb..076afea 100644 --- a/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp +++ b/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp @@ -59,6 +59,7 @@ private slots: void simpleProperty(); void simpleNumber(); void simpleColor(); + void simpleRotation(); void alwaysRunToEnd(); void complete(); void resume(); @@ -73,6 +74,7 @@ private slots: void propertyValueSourceDefaultStart(); void dontStart(); void easingProperties(); + void rotation(); }; #define QTIMED_COMPARE(lhs, rhs) do { \ @@ -168,6 +170,32 @@ void tst_qdeclarativeanimations::simpleColor() QCOMPARE(rect.color(), QColor::fromRgbF(0.498039, 0, 0.498039, 1)); } +void tst_qdeclarativeanimations::simpleRotation() +{ + QDeclarativeRectangle rect; + QDeclarativeRotationAnimation animation; + animation.setTarget(&rect); + animation.setProperty("rotation"); + animation.setTo(270); + QVERIFY(animation.target() == &rect); + QVERIFY(animation.property() == "rotation"); + QVERIFY(animation.to() == 270); + QVERIFY(animation.direction() == QDeclarativeRotationAnimation::Shortest); + animation.start(); + QVERIFY(animation.isRunning()); + QTest::qWait(animation.duration()); + QTIMED_COMPARE(rect.rotation(), qreal(270)); + + rect.setRotation(0); + animation.start(); + animation.pause(); + QVERIFY(animation.isRunning()); + QVERIFY(animation.isPaused()); + animation.setCurrentTime(125); + QVERIFY(animation.currentTime() == 125); + QCOMPARE(rect.rotation(), qreal(-45)); +} + void tst_qdeclarativeanimations::alwaysRunToEnd() { QDeclarativeRectangle rect; @@ -667,6 +695,36 @@ void tst_qdeclarativeanimations::easingProperties() } } +void tst_qdeclarativeanimations::rotation() +{ + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/rotation.qml")); + QDeclarativeRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + QDeclarativeRectangle *rr = rect->findChild("rr"); + QDeclarativeRectangle *rr2 = rect->findChild("rr2"); + QDeclarativeRectangle *rr3 = rect->findChild("rr3"); + QDeclarativeRectangle *rr4 = rect->findChild("rr4"); + + rect->setState("state1"); + QTest::qWait(800); + qreal r1 = rr->rotation(); + qreal r2 = rr2->rotation(); + qreal r3 = rr3->rotation(); + qreal r4 = rr4->rotation(); + + QVERIFY(r1 > qreal(0) && r1 < qreal(370)); + QVERIFY(r2 > qreal(0) && r2 < qreal(370)); + QVERIFY(r3 < qreal(0) && r3 > qreal(-350)); + QVERIFY(r4 > qreal(0) && r4 < qreal(10)); + QCOMPARE(r1,r2); + QVERIFY(r4 < r2); + + QTest::qWait(800); + QTIMED_COMPARE(rr->rotation() + rr2->rotation() + rr3->rotation() + rr4->rotation(), qreal(370*4)); +} + QTEST_MAIN(tst_qdeclarativeanimations) #include "tst_qdeclarativeanimations.moc" -- cgit v0.12 From 8344c3e53d1ef13faae80de313ab2959012faf45 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 5 Mar 2010 10:20:29 +1000 Subject: Remove NumberFormatter and DateTimeFormatter. Functions have been added to QML's global Qt object for date/time formatting. Number formatting will not be supported for 4.7. Task-number: QT-2821 --- doc/src/declarative/elements.qdoc | 2 - .../util/qdeclarativedatetimeformatter.cpp | 373 --------------------- .../util/qdeclarativedatetimeformatter_p.h | 117 ------- .../util/qdeclarativenumberformatter.cpp | 261 -------------- .../util/qdeclarativenumberformatter_p.h | 93 ----- src/declarative/util/qdeclarativeutilmodule.cpp | 6 - src/declarative/util/qnumberformat.cpp | 224 ------------- src/declarative/util/qnumberformat_p.h | 174 ---------- src/declarative/util/util.pri | 6 - tests/auto/declarative/declarative.pro | 2 - .../qdeclarativedatetimeformatter.pro | 5 - .../tst_qdeclarativedatetimeformatter.cpp | 150 --------- .../qdeclarativenumberformatter.pro | 5 - .../tst_qdeclarativenumberformatter.cpp | 224 ------------- 14 files changed, 1642 deletions(-) delete mode 100644 src/declarative/util/qdeclarativedatetimeformatter.cpp delete mode 100644 src/declarative/util/qdeclarativedatetimeformatter_p.h delete mode 100644 src/declarative/util/qdeclarativenumberformatter.cpp delete mode 100644 src/declarative/util/qdeclarativenumberformatter_p.h delete mode 100644 src/declarative/util/qnumberformat.cpp delete mode 100644 src/declarative/util/qnumberformat_p.h delete mode 100644 tests/auto/declarative/qdeclarativedatetimeformatter/qdeclarativedatetimeformatter.pro delete mode 100644 tests/auto/declarative/qdeclarativedatetimeformatter/tst_qdeclarativedatetimeformatter.cpp delete mode 100644 tests/auto/declarative/qdeclarativenumberformatter/qdeclarativenumberformatter.pro delete mode 100644 tests/auto/declarative/qdeclarativenumberformatter/tst_qdeclarativenumberformatter.cpp diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc index 22810e3..83adcb3 100644 --- a/doc/src/declarative/elements.qdoc +++ b/doc/src/declarative/elements.qdoc @@ -93,8 +93,6 @@ The following table lists the QML elements provided by the Qt Declarative module \o \l Package \o \l XmlListModel and XmlRole \o \l WorkerListModel -\o \l DateTimeFormatter -\o \l NumberFormatter \endlist \o diff --git a/src/declarative/util/qdeclarativedatetimeformatter.cpp b/src/declarative/util/qdeclarativedatetimeformatter.cpp deleted file mode 100644 index 4087091..0000000 --- a/src/declarative/util/qdeclarativedatetimeformatter.cpp +++ /dev/null @@ -1,373 +0,0 @@ -/**************************************************************************** -** -** 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: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 "qdeclarativedatetimeformatter_p.h" - -#include - -#include - -QT_BEGIN_NAMESPACE - -//TODO: may need optimisation as the QDateTime member may not be needed? -// be able to set a locale? - -class QDeclarativeDateTimeFormatterPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QDeclarativeDateTimeFormatter) -public: - QDeclarativeDateTimeFormatterPrivate() : locale(QLocale::system()), longStyle(false), componentComplete(true) {} - - void updateText(); - - QDateTime dateTime; - QDate date; - QTime time; - QLocale locale; - QString dateTimeText; - QString dateText; - QString timeText; - QString dateTimeFormat; //set for convienience? - QString dateFormat; - QString timeFormat; - bool longStyle; - bool componentComplete; -}; - -/*! - \qmlclass DateTimeFormatter QDeclarativeDateTimeFormatter - \since 4.7 - \brief The DateTimeFormatter allows you to control the format of a date string. - - \code - DateTimeFormatter { id: formatter; date: System.date } - Text { text: formatter.dateText } - \endcode - - By default, the text properties (dateText, timeText, and dateTimeText) will return the - date and time using the current system locale's format. -*/ - -/*! - \internal - \class QDeclarativeDateTimeFormatter - \ingroup group_utility - \brief The QDeclarativeDateTimeFormatter class allows you to format a date string. -*/ - -QDeclarativeDateTimeFormatter::QDeclarativeDateTimeFormatter(QObject *parent) -: QObject(*(new QDeclarativeDateTimeFormatterPrivate), parent) -{ -} - -QDeclarativeDateTimeFormatter::~QDeclarativeDateTimeFormatter() -{ -} - -/*! - \qmlproperty string DateTimeFormatter::dateText - \qmlproperty string DateTimeFormatter::timeText - \qmlproperty string DateTimeFormatter::dateTimeText - - Formatted text representations of the \c date, \c time, - and \c {date and time}, respectively. - - If there is no explictly specified format the DateTimeFormatter - will use the system locale's default 'short' setting. - - \code - // specify source date (assuming today is February 19, 2009) - DateTimeFormatter { id: formatter; dateTime: Today.date } - - // display the full date and time - Text { text: formatter.dateText } - \endcode - - Would be equivalent to the following for a US English locale: - - \code - // display the date - Text { text: "2/19/09" } - \endcode -*/ -QString QDeclarativeDateTimeFormatter::dateTimeText() const -{ - Q_D(const QDeclarativeDateTimeFormatter); - return d->dateTimeText; -} - -QString QDeclarativeDateTimeFormatter::dateText() const -{ - Q_D(const QDeclarativeDateTimeFormatter); - return d->dateText; -} - -QString QDeclarativeDateTimeFormatter::timeText() const -{ - Q_D(const QDeclarativeDateTimeFormatter); - return d->timeText; -} - -/*! - \qmlproperty date DateTimeFormatter::date - \qmlproperty time DateTimeFormatter::time - \qmlproperty datetime DateTimeFormatter::dateTime - - The source date and time to be used by the formatter. - - \code - // setting the date and time - DateTimeFormatter { date: System.date; time: System.time } - \endcode - - For convienience it is possible to set the datetime property to set both the date and the time. - \code - // setting the datetime - DateTimeFormatter { dateTime: System.dateTime } - \endcode - - There can only be one instance of date and time per formatter; if date, time, and dateTime are all - set the actual date and time used is not guaranteed. - - \note If no date is set, dateTimeText will be just the date; - If no time is set, the dateTimeText will be just the time. - -*/ -QDate QDeclarativeDateTimeFormatter::date() const -{ - Q_D(const QDeclarativeDateTimeFormatter); - return d->date; -} - -QTime QDeclarativeDateTimeFormatter::time() const -{ - Q_D(const QDeclarativeDateTimeFormatter); - return d->time; -} - -QDateTime QDeclarativeDateTimeFormatter::dateTime() const -{ - Q_D(const QDeclarativeDateTimeFormatter); - return d->dateTime; -} - -/*! - \qmlproperty string DateTimeFormatter::dateFormat - \qmlproperty string DateTimeFormatter::timeFormat - \qmlproperty string DateTimeFormatter::dateTimeFormat - - Specifies a custom format which the DateTime Formatter can use. - - If there is no explictly specified format the DateTimeFormatter - will use the system locale's default 'short' setting. - - The text's format may be modified by setting: - \list - \i \c dateFormat - \i \c timeFormat - \i \c dateTimeFormat - \endlist - - If only the format for date is defined, the time and dateTime formats will be defined - as the system locale default and likewise for the others. - - Syntax for the format is based on the QDateTime::toString() formatting options. - - \code - // Format the date such that the dateText is: '1997-12-12' - DateTimeFormatter { id: formatter; dateTime: Today.dateTime; formatDate: "yyyy-MM-d" } - \endcode - - Assigning an empty string to a particular format will reset it. -*/ -QString QDeclarativeDateTimeFormatter::dateTimeFormat() const -{ - Q_D(const QDeclarativeDateTimeFormatter); - return d->dateTimeFormat; -} - -QString QDeclarativeDateTimeFormatter::dateFormat() const -{ - Q_D(const QDeclarativeDateTimeFormatter); - return d->dateFormat; -} - -QString QDeclarativeDateTimeFormatter::timeFormat() const -{ - Q_D(const QDeclarativeDateTimeFormatter); - return d->timeFormat; -} - -/*! - \qmlproperty bool DateTimeFormatter::longStyle - - This property causes the formatter to use the system locale's long format rather than short format - by default. - - This setting is off by default. -*/ -bool QDeclarativeDateTimeFormatter::longStyle() const -{ - Q_D(const QDeclarativeDateTimeFormatter); - return d->longStyle; -} - -void QDeclarativeDateTimeFormatter::setDateTime(const QDateTime &dateTime) -{ - Q_D(QDeclarativeDateTimeFormatter); - if (d->dateTime == dateTime) - return; - d->dateTime = dateTime; - d->date = d->dateTime.date(); - d->time = d->dateTime.time(); - d->updateText(); -} - -void QDeclarativeDateTimeFormatter::setTime(const QTime &time) -{ - Q_D(QDeclarativeDateTimeFormatter); - if (d->dateTime.time() == time) - return; - d->time = time; - d->dateTime.setTime(time); - d->updateText(); -} - -void QDeclarativeDateTimeFormatter::setDate(const QDate &date) -{ - Q_D(QDeclarativeDateTimeFormatter); - if (d->dateTime.date() == date) - return; - d->date = date; - bool clearTime = d->dateTime.time().isValid() ? false : true; //because setting date generates default time - d->dateTime.setDate(date); - if (clearTime) - d->dateTime.setTime(QTime()); - d->updateText(); -} - -//DateTime formatting may be a combination of date and time? -void QDeclarativeDateTimeFormatter::setDateTimeFormat(const QString &format) -{ - Q_D(QDeclarativeDateTimeFormatter); - //no format checking - d->dateTimeFormat = format; - d->updateText(); -} - -void QDeclarativeDateTimeFormatter::setDateFormat(const QString &format) -{ - Q_D(QDeclarativeDateTimeFormatter); - //no format checking - d->dateFormat = format; - d->updateText(); -} - -void QDeclarativeDateTimeFormatter::setTimeFormat(const QString &format) -{ - Q_D(QDeclarativeDateTimeFormatter); - //no format checking - d->timeFormat = format; - d->updateText(); -} - -void QDeclarativeDateTimeFormatter::setLongStyle(bool longStyle) -{ - Q_D(QDeclarativeDateTimeFormatter); - d->longStyle = longStyle; - d->updateText(); -} - -void QDeclarativeDateTimeFormatterPrivate::updateText() -{ - Q_Q(QDeclarativeDateTimeFormatter); - if (!componentComplete) - return; - - QString str; - QString str1; - QString str2; - - Qt::DateFormat defaultFormat = longStyle ? Qt::SystemLocaleLongDate : Qt::SystemLocaleShortDate; - - if (dateFormat.isEmpty()) - str1 = date.toString(defaultFormat); - else - str1 = date.toString(dateFormat); - - if (timeFormat.isEmpty()) - str2 = time.toString(defaultFormat); - else - str2 = time.toString(timeFormat); - - if (dateTimeFormat.isEmpty()) - str = dateTime.toString(defaultFormat); - //else if (!formatTime.isEmpty() && !formatDate.isEmpty()) - // str = str1 + QLatin1Char(' ') + str2; - else - str = dateTime.toString(dateTimeFormat); - - if (dateTimeText == str && dateText == str1 && timeText == str2) - return; - - dateTimeText = str; - dateText = str1; - timeText = str2; - - emit q->textChanged(); -} - -void QDeclarativeDateTimeFormatter::classBegin() -{ - Q_D(QDeclarativeDateTimeFormatter); - d->componentComplete = false; -} - -void QDeclarativeDateTimeFormatter::componentComplete() -{ - Q_D(QDeclarativeDateTimeFormatter); - d->componentComplete = true; - d->updateText(); -} - - - -QT_END_NAMESPACE diff --git a/src/declarative/util/qdeclarativedatetimeformatter_p.h b/src/declarative/util/qdeclarativedatetimeformatter_p.h deleted file mode 100644 index da900be..0000000 --- a/src/declarative/util/qdeclarativedatetimeformatter_p.h +++ /dev/null @@ -1,117 +0,0 @@ -/**************************************************************************** -** -** 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: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$ -** -****************************************************************************/ - -#ifndef QDECLARATIVEDATETIMEFORMATTER_H -#define QDECLARATIVEDATETIMEFORMATTER_H - -#include - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QDeclarativeDateTimeFormatterPrivate; -class Q_DECLARATIVE_EXPORT QDeclarativeDateTimeFormatter : public QObject, public QDeclarativeParserStatus -{ - Q_OBJECT - Q_INTERFACES(QDeclarativeParserStatus) - - Q_PROPERTY(QString dateText READ dateText NOTIFY textChanged) - Q_PROPERTY(QString timeText READ timeText NOTIFY textChanged) - Q_PROPERTY(QString dateTimeText READ dateTimeText NOTIFY textChanged) - Q_PROPERTY(QDate date READ date WRITE setDate) - Q_PROPERTY(QTime time READ time WRITE setTime) - Q_PROPERTY(QDateTime dateTime READ dateTime WRITE setDateTime) - Q_PROPERTY(QString dateFormat READ dateFormat WRITE setDateFormat) - Q_PROPERTY(QString timeFormat READ timeFormat WRITE setTimeFormat) - Q_PROPERTY(QString dateTimeFormat READ dateTimeFormat WRITE setDateTimeFormat) - Q_PROPERTY(bool longStyle READ longStyle WRITE setLongStyle) -public: - QDeclarativeDateTimeFormatter(QObject *parent=0); - ~QDeclarativeDateTimeFormatter(); - - QString dateTimeText() const; - QString dateText() const; - QString timeText() const; - - QDate date() const; - void setDate(const QDate &); - - QTime time() const; - void setTime(const QTime &); - - QDateTime dateTime() const; - void setDateTime(const QDateTime &); - - QString dateTimeFormat() const; - void setDateTimeFormat(const QString &); - - QString dateFormat() const; - void setDateFormat(const QString &); - - QString timeFormat() const; - void setTimeFormat(const QString &); - - bool longStyle() const; - void setLongStyle(bool); - - virtual void classBegin(); - virtual void componentComplete(); - -Q_SIGNALS: - void textChanged(); - -private: - Q_DISABLE_COPY(QDeclarativeDateTimeFormatter) - Q_DECLARE_PRIVATE(QDeclarativeDateTimeFormatter) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QDeclarativeDateTimeFormatter) - -QT_END_HEADER - -#endif diff --git a/src/declarative/util/qdeclarativenumberformatter.cpp b/src/declarative/util/qdeclarativenumberformatter.cpp deleted file mode 100644 index 5d81958..0000000 --- a/src/declarative/util/qdeclarativenumberformatter.cpp +++ /dev/null @@ -1,261 +0,0 @@ -/**************************************************************************** -** -** 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: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 "qdeclarativenumberformatter_p.h" - -#include - -QT_BEGIN_NAMESPACE - -//TODO: set locale -// docs -// this is a wrapper around qnumberformat (test integration) -// if number or format haven't been explictly set, text should be an empty string - -class QDeclarativeNumberFormatterPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QDeclarativeNumberFormatter) -public: - QDeclarativeNumberFormatterPrivate() : locale(QLocale::system()), number(0), componentComplete(true) {} - - void updateText(); - - QLocale locale; - QString format; - QNumberFormat numberFormat; - QString text; - qreal number; - bool componentComplete; -}; -/*! - \qmlclass NumberFormatter - \since 4.7 - \brief The NumberFormatter allows you to control the format of a number string. - - The format property documentation has more details on how the format can be manipulated. - - In the following example, the text element will display the text "1,234.57". - \code - NumberFormatter { id: formatter; number: 1234.5678; format: "##,##0.##" } - Text { text: formatter.text } - \endcode - - */ -/*! - \internal - \class QDeclarativeNumberFormatter - \ingroup group_utility - \brief The QDeclarativeNumberFormatter class allows you to format a number to a particular string format/locale specific number format. -*/ - -QDeclarativeNumberFormatter::QDeclarativeNumberFormatter(QObject *parent) -: QObject(*(new QDeclarativeNumberFormatterPrivate), parent) -{ -} - -QDeclarativeNumberFormatter::~QDeclarativeNumberFormatter() -{ -} - -/*! - \qmlproperty string NumberFormatter::text - - The number in the specified format. - - If no format is specified the text will be empty. -*/ - -QString QDeclarativeNumberFormatter::text() const -{ - Q_D(const QDeclarativeNumberFormatter); - return d->text; -} - -/*! - \qmlproperty real NumberFormatter::number - - A single point precision number. (Doubles are not yet supported) - -*/ -qreal QDeclarativeNumberFormatter::number() const -{ - Q_D(const QDeclarativeNumberFormatter); - return d->number; -} - -/*! - \qmlproperty string NumberFormatter::format - - The particular format the number will adhere to during the conversion to text. - - The format syntax follows a style similar to the Unicode Standard (UTS35). - - The table below shows the characters, patterns that can be used in the format. - - \table - \header - \o Character - \o Meaning - \row - \o # - \o Any digit(s), zero shows as absent (for leading/trailing zeroes). - \row - \o 0 - \o Implicit digit. Zero will show in the case that the input number is too small. - \row - \o . - \o Decimal separator. Output decimal seperator will be dependant on system locale. - \row - \o , - \o Grouping separator. The number of digits (either #, or 0) between the grouping separator and the decimal (or the rightmost digit) will determine the groupingSize). - \row - \o other - \o Any other character will be taken as a string literal and placed directly into the output string. - \endtable - - Invalid formats will not guarantee a meaningful text output. - - \note Input numbers that are too long for the given format will be rounded dependent on precison based on the position of the decimal point. - - The following table illustrates the output text created by applying some examples of numeric formats to the formatter. - - \table - \header - \o Format - \o Number - \o Output - \row - \o ### - \o 123456 - \o 123456 - \row - \o 000 - \o 123456 - \o 123456 - \row - \o ###### - \o 1234 - \o 1234 - \row - \o 000000 - \o 1234 - \o 001234 - \row - \o ##,##0.## - \o 1234.456 - \o 1,234.46 (for US locale) - \codeline 1 234,46 (for FR locale) - \row - \o 000000,000.# - \o 123456 - \o 000,123,456 (for US locale) - \codeline 000 123 456 (for FR locale) - \row - \o 0.0### - \o 0.999997 - \o 1.0 - \row - \o (000) 000 - 000 - \o 12345678 - \o (012) 345 - 678 - \row - \o #A - \o 12 - \o 12A - \endtable - -*/ -QString QDeclarativeNumberFormatter::format() const -{ - Q_D(const QDeclarativeNumberFormatter); - return d->format; -} - -void QDeclarativeNumberFormatter::setNumber(const qreal &number) -{ - Q_D(QDeclarativeNumberFormatter); - if (d->number == number) - return; - d->number = number; - d->updateText(); -} - -void QDeclarativeNumberFormatter::setFormat(const QString &format) -{ - Q_D(QDeclarativeNumberFormatter); - //no format checking - if (format.isEmpty()) - d->format = QString::null; - else - d->format = format; - d->updateText(); -} - -void QDeclarativeNumberFormatterPrivate::updateText() -{ - Q_Q(QDeclarativeNumberFormatter); - if (!componentComplete) - return; - - QNumberFormat tempFormat; - tempFormat.setFormat(format); - tempFormat.setNumber(number); - - text = tempFormat.text(); - - emit q->textChanged(); -} - -void QDeclarativeNumberFormatter::classBegin() -{ - Q_D(QDeclarativeNumberFormatter); - d->componentComplete = false; -} - -void QDeclarativeNumberFormatter::componentComplete() -{ - Q_D(QDeclarativeNumberFormatter); - d->componentComplete = true; - d->updateText(); -} - - -QT_END_NAMESPACE diff --git a/src/declarative/util/qdeclarativenumberformatter_p.h b/src/declarative/util/qdeclarativenumberformatter_p.h deleted file mode 100644 index 3b8c7e1..0000000 --- a/src/declarative/util/qdeclarativenumberformatter_p.h +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -** -** 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: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$ -** -****************************************************************************/ - -#ifndef QDECLARATIVENUMBERFORMATTER_H -#define QDECLARATIVENUMBERFORMATTER_H - -#include "qnumberformat_p.h" - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QDeclarativeNumberFormatterPrivate; -class Q_DECLARATIVE_EXPORT QDeclarativeNumberFormatter : public QObject, public QDeclarativeParserStatus -{ - Q_OBJECT - Q_INTERFACES(QDeclarativeParserStatus) - - Q_PROPERTY(QString text READ text NOTIFY textChanged) - Q_PROPERTY(QString format READ format WRITE setFormat) - Q_PROPERTY(qreal number READ number WRITE setNumber) -public: - QDeclarativeNumberFormatter(QObject *parent=0); - ~QDeclarativeNumberFormatter(); - - QString text() const; - - qreal number() const; - void setNumber(const qreal &); - - QString format() const; - void setFormat(const QString &); - - virtual void classBegin(); - virtual void componentComplete(); - -Q_SIGNALS: - void textChanged(); - -private: - Q_DISABLE_COPY(QDeclarativeNumberFormatter) - Q_DECLARE_PRIVATE(QDeclarativeNumberFormatter) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QDeclarativeNumberFormatter) - -QT_END_HEADER - -#endif diff --git a/src/declarative/util/qdeclarativeutilmodule.cpp b/src/declarative/util/qdeclarativeutilmodule.cpp index 1f85b89..65bfdc1 100644 --- a/src/declarative/util/qdeclarativeutilmodule.cpp +++ b/src/declarative/util/qdeclarativeutilmodule.cpp @@ -46,13 +46,11 @@ #include "qdeclarativebehavior_p.h" #include "qdeclarativebind_p.h" #include "qdeclarativeconnections_p.h" -#include "qdeclarativedatetimeformatter_p.h" #include "qdeclarativeeasefollow_p.h" #include "qdeclarativefontloader_p.h" #include "qdeclarativelistaccessor_p.h" #include "qdeclarativelistmodel_p.h" #include "qdeclarativenullablevalue_p_p.h" -#include "qdeclarativenumberformatter_p.h" #include "qdeclarativeopenmetaobject_p.h" #include "qdeclarativepackage_p.h" #include "qdeclarativepixmapcache_p.h" @@ -73,7 +71,6 @@ #ifndef QT_NO_XMLPATTERNS #include "qdeclarativexmllistmodel_p.h" #endif -#include "qnumberformat_p.h" #include "qperformancelog_p_p.h" void QDeclarativeUtilModule::defineModule() @@ -83,12 +80,10 @@ void QDeclarativeUtilModule::defineModule() QML_REGISTER_TYPE(Qt,4,6,Binding,QDeclarativeBind); QML_REGISTER_TYPE(Qt,4,6,ColorAnimation,QDeclarativeColorAnimation); QML_REGISTER_TYPE(Qt,4,6,Connections,QDeclarativeConnections); - QML_REGISTER_TYPE(Qt,4,6,DateTimeFormatter,QDeclarativeDateTimeFormatter); QML_REGISTER_TYPE(Qt,4,6,EaseFollow,QDeclarativeEaseFollow);; QML_REGISTER_TYPE(Qt,4,6,FontLoader,QDeclarativeFontLoader); QML_REGISTER_TYPE(Qt,4,6,ListElement,QDeclarativeListElement); QML_REGISTER_TYPE(Qt,4,6,NumberAnimation,QDeclarativeNumberAnimation); - QML_REGISTER_TYPE(Qt,4,6,NumberFormatter,QDeclarativeNumberFormatter);; QML_REGISTER_TYPE(Qt,4,6,Package,QDeclarativePackage); QML_REGISTER_TYPE(Qt,4,6,ParallelAnimation,QDeclarativeParallelAnimation); QML_REGISTER_TYPE(Qt,4,6,ParentAction,QDeclarativeParentAction); @@ -116,7 +111,6 @@ void QDeclarativeUtilModule::defineModule() QML_REGISTER_NOCREATE_TYPE(QDeclarativeAnchors); QML_REGISTER_NOCREATE_TYPE(QDeclarativeAbstractAnimation); QML_REGISTER_NOCREATE_TYPE(QDeclarativeStateOperation); - QML_REGISTER_NOCREATE_TYPE(QNumberFormat); QML_REGISTER_CUSTOM_TYPE(Qt, 4,6, ListModel, QDeclarativeListModel, QDeclarativeListModelParser); QML_REGISTER_CUSTOM_TYPE(Qt, 4,6, PropertyChanges, QDeclarativePropertyChanges, QDeclarativePropertyChangesParser); diff --git a/src/declarative/util/qnumberformat.cpp b/src/declarative/util/qnumberformat.cpp deleted file mode 100644 index 81d0b90..0000000 --- a/src/declarative/util/qnumberformat.cpp +++ /dev/null @@ -1,224 +0,0 @@ -/**************************************************************************** -** -** 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: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 "qnumberformat_p.h" -#include - -QT_BEGIN_NAMESPACE - -QNumberFormat::QNumberFormat(QObject *parent) : QObject(parent), _number(0), _type(Decimal), - _groupingSize(0) -{ - _locale = QLocale::system(); - _groupingSeparator = _locale.groupSeparator(); - _decimalSeparator = _locale.decimalPoint(); - _currencySymbol = QLatin1Char('$'); -} - -QNumberFormat::~QNumberFormat() -{ - -} - -void QNumberFormat::updateText() -{ - QTime t; - t.start(); - static int totalTime; - - handleFormat(); - - totalTime += t.elapsed(); - emit textChanged(); -} - -void QNumberFormat::handleFormat() -{ - // ### is extremely messy - if (_format.isEmpty()) { - _text = QString::number(_number, 'f', -1); - return; - } - - QString inputString; - - // ### possible to use the following parsed data in the future - - int remainingLength = _format.size(); - int currentIndex = _format.size()-1; - - int maxDigits = 0; - int minDigits = 0; - int decimalLength = 0; - - while (remainingLength > 0) { - switch(_format.at(currentIndex).unicode()) { - case ',': - if (decimalLength && !_groupingSize) - setGroupingSize(maxDigits - decimalLength); - else if (!_groupingSize) - setGroupingSize(maxDigits); - break; - case '.': - if (!decimalLength) - decimalLength = maxDigits; - break; - case '0': - minDigits++; - case '#': - maxDigits++; - break; - default: - break; - } - currentIndex--; - remainingLength--; - } - - // round given the decimal length/precision - inputString = QString::number(_number, 'f', decimalLength); - - QStringList parts = inputString.split(QLatin1Char('.')); - QStringList formatParts = _format.split(QLatin1Char('.')); - - if (formatParts.size() > 2 || parts.size() > 2 ) - return; - - QString formatInt = formatParts.at(0); - - QString formatDec; - if (formatParts.size() == 2) - formatDec = formatParts.at(1); - - QString integer = parts.at(0); - - QString decimal; - if (parts.size() == 2) - decimal = parts.at(1); - - QString outputDecimal = formatDecimal(formatDec, decimal); - QString outputInteger = formatInteger(formatInt, integer); - - // insert separators - if (_groupingSize) { - unsigned int count = 0; - for (int i = outputInteger.size()-1; i > 0; i--) { - if (outputInteger.at(i).digitValue() >= 0) { - if (count == _groupingSize - 1) { - count = 0; - outputInteger.insert(i, _groupingSeparator); - } - else - count++; - } - } - } - if (!outputDecimal.isEmpty()) - _text = outputInteger + _decimalSeparator + outputDecimal; - else - _text = outputInteger; -} - -QString QNumberFormat::formatInteger(const QString &formatInt, const QString &integer) -{ - if (formatInt.isEmpty() || integer.isEmpty()) - return QString(); - - QString outputInteger; - int formatIndex = formatInt.size()-1; - - //easier for carry? - for (int index= integer.size()-1; index >= 0; index--) { - if (formatIndex < 0) { - outputInteger.push_front(integer.at(index)); - } - else { - switch(formatInt.at(formatIndex).unicode()) { - case '0': - if (index > integer.size()-1) { - outputInteger.push_front(QLatin1Char('0')); - break; - } - case '#': - outputInteger.push_front(integer.at(index)); - break; - case ',': - index++; - break; - default: - outputInteger.push_front(formatInt.at(formatIndex)); - index++; - break; - } - formatIndex--; - } - } - while (formatIndex >= 0) { - if (formatInt.at(formatIndex).unicode() != '#' && formatInt.at(formatIndex).unicode() != ',') - outputInteger.push_front(formatInt.at(formatIndex)); - formatIndex--; - } - return outputInteger; -} - -QString QNumberFormat::formatDecimal(const QString &formatDec, const QString &decimal) -{ - QString outputDecimal; - - // up to max 6 decimal places - for (int index=formatDec.size()-1; index >= 0; index--) { - switch(formatDec.at(index).unicode()) { - case '0': - outputDecimal.push_front(decimal.at(index)); - break; - case '#': - if (decimal.at(index) != QLatin1Char('0') || outputDecimal.size() > 0) - outputDecimal.push_front(decimal.at(index)); - break; - default: - outputDecimal.push_front(formatDec.at(index)); - break; - } - } - return outputDecimal; -} - -QT_END_NAMESPACE diff --git a/src/declarative/util/qnumberformat_p.h b/src/declarative/util/qnumberformat_p.h deleted file mode 100644 index ced4442..0000000 --- a/src/declarative/util/qnumberformat_p.h +++ /dev/null @@ -1,174 +0,0 @@ -/**************************************************************************** -** -** 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: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$ -** -****************************************************************************/ - -#ifndef NUMBERFORMAT_H -#define NUMBERFORMAT_H - -#include - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -// TODO -// be able to set Locale, instead of default system for dynamic formatting -// add currency support -// add additional syntax, extend to format scientific, percentiles, significant digits etc - - -class QNumberFormat : public QObject -{ - Q_OBJECT - Q_ENUMS(NumberType) -public: - QNumberFormat(QObject *parent=0); - ~QNumberFormat(); - - enum NumberType { - Percent, - Scientific, - Currency, - Decimal - }; - - //external property, only visible - Q_PROPERTY(QString text READ text NOTIFY textChanged) - - //mutatable properties to modify the output (text) - Q_PROPERTY(qreal number READ number WRITE setNumber) - Q_PROPERTY(QString format READ format WRITE setFormat) - Q_PROPERTY(QLocale locale READ locale WRITE setLocale) - - //Format specific settings - Q_PROPERTY(unsigned short groupingSeparator READ groupingSeparator WRITE setGroupingSeparator) - Q_PROPERTY(unsigned short decimalSeperator READ decimalSeparator WRITE setDecimalSeparator) - Q_PROPERTY(unsigned int groupingSize READ groupingSize WRITE setGroupingSize) - Q_PROPERTY(unsigned short currencySymbol READ currencySymbol WRITE setCurrencySymbol) - - - QString text() const { return _text; } - - qreal number() const { return _number; } - void setNumber(qreal n) { - if (_number == n) - return; - _number = n; - updateText(); - } - - QString format() const { return _format; } - void setFormat(const QString &format) { - if (format.isEmpty()) - _format = QString::null; - else if (_format == format) - return; - - _format = format; - updateText(); - } - - QLocale locale() const { return _locale; } - void setLocale(const QLocale &locale) { _locale = locale; updateText(); } - - //Do we deal with unicode standard? or create our own - // ### since this is the backend for the number conversions, we will use the unicode - // the front-end will handle the QChar/QString -> short int - - unsigned short groupingSeparator() { return _groupingSeparator.unicode(); } - void setGroupingSeparator(unsigned short unicodeSymbol) - { - _groupingSeparator = QChar(unicodeSymbol); - } - - unsigned short decimalSeparator() { return _decimalSeparator.unicode(); } - void setDecimalSeparator(unsigned short unicodeSymbol) - { - _decimalSeparator = QChar(unicodeSymbol); - } - - unsigned short currencySymbol() { return _currencySymbol.unicode(); } - void setCurrencySymbol(unsigned short unicodeSymbol) - { - _currencySymbol = QChar(unicodeSymbol); - } - - unsigned int groupingSize() { return _groupingSize; } - void setGroupingSize(unsigned int size) - { - _groupingSize = size; - } - -Q_SIGNALS: - void textChanged(); - -private: - void updateText(); - void handleFormat(); - QString formatInteger(const QString &formatInt, const QString &integer); - QString formatDecimal(const QString &formatDec, const QString &decimal); - - qreal _number; - NumberType _type; - QChar _groupingSeparator; - QChar _decimalSeparator; - QChar _currencySymbol; - unsigned int _groupingSize; - - QLocale _locale; - QString _format; - - // only hooked member at the moment - QString _text; - -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QNumberFormat) - -QT_END_HEADER - -#endif diff --git a/src/declarative/util/util.pri b/src/declarative/util/util.pri index 198e9e5..26edecc 100644 --- a/src/declarative/util/util.pri +++ b/src/declarative/util/util.pri @@ -25,9 +25,6 @@ SOURCES += \ $$PWD/qdeclarativebind.cpp \ $$PWD/qdeclarativepropertymap.cpp \ $$PWD/qdeclarativepixmapcache.cpp \ - $$PWD/qnumberformat.cpp \ - $$PWD/qdeclarativenumberformatter.cpp \ - $$PWD/qdeclarativedatetimeformatter.cpp \ $$PWD/qdeclarativebehavior.cpp \ $$PWD/qdeclarativefontloader.cpp \ $$PWD/qdeclarativestyledtext.cpp @@ -60,9 +57,6 @@ HEADERS += \ $$PWD/qdeclarativebind_p.h \ $$PWD/qdeclarativepropertymap.h \ $$PWD/qdeclarativepixmapcache_p.h \ - $$PWD/qnumberformat_p.h \ - $$PWD/qdeclarativenumberformatter_p.h \ - $$PWD/qdeclarativedatetimeformatter_p.h \ $$PWD/qdeclarativebehavior_p.h \ $$PWD/qdeclarativefontloader_p.h \ $$PWD/qdeclarativestyledtext_p.h diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 99a32d9..143fbad 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -10,7 +10,6 @@ SUBDIRS += \ qdeclarativecomponent \ # Cover qdeclarativeconnection \ # Cover qdeclarativecontext \ # Cover - qdeclarativedatetimeformatter \ # Cover qdeclarativedebug \ # Cover qdeclarativedebugclient \ # Cover qdeclarativedebugservice \ # Cover @@ -45,7 +44,6 @@ SUBDIRS += \ qdeclarativeproperty \ # Cover qdeclarativemetatype \ # Cover qdeclarativemoduleplugin \ # Cover - qdeclarativenumberformatter \ # Cover qdeclarativepixmapcache \ # Cover qdeclarativepropertymap \ # Cover qdeclarativeqt \ # Cover diff --git a/tests/auto/declarative/qdeclarativedatetimeformatter/qdeclarativedatetimeformatter.pro b/tests/auto/declarative/qdeclarativedatetimeformatter/qdeclarativedatetimeformatter.pro deleted file mode 100644 index 22f53e6..0000000 --- a/tests/auto/declarative/qdeclarativedatetimeformatter/qdeclarativedatetimeformatter.pro +++ /dev/null @@ -1,5 +0,0 @@ -load(qttest_p4) -contains(QT_CONFIG,declarative): QT += declarative -macx:CONFIG -= app_bundle - -SOURCES += tst_qdeclarativedatetimeformatter.cpp diff --git a/tests/auto/declarative/qdeclarativedatetimeformatter/tst_qdeclarativedatetimeformatter.cpp b/tests/auto/declarative/qdeclarativedatetimeformatter/tst_qdeclarativedatetimeformatter.cpp deleted file mode 100644 index 69d7900..0000000 --- a/tests/auto/declarative/qdeclarativedatetimeformatter/tst_qdeclarativedatetimeformatter.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/**************************************************************************** -** -** 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 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 - -class tst_qdeclarativedatetimeformatter : public QObject -{ - Q_OBJECT -public: - tst_qdeclarativedatetimeformatter() {} - -private slots: - void date(); - void time(); - void dateTime(); -}; - -void tst_qdeclarativedatetimeformatter::date() -{ - QDeclarativeEngine engine; - QDeclarativeComponent formatterComponent(&engine); - formatterComponent.setData(QByteArray("import Qt 4.6\n DateTimeFormatter { date: \"2008-12-24\" }"), - QUrl::fromLocalFile("")); - QDeclarativeDateTimeFormatter *formatter = qobject_cast(formatterComponent.create()); - if(formatterComponent.isError()) - qDebug() << formatterComponent.errors(); - QVERIFY(formatter != 0); - - QDate date(2008,12,24); - QCOMPARE(formatter->date(), date); - QCOMPARE(formatter->dateTime().date(), date); - QCOMPARE(formatter->dateText(),date.toString(Qt::SystemLocaleShortDate)); - - formatter->setLongStyle(true); - QVERIFY(formatter->longStyle()); - QCOMPARE(formatter->dateText(),date.toString(Qt::SystemLocaleLongDate)); - - formatter->setDateFormat("ddd MMMM d yy"); - QCOMPARE(formatter->dateFormat(), QLatin1String("ddd MMMM d yy")); - QCOMPARE(formatter->dateText(),date.toString("ddd MMMM d yy")); - - QVERIFY(formatter->timeText().isEmpty()); - QVERIFY(formatter->dateTimeText().isEmpty()); - - delete formatter; -} - -void tst_qdeclarativedatetimeformatter::time() -{ - QDeclarativeEngine engine; - QDeclarativeComponent formatterComponent(&engine); - formatterComponent.setData("import Qt 4.6\n DateTimeFormatter { time: \"14:15:38.200\" }", QUrl::fromLocalFile("")); - QDeclarativeDateTimeFormatter *formatter = qobject_cast(formatterComponent.create()); - if(formatterComponent.isError()) - qDebug() << formatterComponent.errors(); - QVERIFY(formatter != 0); - - QTime time(14,15,38,200); - - QCOMPARE(formatter->time(),time); - QCOMPARE(formatter->dateTime().time(),time); - - QCOMPARE(formatter->timeText(),time.toString(Qt::SystemLocaleShortDate)); - - formatter->setLongStyle(true); - QCOMPARE(formatter->timeText(),time.toString(Qt::SystemLocaleLongDate)); - - formatter->setTimeFormat("H:m:s a"); - QCOMPARE(formatter->timeFormat(), QLatin1String("H:m:s a")); - QCOMPARE(formatter->timeText(),time.toString("H:m:s a")); - - formatter->setTimeFormat("hh:mm:ss.zzz"); - QCOMPARE(formatter->timeText(),time.toString("hh:mm:ss.zzz")); - - QVERIFY(formatter->dateText().isEmpty()); - QVERIFY(formatter->dateTimeText().isEmpty()); - - delete formatter; -} - -void tst_qdeclarativedatetimeformatter::dateTime() -{ - QDeclarativeEngine engine; - QDeclarativeComponent formatterComponent(&engine); - formatterComponent.setData("import Qt 4.6\n DateTimeFormatter { dateTime: \"1978-03-04T09:13:54\" }", QUrl::fromLocalFile("")); - QDeclarativeDateTimeFormatter *formatter = qobject_cast(formatterComponent.create()); - if(formatterComponent.isError()) - qDebug() << formatterComponent.errors(); - QVERIFY(formatter != 0); - - QDateTime dateTime(QDate(1978,03,04),QTime(9,13,54)); - QCOMPARE(formatter->dateTime(),dateTime); - QCOMPARE(formatter->date(),dateTime.date()); - QCOMPARE(formatter->time(),dateTime.time()); - QCOMPARE(formatter->dateTimeText(),dateTime.toString(Qt::SystemLocaleShortDate)); - - formatter->setLongStyle(true); - QCOMPARE(formatter->dateTimeText(),dateTime.toString(Qt::SystemLocaleLongDate)); - - formatter->setDateTimeFormat("M/d/yy H:m:s a"); - QCOMPARE(formatter->dateTimeFormat(), QLatin1String("M/d/yy H:m:s a")); - QCOMPARE(formatter->dateTimeText(),dateTime.toString("M/d/yy H:m:s a")); - - delete formatter; -} - -QTEST_MAIN(tst_qdeclarativedatetimeformatter) - -#include "tst_qdeclarativedatetimeformatter.moc" diff --git a/tests/auto/declarative/qdeclarativenumberformatter/qdeclarativenumberformatter.pro b/tests/auto/declarative/qdeclarativenumberformatter/qdeclarativenumberformatter.pro deleted file mode 100644 index 672e95c..0000000 --- a/tests/auto/declarative/qdeclarativenumberformatter/qdeclarativenumberformatter.pro +++ /dev/null @@ -1,5 +0,0 @@ -load(qttest_p4) -contains(QT_CONFIG,declarative): QT += declarative -macx:CONFIG -= app_bundle - -SOURCES += tst_qdeclarativenumberformatter.cpp diff --git a/tests/auto/declarative/qdeclarativenumberformatter/tst_qdeclarativenumberformatter.cpp b/tests/auto/declarative/qdeclarativenumberformatter/tst_qdeclarativenumberformatter.cpp deleted file mode 100644 index a9a0077..0000000 --- a/tests/auto/declarative/qdeclarativenumberformatter/tst_qdeclarativenumberformatter.cpp +++ /dev/null @@ -1,224 +0,0 @@ -/**************************************************************************** -** -** 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 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 -#include - -class tst_qdeclarativenumberformatter : public QObject -{ - Q_OBJECT -public: - tst_qdeclarativenumberformatter(); - - void init() {} - void initTestCase() {} - - void cleanup() {} - void cleanupTestCase() {} - -private slots: - void text_data(); - void text(); - -private: - QStringList strings; - QStringList formats; - QStringList texts; -}; - -tst_qdeclarativenumberformatter::tst_qdeclarativenumberformatter() -{ - strings << "100.0" - << "12345" - << "1234567" - << "0.123" - << "0.9999" - << "0.989" - << "1" - << "1.0" - << "1.01"; - - formats << "" - << "0000" - << "0000.00" - << "##" - << "##.##" - << "#0.00#" - << "##,##0.##" - << "(000) 000 - 000" - << "00000,000.0000"; - - //US locale only. - texts << "100.000000" - << "12345.000000" - << "1234567.000000" - << "0.123000" - << "0.999900" - << "0.989000" - << "1.000000" - << "1.000000" - << "1.010000" //end "" - << "0100" - << "12345" - << "1234567" - << "0000" - << "0001" - << "0001" - << "0001" - << "0001" - << "0001" // end "0000" - << "0100.00" - << "12345.00" - << "1234567.00" - << "0000.12" - << "0001.00" - << "0000.99" - << "0001.00" - << "0001.00" - << "0001.01" // end "0000.00" - << "100" - << "12345" - << "1234567" - << "0" - << "1" - << "1" - << "1" - << "1" - << "1" // end "##" - << "100"//start "##.##" - << "12345" - << "1234567" - << "0.12" - << "1" - << "0.99" - << "1" - << "1" - << "1.01" // end "##.##" -- ### EXPECT FAIL ### QNumberFormat::formatDecimal() bug - << "100.00" //start "#0.00#" - << "12345.00" - << "1234567.00" - << "0.123" - << "1.00" - << "0.989" - << "1.00" - << "1.00" - << "1.01" //end "#0.00#" - << "100" //start "##,##0.##" - << "12,345" - << "1,234,567" - << "0.12" - << "1" - << "0.99" - << "1" - << "1" - << "1.01" //end "##,##0.##" -- ### EXPECT FAIL ### QNumberFormat::formatDecimal() bug - << "(000) 000 - 100" //start "(000) 000 - 000" - << "(000) 012 - 345" - << "(001) 234 - 567" - << "(000) 000 - 000" - << "(000) 000 - 001" - << "(000) 000 - 001" - << "(000) 000 - 001" - << "(000) 000 - 001" - << "(000) 000 - 001" // end "(000) 000 - 000" - << "00,000,100.0000" // start "00000,000.0000" - << "00,012,345.0000" - << "01,234,567.0000" - << "00,000,000.1230" - << "00,000,000.9999" - << "00,000,000.9890" - << "00,000,001.0000" - << "00,000,001.0000" - << "00,000,001.0100"; // end - - /* - qDebug() << "strings.size()" << strings.size() - << "\nformats.size()" << formats.size() - << "texts.size()" << texts.size(); - */ -} - -void tst_qdeclarativenumberformatter::text_data() -{ - QTest::addColumn("string"); - QTest::addColumn("format"); - QTest::addColumn("text"); - - for (int j=0; j < formats.size(); j++) - { - for (int i=0; i < strings.size(); i++) - { - QTest::newRow(QString("%1, %2").arg(strings.at(i)).arg(formats.at(j)).toAscii()) - << strings.at(i) << formats.at(j) << texts.at(j*formats.size()+i); - } - } - -} - -void tst_qdeclarativenumberformatter::text() -{ - QFETCH(QString, string); - QFETCH(QString, format); - QFETCH(QString, text); - - QString componentStr = QString("import Qt 4.6\nNumberFormatter { number: ") + string + QString("; format: \"") + format + QString("\" }"); - - QDeclarativeEngine engine; - QDeclarativeComponent formatterComponent(&engine); - formatterComponent.setData(componentStr.toUtf8(), QUrl::fromLocalFile("")); - if(formatterComponent.isError()) - qDebug() << formatterComponent.errors(); - QVERIFY(formatterComponent.isReady()); - QDeclarativeNumberFormatter *formatter = qobject_cast(formatterComponent.create()); - QVERIFY(formatter != 0); - - QCOMPARE(formatter->format(), format); - QCOMPARE(formatter->text(), text); - - delete formatter; -} - -QTEST_MAIN(tst_qdeclarativenumberformatter) - -#include "tst_qdeclarativenumberformatter.moc" -- cgit v0.12 From c78995a093ecab4802e09815147f868d4e47e2d5 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 5 Mar 2010 11:05:19 +1000 Subject: ParentAnimation docs + test. Task-number: QTBUG-8612 --- doc/src/declarative/elements.qdoc | 1 + src/declarative/util/qdeclarativeanimation.cpp | 63 + .../parentAnimation/data/parentAnimation.0.png | Bin 0 -> 3742 bytes .../parentAnimation/data/parentAnimation.1.png | Bin 0 -> 3727 bytes .../parentAnimation/data/parentAnimation.2.png | Bin 0 -> 3742 bytes .../parentAnimation/data/parentAnimation.3.png | Bin 0 -> 3628 bytes .../parentAnimation/data/parentAnimation.4.png | Bin 0 -> 3610 bytes .../parentAnimation/data/parentAnimation.5.png | Bin 0 -> 3742 bytes .../parentAnimation/data/parentAnimation.qml | 1663 ++++++++++++++++++++ .../animation/parentAnimation/parentAnimation.qml | 58 + 10 files changed, 1785 insertions(+) create mode 100644 tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.0.png create mode 100644 tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.1.png create mode 100644 tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.2.png create mode 100644 tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.3.png create mode 100644 tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.4.png create mode 100644 tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.5.png create mode 100644 tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.qml create mode 100644 tests/auto/declarative/visual/animation/parentAnimation/parentAnimation.qml diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc index 83adcb3..67aadcf 100644 --- a/doc/src/declarative/elements.qdoc +++ b/doc/src/declarative/elements.qdoc @@ -75,6 +75,7 @@ The following table lists the QML elements provided by the Qt Declarative module \o \l SequentialAnimation \o \l ParallelAnimation \o \l PauseAnimation +\o \l ParentAnimation \o \l PropertyAction \o \l ParentAction \o \l ScriptAction diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index d1a3770..49177d1 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -2391,6 +2391,52 @@ void QDeclarativePropertyAnimation::transition(QDeclarativeStateActions &actions } } +/*! + \qmlclass ParentAnimation QDeclarativeParentAnimation + \since 4.7 + \inherits Animation + \brief The ParentAnimation element allows you to animate parent changes. + + ParentAnimation is used in conjunction with NumberAnimation to smoothly + animate changing an item's parent. In the following example, + ParentAnimation wraps a NumberAnimation which animates from the + current position in the old parent to the new position in the new + parent. + + \qml + ... + State { + //reparent myItem to newParent. myItem's final location + //should be 10,10 in newParent. + ParentChange { + target: myItem + parent: newParent + x: 10; y: 10 + } + } + ... + Transition { + //smoothly reparent myItem and move into new position + ParentAnimation { + target: theItem + NumberAnimation { properties: "x,y" } + } + } + \endqml + + ParentAnimation can wrap any number of animations -- those animations will + be run in parallel (like those in a ParallelAnimation group). + + In some cases, such as reparenting between items with clipping, it's useful + to animate the parent change \i via another item with no clipping. + + When used in a transition, ParentAnimation will by default animate + all ParentChanges. +*/ +/*! + \internal + \class QDeclarativeParentAnimation +*/ QDeclarativeParentAnimation::QDeclarativeParentAnimation(QObject *parent) : QDeclarativeAnimationGroup(*(new QDeclarativeParentAnimationPrivate), parent) { @@ -2412,6 +2458,10 @@ QDeclarativeParentAnimation::~QDeclarativeParentAnimation() { } +/*! + \qmlproperty item ParentAnimation::target + The item to reparent. +*/ QDeclarativeItem *QDeclarativeParentAnimation::target() const { Q_D(const QDeclarativeParentAnimation); @@ -2436,6 +2486,19 @@ void QDeclarativeParentAnimation::setNewParent(QDeclarativeItem *newParent) d->newParent = newParent; } +/*! + \qmlproperty item ParentAnimation::via + The item to reparent via. This provides a way to do an unclipped animation + when both the old parent and new parent are clipped + + \qml + ParentAnimation { + target: myItem + via: topLevelItem + ... + } + \endqml +*/ QDeclarativeItem *QDeclarativeParentAnimation::via() const { Q_D(const QDeclarativeParentAnimation); diff --git a/tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.0.png b/tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.0.png new file mode 100644 index 0000000..7d41abc Binary files /dev/null and b/tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.0.png differ diff --git a/tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.1.png b/tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.1.png new file mode 100644 index 0000000..16b95ab Binary files /dev/null and b/tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.1.png differ diff --git a/tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.2.png b/tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.2.png new file mode 100644 index 0000000..7d41abc Binary files /dev/null and b/tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.2.png differ diff --git a/tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.3.png b/tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.3.png new file mode 100644 index 0000000..800bf12 Binary files /dev/null and b/tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.3.png differ diff --git a/tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.4.png b/tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.4.png new file mode 100644 index 0000000..d0155bb Binary files /dev/null and b/tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.4.png differ diff --git a/tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.5.png b/tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.5.png new file mode 100644 index 0000000..7d41abc Binary files /dev/null and b/tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.5.png differ diff --git a/tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.qml b/tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.qml new file mode 100644 index 0000000..5718560 --- /dev/null +++ b/tests/auto/declarative/visual/animation/parentAnimation/data/parentAnimation.qml @@ -0,0 +1,1663 @@ +import Qt.VisualTest 4.6 + +VisualTest { + Frame { + msec: 0 + } + Frame { + msec: 16 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 32 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 48 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 64 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 80 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 96 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 112 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 128 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 144 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 160 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 176 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 192 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 208 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 224 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 240 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 256 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 272 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 288 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 304 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 320 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 336 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 352 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 368 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 384 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 400 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 416 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 432 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 448 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 464 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 480 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 496 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 512 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 528 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 544 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 560 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 576 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 592 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 608 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 624 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 640 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 656 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 672 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 688 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 704 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 720 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 736 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 752 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 768 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 784 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 800 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 816 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 832 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 848 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 864 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 880 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 896 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 912 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 928 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 944 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 960 + image: "parentAnimation.0.png" + } + Frame { + msec: 976 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 992 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1008 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1024 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1040 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1056 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1072 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1088 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1104 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1120 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1136 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1152 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1168 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1184 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1200 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1216 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1232 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1248 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1264 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1280 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1296 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1312 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1328 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1344 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1360 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1376 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1392 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1408 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1424 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1440 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1456 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1472 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1488 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1504 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1520 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1536 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Mouse { + type: 2 + button: 1 + buttons: 1 + x: 237; y: 299 + modifiers: 0 + sendToViewport: true + } + Frame { + msec: 1552 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 1568 + hash: "633b5668278295faa57d0cfffe8a29cb" + } + Frame { + msec: 1584 + hash: "ccbf4505e0f05547d2f7ce874ab941c0" + } + Frame { + msec: 1600 + hash: "be904489959fa365badb642fa9e85922" + } + Frame { + msec: 1616 + hash: "de6a97ac6e2677feb223336199cbffe1" + } + Frame { + msec: 1632 + hash: "997b0a547336a9bb6a67cd9beffe1831" + } + Frame { + msec: 1648 + hash: "ac9a6e111050b8a7c4492f06c33d3969" + } + Frame { + msec: 1664 + hash: "7313c0d2ee06e393f486670222c29bb4" + } + Frame { + msec: 1680 + hash: "24cea420d03d1fdcddb1b9cf5112cbee" + } + Frame { + msec: 1696 + hash: "764688785eeaa01e9c84821476911edb" + } + Frame { + msec: 1712 + hash: "b24ae0cb512abfd2606ff9c20a6751bf" + } + Frame { + msec: 1728 + hash: "f1daed3391f10e27435a54222df8d0ab" + } + Frame { + msec: 1744 + hash: "99704e182267f2c12d0215b9c03f4d68" + } + Frame { + msec: 1760 + hash: "143cd9259a41b8af5d41a5b2aaf8de64" + } + Frame { + msec: 1776 + hash: "b5f0a0f838b5870c162a24cd767f068b" + } + Frame { + msec: 1792 + hash: "c5c8cdcbfab7466e447eaff582bf7312" + } + Frame { + msec: 1808 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 1824 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 1840 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 1856 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 1872 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 1888 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 1904 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 1920 + image: "parentAnimation.1.png" + } + Frame { + msec: 1936 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 1952 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 1968 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 1984 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2000 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2016 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2032 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2048 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2064 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2080 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2096 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2112 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2128 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2144 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2160 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2176 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2192 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2208 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2224 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2240 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2256 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2272 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2288 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2304 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2320 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2336 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2352 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2368 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2384 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2400 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2416 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2432 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2448 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2464 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2480 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Mouse { + type: 3 + button: 1 + buttons: 0 + x: 237; y: 299 + modifiers: 0 + sendToViewport: true + } + Frame { + msec: 2496 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 2512 + hash: "eaeeb8c51d43e3c38ff7dde632d1f9c8" + } + Frame { + msec: 2528 + hash: "ec0e68c2e7a75fedd1091ce633dadd4f" + } + Frame { + msec: 2544 + hash: "a5d60efc176dee9083a2d746e7ad8315" + } + Frame { + msec: 2560 + hash: "48bcbbacf413080247f818e35e496e04" + } + Frame { + msec: 2576 + hash: "c521af8efa19fbac39119ad75cd469f5" + } + Frame { + msec: 2592 + hash: "0e74613c67fc9d9acb21a3d382c5efcd" + } + Frame { + msec: 2608 + hash: "eeb3f4467ebd7ee678c3b7371db28519" + } + Frame { + msec: 2624 + hash: "9c5b9009a35b74d0ddec8fec85f204bf" + } + Frame { + msec: 2640 + hash: "aefc70824e23428aebf0a40830a57469" + } + Frame { + msec: 2656 + hash: "1fa9c23760193b74b0063b4e4c434070" + } + Frame { + msec: 2672 + hash: "8091700d4729163bd87521385853e608" + } + Frame { + msec: 2688 + hash: "a13558e609570f9390f20a85d244fa22" + } + Frame { + msec: 2704 + hash: "7be5e3609bbeb9a2c1df7d52f3953d4d" + } + Frame { + msec: 2720 + hash: "51c8ae31f858121d86ef09cc9a5c5ef3" + } + Frame { + msec: 2736 + hash: "84ce8f39207f4b07c2c3323425a8c238" + } + Frame { + msec: 2752 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 2768 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 2784 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 2800 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 2816 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 2832 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 2848 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 2864 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 2880 + image: "parentAnimation.2.png" + } + Frame { + msec: 2896 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 2912 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 2928 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 2944 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 2960 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 2976 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 2992 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 3008 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 3024 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 3040 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 3056 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 3072 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 3088 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 3104 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 3120 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 3136 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 3152 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 3168 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 3184 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 3200 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 3216 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 3232 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 3248 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 3264 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 3280 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 3296 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 3312 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 3328 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 3344 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 3360 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 3376 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Mouse { + type: 2 + button: 1 + buttons: 1 + x: 237; y: 299 + modifiers: 0 + sendToViewport: true + } + Frame { + msec: 3392 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 3408 + hash: "633b5668278295faa57d0cfffe8a29cb" + } + Frame { + msec: 3424 + hash: "ccbf4505e0f05547d2f7ce874ab941c0" + } + Frame { + msec: 3440 + hash: "be904489959fa365badb642fa9e85922" + } + Frame { + msec: 3456 + hash: "de6a97ac6e2677feb223336199cbffe1" + } + Frame { + msec: 3472 + hash: "997b0a547336a9bb6a67cd9beffe1831" + } + Frame { + msec: 3488 + hash: "ac9a6e111050b8a7c4492f06c33d3969" + } + Frame { + msec: 3504 + hash: "7313c0d2ee06e393f486670222c29bb4" + } + Frame { + msec: 3520 + hash: "24cea420d03d1fdcddb1b9cf5112cbee" + } + Frame { + msec: 3536 + hash: "764688785eeaa01e9c84821476911edb" + } + Frame { + msec: 3552 + hash: "b24ae0cb512abfd2606ff9c20a6751bf" + } + Mouse { + type: 3 + button: 1 + buttons: 0 + x: 237; y: 299 + modifiers: 0 + sendToViewport: true + } + Frame { + msec: 3568 + hash: "b24ae0cb512abfd2606ff9c20a6751bf" + } + Frame { + msec: 3584 + hash: "d7bf1b48f1a03974e7f095468e07f037" + } + Frame { + msec: 3600 + hash: "a59ab4fe1c22d27b5cdde949cf90e6f4" + } + Frame { + msec: 3616 + hash: "7c3082720e65b8a6217bf5a5fe4d48c0" + } + Frame { + msec: 3632 + hash: "350d1ff24fb8fba0ab8a6694d99544b3" + } + Frame { + msec: 3648 + hash: "81d17a62c33d79ed25968ec47771d292" + } + Frame { + msec: 3664 + hash: "43fd3ef88bd7a2e5bf4546f088783077" + } + Frame { + msec: 3680 + hash: "041938ad2e023202db18df28f2329c8f" + } + Frame { + msec: 3696 + hash: "ec8677eae06cbf77a9508953325b179e" + } + Mouse { + type: 4 + button: 1 + buttons: 1 + x: 237; y: 299 + modifiers: 0 + sendToViewport: true + } + Frame { + msec: 3712 + hash: "ec8677eae06cbf77a9508953325b179e" + } + Frame { + msec: 3728 + hash: "453026339c3901ee286831b4b41088f6" + } + Frame { + msec: 3744 + hash: "d58a7a41ade691cc0acfb0303bfc3b68" + } + Frame { + msec: 3760 + hash: "a200b05ef3d7e39e11513fd2f8ff1497" + } + Frame { + msec: 3776 + hash: "faa1223975acdf2d4b48045d7f2ce445" + } + Frame { + msec: 3792 + hash: "964d9b80d82d0fe3d3fb328a1661a60e" + } + Frame { + msec: 3808 + hash: "705871bc384de93100354acb19b371b0" + } + Frame { + msec: 3824 + hash: "1a4480463adfc5a3d525916b03c2c3ce" + } + Frame { + msec: 3840 + image: "parentAnimation.3.png" + } + Frame { + msec: 3856 + hash: "9a55bdf428f45f02d9c8cf414dcd7754" + } + Mouse { + type: 3 + button: 1 + buttons: 0 + x: 237; y: 299 + modifiers: 0 + sendToViewport: true + } + Frame { + msec: 3872 + hash: "9a55bdf428f45f02d9c8cf414dcd7754" + } + Frame { + msec: 3888 + hash: "0f6d82d02ce7d79a1bdf6bf81791f321" + } + Frame { + msec: 3904 + hash: "b145b9d299714020686069baec11cb71" + } + Frame { + msec: 3920 + hash: "5dbf5e4151c01f10cf23b07ca1df56ab" + } + Frame { + msec: 3936 + hash: "822d4397ac514673ca1015ad05c9b4ac" + } + Frame { + msec: 3952 + hash: "461d35e865153d22e9a67bb0ffddefb7" + } + Frame { + msec: 3968 + hash: "676fff498e6879144090d5596056c6c8" + } + Frame { + msec: 3984 + hash: "854da7ed627237250e20b263f9eb9d90" + } + Frame { + msec: 4000 + hash: "157ec877797883d329ff329537205d02" + } + Frame { + msec: 4016 + hash: "613669ca60240fcc490d548fe802390d" + } + Frame { + msec: 4032 + hash: "803e84f027c773db96f9530511e5fedb" + } + Mouse { + type: 2 + button: 1 + buttons: 1 + x: 237; y: 299 + modifiers: 0 + sendToViewport: true + } + Frame { + msec: 4048 + hash: "803e84f027c773db96f9530511e5fedb" + } + Frame { + msec: 4064 + hash: "f47cfd1f1094b782c08490be2f49c6ed" + } + Frame { + msec: 4080 + hash: "db5953f3ee4e2db87e33b85464167f74" + } + Frame { + msec: 4096 + hash: "8313cb750b9abc586a43b9422de08f53" + } + Frame { + msec: 4112 + hash: "deb390ce992fee85c56733168b4bd1ec" + } + Frame { + msec: 4128 + hash: "29a1cda3647c49731e9adcd107a2d13c" + } + Frame { + msec: 4144 + hash: "bfa17a3afa06699107b217df6e4aed43" + } + Frame { + msec: 4160 + hash: "8e639ef01ab6d8876c3f40adc44928c6" + } + Frame { + msec: 4176 + hash: "14038aedf42de0ca62d872d317018ee0" + } + Frame { + msec: 4192 + hash: "c1288465163d44ed40e28f21e0298ea6" + } + Frame { + msec: 4208 + hash: "d6915f22a905737488d27e8138002f31" + } + Frame { + msec: 4224 + hash: "5b1621451a5a3af40302603ec31bb8bb" + } + Frame { + msec: 4240 + hash: "16fd73c0cb615cc717cdc4a6787471c2" + } + Mouse { + type: 3 + button: 1 + buttons: 0 + x: 237; y: 299 + modifiers: 0 + sendToViewport: true + } + Frame { + msec: 4256 + hash: "16fd73c0cb615cc717cdc4a6787471c2" + } + Frame { + msec: 4272 + hash: "db5caf42e11705ecdb2006e1ed6b0c4f" + } + Frame { + msec: 4288 + hash: "4b7e51e4e9fb1dacb32aac11a4a46ceb" + } + Frame { + msec: 4304 + hash: "63c93cda9892f733809125991af997b6" + } + Frame { + msec: 4320 + hash: "0e74613c67fc9d9acb21a3d382c5efcd" + } + Frame { + msec: 4336 + hash: "58e813a6619828b6c9ec9cf300ff0e2d" + } + Frame { + msec: 4352 + hash: "181a6e334d745381f091bf1b55fc1690" + } + Frame { + msec: 4368 + hash: "f25bbc9ddc8cc72036c49d50b45bece8" + } + Frame { + msec: 4384 + hash: "88e8f0496debfee6bc2426895fe1c3d9" + } + Frame { + msec: 4400 + hash: "db5953f3ee4e2db87e33b85464167f74" + } + Frame { + msec: 4416 + hash: "9818a899adb916b6ba5f7537697ef062" + } + Frame { + msec: 4432 + hash: "3842f40093d70089a4004fb803c05981" + } + Frame { + msec: 4448 + hash: "be904489959fa365badb642fa9e85922" + } + Frame { + msec: 4464 + hash: "cbae27751ff0ebce4fcc164564f4cf1b" + } + Frame { + msec: 4480 + hash: "3a1b468bd3fd747bbe6b069426b170a9" + } + Frame { + msec: 4496 + hash: "57fbcd580eb1607a2a7526a65842dfeb" + } + Frame { + msec: 4512 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 4528 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 4544 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 4560 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 4576 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 4592 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 4608 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 4624 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Mouse { + type: 2 + button: 1 + buttons: 1 + x: 237; y: 299 + modifiers: 0 + sendToViewport: true + } + Frame { + msec: 4640 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 4656 + hash: "633b5668278295faa57d0cfffe8a29cb" + } + Frame { + msec: 4672 + hash: "ccbf4505e0f05547d2f7ce874ab941c0" + } + Frame { + msec: 4688 + hash: "be904489959fa365badb642fa9e85922" + } + Frame { + msec: 4704 + hash: "de6a97ac6e2677feb223336199cbffe1" + } + Frame { + msec: 4720 + hash: "997b0a547336a9bb6a67cd9beffe1831" + } + Frame { + msec: 4736 + hash: "ac9a6e111050b8a7c4492f06c33d3969" + } + Frame { + msec: 4752 + hash: "7313c0d2ee06e393f486670222c29bb4" + } + Frame { + msec: 4768 + hash: "24cea420d03d1fdcddb1b9cf5112cbee" + } + Frame { + msec: 4784 + hash: "764688785eeaa01e9c84821476911edb" + } + Frame { + msec: 4800 + image: "parentAnimation.4.png" + } + Frame { + msec: 4816 + hash: "f1daed3391f10e27435a54222df8d0ab" + } + Frame { + msec: 4832 + hash: "99704e182267f2c12d0215b9c03f4d68" + } + Frame { + msec: 4848 + hash: "143cd9259a41b8af5d41a5b2aaf8de64" + } + Frame { + msec: 4864 + hash: "b5f0a0f838b5870c162a24cd767f068b" + } + Frame { + msec: 4880 + hash: "c5c8cdcbfab7466e447eaff582bf7312" + } + Frame { + msec: 4896 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 4912 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 4928 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 4944 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 4960 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 4976 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 4992 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 5008 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 5024 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 5040 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 5056 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 5072 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 5088 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 5104 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 5120 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 5136 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 5152 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 5168 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 5184 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 5200 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 5216 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 5232 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 5248 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 5264 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 5280 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 5296 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 5312 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 5328 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 5344 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Mouse { + type: 3 + button: 1 + buttons: 0 + x: 237; y: 299 + modifiers: 0 + sendToViewport: true + } + Frame { + msec: 5360 + hash: "f1bc451d1f62cfb5dd60a7ea483d3844" + } + Frame { + msec: 5376 + hash: "eaeeb8c51d43e3c38ff7dde632d1f9c8" + } + Frame { + msec: 5392 + hash: "ec0e68c2e7a75fedd1091ce633dadd4f" + } + Frame { + msec: 5408 + hash: "a5d60efc176dee9083a2d746e7ad8315" + } + Frame { + msec: 5424 + hash: "48bcbbacf413080247f818e35e496e04" + } + Frame { + msec: 5440 + hash: "c521af8efa19fbac39119ad75cd469f5" + } + Frame { + msec: 5456 + hash: "0e74613c67fc9d9acb21a3d382c5efcd" + } + Frame { + msec: 5472 + hash: "eeb3f4467ebd7ee678c3b7371db28519" + } + Frame { + msec: 5488 + hash: "9c5b9009a35b74d0ddec8fec85f204bf" + } + Frame { + msec: 5504 + hash: "aefc70824e23428aebf0a40830a57469" + } + Frame { + msec: 5520 + hash: "1fa9c23760193b74b0063b4e4c434070" + } + Frame { + msec: 5536 + hash: "8091700d4729163bd87521385853e608" + } + Frame { + msec: 5552 + hash: "a13558e609570f9390f20a85d244fa22" + } + Frame { + msec: 5568 + hash: "7be5e3609bbeb9a2c1df7d52f3953d4d" + } + Frame { + msec: 5584 + hash: "51c8ae31f858121d86ef09cc9a5c5ef3" + } + Frame { + msec: 5600 + hash: "84ce8f39207f4b07c2c3323425a8c238" + } + Frame { + msec: 5616 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 5632 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 5648 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 5664 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 5680 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 5696 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 5712 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 5728 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 5744 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 5760 + image: "parentAnimation.5.png" + } + Frame { + msec: 5776 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 5792 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 5808 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 5824 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 5840 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 5856 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 5872 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 5888 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 5904 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 5920 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 5936 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 5952 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 5968 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 5984 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 6000 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 6016 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Key { + type: 6 + key: 16777249 + modifiers: 67108864 + text: "" + autorep: false + count: 1 + } + Frame { + msec: 6032 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 6048 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 6064 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 6080 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 6096 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 6112 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 6128 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 6144 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 6160 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 6176 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 6192 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 6208 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 6224 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 6240 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 6256 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } + Frame { + msec: 6272 + hash: "4135271d78a5c63c3837a09c86f35ebe" + } +} diff --git a/tests/auto/declarative/visual/animation/parentAnimation/parentAnimation.qml b/tests/auto/declarative/visual/animation/parentAnimation/parentAnimation.qml new file mode 100644 index 0000000..1833cf0 --- /dev/null +++ b/tests/auto/declarative/visual/animation/parentAnimation/parentAnimation.qml @@ -0,0 +1,58 @@ +import Qt 4.6 +Rectangle { + width: 800; + height: 480; + color: "black"; + + Rectangle { + id: gr + color: "green" + width: 100; height: 100 + } + + MouseRegion { + id: mouser + anchors.fill: parent + } + + Rectangle { + id: np + x: 300 + width: 300; height: 300 + color: "yellow" + clip: true + Rectangle { + color: "red" + x: 100; y: 100; height: 100; width: 100 + } + + } + + Rectangle { + id: vp + x: 200; y: 200 + width: 100; height: 100 + color: "blue" + rotation: 45 + scale: 2 + } + + states: State { + name: "state1" + when: mouser.pressed + ParentChange { + target: gr + parent: np + x: 100; y: 100; width: 200; + } + } + + transitions: Transition { + reversible: true + to: "state1" + ParentAnimation { + target: gr; via: vp; + NumberAnimation { properties: "x,y,rotation,scale,width" } + } + } +} -- cgit v0.12 From fefa0bb4701e0899c4b087864fcf109330fca64d Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 5 Mar 2010 11:13:02 +1000 Subject: Update QmlChanges.txt --- src/declarative/QmlChanges.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index 6e77abf..591fb3d 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -7,6 +7,8 @@ Flickable: renamed viewportX -> contentX Flickable: renamed viewportY -> contentY Removed Flickable.reportedVelocitySmoothing Removed Qt.playSound (replaced by SoundEffect element) +Removed NumberFormatter +Removed DateTimeFormatter (use Qt.formatDateTime() instead) Renamed MouseRegion -> MouseArea Connection: syntax and rename: Connection { sender: a; signal: foo(); script: xxx } -- cgit v0.12 From af81ea8a5abbd9a94eb6ab5c3fe0425779905d5a Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Fri, 5 Mar 2010 11:14:38 +1000 Subject: Fix test --- .../tst_qdeclarativexmllistmodel.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp index 68029bc..20f4ef3 100644 --- a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp +++ b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp @@ -266,6 +266,8 @@ void tst_qdeclarativexmllistmodel::reload() QCOMPARE(spyRemove[0][0].toInt(), 0); QCOMPARE(spyRemove[0][1].toInt(), 9); + + delete model; } void tst_qdeclarativexmllistmodel::useKeys() @@ -284,7 +286,7 @@ void tst_qdeclarativexmllistmodel::useKeys() QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/roleKeys.qml")); QDeclarativeXmlListModel *model = qobject_cast(component.create()); QVERIFY(model != 0); - + model->setXml(oldXml); QTRY_COMPARE(model->count(), oldCount); @@ -319,6 +321,8 @@ void tst_qdeclarativexmllistmodel::useKeys() QCOMPARE(spyRemove[i][0].toInt(), removeRanges[i].first); QCOMPARE(spyRemove[i][1].toInt(), removeRanges[i].second); } + + delete model; } void tst_qdeclarativexmllistmodel::useKeys_data() @@ -448,18 +452,16 @@ void tst_qdeclarativexmllistmodel::noKeysValueChanges() model->setXml(xml); // wait for the new xml data to be set, and verify no signals were emitted - for (int i=0; i<50; i++) { - QTest::qWait(100); - if (model->data(0, model->roles()[2]).toString() != QLatin1String("AussieRules")) - break; - } + QTRY_VERIFY(model->data(0, model->roles()[2]).toString() != QLatin1String("Football")); QCOMPARE(model->data(0, model->roles()[2]).toString(), QLatin1String("AussieRules")); QVERIFY(spyInsert.count() == 0); QVERIFY(spyRemove.count() == 0); QVERIFY(spyCount.count() == 0); - + QCOMPARE(model->count(), 2); + + delete model; } void tst_qdeclarativexmllistmodel::keysChanged() @@ -494,6 +496,8 @@ void tst_qdeclarativexmllistmodel::keysChanged() QCOMPARE(spyRemove[0][1].toInt(), 2); QCOMPARE(spyCount.count(), 0); + + delete model; } QTEST_MAIN(tst_qdeclarativexmllistmodel) -- cgit v0.12 From 24a94c1b88fc72243c53e1bf51b87dc0d0be41b7 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Fri, 5 Mar 2010 11:18:53 +1000 Subject: declarative examples cleanup --- examples/declarative/behaviours/MyRect.qml | 13 ------- examples/declarative/fonts/fonts.qml | 13 ------- examples/declarative/listview/itemlist.qml | 8 ++--- examples/declarative/mousearea/mouse.qml | 40 ++++++++++++++++++++++ examples/declarative/mouseregion/mouse.qml | 40 ---------------------- .../plugins/com/nokia/TimeExample/Clock.qml | 8 ++--- examples/declarative/searchbox/main.qml | 6 ++-- examples/declarative/velocity/Day.qml | 4 +-- 8 files changed, 52 insertions(+), 80 deletions(-) delete mode 100644 examples/declarative/behaviours/MyRect.qml create mode 100644 examples/declarative/mousearea/mouse.qml delete mode 100644 examples/declarative/mouseregion/mouse.qml diff --git a/examples/declarative/behaviours/MyRect.qml b/examples/declarative/behaviours/MyRect.qml deleted file mode 100644 index caf0d83..0000000 --- a/examples/declarative/behaviours/MyRect.qml +++ /dev/null @@ -1,13 +0,0 @@ -import Qt 4.6 - -Rectangle { - radius: 15 - border.color: "black" - width: 100 - height: 100 - id: page - MouseArea { - anchors.fill: parent - onClicked: { bluerect.parent = page; bluerect.x=0 } - } -} diff --git a/examples/declarative/fonts/fonts.qml b/examples/declarative/fonts/fonts.qml index 275ad43..6246d16 100644 --- a/examples/declarative/fonts/fonts.qml +++ b/examples/declarative/fonts/fonts.qml @@ -7,11 +7,8 @@ Rectangle { color: "steelblue" FontLoader { id: fixedFont; name: "Courier" } - FontLoader { id: localFont; source: "fonts/tarzenau-ocr-a.ttf" } - FontLoader { id: webFont; source: "http://www.princexml.com/fonts/steffmann/Starburst.ttf" } - FontLoader { id: webFont2; source: "http://wrong.address.org" } Column { anchors.fill: parent; spacing: 10 @@ -55,15 +52,5 @@ Rectangle { width: parent.width; elide: Text.ElideMiddle font.family: webFont.name; font.pointSize: 36 } - Text { - text: { - if (webFont2.status == 1) myText - else if (webFont2.status == 2) "Loading..." - else if (webFont2.status == 3) "Error loading font" - } - color: "lightsteelblue" - width: parent.width; elide: Text.ElideRight - font.family: webFont2.name; font.pointSize: 36 - } } } diff --git a/examples/declarative/listview/itemlist.qml b/examples/declarative/listview/itemlist.qml index 54981b7..41aa860 100644 --- a/examples/declarative/listview/itemlist.qml +++ b/examples/declarative/listview/itemlist.qml @@ -26,14 +26,12 @@ Rectangle { ListView { id: view - anchors.fill: parent - anchors.bottomMargin: 30 + anchors.fill: parent; anchors.bottomMargin: 30 model: itemModel - preferredHighlightBegin: 0 - preferredHighlightEnd: 0 + preferredHighlightBegin: 0; preferredHighlightEnd: 0 highlightRangeMode: "StrictlyEnforceRange" orientation: ListView.Horizontal - flickDeceleration: 2000 + snapMode: ListView.SnapOneItem; flickDeceleration: 2000 } Rectangle { diff --git a/examples/declarative/mousearea/mouse.qml b/examples/declarative/mousearea/mouse.qml new file mode 100644 index 0000000..9191f8a --- /dev/null +++ b/examples/declarative/mousearea/mouse.qml @@ -0,0 +1,40 @@ +import Qt 4.6 + +Rectangle { + color: "white" + width: 200; height: 200 + Rectangle { + width: 50; height: 50 + color: "red" + Text { text: "Click"; anchors.centerIn: parent } + MouseArea { + hoverEnabled: true + acceptedButtons: Qt.LeftButton | Qt.RightButton + onPressed: { console.log('press (x: ' + mouse.x + ' y: ' + mouse.y + ' button: ' + (mouse.button == Qt.RightButton ? 'right' : 'left') + ' Shift: ' + (mouse.modifiers & Qt.ShiftModifier ? 'true' : 'false') + ')') } + onReleased: { console.log('release (x: ' + mouse.x + ' y: ' + mouse.y + ' isClick: ' + mouse.isClick + ' wasHeld: ' + mouse.wasHeld + ')') } + onClicked: { console.log('click (x: ' + mouse.x + ' y: ' + mouse.y + ' wasHeld: ' + mouse.wasHeld + ')') } + onDoubleClicked: { console.log('double click (x: ' + mouse.x + ' y: ' + mouse.y + ')') } + onPressAndHold: { console.log('press and hold') } + onEntered: { console.log('entered ' + pressed) } + onExited: { console.log('exited ' + pressed) } + anchors.fill: parent + } + } + Rectangle { + y: 100; width: 50; height: 50 + color: "blue" + Text { text: "Drag"; anchors.centerIn: parent } + MouseArea { + drag.target: parent + drag.axis: "XAxis" + drag.minimumX: 0 + drag.maximumX: 150 + onPressed: { console.log('press') } + onReleased: { console.log('release (isClick: ' + mouse.isClick + ') (wasHeld: ' + mouse.wasHeld + ')') } + onClicked: { console.log('click' + '(wasHeld: ' + mouse.wasHeld + ')') } + onDoubleClicked: { console.log('double click') } + onPressAndHold: { console.log('press and hold') } + anchors.fill: parent + } + } +} diff --git a/examples/declarative/mouseregion/mouse.qml b/examples/declarative/mouseregion/mouse.qml deleted file mode 100644 index 9191f8a..0000000 --- a/examples/declarative/mouseregion/mouse.qml +++ /dev/null @@ -1,40 +0,0 @@ -import Qt 4.6 - -Rectangle { - color: "white" - width: 200; height: 200 - Rectangle { - width: 50; height: 50 - color: "red" - Text { text: "Click"; anchors.centerIn: parent } - MouseArea { - hoverEnabled: true - acceptedButtons: Qt.LeftButton | Qt.RightButton - onPressed: { console.log('press (x: ' + mouse.x + ' y: ' + mouse.y + ' button: ' + (mouse.button == Qt.RightButton ? 'right' : 'left') + ' Shift: ' + (mouse.modifiers & Qt.ShiftModifier ? 'true' : 'false') + ')') } - onReleased: { console.log('release (x: ' + mouse.x + ' y: ' + mouse.y + ' isClick: ' + mouse.isClick + ' wasHeld: ' + mouse.wasHeld + ')') } - onClicked: { console.log('click (x: ' + mouse.x + ' y: ' + mouse.y + ' wasHeld: ' + mouse.wasHeld + ')') } - onDoubleClicked: { console.log('double click (x: ' + mouse.x + ' y: ' + mouse.y + ')') } - onPressAndHold: { console.log('press and hold') } - onEntered: { console.log('entered ' + pressed) } - onExited: { console.log('exited ' + pressed) } - anchors.fill: parent - } - } - Rectangle { - y: 100; width: 50; height: 50 - color: "blue" - Text { text: "Drag"; anchors.centerIn: parent } - MouseArea { - drag.target: parent - drag.axis: "XAxis" - drag.minimumX: 0 - drag.maximumX: 150 - onPressed: { console.log('press') } - onReleased: { console.log('release (isClick: ' + mouse.isClick + ') (wasHeld: ' + mouse.wasHeld + ')') } - onClicked: { console.log('click' + '(wasHeld: ' + mouse.wasHeld + ')') } - onDoubleClicked: { console.log('double click') } - onPressAndHold: { console.log('press and hold') } - anchors.fill: parent - } - } -} diff --git a/examples/declarative/plugins/com/nokia/TimeExample/Clock.qml b/examples/declarative/plugins/com/nokia/TimeExample/Clock.qml index 01ec686..622fcf9 100644 --- a/examples/declarative/plugins/com/nokia/TimeExample/Clock.qml +++ b/examples/declarative/plugins/com/nokia/TimeExample/Clock.qml @@ -1,8 +1,8 @@ import Qt 4.6 -Item { +Rectangle { id: clock - width: 200; height: 200 + width: 200; height: 200; color: "gray" property alias city: cityLabel.text property var hours @@ -18,7 +18,7 @@ Item { transform: Rotation { id: hourRotation origin.x: 7.5; origin.y: 73; angle: 0 - angle: SpringFollow { + SpringFollow on angle { spring: 2; damping: 0.2; modulus: 360 source: (clock.hours * 30) + (clock.minutes * 0.5) } @@ -32,7 +32,7 @@ Item { transform: Rotation { id: minuteRotation origin.x: 6.5; origin.y: 83; angle: 0 - angle: SpringFollow { + SpringFollow on angle { spring: 2; damping: 0.2; modulus: 360 source: clock.minutes * 6 } diff --git a/examples/declarative/searchbox/main.qml b/examples/declarative/searchbox/main.qml index 39c3720..9b33be3 100644 --- a/examples/declarative/searchbox/main.qml +++ b/examples/declarative/searchbox/main.qml @@ -6,8 +6,8 @@ Rectangle { Column { anchors.horizontalCenter: parent.horizontalCenter; anchors.verticalCenter: parent.verticalCenter; spacing: 10 - SearchBox { id: search1; KeyNavigation.down: search2; focus: true } - SearchBox { id: search2; KeyNavigation.up: search1; KeyNavigation.down: search3 } - SearchBox { id: search3; KeyNavigation.up: search2 } + SearchBox { id: search1; KeyNavigation.tab: search2; KeyNavigation.backtab: search3; focus: true } + SearchBox { id: search2; KeyNavigation.tab: search3; KeyNavigation.backtab: search1 } + SearchBox { id: search3; KeyNavigation.tab: search1; KeyNavigation.backtab: search2 } } } diff --git a/examples/declarative/velocity/Day.qml b/examples/declarative/velocity/Day.qml index 7424f60..8a7364e 100644 --- a/examples/declarative/velocity/Day.qml +++ b/examples/declarative/velocity/Day.qml @@ -33,7 +33,7 @@ Rectangle { id: sticky scale: 0.5 Image { - id: stickyImage; source: "sticky.png" + id: stickyImage; source: "sticky.png"; transformOrigin: Item.TopLeft smooth: true; y: -20; x: 8 + -width * 0.6 / 2; scale: 0.6 } @@ -59,7 +59,7 @@ Rectangle { } Image { - source: "tack.png" + source: "tack.png"; transformOrigin: Item.TopLeft x: -width / 2; y: -height * 0.7 / 2; scale: 0.7 } -- cgit v0.12 From 356963b1bc81dcad1826449da14b6130eea9cc3f Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 5 Mar 2010 11:33:57 +1000 Subject: Document new ParentChange properties. --- .../util/qdeclarativestateoperations.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/declarative/util/qdeclarativestateoperations.cpp b/src/declarative/util/qdeclarativestateoperations.cpp index cea9ad7..cd06380 100644 --- a/src/declarative/util/qdeclarativestateoperations.cpp +++ b/src/declarative/util/qdeclarativestateoperations.cpp @@ -158,17 +158,17 @@ void QDeclarativeParentChangePrivate::doChange(QDeclarativeItem *targetParent, Q \qmlclass ParentChange QDeclarativeParentChange \brief The ParentChange element allows you to reparent an Item in a state change. - ParentChange reparents an Item while preserving its visual appearance (position, rotation, - and scale) on screen. You can then specify a transition to move/rotate/scale the Item to - its final intended appearance. + ParentChange reparents an item while preserving its visual appearance (position, size, + rotation, and scale) on screen. You can then specify a transition to move/resize/rotate/scale + the item to its final intended appearance. ParentChange can only preserve visual appearance if no complex transforms are involved. More specifically, it will not work if the transform property has been set for any - Items involved in the reparenting (defined as any Items in the common ancestor tree + items involved in the reparenting (i.e. items in the common ancestor tree for the original and new parent). You can specify at which point in a transition you want a ParentChange to occur by - using a ParentAction. + using a ParentAnimation or ParentAction. */ @@ -181,6 +181,16 @@ QDeclarativeParentChange::~QDeclarativeParentChange() { } +/*! + \qmlproperty real ParentChange::x + \qmlproperty real ParentChange::y + \qmlproperty real ParentChange::width + \qmlproperty real ParentChange::height + \qmlproperty real ParentChange::scale + \qmlproperty real ParentChange::rotation + These properties hold the new position, size, scale, and rotation + for the item in this state. +*/ qreal QDeclarativeParentChange::x() const { Q_D(const QDeclarativeParentChange); @@ -314,7 +324,7 @@ void QDeclarativeParentChange::setObject(QDeclarativeItem *target) /*! \qmlproperty Item ParentChange::parent - This property holds the parent for the item in this state + This property holds the new parent for the item in this state. */ QDeclarativeItem *QDeclarativeParentChange::parent() const -- cgit v0.12 From 34052400e537c188af883c4152df760bc531060d Mon Sep 17 00:00:00 2001 From: Joona Petrell Date: Thu, 4 Mar 2010 15:58:26 +1000 Subject: Add missing NOTIFYs to timer, xmllistmodel, xmlrole Reviewed-by: akennedy --- src/declarative/util/qdeclarativetimer.cpp | 3 + src/declarative/util/qdeclarativetimer_p.h | 9 ++- src/declarative/util/qdeclarativexmllistmodel.cpp | 14 +++-- src/declarative/util/qdeclarativexmllistmodel_p.h | 41 +++++++++---- .../qdeclarativetimer/tst_qdeclarativetimer.cpp | 37 ++++++++++++ .../data/propertychanges.qml | 10 ++++ .../tst_qdeclarativexmllistmodel.cpp | 70 ++++++++++++++++++++++ 7 files changed, 167 insertions(+), 17 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativexmllistmodel/data/propertychanges.qml diff --git a/src/declarative/util/qdeclarativetimer.cpp b/src/declarative/util/qdeclarativetimer.cpp index d7e02b1..104e3ae 100644 --- a/src/declarative/util/qdeclarativetimer.cpp +++ b/src/declarative/util/qdeclarativetimer.cpp @@ -123,6 +123,7 @@ void QDeclarativeTimer::setInterval(int interval) if (interval != d->interval) { d->interval = interval; update(); + emit intervalChanged(); } } @@ -183,6 +184,7 @@ void QDeclarativeTimer::setRepeating(bool repeating) if (repeating != d->repeating) { d->repeating = repeating; update(); + emit repeatChanged(); } } @@ -215,6 +217,7 @@ void QDeclarativeTimer::setTriggeredOnStart(bool triggeredOnStart) if (d->triggeredOnStart != triggeredOnStart) { d->triggeredOnStart = triggeredOnStart; update(); + emit triggeredOnStartChanged(); } } diff --git a/src/declarative/util/qdeclarativetimer_p.h b/src/declarative/util/qdeclarativetimer_p.h index e063657..d1e6630 100644 --- a/src/declarative/util/qdeclarativetimer_p.h +++ b/src/declarative/util/qdeclarativetimer_p.h @@ -59,10 +59,10 @@ class Q_DECLARATIVE_EXPORT QDeclarativeTimer : public QObject, public QDeclarati Q_OBJECT Q_DECLARE_PRIVATE(QDeclarativeTimer) Q_INTERFACES(QDeclarativeParserStatus) - Q_PROPERTY(int interval READ interval WRITE setInterval) + Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY intervalChanged) Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged) - Q_PROPERTY(bool repeat READ isRepeating WRITE setRepeating) - Q_PROPERTY(bool triggeredOnStart READ triggeredOnStart WRITE setTriggeredOnStart) + Q_PROPERTY(bool repeat READ isRepeating WRITE setRepeating NOTIFY repeatChanged) + Q_PROPERTY(bool triggeredOnStart READ triggeredOnStart WRITE setTriggeredOnStart NOTIFY triggeredOnStartChanged) public: QDeclarativeTimer(QObject *parent=0); @@ -91,6 +91,9 @@ public Q_SLOTS: Q_SIGNALS: void triggered(); void runningChanged(); + void intervalChanged(); + void repeatChanged(); + void triggeredOnStartChanged(); private: void update(); diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp index d260ada..53e08b0 100644 --- a/src/declarative/util/qdeclarativexmllistmodel.cpp +++ b/src/declarative/util/qdeclarativexmllistmodel.cpp @@ -571,9 +571,10 @@ void QDeclarativeXmlListModel::setSource(const QUrl &src) { Q_D(QDeclarativeXmlListModel); if (d->src != src) { - d->src = src; reload(); - } + d->src = src; + emit sourceChanged(); + } } /*! @@ -593,8 +594,11 @@ QString QDeclarativeXmlListModel::xml() const void QDeclarativeXmlListModel::setXml(const QString &xml) { Q_D(QDeclarativeXmlListModel); - d->xml = xml; - reload(); + if (d->xml != xml) { + d->xml = xml; + reload(); + emit xmlChanged(); + } } /*! @@ -619,6 +623,7 @@ void QDeclarativeXmlListModel::setQuery(const QString &query) if (d->query != query) { d->query = query; reload(); + emit queryChanged(); } } @@ -638,6 +643,7 @@ void QDeclarativeXmlListModel::setNamespaceDeclarations(const QString &declarati if (d->namespaces != declarations) { d->namespaces = declarations; reload(); + emit namespaceDeclarationsChanged(); } } diff --git a/src/declarative/util/qdeclarativexmllistmodel_p.h b/src/declarative/util/qdeclarativexmllistmodel_p.h index f0ad4b8..23ff7ce 100644 --- a/src/declarative/util/qdeclarativexmllistmodel_p.h +++ b/src/declarative/util/qdeclarativexmllistmodel_p.h @@ -68,10 +68,10 @@ class Q_DECLARATIVE_EXPORT QDeclarativeXmlListModel : public QListModelInterface Q_PROPERTY(Status status READ status NOTIFY statusChanged) Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) - Q_PROPERTY(QUrl source READ source WRITE setSource) - Q_PROPERTY(QString xml READ xml WRITE setXml) - Q_PROPERTY(QString query READ query WRITE setQuery) - Q_PROPERTY(QString namespaceDeclarations READ namespaceDeclarations WRITE setNamespaceDeclarations) + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(QString xml READ xml WRITE setXml NOTIFY xmlChanged) + Q_PROPERTY(QString query READ query WRITE setQuery NOTIFY queryChanged) + Q_PROPERTY(QString namespaceDeclarations READ namespaceDeclarations WRITE setNamespaceDeclarations NOTIFY namespaceDeclarationsChanged) Q_PROPERTY(QDeclarativeListProperty roles READ roleObjects) Q_PROPERTY(int count READ count NOTIFY countChanged) Q_CLASSINFO("DefaultProperty", "roles") @@ -111,6 +111,10 @@ Q_SIGNALS: void statusChanged(Status); void progressChanged(qreal progress); void countChanged(); + void sourceChanged(); + void xmlChanged(); + void queryChanged(); + void namespaceDeclarationsChanged(); public Q_SLOTS: // ### need to use/expose Expiry to guess when to call this? @@ -132,16 +136,20 @@ private: class Q_DECLARATIVE_EXPORT QDeclarativeXmlListModelRole : public QObject { Q_OBJECT - Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(QString query READ query WRITE setQuery) - Q_PROPERTY(bool isKey READ isKey WRITE setIsKey) - + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(QString query READ query WRITE setQuery NOTIFY queryChanged) + Q_PROPERTY(bool isKey READ isKey WRITE setIsKey NOTIFY isKeyChanged) public: QDeclarativeXmlListModelRole() : m_isKey(false) {} ~QDeclarativeXmlListModelRole() {} QString name() const { return m_name; } - void setName(const QString &name) { m_name = name; } + void setName(const QString &name) { + if (name == m_name) + return; + m_name = name; + emit nameChanged(); + } QString query() const { return m_query; } void setQuery(const QString &query) @@ -150,16 +158,29 @@ public: qmlInfo(this) << tr("An XmlRole query must not start with '/'"); return; } + if (m_query == query) + return; m_query = query; + emit queryChanged(); } bool isKey() const { return m_isKey; } - void setIsKey(bool b) { m_isKey = b; } + void setIsKey(bool b) { + if (m_isKey == b) + return; + m_isKey = b; + emit isKeyChanged(); + } bool isValid() { return !m_name.isEmpty() && !m_query.isEmpty(); } +Q_SIGNALS: + void nameChanged(); + void queryChanged(); + void isKeyChanged(); + private: QString m_name; QString m_query; diff --git a/tests/auto/declarative/qdeclarativetimer/tst_qdeclarativetimer.cpp b/tests/auto/declarative/qdeclarativetimer/tst_qdeclarativetimer.cpp index b120d5d..1dfec50 100644 --- a/tests/auto/declarative/qdeclarativetimer/tst_qdeclarativetimer.cpp +++ b/tests/auto/declarative/qdeclarativetimer/tst_qdeclarativetimer.cpp @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include #include #include #include @@ -161,6 +162,18 @@ void tst_qdeclarativetimer::repeat() QVERIFY(helper.count == oldCount); QVERIFY(timer->isRunning() == false); + QSignalSpy spy(timer, SIGNAL(repeatChanged())); + + timer->setRepeating(false); + QVERIFY(!timer->isRepeating()); + QCOMPARE(spy.count(),1); + + timer->setRepeating(false); + QCOMPARE(spy.count(),1); + + timer->setRepeating(true); + QCOMPARE(spy.count(),2); + delete timer; } @@ -184,6 +197,18 @@ void tst_qdeclarativetimer::triggeredOnStart() QCOMPARE(helper.count, 2); QVERIFY(timer->isRunning() == false); + QSignalSpy spy(timer, SIGNAL(triggeredOnStartChanged())); + + timer->setTriggeredOnStart(false); + QVERIFY(!timer->triggeredOnStart()); + QCOMPARE(spy.count(),1); + + timer->setTriggeredOnStart(false); + QCOMPARE(spy.count(),1); + + timer->setTriggeredOnStart(true); + QCOMPARE(spy.count(),2); + delete timer; } @@ -250,6 +275,18 @@ void tst_qdeclarativetimer::changeDuration() QCOMPARE(helper.count, 3); QVERIFY(timer->isRunning()); + QSignalSpy spy(timer, SIGNAL(intervalChanged())); + + timer->setInterval(200); + QCOMPARE(timer->interval(), 200); + QCOMPARE(spy.count(),1); + + timer->setInterval(200); + QCOMPARE(spy.count(),1); + + timer->setInterval(300); + QCOMPARE(spy.count(),2); + delete timer; } diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/data/propertychanges.qml b/tests/auto/declarative/qdeclarativexmllistmodel/data/propertychanges.qml new file mode 100644 index 0000000..737ec81 --- /dev/null +++ b/tests/auto/declarative/qdeclarativexmllistmodel/data/propertychanges.qml @@ -0,0 +1,10 @@ +import Qt 4.6 + +XmlListModel { + source: "model.xml" + query: "/Pets/Pet" + XmlRole { objectName: "role"; 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/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp index 68029bc..6199234 100644 --- a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp +++ b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp @@ -74,6 +74,7 @@ private slots: void useKeys_data(); void noKeysValueChanges(); void keysChanged(); + void propertyChanges(); private: QString makeItemXmlAndData(const QString &data, QDeclarativeXmlModelData *modelData = 0) const @@ -440,6 +441,8 @@ void tst_qdeclarativexmllistmodel::noKeysValueChanges() model->setXml(xml); QTRY_COMPARE(model->count(), 2); + model->setXml(""); + QSignalSpy spyInsert(model, SIGNAL(itemsInserted(int,int))); QSignalSpy spyRemove(model, SIGNAL(itemsRemoved(int,int))); QSignalSpy spyCount(model, SIGNAL(countChanged())); @@ -476,6 +479,8 @@ void tst_qdeclarativexmllistmodel::keysChanged() model->setXml(xml); QTRY_COMPARE(model->count(), 2); + model->setXml(""); + QSignalSpy spyInsert(model, SIGNAL(itemsInserted(int,int))); QSignalSpy spyRemove(model, SIGNAL(itemsRemoved(int,int))); QSignalSpy spyCount(model, SIGNAL(countChanged())); @@ -496,6 +501,71 @@ void tst_qdeclarativexmllistmodel::keysChanged() QCOMPARE(spyCount.count(), 0); } +void tst_qdeclarativexmllistmodel::propertyChanges() +{ + QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + QDeclarativeXmlListModel *model = qobject_cast(component.create()); + QVERIFY(model != 0); + QTRY_COMPARE(model->count(), 9); + + QDeclarativeXmlListModelRole *role = model->findChild("role"); + QVERIFY(role); + + QSignalSpy nameSpy(role, SIGNAL(nameChanged())); + QSignalSpy querySpy(role, SIGNAL(queryChanged())); + QSignalSpy isKeySpy(role, SIGNAL(isKeyChanged())); + + role->setName("size"); + role->setQuery("size/string()"); + role->setIsKey(true); + + QCOMPARE(role->name(), QString("size")); + QCOMPARE(role->query(), QString("size/string()")); + QVERIFY(role->isKey()); + + QCOMPARE(nameSpy.count(),1); + QCOMPARE(querySpy.count(),1); + QCOMPARE(isKeySpy.count(),1); + + role->setName("size"); + role->setQuery("size/string()"); + role->setIsKey(true); + + QCOMPARE(nameSpy.count(),1); + QCOMPARE(querySpy.count(),1); + QCOMPARE(isKeySpy.count(),1); + + QSignalSpy sourceSpy(model, SIGNAL(sourceChanged())); + QSignalSpy xmlSpy(model, SIGNAL(xmlChanged())); + QSignalSpy modelQuerySpy(model, SIGNAL(queryChanged())); + QSignalSpy namespaceDeclarationsSpy(model, SIGNAL(namespaceDeclarationsChanged())); + + model->setSource(QUrl("")); + model->setXml("PollyParrot12Small"); + model->setQuery("/Pets"); + model->setNamespaceDeclarations("declare namespace media=\"http://search.yahoo.com/mrss/\";"); + + QCOMPARE(model->source(), QUrl("")); + QCOMPARE(model->xml(), QString("PollyParrot12Small")); + QCOMPARE(model->query(), QString("/Pets")); + QCOMPARE(model->namespaceDeclarations(), QString("declare namespace media=\"http://search.yahoo.com/mrss/\";")); + + QCOMPARE(sourceSpy.count(),1); + QCOMPARE(xmlSpy.count(),1); + QCOMPARE(modelQuerySpy.count(),1); + QCOMPARE(namespaceDeclarationsSpy.count(),1); + + model->setSource(QUrl("")); + model->setXml("PollyParrot12Small"); + model->setQuery("/Pets"); + model->setNamespaceDeclarations("declare namespace media=\"http://search.yahoo.com/mrss/\";"); + + QCOMPARE(sourceSpy.count(),1); + QCOMPARE(xmlSpy.count(),1); + QCOMPARE(modelQuerySpy.count(),1); + QCOMPARE(namespaceDeclarationsSpy.count(),1); +} + QTEST_MAIN(tst_qdeclarativexmllistmodel) #include "tst_qdeclarativexmllistmodel.moc" -- cgit v0.12 From 87628252d721d4f8cf6963e5f20a02a56bd70f9a Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Fri, 5 Mar 2010 12:51:45 +1000 Subject: Use _data() for some tests --- .../tst_qdeclarativexmlhttprequest.cpp | 535 ++++++--------------- 1 file changed, 158 insertions(+), 377 deletions(-) diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp b/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp index 7dec0ee..01f07ab 100644 --- a/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp +++ b/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp @@ -69,6 +69,7 @@ private slots: void constructor(); void defaultState(); void open(); + void open_data(); void open_invalid_method(); void open_sync(); void open_arg_count(); @@ -82,6 +83,7 @@ private slots: void send_alreadySent(); void send_ignoreData(); void send_withdata(); + void send_withdata_data(); void abort(); void abort_unsent(); void abort_opened(); @@ -94,8 +96,11 @@ private slots: void getAllResponseHeaders_sent(); void getAllResponseHeaders_args(); void status(); + void status_data(); void statusText(); + void statusText_data(); void responseText(); + void responseText_data(); void responseXML_invalid(); void invalidMethodUsage(); void redirects(); @@ -257,99 +262,50 @@ void tst_qdeclarativexmlhttprequest::defaultState() // Test valid XMLHttpRequest.open() calls void tst_qdeclarativexmlhttprequest::open() { - // Relative url - { - QDeclarativeComponent component(&engine, TEST_FILE("open.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "testdocument.html"); - component.completeCreate(); - - QCOMPARE(object->property("readyState").toBool(), true); - QCOMPARE(object->property("openedState").toBool(), true); - QCOMPARE(object->property("status").toBool(), true); - QCOMPARE(object->property("statusText").toBool(), true); - QCOMPARE(object->property("responseText").toBool(), true); - QCOMPARE(object->property("responseXML").toBool(), true); - - TRY_WAIT(object->property("dataOK").toBool() == true); - - delete object; + QFETCH(QUrl, qmlFile); + QFETCH(QString, url); + QFETCH(bool, remote); + + TestHTTPServer *server = 0; + if (remote) { + server = new TestHTTPServer(SERVER_PORT); + QVERIFY(server->isValid()); + QVERIFY(server->wait(TEST_FILE("open_network.expect"), + TEST_FILE("open_network.reply"), + TEST_FILE("testdocument.html"))); } - // Absolute url - { - QDeclarativeComponent component(&engine, TEST_FILE("open.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", TEST_FILE("testdocument.html").toString()); - component.completeCreate(); - - QCOMPARE(object->property("readyState").toBool(), true); - QCOMPARE(object->property("openedState").toBool(), true); - QCOMPARE(object->property("status").toBool(), true); - QCOMPARE(object->property("statusText").toBool(), true); - QCOMPARE(object->property("responseText").toBool(), true); - QCOMPARE(object->property("responseXML").toBool(), true); - - TRY_WAIT(object->property("dataOK").toBool() == true); - - delete object; - } - - // Absolute network url - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("open_network.expect"), - TEST_FILE("open_network.reply"), - TEST_FILE("testdocument.html"))); - - QDeclarativeComponent component(&engine, TEST_FILE("open.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - component.completeCreate(); - - QCOMPARE(object->property("readyState").toBool(), true); - QCOMPARE(object->property("openedState").toBool(), true); - QCOMPARE(object->property("status").toBool(), true); - QCOMPARE(object->property("statusText").toBool(), true); - QCOMPARE(object->property("responseText").toBool(), true); - QCOMPARE(object->property("responseXML").toBool(), true); - - TRY_WAIT(object->property("dataOK").toBool() == true); - - delete object; - } + QDeclarativeComponent component(&engine, qmlFile); + QObject *object = component.beginCreate(engine.rootContext()); + QVERIFY(object != 0); + object->setProperty("url", url); + component.completeCreate(); - // User/pass - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("open_network.expect"), - TEST_FILE("open_network.reply"), - TEST_FILE("testdocument.html"))); + QCOMPARE(object->property("readyState").toBool(), true); + QCOMPARE(object->property("openedState").toBool(), true); + QCOMPARE(object->property("status").toBool(), true); + QCOMPARE(object->property("statusText").toBool(), true); + QCOMPARE(object->property("responseText").toBool(), true); + QCOMPARE(object->property("responseXML").toBool(), true); - QDeclarativeComponent component(&engine, TEST_FILE("open_user.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - component.completeCreate(); + TRY_WAIT(object->property("dataOK").toBool() == true); - QCOMPARE(object->property("readyState").toBool(), true); - QCOMPARE(object->property("openedState").toBool(), true); - QCOMPARE(object->property("status").toBool(), true); - QCOMPARE(object->property("statusText").toBool(), true); - QCOMPARE(object->property("responseText").toBool(), true); - QCOMPARE(object->property("responseXML").toBool(), true); + delete server; + delete object; +} - TRY_WAIT(object->property("dataOK").toBool() == true); +void tst_qdeclarativexmlhttprequest::open_data() +{ + QTest::addColumn("qmlFile"); + QTest::addColumn("url"); + QTest::addColumn("remote"); - // ### Check that the username/password were sent to the server + QTest::newRow("Relative url)") << TEST_FILE("open.qml") << "testdocument.html" << false; + QTest::newRow("Absolute url)") << TEST_FILE("open.qml") << TEST_FILE("testdocument.html").toString() << false; + QTest::newRow("Absolute network url)") << TEST_FILE("open.qml") << "http://127.0.0.1:14445/testdocument.html" << true; - delete object; - } + // ### Check that the username/password were sent to the server + QTest::newRow("User/pass") << TEST_FILE("open_user.qml") << "http://127.0.0.1:14445/testdocument.html" << true; } // Test that calling XMLHttpRequest.open() with an invalid method raises an exception @@ -594,138 +550,38 @@ void tst_qdeclarativexmlhttprequest::send_ignoreData() // Test that send()'ing data works void tst_qdeclarativexmlhttprequest::send_withdata() { - // No content-type - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("send_data.1.expect"), - TEST_FILE("send_data.reply"), - TEST_FILE("testdocument.html"))); - - QDeclarativeComponent component(&engine, TEST_FILE("send_data.1.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - component.completeCreate(); - - TRY_WAIT(object->property("dataOK").toBool() == true); + QFETCH(QString, file_expected); + QFETCH(QString, file_qml); - delete object; - } - - // Correct content-type - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("send_data.1.expect"), - TEST_FILE("send_data.reply"), - TEST_FILE("testdocument.html"))); - - QDeclarativeComponent component(&engine, TEST_FILE("send_data.2.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - component.completeCreate(); - - TRY_WAIT(object->property("dataOK").toBool() == true); - - delete object; - } - - // Incorrect content-type - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("send_data.1.expect"), - TEST_FILE("send_data.reply"), - TEST_FILE("testdocument.html"))); - - QDeclarativeComponent component(&engine, TEST_FILE("send_data.3.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - component.completeCreate(); - - TRY_WAIT(object->property("dataOK").toBool() == true); - - delete object; - } - - // Correct content-type - out of order - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("send_data.4.expect"), - TEST_FILE("send_data.reply"), - TEST_FILE("testdocument.html"))); - - QDeclarativeComponent component(&engine, TEST_FILE("send_data.4.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - component.completeCreate(); - - TRY_WAIT(object->property("dataOK").toBool() == true); - - delete object; - } - - // Incorrect content-type - out of order - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("send_data.4.expect"), - TEST_FILE("send_data.reply"), - TEST_FILE("testdocument.html"))); - - QDeclarativeComponent component(&engine, TEST_FILE("send_data.5.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - component.completeCreate(); - - TRY_WAIT(object->property("dataOK").toBool() == true); - - delete object; - } - - // PUT - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("send_data.6.expect"), - TEST_FILE("send_data.reply"), - TEST_FILE("testdocument.html"))); - - QDeclarativeComponent component(&engine, TEST_FILE("send_data.6.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - component.completeCreate(); - - TRY_WAIT(object->property("dataOK").toBool() == true); - - delete object; - } + TestHTTPServer server(SERVER_PORT); + QVERIFY(server.isValid()); + QVERIFY(server.wait(TEST_FILE(file_expected), + TEST_FILE("send_data.reply"), + TEST_FILE("testdocument.html"))); - // Correct content-type - no charset - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("send_data.1.expect"), - TEST_FILE("send_data.reply"), - TEST_FILE("testdocument.html"))); + QDeclarativeComponent component(&engine, TEST_FILE(file_qml)); + QObject *object = component.beginCreate(engine.rootContext()); + QVERIFY(object != 0); + object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); + component.completeCreate(); - QDeclarativeComponent component(&engine, TEST_FILE("send_data.7.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - component.completeCreate(); + TRY_WAIT(object->property("dataOK").toBool() == true); - TRY_WAIT(object->property("dataOK").toBool() == true); + delete object; +} - delete object; - } +void tst_qdeclarativexmlhttprequest::send_withdata_data() +{ + QTest::addColumn("file_expected"); + QTest::addColumn("file_qml"); + + QTest::newRow("No content-type") << "send_data.1.expect" << "send_data.1.qml"; + QTest::newRow("Correct content-type") << "send_data.1.expect" << "send_data.2.qml"; + QTest::newRow("Incorrect content-type") << "send_data.1.expect" << "send_data.3.qml"; + QTest::newRow("Correct content-type - out of order") << "send_data.4.expect" << "send_data.4.qml"; + QTest::newRow("Incorrect content-type - out of order") << "send_data.4.expect" << "send_data.5.qml"; + QTest::newRow("PUT") << "send_data.6.expect" << "send_data.6.qml"; + QTest::newRow("Correct content-type - no charset") << "send_data.1.expect" << "send_data.7.qml"; } // Test abort() has no effect in unsent state @@ -940,200 +796,125 @@ void tst_qdeclarativexmlhttprequest::getAllResponseHeaders_args() void tst_qdeclarativexmlhttprequest::status() { - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("status.expect"), - TEST_FILE("status.200.reply"), - TEST_FILE("testdocument.html"))); - - QDeclarativeComponent component(&engine, TEST_FILE("status.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - object->setProperty("expectedStatus", 200); - component.completeCreate(); - - TRY_WAIT(object->property("dataOK").toBool() == true); + QFETCH(QUrl, replyUrl); + QFETCH(int, status); - QCOMPARE(object->property("unsentException").toBool(), true); - QCOMPARE(object->property("openedException").toBool(), true); - QCOMPARE(object->property("sentException").toBool(), true); - QCOMPARE(object->property("headersReceived").toBool(), true); - QCOMPARE(object->property("loading").toBool(), true); - QCOMPARE(object->property("done").toBool(), true); - QCOMPARE(object->property("resetException").toBool(), true); + TestHTTPServer server(SERVER_PORT); + QVERIFY(server.isValid()); + QVERIFY(server.wait(TEST_FILE("status.expect"), + replyUrl, + TEST_FILE("testdocument.html"))); - delete object; - } + QDeclarativeComponent component(&engine, TEST_FILE("status.qml")); + QObject *object = component.beginCreate(engine.rootContext()); + QVERIFY(object != 0); + object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); + object->setProperty("expectedStatus", status); + component.completeCreate(); - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("status.expect"), - TEST_FILE("status.404.reply"), - TEST_FILE("testdocument.html"))); + TRY_WAIT(object->property("dataOK").toBool() == true); - QDeclarativeComponent component(&engine, TEST_FILE("status.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - object->setProperty("expectedStatus", 404); - component.completeCreate(); + QCOMPARE(object->property("unsentException").toBool(), true); + QCOMPARE(object->property("openedException").toBool(), true); + QCOMPARE(object->property("sentException").toBool(), true); + QCOMPARE(object->property("headersReceived").toBool(), true); + QCOMPARE(object->property("loading").toBool(), true); + QCOMPARE(object->property("done").toBool(), true); + QCOMPARE(object->property("resetException").toBool(), true); - TRY_WAIT(object->property("dataOK").toBool() == true); + delete object; +} - QCOMPARE(object->property("unsentException").toBool(), true); - QCOMPARE(object->property("openedException").toBool(), true); - QCOMPARE(object->property("sentException").toBool(), true); - QCOMPARE(object->property("headersReceived").toBool(), true); - QCOMPARE(object->property("loading").toBool(), true); - QCOMPARE(object->property("done").toBool(), true); - QCOMPARE(object->property("resetException").toBool(), true); +void tst_qdeclarativexmlhttprequest::status_data() +{ + QTest::addColumn("replyUrl"); + QTest::addColumn("status"); - delete object; - } + QTest::newRow("OK") << TEST_FILE("status.200.reply") << 200; + QTest::newRow("Not Found") << TEST_FILE("status.404.reply") << 404; } void tst_qdeclarativexmlhttprequest::statusText() { - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("status.expect"), - TEST_FILE("status.200.reply"), - TEST_FILE("testdocument.html"))); - - QDeclarativeComponent component(&engine, TEST_FILE("statusText.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - object->setProperty("expectedStatus", "OK"); - component.completeCreate(); - - TRY_WAIT(object->property("dataOK").toBool() == true); + QFETCH(QUrl, replyUrl); + QFETCH(QString, statusText); - QCOMPARE(object->property("unsentException").toBool(), true); - QCOMPARE(object->property("openedException").toBool(), true); - QCOMPARE(object->property("sentException").toBool(), true); - QCOMPARE(object->property("headersReceived").toBool(), true); - QCOMPARE(object->property("loading").toBool(), true); - QCOMPARE(object->property("done").toBool(), true); - QCOMPARE(object->property("resetException").toBool(), true); + TestHTTPServer server(SERVER_PORT); + QVERIFY(server.isValid()); + QVERIFY(server.wait(TEST_FILE("status.expect"), + replyUrl, + TEST_FILE("testdocument.html"))); - delete object; - } + QDeclarativeComponent component(&engine, TEST_FILE("statusText.qml")); + QObject *object = component.beginCreate(engine.rootContext()); + QVERIFY(object != 0); + object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); + object->setProperty("expectedStatus", statusText); + component.completeCreate(); - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("status.expect"), - TEST_FILE("status.404.reply"), - TEST_FILE("testdocument.html"))); + TRY_WAIT(object->property("dataOK").toBool() == true); - QDeclarativeComponent component(&engine, TEST_FILE("statusText.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - object->setProperty("expectedStatus", "Document not found"); - component.completeCreate(); + QCOMPARE(object->property("unsentException").toBool(), true); + QCOMPARE(object->property("openedException").toBool(), true); + QCOMPARE(object->property("sentException").toBool(), true); + QCOMPARE(object->property("headersReceived").toBool(), true); + QCOMPARE(object->property("loading").toBool(), true); + QCOMPARE(object->property("done").toBool(), true); + QCOMPARE(object->property("resetException").toBool(), true); - TRY_WAIT(object->property("dataOK").toBool() == true); + delete object; +} - QCOMPARE(object->property("unsentException").toBool(), true); - QCOMPARE(object->property("openedException").toBool(), true); - QCOMPARE(object->property("sentException").toBool(), true); - QCOMPARE(object->property("headersReceived").toBool(), true); - QCOMPARE(object->property("loading").toBool(), true); - QCOMPARE(object->property("done").toBool(), true); - QCOMPARE(object->property("resetException").toBool(), true); +void tst_qdeclarativexmlhttprequest::statusText_data() +{ + QTest::addColumn("replyUrl"); + QTest::addColumn("statusText"); - delete object; - } + QTest::newRow("OK") << TEST_FILE("status.200.reply") << "OK"; + QTest::newRow("Not Found") << TEST_FILE("status.404.reply") << "Document not found"; } void tst_qdeclarativexmlhttprequest::responseText() { - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("status.expect"), - TEST_FILE("status.200.reply"), - TEST_FILE("testdocument.html"))); - - QDeclarativeComponent component(&engine, TEST_FILE("responseText.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - object->setProperty("expectedText", "QML Rocks!\n"); - component.completeCreate(); - - TRY_WAIT(object->property("dataOK").toBool() == true); - - QCOMPARE(object->property("unsent").toBool(), true); - QCOMPARE(object->property("opened").toBool(), true); - QCOMPARE(object->property("sent").toBool(), true); - QCOMPARE(object->property("headersReceived").toBool(), true); - QCOMPARE(object->property("loading").toBool(), true); - QCOMPARE(object->property("done").toBool(), true); - QCOMPARE(object->property("reset").toBool(), true); - - delete object; - } + QFETCH(QUrl, replyUrl); + QFETCH(QUrl, bodyUrl); + QFETCH(QString, responseText); - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("status.expect"), - TEST_FILE("status.200.reply"), - QUrl())); - - QDeclarativeComponent component(&engine, TEST_FILE("responseText.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - object->setProperty("expectedText", ""); - component.completeCreate(); - - TRY_WAIT(object->property("dataOK").toBool() == true); - - QCOMPARE(object->property("unsent").toBool(), true); - QCOMPARE(object->property("opened").toBool(), true); - QCOMPARE(object->property("sent").toBool(), true); - QCOMPARE(object->property("headersReceived").toBool(), true); - QCOMPARE(object->property("loading").toBool(), true); - QCOMPARE(object->property("done").toBool(), true); - QCOMPARE(object->property("reset").toBool(), true); + TestHTTPServer server(SERVER_PORT); + QVERIFY(server.isValid()); + QVERIFY(server.wait(TEST_FILE("status.expect"), + replyUrl, + bodyUrl)); - delete object; - } + QDeclarativeComponent component(&engine, TEST_FILE("responseText.qml")); + QObject *object = component.beginCreate(engine.rootContext()); + QVERIFY(object != 0); + object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); + object->setProperty("expectedText", responseText); + component.completeCreate(); - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("status.expect"), - TEST_FILE("status.404.reply"), - TEST_FILE("testdocument.html"))); + TRY_WAIT(object->property("dataOK").toBool() == true); - QDeclarativeComponent component(&engine, TEST_FILE("responseText.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - object->setProperty("expectedText", ""); - component.completeCreate(); + QCOMPARE(object->property("unsent").toBool(), true); + QCOMPARE(object->property("opened").toBool(), true); + QCOMPARE(object->property("sent").toBool(), true); + QCOMPARE(object->property("headersReceived").toBool(), true); + QCOMPARE(object->property("loading").toBool(), true); + QCOMPARE(object->property("done").toBool(), true); + QCOMPARE(object->property("reset").toBool(), true); - TRY_WAIT(object->property("dataOK").toBool() == true); + delete object; +} - QCOMPARE(object->property("unsent").toBool(), true); - QCOMPARE(object->property("opened").toBool(), true); - QCOMPARE(object->property("sent").toBool(), true); - QCOMPARE(object->property("headersReceived").toBool(), true); - QCOMPARE(object->property("loading").toBool(), true); - QCOMPARE(object->property("done").toBool(), true); - QCOMPARE(object->property("reset").toBool(), true); +void tst_qdeclarativexmlhttprequest::responseText_data() +{ + QTest::addColumn("replyUrl"); + QTest::addColumn("bodyUrl"); + QTest::addColumn("responseText"); - delete object; - } + QTest::newRow("OK") << TEST_FILE("status.200.reply") << TEST_FILE("testdocument.html") << "QML Rocks!\n"; + QTest::newRow("empty body") << TEST_FILE("status.200.reply") << QUrl() << ""; + QTest::newRow("Not Found") << TEST_FILE("status.404.reply") << TEST_FILE("testdocument.html") << ""; } // Test that calling hte XMLHttpRequest methods on a non-XMLHttpRequest object -- cgit v0.12 From a7b46bda37a428ae2e5554aa8e58469c92b310a9 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Fri, 5 Mar 2010 12:52:06 +1000 Subject: Fix test leaks --- tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp | 8 ++++++++ .../qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp index 3e69db9..5549a3e 100644 --- a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp +++ b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp @@ -242,6 +242,8 @@ void tst_QDeclarativeItem::keyNavigation() item = findItem(canvas->rootObject(), "item1"); QVERIFY(item); QVERIFY(item->hasFocus()); + + delete canvas; } void tst_QDeclarativeItem::smooth() @@ -265,6 +267,8 @@ void tst_QDeclarativeItem::smooth() QCOMPARE(spy.count(),2); item->setSmooth(false); QCOMPARE(spy.count(),2); + + delete item; } void tst_QDeclarativeItem::clip() @@ -288,6 +292,8 @@ void tst_QDeclarativeItem::clip() QCOMPARE(spy.count(),2); item->setClip(false); QCOMPARE(spy.count(),2); + + delete item; } void tst_QDeclarativeItem::mapCoordinates() @@ -335,6 +341,8 @@ void tst_QDeclarativeItem::mapCoordinates() QVERIFY(QMetaObject::invokeMethod(root, "checkMapAFromInvalid", Q_RETURN_ARG(QVariant, result), Q_ARG(QVariant, x), Q_ARG(QVariant, y))); QVERIFY(result.toBool()); + + delete canvas; } void tst_QDeclarativeItem::mapCoordinates_data() diff --git a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp index 9957b50..56e906e 100644 --- a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp +++ b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp @@ -99,6 +99,7 @@ void tst_QDeclarativeWorkerScript::source() QCOMPARE(item->source(), source); qApp->processEvents(); + delete item; } void tst_QDeclarativeWorkerScript::source_data() @@ -125,6 +126,7 @@ void tst_QDeclarativeWorkerScript::messaging() QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker).value(), value); qApp->processEvents(); + delete item; } void tst_QDeclarativeWorkerScript::messaging_data() @@ -161,6 +163,7 @@ void tst_QDeclarativeWorkerScript::messaging_sendQObjectList() QCOMPARE(result, (QVariantList() << QVariant() << QVariant() << QVariant())); qApp->processEvents(); + delete item; } void tst_QDeclarativeWorkerScript::messaging_sendJsObject() @@ -180,6 +183,7 @@ void tst_QDeclarativeWorkerScript::messaging_sendJsObject() QVERIFY(result.toBool()); qApp->processEvents(); + delete item; } QTEST_MAIN(tst_QDeclarativeWorkerScript) -- cgit v0.12 From e85b39067914276fb42ce1a8ae35c45d2f688dae Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Fri, 5 Mar 2010 13:03:13 +1000 Subject: Improve declarative tabs example. --- examples/declarative/tabwidget/TabWidget.qml | 44 +++++++++++++++---------- examples/declarative/tabwidget/tabs.qml | 49 +++++++++++++++++++--------- 2 files changed, 60 insertions(+), 33 deletions(-) diff --git a/examples/declarative/tabwidget/TabWidget.qml b/examples/declarative/tabwidget/TabWidget.qml index f0dfee8..f0f7164 100644 --- a/examples/declarative/tabwidget/TabWidget.qml +++ b/examples/declarative/tabwidget/TabWidget.qml @@ -1,42 +1,50 @@ import Qt 4.6 Item { - id: page + id: tabWidget property int current: 0 default property alias content: stack.children + onCurrentChanged: setOpacities() Component.onCompleted: setOpacities() + function setOpacities() { - for (var i=0; iRoses are red"; font.pixelSize: 24 - wrap: true; width: parent.width-20 } + anchors.fill: parent; color: "#e3e3e3" + Rectangle { + anchors { fill: parent; topMargin: 20; leftMargin: 20; rightMargin: 20; bottomMargin: 20 } + color: "#ff7f7f" + Text { + anchors.centerIn: parent; horizontalAlignment: Qt.AlignHCenter + text: "Roses are red"; font.pixelSize: 20 + wrap: true; width: parent.width - 20 + } + } } + Rectangle { property string title: "Green" - color: "green" - anchors.fill: parent - Text { anchors.centerIn: parent; text: "
Flower stems are green"; font.pixelSize: 24; - wrap: true; width: parent.width-20 } + anchors.fill: parent; color: "#e3e3e3" + Rectangle { + anchors { fill: parent; topMargin: 20; leftMargin: 20; rightMargin: 20; bottomMargin: 20 } + color: "#7fff7f" + Text { + anchors.centerIn: parent; horizontalAlignment: Qt.AlignHCenter + text: "Flower stems are green"; font.pixelSize: 20 + wrap: true; width: parent.width - 20 + } + } } + Rectangle { property string title: "Blue" - color: "blue" - anchors.fill: parent - Text { anchors.centerIn: parent; text: "
Violets are blue"; color: "white"; font.pixelSize: 24 - wrap: true; width: parent.width-20 } + anchors.fill: parent; color: "#e3e3e3" + Rectangle { + anchors { fill: parent; topMargin: 20; leftMargin: 20; rightMargin: 20; bottomMargin: 20 } + color: "#7f7fff" + Text { + anchors.centerIn: parent; horizontalAlignment: Qt.AlignHCenter + text: "Violets are blue"; font.pixelSize: 20 + wrap: true; width: parent.width - 20 + } + } } } -- cgit v0.12 From 52fc88c05ede03f15328a69989c4acef9bf7c65b Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Fri, 5 Mar 2010 13:07:37 +1000 Subject: More declarative examples cleanup. --- examples/declarative/dynamic/dynamic.qml | 42 +++++++++++++++++-------------- examples/declarative/tabwidget/tab.png | Bin 0 -> 507 bytes examples/declarative/velocity/Day.qml | 2 +- 3 files changed, 24 insertions(+), 20 deletions(-) create mode 100644 examples/declarative/tabwidget/tab.png diff --git a/examples/declarative/dynamic/dynamic.qml b/examples/declarative/dynamic/dynamic.qml index 2831b0c..6af3e81 100644 --- a/examples/declarative/dynamic/dynamic.qml +++ b/examples/declarative/dynamic/dynamic.qml @@ -17,15 +17,17 @@ Item { } // stars (when there's no sun) - Particles { id: stars - x: 0; y: 0; width: parent.width; height: parent.height/2 + Particles { + id: stars + x: 0; y: 0; width: parent.width; height: parent.height / 2 source: "images/star.png"; angleDeviation: 360; velocity: 0 velocityDeviation: 0; count: parent.width / 10; fadeInDuration: 2800 opacity: 1 } // ground, which has a z such that the sun can set behind it - Rectangle { id: ground + Rectangle { + id: ground z: 2 anchors { left: parent.left; top: parent.verticalCenter; right: toolbox.right; bottom: parent.bottom } gradient: Gradient { @@ -35,7 +37,8 @@ Item { } //Day state, for when you place a sun - states: State { name: "Day"; when: window.activeSuns > 0 + states: State { + name: "Day"; when: window.activeSuns > 0 PropertyChanges { target: stopA; color: "DeepSkyBlue"} PropertyChanges { target: stopB; color: "SkyBlue"} PropertyChanges { target: stars; opacity: 0 } @@ -56,56 +59,57 @@ Item { width: 480 anchors { right: parent.right; top:parent.top; bottom: parent.bottom } Rectangle { //Not a child of any positioner - color: "white"; border.color: "black"; + color: "white"; border.color: "black"; width: toolRow.width + 4 height: toolRow.height + 4 x: toolboxPositioner.x + toolRow.x - 2 y: toolboxPositioner.y + toolRow.y - 2 } - Column{ + Column { id: toolboxPositioner anchors.centerIn: parent spacing: 8 - Text{ text: "Drag an item into the scene." } - Row{ id: toolRow - spacing: 8; - PaletteItem{ + Text { text: "Drag an item into the scene." } + Row { + id: toolRow + spacing: 8; + PaletteItem { anchors.verticalCenter: parent.verticalCenter file: "Sun.qml"; image: "../images/sun.png" } - PaletteItem{ + PaletteItem { file: "GenericItem.qml" image: "../images/moon.png" } - PaletteItem{ + PaletteItem { anchors.verticalCenter: parent.verticalCenter file: "PerspectiveItem.qml" image: "../images/tree_s.png" } - PaletteItem{ + PaletteItem { anchors.verticalCenter: parent.verticalCenter file: "PerspectiveItem.qml" image: "../images/rabbit_brown.png" } - PaletteItem{ + PaletteItem { anchors.verticalCenter: parent.verticalCenter file: "PerspectiveItem.qml" image: "../images/rabbit_bw.png" } } - Text{ text: "Active Suns: " + activeSuns } + Text { text: "Active Suns: " + activeSuns } Rectangle { width: 440; height: 1; color: "black" } - Text{ text: "Arbitrary QML: " } + Text { text: "Arbitrary QML: " } TextEdit { id: qmlText width: 460 height: 220 readOnly: false focusOnPress: true - font.pixelSize: 16 - - text: "import Qt 4.6\nImage { id: smile;\n x: 500*Math.random();\n y: 200*Math.random(); \n source: 'images/face-smile.png';\n opacity: NumberAnimation{ \n to: 0; duration: 1500;\n }\n Component.onCompleted: smile.destroy(1500);\n}" + font.pixelSize: 14 + + text: "import Qt 4.6\nImage {\n id: smile;\n x: 500*Math.random();\n y: 200*Math.random(); \n source: 'images/face-smile.png';\n NumberAnimation on opacity { \n to: 0; duration: 1500;\n }\n Component.onCompleted: smile.destroy(1500);\n}" } Button { text: "Create" diff --git a/examples/declarative/tabwidget/tab.png b/examples/declarative/tabwidget/tab.png new file mode 100644 index 0000000..ad80216 Binary files /dev/null and b/examples/declarative/tabwidget/tab.png differ diff --git a/examples/declarative/velocity/Day.qml b/examples/declarative/velocity/Day.qml index 8a7364e..f4c24a5 100644 --- a/examples/declarative/velocity/Day.qml +++ b/examples/declarative/velocity/Day.qml @@ -52,7 +52,7 @@ Rectangle { id: mouse onClicked: { myText.focus = true } anchors.fill: parent - drag.target: stickyPage; drag.axis: "XandYAxis"; drag.minimumY: 0; drag.maximumY: 500 + drag.target: stickyPage; drag.axis: MouseArea.XandYAxis; drag.minimumY: 0; drag.maximumY: 500 drag.minimumX: 0; drag.maximumX: 400 } } -- cgit v0.12 From ae6f59d8dffc1a0569640e374dde01ed84f9c542 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 5 Mar 2010 13:23:04 +1000 Subject: Allow unquoted enum syntax for value types QTBUG-5424 --- src/declarative/qml/qdeclarativecompiler.cpp | 6 ++-- src/declarative/qml/qdeclarativeengine.cpp | 1 + src/declarative/qml/qdeclarativemetatype.cpp | 9 ++++-- src/declarative/qml/qdeclarativemetatype_p.h | 2 ++ src/declarative/qml/qdeclarativevaluetype.cpp | 34 ++++++++++++++++++++++ src/declarative/qml/qdeclarativevaluetype_p.h | 2 ++ .../qdeclarativelanguage/data/enumTypes.errors.txt | 1 + .../qdeclarativelanguage/data/enumTypes.qml | 4 +++ .../tst_qdeclarativelanguage.cpp | 1 + .../qdeclarativevaluetypes/data/enums.1.qml | 2 +- .../qdeclarativevaluetypes/data/enums.2.qml | 2 +- .../qdeclarativevaluetypes/data/enums.3.qml | 6 ++++ .../qdeclarativevaluetypes/data/enums.4.qml | 7 +++++ .../tst_qdeclarativevaluetypes.cpp | 20 +++++++++++-- 14 files changed, 89 insertions(+), 8 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/enumTypes.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/enumTypes.qml create mode 100644 tests/auto/declarative/qdeclarativevaluetypes/data/enums.3.qml create mode 100644 tests/auto/declarative/qdeclarativevaluetypes/data/enums.4.qml diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index 5a2f3b5..3c6c949 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -561,9 +561,11 @@ bool QDeclarativeCompiler::compile(QDeclarativeEngine *engine, QDeclarativeCompositeTypeData::TypeReference &tref = unit->types[ii]; QDeclarativeCompiledData::TypeReference ref; QDeclarativeScriptParser::TypeReference *parserRef = unit->data.referencedTypes().at(ii); - if (tref.type) + if (tref.type) { ref.type = tref.type; - else if (tref.unit) { + if (!ref.type->isCreatable()) + COMPILE_EXCEPTION(parserRef->refObjects.first(), QCoreApplication::translate("QDeclarativeCompiler", "Element is not creatable.")); + } else if (tref.unit) { ref.component = tref.unit->toComponent(engine); if (ref.component->isError()) { diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 7ce2d0b..1e60df4 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -167,6 +167,7 @@ QDeclarativeEnginePrivate::QDeclarativeEnginePrivate(QDeclarativeEngine *e) QDeclarativeItemModule::defineModule(); QDeclarativeUtilModule::defineModule(); QDeclarativeEnginePrivate::defineModule(); + QDeclarativeValueTypeFactory::registerValueTypes(); } globalClass = new QDeclarativeGlobalScriptClass(&scriptEngine); diff --git a/src/declarative/qml/qdeclarativemetatype.cpp b/src/declarative/qml/qdeclarativemetatype.cpp index abbb9d6..50ab56b 100644 --- a/src/declarative/qml/qdeclarativemetatype.cpp +++ b/src/declarative/qml/qdeclarativemetatype.cpp @@ -286,6 +286,11 @@ QDeclarativeCustomParser *QDeclarativeType::customParser() const return d->m_customParser; } +bool QDeclarativeType::isCreatable() const +{ + return d->m_newFunc != 0; +} + bool QDeclarativeType::isInterface() const { return d->m_isInterface; @@ -402,7 +407,7 @@ int QDeclarativePrivate::registerType(const QDeclarativePrivate::RegisterType &t data->types.append(dtype); data->idToType.insert(dtype->typeId(), dtype); - data->idToType.insert(dtype->qListTypeId(), dtype); + if (dtype->qListTypeId()) data->idToType.insert(dtype->qListTypeId(), dtype); if (!dtype->qmlTypeName().isEmpty()) data->nameToType.insertMulti(dtype->qmlTypeName(), dtype); @@ -414,7 +419,7 @@ int QDeclarativePrivate::registerType(const QDeclarativePrivate::RegisterType &t if (data->lists.size() <= type.listId) data->lists.resize(type.listId + 16); data->objects.setBit(type.typeId, true); - data->lists.setBit(type.listId, true); + if (type.listId) data->lists.setBit(type.listId, true); return index; } diff --git a/src/declarative/qml/qdeclarativemetatype_p.h b/src/declarative/qml/qdeclarativemetatype_p.h index ec5c045..cf8946d 100644 --- a/src/declarative/qml/qdeclarativemetatype_p.h +++ b/src/declarative/qml/qdeclarativemetatype_p.h @@ -114,6 +114,8 @@ public: QDeclarativeCustomParser *customParser() const; + bool isCreatable() const; + bool isInterface() const; int typeId() const; int qListTypeId() const; diff --git a/src/declarative/qml/qdeclarativevaluetype.cpp b/src/declarative/qml/qdeclarativevaluetype.cpp index 34d3795..c070123 100644 --- a/src/declarative/qml/qdeclarativevaluetype.cpp +++ b/src/declarative/qml/qdeclarativevaluetype.cpp @@ -41,6 +41,8 @@ #include "qdeclarativevaluetype_p.h" +#include "qdeclarativemetatype_p.h" + #include QT_BEGIN_NAMESPACE @@ -49,6 +51,32 @@ QT_BEGIN_NAMESPACE Q_DECLARE_METATYPE(QEasingCurve); #endif +template +int qmlRegisterValueTypeEnums(const char *qmlName) +{ + QByteArray name(T::staticMetaObject.className()); + + QByteArray pointerName(name + '*'); + + QDeclarativePrivate::RegisterType type = { + 0, + + qRegisterMetaType(pointerName.constData()), 0, 0, + + "Qt", 4, 6, qmlName, &T::staticMetaObject, + + 0, 0, + + 0, 0, 0, + + 0, 0, + + 0 + }; + + return QDeclarativePrivate::registerType(type); +} + QDeclarativeValueTypeFactory::QDeclarativeValueTypeFactory() { // ### Optimize @@ -80,6 +108,12 @@ bool QDeclarativeValueTypeFactory::isValueType(int idx) return false; } +void QDeclarativeValueTypeFactory::registerValueTypes() +{ + qmlRegisterValueTypeEnums("Easing"); + qmlRegisterValueTypeEnums("Font"); +} + QDeclarativeValueType *QDeclarativeValueTypeFactory::operator[](int idx) const { #if (QT_VERSION < QT_VERSION_CHECK(4,7,0)) diff --git a/src/declarative/qml/qdeclarativevaluetype_p.h b/src/declarative/qml/qdeclarativevaluetype_p.h index e69f161..ad2f6c4 100644 --- a/src/declarative/qml/qdeclarativevaluetype_p.h +++ b/src/declarative/qml/qdeclarativevaluetype_p.h @@ -84,6 +84,8 @@ public: static bool isValueType(int); static QDeclarativeValueType *valueType(int); + static void registerValueTypes(); + QDeclarativeValueType *operator[](int idx) const; private: diff --git a/tests/auto/declarative/qdeclarativelanguage/data/enumTypes.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/enumTypes.errors.txt new file mode 100644 index 0000000..d4e0cc0 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/enumTypes.errors.txt @@ -0,0 +1 @@ +3:1:Element is not creatable. diff --git a/tests/auto/declarative/qdeclarativelanguage/data/enumTypes.qml b/tests/auto/declarative/qdeclarativelanguage/data/enumTypes.qml new file mode 100644 index 0000000..a723269 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/enumTypes.qml @@ -0,0 +1,4 @@ +import Qt 4.6 + +Font { +} diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index 3ce15cb..da0bf1a 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -326,6 +326,7 @@ void tst_qdeclarativelanguage::errors_data() QTest::newRow("invalidRoot") << "invalidRoot.qml" << "invalidRoot.errors.txt" << false; QTest::newRow("missingValueTypeProperty") << "missingValueTypeProperty.qml" << "missingValueTypeProperty.errors.txt" << false; QTest::newRow("objectValueTypeProperty") << "objectValueTypeProperty.qml" << "objectValueTypeProperty.errors.txt" << false; + QTest::newRow("enumTypes") << "enumTypes.qml" << "enumTypes.errors.txt" << false; } diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/enums.1.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/enums.1.qml index 0eadd50..cb01a80 100644 --- a/tests/auto/declarative/qdeclarativevaluetypes/data/enums.1.qml +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/enums.1.qml @@ -1,6 +1,6 @@ import Test 1.0 MyTypeObject { - font.capitalization: "MixedCase" + font.capitalization: "AllUppercase" } diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/enums.2.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/enums.2.qml index 81f1c92..93f1ed5 100644 --- a/tests/auto/declarative/qdeclarativevaluetypes/data/enums.2.qml +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/enums.2.qml @@ -1,6 +1,6 @@ import Test 1.0 MyTypeObject { - font.capitalization: if (1) "MixedCase" + font.capitalization: if (1) "AllUppercase" } diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/enums.3.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/enums.3.qml new file mode 100644 index 0000000..3be5099 --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/enums.3.qml @@ -0,0 +1,6 @@ +import Test 1.0 +import Qt 4.6 + +MyTypeObject { + font.capitalization: Font.AllUppercase +} diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/enums.4.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/enums.4.qml new file mode 100644 index 0000000..6b494e4 --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/enums.4.qml @@ -0,0 +1,7 @@ +import Test 1.0 +import Qt 4.6 as MyQt + +MyTypeObject { + font.capitalization: MyQt.Font.AllUppercase +} + diff --git a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp index 8732215..51f9a07 100644 --- a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp +++ b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp @@ -597,7 +597,7 @@ void tst_qdeclarativevaluetypes::enums() QDeclarativeComponent component(&engine, TEST_FILE("enums.1.qml")); MyTypeObject *object = qobject_cast(component.create()); QVERIFY(object != 0); - QVERIFY(object->font().capitalization() == QFont::MixedCase); + QVERIFY(object->font().capitalization() == QFont::AllUppercase); delete object; } @@ -605,7 +605,23 @@ void tst_qdeclarativevaluetypes::enums() QDeclarativeComponent component(&engine, TEST_FILE("enums.2.qml")); MyTypeObject *object = qobject_cast(component.create()); QVERIFY(object != 0); - QVERIFY(object->font().capitalization() == QFont::MixedCase); + QVERIFY(object->font().capitalization() == QFont::AllUppercase); + delete object; + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("enums.3.qml")); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + QVERIFY(object->font().capitalization() == QFont::AllUppercase); + delete object; + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("enums.4.qml")); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + QVERIFY(object->font().capitalization() == QFont::AllUppercase); delete object; } } -- cgit v0.12 From 8fa8dcd33f5395060a84f6b7062c927aa675cde6 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 5 Mar 2010 13:31:12 +1000 Subject: Expect fail in currentIndex test for now. --- .../tst_qdeclarativelistview.cpp | 46 ++++++++++------------ 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp index a36224f..1df4448 100644 --- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp +++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp @@ -450,7 +450,7 @@ void tst_QDeclarativeListView::inserted() model.insertItem(1, "Will", "9876"); // let transitions settle. - QTest::qWait(500); + QTest::qWait(300); QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item @@ -470,7 +470,7 @@ void tst_QDeclarativeListView::inserted() model.insertItem(0, "Foo", "1111"); // zero index, and current item // let transitions settle. - QTest::qWait(500); + QTest::qWait(300); QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item @@ -491,14 +491,14 @@ void tst_QDeclarativeListView::inserted() for (int i = model.count(); i < 30; ++i) model.insertItem(i, "Hello", QString::number(i)); - QTest::qWait(500); + QTest::qWait(300); listview->setContentY(80); - QTest::qWait(500); + QTest::qWait(300); // Insert item outside visible area model.insertItem(1, "Hello", "1324"); - QTest::qWait(500); + QTest::qWait(300); QVERIFY(listview->contentY() == 80); @@ -543,7 +543,7 @@ void tst_QDeclarativeListView::removed(bool animated) model.removeItem(1); // let transitions settle. - QTest::qWait(500); + QTest::qWait(300); QDeclarativeText *name = findItem(viewport, "textName", 1); QVERIFY(name != 0); @@ -565,7 +565,7 @@ void tst_QDeclarativeListView::removed(bool animated) model.removeItem(0); // post: top item starts at 20 // let transitions settle. - QTest::qWait(500); + QTest::qWait(300); name = findItem(viewport, "textName", 0); QVERIFY(name != 0); @@ -586,7 +586,7 @@ void tst_QDeclarativeListView::removed(bool animated) // Remove items not visible model.removeItem(18); // let transitions settle. - QTest::qWait(500); + QTest::qWait(300); // Confirm items positioned correctly itemCount = findItems(viewport, "wrapper").count(); @@ -603,7 +603,7 @@ void tst_QDeclarativeListView::removed(bool animated) model.removeItem(1); // post: top item will be at 40 // let transitions settle. - QTest::qWait(500); + QTest::qWait(300); // Confirm items positioned correctly for (int i = 2; i < 18; ++i) { @@ -617,14 +617,14 @@ void tst_QDeclarativeListView::removed(bool animated) QVERIFY(listview->currentIndex() == 9); QDeclarativeItem *oldCurrent = listview->currentItem(); model.removeItem(9); - QTest::qWait(500); + QTest::qWait(300); QCOMPARE(listview->currentIndex(), 9); QVERIFY(listview->currentItem() != oldCurrent); listview->setContentY(40); // That's the top now // let transitions settle. - QTest::qWait(500); + QTest::qWait(300); // Confirm items positioned correctly itemCount = findItems(viewport, "wrapper").count(); @@ -637,20 +637,20 @@ void tst_QDeclarativeListView::removed(bool animated) // remove current item beyond visible items. listview->setCurrentIndex(20); - QTest::qWait(500); + QTest::qWait(300); listview->setContentY(40); model.removeItem(20); - QTest::qWait(500); + QTest::qWait(300); QCOMPARE(listview->currentIndex(), 20); QVERIFY(listview->currentItem() != 0); // remove item before current, but visible listview->setCurrentIndex(8); - QTest::qWait(500); + QTest::qWait(300); oldCurrent = listview->currentItem(); model.removeItem(6); - QTest::qWait(500); + QTest::qWait(300); QCOMPARE(listview->currentIndex(), 7); QVERIFY(listview->currentItem() == oldCurrent); @@ -1028,22 +1028,16 @@ void tst_QDeclarativeListView::currentIndex() QCOMPARE(listview->contentY(), 0.0); // Test keys + qApp->setActiveWindow(canvas); canvas->show(); + canvas->setFocus(); qApp->processEvents(); - QEvent wa(QEvent::WindowActivate); - QApplication::sendEvent(canvas, &wa); - QFocusEvent fe(QEvent::FocusIn); - QApplication::sendEvent(canvas, &fe); - - QKeyEvent key(QEvent::KeyPress, Qt::Key_Down, Qt::NoModifier, "", false, 1); - QApplication::sendEvent(canvas, &key); - QVERIFY(key.isAccepted()); + QTest::keyClick(canvas, Qt::Key_Down); + QEXPECT_FAIL("", "QTBUG-8475", Abort); QCOMPARE(listview->currentIndex(), 1); - key = QKeyEvent(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier, "", false, 1); - QApplication::sendEvent(canvas, &key); - QVERIFY(key.isAccepted()); + QTest::keyClick(canvas, Qt::Key_Up); QCOMPARE(listview->currentIndex(), 0); // turn off auto highlight -- cgit v0.12 From 330e85d06600d50972f8abfeec6086e7e8ad6bc1 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Fri, 5 Mar 2010 13:41:14 +1000 Subject: Use new enum syntax for value types. --- examples/declarative/fonts/fonts.qml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/declarative/fonts/fonts.qml b/examples/declarative/fonts/fonts.qml index 6246d16..e928df4 100644 --- a/examples/declarative/fonts/fonts.qml +++ b/examples/declarative/fonts/fonts.qml @@ -11,36 +11,36 @@ Rectangle { FontLoader { id: webFont; source: "http://www.princexml.com/fonts/steffmann/Starburst.ttf" } Column { - anchors.fill: parent; spacing: 10 + anchors.fill: parent; spacing: 15 anchors.leftMargin: 10; anchors.rightMargin: 10 Text { text: myText; color: "lightsteelblue" width: parent.width; elide: Text.ElideRight - font.family: "Times"; font.pointSize: 36 + font.family: "Times"; font.pointSize: 42 } Text { text: myText; color: "lightsteelblue" width: parent.width; elide: Text.ElideLeft - font.family: "Times"; font.pointSize: 36 - font.capitalization: "AllUppercase" + font.family: "Times"; font.pointSize: 42 + font.capitalization: Font.AllUppercase } Text { text: myText; color: "lightsteelblue" width: parent.width; elide: Text.ElideMiddle - font.family: fixedFont.name; font.pointSize: 36; font.weight: "Bold" - font.capitalization: "AllLowercase" + font.family: fixedFont.name; font.pointSize: 42; font.weight: Font.Bold + font.capitalization: Font.AllLowercase } Text { text: myText; color: "lightsteelblue" width: parent.width; elide: Text.ElideRight - font.family: fixedFont.name; font.pointSize: 36; font.italic: true - font.capitalization: "SmallCaps" + font.family: fixedFont.name; font.pointSize: 42; font.italic: true + font.capitalization: Font.SmallCaps } Text { text: myText; color: "lightsteelblue" width: parent.width; elide: Text.ElideLeft - font.family: localFont.name; font.pointSize: 36 - font.capitalization: "Capitalize" + font.family: localFont.name; font.pointSize: 42 + font.capitalization: Font.Capitalize } Text { text: { @@ -50,7 +50,7 @@ Rectangle { } color: "lightsteelblue" width: parent.width; elide: Text.ElideMiddle - font.family: webFont.name; font.pointSize: 36 + font.family: webFont.name; font.pointSize: 42 } } } -- cgit v0.12 From 3d84e74212d7cb43e822aa7f0188ef533d8bb4a2 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 5 Mar 2010 13:40:11 +1000 Subject: Fix compiler warning on RVCT Anonymous structures in unions cause warnings on this compiler. QTBUG-8738 --- src/declarative/qml/qdeclarativeinstruction_p.h | 321 +++++++++++++----------- 1 file changed, 173 insertions(+), 148 deletions(-) diff --git a/src/declarative/qml/qdeclarativeinstruction_p.h b/src/declarative/qml/qdeclarativeinstruction_p.h index c41b14f..ec32b35 100644 --- a/src/declarative/qml/qdeclarativeinstruction_p.h +++ b/src/declarative/qml/qdeclarativeinstruction_p.h @@ -161,155 +161,180 @@ public: Type type; unsigned short line; + + struct InitInstruction { + int bindingsSize; + int parserStatusSize; + int contextCache; + int compiledBinding; + }; + struct CreateInstruction { + int type; + int data; + int bindingBits; + ushort column; + }; + struct StoreMetaInstruction { + int data; + int aliasData; + int propertyCache; + }; + struct SetIdInstruction { + int value; + int index; + }; + struct AssignValueSourceInstruction { + int property; + int owner; + int castValue; + }; + struct AssignValueInterceptorInstruction { + int property; + int owner; + int castValue; + }; + struct AssignBindingInstruction { + unsigned int property; + int value; + short context; + short owner; + }; + struct FetchInstruction { + int property; + }; + struct FetchValueInstruction { + int property; + int type; + }; + struct FetchQmlListInstruction { + int property; + int type; + }; + struct BeginInstruction { + int castValue; + }; + struct StoreFloatInstruction { + int propertyIndex; + float value; + }; + struct StoreDoubleInstruction { + int propertyIndex; + double value; + }; + struct StoreIntegerInstruction { + int propertyIndex; + int value; + }; + struct StoreBoolInstruction { + int propertyIndex; + bool value; + }; + struct StoreStringInstruction { + int propertyIndex; + int value; + }; + struct StoreScriptStringInstruction { + int propertyIndex; + int value; + int scope; + }; + struct StoreScriptInstruction { + int value; + }; + struct StoreUrlInstruction { + int propertyIndex; + int value; + }; + struct StoreColorInstruction { + int propertyIndex; + unsigned int value; + }; + struct StoreDateInstruction { + int propertyIndex; + int value; + }; + struct StoreTimeInstruction { + int propertyIndex; + int valueIndex; + }; + struct StoreDateTimeInstruction { + int propertyIndex; + int valueIndex; + }; + struct StoreRealPairInstruction { + int propertyIndex; + int valueIndex; + }; + struct StoreRectInstruction { + int propertyIndex; + int valueIndex; + }; + struct StoreVector3DInstruction { + int propertyIndex; + int valueIndex; + }; + struct StoreObjectInstruction { + int propertyIndex; + }; + struct AssignCustomTypeInstruction { + int propertyIndex; + int valueIndex; + }; + struct StoreSignalInstruction { + int signalIndex; + int value; + int context; + }; + struct AssignSignalObjectInstruction { + int signal; + }; + struct CreateComponentInstruction { + int count; + ushort column; + int endLine; + int metaObject; + }; + struct FetchAttachedInstruction { + int id; + }; + struct DeferInstruction { + int deferCount; + }; + union { - struct { - int bindingsSize; - int parserStatusSize; - int contextCache; - int compiledBinding; - } init; - struct { - int type; - int data; - int bindingBits; - ushort column; - } create; - struct { - int data; - int aliasData; - int propertyCache; - } storeMeta; - struct { - int value; - int index; - } setId; - struct { - int property; - int owner; - int castValue; - } assignValueSource; - struct { - int property; - int owner; - int castValue; - } assignValueInterceptor; - struct { - unsigned int property; - int value; - short context; - short owner; - } assignBinding; - struct { - int property; - int id; - } assignIdOptBinding; - struct { - int property; - int contextIdx; - short context; - short notifyIdx; - } assignObjPropBinding; - struct { - int property; - } fetch; - struct { - int property; - int type; - } fetchValue; - struct { - int property; - int type; - } fetchQmlList; - struct { - int castValue; - } begin; - struct { - int propertyIndex; - float value; - } storeFloat; - struct { - int propertyIndex; - double value; - } storeDouble; - struct { - int propertyIndex; - int value; - } storeInteger; - struct { - int propertyIndex; - bool value; - } storeBool; - struct { - int propertyIndex; - int value; - } storeString; - struct { - int propertyIndex; - int value; - int scope; - } storeScriptString; - struct { - int value; - } storeScript; - struct { - int propertyIndex; - int value; - } storeUrl; - struct { - int propertyIndex; - unsigned int value; - } storeColor; - struct { - int propertyIndex; - int value; - } storeDate; - struct { - int propertyIndex; - int valueIndex; - } storeTime; - struct { - int propertyIndex; - int valueIndex; - } storeDateTime; - struct { - int propertyIndex; - int valueIndex; - } storeRealPair; - struct { - int propertyIndex; - int valueIndex; - } storeRect; - struct { - int propertyIndex; - int valueIndex; - } storeVector3D; - struct { - int propertyIndex; - } storeObject; - struct { - int propertyIndex; - int valueIndex; - } assignCustomType; - struct { - int signalIndex; - int value; - int context; - } storeSignal; - struct { - int signal; - } assignSignalObject; - struct { - int count; - ushort column; - int endLine; - int metaObject; - } createComponent; - struct { - int id; - } fetchAttached; - struct { - int deferCount; - } defer; + InitInstruction init; + CreateInstruction create; + StoreMetaInstruction storeMeta; + SetIdInstruction setId; + AssignValueSourceInstruction assignValueSource; + AssignValueInterceptorInstruction assignValueInterceptor; + AssignBindingInstruction assignBinding; + FetchInstruction fetch; + FetchValueInstruction fetchValue; + FetchQmlListInstruction fetchQmlList; + BeginInstruction begin; + StoreFloatInstruction storeFloat; + StoreDoubleInstruction storeDouble; + StoreIntegerInstruction storeInteger; + StoreBoolInstruction storeBool; + StoreStringInstruction storeString; + StoreScriptStringInstruction storeScriptString; + StoreScriptInstruction storeScript; + StoreUrlInstruction storeUrl; + StoreColorInstruction storeColor; + StoreDateInstruction storeDate; + StoreTimeInstruction storeTime; + StoreDateTimeInstruction storeDateTime; + StoreRealPairInstruction storeRealPair; + StoreRectInstruction storeRect; + StoreVector3DInstruction storeVector3D; + StoreObjectInstruction storeObject; + AssignCustomTypeInstruction assignCustomType; + StoreSignalInstruction storeSignal; + AssignSignalObjectInstruction assignSignalObject; + CreateComponentInstruction createComponent; + FetchAttachedInstruction fetchAttached; + DeferInstruction defer; }; void dump(QDeclarativeCompiledData *); -- cgit v0.12 From b771a3a1238bd843c962a3a2a7cb04e2dfaeadbf Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Fri, 5 Mar 2010 13:41:55 +1000 Subject: Delete uninspiring example. --- examples/declarative/anchors/anchor-changes.qml | 46 ------------------------- 1 file changed, 46 deletions(-) delete mode 100644 examples/declarative/anchors/anchor-changes.qml diff --git a/examples/declarative/anchors/anchor-changes.qml b/examples/declarative/anchors/anchor-changes.qml deleted file mode 100644 index 99ca3db..0000000 --- a/examples/declarative/anchors/anchor-changes.qml +++ /dev/null @@ -1,46 +0,0 @@ -import Qt 4.6 - -Item { - id: window - width: 200; height: 450 - - Rectangle { - id: titleBar; color: "Gray" - anchors.top: parent.top; height: 50 - width: parent.width - } - - Rectangle { - id: statusBar; color: "Gray" - height: 50; anchors.bottom: parent.bottom - width: parent.width - } - - Rectangle { - id: content - anchors.top: titleBar.bottom; anchors.bottom: statusBar.top - width: parent.width - - Text { text: "Top"; anchors.top: parent.top } - Text { text: "Bottom"; anchors.bottom: parent.bottom } - } - - MouseArea { - anchors.fill: content - onPressed: window.state = "FullScreen" - onReleased: window.state = "" - } - - states : State { - name: "FullScreen" - //! [0] - AnchorChanges { - target: content; top: window.top; bottom: window.bottom - } - //! [0] - } - - transitions : Transition { - NumberAnimation { properties: "y,height" } - } -} -- cgit v0.12 From 09e39c9c86e8ed346aff348b28c512710862e70e Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 5 Mar 2010 13:43:08 +1000 Subject: Add basic support for explicit newParent in ParentAnimation. --- src/declarative/util/qdeclarativeanimation.cpp | 62 +++++++++++++++++++++++--- src/declarative/util/qdeclarativeanimation_p.h | 2 +- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index 49177d1..8c8dd95 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -2461,6 +2461,9 @@ QDeclarativeParentAnimation::~QDeclarativeParentAnimation() /*! \qmlproperty item ParentAnimation::target The item to reparent. + + When used in a transition, if no target is specified all + ParentChanges will be animated by the ParentAnimation. */ QDeclarativeItem *QDeclarativeParentAnimation::target() const { @@ -2474,6 +2477,12 @@ void QDeclarativeParentAnimation::setTarget(QDeclarativeItem *target) d->target = target; } +/*! + \qmlproperty item ParentAnimation::newParent + The new parent to animate to. + + If not set, then the parent defined in the end state of the transition. +*/ QDeclarativeItem *QDeclarativeParentAnimation::newParent() const { Q_D(const QDeclarativeParentAnimation); @@ -2545,12 +2554,13 @@ void QDeclarativeParentAnimation::transition(QDeclarativeStateActions &actions, struct QDeclarativeParentActionData : public QAbstractAnimationAction { - QDeclarativeParentActionData(): pc(0) {} - ~QDeclarativeParentActionData() { delete pc; } + QDeclarativeParentActionData() {} + ~QDeclarativeParentActionData() { qDeleteAll(pc); } QDeclarativeStateActions actions; + //### reverse should probably apply on a per-action basis bool reverse; - QDeclarativeParentChange *pc; + QList pc; virtual void doAction() { for (int ii = 0; ii < actions.count(); ++ii) { @@ -2565,6 +2575,33 @@ void QDeclarativeParentAnimation::transition(QDeclarativeStateActions &actions, QDeclarativeParentActionData *data = new QDeclarativeParentActionData; QDeclarativeParentActionData *viaData = new QDeclarativeParentActionData; + + bool hasExplicit = false; + if (d->target && d->newParent) { + data->reverse = false; + QDeclarativeAction myAction; + QDeclarativeParentChange *pc = new QDeclarativeParentChange; + pc->setObject(d->target); + pc->setParent(d->newParent); + myAction.event = pc; + data->pc << pc; + data->actions << myAction; + hasExplicit = true; + if (d->via) { + viaData->reverse = false; + QDeclarativeAction myVAction; + QDeclarativeParentChange *vpc = new QDeclarativeParentChange; + vpc->setObject(d->target); + vpc->setParent(d->via); + myVAction.event = vpc; + viaData->pc << vpc; + viaData->actions << myVAction; + } + //### once actions have concept of modified, + // loop to match appropriate ParentChanges and mark as modified + } + + if (!hasExplicit) for (int i = 0; i < actions.size(); ++i) { QDeclarativeAction &action = actions[i]; if (action.event && action.event->typeName() == QLatin1String("ParentChange") @@ -2573,8 +2610,21 @@ void QDeclarativeParentAnimation::transition(QDeclarativeStateActions &actions, QDeclarativeParentChange *pc = static_cast(action.event); QDeclarativeAction myAction = action; data->reverse = action.reverseEvent; - action.actionDone = true; - data->actions << myAction; + + //### this logic differs from PropertyAnimation + // (probably a result of modified vs. done) + if (d->newParent) { + QDeclarativeParentChange *epc = new QDeclarativeParentChange; + epc->setObject(static_cast(action.event)->object()); + epc->setParent(d->newParent); + myAction.event = epc; + data->pc << epc; + data->actions << myAction; + pc = epc; + } else { + action.actionDone = true; + data->actions << myAction; + } if (d->via) { viaData->reverse = false; @@ -2583,7 +2633,7 @@ void QDeclarativeParentAnimation::transition(QDeclarativeStateActions &actions, vpc->setObject(pc->object()); vpc->setParent(d->via); myAction.event = vpc; - viaData->pc = vpc; + viaData->pc << vpc; viaData->actions << myAction; QDeclarativeAction dummyAction; QDeclarativeAction &xAction = pc->xIsSet() ? actions[++i] : dummyAction; diff --git a/src/declarative/util/qdeclarativeanimation_p.h b/src/declarative/util/qdeclarativeanimation_p.h index 0f23f5c..af48309 100644 --- a/src/declarative/util/qdeclarativeanimation_p.h +++ b/src/declarative/util/qdeclarativeanimation_p.h @@ -457,7 +457,7 @@ class QDeclarativeParentAnimation : public QDeclarativeAnimationGroup Q_DECLARE_PRIVATE(QDeclarativeParentAnimation) Q_PROPERTY(QDeclarativeItem *target READ target WRITE setTarget) - //Q_PROPERTY(QDeclarativeItem *newParent READ newParent WRITE setNewParent) + Q_PROPERTY(QDeclarativeItem *newParent READ newParent WRITE setNewParent) Q_PROPERTY(QDeclarativeItem *via READ via WRITE setVia) public: -- cgit v0.12 From 769a11719ca85e9cdac4c0f1d0fcffe6145d6972 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Fri, 5 Mar 2010 16:08:26 +1000 Subject: Don't assume documents are in UTF-8. Task-number: QTBUG-7719 --- src/declarative/qml/qdeclarativexmlhttprequest.cpp | 19 +++++++++++--- .../qdeclarativexmlhttprequest/data/utf16.qml | 28 +++++++++++++++++++++ .../qdeclarativexmlhttprequest/data/utf16.xml | Bin 0 -> 154 bytes .../tst_qdeclarativexmlhttprequest.cpp | 25 ++++++++++++++++++ 4 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.qml create mode 100644 tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.xml diff --git a/src/declarative/qml/qdeclarativexmlhttprequest.cpp b/src/declarative/qml/qdeclarativexmlhttprequest.cpp index 3ba53f0..87cab85 100644 --- a/src/declarative/qml/qdeclarativexmlhttprequest.cpp +++ b/src/declarative/qml/qdeclarativexmlhttprequest.cpp @@ -52,6 +52,7 @@ #include #include #include +#include #include #include #include @@ -312,7 +313,7 @@ public: // C++ API static QScriptValue prototype(QScriptEngine *); - static QScriptValue load(QScriptEngine *engine, const QString &data); + static QScriptValue load(QScriptEngine *engine, const QByteArray &data); }; QT_END_NAMESPACE @@ -619,7 +620,7 @@ QScriptValue Document::prototype(QScriptEngine *engine) return proto; } -QScriptValue Document::load(QScriptEngine *engine, const QString &data) +QScriptValue Document::load(QScriptEngine *engine, const QByteArray &data) { Q_ASSERT(engine); @@ -960,6 +961,7 @@ public: QScriptValue abort(QScriptValue *me); QString responseBody() const; + const QByteArray & rawResponseBody() const; private slots: void downloadProgress(qint64); void error(QNetworkReply::NetworkError); @@ -1279,9 +1281,20 @@ void QDeclarativeXMLHttpRequest::finished() QString QDeclarativeXMLHttpRequest::responseBody() const { + QXmlStreamReader reader(m_responseEntityBody); + reader.readNext(); + QTextCodec *codec = QTextCodec::codecForName(reader.documentEncoding().toString().toUtf8()); + if (codec) + return codec->toUnicode(m_responseEntityBody); + return QString::fromUtf8(m_responseEntityBody); } +const QByteArray &QDeclarativeXMLHttpRequest::rawResponseBody() const +{ + return m_responseEntityBody; +} + QScriptValue QDeclarativeXMLHttpRequest::dispatchCallback(QScriptValue *me) { QScriptValue v = me->property(QLatin1String("callback")); @@ -1538,7 +1551,7 @@ static QScriptValue qmlxmlhttprequest_responseXML(QScriptContext *context, QScri request->readyState() != QDeclarativeXMLHttpRequest::Done) return engine->nullValue(); else - return Document::load(engine, request->responseBody()); + return Document::load(engine, request->rawResponseBody()); } static QScriptValue qmlxmlhttprequest_onreadystatechange(QScriptContext *context, QScriptEngine *engine) diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.qml b/tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.qml new file mode 100644 index 0000000..63165ab --- /dev/null +++ b/tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.qml @@ -0,0 +1,28 @@ +import Qt 4.6 + +QtObject { + property bool dataOK: false + + property string responseText + property string responseXmlRootNodeValue + + Component.onCompleted: { + var x = new XMLHttpRequest; + + x.open("GET", "utf16.xml"); + + // Test to the end + x.onreadystatechange = function() { + if (x.readyState == XMLHttpRequest.DONE) { + + responseText = x.responseText + if (x.responseXML) + responseXmlRootNodeValue = x.responseXML.documentElement.childNodes[0].nodeValue + + dataOK = true; + } + } + x.send() + } +} + diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.xml b/tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.xml new file mode 100644 index 0000000..0fbb126 Binary files /dev/null and b/tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.xml differ diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp b/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp index 01f07ab..13ed959 100644 --- a/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp +++ b/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp @@ -104,6 +104,7 @@ private slots: void responseXML_invalid(); void invalidMethodUsage(); void redirects(); + void nonUtf8(); // Attributes void document(); @@ -917,6 +918,30 @@ void tst_qdeclarativexmlhttprequest::responseText_data() QTest::newRow("Not Found") << TEST_FILE("status.404.reply") << TEST_FILE("testdocument.html") << ""; } +void tst_qdeclarativexmlhttprequest::nonUtf8() +{ + QDeclarativeComponent component(&engine, TEST_FILE("utf16.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QString uc; + uc.resize(3); + uc[0] = QChar(0x10e3); + uc[1] = QChar(' '); + uc[2] = QChar(0x03a3); + QString xml = "\n\n" + uc + "\n\n"; + + TRY_WAIT(object->property("dataOK").toBool() == true); + + QString responseText = object->property("responseText").toString(); + QCOMPARE(responseText, xml); + + QString responseXmlText = object->property("responseXmlRootNodeValue").toString(); + QCOMPARE(responseXmlText, '\n' + uc + '\n'); + + delete object; +} + // Test that calling hte XMLHttpRequest methods on a non-XMLHttpRequest object // throws an exception void tst_qdeclarativexmlhttprequest::invalidMethodUsage() -- cgit v0.12 From b075f407c724cbe4b96b9936c8cf91b88c526619 Mon Sep 17 00:00:00 2001 From: Justin McPherson Date: Fri, 5 Mar 2010 16:23:23 +1000 Subject: Fix qdeclarative{audio,video} tests. Location of declarative modules moved. --- tests/auto/qdeclarativeaudio/qdeclarativeaudio.pro | 12 ++++++------ tests/auto/qdeclarativeaudio/tst_qdeclarativeaudio.cpp | 2 +- tests/auto/qdeclarativevideo/qdeclarativevideo.pro | 12 ++++++------ tests/auto/qdeclarativevideo/tst_qdeclarativevideo.cpp | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/auto/qdeclarativeaudio/qdeclarativeaudio.pro b/tests/auto/qdeclarativeaudio/qdeclarativeaudio.pro index bfc2223..7779efc 100644 --- a/tests/auto/qdeclarativeaudio/qdeclarativeaudio.pro +++ b/tests/auto/qdeclarativeaudio/qdeclarativeaudio.pro @@ -1,14 +1,14 @@ load(qttest_p4) HEADERS += \ - $$PWD/../../../src/plugins/qdeclarativemodules/multimedia/qdeclarativeaudio_p.h \ - $$PWD/../../../src/plugins/qdeclarativemodules/multimedia/qdeclarativemediabase_p.h \ - $$PWD/../../../src/plugins/qdeclarativemodules/multimedia/qmetadatacontrolmetaobject_p.h + $$PWD/../../../src/imports/multimedia/qdeclarativeaudio_p.h \ + $$PWD/../../../src/imports/multimedia/qdeclarativemediabase_p.h \ + $$PWD/../../../src/imports/multimedia/qmetadatacontrolmetaobject_p.h SOURCES += \ tst_qdeclarativeaudio.cpp \ - $$PWD/../../../src/plugins/qdeclarativemodules/multimedia/qdeclarativeaudio.cpp \ - $$PWD/../../../src/plugins/qdeclarativemodules/multimedia/qdeclarativemediabase.cpp \ - $$PWD/../../../src/plugins/qdeclarativemodules/multimedia/qmetadatacontrolmetaobject.cpp + $$PWD/../../../src/imports/multimedia/qdeclarativeaudio.cpp \ + $$PWD/../../../src/imports/multimedia/qdeclarativemediabase.cpp \ + $$PWD/../../../src/imports/multimedia/qmetadatacontrolmetaobject.cpp QT += multimedia declarative diff --git a/tests/auto/qdeclarativeaudio/tst_qdeclarativeaudio.cpp b/tests/auto/qdeclarativeaudio/tst_qdeclarativeaudio.cpp index 55c7135..d750c69 100644 --- a/tests/auto/qdeclarativeaudio/tst_qdeclarativeaudio.cpp +++ b/tests/auto/qdeclarativeaudio/tst_qdeclarativeaudio.cpp @@ -41,7 +41,7 @@ #include -#include "../../../src/plugins/qdeclarativemodules/multimedia/qdeclarativeaudio_p.h" +#include "../../../src/imports/multimedia/qdeclarativeaudio_p.h" #include #include diff --git a/tests/auto/qdeclarativevideo/qdeclarativevideo.pro b/tests/auto/qdeclarativevideo/qdeclarativevideo.pro index 497ee0e..4cd4c71 100644 --- a/tests/auto/qdeclarativevideo/qdeclarativevideo.pro +++ b/tests/auto/qdeclarativevideo/qdeclarativevideo.pro @@ -1,14 +1,14 @@ load(qttest_p4) HEADERS += \ - $$PWD/../../../src/plugins/qdeclarativemodules/multimedia/qdeclarativevideo_p.h \ - $$PWD/../../../src/plugins/qdeclarativemodules/multimedia/qdeclarativemediabase_p.h \ - $$PWD/../../../src/plugins/qdeclarativemodules/multimedia/qmetadatacontrolmetaobject_p.h + $$PWD/../../../src/imports/multimedia/qdeclarativevideo_p.h \ + $$PWD/../../../src/imports/multimedia/qdeclarativemediabase_p.h \ + $$PWD/../../../src/imports/multimedia/qmetadatacontrolmetaobject_p.h SOURCES += \ tst_qdeclarativevideo.cpp \ - $$PWD/../../../src/plugins/qdeclarativemodules/multimedia/qdeclarativevideo.cpp \ - $$PWD/../../../src/plugins/qdeclarativemodules/multimedia/qdeclarativemediabase.cpp \ - $$PWD/../../../src/plugins/qdeclarativemodules/multimedia/qmetadatacontrolmetaobject.cpp + $$PWD/../../../src/imports/multimedia/qdeclarativevideo.cpp \ + $$PWD/../../../src/imports/multimedia/qdeclarativemediabase.cpp \ + $$PWD/../../../src/imports/multimedia/qmetadatacontrolmetaobject.cpp QT += multimedia declarative diff --git a/tests/auto/qdeclarativevideo/tst_qdeclarativevideo.cpp b/tests/auto/qdeclarativevideo/tst_qdeclarativevideo.cpp index d3bfc38..5fd3675 100644 --- a/tests/auto/qdeclarativevideo/tst_qdeclarativevideo.cpp +++ b/tests/auto/qdeclarativevideo/tst_qdeclarativevideo.cpp @@ -41,7 +41,7 @@ #include -#include "../../../src/plugins/qdeclarativemodules/multimedia/qdeclarativevideo_p.h" +#include "../../../src/imports/multimedia/qdeclarativevideo_p.h" #include #include -- cgit v0.12 From 4a6154ec912d5b84a556aa731c5b7de8f758ba3d Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 5 Mar 2010 16:26:40 +1000 Subject: Minor perf improvement when running QML script blocks There is no need to capture a property access if a binding is not being evaluated. --- src/declarative/qml/qdeclarativecontextscriptclass.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/declarative/qml/qdeclarativecontextscriptclass.cpp b/src/declarative/qml/qdeclarativecontextscriptclass.cpp index d6305d8..5fcf4e2 100644 --- a/src/declarative/qml/qdeclarativecontextscriptclass.cpp +++ b/src/declarative/qml/qdeclarativecontextscriptclass.cpp @@ -262,8 +262,9 @@ QDeclarativeContextScriptClass::property(Object *object, const Identifier &name) } } - ep->capturedProperties << - QDeclarativeEnginePrivate::CapturedProperty(bindContext, -1, lastPropertyIndex + cp->notifyIndex); + if (ep->captureProperties) + ep->capturedProperties << QDeclarativeEnginePrivate::CapturedProperty(bindContext, -1, lastPropertyIndex + cp->notifyIndex); + return Value(scriptEngine, rv); } else if(lastDefaultObject != -1) { -- cgit v0.12 From dcd17fa7b77cb6adfb8b21ea90c113915cab9bd5 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 5 Mar 2010 18:04:37 +1000 Subject: Add support for QtScript connect/disconnect syntax in QML This support was accidentally removed as a consequence of 4a665ff5da05860f5eb46e3982ef3d8163a6cf59. QTBUG-8001 --- .../qml/qdeclarativeobjectscriptclass.cpp | 81 +++++++++++ .../qml/qdeclarativeobjectscriptclass_p.h | 12 ++ .../data/scriptConnect.1.qml | 16 ++ .../data/scriptConnect.2.qml | 22 +++ .../data/scriptConnect.3.qml | 15 ++ .../data/scriptConnect.4.qml | 12 ++ .../data/scriptConnect.5.qml | 11 ++ .../data/scriptConnect.6.qml | 20 +++ .../data/scriptDisconnect.1.qml | 18 +++ .../data/scriptDisconnect.2.qml | 19 +++ .../data/scriptDisconnect.3.qml | 19 +++ .../data/scriptDisconnect.4.qml | 20 +++ .../tst_qdeclarativeecmascript.cpp | 162 +++++++++++++++++++++ 13 files changed, 427 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.1.qml create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.2.qml create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.3.qml create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.4.qml create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.5.qml create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.6.qml create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.1.qml create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.2.qml create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.3.qml create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.4.qml diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp index 2e4ffa7..e6f6e5f 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp @@ -442,6 +442,13 @@ QDeclarativeObjectMethodScriptClass::QDeclarativeObjectMethodScriptClass(QDeclar engine(bindEngine) { setSupportsCall(true); + + QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine); + + m_connect = scriptEngine->newFunction(connect); + m_connectId = createPersistentIdentifier(QLatin1String("connect")); + m_disconnect = scriptEngine->newFunction(disconnect); + m_disconnectId = createPersistentIdentifier(QLatin1String("disconnect")); } QDeclarativeObjectMethodScriptClass::~QDeclarativeObjectMethodScriptClass() @@ -455,6 +462,80 @@ QScriptValue QDeclarativeObjectMethodScriptClass::newMethod(QObject *object, con return newObject(scriptEngine, this, new MethodData(object, *method)); } +QScriptValue QDeclarativeObjectMethodScriptClass::connect(QScriptContext *context, QScriptEngine *engine) +{ + QDeclarativeEnginePrivate *p = QDeclarativeEnginePrivate::get(engine); + + QScriptValue that = context->thisObject(); + if (&p->objectClass->methods != scriptClass(that)) + return engine->undefinedValue(); + + MethodData *data = (MethodData *)object(that); + + if (!data->object || context->argumentCount() == 0) + return engine->undefinedValue(); + + QByteArray signal("2"); + signal.append(data->object->metaObject()->method(data->data.coreIndex).signature()); + + if (context->argumentCount() == 1) { + qScriptConnect(data->object, signal.constData(), QScriptValue(), context->argument(0)); + } else { + qScriptConnect(data->object, signal.constData(), context->argument(0), context->argument(1)); + } + + return engine->undefinedValue(); +} + +QScriptValue QDeclarativeObjectMethodScriptClass::disconnect(QScriptContext *context, QScriptEngine *engine) +{ + QDeclarativeEnginePrivate *p = QDeclarativeEnginePrivate::get(engine); + + QScriptValue that = context->thisObject(); + if (&p->objectClass->methods != scriptClass(that)) + return engine->undefinedValue(); + + MethodData *data = (MethodData *)object(that); + + if (!data->object || context->argumentCount() == 0) + return engine->undefinedValue(); + + QByteArray signal("2"); + signal.append(data->object->metaObject()->method(data->data.coreIndex).signature()); + + if (context->argumentCount() == 1) { + qScriptDisconnect(data->object, signal.constData(), QScriptValue(), context->argument(0)); + } else { + qScriptDisconnect(data->object, signal.constData(), context->argument(0), context->argument(1)); + } + + return engine->undefinedValue(); +} + +QScriptClass::QueryFlags +QDeclarativeObjectMethodScriptClass::queryProperty(Object *, const Identifier &name, + QScriptClass::QueryFlags flags) +{ + if (name == m_connectId.identifier || name == m_disconnectId.identifier) + return QScriptClass::HandlesReadAccess; + else + return 0; + +} + +QDeclarativeObjectScriptClass::ScriptValue +QDeclarativeObjectMethodScriptClass::property(Object *, const Identifier &name) +{ + QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine); + + if (name == m_connectId.identifier) + return Value(scriptEngine, m_connect); + else if (name == m_disconnectId.identifier) + return Value(scriptEngine, m_disconnect); + else + return Value(); +} + namespace { struct MetaCallArgument { inline MetaCallArgument(); diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass_p.h b/src/declarative/qml/qdeclarativeobjectscriptclass_p.h index 8023756..04e760f 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass_p.h +++ b/src/declarative/qml/qdeclarativeobjectscriptclass_p.h @@ -73,10 +73,21 @@ public: ~QDeclarativeObjectMethodScriptClass(); QScriptValue newMethod(QObject *, const QDeclarativePropertyCache::Data *); + protected: virtual Value call(Object *, QScriptContext *); + virtual QScriptClass::QueryFlags queryProperty(Object *, const Identifier &, QScriptClass::QueryFlags flags); + virtual Value property(Object *, const Identifier &); private: + PersistentIdentifier m_connectId; + PersistentIdentifier m_disconnectId; + QScriptValue m_connect; + QScriptValue m_disconnect; + + static QScriptValue connect(QScriptContext *context, QScriptEngine *engine); + static QScriptValue disconnect(QScriptContext *context, QScriptEngine *engine); + QDeclarativeEngine *engine; }; #endif @@ -119,6 +130,7 @@ protected: private: #if (QT_VERSION > QT_VERSION_CHECK(4, 6, 2)) || defined(QT_HAVE_QSCRIPTDECLARATIVECLASS_VALUE) + friend class QDeclarativeObjectMethodScriptClass; QDeclarativeObjectMethodScriptClass methods; #endif diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.1.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.1.qml new file mode 100644 index 0000000..2bdd706 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.1.qml @@ -0,0 +1,16 @@ +import Qt.test 1.0 +import Qt 4.6 + +MyQmlObject { + property bool test: false + + id: root + + Script { + function testFunction() { + test = true; + } + } + + Component.onCompleted: root.argumentSignal.connect(testFunction); +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.2.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.2.qml new file mode 100644 index 0000000..fa90918 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.2.qml @@ -0,0 +1,22 @@ +import Qt.test 1.0 +import Qt 4.6 + +MyQmlObject { + property bool test: false + + id: root + + Script { + function testFunction() { + if (this.b == 12) + test = true; + } + } + + Component.onCompleted: { + var a = new Object; + a.b = 12; + root.argumentSignal.connect(a, testFunction); + } +} + diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.3.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.3.qml new file mode 100644 index 0000000..0d8e6ef --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.3.qml @@ -0,0 +1,15 @@ +import Qt.test 1.0 +import Qt 4.6 + +MyQmlObject { + property bool test: false + + id: root + + function testFunction() { + test = true; + } + + Component.onCompleted: root.argumentSignal.connect(testFunction); +} + diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.4.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.4.qml new file mode 100644 index 0000000..3e1ff1b --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.4.qml @@ -0,0 +1,12 @@ +import Qt.test 1.0 +import Qt 4.6 + +MyQmlObject { + property bool test: false + + id: root + + Component.onCompleted: root.argumentSignal.connect(methodNoArgs); +} + + diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.5.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.5.qml new file mode 100644 index 0000000..3ad5cbc --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.5.qml @@ -0,0 +1,11 @@ +import Qt.test 1.0 +import Qt 4.6 + +MyQmlObject { + property bool test: false + + id: root + + Component.onCompleted: root.argumentSignal.connect(root, methodNoArgs); +} + diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.6.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.6.qml new file mode 100644 index 0000000..8c35db1 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.6.qml @@ -0,0 +1,20 @@ +import Qt.test 1.0 +import Qt 4.6 + +MyQmlObject { + property int test: 0 + + id: root + + Script { + function testFunction() { + test++; + } + } + + Component.onCompleted: { + root.argumentSignal.connect(testFunction); + root.argumentSignal.connect(testFunction); + } +} + diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.1.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.1.qml new file mode 100644 index 0000000..45c4f73 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.1.qml @@ -0,0 +1,18 @@ +import Qt.test 1.0 +import Qt 4.6 + +MyQmlObject { + property int test: 0 + + id: root + + Script { + function testFunction() { + test++; + } + } + + Component.onCompleted: root.argumentSignal.connect(testFunction); + + onBasicSignal: root.argumentSignal.disconnect(testFunction); +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.2.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.2.qml new file mode 100644 index 0000000..a47fe74 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.2.qml @@ -0,0 +1,19 @@ +import Qt.test 1.0 +import Qt 4.6 + +MyQmlObject { + property int test: 0 + + id: root + + Script { + function testFunction() { + test++; + } + } + + Component.onCompleted: root.argumentSignal.connect(root, testFunction); + + onBasicSignal: root.argumentSignal.disconnect(root, testFunction); +} + diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.3.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.3.qml new file mode 100644 index 0000000..c95ffbf --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.3.qml @@ -0,0 +1,19 @@ +import Qt.test 1.0 +import Qt 4.6 + +MyQmlObject { + property int test: 0 + + id: root + + Script { + function testFunction() { + test++; + } + } + + Component.onCompleted: root.argumentSignal.connect(root, testFunction); + + onBasicSignal: root.argumentSignal.disconnect(testFunction); +} + diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.4.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.4.qml new file mode 100644 index 0000000..342f24a --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.4.qml @@ -0,0 +1,20 @@ +import Qt.test 1.0 +import Qt 4.6 + +MyQmlObject { + property int test: 0 + + id: root + + Script { + function testFunction() { + test++; + } + function otherFunction() { + } + } + + Component.onCompleted: root.argumentSignal.connect(testFunction); + + onBasicSignal: root.argumentSignal.disconnect(otherFunction); +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index b5649cb..4838288 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -124,6 +124,8 @@ private slots: void deletedObject(); void scriptScope(); void attachedPropertyScope(); + void scriptConnect(); + void scriptDisconnect(); void bug1(); @@ -1731,6 +1733,166 @@ void tst_qdeclarativeecmascript::attachedPropertyScope() delete object; } +void tst_qdeclarativeecmascript::scriptConnect() +{ + { + QDeclarativeComponent component(&engine, TEST_FILE("scriptConnect.1.qml")); + + MyQmlObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->property("test").toBool(), false); + emit object->argumentSignal(19, "Hello world!", 10.3); + QCOMPARE(object->property("test").toBool(), true); + + delete object; + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("scriptConnect.2.qml")); + + MyQmlObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->property("test").toBool(), false); + emit object->argumentSignal(19, "Hello world!", 10.3); + QCOMPARE(object->property("test").toBool(), true); + + delete object; + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("scriptConnect.3.qml")); + + MyQmlObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->property("test").toBool(), false); + emit object->argumentSignal(19, "Hello world!", 10.3); + QCOMPARE(object->property("test").toBool(), true); + + delete object; + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("scriptConnect.4.qml")); + + MyQmlObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->methodCalled(), false); + emit object->argumentSignal(19, "Hello world!", 10.3); + QCOMPARE(object->methodCalled(), true); + + delete object; + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("scriptConnect.5.qml")); + + MyQmlObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->methodCalled(), false); + emit object->argumentSignal(19, "Hello world!", 10.3); + QCOMPARE(object->methodCalled(), true); + + delete object; + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("scriptConnect.6.qml")); + + MyQmlObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->property("test").toInt(), 0); + emit object->argumentSignal(19, "Hello world!", 10.3); + QCOMPARE(object->property("test").toInt(), 2); + + delete object; + } +} + +void tst_qdeclarativeecmascript::scriptDisconnect() +{ + { + QDeclarativeComponent component(&engine, TEST_FILE("scriptDisconnect.1.qml")); + + MyQmlObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->property("test").toInt(), 0); + emit object->argumentSignal(19, "Hello world!", 10.3); + QCOMPARE(object->property("test").toInt(), 1); + emit object->argumentSignal(19, "Hello world!", 10.3); + QCOMPARE(object->property("test").toInt(), 2); + emit object->basicSignal(); + QCOMPARE(object->property("test").toInt(), 2); + emit object->argumentSignal(19, "Hello world!", 10.3); + QCOMPARE(object->property("test").toInt(), 2); + + delete object; + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("scriptDisconnect.2.qml")); + + MyQmlObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->property("test").toInt(), 0); + emit object->argumentSignal(19, "Hello world!", 10.3); + QCOMPARE(object->property("test").toInt(), 1); + emit object->argumentSignal(19, "Hello world!", 10.3); + QCOMPARE(object->property("test").toInt(), 2); + emit object->basicSignal(); + QCOMPARE(object->property("test").toInt(), 2); + emit object->argumentSignal(19, "Hello world!", 10.3); + QCOMPARE(object->property("test").toInt(), 2); + + delete object; + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("scriptDisconnect.3.qml")); + + MyQmlObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->property("test").toInt(), 0); + emit object->argumentSignal(19, "Hello world!", 10.3); + QCOMPARE(object->property("test").toInt(), 1); + emit object->argumentSignal(19, "Hello world!", 10.3); + QCOMPARE(object->property("test").toInt(), 2); + emit object->basicSignal(); + QCOMPARE(object->property("test").toInt(), 2); + emit object->argumentSignal(19, "Hello world!", 10.3); + QCOMPARE(object->property("test").toInt(), 3); + + delete object; + } + { + QDeclarativeComponent component(&engine, TEST_FILE("scriptDisconnect.4.qml")); + + MyQmlObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->property("test").toInt(), 0); + emit object->argumentSignal(19, "Hello world!", 10.3); + QCOMPARE(object->property("test").toInt(), 1); + emit object->argumentSignal(19, "Hello world!", 10.3); + QCOMPARE(object->property("test").toInt(), 2); + emit object->basicSignal(); + QCOMPARE(object->property("test").toInt(), 2); + emit object->argumentSignal(19, "Hello world!", 10.3); + QCOMPARE(object->property("test").toInt(), 3); + + delete object; + } + +} + QTEST_MAIN(tst_qdeclarativeecmascript) #include "tst_qdeclarativeecmascript.moc" -- cgit v0.12 From 5de63109f548eee20df1fcf8b705b3471b005238 Mon Sep 17 00:00:00 2001 From: mae Date: Fri, 5 Mar 2010 11:53:07 +0100 Subject: optimize dynamic call-by-name away Reviewed-by: Roberto Raggi --- src/gui/graphicsview/qgraphicsscene.cpp | 20 ++++++++++++-------- src/gui/graphicsview/qgraphicsscene_p.h | 4 +++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 6bc02cc..f3de71e 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -228,6 +228,7 @@ #include #include #include +#include #include #include #include @@ -277,8 +278,6 @@ static void _q_hoverFromMouseEvent(QGraphicsSceneHoverEvent *hover, const QGraph hover->setAccepted(mouseEvent->isAccepted()); } -int QGraphicsScenePrivate::changedSignalIndex; - /*! \internal */ @@ -329,9 +328,10 @@ void QGraphicsScenePrivate::init() index = new QGraphicsSceneBspTreeIndex(q); // Keep this index so we can check for connected slots later on. - if (!changedSignalIndex) { - changedSignalIndex = signalIndex("changed(QList)"); - } + changedSignalIndex = signalIndex("changed(QList)"); + processDirtyItemsIndex = q->metaObject()->indexOfSlot("_q_processDirtyItems()"); + polishItemsIndex = q->metaObject()->indexOfSlot("_q_polishItems()"); + qApp->d_func()->scene_list.append(q); q->update(); } @@ -2537,8 +2537,10 @@ void QGraphicsScene::addItem(QGraphicsItem *item) return; } - if (d->unpolishedItems.isEmpty()) - QMetaObject::invokeMethod(this, "_q_polishItems", Qt::QueuedConnection); + if (d->unpolishedItems.isEmpty()) { + QMetaMethod method = metaObject()->method(d->polishItemsIndex); + method.invoke(this, Qt::QueuedConnection); + } d->unpolishedItems.append(item); item->d_ptr->pendingPolish = true; @@ -4892,7 +4894,9 @@ void QGraphicsScenePrivate::markDirty(QGraphicsItem *item, const QRectF &rect, b return; if (!processDirtyItemsEmitted) { - QMetaObject::invokeMethod(q_ptr, "_q_processDirtyItems", Qt::QueuedConnection); + QMetaMethod method = q_ptr->metaObject()->method(processDirtyItemsIndex); + method.invoke(q_ptr, Qt::QueuedConnection); +// QMetaObject::invokeMethod(q_ptr, "_q_processDirtyItems", Qt::QueuedConnection); processDirtyItemsEmitted = true; } diff --git a/src/gui/graphicsview/qgraphicsscene_p.h b/src/gui/graphicsview/qgraphicsscene_p.h index ca8b829..11e250e 100644 --- a/src/gui/graphicsview/qgraphicsscene_p.h +++ b/src/gui/graphicsview/qgraphicsscene_p.h @@ -87,7 +87,9 @@ public: static QGraphicsScenePrivate *get(QGraphicsScene *q); - static int changedSignalIndex; + int changedSignalIndex; + int processDirtyItemsIndex; + int polishItemsIndex; QGraphicsScene::ItemIndexMethod indexMethod; QGraphicsSceneIndex *index; -- cgit v0.12 From 038f6fc10092da1414fd2efff353671dbf862995 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Mon, 8 Mar 2010 11:42:31 +1000 Subject: Make test compile --- .../qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp index 4f9f21a..9adbc28 100644 --- a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp +++ b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp @@ -127,7 +127,7 @@ void tst_QDeclarativeWorkerScript::messaging() QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker).value(), value); qApp->processEvents(); - delete item; + delete worker; } void tst_QDeclarativeWorkerScript::messaging_data() @@ -164,7 +164,7 @@ void tst_QDeclarativeWorkerScript::messaging_sendQObjectList() QCOMPARE(result, (QVariantList() << QVariant() << QVariant() << QVariant())); qApp->processEvents(); - delete item; + delete worker; } void tst_QDeclarativeWorkerScript::messaging_sendJsObject() @@ -190,7 +190,7 @@ void tst_QDeclarativeWorkerScript::messaging_sendJsObject() QVERIFY(result.toBool()); qApp->processEvents(); - delete item; + delete worker; } QTEST_MAIN(tst_QDeclarativeWorkerScript) -- cgit v0.12 From 23440d84ddf78755e77cea75956cd7445647230a Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Mon, 8 Mar 2010 11:52:26 +1000 Subject: Fixed declarative demos not being installed. --- demos/declarative/calculator/calculator.pro | 13 +++++++++++++ demos/declarative/declarative.pro | 9 +++++++++ demos/declarative/flickr/flickr.pro | 16 ++++++++++++++++ demos/declarative/minehunt/minehunt.pro | 14 ++++++++++++++ demos/declarative/snake/snake.pro | 13 +++++++++++++ demos/declarative/twitter/twitter.pro | 13 +++++++++++++ demos/declarative/webbrowser/webbrowser.pro | 13 +++++++++++++ demos/demos.pro | 2 ++ 8 files changed, 93 insertions(+) create mode 100644 demos/declarative/calculator/calculator.pro create mode 100644 demos/declarative/declarative.pro create mode 100644 demos/declarative/flickr/flickr.pro create mode 100644 demos/declarative/snake/snake.pro create mode 100644 demos/declarative/twitter/twitter.pro create mode 100644 demos/declarative/webbrowser/webbrowser.pro diff --git a/demos/declarative/calculator/calculator.pro b/demos/declarative/calculator/calculator.pro new file mode 100644 index 0000000..efe6413 --- /dev/null +++ b/demos/declarative/calculator/calculator.pro @@ -0,0 +1,13 @@ +TEMPLATE=app +CONFIG -= qt separate_debug_info +LIBS = +QT = +QMAKE_LINK = @: dummy + +sources.files = \ + CalcButton.qml \ + calculator.js \ + calculator.qml +sources.path = $$[QT_INSTALL_DEMOS]/declarative/calculator +INSTALLS = sources + diff --git a/demos/declarative/declarative.pro b/demos/declarative/declarative.pro new file mode 100644 index 0000000..037ad85 --- /dev/null +++ b/demos/declarative/declarative.pro @@ -0,0 +1,9 @@ +TEMPLATE = subdirs +SUBDIRS = calculator \ + flickr \ + minehunt \ + samegame \ + snake \ + twitter \ + webbrowser + diff --git a/demos/declarative/flickr/flickr.pro b/demos/declarative/flickr/flickr.pro new file mode 100644 index 0000000..c4c1d44 --- /dev/null +++ b/demos/declarative/flickr/flickr.pro @@ -0,0 +1,16 @@ +TEMPLATE=app +CONFIG -= qt separate_debug_info +LIBS = +QT = +QMAKE_LINK = @: dummy + +sources.files = \ + flickr-desktop.qml \ + flickr-mobile-90.qml \ + flickr-mobile.qml \ + common \ + mobile + +sources.path = $$[QT_INSTALL_DEMOS]/declarative/flickr +INSTALLS = sources + diff --git a/demos/declarative/minehunt/minehunt.pro b/demos/declarative/minehunt/minehunt.pro index a497b0f..2f9a8ad 100644 --- a/demos/declarative/minehunt/minehunt.pro +++ b/demos/declarative/minehunt/minehunt.pro @@ -9,3 +9,17 @@ DESTDIR = MinehuntCore # Input SOURCES += minehunt.cpp + +sources.files = minehunt.qml +sources.path = $$[QT_INSTALL_DEMOS]/declarative/minehunt + +target.path = $$[QT_INSTALL_DEMOS]/declarative/minehunt/MinehuntCore + +MinehuntCore_sources.files = \ + MinehuntCore/Explosion.qml \ + MinehuntCore/pics \ + MinehuntCore/qmldir +MinehuntCore_sources.path = $$[QT_INSTALL_DEMOS]/declarative/minehunt/MinehuntCore + +INSTALLS = sources MinehuntCore_sources target + diff --git a/demos/declarative/snake/snake.pro b/demos/declarative/snake/snake.pro new file mode 100644 index 0000000..a206fd4 --- /dev/null +++ b/demos/declarative/snake/snake.pro @@ -0,0 +1,13 @@ +TEMPLATE=app +CONFIG -= qt separate_debug_info +LIBS = +QT = +QMAKE_LINK = @: dummy + +sources.files = \ + content \ + snake.qml + +sources.path = $$[QT_INSTALL_DEMOS]/declarative/snake +INSTALLS = sources + diff --git a/demos/declarative/twitter/twitter.pro b/demos/declarative/twitter/twitter.pro new file mode 100644 index 0000000..e1dd821 --- /dev/null +++ b/demos/declarative/twitter/twitter.pro @@ -0,0 +1,13 @@ +TEMPLATE=app +CONFIG -= qt separate_debug_info +LIBS = +QT = +QMAKE_LINK = @: dummy + +sources.files = \ + TwitterCore \ + twitter.qml + +sources.path = $$[QT_INSTALL_DEMOS]/declarative/twitter +INSTALLS = sources + diff --git a/demos/declarative/webbrowser/webbrowser.pro b/demos/declarative/webbrowser/webbrowser.pro new file mode 100644 index 0000000..c033ef9 --- /dev/null +++ b/demos/declarative/webbrowser/webbrowser.pro @@ -0,0 +1,13 @@ +TEMPLATE=app +CONFIG -= qt separate_debug_info +LIBS = +QT = +QMAKE_LINK = @: dummy + +sources.files = \ + content \ + webbrowser.qml + +sources.path = $$[QT_INSTALL_DEMOS]/declarative/webbrowser +INSTALLS = sources + diff --git a/demos/demos.pro b/demos/demos.pro index 4c2318c..83e9355 100644 --- a/demos/demos.pro +++ b/demos/demos.pro @@ -56,6 +56,7 @@ wince*:SUBDIRS += demos_sqlbrowser contains(QT_CONFIG, phonon):!static:SUBDIRS += demos_mediaplayer contains(QT_CONFIG, webkit):contains(QT_CONFIG, svg):!symbian:SUBDIRS += demos_browser contains(QT_CONFIG, multimedia):SUBDIRS += demos_multimedia +contains(QT_CONFIG, declarative):SUBDIRS += demos_declarative # install sources.files = README *.pro @@ -84,6 +85,7 @@ demos_undo.subdir = undo demos_qtdemo.subdir = qtdemo demos_mediaplayer.subdir = qmediaplayer demos_multimedia.subdir = multimedia +demos_declarative.subdir = declarative demos_browser.subdir = browser -- cgit v0.12 From a7856e3a5f6b9e5e2fd10690574b5f44ca50ba73 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Mon, 8 Mar 2010 12:30:34 +1000 Subject: Make compile following QDeclarativeMetaProperty renaming --- examples/declarative/extending/binding/happybirthday.cpp | 2 +- examples/declarative/extending/binding/happybirthday.h | 6 +++--- examples/declarative/extending/valuesource/happybirthday.cpp | 2 +- examples/declarative/extending/valuesource/happybirthday.h | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/declarative/extending/binding/happybirthday.cpp b/examples/declarative/extending/binding/happybirthday.cpp index 7d4d021..aa5f937 100644 --- a/examples/declarative/extending/binding/happybirthday.cpp +++ b/examples/declarative/extending/binding/happybirthday.cpp @@ -50,7 +50,7 @@ HappyBirthday::HappyBirthday(QObject *parent) timer->start(1000); } -void HappyBirthday::setTarget(const QDeclarativeMetaProperty &p) +void HappyBirthday::setTarget(const QDeclarativeProperty &p) { m_target = p; } diff --git a/examples/declarative/extending/binding/happybirthday.h b/examples/declarative/extending/binding/happybirthday.h index ee4d1ec..eb2da5e 100644 --- a/examples/declarative/extending/binding/happybirthday.h +++ b/examples/declarative/extending/binding/happybirthday.h @@ -42,7 +42,7 @@ #define HAPPYBIRTHDAY_H #include -#include +#include #include #include @@ -54,7 +54,7 @@ Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) public: HappyBirthday(QObject *parent = 0); - virtual void setTarget(const QDeclarativeMetaProperty &); + virtual void setTarget(const QDeclarativeProperty &); QString name() const; void setName(const QString &); @@ -67,7 +67,7 @@ signals: private: int m_line; QStringList m_lyrics; - QDeclarativeMetaProperty m_target; + QDeclarativeProperty m_target; QString m_name; }; QML_DECLARE_TYPE(HappyBirthday); diff --git a/examples/declarative/extending/valuesource/happybirthday.cpp b/examples/declarative/extending/valuesource/happybirthday.cpp index 7b9d05a..0dbbd6e 100644 --- a/examples/declarative/extending/valuesource/happybirthday.cpp +++ b/examples/declarative/extending/valuesource/happybirthday.cpp @@ -50,7 +50,7 @@ HappyBirthday::HappyBirthday(QObject *parent) timer->start(1000); } -void HappyBirthday::setTarget(const QDeclarativeMetaProperty &p) +void HappyBirthday::setTarget(const QDeclarativeProperty &p) { m_target = p; } diff --git a/examples/declarative/extending/valuesource/happybirthday.h b/examples/declarative/extending/valuesource/happybirthday.h index 3e68c35..b48c012 100644 --- a/examples/declarative/extending/valuesource/happybirthday.h +++ b/examples/declarative/extending/valuesource/happybirthday.h @@ -42,7 +42,7 @@ #define HAPPYBIRTHDAY_H #include -#include +#include #include #include @@ -57,7 +57,7 @@ Q_PROPERTY(QString name READ name WRITE setName) public: HappyBirthday(QObject *parent = 0); - virtual void setTarget(const QDeclarativeMetaProperty &); + virtual void setTarget(const QDeclarativeProperty &); // ![1] QString name() const; @@ -69,7 +69,7 @@ private slots: private: int m_line; QStringList m_lyrics; - QDeclarativeMetaProperty m_target; + QDeclarativeProperty m_target; QString m_name; // ![2] }; -- cgit v0.12 From 4ffb2a7a27ef5f06672e5f668e46d1657fa3e7ca Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 8 Mar 2010 12:28:32 +1000 Subject: Optimize Rectangle, Image, and Text creation. --- src/declarative/graphicsitems/qdeclarativeimage.cpp | 9 +++++++-- src/declarative/graphicsitems/qdeclarativeimage_p.h | 1 + src/declarative/graphicsitems/qdeclarativeimagebase.cpp | 12 ++++++++---- src/declarative/graphicsitems/qdeclarativeimagebase_p.h | 1 + src/declarative/graphicsitems/qdeclarativeimagebase_p_p.h | 1 + src/declarative/graphicsitems/qdeclarativerectangle.cpp | 3 --- src/declarative/graphicsitems/qdeclarativerectangle_p_p.h | 15 ++++++--------- src/declarative/graphicsitems/qdeclarativetext.cpp | 2 -- src/declarative/graphicsitems/qdeclarativetext_p_p.h | 10 ++++++---- 9 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp index 2739ab8..a20d6bc 100644 --- a/src/declarative/graphicsitems/qdeclarativeimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp @@ -127,7 +127,6 @@ QT_BEGIN_NAMESPACE QDeclarativeImage::QDeclarativeImage(QDeclarativeItem *parent) : QDeclarativeImageBase(*(new QDeclarativeImagePrivate), parent) { - connect(this, SIGNAL(pixmapChanged()), this, SLOT(updatePaintedGeometry())); } QDeclarativeImage::QDeclarativeImage(QDeclarativeImagePrivate &dd, QDeclarativeItem *parent) @@ -172,7 +171,7 @@ void QDeclarativeImagePrivate::setPixmap(const QPixmap &pixmap) status = pix.isNull() ? QDeclarativeImageBase::Null : QDeclarativeImageBase::Ready; q->update(); - emit q->pixmapChanged(); + q->pixmapChange(); } /*! @@ -384,4 +383,10 @@ void QDeclarativeImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWi } } +void QDeclarativeImage::pixmapChange() +{ + updatePaintedGeometry(); + QDeclarativeImageBase::pixmapChange(); +} + QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qdeclarativeimage_p.h b/src/declarative/graphicsitems/qdeclarativeimage_p.h index fb77ac9..7394774 100644 --- a/src/declarative/graphicsitems/qdeclarativeimage_p.h +++ b/src/declarative/graphicsitems/qdeclarativeimage_p.h @@ -85,6 +85,7 @@ Q_SIGNALS: protected: QDeclarativeImage(QDeclarativeImagePrivate &dd, QDeclarativeItem *parent); void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); + void pixmapChange(); protected Q_SLOTS: void updatePaintedGeometry(); diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp index a8cce3f..0e9638d 100644 --- a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp @@ -52,7 +52,6 @@ QT_BEGIN_NAMESPACE QDeclarativeImageBase::QDeclarativeImageBase(QDeclarativeImageBasePrivate &dd, QDeclarativeItem *parent) : QDeclarativeItem(dd, parent) { - setFlag(QGraphicsItem::ItemHasNoContents, false); } QDeclarativeImageBase::~QDeclarativeImageBase() @@ -131,7 +130,7 @@ void QDeclarativeImageBase::load() setImplicitWidth(0); setImplicitHeight(0); emit statusChanged(d->status); - emit pixmapChanged(); + pixmapChange(); update(); } else { d->status = Loading; @@ -173,7 +172,7 @@ void QDeclarativeImageBase::load() d->progress = 1.0; emit statusChanged(d->status); emit progressChanged(d->progress); - emit pixmapChanged(); + pixmapChange(); update(); } } @@ -197,7 +196,7 @@ void QDeclarativeImageBase::requestFinished() d->progress = 1.0; emit statusChanged(d->status); emit progressChanged(1.0); - emit pixmapChanged(); + pixmapChange(); update(); } @@ -218,4 +217,9 @@ void QDeclarativeImageBase::componentComplete() load(); } +void QDeclarativeImageBase::pixmapChange() +{ + emit pixmapChanged(); +} + QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase_p.h b/src/declarative/graphicsitems/qdeclarativeimagebase_p.h index c8c50ac..cfebdca 100644 --- a/src/declarative/graphicsitems/qdeclarativeimagebase_p.h +++ b/src/declarative/graphicsitems/qdeclarativeimagebase_p.h @@ -81,6 +81,7 @@ Q_SIGNALS: protected: virtual void load(); virtual void componentComplete(); + virtual void pixmapChange(); QDeclarativeImageBase(QDeclarativeImageBasePrivate &dd, QDeclarativeItem *parent); private Q_SLOTS: diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase_p_p.h b/src/declarative/graphicsitems/qdeclarativeimagebase_p_p.h index 2e062a8..c4a61f3 100644 --- a/src/declarative/graphicsitems/qdeclarativeimagebase_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativeimagebase_p_p.h @@ -71,6 +71,7 @@ public: pendingPixmapCache(false), async(false) { + QGraphicsItemPrivate::flags = QGraphicsItemPrivate::flags & ~QGraphicsItem::ItemHasNoContents; } QPixmap pix; diff --git a/src/declarative/graphicsitems/qdeclarativerectangle.cpp b/src/declarative/graphicsitems/qdeclarativerectangle.cpp index 05fe0f7..207d05e 100644 --- a/src/declarative/graphicsitems/qdeclarativerectangle.cpp +++ b/src/declarative/graphicsitems/qdeclarativerectangle.cpp @@ -180,9 +180,6 @@ void QDeclarativeGradient::doUpdate() QDeclarativeRectangle::QDeclarativeRectangle(QDeclarativeItem *parent) : QDeclarativeItem(*(new QDeclarativeRectanglePrivate), parent) { - Q_D(QDeclarativeRectangle); - d->init(); - setFlag(QGraphicsItem::ItemHasNoContents, false); } void QDeclarativeRectangle::doUpdate() diff --git a/src/declarative/graphicsitems/qdeclarativerectangle_p_p.h b/src/declarative/graphicsitems/qdeclarativerectangle_p_p.h index b87c57f..6bae219 100644 --- a/src/declarative/graphicsitems/qdeclarativerectangle_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativerectangle_p_p.h @@ -67,6 +67,7 @@ public: QDeclarativeRectanglePrivate() : color(Qt::white), gradient(0), pen(0), radius(0), paintmargin(0) { + QGraphicsItemPrivate::flags = QGraphicsItemPrivate::flags & ~QGraphicsItem::ItemHasNoContents; } ~QDeclarativeRectanglePrivate() @@ -74,13 +75,13 @@ public: delete pen; } - void init() - { - } - - QColor getColor(); QColor color; QDeclarativeGradient *gradient; + QDeclarativePen *pen; + qreal radius; + qreal paintmargin; + QPixmap rectImage; + QDeclarativePen *getPen() { if (!pen) { Q_Q(QDeclarativeRectangle); @@ -89,10 +90,6 @@ public: } return pen; } - QDeclarativePen *pen; - qreal radius; - qreal paintmargin; - QPixmap rectImage; void setPaintMargin(qreal margin) { diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index ca253df..05139f6 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -110,8 +110,6 @@ QT_BEGIN_NAMESPACE QDeclarativeText::QDeclarativeText(QDeclarativeItem *parent) : QDeclarativeItem(*(new QDeclarativeTextPrivate), parent) { - setAcceptedMouseButtons(Qt::LeftButton); - setFlag(QGraphicsItem::ItemHasNoContents, false); } QDeclarativeText::~QDeclarativeText() diff --git a/src/declarative/graphicsitems/qdeclarativetext_p_p.h b/src/declarative/graphicsitems/qdeclarativetext_p_p.h index a0c8abe..0d9a0a6 100644 --- a/src/declarative/graphicsitems/qdeclarativetext_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativetext_p_p.h @@ -70,14 +70,16 @@ class QDeclarativeTextPrivate : public QDeclarativeItemPrivate Q_DECLARE_PUBLIC(QDeclarativeText) public: QDeclarativeTextPrivate() - : color((QRgb)0), style(QDeclarativeText::Normal), imgDirty(true), + : color((QRgb)0), style(QDeclarativeText::Normal), hAlign(QDeclarativeText::AlignLeft), vAlign(QDeclarativeText::AlignTop), elideMode(QDeclarativeText::ElideNone), - dirty(true), wrap(false), richText(false), singleline(false), cache(true), doc(0), + imgDirty(true), dirty(true), wrap(false), richText(false), singleline(false), cache(true), doc(0), format(QDeclarativeText::AutoText) { #if defined(QML_NO_TEXT_CACHE) cache = false; #endif + QGraphicsItemPrivate::acceptedMouseButtons = Qt::LeftButton; + QGraphicsItemPrivate::flags = QGraphicsItemPrivate::flags & ~QGraphicsItem::ItemHasNoContents; } ~QDeclarativeTextPrivate(); @@ -106,12 +108,12 @@ public: QDeclarativeText::TextStyle style; QColor styleColor; QString activeLink; - bool imgDirty; QPixmap imgCache; QPixmap imgStyleCache; QDeclarativeText::HAlignment hAlign; QDeclarativeText::VAlignment vAlign; - QDeclarativeText::TextElideMode elideMode; + QDeclarativeText::TextElideMode elideMode; + bool imgDirty:1; bool dirty:1; bool wrap:1; bool richText:1; -- cgit v0.12 From 8429de44c2c5c046e403990ff04bc15ff1dee42a Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 8 Mar 2010 12:31:35 +1000 Subject: Stop benchmark from crashing. --- tests/benchmarks/declarative/creation/tst_creation.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/benchmarks/declarative/creation/tst_creation.cpp b/tests/benchmarks/declarative/creation/tst_creation.cpp index 4319208..5b0004f 100644 --- a/tests/benchmarks/declarative/creation/tst_creation.cpp +++ b/tests/benchmarks/declarative/creation/tst_creation.cpp @@ -163,6 +163,8 @@ void tst_creation::objects_qmltype() { QFETCH(QByteArray, type); QDeclarativeType *t = QDeclarativeMetaType::qmlType(type, 4, 6); + if (!t || !t->isCreatable()) + QSKIP("Non-creatable type", SkipSingle); QBENCHMARK { QObject *obj = t->create(); -- cgit v0.12 From 2d3323d239c9d20c98e09c9398931e60bb799cca Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 8 Mar 2010 12:38:17 +1000 Subject: Add PathView.isCurrentIndex and PathView.view attached properties Adding PathView attached properties to be in line with other views. Task-number: QT-319 --- .../graphicsitems/qdeclarativepathview.cpp | 196 +++++++++++++-------- .../graphicsitems/qdeclarativepathview_p.h | 51 +++++- .../graphicsitems/qdeclarativepathview_p_p.h | 7 +- .../qdeclarativepathview/data/pathview.qml | 11 +- .../tst_qdeclarativepathview.cpp | 46 ++++- 5 files changed, 235 insertions(+), 76 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp index 50aa9ef..cc17157 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview.cpp +++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp @@ -44,7 +44,6 @@ #include #include - #include #include #include @@ -64,48 +63,31 @@ inline qreal qmlMod(qreal x, qreal y) return fmod(x, y); } +static QDeclarativeOpenMetaObjectType *qPathViewAttachedType = 0; -class QDeclarativePathViewAttached : public QObject +QDeclarativePathViewAttached::QDeclarativePathViewAttached(QObject *parent) +: QObject(parent), m_view(0), m_onPath(false), m_isCurrent(false) { - Q_OBJECT - - Q_PROPERTY(bool onPath READ isOnPath NOTIFY onPathChanged) -public: - QDeclarativePathViewAttached(QObject *parent) - : QObject(parent), mo(new QDeclarativeOpenMetaObject(this)), onPath(false) - { - } - - ~QDeclarativePathViewAttached() - { - QDeclarativePathView::attachedProperties.remove(parent()); - } - - QVariant value(const QByteArray &name) const - { - return mo->value(name); - } - void setValue(const QByteArray &name, const QVariant &val) - { - mo->setValue(name, val); - } - - bool isOnPath() const { return onPath; } - void setOnPath(bool on) { - if (on != onPath) { - onPath = on; - emit onPathChanged(); - } + if (qPathViewAttachedType) { + m_metaobject = new QDeclarativeOpenMetaObject(this, qPathViewAttachedType); + m_metaobject->setCached(true); + } else { + m_metaobject = new QDeclarativeOpenMetaObject(this); } +} -Q_SIGNALS: - void onPathChanged(); - -private: - QDeclarativeOpenMetaObject *mo; - bool onPath; -}; +QDeclarativePathViewAttached::~QDeclarativePathViewAttached() +{ +} +QVariant QDeclarativePathViewAttached::value(const QByteArray &name) const +{ + return m_metaobject->value(name); +} +void QDeclarativePathViewAttached::setValue(const QByteArray &name, const QVariant &val) +{ + m_metaobject->setValue(name, val); +} QDeclarativeItem *QDeclarativePathViewPrivate::getItem(int modelIndex) { @@ -113,8 +95,20 @@ QDeclarativeItem *QDeclarativePathViewPrivate::getItem(int modelIndex) requestedIndex = modelIndex; QDeclarativeItem *item = model->item(modelIndex, false); if (item) { - if (QObject *obj = QDeclarativePathView::qmlAttachedProperties(item)) - static_cast(obj)->setOnPath(true); + if (!attType) { + // pre-create one metatype to share with all attached objects + attType = new QDeclarativeOpenMetaObjectType(&QDeclarativePathViewAttached::staticMetaObject, qmlEngine(q)); + foreach(const QString &attr, path->attributes()) { + attType->createProperty(attr.toUtf8()); + } + } + qPathViewAttachedType = attType; + QDeclarativePathViewAttached *att = static_cast(qmlAttachedPropertiesObject(item)); + qPathViewAttachedType = 0; + if (att) { + att->m_view = q; + att->setOnPath(true); + } item->setParentItem(q); } requestedIndex = -1; @@ -125,14 +119,26 @@ void QDeclarativePathViewPrivate::releaseItem(QDeclarativeItem *item) { if (!item || !model) return; - if (QObject *obj = QDeclarativePathView::qmlAttachedProperties(item)) - static_cast(obj)->setOnPath(false); - if (model->release(item) == 0) { - if (QObject *obj = QDeclarativePathView::qmlAttachedProperties(item)) - static_cast(obj)->setOnPath(false); + if (QDeclarativePathViewAttached *att = attached(item)) + att->setOnPath(false); + model->release(item); +} + +QDeclarativePathViewAttached *QDeclarativePathViewPrivate::attached(QDeclarativeItem *item) +{ + return static_cast(qmlAttachedPropertiesObject(item, false)); +} + +void QDeclarativePathViewPrivate::clear() +{ + for (int i=0; iclear(); + if (d->attType) + d->attType->release(); if (d->ownModel) delete d->model; } @@ -185,6 +199,15 @@ QDeclarativePathView::~QDeclarativePathView() */ /*! + \qmlattachedproperty bool PathView::isCurrentItem + This attached property is true if this delegate is the current item; otherwise false. + + It is attached to each instance of the delegate. + + This property may be used to adjust the appearance of the current item. +*/ + +/*! \qmlproperty model PathView::model This property holds the model providing data for the view. @@ -275,8 +298,15 @@ void QDeclarativePathView::setPath(QDeclarativePath *path) Q_D(QDeclarativePathView); if (d->path == path) return; + if (d->path) + disconnect(d->path, SIGNAL(changed()), this, SLOT(refill())); d->path = path; connect(d->path, SIGNAL(changed()), this, SLOT(refill())); + d->clear(); + if (d->attType) { + d->attType->release(); + d->attType = 0; + } d->regenerate(); emit pathChanged(); } @@ -297,12 +327,25 @@ void QDeclarativePathView::setCurrentIndex(int idx) if (d->model && d->model->count()) idx = qAbs(idx % d->model->count()); if (d->model && idx != d->currentIndex) { + if (d->model->count()) { + int itemIndex = (d->currentIndex - d->firstIndex + d->model->count()) % d->model->count(); + if (itemIndex < d->items.count()) { + if (QDeclarativeItem *item = d->items.at(d->currentIndex)) { + if (QDeclarativePathViewAttached *att = d->attached(item)) + att->setIsCurrentItem(false); + } + } + } d->currentIndex = idx; if (d->model->count()) { d->snapToCurrent(); int itemIndex = (idx - d->firstIndex + d->model->count()) % d->model->count(); - if (itemIndex < d->items.count()) - d->items.at(itemIndex)->setFocus(true); + if (itemIndex < d->items.count()) { + QDeclarativeItem *item = d->items.at(itemIndex); + item->setFocus(true); + if (QDeclarativePathViewAttached *att = d->attached(item)) + att->setIsCurrentItem(true); + } } emit currentIndexChanged(); } @@ -649,11 +692,7 @@ void QDeclarativePathViewPrivate::regenerate() if (!q->isComponentComplete()) return; - for (int i=0; isetZValue(i); + qreal percent = i * (100. / numItems) + _offset; + percent = qAbs(qmlMod(percent, qreal(100.0))/100.0); + updateItem(item, percent); model->completeItem(); - if (currentIndex == index) + if (currentIndex == index) { item->setFocus(true); + if (QDeclarativePathViewAttached *att = attached(item)) + att->setIsCurrentItem(true); + } } - q->refill(); + if (pathItems != -1) + q->refill(); } void QDeclarativePathViewPrivate::updateItem(QDeclarativeItem *item, qreal percent) { - if (QObject *obj = QDeclarativePathView::qmlAttachedProperties(item)) { + if (QDeclarativePathViewAttached *att = attached(item)) { foreach(const QString &attr, path->attributes()) - static_cast(obj)->setValue(attr.toUtf8(), path->attributeAt(attr, percent)); + att->setValue(attr.toUtf8(), path->attributeAt(attr, percent)); } QPointF pf = path->pointAt(percent); item->setX(pf.x() - item->width()*item->scale()/2); @@ -735,8 +781,11 @@ void QDeclarativePathView::refill() QDeclarativeItem *item = d->getItem(index); item->setZValue(wrapIndex); d->model->completeItem(); - if (d->currentIndex == index) + if (d->currentIndex == index) { item->setFocus(true); + if (QDeclarativePathViewAttached *att = d->attached(item)) + att->setIsCurrentItem(true); + } d->items << item; d->pathOffset++; d->pathOffset=d->pathOffset % d->items.count(); @@ -752,8 +801,11 @@ void QDeclarativePathView::refill() QDeclarativeItem *item = d->getItem(d->firstIndex); item->setZValue(d->firstIndex); d->model->completeItem(); - if (d->currentIndex == d->firstIndex) + if (d->currentIndex == d->firstIndex) { item->setFocus(true); + if (QDeclarativePathViewAttached *att = d->attached(item)) + att->setIsCurrentItem(true); + } d->items.prepend(item); d->pathOffset--; if (d->pathOffset < 0) @@ -909,10 +961,21 @@ void QDeclarativePathViewPrivate::updateCurrent() return; int idx = calcCurrentIndex(); if (model && idx != currentIndex) { + int itemIndex = (currentIndex - firstIndex + model->count()) % model->count(); + if (itemIndex < items.count()) { + if (QDeclarativeItem *item = items.at(itemIndex)) { + if (QDeclarativePathViewAttached *att = attached(item)) + att->setIsCurrentItem(false); + } + } currentIndex = idx; - int itemIndex = (idx - firstIndex + model->count()) % model->count(); - if (itemIndex < items.count()) - items.at(itemIndex)->setFocus(true); + itemIndex = (idx - firstIndex + model->count()) % model->count(); + if (itemIndex < items.count()) { + QDeclarativeItem *item = items.at(itemIndex); + item->setFocus(true); + if (QDeclarativePathViewAttached *att = attached(item)) + att->setIsCurrentItem(true); + } emit q->currentIndexChanged(); } } @@ -993,17 +1056,10 @@ void QDeclarativePathViewPrivate::snapToCurrent() } } -QHash QDeclarativePathView::attachedProperties; -QObject *QDeclarativePathView::qmlAttachedProperties(QObject *obj) +QDeclarativePathViewAttached *QDeclarativePathView::qmlAttachedProperties(QObject *obj) { - QObject *rv = attachedProperties.value(obj); - if (!rv) { - rv = new QDeclarativePathViewAttached(obj); - attachedProperties.insert(obj, rv); - } - return rv; + return new QDeclarativePathViewAttached(obj); } QT_END_NAMESPACE -#include diff --git a/src/declarative/graphicsitems/qdeclarativepathview_p.h b/src/declarative/graphicsitems/qdeclarativepathview_p.h index df9c6ae..6dbd044 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview_p.h +++ b/src/declarative/graphicsitems/qdeclarativepathview_p.h @@ -52,6 +52,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) class QDeclarativePathViewPrivate; +class QDeclarativePathViewAttached; class Q_DECLARATIVE_EXPORT QDeclarativePathView : public QDeclarativeItem { Q_OBJECT @@ -96,7 +97,7 @@ public: int pathItemCount() const; void setPathItemCount(int); - static QObject *qmlAttachedProperties(QObject *); + static QDeclarativePathViewAttached *qmlAttachedProperties(QObject *); Q_SIGNALS: void currentIndexChanged(); @@ -127,11 +128,57 @@ private Q_SLOTS: private: friend class QDeclarativePathViewAttached; - static QHash attachedProperties; Q_DISABLE_COPY(QDeclarativePathView) Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativePathView) }; +class QDeclarativeOpenMetaObject; +class QDeclarativePathViewAttached : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QDeclarativePathView *view READ view CONSTANT) + Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged) + Q_PROPERTY(bool onPath READ isOnPath NOTIFY pathChanged) + +public: + QDeclarativePathViewAttached(QObject *parent); + ~QDeclarativePathViewAttached(); + + QDeclarativePathView *view() { return m_view; } + + bool isCurrentItem() const { return m_isCurrent; } + void setIsCurrentItem(bool c) { + if (m_isCurrent != c) { + m_isCurrent = c; + emit currentItemChanged(); + } + } + + QVariant value(const QByteArray &name) const; + void setValue(const QByteArray &name, const QVariant &val); + + bool isOnPath() const { return m_onPath; } + void setOnPath(bool on) { + if (on != m_onPath) { + m_onPath = on; + emit pathChanged(); + } + } + +Q_SIGNALS: + void currentItemChanged(); + void pathChanged(); + +private: + friend class QDeclarativePathViewPrivate; + QDeclarativePathView *m_view; + QDeclarativeOpenMetaObject *m_metaobject; + bool m_onPath : 1; + bool m_isCurrent : 1; +}; + + QT_END_NAMESPACE QML_DECLARE_TYPE(QDeclarativePathView) diff --git a/src/declarative/graphicsitems/qdeclarativepathview_p_p.h b/src/declarative/graphicsitems/qdeclarativepathview_p_p.h index 6344a8a..4083ab5 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativepathview_p_p.h @@ -71,6 +71,8 @@ typedef struct PathViewItem{ QDeclarativeItem* item; }PathViewItem; +class QDeclarativeOpenMetaObjectType; +class QDeclarativePathViewAttached; class QDeclarativePathViewPrivate : public QDeclarativeItemPrivate { Q_DECLARE_PUBLIC(QDeclarativePathView) @@ -81,7 +83,7 @@ public: , lastElapsed(0), stealMouse(false), ownModel(false), activeItem(0) , snapPos(0), dragMargin(0), moveOffset(this, &QDeclarativePathViewPrivate::setOffset) , firstIndex(0), pathItems(-1), pathOffset(0), requestedIndex(-1) - , moveReason(Other) + , moveReason(Other), attType(0) { } @@ -97,6 +99,8 @@ public: QDeclarativeItem *getItem(int modelIndex); void releaseItem(QDeclarativeItem *item); + QDeclarativePathViewAttached *attached(QDeclarativeItem *item); + void clear(); bool isValid() const { return model && model->count() > 0 && model->isValid() && path; @@ -137,6 +141,7 @@ public: QVariant modelVariant; enum MovementReason { Other, Key, Mouse }; MovementReason moveReason; + QDeclarativeOpenMetaObjectType *attType; }; QT_END_NAMESPACE diff --git a/tests/auto/declarative/qdeclarativepathview/data/pathview.qml b/tests/auto/declarative/qdeclarativepathview/data/pathview.qml index c5d88cd..ae0c86a 100644 --- a/tests/auto/declarative/qdeclarativepathview/data/pathview.qml +++ b/tests/auto/declarative/qdeclarativepathview/data/pathview.qml @@ -1,6 +1,9 @@ import Qt 4.6 Rectangle { + id: root + property int currentA: -1 + property int currentB: -1 width: 240 height: 320 color: "#ffffff" @@ -12,7 +15,7 @@ Rectangle { objectName: "wrapper" height: 20 width: 60 - color: "white" + color: PathView.isCurrentItem ? "lightsteelblue" : "white" border.color: "black" Text { text: index @@ -29,6 +32,12 @@ Rectangle { objectName: "textNumber" text: number } + PathView.onCurrentItemChanged: { + if (PathView.isCurrentItem) { + root.currentA = index; + root.currentB = wrapper.PathView.view.currentIndex; + } + } } } ] diff --git a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp index fa4e9d3..62eb8c3 100644 --- a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp +++ b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp @@ -71,6 +71,7 @@ private slots: void pathview3(); void path(); void pathMoved(); + void setCurrentIndex(); void resetModel(); void propertyChanges(); void pathChanges(); @@ -207,6 +208,7 @@ void tst_QDeclarativePathView::items() model.addItem("Fred", "12345"); model.addItem("John", "2345"); model.addItem("Bob", "54321"); + model.addItem("Bill", "4321"); QDeclarativeContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); @@ -421,7 +423,6 @@ void tst_QDeclarativePathView::pathMoved() offset.setY(firstItem->height()/2); QCOMPARE(firstItem->pos() + offset, start); pathview->setOffset(10); - QTest::qWait(1000);//Moving is animated? for(int i=0; i(pathview, "wrapper", i); @@ -429,12 +430,53 @@ void tst_QDeclarativePathView::pathMoved() } pathview->setOffset(100); - QTest::qWait(1000);//Moving is animated? QCOMPARE(firstItem->pos() + offset, start); delete canvas; } +void tst_QDeclarativePathView::setCurrentIndex() +{ + QDeclarativeView *canvas = createView(); + + TestModel model; + model.addItem("Ben", "12345"); + model.addItem("Bohn", "2345"); + model.addItem("Bob", "54321"); + model.addItem("Bill", "4321"); + + QDeclarativeContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/pathview.qml")); + qApp->processEvents(); + + QDeclarativePathView *pathview = findItem(canvas->rootObject(), "view"); + QVERIFY(pathview != 0); + + QDeclarativeRectangle *firstItem = findItem(pathview, "wrapper", 0); + QVERIFY(firstItem); + QDeclarativePath *path = qobject_cast(pathview->path()); + QVERIFY(path); + QPointF start = path->pointAt(0.0); + QPointF offset;//Center of item is at point, but pos is from corner + offset.setX(firstItem->width()/2); + offset.setY(firstItem->height()/2); + QCOMPARE(firstItem->pos() + offset, start); + QCOMPARE(canvas->rootObject()->property("currentA").toInt(), 0); + QCOMPARE(canvas->rootObject()->property("currentB").toInt(), 0); + + pathview->setCurrentIndex(2); + QTest::qWait(1000); + + firstItem = findItem(pathview, "wrapper", 2); + QCOMPARE(firstItem->pos() + offset, start); + QCOMPARE(canvas->rootObject()->property("currentA").toInt(), 2); + QCOMPARE(canvas->rootObject()->property("currentB").toInt(), 2); + + delete canvas; +} + void tst_QDeclarativePathView::resetModel() { QDeclarativeView *canvas = createView(); -- cgit v0.12 From eb45d1cc264dbec26575b2bd6cd23b09e3ade653 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 8 Mar 2010 12:43:22 +1000 Subject: Remove code dupliation in fixupX/Y(), flickX/Y() Also some minor perf improvements by avoiding signal/slot connection --- .../graphicsitems/qdeclarativeflickable.cpp | 385 ++++++++++----------- .../graphicsitems/qdeclarativeflickable_p.h | 4 +- .../graphicsitems/qdeclarativeflickable_p_p.h | 79 +++-- .../graphicsitems/qdeclarativegridview.cpp | 33 +- .../graphicsitems/qdeclarativegridview_p.h | 1 - .../graphicsitems/qdeclarativelistview.cpp | 287 +++++---------- .../graphicsitems/qdeclarativelistview_p.h | 4 +- 7 files changed, 326 insertions(+), 467 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index 63c97e0..67068a0 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -90,7 +90,7 @@ void QDeclarativeFlickableVisibleArea::updateVisible() // Vertical const qreal viewheight = flickable->height(); const qreal maxyextent = -flickable->maxYExtent() + flickable->minYExtent(); - qreal pagePos = (-p->_moveY.value() + flickable->minYExtent()) / (maxyextent + viewheight); + qreal pagePos = (-p->vData.move.value() + flickable->minYExtent()) / (maxyextent + viewheight); qreal pageSize = viewheight / (maxyextent + viewheight); if (pageSize != m_heightRatio) { @@ -105,7 +105,7 @@ void QDeclarativeFlickableVisibleArea::updateVisible() // Horizontal const qreal viewwidth = flickable->width(); const qreal maxxextent = -flickable->maxXExtent() + flickable->minXExtent(); - pagePos = (-p->_moveX.value() + flickable->minXExtent()) / (maxxextent + viewwidth); + pagePos = (-p->hData.move.value() + flickable->minXExtent()) / (maxxextent + viewwidth); pageSize = viewwidth / (maxxextent + viewwidth); if (pageSize != m_widthRatio) { @@ -123,13 +123,13 @@ void QDeclarativeFlickableVisibleArea::updateVisible() QDeclarativeFlickablePrivate::QDeclarativeFlickablePrivate() : viewport(new QDeclarativeItem) - , _moveX(this, &QDeclarativeFlickablePrivate::setRoundedViewportX) - , _moveY(this, &QDeclarativeFlickablePrivate::setRoundedViewportY) - , vWidth(-1), vHeight(-1), overShoot(true), flicked(false), moving(false), stealMouse(false) - , pressed(false), atXEnd(false), atXBeginning(true), atYEnd(false), atYBeginning(true) + , hData(this, &QDeclarativeFlickablePrivate::setRoundedViewportX) + , vData(this, &QDeclarativeFlickablePrivate::setRoundedViewportY) + , overShoot(true), flicked(false), moving(false), stealMouse(false) + , pressed(false) , interactive(true), deceleration(500), maxVelocity(2000), reportedVelocitySmoothing(100) , delayedPressEvent(0), delayedPressTarget(0), pressDelay(0), fixupDuration(600) - , horizontalVelocity(this), verticalVelocity(this), vTime(0), visibleArea(0) + , vTime(0), visibleArea(0) , flickDirection(QDeclarativeFlickable::AutoFlickDirection) { } @@ -138,14 +138,24 @@ void QDeclarativeFlickablePrivate::init() { Q_Q(QDeclarativeFlickable); viewport->setParent(q); - QObject::connect(&timeline, SIGNAL(updated()), q, SLOT(ticked())); - QObject::connect(&timeline, SIGNAL(completed()), q, SLOT(movementEnding())); + static int timelineUpdatedIdx = -1; + static int timelineCompletedIdx = -1; + static int flickableTickedIdx = -1; + static int flickableMovementEndingIdx = -1; + if (timelineUpdatedIdx == -1) { + timelineUpdatedIdx = QDeclarativeTimeLine::staticMetaObject.indexOfSignal("updated()"); + timelineCompletedIdx = QDeclarativeTimeLine::staticMetaObject.indexOfSignal("completed()"); + flickableTickedIdx = QDeclarativeFlickable::staticMetaObject.indexOfSlot("ticked()"); + flickableMovementEndingIdx = QDeclarativeFlickable::staticMetaObject.indexOfSlot("movementEnding()"); + } + QMetaObject::connect(&timeline, timelineUpdatedIdx, + q, flickableTickedIdx, Qt::DirectConnection); + QMetaObject::connect(&timeline, timelineCompletedIdx, + q, flickableMovementEndingIdx, Qt::DirectConnection); q->setAcceptedMouseButtons(Qt::LeftButton); q->setFiltersChildEvents(true); - QObject::connect(viewport, SIGNAL(xChanged()), q, SIGNAL(contentXChanged())); - QObject::connect(viewport, SIGNAL(yChanged()), q, SIGNAL(contentYChanged())); - QObject::connect(q, SIGNAL(heightChanged()), q, SLOT(heightChange())); - QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(widthChange())); + QDeclarativeItemPrivate *viewportPrivate = static_cast(QGraphicsItemPrivate::get(viewport)); + viewportPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry); } /* @@ -164,59 +174,43 @@ qreal QDeclarativeFlickablePrivate::overShootDistance(qreal velocity, qreal size return dist; } -void QDeclarativeFlickablePrivate::flickX(qreal velocity) +void QDeclarativeFlickablePrivate::itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeom, const QRectF &oldGeom) { Q_Q(QDeclarativeFlickable); - qreal maxDistance = -1; - // -ve velocity means list is moving up - if (velocity > 0) { - const qreal minX = q->minXExtent(); - if (_moveX.value() < minX) - maxDistance = qAbs(minX -_moveX.value() + (overShoot?overShootDistance(velocity,q->width()):0)); - flickTargetX = minX; - } else { - const qreal maxX = q->maxXExtent(); - if (_moveX.value() > maxX) - maxDistance = qAbs(maxX - _moveX.value()) + (overShoot?overShootDistance(velocity,q->width()):0); - flickTargetX = maxX; - } - if (maxDistance > 0) { - qreal v = velocity; - if (maxVelocity != -1 && maxVelocity < qAbs(v)) { - if (v < 0) - v = -maxVelocity; - else - v = maxVelocity; - } - timeline.reset(_moveX); - timeline.accel(_moveX, v, deceleration, maxDistance); - timeline.callback(QDeclarativeTimeLineCallback(&_moveX, fixupX_callback, this)); - if (!flicked) { - flicked = true; - emit q->flickingChanged(); - emit q->flickStarted(); - } - } else { - timeline.reset(_moveX); - fixupX(); + if (item == viewport) { + if (newGeom.x() != oldGeom.x()) + emit q->contentXChanged(); + if (newGeom.y() != oldGeom.y()) + emit q->contentYChanged(); } } +void QDeclarativeFlickablePrivate::flickX(qreal velocity) +{ + Q_Q(QDeclarativeFlickable); + flick(hData, q->minXExtent(), q->maxXExtent(), q->width(), fixupX_callback, velocity); +} + void QDeclarativeFlickablePrivate::flickY(qreal velocity) { Q_Q(QDeclarativeFlickable); + flick(vData, q->minYExtent(), q->maxYExtent(), q->height(), fixupY_callback, velocity); +} + +void QDeclarativeFlickablePrivate::flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize, + QDeclarativeTimeLineCallback::Callback fixupCallback, qreal velocity) +{ + Q_Q(QDeclarativeFlickable); qreal maxDistance = -1; // -ve velocity means list is moving up if (velocity > 0) { - const qreal minY = q->minYExtent(); - if (_moveY.value() < minY) - maxDistance = qAbs(minY -_moveY.value() + (overShoot?overShootDistance(velocity,q->height()):0)); - flickTargetY = minY; + if (data.move.value() < minExtent) + maxDistance = qAbs(minExtent - data.move.value() + (overShoot?overShootDistance(velocity,vSize):0)); + data.flickTarget = minExtent; } else { - const qreal maxY = q->maxYExtent(); - if (_moveY.value() > maxY) - maxDistance = qAbs(maxY - _moveY.value()) + (overShoot?overShootDistance(velocity,q->height()):0); - flickTargetY = maxY; + if (data.move.value() > maxExtent) + maxDistance = qAbs(maxExtent - data.move.value()) + (overShoot?overShootDistance(velocity,vSize):0); + data.flickTarget = maxExtent; } if (maxDistance > 0) { qreal v = velocity; @@ -226,55 +220,20 @@ void QDeclarativeFlickablePrivate::flickY(qreal velocity) else v = maxVelocity; } - timeline.reset(_moveY); - timeline.accel(_moveY, v, deceleration, maxDistance); - timeline.callback(QDeclarativeTimeLineCallback(&_moveY, fixupY_callback, this)); + timeline.reset(data.move); + timeline.accel(data.move, v, deceleration, maxDistance); + timeline.callback(QDeclarativeTimeLineCallback(&data.move, fixupCallback, this)); if (!flicked) { flicked = true; emit q->flickingChanged(); emit q->flickStarted(); } } else { - timeline.reset(_moveY); - fixupY(); + timeline.reset(data.move); + fixup(data, minExtent, maxExtent); } } -void QDeclarativeFlickablePrivate::fixupX() -{ - Q_Q(QDeclarativeFlickable); - if (!q->xflick() || _moveX.timeLine()) - return; - - if (_moveX.value() > q->minXExtent() || (q->maxXExtent() > q->minXExtent())) { - timeline.reset(_moveX); - if (_moveX.value() != q->minXExtent()) { - if (fixupDuration) { - qreal dist = q->minXExtent() - _moveX; - timeline.move(_moveX, q->minXExtent() - dist/2, QEasingCurve(QEasingCurve::InQuad), fixupDuration/4); - timeline.move(_moveX, q->minXExtent(), QEasingCurve(QEasingCurve::OutQuint), 3*fixupDuration/4); - } else { - _moveX.setValue(q->minXExtent()); - } - } - //emit flickingChanged(); - } else if (_moveX.value() < q->maxXExtent()) { - timeline.reset(_moveX); - if (fixupDuration) { - qreal dist = q->maxXExtent() - _moveX; - timeline.move(_moveX, q->maxXExtent() - dist/2, QEasingCurve(QEasingCurve::InQuad), fixupDuration/4); - timeline.move(_moveX, q->maxXExtent(), QEasingCurve(QEasingCurve::OutQuint), 3*fixupDuration/4); - } else { - _moveX.setValue(q->maxXExtent()); - } - //emit flickingChanged(); - } else { - flicked = false; - } - - vTime = timeline.time(); -} - void QDeclarativeFlickablePrivate::fixupY_callback(void *data) { ((QDeclarativeFlickablePrivate *)data)->fixupY(); @@ -285,32 +244,46 @@ void QDeclarativeFlickablePrivate::fixupX_callback(void *data) ((QDeclarativeFlickablePrivate *)data)->fixupX(); } +void QDeclarativeFlickablePrivate::fixupX() +{ + Q_Q(QDeclarativeFlickable); + if (!q->xflick() || hData.move.timeLine()) + return; + + fixup(hData, q->minXExtent(), q->maxXExtent()); +} + void QDeclarativeFlickablePrivate::fixupY() { Q_Q(QDeclarativeFlickable); - if (!q->yflick() || _moveY.timeLine()) + if (!q->yflick() || vData.move.timeLine()) return; - if (_moveY.value() > q->minYExtent() || (q->maxYExtent() > q->minYExtent())) { - timeline.reset(_moveY); - if (_moveY.value() != q->minYExtent()) { + fixup(vData, q->minYExtent(), q->maxYExtent()); +} + +void QDeclarativeFlickablePrivate::fixup(AxisData &data, qreal minExtent, qreal maxExtent) +{ + if (data.move.value() > minExtent || maxExtent > minExtent) { + timeline.reset(data.move); + if (data.move.value() != minExtent) { if (fixupDuration) { - qreal dist = q->minYExtent() - _moveY; - timeline.move(_moveY, q->minYExtent() - dist/2, QEasingCurve(QEasingCurve::InQuad), fixupDuration/4); - timeline.move(_moveY, q->minYExtent(), QEasingCurve(QEasingCurve::OutQuint), 3*fixupDuration/4); + qreal dist = minExtent - data.move; + timeline.move(data.move, minExtent - dist/2, QEasingCurve(QEasingCurve::InQuad), fixupDuration/4); + timeline.move(data.move, minExtent, QEasingCurve(QEasingCurve::OutQuint), 3*fixupDuration/4); } else { - _moveY.setValue(q->minYExtent()); + data.move.setValue(minExtent); } } //emit flickingChanged(); - } else if (_moveY.value() < q->maxYExtent()) { - timeline.reset(_moveY); + } else if (data.move.value() < maxExtent) { + timeline.reset(data.move); if (fixupDuration) { - qreal dist = q->maxYExtent() - _moveY; - timeline.move(_moveY, q->maxYExtent() - dist/2, QEasingCurve(QEasingCurve::InQuad), fixupDuration/4); - timeline.move(_moveY, q->maxYExtent(), QEasingCurve(QEasingCurve::OutQuint), 3*fixupDuration/4); + qreal dist = maxExtent - data.move; + timeline.move(data.move, maxExtent - dist/2, QEasingCurve(QEasingCurve::InQuad), fixupDuration/4); + timeline.move(data.move, maxExtent, QEasingCurve(QEasingCurve::OutQuint), 3*fixupDuration/4); } else { - _moveY.setValue(q->maxYExtent()); + data.move.setValue(maxExtent); } //emit flickingChanged(); } else { @@ -327,31 +300,31 @@ void QDeclarativeFlickablePrivate::updateBeginningEnd() // Vertical const int maxyextent = int(-q->maxYExtent()); - const qreal ypos = -_moveY.value(); + const qreal ypos = -vData.move.value(); bool atBeginning = (ypos <= -q->minYExtent()); bool atEnd = (maxyextent <= ypos); - if (atBeginning != atYBeginning) { - atYBeginning = atBeginning; + if (atBeginning != vData.atBeginning) { + vData.atBeginning = atBeginning; atBoundaryChange = true; } - if (atEnd != atYEnd) { - atYEnd = atEnd; + if (atEnd != vData.atEnd) { + vData.atEnd = atEnd; atBoundaryChange = true; } // Horizontal const int maxxextent = int(-q->maxXExtent()); - const qreal xpos = -_moveX.value(); + const qreal xpos = -hData.move.value(); atBeginning = (xpos <= -q->minXExtent()); atEnd = (maxxextent <= xpos); - if (atBeginning != atXBeginning) { - atXBeginning = atBeginning; + if (atBeginning != hData.atBeginning) { + hData.atBeginning = atBeginning; atBoundaryChange = true; } - if (atEnd != atXEnd) { - atXEnd = atEnd; + if (atEnd != hData.atEnd) { + hData.atEnd = atEnd; atBoundaryChange = true; } @@ -468,17 +441,17 @@ QDeclarativeFlickable::~QDeclarativeFlickable() qreal QDeclarativeFlickable::contentX() const { Q_D(const QDeclarativeFlickable); - return -d->_moveX.value(); + return -d->hData.move.value(); } void QDeclarativeFlickable::setContentX(qreal pos) { Q_D(QDeclarativeFlickable); pos = qRound(pos); - d->timeline.reset(d->_moveX); + d->timeline.reset(d->hData.move); d->vTime = d->timeline.time(); - if (-pos != d->_moveX.value()) { - d->_moveX.setValue(-pos); + if (-pos != d->hData.move.value()) { + d->hData.move.setValue(-pos); viewportMoved(); } } @@ -486,17 +459,17 @@ void QDeclarativeFlickable::setContentX(qreal pos) qreal QDeclarativeFlickable::contentY() const { Q_D(const QDeclarativeFlickable); - return -d->_moveY.value(); + return -d->vData.move.value(); } void QDeclarativeFlickable::setContentY(qreal pos) { Q_D(QDeclarativeFlickable); pos = qRound(pos); - d->timeline.reset(d->_moveY); + d->timeline.reset(d->vData.move); d->vTime = d->timeline.time(); - if (-pos != d->_moveY.value()) { - d->_moveY.setValue(-pos); + if (-pos != d->vData.move.value()) { + d->vData.move.setValue(-pos); viewportMoved(); } } @@ -543,13 +516,13 @@ void QDeclarativeFlickable::setInteractive(bool interactive) qreal QDeclarativeFlickable::horizontalVelocity() const { Q_D(const QDeclarativeFlickable); - return d->horizontalVelocity.value(); + return d->hData.smoothVelocity.value(); } qreal QDeclarativeFlickable::verticalVelocity() const { Q_D(const QDeclarativeFlickable); - return d->verticalVelocity.value(); + return d->vData.smoothVelocity.value(); } /*! @@ -564,25 +537,25 @@ qreal QDeclarativeFlickable::verticalVelocity() const bool QDeclarativeFlickable::isAtXEnd() const { Q_D(const QDeclarativeFlickable); - return d->atXEnd; + return d->hData.atEnd; } bool QDeclarativeFlickable::isAtXBeginning() const { Q_D(const QDeclarativeFlickable); - return d->atXBeginning; + return d->hData.atBeginning; } bool QDeclarativeFlickable::isAtYEnd() const { Q_D(const QDeclarativeFlickable); - return d->atYEnd; + return d->vData.atEnd; } bool QDeclarativeFlickable::isAtYBeginning() const { Q_D(const QDeclarativeFlickable); - return d->atYBeginning; + return d->vData.atBeginning; } void QDeclarativeFlickable::ticked() @@ -636,19 +609,19 @@ void QDeclarativeFlickable::setFlickDirection(FlickDirection direction) void QDeclarativeFlickablePrivate::handleMousePressEvent(QGraphicsSceneMouseEvent *event) { - if (interactive && timeline.isActive() && (qAbs(velocityX) > 10 || qAbs(velocityY) > 10)) + if (interactive && timeline.isActive() && (qAbs(hData.velocity) > 10 || qAbs(vData.velocity) > 10)) stealMouse = true; // If we've been flicked then steal the click. else stealMouse = false; pressed = true; timeline.clear(); - velocityX = 0; - velocityY = 0; + hData.velocity = 0; + vData.velocity = 0; lastPos = QPoint(); QDeclarativeItemPrivate::start(lastPosTime); pressPos = event->pos(); - pressX = _moveX.value(); - pressY = _moveY.value(); + hData.pressPos = hData.move.value(); + vData.pressPos = vData.move.value(); flicked = false; QDeclarativeItemPrivate::start(pressTime); QDeclarativeItemPrivate::start(velocityTime); @@ -666,7 +639,7 @@ void QDeclarativeFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent if (q->yflick()) { int dy = int(event->pos().y() - pressPos.y()); if (qAbs(dy) > QApplication::startDragDistance() || QDeclarativeItemPrivate::elapsed(pressTime) > 200) { - qreal newY = dy + pressY; + qreal newY = dy + vData.pressPos; const qreal minY = q->minYExtent(); const qreal maxY = q->maxYExtent(); if (newY > minY) @@ -682,7 +655,7 @@ void QDeclarativeFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent rejectY = true; } if (!rejectY && stealMouse) { - _moveY.setValue(newY); + vData.move.setValue(newY); moved = true; } if (qAbs(dy) > QApplication::startDragDistance()) @@ -693,7 +666,7 @@ void QDeclarativeFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent if (q->xflick()) { int dx = int(event->pos().x() - pressPos.x()); if (qAbs(dx) > QApplication::startDragDistance() || QDeclarativeItemPrivate::elapsed(pressTime) > 200) { - qreal newX = dx + pressX; + qreal newX = dx + hData.pressPos; const qreal minX = q->minXExtent(); const qreal maxX = q->maxXExtent(); if (newX > minX) @@ -709,7 +682,7 @@ void QDeclarativeFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent rejectX = true; } if (!rejectX && stealMouse) { - _moveX.setValue(newX); + hData.move.setValue(newX); moved = true; } @@ -725,20 +698,20 @@ void QDeclarativeFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent if (q->yflick()) { qreal diff = event->pos().y() - lastPos.y(); // average to reduce the effect of spurious moves - velocityY += diff / elapsed; - velocityY /= 2; + vData.velocity += diff / elapsed; + vData.velocity /= 2; } if (q->xflick()) { qreal diff = event->pos().x() - lastPos.x(); // average to reduce the effect of spurious moves - velocityX += diff / elapsed; - velocityX /= 2; + hData.velocity += diff / elapsed; + hData.velocity /= 2; } } - if (rejectY) velocityY = 0; - if (rejectX) velocityX = 0; + if (rejectY) vData.velocity = 0; + if (rejectX) hData.velocity = 0; if (moved) { q->movementStarting(); @@ -759,13 +732,13 @@ void QDeclarativeFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEv if (QDeclarativeItemPrivate::elapsed(lastPosTime) > 100) { // if we drag then pause before release we should not cause a flick. - velocityX = 0.0; - velocityY = 0.0; + hData.velocity = 0.0; + vData.velocity = 0.0; } vTime = timeline.time(); - if (qAbs(velocityY) > 10 && qAbs(event->pos().y() - pressPos.y()) > FlickThreshold) { - qreal velocity = velocityY; + 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); @@ -773,8 +746,8 @@ void QDeclarativeFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEv fixupY(); } - if (qAbs(velocityX) > 10 && qAbs(event->pos().x() - pressPos.x()) > FlickThreshold) { - qreal velocity = velocityX; + 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); @@ -832,19 +805,19 @@ void QDeclarativeFlickable::wheelEvent(QGraphicsSceneWheelEvent *event) QDeclarativeItem::wheelEvent(event); } else if (yflick()) { if (event->delta() > 0) - d->velocityY = qMax(event->delta() - d->verticalVelocity.value(), qreal(250.0)); + d->vData.velocity = qMax(event->delta() - d->vData.smoothVelocity.value(), qreal(250.0)); else - d->velocityY = qMin(event->delta() - d->verticalVelocity.value(), qreal(-250.0)); + d->vData.velocity = qMin(event->delta() - d->vData.smoothVelocity.value(), qreal(-250.0)); d->flicked = false; - d->flickY(d->velocityY); + d->flickY(d->vData.velocity); event->accept(); } else if (xflick()) { if (event->delta() > 0) - d->velocityX = qMax(event->delta() - d->horizontalVelocity.value(), qreal(250.0)); + d->hData.velocity = qMax(event->delta() - d->hData.smoothVelocity.value(), qreal(250.0)); else - d->velocityX = qMin(event->delta() - d->horizontalVelocity.value(), qreal(-250.0)); + d->hData.velocity = qMin(event->delta() - d->hData.smoothVelocity.value(), qreal(-250.0)); d->flicked = false; - d->flickX(d->velocityX); + d->flickX(d->hData.velocity); event->accept(); } else { QDeclarativeItem::wheelEvent(event); @@ -946,32 +919,56 @@ void QDeclarativeFlickable::viewportMoved() qreal prevX = d->lastFlickablePosition.y(); d->velocityTimeline.clear(); if (d->pressed) { - qreal horizontalVelocity = (prevX - d->_moveX.value()) * 1000 / elapsed; - qreal verticalVelocity = (prevY - d->_moveY.value()) * 1000 / elapsed; - d->velocityTimeline.move(d->horizontalVelocity, horizontalVelocity, d->reportedVelocitySmoothing); - d->velocityTimeline.move(d->horizontalVelocity, 0, d->reportedVelocitySmoothing); - d->velocityTimeline.move(d->verticalVelocity, verticalVelocity, d->reportedVelocitySmoothing); - d->velocityTimeline.move(d->verticalVelocity, 0, d->reportedVelocitySmoothing); + qreal horizontalVelocity = (prevX - d->hData.move.value()) * 1000 / elapsed; + qreal verticalVelocity = (prevY - d->vData.move.value()) * 1000 / elapsed; + d->velocityTimeline.move(d->hData.smoothVelocity, horizontalVelocity, d->reportedVelocitySmoothing); + d->velocityTimeline.move(d->hData.smoothVelocity, 0, d->reportedVelocitySmoothing); + d->velocityTimeline.move(d->vData.smoothVelocity, verticalVelocity, d->reportedVelocitySmoothing); + d->velocityTimeline.move(d->vData.smoothVelocity, 0, d->reportedVelocitySmoothing); } else { if (d->timeline.time() > d->vTime) { - qreal horizontalVelocity = (prevX - d->_moveX.value()) * 1000 / (d->timeline.time() - d->vTime); - qreal verticalVelocity = (prevY - d->_moveY.value()) * 1000 / (d->timeline.time() - d->vTime); - d->horizontalVelocity.setValue(horizontalVelocity); - d->verticalVelocity.setValue(verticalVelocity); + qreal horizontalVelocity = (prevX - d->hData.move.value()) * 1000 / (d->timeline.time() - d->vTime); + qreal verticalVelocity = (prevY - d->vData.move.value()) * 1000 / (d->timeline.time() - d->vTime); + d->hData.smoothVelocity.setValue(horizontalVelocity); + d->vData.smoothVelocity.setValue(verticalVelocity); } } - d->lastFlickablePosition = QPointF(d->_moveY.value(), d->_moveX.value()); + d->lastFlickablePosition = QPointF(d->vData.move.value(), d->hData.move.value()); d->vTime = d->timeline.time(); d->updateBeginningEnd(); } +void QDeclarativeFlickable::geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry) +{ + Q_D(QDeclarativeFlickable); + QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); + + bool changed = false; + if (newGeometry.width() != oldGeometry.width()) { + if (d->hData.viewSize < 0) { + d->viewport->setWidth(width()); + emit contentWidthChanged(); + } + } + if (newGeometry.height() != oldGeometry.height()) { + if (d->vData.viewSize < 0) { + d->viewport->setHeight(height()); + emit contentHeightChanged(); + } + } + + if (changed) + d->updateBeginningEnd(); +} + void QDeclarativeFlickable::cancelFlick() { Q_D(QDeclarativeFlickable); - d->timeline.reset(d->_moveX); - d->timeline.reset(d->_moveY); + d->timeline.reset(d->hData.move); + d->timeline.reset(d->vData.move); movementEnding(); } @@ -1038,15 +1035,15 @@ void QDeclarativeFlickable::setOverShoot(bool o) qreal QDeclarativeFlickable::contentWidth() const { Q_D(const QDeclarativeFlickable); - return d->vWidth; + return d->hData.viewSize; } void QDeclarativeFlickable::setContentWidth(qreal w) { Q_D(QDeclarativeFlickable); - if (d->vWidth == w) + if (d->hData.viewSize == w) return; - d->vWidth = w; + d->hData.viewSize = w; if (w < 0) d->viewport->setWidth(width()); else @@ -1058,38 +1055,18 @@ void QDeclarativeFlickable::setContentWidth(qreal w) d->updateBeginningEnd(); } -void QDeclarativeFlickable::widthChange() -{ - Q_D(QDeclarativeFlickable); - if (d->vWidth < 0) { - d->viewport->setWidth(width()); - emit contentWidthChanged(); - } - d->updateBeginningEnd(); -} - -void QDeclarativeFlickable::heightChange() -{ - Q_D(QDeclarativeFlickable); - if (d->vHeight < 0) { - d->viewport->setHeight(height()); - emit contentHeightChanged(); - } - d->updateBeginningEnd(); -} - qreal QDeclarativeFlickable::contentHeight() const { Q_D(const QDeclarativeFlickable); - return d->vHeight; + return d->vData.viewSize; } void QDeclarativeFlickable::setContentHeight(qreal h) { Q_D(QDeclarativeFlickable); - if (d->vHeight == h) + if (d->vData.viewSize == h) return; - d->vHeight = h; + d->vData.viewSize = h; if (h < 0) d->viewport->setHeight(height()); else @@ -1104,19 +1081,19 @@ void QDeclarativeFlickable::setContentHeight(qreal h) qreal QDeclarativeFlickable::vWidth() const { Q_D(const QDeclarativeFlickable); - if (d->vWidth < 0) + if (d->hData.viewSize < 0) return width(); else - return d->vWidth; + return d->hData.viewSize; } qreal QDeclarativeFlickable::vHeight() const { Q_D(const QDeclarativeFlickable); - if (d->vHeight < 0) + if (d->vData.viewSize < 0) return height(); else - return d->vHeight; + return d->vData.viewSize; } bool QDeclarativeFlickable::xflick() const @@ -1327,8 +1304,8 @@ void QDeclarativeFlickable::movementEnding() emit flickingChanged(); emit flickEnded(); } - d->horizontalVelocity.setValue(0); - d->verticalVelocity.setValue(0); + d->hData.smoothVelocity.setValue(0); + d->vData.smoothVelocity.setValue(0); } void QDeclarativeFlickablePrivate::updateVelocity() diff --git a/src/declarative/graphicsitems/qdeclarativeflickable_p.h b/src/declarative/graphicsitems/qdeclarativeflickable_p.h index 4617688..7dcab98 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable_p.h +++ b/src/declarative/graphicsitems/qdeclarativeflickable_p.h @@ -174,8 +174,6 @@ protected Q_SLOTS: virtual void ticked(); void movementStarting(); void movementEnding(); - void heightChange(); - void widthChange(); protected: virtual qreal minXExtent() const; @@ -185,6 +183,8 @@ protected: qreal vWidth() const; qreal vHeight() const; virtual void viewportMoved(); + virtual void geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry); bool sendMouseEvent(QGraphicsSceneMouseEvent *event); bool xflick() const; diff --git a/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h b/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h index ad7a04d..c963c2b 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h @@ -56,6 +56,7 @@ #include "qdeclarativeflickable_p.h" #include "qdeclarativeitem_p.h" +#include "qdeclarativeitemchangelistener_p.h" #include #include @@ -66,17 +67,51 @@ QT_BEGIN_NAMESPACE class QDeclarativeFlickableVisibleArea; -class QDeclarativeFlickablePrivate : public QDeclarativeItemPrivate +class QDeclarativeFlickablePrivate : public QDeclarativeItemPrivate, public QDeclarativeItemChangeListener { Q_DECLARE_PUBLIC(QDeclarativeFlickable) public: QDeclarativeFlickablePrivate(); void init(); - virtual void flickX(qreal velocity); - virtual void flickY(qreal velocity); - virtual void fixupX(); - virtual void fixupY(); + + struct Velocity : public QDeclarativeTimeLineValue + { + Velocity(QDeclarativeFlickablePrivate *p) + : parent(p) {} + virtual void setValue(qreal v) { + if (v != value()) { + QDeclarativeTimeLineValue::setValue(v); + parent->updateVelocity(); + } + } + QDeclarativeFlickablePrivate *parent; + }; + + struct AxisData { + AxisData(QDeclarativeFlickablePrivate *fp, void (QDeclarativeFlickablePrivate::*func)(qreal)) + : move(fp, func), viewSize(-1), smoothVelocity(fp), atEnd(false), atBeginning(true) + {} + + QDeclarativeTimeLineValueProxy move; + qreal viewSize; + qreal pressPos; + qreal velocity; + qreal flickTarget; + QDeclarativeFlickablePrivate::Velocity smoothVelocity; + bool atEnd : 1; + bool atBeginning : 1; + }; + + void flickX(qreal velocity); + void flickY(qreal velocity); + virtual void flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize, + QDeclarativeTimeLineCallback::Callback fixupCallback, qreal velocity); + + void fixupX(); + void fixupY(); + virtual void fixup(AxisData &data, qreal minExtent, qreal maxExtent); + void updateBeginningEnd(); void captureDelayedPress(QGraphicsSceneMouseEvent *event); @@ -87,38 +122,30 @@ public: qreal overShootDistance(qreal velocity, qreal size); + void itemGeometryChanged(QDeclarativeItem *, const QRectF &, const QRectF &); + public: QDeclarativeItem *viewport; - QDeclarativeTimeLineValueProxy _moveX; - QDeclarativeTimeLineValueProxy _moveY; + + AxisData hData; + AxisData vData; + QDeclarativeTimeLine timeline; - qreal vWidth; - qreal vHeight; bool overShoot : 1; bool flicked : 1; bool moving : 1; bool stealMouse : 1; bool pressed : 1; - bool atXEnd : 1; - bool atXBeginning : 1; - bool atYEnd : 1; - bool atYBeginning : 1; bool interactive : 1; QTime lastPosTime; QPointF lastPos; QPointF pressPos; - qreal pressX; - qreal pressY; - qreal velocityX; - qreal velocityY; QTime pressTime; qreal deceleration; qreal maxVelocity; QTime velocityTime; QPointF lastFlickablePosition; qreal reportedVelocitySmoothing; - qreal flickTargetX; - qreal flickTargetY; QGraphicsSceneMouseEvent *delayedPressEvent; QGraphicsItem *delayedPressTarget; QBasicTimer delayedPressTimer; @@ -129,20 +156,6 @@ public: static void fixupX_callback(void *); void updateVelocity(); - struct Velocity : public QDeclarativeTimeLineValue - { - Velocity(QDeclarativeFlickablePrivate *p) - : parent(p) {} - virtual void setValue(qreal v) { - if (v != value()) { - QDeclarativeTimeLineValue::setValue(v); - parent->updateVelocity(); - } - } - QDeclarativeFlickablePrivate *parent; - }; - Velocity horizontalVelocity; - Velocity verticalVelocity; int vTime; QDeclarativeTimeLine velocityTimeline; QDeclarativeFlickableVisibleArea *visibleArea; diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index 463b238..76ad9b7 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -236,6 +236,19 @@ public: return -1; // Not in visibleList } + void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) { + Q_Q(const QDeclarativeGridView); + QDeclarativeFlickablePrivate::itemGeometryChanged(item, newGeometry, oldGeometry); + if (item == q) { + if (newGeometry.height() != oldGeometry.height() + || newGeometry.width() != oldGeometry.width()) { + if (q->isComponentComplete()) { + updateGrid(); + layout(); + } + } + } + } // for debugging only void checkVisible() const { int skip = 0; @@ -288,9 +301,8 @@ void QDeclarativeGridViewPrivate::init() { Q_Q(QDeclarativeGridView); q->setFlag(QGraphicsItem::ItemIsFocusScope); - QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(sizeChange())); - QObject::connect(q, SIGNAL(heightChanged()), q, SLOT(sizeChange())); q->setFlickDirection(QDeclarativeFlickable::VerticalFlick); + addItemChangeListener(this, Geometry); } void QDeclarativeGridViewPrivate::clear() @@ -1142,15 +1154,6 @@ void QDeclarativeGridView::setCellHeight(int cellHeight) } } -void QDeclarativeGridView::sizeChange() -{ - Q_D(QDeclarativeGridView); - if (isComponentComplete()) { - d->updateGrid(); - d->layout(); - } -} - void QDeclarativeGridView::viewportMoved() { Q_D(QDeclarativeGridView); @@ -1158,16 +1161,16 @@ void QDeclarativeGridView::viewportMoved() d->lazyRelease = true; if (d->flicked) { if (yflick()) { - if (d->velocityY > 0) + if (d->vData.velocity > 0) d->bufferMode = QDeclarativeGridViewPrivate::BufferBefore; - else if (d->velocityY < 0) + else if (d->vData.velocity < 0) d->bufferMode = QDeclarativeGridViewPrivate::BufferAfter; } if (xflick()) { - if (d->velocityX > 0) + if (d->hData.velocity > 0) d->bufferMode = QDeclarativeGridViewPrivate::BufferBefore; - else if (d->velocityX < 0) + else if (d->hData.velocity < 0) d->bufferMode = QDeclarativeGridViewPrivate::BufferAfter; } } diff --git a/src/declarative/graphicsitems/qdeclarativegridview_p.h b/src/declarative/graphicsitems/qdeclarativegridview_p.h index 22fcef6..7255d3d 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview_p.h +++ b/src/declarative/graphicsitems/qdeclarativegridview_p.h @@ -154,7 +154,6 @@ private Q_SLOTS: void destroyRemoved(); void createdItem(int index, QDeclarativeItem *item); void destroyingItem(QDeclarativeItem *item); - void sizeChange(); void layout(); private: diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index cd8d143..d54bb70 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -139,7 +139,7 @@ public: //---------------------------------------------------------------------------- -class QDeclarativeListViewPrivate : public QDeclarativeFlickablePrivate, private QDeclarativeItemChangeListener +class QDeclarativeListViewPrivate : public QDeclarativeFlickablePrivate { Q_DECLARE_PUBLIC(QDeclarativeListView) @@ -389,11 +389,14 @@ public: } } - void itemGeometryChanged(QDeclarativeItem *, const QRectF &newGeometry, const QRectF &oldGeometry) { - if ((orient == QDeclarativeListView::Vertical && newGeometry.height() != oldGeometry.height()) - || newGeometry.width() != oldGeometry.width()) { - layout(); - fixupPosition(); + void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) { + QDeclarativeFlickablePrivate::itemGeometryChanged(item, newGeometry, oldGeometry); + if (item != viewport) { + if ((orient == QDeclarativeListView::Vertical && newGeometry.height() != oldGeometry.height()) + || newGeometry.width() != oldGeometry.width()) { + layout(); + fixupPosition(); + } } } @@ -425,10 +428,9 @@ public: void updateHeader(); void updateFooter(); void fixupPosition(); - virtual void fixupY(); - virtual void fixupX(); - virtual void flickX(qreal velocity); - virtual void flickY(qreal velocity); + virtual void fixup(AxisData &data, qreal minExtent, qreal maxExtent); + virtual void flick(QDeclarativeFlickablePrivate::AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize, + QDeclarativeTimeLineCallback::Callback fixupCallback, qreal velocity); QDeclarativeGuard model; QVariant modelVariant; @@ -1061,52 +1063,16 @@ void QDeclarativeListViewPrivate::fixupPosition() fixupX(); } -void QDeclarativeListViewPrivate::fixupY() +void QDeclarativeListViewPrivate::fixup(AxisData &data, qreal minExtent, qreal maxExtent) { Q_Q(QDeclarativeListView); - if (orient == QDeclarativeListView::Horizontal) - return; - if (!q->yflick() || _moveY.timeLine()) + if ((orient == QDeclarativeListView::Horizontal && &data == &vData) + || (orient == QDeclarativeListView::Vertical && &data == &hData)) return; - int oldDuration = fixupDuration; - fixupDuration = moveReason == Mouse ? fixupDuration : 0; - - if (haveHighlightRange && highlightRange == QDeclarativeListView::StrictlyEnforceRange) { - if (currentItem && currentItem->position() - position() != highlightRangeStart) { - qreal pos = currentItem->position() - highlightRangeStart; - timeline.reset(_moveY); - if (fixupDuration) - timeline.move(_moveY, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2); - else - _moveY.setValue(-pos); - vTime = timeline.time(); - } - } else if (snapMode != QDeclarativeListView::NoSnap) { - if (FxListItem *item = snapItemAt(position())) { - qreal pos = qMin(item->position() - highlightRangeStart, -q->maxYExtent()); - qreal dist = qAbs(_moveY + pos); - if (dist > 0) { - timeline.reset(_moveY); - if (fixupDuration) - timeline.move(_moveY, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2); - else - _moveY.setValue(-pos); - vTime = timeline.time(); - } - } - } else { - QDeclarativeFlickablePrivate::fixupY(); - } - fixupDuration = oldDuration; -} - -void QDeclarativeListViewPrivate::fixupX() -{ - Q_Q(QDeclarativeListView); - if (orient == QDeclarativeListView::Vertical) - return; - if (!q->xflick() || _moveX.timeLine()) + if ((&data == &vData && !q->yflick()) + || (&data == &hData && !q->xflick()) + || data.move.timeLine()) return; int oldDuration = fixupDuration; @@ -1115,161 +1081,62 @@ void QDeclarativeListViewPrivate::fixupX() if (haveHighlightRange && highlightRange == QDeclarativeListView::StrictlyEnforceRange) { if (currentItem && currentItem->position() - position() != highlightRangeStart) { qreal pos = currentItem->position() - highlightRangeStart; - timeline.reset(_moveX); + timeline.reset(data.move); if (fixupDuration) - timeline.move(_moveX, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration); + timeline.move(data.move, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2); else - _moveX.setValue(-pos); + data.move.setValue(-pos); vTime = timeline.time(); } } else if (snapMode != QDeclarativeListView::NoSnap) { if (FxListItem *item = snapItemAt(position())) { - qreal pos = qMin(item->position() - highlightRangeStart, -q->maxXExtent()); - qreal dist = qAbs(_moveX + pos); + qreal pos = qMin(item->position() - highlightRangeStart, -maxExtent); + qreal dist = qAbs(data.move + pos); if (dist > 0) { - timeline.reset(_moveX); + timeline.reset(data.move); if (fixupDuration) - timeline.move(_moveX, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration); + timeline.move(data.move, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2); else - _moveX.setValue(-pos); + data.move.setValue(-pos); vTime = timeline.time(); } } } else { - QDeclarativeFlickablePrivate::fixupX(); + QDeclarativeFlickablePrivate::fixup(data, minExtent, maxExtent); } fixupDuration = oldDuration; } -void QDeclarativeListViewPrivate::flickX(qreal velocity) -{ - Q_Q(QDeclarativeListView); - - moveReason = Mouse; - if ((!haveHighlightRange || highlightRange != QDeclarativeListView::StrictlyEnforceRange) && snapMode == QDeclarativeListView::NoSnap) { - QDeclarativeFlickablePrivate::flickX(velocity); - return; - } - qreal maxDistance = -1; - const qreal maxX = q->maxXExtent(); - const qreal minX = q->minXExtent(); - // -ve velocity means list is moving up - if (velocity > 0) { - if (snapMode == QDeclarativeListView::SnapOneItem) { - if (FxListItem *item = firstVisibleItem()) - maxDistance = qAbs(item->position() + _moveX.value()); - } else if (_moveX.value() < minX) { - maxDistance = qAbs(minX -_moveX.value() + (overShoot?overShootDistance(velocity, q->width()):0)); - } - if (snapMode != QDeclarativeListView::SnapToItem && highlightRange != QDeclarativeListView::StrictlyEnforceRange) - flickTargetX = minX; - } else { - if (snapMode == QDeclarativeListView::SnapOneItem) { - if (FxListItem *item = nextVisibleItem()) - maxDistance = qAbs(item->position() + _moveX.value()); - } else if (_moveX.value() > maxX) { - maxDistance = qAbs(maxX - _moveX.value()) + (overShoot?overShootDistance(velocity, q->width()):0); - } - if (snapMode != QDeclarativeListView::SnapToItem && highlightRange != QDeclarativeListView::StrictlyEnforceRange) - flickTargetX = maxX; - } - if (maxDistance > 0 && (snapMode != QDeclarativeListView::NoSnap || highlightRange == QDeclarativeListView::StrictlyEnforceRange)) { - // These modes require the list to stop exactly on an item boundary. - // The initial flick will estimate the boundary to stop on. - // Since list items can have variable sizes, the boundary will be - // reevaluated and adjusted as we approach the boundary. - qreal v = velocity; - if (maxVelocity != -1 && maxVelocity < qAbs(v)) { - if (v < 0) - v = -maxVelocity; - else - v = maxVelocity; - } - if (!flicked) { - // the initial flick - estimate boundary - qreal accel = deceleration; - qreal v2 = v * v; - qreal maxAccel = v2 / (2.0f * maxDistance); - if (maxAccel < accel) { - qreal dist = v2 / (accel * 2.0); - if (v > 0) - dist = -dist; - flickTargetX = -snapPosAt(-(_moveX.value() - highlightRangeStart) + dist) + highlightRangeStart; - dist = -flickTargetX + _moveX.value(); - accel = v2 / (2.0f * qAbs(dist)); - overshootDist = 0.0; - } else { - flickTargetX = velocity > 0 ? minX : maxX; - overshootDist = overShoot ? overShootDistance(v, q->width()) : 0; - } - timeline.reset(_moveX); - timeline.accel(_moveX, v, accel, maxDistance + overshootDist); - timeline.callback(QDeclarativeTimeLineCallback(&_moveX, fixupX_callback, this)); - flicked = true; - emit q->flickingChanged(); - emit q->flickStarted(); - correctFlick = true; - } else { - // reevaluate the target boundary. - qreal newtarget = flickTargetX; - if (snapMode != QDeclarativeListView::NoSnap || highlightRange == QDeclarativeListView::StrictlyEnforceRange) - newtarget = -snapPosAt(-(flickTargetX - highlightRangeStart)) + highlightRangeStart; - if (velocity < 0 && newtarget < maxX) - newtarget = maxX; - else if (velocity > 0 && newtarget > minX) - newtarget = minX; - if (newtarget == flickTargetX) // boundary unchanged - nothing to do - return; - flickTargetX = newtarget; - qreal dist = -newtarget + _moveX.value(); - if ((v < 0 && dist < 0) || (v > 0 && dist > 0)) { - correctFlick = false; - timeline.reset(_moveX); - fixupX(); - return; - } - timeline.reset(_moveX); - timeline.accelDistance(_moveX, v, -dist + (v < 0 ? -overshootDist : overshootDist)); - timeline.callback(QDeclarativeTimeLineCallback(&_moveX, fixupX_callback, this)); - } - } else { - correctFlick = false; - timeline.reset(_moveX); - fixupX(); - } -} - -void QDeclarativeListViewPrivate::flickY(qreal velocity) +void QDeclarativeListViewPrivate::flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize, + QDeclarativeTimeLineCallback::Callback fixupCallback, qreal velocity) { Q_Q(QDeclarativeListView); moveReason = Mouse; if ((!haveHighlightRange || highlightRange != QDeclarativeListView::StrictlyEnforceRange) && snapMode == QDeclarativeListView::NoSnap) { - QDeclarativeFlickablePrivate::flickY(velocity); + QDeclarativeFlickablePrivate::flick(data, minExtent, maxExtent, vSize, fixupCallback, velocity); return; } qreal maxDistance = -1; - const qreal maxY = q->maxYExtent(); - const qreal minY = q->minYExtent(); // -ve velocity means list is moving up if (velocity > 0) { if (snapMode == QDeclarativeListView::SnapOneItem) { if (FxListItem *item = firstVisibleItem()) - maxDistance = qAbs(item->position() + _moveY.value()); - } else if (_moveY.value() < minY) { - maxDistance = qAbs(minY -_moveY.value() + (overShoot?overShootDistance(velocity, q->height()):0)); + maxDistance = qAbs(item->position() + data.move.value()); + } else if (data.move.value() < minExtent) { + maxDistance = qAbs(minExtent - data.move.value() + (overShoot?overShootDistance(velocity, vSize):0)); } if (snapMode != QDeclarativeListView::SnapToItem && highlightRange != QDeclarativeListView::StrictlyEnforceRange) - flickTargetY = minY; + data.flickTarget = minExtent; } else { if (snapMode == QDeclarativeListView::SnapOneItem) { if (FxListItem *item = nextVisibleItem()) - maxDistance = qAbs(item->position() + _moveY.value()); - } else if (_moveY.value() > maxY) { - maxDistance = qAbs(maxY - _moveY.value()) + (overShoot?overShootDistance(velocity, q->height()):0); + maxDistance = qAbs(item->position() + data.move.value()); + } else if (data.move.value() > maxExtent) { + maxDistance = qAbs(maxExtent - data.move.value()) + (overShoot?overShootDistance(velocity, vSize):0); } if (snapMode != QDeclarativeListView::SnapToItem && highlightRange != QDeclarativeListView::StrictlyEnforceRange) - flickTargetY = maxY; + data.flickTarget = maxExtent; } if (maxDistance > 0 && (snapMode != QDeclarativeListView::NoSnap || highlightRange == QDeclarativeListView::StrictlyEnforceRange)) { // These modes require the list to stop exactly on an item boundary. @@ -1292,48 +1159,48 @@ void QDeclarativeListViewPrivate::flickY(qreal velocity) qreal dist = v2 / (accel * 2.0); if (v > 0) dist = -dist; - flickTargetY = -snapPosAt(-(_moveY.value() - highlightRangeStart) + dist) + highlightRangeStart; - dist = -flickTargetY + _moveY.value(); + data.flickTarget = -snapPosAt(-(data.move.value() - highlightRangeStart) + dist) + highlightRangeStart; + dist = -data.flickTarget + data.move.value(); accel = v2 / (2.0f * qAbs(dist)); overshootDist = 0.0; } else { - flickTargetY = velocity > 0 ? minY : maxY; - overshootDist = overShoot ? overShootDistance(v, q->height()) : 0; + data.flickTarget = velocity > 0 ? minExtent : maxExtent; + overshootDist = overShoot ? overShootDistance(v, vSize) : 0; } - timeline.reset(_moveY); - timeline.accel(_moveY, v, accel, maxDistance + overshootDist); - timeline.callback(QDeclarativeTimeLineCallback(&_moveY, fixupY_callback, this)); + timeline.reset(data.move); + timeline.accel(data.move, v, accel, maxDistance + overshootDist); + timeline.callback(QDeclarativeTimeLineCallback(&data.move, fixupCallback, this)); flicked = true; emit q->flickingChanged(); emit q->flickStarted(); correctFlick = true; } else { // reevaluate the target boundary. - qreal newtarget = flickTargetY; + qreal newtarget = data.flickTarget; if (snapMode != QDeclarativeListView::NoSnap || highlightRange == QDeclarativeListView::StrictlyEnforceRange) - newtarget = -snapPosAt(-(flickTargetY - highlightRangeStart)) + highlightRangeStart; - if (velocity < 0 && newtarget < maxY) - newtarget = maxY; - else if (velocity > 0 && newtarget > minY) - newtarget = minY; - if (newtarget == flickTargetY) // boundary unchanged - nothing to do + newtarget = -snapPosAt(-(data.flickTarget - highlightRangeStart)) + highlightRangeStart; + if (velocity < 0 && newtarget < maxExtent) + newtarget = maxExtent; + else if (velocity > 0 && newtarget > minExtent) + newtarget = minExtent; + if (newtarget == data.flickTarget) // boundary unchanged - nothing to do return; - flickTargetY = newtarget; - qreal dist = -newtarget + _moveY.value(); + data.flickTarget = newtarget; + qreal dist = -newtarget + data.move.value(); if ((v < 0 && dist < 0) || (v > 0 && dist > 0)) { correctFlick = false; - timeline.reset(_moveY); - fixupY(); + timeline.reset(data.move); + fixup(data, minExtent, maxExtent); return; } - timeline.reset(_moveY); - timeline.accelDistance(_moveY, v, -dist + (v < 0 ? -overshootDist : overshootDist)); - timeline.callback(QDeclarativeTimeLineCallback(&_moveY, fixupY_callback, this)); + timeline.reset(data.move); + timeline.accelDistance(data.move, v, -dist + (v < 0 ? -overshootDist : overshootDist)); + timeline.callback(QDeclarativeTimeLineCallback(&data.move, fixupCallback, this)); } } else { correctFlick = false; - timeline.reset(_moveY); - fixupY(); + timeline.reset(data.move); + fixup(data, minExtent, maxExtent); } } @@ -2107,33 +1974,33 @@ void QDeclarativeListView::viewportMoved() // Near an end and it seems that the extent has changed? // Recalculate the flick so that we don't end up in an odd position. if (yflick()) { - if (d->velocityY > 0) { + if (d->vData.velocity > 0) { const qreal minY = minYExtent(); - if ((minY - d->_moveY.value() < height()/2 || d->flickTargetY - d->_moveY.value() < height()/2) - && minY != d->flickTargetY) - d->flickY(-d->verticalVelocity.value()); + if ((minY - d->vData.move.value() < height()/2 || d->vData.flickTarget - d->vData.move.value() < height()/2) + && minY != d->vData.flickTarget) + d->flickY(-d->vData.smoothVelocity.value()); d->bufferMode = QDeclarativeListViewPrivate::BufferBefore; - } else if (d->velocityY < 0) { + } else if (d->vData.velocity < 0) { const qreal maxY = maxYExtent(); - if ((d->_moveY.value() - maxY < height()/2 || d->_moveY.value() - d->flickTargetY < height()/2) - && maxY != d->flickTargetY) - d->flickY(-d->verticalVelocity.value()); + if ((d->vData.move.value() - maxY < height()/2 || d->vData.move.value() - d->vData.flickTarget < height()/2) + && maxY != d->vData.flickTarget) + d->flickY(-d->vData.smoothVelocity.value()); d->bufferMode = QDeclarativeListViewPrivate::BufferAfter; } } if (xflick()) { - if (d->velocityX > 0) { + if (d->hData.velocity > 0) { const qreal minX = minXExtent(); - if ((minX - d->_moveX.value() < height()/2 || d->flickTargetX - d->_moveX.value() < height()/2) - && minX != d->flickTargetX) - d->flickX(-d->horizontalVelocity.value()); + if ((minX - d->hData.move.value() < width()/2 || d->hData.flickTarget - d->hData.move.value() < width()/2) + && minX != d->hData.flickTarget) + d->flickX(-d->hData.smoothVelocity.value()); d->bufferMode = QDeclarativeListViewPrivate::BufferBefore; - } else if (d->velocityX < 0) { + } else if (d->hData.velocity < 0) { const qreal maxX = maxXExtent(); - if ((d->_moveX.value() - maxX < height()/2 || d->_moveX.value() - d->flickTargetX < height()/2) - && maxX != d->flickTargetX) - d->flickX(-d->horizontalVelocity.value()); + if ((d->hData.move.value() - maxX < width()/2 || d->hData.move.value() - d->hData.flickTarget < width()/2) + && maxX != d->hData.flickTarget) + d->flickX(-d->hData.smoothVelocity.value()); d->bufferMode = QDeclarativeListViewPrivate::BufferAfter; } } diff --git a/src/declarative/graphicsitems/qdeclarativelistview_p.h b/src/declarative/graphicsitems/qdeclarativelistview_p.h index f9b7b50..d66ac2b 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview_p.h +++ b/src/declarative/graphicsitems/qdeclarativelistview_p.h @@ -300,10 +300,10 @@ Q_SIGNALS: public: QDeclarativeListView *m_view; - bool m_isCurrent; mutable QString m_section; QString m_prevSection; - bool m_delayRemove; + bool m_isCurrent : 1; + bool m_delayRemove : 1; }; -- cgit v0.12 From 69a3c7fc51fcab07a6a0a18a753546b45cf522c3 Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Mon, 8 Mar 2010 12:36:12 +1000 Subject: Fixed declarative examples not being installed. --- examples/declarative/declarative.pro | 48 ++++++++++++++++++++++ examples/declarative/extending/adding/adding.pro | 4 ++ .../declarative/extending/attached/attached.pro | 4 ++ examples/declarative/extending/binding/binding.pro | 4 ++ .../declarative/extending/coercion/coercion.pro | 4 ++ examples/declarative/extending/default/default.pro | 4 ++ .../declarative/extending/extended/extended.pro | 4 ++ examples/declarative/extending/grouped/grouped.pro | 4 ++ .../extending/properties/properties.pro | 5 +++ examples/declarative/extending/signal/signal.pro | 4 ++ .../extending/valuesource/valuesource.pro | 4 ++ .../declarative/imageprovider/imageprovider.pro | 10 +++++ .../objectlistmodel/objectlistmodel.pro | 7 ++++ examples/declarative/plugins/plugins.pro | 2 +- 14 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 examples/declarative/declarative.pro diff --git a/examples/declarative/declarative.pro b/examples/declarative/declarative.pro new file mode 100644 index 0000000..b8c0200 --- /dev/null +++ b/examples/declarative/declarative.pro @@ -0,0 +1,48 @@ +TEMPLATE = subdirs + +# These examples contain some C++ and need to be built +SUBDIRS = \ + extending \ + imageprovider \ + objectlistmodel \ + plugins + +# These examples contain no C++ and can simply be copied +sources.files = \ + animations \ + aspectratio \ + behaviours \ + border-image \ + clocks \ + colorbrowser \ + connections \ + dial \ + dynamic \ + effects \ + fillmode \ + focusscope \ + fonts \ + gridview \ + layouts \ + listview \ + mousearea \ + package \ + parallax \ + progressbar \ + scrollbar \ + searchbox \ + slideswitch \ + sql \ + states \ + tabwidget \ + tic-tac-toe \ + tutorials \ + tvtennis \ + velocity \ + webview \ + workerlistmodel \ + workerscript \ + xmldata \ + xmlhttprequest +sources.path = $$[QT_INSTALL_EXAMPLES]/declarative +INSTALLS += sources diff --git a/examples/declarative/extending/adding/adding.pro b/examples/declarative/extending/adding/adding.pro index c02a35f..6072de4 100644 --- a/examples/declarative/extending/adding/adding.pro +++ b/examples/declarative/extending/adding/adding.pro @@ -9,3 +9,7 @@ SOURCES += main.cpp \ person.cpp HEADERS += person.h RESOURCES += adding.qrc +target.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/adding +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS adding.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/adding +INSTALLS += target sources diff --git a/examples/declarative/extending/attached/attached.pro b/examples/declarative/extending/attached/attached.pro index b0f3fea..f6d76ed 100644 --- a/examples/declarative/extending/attached/attached.pro +++ b/examples/declarative/extending/attached/attached.pro @@ -11,3 +11,7 @@ SOURCES += main.cpp \ HEADERS += person.h \ birthdayparty.h RESOURCES += attached.qrc +target.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/attached +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS attached.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/attached +INSTALLS += target sources diff --git a/examples/declarative/extending/binding/binding.pro b/examples/declarative/extending/binding/binding.pro index 8298565..903712e 100644 --- a/examples/declarative/extending/binding/binding.pro +++ b/examples/declarative/extending/binding/binding.pro @@ -13,3 +13,7 @@ HEADERS += person.h \ birthdayparty.h \ happybirthday.h RESOURCES += binding.qrc +target.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/binding +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS binding.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/binding +INSTALLS += target sources diff --git a/examples/declarative/extending/coercion/coercion.pro b/examples/declarative/extending/coercion/coercion.pro index 136b210..c8daed8 100644 --- a/examples/declarative/extending/coercion/coercion.pro +++ b/examples/declarative/extending/coercion/coercion.pro @@ -11,3 +11,7 @@ SOURCES += main.cpp \ HEADERS += person.h \ birthdayparty.h RESOURCES += coercion.qrc +target.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/coercion +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS coercion.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/coercion +INSTALLS += target sources diff --git a/examples/declarative/extending/default/default.pro b/examples/declarative/extending/default/default.pro index 0d5d45c..32aff0b 100644 --- a/examples/declarative/extending/default/default.pro +++ b/examples/declarative/extending/default/default.pro @@ -11,3 +11,7 @@ SOURCES += main.cpp \ HEADERS += person.h \ birthdayparty.h RESOURCES += default.qrc +target.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/default +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS default.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/default +INSTALLS += target sources diff --git a/examples/declarative/extending/extended/extended.pro b/examples/declarative/extending/extended/extended.pro index 1182226..97af286 100644 --- a/examples/declarative/extending/extended/extended.pro +++ b/examples/declarative/extending/extended/extended.pro @@ -9,3 +9,7 @@ SOURCES += main.cpp \ lineedit.cpp HEADERS += lineedit.h RESOURCES += extended.qrc +target.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/extended +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS extended.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/extended +INSTALLS += target sources diff --git a/examples/declarative/extending/grouped/grouped.pro b/examples/declarative/extending/grouped/grouped.pro index 8fde8e8..576e1d2 100644 --- a/examples/declarative/extending/grouped/grouped.pro +++ b/examples/declarative/extending/grouped/grouped.pro @@ -11,3 +11,7 @@ SOURCES += main.cpp \ HEADERS += person.h \ birthdayparty.h RESOURCES += grouped.qrc +target.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/grouped +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS grouped.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/grouped +INSTALLS += target sources diff --git a/examples/declarative/extending/properties/properties.pro b/examples/declarative/extending/properties/properties.pro index 6355644..a8f4301 100644 --- a/examples/declarative/extending/properties/properties.pro +++ b/examples/declarative/extending/properties/properties.pro @@ -11,3 +11,8 @@ SOURCES += main.cpp \ HEADERS += person.h \ birthdayparty.h RESOURCES += properties.qrc + +target.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/properties +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS properties.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/properties +INSTALLS += target sources diff --git a/examples/declarative/extending/signal/signal.pro b/examples/declarative/extending/signal/signal.pro index 30e413f..6367a38 100644 --- a/examples/declarative/extending/signal/signal.pro +++ b/examples/declarative/extending/signal/signal.pro @@ -11,3 +11,7 @@ SOURCES += main.cpp \ HEADERS += person.h \ birthdayparty.h RESOURCES += signal.qrc +target.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/signal +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS signal.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/signal +INSTALLS += target sources diff --git a/examples/declarative/extending/valuesource/valuesource.pro b/examples/declarative/extending/valuesource/valuesource.pro index 9e54448..d3409b6 100644 --- a/examples/declarative/extending/valuesource/valuesource.pro +++ b/examples/declarative/extending/valuesource/valuesource.pro @@ -13,3 +13,7 @@ HEADERS += person.h \ birthdayparty.h \ happybirthday.h RESOURCES += valuesource.qrc +target.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/valuesource +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS valuesource.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/valuesource +INSTALLS += target sources diff --git a/examples/declarative/imageprovider/imageprovider.pro b/examples/declarative/imageprovider/imageprovider.pro index e403bf8..86dbcca 100644 --- a/examples/declarative/imageprovider/imageprovider.pro +++ b/examples/declarative/imageprovider/imageprovider.pro @@ -9,3 +9,13 @@ DESTDIR = ImageProviderCore # Input SOURCES += imageprovider.cpp +sources.files = $$SOURCES imageprovider.qml imageprovider.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/imageprovider + +target.path = $$[QT_INSTALL_EXAMPLES]/declarative/imageprovider/ImageProviderCore + +ImageProviderCore_sources.files = \ + ImageProviderCore/qmldir +ImageProviderCore_sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/imageprovider/ImageProviderCore + +INSTALLS = sources ImageProviderCore_sources target diff --git a/examples/declarative/objectlistmodel/objectlistmodel.pro b/examples/declarative/objectlistmodel/objectlistmodel.pro index ca61e4c..869cde3 100644 --- a/examples/declarative/objectlistmodel/objectlistmodel.pro +++ b/examples/declarative/objectlistmodel/objectlistmodel.pro @@ -9,3 +9,10 @@ SOURCES += main.cpp \ dataobject.cpp HEADERS += dataobject.h RESOURCES += objectlistmodel.qrc + +sources.files = $$SOURCES $$HEADERS $$RESOURCES objectlistmodel.pro view.qml +sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/objectlistmodel +target.path = $$[QT_INSTALL_EXAMPLES]/declarative/objectlistmodel + +INSTALLS += sources target + diff --git a/examples/declarative/plugins/plugins.pro b/examples/declarative/plugins/plugins.pro index c925cea..877a5ce 100644 --- a/examples/declarative/plugins/plugins.pro +++ b/examples/declarative/plugins/plugins.pro @@ -17,7 +17,7 @@ qdeclarativesources.files += \ qdeclarativesources.path += $$[QT_INSTALL_EXAMPLES]/declarative/plugins/com/nokia/TimeExample -sources.files += plugins.pro plugin.cpp plugins.qml +sources.files += plugins.pro plugin.cpp plugins.qml README sources.path += $$[QT_INSTALL_EXAMPLES]/declarative/plugins target.path += $$[QT_INSTALL_EXAMPLES]/declarative/plugins/com/nokia/TimeExample -- cgit v0.12 From c97e1e29aedaceead92cd231b3a77d60bab2af50 Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Mon, 8 Mar 2010 12:52:11 +1000 Subject: Use a better method for installing declarative demos. Simply copy the demo directories, instead of writing a stub .pro file. --- demos/declarative/calculator/calculator.pro | 13 ------------- demos/declarative/declarative.pro | 22 +++++++++++++++------- demos/declarative/flickr/flickr.pro | 16 ---------------- demos/declarative/minehunt/minehunt.pro | 2 +- demos/declarative/snake/snake.pro | 13 ------------- demos/declarative/twitter/twitter.pro | 13 ------------- demos/declarative/webbrowser/webbrowser.pro | 13 ------------- 7 files changed, 16 insertions(+), 76 deletions(-) delete mode 100644 demos/declarative/calculator/calculator.pro delete mode 100644 demos/declarative/flickr/flickr.pro delete mode 100644 demos/declarative/snake/snake.pro delete mode 100644 demos/declarative/twitter/twitter.pro delete mode 100644 demos/declarative/webbrowser/webbrowser.pro diff --git a/demos/declarative/calculator/calculator.pro b/demos/declarative/calculator/calculator.pro deleted file mode 100644 index efe6413..0000000 --- a/demos/declarative/calculator/calculator.pro +++ /dev/null @@ -1,13 +0,0 @@ -TEMPLATE=app -CONFIG -= qt separate_debug_info -LIBS = -QT = -QMAKE_LINK = @: dummy - -sources.files = \ - CalcButton.qml \ - calculator.js \ - calculator.qml -sources.path = $$[QT_INSTALL_DEMOS]/declarative/calculator -INSTALLS = sources - diff --git a/demos/declarative/declarative.pro b/demos/declarative/declarative.pro index 037ad85..4d169e3 100644 --- a/demos/declarative/declarative.pro +++ b/demos/declarative/declarative.pro @@ -1,9 +1,17 @@ TEMPLATE = subdirs -SUBDIRS = calculator \ - flickr \ - minehunt \ - samegame \ - snake \ - twitter \ - webbrowser + +# These demos contain C++ and need to be compiled +SUBDIRS = \ + minehunt + +# These examples contain no C++ and can simply be copied +sources.files = \ + calculator \ + flickr \ + samegame \ + snake \ + twitter \ + webbrowser +sources.path = $$[QT_INSTALL_DEMOS]/declarative +INSTALLS += sources diff --git a/demos/declarative/flickr/flickr.pro b/demos/declarative/flickr/flickr.pro deleted file mode 100644 index c4c1d44..0000000 --- a/demos/declarative/flickr/flickr.pro +++ /dev/null @@ -1,16 +0,0 @@ -TEMPLATE=app -CONFIG -= qt separate_debug_info -LIBS = -QT = -QMAKE_LINK = @: dummy - -sources.files = \ - flickr-desktop.qml \ - flickr-mobile-90.qml \ - flickr-mobile.qml \ - common \ - mobile - -sources.path = $$[QT_INSTALL_DEMOS]/declarative/flickr -INSTALLS = sources - diff --git a/demos/declarative/minehunt/minehunt.pro b/demos/declarative/minehunt/minehunt.pro index 2f9a8ad..2df33e6 100644 --- a/demos/declarative/minehunt/minehunt.pro +++ b/demos/declarative/minehunt/minehunt.pro @@ -10,7 +10,7 @@ DESTDIR = MinehuntCore SOURCES += minehunt.cpp -sources.files = minehunt.qml +sources.files = minehunt.qml minehunt.pro sources.path = $$[QT_INSTALL_DEMOS]/declarative/minehunt target.path = $$[QT_INSTALL_DEMOS]/declarative/minehunt/MinehuntCore diff --git a/demos/declarative/snake/snake.pro b/demos/declarative/snake/snake.pro deleted file mode 100644 index a206fd4..0000000 --- a/demos/declarative/snake/snake.pro +++ /dev/null @@ -1,13 +0,0 @@ -TEMPLATE=app -CONFIG -= qt separate_debug_info -LIBS = -QT = -QMAKE_LINK = @: dummy - -sources.files = \ - content \ - snake.qml - -sources.path = $$[QT_INSTALL_DEMOS]/declarative/snake -INSTALLS = sources - diff --git a/demos/declarative/twitter/twitter.pro b/demos/declarative/twitter/twitter.pro deleted file mode 100644 index e1dd821..0000000 --- a/demos/declarative/twitter/twitter.pro +++ /dev/null @@ -1,13 +0,0 @@ -TEMPLATE=app -CONFIG -= qt separate_debug_info -LIBS = -QT = -QMAKE_LINK = @: dummy - -sources.files = \ - TwitterCore \ - twitter.qml - -sources.path = $$[QT_INSTALL_DEMOS]/declarative/twitter -INSTALLS = sources - diff --git a/demos/declarative/webbrowser/webbrowser.pro b/demos/declarative/webbrowser/webbrowser.pro deleted file mode 100644 index c033ef9..0000000 --- a/demos/declarative/webbrowser/webbrowser.pro +++ /dev/null @@ -1,13 +0,0 @@ -TEMPLATE=app -CONFIG -= qt separate_debug_info -LIBS = -QT = -QMAKE_LINK = @: dummy - -sources.files = \ - content \ - webbrowser.qml - -sources.path = $$[QT_INSTALL_DEMOS]/declarative/webbrowser -INSTALLS = sources - -- cgit v0.12 From baed547d0bccabf3ec92cafb54b6642d81c854f0 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Mon, 8 Mar 2010 13:42:44 +1000 Subject: Remove expected warning --- .../qdeclarativeworkerscript.pro | 3 +-- .../tst_qdeclarativeworkerscript.cpp | 18 +----------------- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/tests/auto/declarative/qdeclarativeworkerscript/qdeclarativeworkerscript.pro b/tests/auto/declarative/qdeclarativeworkerscript/qdeclarativeworkerscript.pro index 0543ff6..e2b31c7 100644 --- a/tests/auto/declarative/qdeclarativeworkerscript/qdeclarativeworkerscript.pro +++ b/tests/auto/declarative/qdeclarativeworkerscript/qdeclarativeworkerscript.pro @@ -1,6 +1,5 @@ load(qttest_p4) -contains(QT_CONFIG,declarative): QT += declarative -QT += script +contains(QT_CONFIG,declarative): QT += declarative script macx:CONFIG -= app_bundle SOURCES += tst_qdeclarativeworkerscript.cpp diff --git a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp index 9adbc28..fe2dac2 100644 --- a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp +++ b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp @@ -60,7 +60,6 @@ public: tst_QDeclarativeWorkerScript() {} private slots: void source(); - void source_data(); void messaging(); void messaging_data(); void messaging_sendQObjectList(); @@ -83,13 +82,7 @@ private: void tst_QDeclarativeWorkerScript::source() { - QFETCH(QUrl, source); - QFETCH(bool, valid); - - if (!valid) { - QByteArray w = "WorkerScript: Cannot find source file \"" + source.toString().toUtf8() + "\""; - QTest::ignoreMessage(QtWarningMsg, w.constData()); - } + QUrl source = QUrl::fromLocalFile(SRCDIR "/data/worker.qml"); QDeclarativeComponent component(&m_engine); component.setData("import Qt 4.6\nWorkerScript { source: '" + source.toString().toUtf8() + "'; }", QUrl()); @@ -103,15 +96,6 @@ void tst_QDeclarativeWorkerScript::source() delete item; } -void tst_QDeclarativeWorkerScript::source_data() -{ - QTest::addColumn("source"); - QTest::addColumn("valid"); - - QTest::newRow("valid") << QUrl::fromLocalFile(SRCDIR "/data/worker.qml") << true; - QTest::newRow("invalid") << QUrl::fromLocalFile("asdjfk.js") << false; -} - void tst_QDeclarativeWorkerScript::messaging() { QFETCH(QVariant, value); -- cgit v0.12 From a7b6bb3537f359a406e3e8d0d0340137a73fc677 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Mon, 8 Mar 2010 14:18:42 +1000 Subject: Disallow upper case property, signal and method names in QML QT-2976 --- src/declarative/qml/qdeclarativecompiler.cpp | 6 ++++++ .../auto/declarative/qdeclarativelanguage/data/method.1.errors.txt | 1 + tests/auto/declarative/qdeclarativelanguage/data/method.1.qml | 5 +++++ .../declarative/qdeclarativelanguage/data/property.6.errors.txt | 1 + tests/auto/declarative/qdeclarativelanguage/data/property.6.qml | 6 ++++++ .../declarative/qdeclarativelanguage/data/property.7.errors.txt | 1 + tests/auto/declarative/qdeclarativelanguage/data/property.7.qml | 5 +++++ .../auto/declarative/qdeclarativelanguage/data/signal.4.errors.txt | 1 + tests/auto/declarative/qdeclarativelanguage/data/signal.4.qml | 6 ++++++ .../declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp | 5 +++++ 10 files changed, 37 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/method.1.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/method.1.qml create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/property.6.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/property.6.qml create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/property.7.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/property.7.qml create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/signal.4.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/signal.4.qml diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index 3c6c949..ef1032b 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -2204,6 +2204,8 @@ bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj) if (propNames.contains(prop.name)) COMPILE_EXCEPTION(&prop, QCoreApplication::translate("QDeclarativeCompiler","Duplicate property name")); + if (QString::fromUtf8(prop.name).at(0).isUpper()) + COMPILE_EXCEPTION(&prop, QCoreApplication::translate("QDeclarativeCompiler","Property names cannot begin with an upper case letter")); propNames.insert(prop.name); } @@ -2211,12 +2213,16 @@ bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj) QByteArray name = obj->dynamicSignals.at(ii).name; if (methodNames.contains(name)) COMPILE_EXCEPTION(obj, QCoreApplication::translate("QDeclarativeCompiler","Duplicate signal name")); + if (QString::fromUtf8(name).at(0).isUpper()) + COMPILE_EXCEPTION(obj, QCoreApplication::translate("QDeclarativeCompiler","Signal names cannot begin with an upper case letter")); methodNames.insert(name); } for (int ii = 0; ii < obj->dynamicSlots.count(); ++ii) { QByteArray name = obj->dynamicSlots.at(ii).name; if (methodNames.contains(name)) COMPILE_EXCEPTION(obj, QCoreApplication::translate("QDeclarativeCompiler","Duplicate method name")); + if (QString::fromUtf8(name).at(0).isUpper()) + COMPILE_EXCEPTION(obj, QCoreApplication::translate("QDeclarativeCompiler","Method names cannot begin with an upper case letter")); methodNames.insert(name); } diff --git a/tests/auto/declarative/qdeclarativelanguage/data/method.1.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/method.1.errors.txt new file mode 100644 index 0000000..b10984f --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/method.1.errors.txt @@ -0,0 +1 @@ +3:1:Method names cannot begin with an upper case letter diff --git a/tests/auto/declarative/qdeclarativelanguage/data/method.1.qml b/tests/auto/declarative/qdeclarativelanguage/data/method.1.qml new file mode 100644 index 0000000..d9794b4 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/method.1.qml @@ -0,0 +1,5 @@ +import Qt 4.6 + +QtObject { + function MyMethod() {} +} diff --git a/tests/auto/declarative/qdeclarativelanguage/data/property.6.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/property.6.errors.txt new file mode 100644 index 0000000..9e8d454 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/property.6.errors.txt @@ -0,0 +1 @@ +4:5:Property names cannot begin with an upper case letter diff --git a/tests/auto/declarative/qdeclarativelanguage/data/property.6.qml b/tests/auto/declarative/qdeclarativelanguage/data/property.6.qml new file mode 100644 index 0000000..f39bed3 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/property.6.qml @@ -0,0 +1,6 @@ +import Qt 4.6 + +QtObject { + property int Hello +} + diff --git a/tests/auto/declarative/qdeclarativelanguage/data/property.7.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/property.7.errors.txt new file mode 100644 index 0000000..9e8d454 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/property.7.errors.txt @@ -0,0 +1 @@ +4:5:Property names cannot begin with an upper case letter diff --git a/tests/auto/declarative/qdeclarativelanguage/data/property.7.qml b/tests/auto/declarative/qdeclarativelanguage/data/property.7.qml new file mode 100644 index 0000000..502eb22 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/property.7.qml @@ -0,0 +1,5 @@ +import Qt 4.6 + +QtObject { + property int Hello: 10 +} diff --git a/tests/auto/declarative/qdeclarativelanguage/data/signal.4.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/signal.4.errors.txt new file mode 100644 index 0000000..d96f9e3 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/signal.4.errors.txt @@ -0,0 +1 @@ +3:1:Signal names cannot begin with an upper case letter diff --git a/tests/auto/declarative/qdeclarativelanguage/data/signal.4.qml b/tests/auto/declarative/qdeclarativelanguage/data/signal.4.qml new file mode 100644 index 0000000..7279a46 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/signal.4.qml @@ -0,0 +1,6 @@ +import Qt 4.6 + +QtObject { + signal MySignal +} + diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index da0bf1a..083c551 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -269,12 +269,17 @@ void tst_qdeclarativelanguage::errors_data() QTest::newRow("signal.1") << "signal.1.qml" << "signal.1.errors.txt" << false; QTest::newRow("signal.2") << "signal.2.qml" << "signal.2.errors.txt" << false; QTest::newRow("signal.3") << "signal.3.qml" << "signal.3.errors.txt" << false; + QTest::newRow("signal.4") << "signal.4.qml" << "signal.4.errors.txt" << false; + + QTest::newRow("method.1") << "method.1.qml" << "method.1.errors.txt" << false; QTest::newRow("property.1") << "property.1.qml" << "property.1.errors.txt" << false; QTest::newRow("property.2") << "property.2.qml" << "property.2.errors.txt" << false; QTest::newRow("property.3") << "property.3.qml" << "property.3.errors.txt" << false; QTest::newRow("property.4") << "property.4.qml" << "property.4.errors.txt" << false; QTest::newRow("property.5") << "property.5.qml" << "property.5.errors.txt" << false; + QTest::newRow("property.6") << "property.6.qml" << "property.6.errors.txt" << false; + QTest::newRow("property.7") << "property.7.qml" << "property.7.errors.txt" << false; QTest::newRow("Script.1") << "script.1.qml" << "script.1.errors.txt" << false; QTest::newRow("Script.2") << "script.2.qml" << "script.2.errors.txt" << false; -- cgit v0.12 From ef16993782b834cb34ed0281925ddfc49535e78b Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Mon, 8 Mar 2010 14:39:11 +1000 Subject: Fix Qt.tint() algorithm QT-2424 --- src/declarative/qml/qdeclarativeengine.cpp | 16 ++++++---------- tests/auto/declarative/qdeclarativeqt/data/tint.qml | 2 +- .../declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp | 4 ++-- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 1e60df4..41d55d7 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -1234,17 +1234,13 @@ QScriptValue QDeclarativeEnginePrivate::tint(QScriptContext *ctxt, QScriptEngine else if (a == 0x00) finalColor = color; else { - uint src = tintColor.rgba(); - uint dest = color.rgba(); + qreal a = tintColor.alphaF(); + qreal inv_a = 1.0 - a; - uint res = (((a * (src & 0xFF00FF)) + - ((0xFF - a) * (dest & 0xFF00FF))) >> 8) & 0xFF00FF; - res |= (((a * ((src >> 8) & 0xFF00FF)) + - ((0xFF - a) * ((dest >> 8) & 0xFF00FF)))) & 0xFF00FF00; - if ((src & 0xFF000000) == 0xFF000000) - res |= 0xFF000000; - - finalColor = QColor::fromRgba(res); + finalColor.setRgbF(tintColor.redF() * a + color.redF() * inv_a, + tintColor.greenF() * a + color.greenF() * inv_a, + tintColor.blueF() * a + color.blueF() * inv_a, + a + inv_a * color.alphaF()); } return qScriptValueFromValue(engine, qVariantFromValue(finalColor)); diff --git a/tests/auto/declarative/qdeclarativeqt/data/tint.qml b/tests/auto/declarative/qdeclarativeqt/data/tint.qml index da8afe2..478245f 100644 --- a/tests/auto/declarative/qdeclarativeqt/data/tint.qml +++ b/tests/auto/declarative/qdeclarativeqt/data/tint.qml @@ -3,7 +3,7 @@ import Qt 4.6 QtObject { property color test1: Qt.tint("red", "blue"); property color test2: Qt.tint(Qt.rgba(1, 0, 0), Qt.rgba(0, 0, 0, 0)); - property color test3: Qt.tint("red", Qt.rgba(0, 0, 1, 0.5)); // XXX - what should this be? + property color test3: Qt.tint("red", Qt.rgba(0, 0, 1, 0.5)); property color test4: Qt.tint("red", Qt.rgba(0, 0, 1, 0.5), 10); property color test5: Qt.tint("red") } diff --git a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp index 90afd4e..b70011b 100644 --- a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp +++ b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp @@ -254,8 +254,8 @@ void tst_qdeclarativeqt::tint() QCOMPARE(qvariant_cast(object->property("test1")), QColor::fromRgbF(0, 0, 1)); QCOMPARE(qvariant_cast(object->property("test2")), QColor::fromRgbF(1, 0, 0)); - QEXPECT_FAIL("", "QT-2424",Continue); - QCOMPARE(qvariant_cast(object->property("test3")), QColor::fromRgbF(1, 0, 0)); + QColor test3 = qvariant_cast(object->property("test3")); + QCOMPARE(test3.rgba(), 0xFF7F0080); QCOMPARE(qvariant_cast(object->property("test4")), QColor()); QCOMPARE(qvariant_cast(object->property("test5")), QColor()); -- cgit v0.12 From ad7e15422be2ae2d3bbae75d0fa1dd99b302283d Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Mon, 8 Mar 2010 14:49:03 +1000 Subject: Add Flipable example. Task-number: QT-2824 --- examples/declarative/flipable/back.png | Bin 0 -> 5048 bytes examples/declarative/flipable/flipable.qml | 37 +++++++++++++++ examples/declarative/flipable/front.png | Bin 0 -> 6431 bytes .../graphicsitems/qdeclarativeflipable.cpp | 51 ++++++--------------- 4 files changed, 50 insertions(+), 38 deletions(-) create mode 100644 examples/declarative/flipable/back.png create mode 100644 examples/declarative/flipable/flipable.qml create mode 100644 examples/declarative/flipable/front.png diff --git a/examples/declarative/flipable/back.png b/examples/declarative/flipable/back.png new file mode 100644 index 0000000..0b4cafc Binary files /dev/null and b/examples/declarative/flipable/back.png differ diff --git a/examples/declarative/flipable/flipable.qml b/examples/declarative/flipable/flipable.qml new file mode 100644 index 0000000..c837ebc --- /dev/null +++ b/examples/declarative/flipable/flipable.qml @@ -0,0 +1,37 @@ +//! [0] +import Qt 4.6 + +Flipable { + id: flipable + width: 240 + height: 240 + + property int angle: 0 + property bool flipped: false + + front: Image { source: "front.png" } + back: Image { source: "back.png" } + + transform: Rotation { + origin.x: flipable.width/2; origin.y: flipable.height/2 + axis.x: 0; axis.y: 1; axis.z: 0 // rotate around y-axis + angle: flipable.angle + } + + states: State { + name: "back" + PropertyChanges { target: flipable; angle: 180 } + when: flipable.flipped + } + + transitions: Transition { + NumberAnimation { properties: "angle"; duration: 1000 } + } + + MouseArea { + anchors.fill: parent + onClicked: flipable.flipped = !flipable.flipped + } +} +//! [0] + diff --git a/examples/declarative/flipable/front.png b/examples/declarative/flipable/front.png new file mode 100644 index 0000000..796b605 Binary files /dev/null and b/examples/declarative/flipable/front.png differ diff --git a/src/declarative/graphicsitems/qdeclarativeflipable.cpp b/src/declarative/graphicsitems/qdeclarativeflipable.cpp index b36127f..1ebbaee 100644 --- a/src/declarative/graphicsitems/qdeclarativeflipable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflipable.cpp @@ -68,56 +68,31 @@ public: \brief The Flipable item provides a surface that can be flipped. \inherits Item - Flipable allows you to specify a front and a back and then flip between those sides. + Flipable is an item that can be visibly "flipped" between its front and + back sides. It is used together with Rotation and State/Transition to + produce a flipping effect. - Here's an example that flips between the front and back sides when clicked: + Here is a Flipable that flips whenever it is clicked: - \qml - - Flipable { - id: flipable - width: 250; height: 250 - property int angle: 0 - - transform: Rotation { - id: rotation - origin.x: flipable.width/2; origin.y: flipable.height/2 - axis.x: 0; axis.y: 1; axis.z: 0 // rotate around y-axis - angle: flipable.angle - } - - front: Image { source: "front.png" } - back: Image { source: "back.png" } - - states: State { - name: "back" - PropertyChanges { target: flipable; angle: 180 } - } - - transitions: Transition { - NumberAnimation { properties: "angle"; duration: 2000 } - } - - MouseArea { - // change between default and 'back' states - onClicked: flipable.state = (flipable.state == 'back' ? '' : 'back') - anchors.fill: parent - } - } - \endqml + \snippet examples/declarative/flipable/flipable.qml 0 \image flipable.gif + + The Rotation element is used to specify the angle and axis of the flip, + and the State defines the changes in angle which produce the flipping + effect. Finally, the Transition creates the animation that changes the + angle over one second. */ /*! \internal \class QDeclarativeFlipable - \brief The QDeclarativeFlipable class provides a flipable surface. + \brief The Flipable item provides a surface that can be flipped. \ingroup group_widgets - QDeclarativeFlipable allows you to specify a front and a back, as well as an - axis for the flip. + Flipable is an item that can be visibly "flipped" between its front and + back sides. */ QDeclarativeFlipable::QDeclarativeFlipable(QDeclarativeItem *parent) -- cgit v0.12 From 03a2ed58778d500cc7eed285478d0e304b3c92dc Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 8 Mar 2010 15:32:16 +1000 Subject: Particles optimization and doc fixes. --- src/declarative/graphicsitems/qdeclarativeparticles.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeparticles.cpp b/src/declarative/graphicsitems/qdeclarativeparticles.cpp index deabdd6..ec0bf6c 100644 --- a/src/declarative/graphicsitems/qdeclarativeparticles.cpp +++ b/src/declarative/graphicsitems/qdeclarativeparticles.cpp @@ -758,11 +758,13 @@ void QDeclarativeParticles::setSource(const QUrl &name) The particles element emits particles until it has count active particles. When this number is reached, new particles are not emitted until - some of the current particles reach theend of their lifespan. + some of the current particles reach the end of their lifespan. If count is -1 then there is no maximum number of active particles, and particles will be constantly emitted at the rate specified by emissionRate. + The default value for count is 1. + If both count and emissionRate are set to -1, nothing will be emitted. */ @@ -1219,7 +1221,7 @@ void QDeclarativeParticles::burst(int count, int emissionRate) void QDeclarativeParticlesPainter::updateSize() { - if (!isComponentComplete()) + if (!d->_componentComplete) return; const int parentX = parentItem()->x(); @@ -1304,7 +1306,7 @@ void QDeclarativeParticles::componentComplete() { Q_D(QDeclarativeParticles); QDeclarativeItem::componentComplete(); - if (d->count) { + if (d->count && d->emissionRate) { d->paintItem->updateSize(); d->clock.start(); } -- cgit v0.12 From ac764b3d0e7b7b591481da5f4da821bc27400817 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 8 Mar 2010 15:56:31 +1000 Subject: Make the animation property of Behavior deferred. --- src/declarative/util/qdeclarativebehavior.cpp | 1 + src/declarative/util/qdeclarativebehavior_p.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/declarative/util/qdeclarativebehavior.cpp b/src/declarative/util/qdeclarativebehavior.cpp index dea2c02..d90ca33 100644 --- a/src/declarative/util/qdeclarativebehavior.cpp +++ b/src/declarative/util/qdeclarativebehavior.cpp @@ -157,6 +157,7 @@ void QDeclarativeBehavior::setEnabled(bool enabled) void QDeclarativeBehavior::write(const QVariant &value) { Q_D(QDeclarativeBehavior); + qmlExecuteDeferred(this); if (!d->animation || !d->enabled) { QDeclarativePropertyPrivate::write(d->property, value, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding); return; diff --git a/src/declarative/util/qdeclarativebehavior_p.h b/src/declarative/util/qdeclarativebehavior_p.h index a633b55..ff58210 100644 --- a/src/declarative/util/qdeclarativebehavior_p.h +++ b/src/declarative/util/qdeclarativebehavior_p.h @@ -65,6 +65,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeBehavior : public QObject, public QDeclar Q_CLASSINFO("DefaultProperty", "animation") Q_PROPERTY(QDeclarativeAbstractAnimation *animation READ animation WRITE setAnimation) Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) + Q_CLASSINFO("DeferredPropertyNames", "animation") public: QDeclarativeBehavior(QObject *parent=0); -- cgit v0.12 From 4bd0dc0b6c07ff288c77f547792a62d5e8ad7356 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Mon, 8 Mar 2010 16:54:11 +1000 Subject: fix QDeclarativeItem sceneEvent handling --- src/declarative/graphicsitems/qdeclarativeitem.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index b0a7570..59dd43d 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -2217,7 +2217,7 @@ void QDeclarativeItem::setKeepMouseGrab(bool keep) \qmlmethod object Item::mapFromItem(Item item, int x, int y) Maps the point (\a x, \a y), which is in \a item's coordinate system, to - this item's coordinate system, and returns an object with \c x and \c y + this item's coordinate system, and returns an object with \c x and \c y properties matching the mapped cooordinate. If \a item is a \c null value, this maps the point from the coordinate @@ -2576,9 +2576,9 @@ bool QDeclarativeItem::sceneEvent(QEvent *event) !(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { keyPressEvent(static_cast(event)); if (!event->isAccepted()) - QGraphicsItem::sceneEvent(event); + return QGraphicsItem::sceneEvent(event); } else { - QGraphicsItem::sceneEvent(event); + return QGraphicsItem::sceneEvent(event); } } else { bool rv = QGraphicsItem::sceneEvent(event); -- cgit v0.12 From 4d8214afabd5e093c02b0de0e72f24139af6660f Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 8 Mar 2010 17:07:05 +1000 Subject: Remove expect fail from ListView currentIndex test --- .../qdeclarativelistview/tst_qdeclarativelistview.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp index 1df4448..75fbbf8 100644 --- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp +++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp @@ -1028,13 +1028,17 @@ void tst_QDeclarativeListView::currentIndex() QCOMPARE(listview->contentY(), 0.0); // Test keys - qApp->setActiveWindow(canvas); canvas->show(); - canvas->setFocus(); + qApp->setActiveWindow(canvas); +#ifdef Q_WS_X11 + // to be safe and avoid failing setFocus with window managers + qt_x11_wait_for_window_manager(canvas); +#endif + QVERIFY(canvas->hasFocus()); + QVERIFY(canvas->scene()->hasFocus()); qApp->processEvents(); QTest::keyClick(canvas, Qt::Key_Down); - QEXPECT_FAIL("", "QTBUG-8475", Abort); QCOMPARE(listview->currentIndex(), 1); QTest::keyClick(canvas, Qt::Key_Up); -- cgit v0.12 From 9b06c2dd119f3c4442f7b26756728bb9c7fefb4a Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 8 Mar 2010 17:17:15 +1000 Subject: clearFocus() before setParentItem(0) on an item with focus. --- src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp | 2 ++ .../qdeclarativegridview/tst_qdeclarativegridview.cpp | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index 55f1c89..6bad4da 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -927,6 +927,8 @@ QDeclarativeVisualDataModel::ReleaseFlags QDeclarativeVisualDataModel::release(Q if (inPackage) { emit destroyingPackage(qobject_cast(obj)); } else { + if (item->hasFocus()) + item->clearFocus(); item->setOpacity(0.0); static_cast(item)->setParentItem(0); } diff --git a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp index 7ade309..aeefea1 100644 --- a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp +++ b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp @@ -659,9 +659,14 @@ void tst_QDeclarativeGridView::currentIndex() QCOMPARE(gridview->contentY(), 0.0); // Test keys - qApp->setActiveWindow(canvas); canvas->show(); - canvas->setFocus(); + qApp->setActiveWindow(canvas); +#ifdef Q_WS_X11 + // to be safe and avoid failing setFocus with window managers + qt_x11_wait_for_window_manager(canvas); +#endif + QVERIFY(canvas->hasFocus()); + QVERIFY(canvas->scene()->hasFocus()); qApp->processEvents(); QTest::keyClick(canvas, Qt::Key_Down); @@ -672,7 +677,6 @@ void tst_QDeclarativeGridView::currentIndex() gridview->setFlow(QDeclarativeGridView::TopToBottom); - QEXPECT_FAIL("", "QTBUG-8475", Abort); QTest::keyClick(canvas, Qt::Key_Right); QCOMPARE(gridview->currentIndex(), 5); -- cgit v0.12