From 9a3e15a05a0c6fb0797d4ef9029c0483ab495bdd Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Mon, 2 Nov 2009 13:44:59 +1000 Subject: Add images to QML easing curve documentation Task-number: QT-2326 --- src/declarative/util/qmlanimation.cpp | 212 +++++++++++++++++++++++++++------- 1 file changed, 169 insertions(+), 43 deletions(-) diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index 180864c..051003f 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -1597,49 +1597,175 @@ void QmlPropertyAnimation::setTo(const QVariant &t) Available values are: - \list - \i \e easeNone - Easing equation function for a simple linear tweening, with no easing. - \i \e easeInQuad - Easing equation function for a quadratic (t^2) easing in: accelerating from zero velocity. - \i \e easeOutQuad - Easing equation function for a quadratic (t^2) easing out: decelerating to zero velocity. - \i \e easeInOutQuad - Easing equation function for a quadratic (t^2) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInQuad - Easing equation function for a quadratic (t^2) easing out/in: deceleration until halfway, then acceleration. - \i \e easeInCubic - Easing equation function for a cubic (t^3) easing in: accelerating from zero velocity. - \i \e easeOutCubic - Easing equation function for a cubic (t^3) easing out: decelerating from zero velocity. - \i \e easeInOutCubic - Easing equation function for a cubic (t^3) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInCubic - Easing equation function for a cubic (t^3) easing out/in: deceleration until halfway, then acceleration. - \i \e easeInQuart - Easing equation function for a quartic (t^4) easing in: accelerating from zero velocity. - \i \e easeOutQuart - Easing equation function for a quartic (t^4) easing out: decelerating from zero velocity. - \i \e easeInOutQuart - Easing equation function for a quartic (t^4) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInQuart - Easing equation function for a quartic (t^4) easing out/in: deceleration until halfway, then acceleration. - \i \e easeInQuint - Easing equation function for a quintic (t^5) easing in: accelerating from zero velocity. - \i \e easeOutQuint - Easing equation function for a quintic (t^5) easing out: decelerating from zero velocity. - \i \e easeInOutQuint - Easing equation function for a quintic (t^5) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInQuint - Easing equation function for a quintic (t^5) easing out/in: deceleration until halfway, then acceleration. - \i \e easeInSine - Easing equation function for a sinusoidal (sin(t)) easing in: accelerating from zero velocity. - \i \e easeOutSine - Easing equation function for a sinusoidal (sin(t)) easing out: decelerating from zero velocity. - \i \e easeInOutSine - Easing equation function for a sinusoidal (sin(t)) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInSine - Easing equation function for a sinusoidal (sin(t)) easing out/in: deceleration until halfway, then acceleration. - \i \e easeInExpo - Easing equation function for an exponential (2^t) easing in: accelerating from zero velocity. - \i \e easeOutExpo - Easing equation function for an exponential (2^t) easing out: decelerating from zero velocity. - \i \e easeInOutExpo - Easing equation function for an exponential (2^t) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInExpo - Easing equation function for an exponential (2^t) easing out/in: deceleration until halfway, then acceleration. - \i \e easeInCirc - Easing equation function for a circular (sqrt(1-t^2)) easing in: accelerating from zero velocity. - \i \e easeOutCirc - Easing equation function for a circular (sqrt(1-t^2)) easing out: decelerating from zero velocity. - \i \e easeInOutCirc - Easing equation function for a circular (sqrt(1-t^2)) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInCirc - Easing equation function for a circular (sqrt(1-t^2)) easing out/in: deceleration until halfway, then acceleration. - \i \e easeInElastic - Easing equation function for an elastic (exponentially decaying sine wave) easing in: accelerating from zero velocity. The peak amplitude can be set with the \e amplitude parameter, and the period of decay by the \e period parameter. - \i \e easeOutElastic - Easing equation function for an elastic (exponentially decaying sine wave) easing out: decelerating from zero velocity. The peak amplitude can be set with the \e amplitude parameter, and the period of decay by the \e period parameter. - \i \e easeInOutElastic - Easing equation function for an elastic (exponentially decaying sine wave) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInElastic - Easing equation function for an elastic (exponentially decaying sine wave) easing out/in: deceleration until halfway, then acceleration. - \i \e easeInBack - Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in: accelerating from zero velocity. - \i \e easeOutBack - Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out: decelerating from zero velocity. - \i \e easeInOutBack - Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInBack - Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in: deceleration until halfway, then acceleration. - \i \e easeOutBounce - Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out: decelerating from zero velocity. - \i \e easeInBounce - Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in: accelerating from zero velocity. - \i \e easeInOutBounce - Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInBounce - Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out/in: deceleration until halfway, then acceleration. - \endlist + \table + \row + \o \c easeNone + \o Easing curve for a linear (t) function: velocity is constant. + \o \inlineimage qeasingcurve-linear.png + \row + \o \c easeInQuad + \o Easing curve for a quadratic (t^2) function: accelerating from zero velocity. + \o \inlineimage qeasingcurve-inquad.png + \row + \o \c easeOutQuad + \o Easing curve for a quadratic (t^2) function: decelerating to zero velocity. + \o \inlineimage qeasingcurve-outquad.png + \row + \o \c easeInOutQuad + \o Easing curve for a quadratic (t^2) function: acceleration until halfway, then deceleration. + \o \inlineimage qeasingcurve-inoutquad.png + \row + \o \c easeOutInQuad + \o Easing curve for a quadratic (t^2) function: deceleration until halfway, then acceleration. + \o \inlineimage qeasingcurve-outinquad.png + \row + \o \c easeInCubic + \o Easing curve for a cubic (t^3) function: accelerating from zero velocity. + \o \inlineimage qeasingcurve-incubic.png + \row + \o \c easeOutCubic + \o Easing curve for a cubic (t^3) function: decelerating from zero velocity. + \o \inlineimage qeasingcurve-outcubic.png + \row + \o \c easeInOutCubic + \o Easing curve for a cubic (t^3) function: acceleration until halfway, then deceleration. + \o \inlineimage qeasingcurve-inoutcubic.png + \row + \o \c easeOutInCubic + \o Easing curve for a cubic (t^3) function: deceleration until halfway, then acceleration. + \o \inlineimage qeasingcurve-outincubic.png + \row + \o \c easeInQuart + \o Easing curve for a quartic (t^4) function: accelerating from zero velocity. + \o \inlineimage qeasingcurve-inquart.png + \row + \o \c easeOutQuart + \o Easing curve for a cubic (t^4) function: decelerating from zero velocity. + \o \inlineimage qeasingcurve-outquart.png + \row + \o \c easeInOutQuart + \o Easing curve for a cubic (t^4) function: acceleration until halfway, then deceleration. + \o \inlineimage qeasingcurve-inoutquart.png + \row + \o \c easeOutInQuart + \o Easing curve for a cubic (t^4) function: deceleration until halfway, then acceleration. + \o \inlineimage qeasingcurve-outinquart.png + \row + \o \c easeInQuint + \o Easing curve for a quintic (t^5) function: accelerating from zero velocity. + \o \inlineimage qeasingcurve-inquint.png + \row + \o \c easeOutQuint + \o Easing curve for a cubic (t^5) function: decelerating from zero velocity. + \o \inlineimage qeasingcurve-outquint.png + \row + \o \c easeInOutQuint + \o Easing curve for a cubic (t^5) function: acceleration until halfway, then deceleration. + \o \inlineimage qeasingcurve-inoutquint.png + \row + \o \c easeOutInQuint + \o Easing curve for a cubic (t^5) function: deceleration until halfway, then acceleration. + \o \inlineimage qeasingcurve-outinquint.png + \row + \o \c easeInSine + \o Easing curve for a sinusoidal (sin(t)) function: accelerating from zero velocity. + \o \inlineimage qeasingcurve-insine.png + \row + \o \c easeOutSine + \o Easing curve for a sinusoidal (sin(t)) function: decelerating from zero velocity. + \o \inlineimage qeasingcurve-outsine.png + \row + \o \c easeInOutSine + \o Easing curve for a sinusoidal (sin(t)) function: acceleration until halfway, then deceleration. + \o \inlineimage qeasingcurve-inoutsine.png + \row + \o \c easeOutInSine + \o Easing curve for a sinusoidal (sin(t)) function: deceleration until halfway, then acceleration. + \o \inlineimage qeasingcurve-outinsine.png + \row + \o \c easeInExpo + \o Easing curve for an exponential (2^t) function: accelerating from zero velocity. + \o \inlineimage qeasingcurve-inexpo.png + \row + \o \c easeOutExpo + \o Easing curve for an exponential (2^t) function: decelerating from zero velocity. + \o \inlineimage qeasingcurve-outexpo.png + \row + \o \c easeInOutExpo + \o Easing curve for an exponential (2^t) function: acceleration until halfway, then deceleration. + \o \inlineimage qeasingcurve-inoutexpo.png + \row + \o \c easeOutInExpo + \o Easing curve for an exponential (2^t) function: deceleration until halfway, then acceleration. + \o \inlineimage qeasingcurve-outinexpo.png + \row + \o \c easeInCirc + \o Easing curve for a circular (sqrt(1-t^2)) function: accelerating from zero velocity. + \o \inlineimage qeasingcurve-incirc.png + \row + \o \c easeOutCirc + \o Easing curve for a circular (sqrt(1-t^2)) function: decelerating from zero velocity. + \o \inlineimage qeasingcurve-outcirc.png + \row + \o \c easeInOutCirc + \o Easing curve for a circular (sqrt(1-t^2)) function: acceleration until halfway, then deceleration. + \o \inlineimage qeasingcurve-inoutcirc.png + \row + \o \c easeOutInCirc + \o Easing curve for a circular (sqrt(1-t^2)) function: deceleration until halfway, then acceleration. + \o \inlineimage qeasingcurve-outincirc.png + \row + \o \c easeInElastic + \o Easing curve for an elastic (exponentially decaying sine wave) function: accelerating from zero velocity. + \br The peak amplitude can be set with the \e amplitude parameter, and the period of decay by the \e period parameter. + \o \inlineimage qeasingcurve-inelastic.png + \row + \o \c easeOutElastic + \o Easing curve for an elastic (exponentially decaying sine wave) function: decelerating from zero velocity. + \br The peak amplitude can be set with the \e amplitude parameter, and the period of decay by the \e period parameter. + \o \inlineimage qeasingcurve-outelastic.png + \row + \o \c easeInOutElastic + \o Easing curve for an elastic (exponentially decaying sine wave) function: acceleration until halfway, then deceleration. + \o \inlineimage qeasingcurve-inoutelastic.png + \row + \o \c easeOutInElastic + \o Easing curve for an elastic (exponentially decaying sine wave) function: deceleration until halfway, then acceleration. + \o \inlineimage qeasingcurve-outinelastic.png + \row + \o \c easeInBack + \o Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing in: accelerating from zero velocity. + \o \inlineimage qeasingcurve-inback.png + \row + \o \c easeOutBack + \o Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing out: decelerating to zero velocity. + \o \inlineimage qeasingcurve-outback.png + \row + \o \c easeInOutBack + \o Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing in/out: acceleration until halfway, then deceleration. + \o \inlineimage qeasingcurve-inoutback.png + \row + \o \c easeOutInBack + \o Easing curve for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in: deceleration until halfway, then acceleration. + \o \inlineimage qeasingcurve-outinback.png + \row + \o \c easeInBounce + \o Easing curve for a bounce (exponentially decaying parabolic bounce) function: accelerating from zero velocity. + \o \inlineimage qeasingcurve-inbounce.png + \row + \o \c easeOutBounce + \o Easing curve for a bounce (exponentially decaying parabolic bounce) function: decelerating from zero velocity. + \o \inlineimage qeasingcurve-outbounce.png + \row + \o \c easeInOutBounce + \o Easing curve for a bounce (exponentially decaying parabolic bounce) function easing in/out: acceleration until halfway, then deceleration. + \o \inlineimage qeasingcurve-inoutbounce.png + \row + \o \c easeOutInBounce + \o Easing curve for a bounce (exponentially decaying parabolic bounce) function easing out/in: deceleration until halfway, then acceleration. + \o \inlineimage qeasingcurve-outinbounce.png + \endtable + */ QString QmlPropertyAnimation::easing() const { -- cgit v0.12 From c0a7cfc6d205caf93bc46693ef4aca15fbcc36f8 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Mon, 2 Nov 2009 13:53:11 +1000 Subject: QmlContext tests --- src/declarative/qml/qmlbinding.cpp | 8 + src/declarative/qml/qmlbinding_p.h | 1 + src/declarative/qml/qmlcontext.cpp | 35 +- src/declarative/qml/qmlcontext_p.h | 1 + src/declarative/qml/qmlexpression.cpp | 4 + src/declarative/qml/qmlexpression_p.h | 6 + tests/auto/declarative/declarative.pro | 1 + tests/auto/declarative/qmlcontext/qmlcontext.pro | 6 + .../auto/declarative/qmlcontext/tst_qmlcontext.cpp | 387 +++++++++++++++++++++ 9 files changed, 445 insertions(+), 4 deletions(-) create mode 100644 tests/auto/declarative/qmlcontext/qmlcontext.pro create mode 100644 tests/auto/declarative/qmlcontext/tst_qmlcontext.cpp diff --git a/src/declarative/qml/qmlbinding.cpp b/src/declarative/qml/qmlbinding.cpp index eb08b61..5f7330f 100644 --- a/src/declarative/qml/qmlbinding.cpp +++ b/src/declarative/qml/qmlbinding.cpp @@ -67,6 +67,14 @@ QmlBindingData::~QmlBindingData() removeError(); } +void QmlBindingData::refresh() +{ + if (enabled && !updating && q) { + QmlBinding *b = static_cast(QmlExpressionPrivate::get(q)); + b->update(); + } +} + void QmlBindingData::removeError() { if (!prevError) return; diff --git a/src/declarative/qml/qmlbinding_p.h b/src/declarative/qml/qmlbinding_p.h index 6977e5b..e4de239 100644 --- a/src/declarative/qml/qmlbinding_p.h +++ b/src/declarative/qml/qmlbinding_p.h @@ -70,6 +70,7 @@ public: QmlMetaProperty property; + virtual void refresh(); void removeError(); bool addError(); QmlBindingData *nextError; diff --git a/src/declarative/qml/qmlcontext.cpp b/src/declarative/qml/qmlcontext.cpp index fe0d9cb..d37d959 100644 --- a/src/declarative/qml/qmlcontext.cpp +++ b/src/declarative/qml/qmlcontext.cpp @@ -180,9 +180,9 @@ void QmlContextPrivate::init() component.create(&context); \endcode - Each context may have up to 32 default objects, and objects added first take - precedence over those added later. All properties added explicitly by - QmlContext::setContextProperty() take precedence over default object properties. + Default objects added first take precedence over those added later. All properties + added explicitly by QmlContext::setContextProperty() take precedence over default + object properties. Contexts are hierarchal, with the \l {QmlEngine::rootContext()}{root context} being created by the QmlEngine. A component instantiated in a given context @@ -323,6 +323,26 @@ void QmlContextPrivate::invalidateEngines() } } +/* +Refreshes all expressions that could possibly depend on this context. +Refreshing flushes all context-tree dependent caches in the expressions, and should occur every +time the context tree *structure* (not values) changes. +*/ +void QmlContextPrivate::refreshExpressions() +{ + for (QSet::ConstIterator iter = childContexts.begin(); + iter != childContexts.end(); + ++iter) { + (*iter)->d_func()->refreshExpressions(); + } + + QmlAbstractExpression *expression = expressions; + while (expression) { + expression->refresh(); + expression = expression->m_nextExpression; + } +} + /*! Return the context's QmlEngine, or 0 if the context has no QmlEngine or the QmlEngine was destroyed. @@ -373,6 +393,8 @@ void QmlContext::setContextProperty(const QString &name, const QVariant &value) if (idx == -1) { d->propertyNames->add(name, d->idValueCount + d->propertyValues.count()); d->propertyValues.append(value); + + d->refreshExpressions(); } else { d->propertyValues[idx] = value; QMetaObject::activate(this, idx + d->notifyIndex, 0); @@ -404,7 +426,7 @@ void QmlContextPrivate::setIdPropertyData(QmlIntegerCache *data) /*! Set a the \a value of the \a name property on this context. - QmlContext does \b not take ownership of \a value. + QmlContext does \bold not take ownership of \a value. */ void QmlContext::setContextProperty(const QString &name, QObject *value) { @@ -418,6 +440,8 @@ void QmlContext::setContextProperty(const QString &name, QObject *value) if (idx == -1) { d->propertyNames->add(name, d->idValueCount + d->propertyValues.count()); d->propertyValues.append(QVariant::fromValue(value)); + + d->refreshExpressions(); } else { d->propertyValues[idx] = QVariant::fromValue(value); QMetaObject::activate(this, idx + d->notifyIndex, 0); @@ -432,6 +456,7 @@ void QmlContext::setContextProperty(const QString &name, QObject *value) */ QUrl QmlContext::resolvedUrl(const QUrl &src) { + Q_D(QmlContext); QmlContext *ctxt = this; if (src.isRelative() && !src.isEmpty()) { if (ctxt) { @@ -444,6 +469,8 @@ QUrl QmlContext::resolvedUrl(const QUrl &src) if (ctxt) return ctxt->d_func()->url.resolved(src); + else if (d->engine) + return d->engine->baseUrl().resolved(src); } return QUrl(); } else { diff --git a/src/declarative/qml/qmlcontext_p.h b/src/declarative/qml/qmlcontext_p.h index 286b882..cc8fcc6 100644 --- a/src/declarative/qml/qmlcontext_p.h +++ b/src/declarative/qml/qmlcontext_p.h @@ -105,6 +105,7 @@ public: void dump(int depth); void invalidateEngines(); + void refreshExpressions(); QSet childContexts; QmlAbstractExpression *expressions; diff --git a/src/declarative/qml/qmlexpression.cpp b/src/declarative/qml/qmlexpression.cpp index 2470c1d..faf9f5a 100644 --- a/src/declarative/qml/qmlexpression.cpp +++ b/src/declarative/qml/qmlexpression.cpp @@ -728,6 +728,10 @@ void QmlAbstractExpression::setContext(QmlContext *context) } } +void QmlAbstractExpression::refresh() +{ +} + bool QmlAbstractExpression::isValid() const { return m_context != 0; diff --git a/src/declarative/qml/qmlexpression_p.h b/src/declarative/qml/qmlexpression_p.h index ea572c3..c6ba54d 100644 --- a/src/declarative/qml/qmlexpression_p.h +++ b/src/declarative/qml/qmlexpression_p.h @@ -72,8 +72,11 @@ public: QmlContext *context() const; void setContext(QmlContext *); + virtual void refresh(); + private: friend class QmlContext; + friend class QmlContextPrivate; QmlContext *m_context; QmlAbstractExpression **m_prevExpression; QmlAbstractExpression *m_nextExpression; @@ -152,6 +155,9 @@ public: static QmlExpressionPrivate *get(QmlExpression *expr) { return static_cast(QObjectPrivate::get(expr)); } + static QmlExpression *get(QmlExpressionPrivate *expr) { + return expr->q_func(); + } static void exceptionToError(QScriptEngine *, QmlError &); }; diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index b9ab3ca..40cdb58 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -15,6 +15,7 @@ SUBDIRS += anchors \ qfxtextedit \ qfxtextinput \ qfxwebview \ + qmlcontext \ qmldom \ qmlecmascript \ qmllanguage \ diff --git a/tests/auto/declarative/qmlcontext/qmlcontext.pro b/tests/auto/declarative/qmlcontext/qmlcontext.pro new file mode 100644 index 0000000..9e66429 --- /dev/null +++ b/tests/auto/declarative/qmlcontext/qmlcontext.pro @@ -0,0 +1,6 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +SOURCES += tst_qmlcontext.cpp +macx:CONFIG -= app_bundle + +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qmlcontext/tst_qmlcontext.cpp b/tests/auto/declarative/qmlcontext/tst_qmlcontext.cpp new file mode 100644 index 0000000..69d9091 --- /dev/null +++ b/tests/auto/declarative/qmlcontext/tst_qmlcontext.cpp @@ -0,0 +1,387 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include + +class tst_qmlcontext : public QObject +{ + Q_OBJECT +public: + tst_qmlcontext() {} + +private slots: + void baseUrl(); + void resolvedUrl(); + void engineMethod(); + void parentContext(); + void setContextProperty(); + void addDefaultObject(); + +private: + QmlEngine engine; +}; + +void tst_qmlcontext::baseUrl() +{ + QmlContext ctxt(&engine); + + QCOMPARE(ctxt.baseUrl(), QUrl()); + + ctxt.setBaseUrl(QUrl("http://www.nokia.com/")); + + QCOMPARE(ctxt.baseUrl(), QUrl("http://www.nokia.com/")); +} + +void tst_qmlcontext::resolvedUrl() +{ + // Relative to the component + { + QmlContext ctxt(&engine); + ctxt.setBaseUrl(QUrl("http://www.nokia.com/")); + + QCOMPARE(ctxt.resolvedUrl(QUrl("main.qml")), QUrl("http://www.nokia.com/main.qml")); + } + + // Relative to a parent + { + QmlContext ctxt(&engine); + ctxt.setBaseUrl(QUrl("http://www.nokia.com/")); + + QmlContext ctxt2(&ctxt); + QCOMPARE(ctxt2.resolvedUrl(QUrl("main2.qml")), QUrl("http://www.nokia.com/main2.qml")); + } + + // Relative to the engine + { + QmlContext ctxt(&engine); + QCOMPARE(ctxt.resolvedUrl(QUrl("main.qml")), engine.baseUrl().resolved(QUrl("main.qml"))); + } + + // Relative to a deleted parent + { + QmlContext *ctxt = new QmlContext(&engine); + ctxt->setBaseUrl(QUrl("http://www.nokia.com/")); + + QmlContext ctxt2(ctxt); + QCOMPARE(ctxt2.resolvedUrl(QUrl("main2.qml")), QUrl("http://www.nokia.com/main2.qml")); + + delete ctxt; ctxt = 0; + + QCOMPARE(ctxt2.resolvedUrl(QUrl("main2.qml")), QUrl()); + } +} + +void tst_qmlcontext::engineMethod() +{ + QmlEngine *engine = new QmlEngine; + + QmlContext ctxt(engine); + QmlContext ctxt2(&ctxt); + QmlContext ctxt3(&ctxt2); + QmlContext ctxt4(&ctxt2); + + QCOMPARE(ctxt.engine(), engine); + QCOMPARE(ctxt2.engine(), engine); + QCOMPARE(ctxt3.engine(), engine); + QCOMPARE(ctxt4.engine(), engine); + + delete engine; engine = 0; + + QCOMPARE(ctxt.engine(), engine); + QCOMPARE(ctxt2.engine(), engine); + QCOMPARE(ctxt3.engine(), engine); + QCOMPARE(ctxt4.engine(), engine); +} + +void tst_qmlcontext::parentContext() +{ + QmlEngine *engine = new QmlEngine; + + QCOMPARE(engine->rootContext()->parentContext(), (QmlContext *)0); + + QmlContext *ctxt = new QmlContext(engine); + QmlContext *ctxt2 = new QmlContext(ctxt); + QmlContext *ctxt3 = new QmlContext(ctxt2); + QmlContext *ctxt4 = new QmlContext(ctxt2); + QmlContext *ctxt5 = new QmlContext(ctxt); + QmlContext *ctxt6 = new QmlContext(engine); + QmlContext *ctxt7 = new QmlContext(engine->rootContext()); + + QCOMPARE(ctxt->parentContext(), engine->rootContext()); + QCOMPARE(ctxt2->parentContext(), ctxt); + QCOMPARE(ctxt3->parentContext(), ctxt2); + QCOMPARE(ctxt4->parentContext(), ctxt2); + QCOMPARE(ctxt5->parentContext(), ctxt); + QCOMPARE(ctxt6->parentContext(), engine->rootContext()); + QCOMPARE(ctxt7->parentContext(), engine->rootContext()); + + delete ctxt2; ctxt2 = 0; + + QCOMPARE(ctxt->parentContext(), engine->rootContext()); + QCOMPARE(ctxt3->parentContext(), ctxt2); + QCOMPARE(ctxt4->parentContext(), ctxt2); + QCOMPARE(ctxt5->parentContext(), ctxt); + QCOMPARE(ctxt6->parentContext(), engine->rootContext()); + QCOMPARE(ctxt7->parentContext(), engine->rootContext()); + + delete engine; engine = 0; + + QCOMPARE(ctxt->parentContext(), (QmlContext *)0); + QCOMPARE(ctxt3->parentContext(), ctxt2); + QCOMPARE(ctxt4->parentContext(), ctxt2); + QCOMPARE(ctxt5->parentContext(), ctxt); + QCOMPARE(ctxt6->parentContext(), (QmlContext *)0); + QCOMPARE(ctxt7->parentContext(), (QmlContext *)0); + + delete ctxt7; + delete ctxt6; + delete ctxt5; + delete ctxt4; + delete ctxt3; + delete ctxt; +} + +class TestObject : public QObject +{ + Q_OBJECT + Q_PROPERTY(int a READ a NOTIFY aChanged) + Q_PROPERTY(int b READ b NOTIFY bChanged) + Q_PROPERTY(int c READ c NOTIFY cChanged) + +public: + TestObject() : _a(10), _b(10), _c(10) {} + + int a() const { return _a; } + void setA(int a) { _a = a; emit aChanged(); } + + int b() const { return _b; } + void setB(int b) { _b = b; emit bChanged(); } + + int c() const { return _c; } + void setC(int c) { _c = c; emit cChanged(); } + +signals: + void aChanged(); + void bChanged(); + void cChanged(); + +private: + int _a; + int _b; + int _c; +}; + +class TestObject2 : public QObject +{ + Q_OBJECT + Q_PROPERTY(int b READ b NOTIFY bChanged) + +public: + TestObject2() : _b(10) {} + + int b() const { return _b; } + void setB(int b) { _b = b; emit bChanged(); } + +signals: + void bChanged(); + +private: + int _b; +}; + +#define TEST_CONTEXT_PROPERTY(ctxt, name, value) \ +{ \ + QmlComponent component(&engine); \ + component.setData("import Qt 4.6; Object { property var test: " #name " }", QUrl()); \ +\ + QObject *obj = component.create(ctxt); \ +\ + QCOMPARE(obj->property("test"), value); \ +\ + delete obj; \ +} + +void tst_qmlcontext::setContextProperty() +{ + QmlContext ctxt(&engine); + QmlContext ctxt2(&ctxt); + + TestObject obj1; + obj1.setA(3345); + TestObject obj2; + obj2.setA(-19); + + // Static context properties + ctxt.setContextProperty("a", QVariant(10)); + ctxt.setContextProperty("b", QVariant(9)); + ctxt2.setContextProperty("b", QVariant(19)); + ctxt2.setContextProperty("c", QVariant(QString("Hello World!"))); + ctxt.setContextProperty("d", &obj1); + ctxt2.setContextProperty("d", &obj2); + ctxt.setContextProperty("e", &obj1); + + TEST_CONTEXT_PROPERTY(&ctxt2, a, QVariant(10)); + TEST_CONTEXT_PROPERTY(&ctxt2, b, QVariant(19)); + TEST_CONTEXT_PROPERTY(&ctxt2, c, QVariant(QString("Hello World!"))); + TEST_CONTEXT_PROPERTY(&ctxt2, d.a, QVariant(-19)); + TEST_CONTEXT_PROPERTY(&ctxt2, e.a, QVariant(3345)); + + ctxt.setContextProperty("a", QVariant(13)); + ctxt.setContextProperty("b", QVariant(4)); + ctxt2.setContextProperty("b", QVariant(8)); + ctxt2.setContextProperty("c", QVariant(QString("Hi World!"))); + ctxt2.setContextProperty("d", &obj1); + obj1.setA(12); + + TEST_CONTEXT_PROPERTY(&ctxt2, a, QVariant(13)); + TEST_CONTEXT_PROPERTY(&ctxt2, b, QVariant(8)); + TEST_CONTEXT_PROPERTY(&ctxt2, c, QVariant(QString("Hi World!"))); + TEST_CONTEXT_PROPERTY(&ctxt2, d.a, QVariant(12)); + TEST_CONTEXT_PROPERTY(&ctxt2, e.a, QVariant(12)); + + // Changes in context properties + { + QmlComponent component(&engine); + component.setData("import Qt 4.6; Object { property var test: a }", QUrl()); + + QObject *obj = component.create(&ctxt2); + + QCOMPARE(obj->property("test"), QVariant(13)); + ctxt.setContextProperty("a", QVariant(19)); + QCOMPARE(obj->property("test"), QVariant(19)); + + delete obj; + } + { + QmlComponent component(&engine); + component.setData("import Qt 4.6; Object { property var test: b }", QUrl()); + + QObject *obj = component.create(&ctxt2); + + QCOMPARE(obj->property("test"), QVariant(8)); + ctxt.setContextProperty("b", QVariant(5)); + QCOMPARE(obj->property("test"), QVariant(8)); + ctxt2.setContextProperty("b", QVariant(1912)); + QCOMPARE(obj->property("test"), QVariant(1912)); + + delete obj; + } + { + QmlComponent component(&engine); + component.setData("import Qt 4.6; Object { property var test: e.a }", QUrl()); + + QObject *obj = component.create(&ctxt2); + + QCOMPARE(obj->property("test"), QVariant(12)); + obj1.setA(13); + QCOMPARE(obj->property("test"), QVariant(13)); + + delete obj; + } + + // New context properties + { + QmlComponent component(&engine); + component.setData("import Qt 4.6; Object { property var test: a }", QUrl()); + + QObject *obj = component.create(&ctxt2); + + QCOMPARE(obj->property("test"), QVariant(19)); + ctxt2.setContextProperty("a", QVariant(1945)); + QCOMPARE(obj->property("test"), QVariant(1945)); + + delete obj; + } +} + +void tst_qmlcontext::addDefaultObject() +{ + QmlContext ctxt(&engine); + + TestObject to; + TestObject2 to2; + + to.setA(2); + to.setB(192); + to.setC(18); + to2.setB(111999); + + ctxt.addDefaultObject(&to2); + ctxt.addDefaultObject(&to); + ctxt.setContextProperty("c", QVariant(9)); + + // Static context properties + TEST_CONTEXT_PROPERTY(&ctxt, a, QVariant(2)); + TEST_CONTEXT_PROPERTY(&ctxt, b, QVariant(111999)); + TEST_CONTEXT_PROPERTY(&ctxt, c, QVariant(9)); + + to.setA(12); + to.setB(100); + to.setC(7); + to2.setB(1612); + ctxt.setContextProperty("c", QVariant(3)); + + TEST_CONTEXT_PROPERTY(&ctxt, a, QVariant(12)); + TEST_CONTEXT_PROPERTY(&ctxt, b, QVariant(1612)); + TEST_CONTEXT_PROPERTY(&ctxt, c, QVariant(3)); + + // Changes in context properties + { + QmlComponent component(&engine); + component.setData("import Qt 4.6; Object { property var test: a }", QUrl()); + + QObject *obj = component.create(&ctxt); + + QCOMPARE(obj->property("test"), QVariant(12)); + to.setA(14); + QCOMPARE(obj->property("test"), QVariant(14)); + + delete obj; + } +} + +QTEST_MAIN(tst_qmlcontext) + +#include "tst_qmlcontext.moc" -- cgit v0.12 From 3dd28725a32c5eae6fa05c2bbe309c7919671cdc Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Mon, 2 Nov 2009 14:33:53 +1000 Subject: add night support for clocks example --- examples/declarative/clocks/content/Clock.qml | 5 ++++- examples/declarative/clocks/content/clock-night.png | Bin 0 -> 23359 bytes examples/declarative/clocks/content/clock.png | Bin 21780 -> 20653 bytes 3 files changed, 4 insertions(+), 1 deletion(-) create mode 100755 examples/declarative/clocks/content/clock-night.png diff --git a/examples/declarative/clocks/content/Clock.qml b/examples/declarative/clocks/content/Clock.qml index 2aac5f1..0c6836f 100644 --- a/examples/declarative/clocks/content/Clock.qml +++ b/examples/declarative/clocks/content/Clock.qml @@ -9,10 +9,12 @@ Item { property var minutes property var seconds property var shift : 0 + property bool night: false function timeChanged() { var date = new Date; hours = shift ? date.getUTCHours() + Math.floor(clock.shift) : date.getHours() + if ( hours < 7 || hours > 19 ) night = true; else night = false minutes = shift ? date.getUTCMinutes() + ((clock.shift % 1) * 60) : date.getMinutes() seconds = date.getUTCSeconds(); } @@ -22,7 +24,8 @@ Item { onTriggered: clock.timeChanged() } - Image { id: background; source: "clock.png" } + Image { id: background; source: "clock.png"; visible: clock.night == false } + Image { source: "clock-night.png"; visible: clock.night == true } Image { x: 92.5; y: 27 diff --git a/examples/declarative/clocks/content/clock-night.png b/examples/declarative/clocks/content/clock-night.png new file mode 100755 index 0000000..cc7151a Binary files /dev/null and b/examples/declarative/clocks/content/clock-night.png differ diff --git a/examples/declarative/clocks/content/clock.png b/examples/declarative/clocks/content/clock.png index 30bc577..462edac 100755 Binary files a/examples/declarative/clocks/content/clock.png and b/examples/declarative/clocks/content/clock.png differ -- cgit v0.12 From 8c39a1ad27594e514afad12fd089ccd988bf4519 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Mon, 2 Nov 2009 15:43:59 +1000 Subject: move smooth example in visual tests --- examples/declarative/smooth/GradientRect.qml | 25 -- examples/declarative/smooth/MyRect.qml | 21 -- examples/declarative/smooth/rect-painting.qml | 64 ---- .../auto/declarative/visual/rect/GradientRect.qml | 25 ++ tests/auto/declarative/visual/rect/MyRect.qml | 21 ++ .../visual/rect/data/rect-painting.0.png | Bin 0 -> 32225 bytes .../declarative/visual/rect/data/rect-painting.qml | 355 +++++++++++++++++++++ .../auto/declarative/visual/rect/rect-painting.qml | 64 ++++ 8 files changed, 465 insertions(+), 110 deletions(-) delete mode 100644 examples/declarative/smooth/GradientRect.qml delete mode 100644 examples/declarative/smooth/MyRect.qml delete mode 100644 examples/declarative/smooth/rect-painting.qml create mode 100644 tests/auto/declarative/visual/rect/GradientRect.qml create mode 100644 tests/auto/declarative/visual/rect/MyRect.qml create mode 100644 tests/auto/declarative/visual/rect/data/rect-painting.0.png create mode 100644 tests/auto/declarative/visual/rect/data/rect-painting.qml create mode 100644 tests/auto/declarative/visual/rect/rect-painting.qml diff --git a/examples/declarative/smooth/GradientRect.qml b/examples/declarative/smooth/GradientRect.qml deleted file mode 100644 index ed56418..0000000 --- a/examples/declarative/smooth/GradientRect.qml +++ /dev/null @@ -1,25 +0,0 @@ -import Qt 4.6 - -Item { - id: rect - property string color - property string border : "" - property int rotation - property int radius - property int borderWidth - property bool smooth: false - - width: 80; height: 80 - Item { - anchors.centerIn: parent; rotation: rect.rotation; - Rectangle { - anchors.centerIn: parent; width: 80; height: 80 - border.color: rect.border; border.width: rect.border != "" ? 2 : 0 - radius: rect.radius; smooth: rect.smooth - gradient: Gradient { - GradientStop { position: 0.0; color: rect.color } - GradientStop { position: 1.0; color: "white" } - } - } - } -} diff --git a/examples/declarative/smooth/MyRect.qml b/examples/declarative/smooth/MyRect.qml deleted file mode 100644 index 9b6c3ae..0000000 --- a/examples/declarative/smooth/MyRect.qml +++ /dev/null @@ -1,21 +0,0 @@ -import Qt 4.6 - -Item { - id: rect - property string color - property string border : "" - property int rotation - property int radius - property int borderWidth - property bool smooth: false - - width: 80; height: 80 - Item { - anchors.centerIn: parent; rotation: rect.rotation; - Rectangle { - anchors.centerIn: parent; width: 80; height: 80 - color: rect.color; border.color: rect.border; border.width: rect.border != "" ? 2 : 0 - radius: rect.radius; smooth: rect.smooth - } - } -} diff --git a/examples/declarative/smooth/rect-painting.qml b/examples/declarative/smooth/rect-painting.qml deleted file mode 100644 index 4b6e223..0000000 --- a/examples/declarative/smooth/rect-painting.qml +++ /dev/null @@ -1,64 +0,0 @@ -import Qt 4.6 - -Rectangle { - width: 900; height: 500 - color: "white" - - Rectangle { - anchors.top: parent.verticalCenter - anchors.left: parent.left - anchors.right: parent.right - anchors.bottom: parent.bottom - color: "#eeeeee" - } - - Grid { - anchors.centerIn: parent - columns: 8; rows:4; spacing: 30 - - MyRect { color: "lightsteelblue" } - MyRect { color: "lightsteelblue"; border: "gray" } - MyRect { color: "lightsteelblue"; radius: 10 } - MyRect { color: "lightsteelblue"; radius: 10; border: "gray" } - GradientRect { color: "lightsteelblue" } - GradientRect { color: "lightsteelblue"; border: "gray" } - GradientRect { color: "lightsteelblue"; radius: 10 } - GradientRect { color: "lightsteelblue"; radius: 10; border: "gray" } - - MyRect { color: "thistle"; rotation: 10 } - MyRect { color: "thistle"; border: "gray"; rotation: 10 } - MyRect { color: "thistle"; radius: 10; rotation: 10 } - MyRect { color: "thistle"; radius: 10; border: "gray"; rotation: 10 } - GradientRect { color: "thistle"; rotation: 10 } - GradientRect { color: "thistle"; border: "gray"; rotation: 10 } - GradientRect { color: "thistle"; radius: 10; rotation: 10 } - GradientRect { color: "thistle"; radius: 10; border: "gray"; rotation: 10 } - - MyRect { color: "lightsteelblue"; smooth: true } - MyRect { color: "lightsteelblue"; border: "gray"; smooth: true } - MyRect { color: "lightsteelblue"; radius: 10; smooth: true } - MyRect { color: "lightsteelblue"; radius: 10; border: "gray"; smooth: true } - GradientRect { color: "lightsteelblue"; smooth: true } - GradientRect { color: "lightsteelblue"; border: "gray"; smooth: true } - GradientRect { color: "lightsteelblue"; radius: 10; smooth: true } - GradientRect { color: "lightsteelblue"; radius: 10; border: "gray"; smooth: true } - - MyRect { color: "thistle"; rotation: 10; smooth: true } - MyRect { color: "thistle"; border: "gray"; rotation: 10; smooth: true } - MyRect { color: "thistle"; radius: 10; rotation: 10; smooth: true } - MyRect { color: "thistle"; radius: 10; border: "gray"; rotation: 10; smooth: true } - GradientRect { color: "thistle"; rotation: 10; smooth: true } - GradientRect { color: "thistle"; border: "gray"; rotation: 10; smooth: true } - GradientRect { color: "thistle"; radius: 10; rotation: 10; smooth: true } - GradientRect { color: "thistle"; radius: 10; border: "gray"; rotation: 10; smooth: true } - } - - Text { - text: "smooth: false"; font.bold: true - anchors.horizontalCenter: parent.horizontalCenter; anchors.top: parent.top - } - Text { - text: "smooth: true"; font.bold: true - anchors.horizontalCenter: parent.horizontalCenter; anchors.bottom: parent.bottom - } -} diff --git a/tests/auto/declarative/visual/rect/GradientRect.qml b/tests/auto/declarative/visual/rect/GradientRect.qml new file mode 100644 index 0000000..ed56418 --- /dev/null +++ b/tests/auto/declarative/visual/rect/GradientRect.qml @@ -0,0 +1,25 @@ +import Qt 4.6 + +Item { + id: rect + property string color + property string border : "" + property int rotation + property int radius + property int borderWidth + property bool smooth: false + + width: 80; height: 80 + Item { + anchors.centerIn: parent; rotation: rect.rotation; + Rectangle { + anchors.centerIn: parent; width: 80; height: 80 + border.color: rect.border; border.width: rect.border != "" ? 2 : 0 + radius: rect.radius; smooth: rect.smooth + gradient: Gradient { + GradientStop { position: 0.0; color: rect.color } + GradientStop { position: 1.0; color: "white" } + } + } + } +} diff --git a/tests/auto/declarative/visual/rect/MyRect.qml b/tests/auto/declarative/visual/rect/MyRect.qml new file mode 100644 index 0000000..9b6c3ae --- /dev/null +++ b/tests/auto/declarative/visual/rect/MyRect.qml @@ -0,0 +1,21 @@ +import Qt 4.6 + +Item { + id: rect + property string color + property string border : "" + property int rotation + property int radius + property int borderWidth + property bool smooth: false + + width: 80; height: 80 + Item { + anchors.centerIn: parent; rotation: rect.rotation; + Rectangle { + anchors.centerIn: parent; width: 80; height: 80 + color: rect.color; border.color: rect.border; border.width: rect.border != "" ? 2 : 0 + radius: rect.radius; smooth: rect.smooth + } + } +} diff --git a/tests/auto/declarative/visual/rect/data/rect-painting.0.png b/tests/auto/declarative/visual/rect/data/rect-painting.0.png new file mode 100644 index 0000000..0b45874 Binary files /dev/null and b/tests/auto/declarative/visual/rect/data/rect-painting.0.png differ diff --git a/tests/auto/declarative/visual/rect/data/rect-painting.qml b/tests/auto/declarative/visual/rect/data/rect-painting.qml new file mode 100644 index 0000000..2c3267e --- /dev/null +++ b/tests/auto/declarative/visual/rect/data/rect-painting.qml @@ -0,0 +1,355 @@ +import Qt.VisualTest 4.6 + +VisualTest { + Frame { + msec: 0 + } + Frame { + msec: 16 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 32 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 48 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 64 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 80 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 96 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 112 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 128 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 144 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 160 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 176 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 192 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 208 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 224 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 240 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 256 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 272 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 288 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 304 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 320 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 336 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 352 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 368 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 384 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 400 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 416 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 432 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 448 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 464 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 480 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 496 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 512 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 528 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 544 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 560 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 576 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 592 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 608 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 624 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 640 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 656 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 672 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 688 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 704 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 720 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 736 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 752 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 768 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 784 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 800 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 816 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 832 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 848 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 864 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 880 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 896 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 912 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 928 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 944 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 960 + image: "rect-painting.0.png" + } + Frame { + msec: 976 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 992 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 1008 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 1024 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 1040 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 1056 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 1072 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 1088 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 1104 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 1120 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 1136 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 1152 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 1168 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 1184 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 1200 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 1216 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 1232 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 1248 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 1264 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 1280 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 1296 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 1312 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Key { + type: 6 + key: 16777249 + modifiers: 67108864 + text: "" + autorep: false + count: 1 + } + Frame { + msec: 1328 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 1344 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } + Frame { + msec: 1360 + hash: "f38360b51d832ed7f70614dfe1964ec8" + } +} diff --git a/tests/auto/declarative/visual/rect/rect-painting.qml b/tests/auto/declarative/visual/rect/rect-painting.qml new file mode 100644 index 0000000..4b6e223 --- /dev/null +++ b/tests/auto/declarative/visual/rect/rect-painting.qml @@ -0,0 +1,64 @@ +import Qt 4.6 + +Rectangle { + width: 900; height: 500 + color: "white" + + Rectangle { + anchors.top: parent.verticalCenter + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: parent.bottom + color: "#eeeeee" + } + + Grid { + anchors.centerIn: parent + columns: 8; rows:4; spacing: 30 + + MyRect { color: "lightsteelblue" } + MyRect { color: "lightsteelblue"; border: "gray" } + MyRect { color: "lightsteelblue"; radius: 10 } + MyRect { color: "lightsteelblue"; radius: 10; border: "gray" } + GradientRect { color: "lightsteelblue" } + GradientRect { color: "lightsteelblue"; border: "gray" } + GradientRect { color: "lightsteelblue"; radius: 10 } + GradientRect { color: "lightsteelblue"; radius: 10; border: "gray" } + + MyRect { color: "thistle"; rotation: 10 } + MyRect { color: "thistle"; border: "gray"; rotation: 10 } + MyRect { color: "thistle"; radius: 10; rotation: 10 } + MyRect { color: "thistle"; radius: 10; border: "gray"; rotation: 10 } + GradientRect { color: "thistle"; rotation: 10 } + GradientRect { color: "thistle"; border: "gray"; rotation: 10 } + GradientRect { color: "thistle"; radius: 10; rotation: 10 } + GradientRect { color: "thistle"; radius: 10; border: "gray"; rotation: 10 } + + MyRect { color: "lightsteelblue"; smooth: true } + MyRect { color: "lightsteelblue"; border: "gray"; smooth: true } + MyRect { color: "lightsteelblue"; radius: 10; smooth: true } + MyRect { color: "lightsteelblue"; radius: 10; border: "gray"; smooth: true } + GradientRect { color: "lightsteelblue"; smooth: true } + GradientRect { color: "lightsteelblue"; border: "gray"; smooth: true } + GradientRect { color: "lightsteelblue"; radius: 10; smooth: true } + GradientRect { color: "lightsteelblue"; radius: 10; border: "gray"; smooth: true } + + MyRect { color: "thistle"; rotation: 10; smooth: true } + MyRect { color: "thistle"; border: "gray"; rotation: 10; smooth: true } + MyRect { color: "thistle"; radius: 10; rotation: 10; smooth: true } + MyRect { color: "thistle"; radius: 10; border: "gray"; rotation: 10; smooth: true } + GradientRect { color: "thistle"; rotation: 10; smooth: true } + GradientRect { color: "thistle"; border: "gray"; rotation: 10; smooth: true } + GradientRect { color: "thistle"; radius: 10; rotation: 10; smooth: true } + GradientRect { color: "thistle"; radius: 10; border: "gray"; rotation: 10; smooth: true } + } + + Text { + text: "smooth: false"; font.bold: true + anchors.horizontalCenter: parent.horizontalCenter; anchors.top: parent.top + } + Text { + text: "smooth: true"; font.bold: true + anchors.horizontalCenter: parent.horizontalCenter; anchors.bottom: parent.bottom + } +} -- cgit v0.12 From d073dfb82c02c1d0a9818525a2a4a4f1adbf44bf Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Mon, 2 Nov 2009 16:47:29 +1000 Subject: renaming QmlGraphicsRect -> QmlGraphicsRectangle --- src/declarative/graphicsitems/graphicsitems.pri | 6 +- src/declarative/graphicsitems/qmlgraphicsrect.cpp | 475 --------------------- src/declarative/graphicsitems/qmlgraphicsrect_p.h | 189 -------- .../graphicsitems/qmlgraphicsrect_p_p.h | 109 ----- .../graphicsitems/qmlgraphicsrectangle.cpp | 475 +++++++++++++++++++++ .../graphicsitems/qmlgraphicsrectangle_p.h | 189 ++++++++ .../graphicsitems/qmlgraphicsrectangle_p_p.h | 109 +++++ tests/auto/declarative/anchors/tst_anchors.cpp | 54 +-- .../auto/declarative/animations/tst_animations.cpp | 22 +- tests/auto/declarative/behaviors/tst_behaviors.cpp | 30 +- tests/auto/declarative/layouts/tst_layouts.cpp | 44 +- tests/auto/declarative/pathview/tst_pathview.cpp | 18 +- .../declarative/qmllanguage/tst_qmllanguage.cpp | 14 +- tests/auto/declarative/states/tst_states.cpp | 22 +- tests/benchmarks/qmlpainting/tst_qmlpainting.cpp | 6 +- 15 files changed, 881 insertions(+), 881 deletions(-) delete mode 100644 src/declarative/graphicsitems/qmlgraphicsrect.cpp delete mode 100644 src/declarative/graphicsitems/qmlgraphicsrect_p.h delete mode 100644 src/declarative/graphicsitems/qmlgraphicsrect_p_p.h create mode 100644 src/declarative/graphicsitems/qmlgraphicsrectangle.cpp create mode 100644 src/declarative/graphicsitems/qmlgraphicsrectangle_p.h create mode 100644 src/declarative/graphicsitems/qmlgraphicsrectangle_p_p.h diff --git a/src/declarative/graphicsitems/graphicsitems.pri b/src/declarative/graphicsitems/graphicsitems.pri index 8eac580..15d775c 100644 --- a/src/declarative/graphicsitems/graphicsitems.pri +++ b/src/declarative/graphicsitems/graphicsitems.pri @@ -28,8 +28,8 @@ HEADERS += \ graphicsitems/qmlgraphicspath_p_p.h \ graphicsitems/qmlgraphicspathview_p.h \ graphicsitems/qmlgraphicspathview_p_p.h \ - graphicsitems/qmlgraphicsrect_p.h \ - graphicsitems/qmlgraphicsrect_p_p.h \ + graphicsitems/qmlgraphicsrectangle_p.h \ + graphicsitems/qmlgraphicsrectangle_p_p.h \ graphicsitems/qmlgraphicsrepeater_p.h \ graphicsitems/qmlgraphicsrepeater_p_p.h \ graphicsitems/qmlgraphicsscalegrid_p_p.h \ @@ -64,7 +64,7 @@ SOURCES += \ graphicsitems/qmlgraphicsmouseregion.cpp \ graphicsitems/qmlgraphicspath.cpp \ graphicsitems/qmlgraphicspathview.cpp \ - graphicsitems/qmlgraphicsrect.cpp \ + graphicsitems/qmlgraphicsrectangle.cpp \ graphicsitems/qmlgraphicsrepeater.cpp \ graphicsitems/qmlgraphicsscalegrid.cpp \ graphicsitems/qmlgraphicstextinput.cpp \ diff --git a/src/declarative/graphicsitems/qmlgraphicsrect.cpp b/src/declarative/graphicsitems/qmlgraphicsrect.cpp deleted file mode 100644 index 605e82c..0000000 --- a/src/declarative/graphicsitems/qmlgraphicsrect.cpp +++ /dev/null @@ -1,475 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the 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 "qmlgraphicsrect_p.h" -#include "qmlgraphicsrect_p_p.h" - -#include -#include - -QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Pen,QmlGraphicsPen) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,GradientStop,QmlGraphicsGradientStop) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Gradient,QmlGraphicsGradient) - -/*! - \internal - \class QmlGraphicsPen - \brief The QmlGraphicsPen class provides a pen used for drawing rectangle borders on a QmlView. - - By default, the pen is invalid and nothing is drawn. You must either set a color (then the default - width is 1) or a width (then the default color is black). - - A width of 1 indicates is a single-pixel line on the border of the item being painted. - - Example: - \qml - Rectangle { border.width: 2; border.color: "red" ... } - \endqml -*/ - -void QmlGraphicsPen::setColor(const QColor &c) -{ - _color = c; - _valid = _color.alpha() ? true : false; - emit penChanged(); -} - -void QmlGraphicsPen::setWidth(int w) -{ - if (_width == w && _valid) - return; - - _width = w; - _valid = (_width < 1) ? false : true; - emit penChanged(); -} - - -/*! - \qmlclass GradientStop QmlGraphicsGradientStop - \brief The GradientStop item defines the color at a position in a Gradient - - \sa Gradient -*/ - -/*! - \qmlproperty real GradientStop::position - \qmlproperty color GradientStop::color - - Sets a \e color at a \e position in a gradient. -*/ - -void QmlGraphicsGradientStop::updateGradient() -{ - if (QmlGraphicsGradient *grad = qobject_cast(parent())) - grad->doUpdate(); -} - -/*! - \qmlclass Gradient QmlGraphicsGradient - \brief The Gradient item defines a gradient fill. - - A gradient is defined by two or more colors, which will be blended seemlessly. The - colors are specified at their position in the range 0.0 - 1.0 via - the GradientStop item. For example, the following code paints a - rectangle with a gradient starting with red, blending to yellow at 1/3 of the - size of the rectangle, and ending with Green: - - \table - \row - \o \image gradient.png - \o \quotefile doc/src/snippets/declarative/gradient.qml - \endtable - - \sa GradientStop -*/ - -/*! - \qmlproperty list Gradient::stops - This property holds the gradient stops describing the gradient. -*/ - -const QGradient *QmlGraphicsGradient::gradient() const -{ - if (!m_gradient && !m_stops.isEmpty()) { - m_gradient = new QLinearGradient(0,0,0,1.0); - for (int i = 0; i < m_stops.count(); ++i) { - const QmlGraphicsGradientStop *stop = m_stops.at(i); - m_gradient->setCoordinateMode(QGradient::ObjectBoundingMode); - m_gradient->setColorAt(stop->position(), stop->color()); - } - } - - return m_gradient; -} - -void QmlGraphicsGradient::doUpdate() -{ - delete m_gradient; - m_gradient = 0; - emit updated(); -} - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Rectangle,QmlGraphicsRect) - -/*! - \qmlclass Rectangle QmlGraphicsRect - \brief The Rectangle item allows you to add rectangles to a scene. - \inherits Item - - A Rectangle is painted having a solid fill (color) and an optional border. - You can also create rounded rectangles using the radius property. - - \qml - Rectangle { - width: 100 - height: 100 - color: "red" - border.color: "black" - border.width: 5 - radius: 10 - } - \endqml - - \image declarative-rect.png -*/ - -/*! - \internal - \class QmlGraphicsRect - \brief The QmlGraphicsRect class provides a rectangle item that you can add to a QmlView. -*/ -QmlGraphicsRect::QmlGraphicsRect(QmlGraphicsItem *parent) - : QmlGraphicsItem(*(new QmlGraphicsRectPrivate), parent) -{ - Q_D(QmlGraphicsRect); - d->init(); - setFlag(QGraphicsItem::ItemHasNoContents, false); -} - -QmlGraphicsRect::QmlGraphicsRect(QmlGraphicsRectPrivate &dd, QmlGraphicsItem *parent) - : QmlGraphicsItem(dd, parent) -{ - Q_D(QmlGraphicsRect); - d->init(); - setFlag(QGraphicsItem::ItemHasNoContents, false); -} - -void QmlGraphicsRect::doUpdate() -{ - Q_D(QmlGraphicsRect); - d->rectImage = QPixmap(); - const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; - d->setPaintMargin((pw+1)/2); - update(); -} - -/*! - \qmlproperty int Rectangle::border.width - \qmlproperty color Rectangle::border.color - - The width and color used to draw the border of the rectangle. - - A width of 1 creates a thin line. For no line, use a width of 0 or a transparent color. - - To keep the border smooth (rather than blurry), odd widths cause the rectangle to be painted at - a half-pixel offset; -*/ -QmlGraphicsPen *QmlGraphicsRect::border() -{ - Q_D(QmlGraphicsRect); - return d->getPen(); -} - -/*! - \qmlproperty Gradient Rectangle::gradient - - The gradient to use to fill the rectangle. - - This property allows for the construction of simple vertical gradients. - Other gradients may by formed by adding rotation to the rectangle. - - \table - \row - \o \image declarative-rect_gradient.png - \o - \qml - Rectangle { y: 0; width: 80; height: 80; color: "lightsteelblue" } - Rectangle { y: 100; width: 80; height: 80 - gradient: Gradient { - GradientStop { position: 0.0; color: "lightsteelblue" } - GradientStop { position: 1.0; color: "blue" } - } - } - Rectangle { rotation: 90; x: 80; y: 200; width: 80; height: 80 - gradient: Gradient { - GradientStop { position: 0.0; color: "lightsteelblue" } - GradientStop { position: 1.0; color: "blue" } - } - } - // The x offset is needed because the rotation is from the top left corner - \endqml - \endtable - - If both a gradient and a color are specified, the gradient will be used. - - \sa Gradient, color -*/ -QmlGraphicsGradient *QmlGraphicsRect::gradient() const -{ - Q_D(const QmlGraphicsRect); - return d->gradient; -} - -void QmlGraphicsRect::setGradient(QmlGraphicsGradient *gradient) -{ - Q_D(QmlGraphicsRect); - if (d->gradient == gradient) - return; - if (d->gradient) - disconnect(d->gradient, SIGNAL(updated()), this, SLOT(doUpdate())); - d->gradient = gradient; - if (d->gradient) - connect(d->gradient, SIGNAL(updated()), this, SLOT(doUpdate())); - update(); -} - - -/*! - \qmlproperty real Rectangle::radius - This property holds the corner radius used to draw a rounded rectangle. - - If radius is non-zero, the rectangle will be painted as a rounded rectangle, otherwise it will be - painted as a normal rectangle. The same radius is used by all 4 corners; there is currently - no way to specify different radii for different corners. -*/ -qreal QmlGraphicsRect::radius() const -{ - Q_D(const QmlGraphicsRect); - return d->radius; -} - -void QmlGraphicsRect::setRadius(qreal radius) -{ - Q_D(QmlGraphicsRect); - if (d->radius == radius) - return; - - d->radius = radius; - d->rectImage = QPixmap(); - update(); - emit radiusChanged(); -} - -/*! - \qmlproperty color Rectangle::color - This property holds the color used to fill the rectangle. - - \qml - // green rectangle using hexidecimal notation - Rectangle { color: "#00FF00" } - - // steelblue rectangle using SVG color name - Rectangle { color: "steelblue" } - \endqml - - The default color is white. - - If both a gradient and a color are specified, the gradient will be used. -*/ -QColor QmlGraphicsRect::color() const -{ - Q_D(const QmlGraphicsRect); - return d->color; -} - -void QmlGraphicsRect::setColor(const QColor &c) -{ - Q_D(QmlGraphicsRect); - if (d->color == c) - return; - - d->color = c; - d->rectImage = QPixmap(); - update(); - emit colorChanged(); -} - -void QmlGraphicsRect::generateRoundedRect() -{ - Q_D(QmlGraphicsRect); - if (d->rectImage.isNull()) { - const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; - const int radius = qCeil(d->radius); //ensure odd numbered width/height so we get 1-pixel center - d->rectImage = QPixmap(radius*2 + 3 + pw*2, radius*2 + 3 + pw*2); - d->rectImage.fill(Qt::transparent); - QPainter p(&(d->rectImage)); - p.setRenderHint(QPainter::Antialiasing); - if (d->pen && d->pen->isValid()) { - QPen pn(QColor(d->pen->color()), d->pen->width()); - p.setPen(pn); - } else { - p.setPen(Qt::NoPen); - } - p.setBrush(d->color); - if (pw%2) - p.drawRoundedRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, d->rectImage.width()-(pw+1), d->rectImage.height()-(pw+1)), d->radius, d->radius); - else - p.drawRoundedRect(QRectF(qreal(pw)/2, qreal(pw)/2, d->rectImage.width()-pw, d->rectImage.height()-pw), d->radius, d->radius); - } -} - -void QmlGraphicsRect::generateBorderedRect() -{ - Q_D(QmlGraphicsRect); - if (d->rectImage.isNull()) { - const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; - d->rectImage = QPixmap(pw*2 + 3, pw*2 + 3); - d->rectImage.fill(Qt::transparent); - QPainter p(&(d->rectImage)); - p.setRenderHint(QPainter::Antialiasing); - if (d->pen && d->pen->isValid()) { - QPen pn(QColor(d->pen->color()), d->pen->width()); - pn.setJoinStyle(Qt::MiterJoin); - p.setPen(pn); - } else { - p.setPen(Qt::NoPen); - } - p.setBrush(d->color); - if (pw%2) - p.drawRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, d->rectImage.width()-(pw+1), d->rectImage.height()-(pw+1))); - else - p.drawRect(QRectF(qreal(pw)/2, qreal(pw)/2, d->rectImage.width()-pw, d->rectImage.height()-pw)); - } -} - -void QmlGraphicsRect::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) -{ - Q_D(QmlGraphicsRect); - if (d->radius > 0 || (d->pen && d->pen->isValid()) - || (d->gradient && d->gradient->gradient()) ) { - drawRect(*p); - } - else { - bool oldAA = p->testRenderHint(QPainter::Antialiasing); - if (d->smooth) - p->setRenderHints(QPainter::Antialiasing, true); - p->fillRect(QRectF(0, 0, width(), height()), d->color); - if (d->smooth) - p->setRenderHint(QPainter::Antialiasing, oldAA); - } -} - -void QmlGraphicsRect::drawRect(QPainter &p) -{ - Q_D(QmlGraphicsRect); - if (d->gradient && d->gradient->gradient()) { - // XXX This path is still slower than the image path - // Image path won't work for gradients though - bool oldAA = p.testRenderHint(QPainter::Antialiasing); - if (d->smooth) - p.setRenderHint(QPainter::Antialiasing); - if (d->pen && d->pen->isValid()) { - QPen pn(QColor(d->pen->color()), d->pen->width()); - p.setPen(pn); - } else { - p.setPen(Qt::NoPen); - } - p.setBrush(*d->gradient->gradient()); - if (d->radius > 0.) - p.drawRoundedRect(0, 0, width(), height(), d->radius, d->radius); - else - p.drawRect(0, 0, width(), height()); - if (d->smooth) - p.setRenderHint(QPainter::Antialiasing, oldAA); - } else { - bool oldAA = p.testRenderHint(QPainter::Antialiasing); - bool oldSmooth = p.testRenderHint(QPainter::SmoothPixmapTransform); - if (d->smooth) - p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth); - - const int pw = d->pen && d->pen->isValid() ? (d->pen->width()+1)/2*2 : 0; - - if (d->radius > 0) - generateRoundedRect(); - else - generateBorderedRect(); - - int xOffset = (d->rectImage.width()-1)/2; - int yOffset = (d->rectImage.height()-1)/2; - Q_ASSERT(d->rectImage.width() == 2*xOffset + 1); - Q_ASSERT(d->rectImage.height() == 2*yOffset + 1); - - QMargins margins(xOffset, yOffset, xOffset, yOffset); - QTileRules rules(Qt::StretchTile, Qt::StretchTile); - //NOTE: even though our item may have qreal-based width and height, qDrawBorderPixmap only supports QRects - qDrawBorderPixmap(&p, QRect(-pw/2, -pw/2, width()+pw, height()+pw), margins, d->rectImage, d->rectImage.rect(), margins, rules); - - if (d->smooth) { - p.setRenderHint(QPainter::Antialiasing, oldAA); - p.setRenderHint(QPainter::SmoothPixmapTransform, oldSmooth); - } - } -} - -/*! - \qmlproperty bool Rectangle::smooth - - Set this property if you want the item to be smoothly scaled or - transformed. Smooth filtering gives better visual quality, but is slower. If - the item is displayed at its natural size, this property has no visual or - performance effect. - - \note Generally scaling artifacts are only visible if the item is stationary on - the screen. A common pattern when animating an item is to disable smooth - filtering at the beginning of the animation and reenable it at the conclusion. - - \image rect-smooth.png -*/ - -QRectF QmlGraphicsRect::boundingRect() const -{ - Q_D(const QmlGraphicsRect); - return QRectF(-d->paintmargin, -d->paintmargin, d->width+d->paintmargin*2, d->height+d->paintmargin*2); -} - -QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qmlgraphicsrect_p.h b/src/declarative/graphicsitems/qmlgraphicsrect_p.h deleted file mode 100644 index 97334fd..0000000 --- a/src/declarative/graphicsitems/qmlgraphicsrect_p.h +++ /dev/null @@ -1,189 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the 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 QMLGRAPHICSRECT_H -#define QMLGRAPHICSRECT_H - -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class Q_DECLARATIVE_EXPORT QmlGraphicsPen : public QObject -{ - Q_OBJECT - - Q_PROPERTY(int width READ width WRITE setWidth NOTIFY penChanged) - Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY penChanged) -public: - QmlGraphicsPen(QObject *parent=0) - : QObject(parent), _width(1), _color("#000000"), _valid(false) - {} - - int width() const { return _width; } - void setWidth(int w); - - QColor color() const { return _color; } - void setColor(const QColor &c); - - bool isValid() { return _valid; }; - -Q_SIGNALS: - void penChanged(); - -private: - int _width; - QColor _color; - bool _valid; -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsGradientStop : public QObject -{ - Q_OBJECT - - Q_PROPERTY(qreal position READ position WRITE setPosition) - Q_PROPERTY(QColor color READ color WRITE setColor) - -public: - QmlGraphicsGradientStop(QObject *parent=0) : QObject(parent) {} - - qreal position() const { return m_position; } - void setPosition(qreal position) { m_position = position; updateGradient(); } - - QColor color() const { return m_color; } - void setColor(const QColor &color) { m_color = color; updateGradient(); } - -private: - void updateGradient(); - -private: - qreal m_position; - QColor m_color; -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsGradient : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QList *stops READ stops) - Q_CLASSINFO("DefaultProperty", "stops") - -public: - QmlGraphicsGradient(QObject *parent=0) : QObject(parent), m_gradient(0) {} - ~QmlGraphicsGradient() { delete m_gradient; } - - QList *stops() { return &m_stops; } - - const QGradient *gradient() const; - -Q_SIGNALS: - void updated(); - -private: - void doUpdate(); - -private: - QList m_stops; - mutable QGradient *m_gradient; - friend class QmlGraphicsGradientStop; -}; - -class QmlGraphicsRectPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsRect : public QmlGraphicsItem -{ - Q_OBJECT - - Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) - Q_PROPERTY(QmlGraphicsGradient *gradient READ gradient WRITE setGradient) - Q_PROPERTY(QmlGraphicsPen * border READ border CONSTANT) - Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged) -public: - QmlGraphicsRect(QmlGraphicsItem *parent=0); - - QColor color() const; - void setColor(const QColor &); - - QmlGraphicsPen *border(); - - QmlGraphicsGradient *gradient() const; - void setGradient(QmlGraphicsGradient *gradient); - - qreal radius() const; - void setRadius(qreal radius); - - QRectF boundingRect() const; - - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - -Q_SIGNALS: - void colorChanged(); - void radiusChanged(); - -private Q_SLOTS: - void doUpdate(); - -private: - void generateRoundedRect(); - void generateBorderedRect(); - void drawRect(QPainter &painter); - -protected: - QmlGraphicsRect(QmlGraphicsRectPrivate &dd, QmlGraphicsItem *parent); - -private: - Q_DISABLE_COPY(QmlGraphicsRect) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsRect) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsPen) -QML_DECLARE_TYPE(QmlGraphicsGradientStop) -QML_DECLARE_TYPE(QmlGraphicsGradient) -QML_DECLARE_TYPE(QmlGraphicsRect) - -QT_END_HEADER - -#endif // QMLGRAPHICSRECT_H diff --git a/src/declarative/graphicsitems/qmlgraphicsrect_p_p.h b/src/declarative/graphicsitems/qmlgraphicsrect_p_p.h deleted file mode 100644 index f44e8de..0000000 --- a/src/declarative/graphicsitems/qmlgraphicsrect_p_p.h +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (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 either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** 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.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMLGRAPHICSRECT_P_H -#define QMLGRAPHICSRECT_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qmlgraphicsitem_p.h" - -QT_BEGIN_NAMESPACE - -class QmlGraphicsGradient; -class QmlGraphicsRect; -class QmlGraphicsRectPrivate : public QmlGraphicsItemPrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsRect) - -public: - QmlGraphicsRectPrivate() : - color(Qt::white), gradient(0), pen(0), radius(0), paintmargin(0) - { - } - - ~QmlGraphicsRectPrivate() - { - delete pen; - } - - void init() - { - } - - QColor getColor(); - QColor color; - QmlGraphicsGradient *gradient; - QmlGraphicsPen *getPen() { - if (!pen) { - Q_Q(QmlGraphicsRect); - pen = new QmlGraphicsPen; - QObject::connect(pen, SIGNAL(penChanged()), q, SLOT(doUpdate())); - } - return pen; - } - QmlGraphicsPen *pen; - qreal radius; - qreal paintmargin; - QPixmap rectImage; - - void setPaintMargin(qreal margin) - { - Q_Q(QmlGraphicsRect); - if (margin == paintmargin) - return; - q->prepareGeometryChange(); - paintmargin = margin; - } -}; - -QT_END_NAMESPACE - -#endif // QMLGRAPHICSRECT_P_H diff --git a/src/declarative/graphicsitems/qmlgraphicsrectangle.cpp b/src/declarative/graphicsitems/qmlgraphicsrectangle.cpp new file mode 100644 index 0000000..8ae40b7 --- /dev/null +++ b/src/declarative/graphicsitems/qmlgraphicsrectangle.cpp @@ -0,0 +1,475 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the 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 "qmlgraphicsrectangle_p.h" +#include "qmlgraphicsrectangle_p_p.h" + +#include +#include + +QT_BEGIN_NAMESPACE +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Pen,QmlGraphicsPen) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,GradientStop,QmlGraphicsGradientStop) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Gradient,QmlGraphicsGradient) + +/*! + \internal + \class QmlGraphicsPen + \brief The QmlGraphicsPen class provides a pen used for drawing rectangle borders on a QmlView. + + By default, the pen is invalid and nothing is drawn. You must either set a color (then the default + width is 1) or a width (then the default color is black). + + A width of 1 indicates is a single-pixel line on the border of the item being painted. + + Example: + \qml + Rectangle { border.width: 2; border.color: "red" ... } + \endqml +*/ + +void QmlGraphicsPen::setColor(const QColor &c) +{ + _color = c; + _valid = _color.alpha() ? true : false; + emit penChanged(); +} + +void QmlGraphicsPen::setWidth(int w) +{ + if (_width == w && _valid) + return; + + _width = w; + _valid = (_width < 1) ? false : true; + emit penChanged(); +} + + +/*! + \qmlclass GradientStop QmlGraphicsGradientStop + \brief The GradientStop item defines the color at a position in a Gradient + + \sa Gradient +*/ + +/*! + \qmlproperty real GradientStop::position + \qmlproperty color GradientStop::color + + Sets a \e color at a \e position in a gradient. +*/ + +void QmlGraphicsGradientStop::updateGradient() +{ + if (QmlGraphicsGradient *grad = qobject_cast(parent())) + grad->doUpdate(); +} + +/*! + \qmlclass Gradient QmlGraphicsGradient + \brief The Gradient item defines a gradient fill. + + A gradient is defined by two or more colors, which will be blended seemlessly. The + colors are specified at their position in the range 0.0 - 1.0 via + the GradientStop item. For example, the following code paints a + rectangle with a gradient starting with red, blending to yellow at 1/3 of the + size of the rectangle, and ending with Green: + + \table + \row + \o \image gradient.png + \o \quotefile doc/src/snippets/declarative/gradient.qml + \endtable + + \sa GradientStop +*/ + +/*! + \qmlproperty list Gradient::stops + This property holds the gradient stops describing the gradient. +*/ + +const QGradient *QmlGraphicsGradient::gradient() const +{ + if (!m_gradient && !m_stops.isEmpty()) { + m_gradient = new QLinearGradient(0,0,0,1.0); + for (int i = 0; i < m_stops.count(); ++i) { + const QmlGraphicsGradientStop *stop = m_stops.at(i); + m_gradient->setCoordinateMode(QGradient::ObjectBoundingMode); + m_gradient->setColorAt(stop->position(), stop->color()); + } + } + + return m_gradient; +} + +void QmlGraphicsGradient::doUpdate() +{ + delete m_gradient; + m_gradient = 0; + emit updated(); +} + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Rectangle,QmlGraphicsRectangle) + +/*! + \qmlclass Rectangle QmlGraphicsRectangle + \brief The Rectangle item allows you to add rectangles to a scene. + \inherits Item + + A Rectangle is painted having a solid fill (color) and an optional border. + You can also create rounded rectangles using the radius property. + + \qml + Rectangle { + width: 100 + height: 100 + color: "red" + border.color: "black" + border.width: 5 + radius: 10 + } + \endqml + + \image declarative-rect.png +*/ + +/*! + \internal + \class QmlGraphicsRectangle + \brief The QmlGraphicsRectangle class provides a rectangle item that you can add to a QmlView. +*/ +QmlGraphicsRectangle::QmlGraphicsRectangle(QmlGraphicsItem *parent) + : QmlGraphicsItem(*(new QmlGraphicsRectanglePrivate), parent) +{ + Q_D(QmlGraphicsRectangle); + d->init(); + setFlag(QGraphicsItem::ItemHasNoContents, false); +} + +QmlGraphicsRectangle::QmlGraphicsRectangle(QmlGraphicsRectanglePrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsItem(dd, parent) +{ + Q_D(QmlGraphicsRectangle); + d->init(); + setFlag(QGraphicsItem::ItemHasNoContents, false); +} + +void QmlGraphicsRectangle::doUpdate() +{ + Q_D(QmlGraphicsRectangle); + d->rectImage = QPixmap(); + const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; + d->setPaintMargin((pw+1)/2); + update(); +} + +/*! + \qmlproperty int Rectangle::border.width + \qmlproperty color Rectangle::border.color + + The width and color used to draw the border of the rectangle. + + A width of 1 creates a thin line. For no line, use a width of 0 or a transparent color. + + To keep the border smooth (rather than blurry), odd widths cause the rectangle to be painted at + a half-pixel offset; +*/ +QmlGraphicsPen *QmlGraphicsRectangle::border() +{ + Q_D(QmlGraphicsRectangle); + return d->getPen(); +} + +/*! + \qmlproperty Gradient Rectangle::gradient + + The gradient to use to fill the rectangle. + + This property allows for the construction of simple vertical gradients. + Other gradients may by formed by adding rotation to the rectangle. + + \table + \row + \o \image declarative-rect_gradient.png + \o + \qml + Rectangle { y: 0; width: 80; height: 80; color: "lightsteelblue" } + Rectangle { y: 100; width: 80; height: 80 + gradient: Gradient { + GradientStop { position: 0.0; color: "lightsteelblue" } + GradientStop { position: 1.0; color: "blue" } + } + } + Rectangle { rotation: 90; x: 80; y: 200; width: 80; height: 80 + gradient: Gradient { + GradientStop { position: 0.0; color: "lightsteelblue" } + GradientStop { position: 1.0; color: "blue" } + } + } + // The x offset is needed because the rotation is from the top left corner + \endqml + \endtable + + If both a gradient and a color are specified, the gradient will be used. + + \sa Gradient, color +*/ +QmlGraphicsGradient *QmlGraphicsRectangle::gradient() const +{ + Q_D(const QmlGraphicsRectangle); + return d->gradient; +} + +void QmlGraphicsRectangle::setGradient(QmlGraphicsGradient *gradient) +{ + Q_D(QmlGraphicsRectangle); + if (d->gradient == gradient) + return; + if (d->gradient) + disconnect(d->gradient, SIGNAL(updated()), this, SLOT(doUpdate())); + d->gradient = gradient; + if (d->gradient) + connect(d->gradient, SIGNAL(updated()), this, SLOT(doUpdate())); + update(); +} + + +/*! + \qmlproperty real Rectangle::radius + This property holds the corner radius used to draw a rounded rectangle. + + If radius is non-zero, the rectangle will be painted as a rounded rectangle, otherwise it will be + painted as a normal rectangle. The same radius is used by all 4 corners; there is currently + no way to specify different radii for different corners. +*/ +qreal QmlGraphicsRectangle::radius() const +{ + Q_D(const QmlGraphicsRectangle); + return d->radius; +} + +void QmlGraphicsRectangle::setRadius(qreal radius) +{ + Q_D(QmlGraphicsRectangle); + if (d->radius == radius) + return; + + d->radius = radius; + d->rectImage = QPixmap(); + update(); + emit radiusChanged(); +} + +/*! + \qmlproperty color Rectangle::color + This property holds the color used to fill the rectangle. + + \qml + // green rectangle using hexidecimal notation + Rectangle { color: "#00FF00" } + + // steelblue rectangle using SVG color name + Rectangle { color: "steelblue" } + \endqml + + The default color is white. + + If both a gradient and a color are specified, the gradient will be used. +*/ +QColor QmlGraphicsRectangle::color() const +{ + Q_D(const QmlGraphicsRectangle); + return d->color; +} + +void QmlGraphicsRectangle::setColor(const QColor &c) +{ + Q_D(QmlGraphicsRectangle); + if (d->color == c) + return; + + d->color = c; + d->rectImage = QPixmap(); + update(); + emit colorChanged(); +} + +void QmlGraphicsRectangle::generateRoundedRect() +{ + Q_D(QmlGraphicsRectangle); + if (d->rectImage.isNull()) { + const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; + const int radius = qCeil(d->radius); //ensure odd numbered width/height so we get 1-pixel center + d->rectImage = QPixmap(radius*2 + 3 + pw*2, radius*2 + 3 + pw*2); + d->rectImage.fill(Qt::transparent); + QPainter p(&(d->rectImage)); + p.setRenderHint(QPainter::Antialiasing); + if (d->pen && d->pen->isValid()) { + QPen pn(QColor(d->pen->color()), d->pen->width()); + p.setPen(pn); + } else { + p.setPen(Qt::NoPen); + } + p.setBrush(d->color); + if (pw%2) + p.drawRoundedRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, d->rectImage.width()-(pw+1), d->rectImage.height()-(pw+1)), d->radius, d->radius); + else + p.drawRoundedRect(QRectF(qreal(pw)/2, qreal(pw)/2, d->rectImage.width()-pw, d->rectImage.height()-pw), d->radius, d->radius); + } +} + +void QmlGraphicsRectangle::generateBorderedRect() +{ + Q_D(QmlGraphicsRectangle); + if (d->rectImage.isNull()) { + const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; + d->rectImage = QPixmap(pw*2 + 3, pw*2 + 3); + d->rectImage.fill(Qt::transparent); + QPainter p(&(d->rectImage)); + p.setRenderHint(QPainter::Antialiasing); + if (d->pen && d->pen->isValid()) { + QPen pn(QColor(d->pen->color()), d->pen->width()); + pn.setJoinStyle(Qt::MiterJoin); + p.setPen(pn); + } else { + p.setPen(Qt::NoPen); + } + p.setBrush(d->color); + if (pw%2) + p.drawRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, d->rectImage.width()-(pw+1), d->rectImage.height()-(pw+1))); + else + p.drawRect(QRectF(qreal(pw)/2, qreal(pw)/2, d->rectImage.width()-pw, d->rectImage.height()-pw)); + } +} + +void QmlGraphicsRectangle::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) +{ + Q_D(QmlGraphicsRectangle); + if (d->radius > 0 || (d->pen && d->pen->isValid()) + || (d->gradient && d->gradient->gradient()) ) { + drawRect(*p); + } + else { + bool oldAA = p->testRenderHint(QPainter::Antialiasing); + if (d->smooth) + p->setRenderHints(QPainter::Antialiasing, true); + p->fillRect(QRectF(0, 0, width(), height()), d->color); + if (d->smooth) + p->setRenderHint(QPainter::Antialiasing, oldAA); + } +} + +void QmlGraphicsRectangle::drawRect(QPainter &p) +{ + Q_D(QmlGraphicsRectangle); + if (d->gradient && d->gradient->gradient()) { + // XXX This path is still slower than the image path + // Image path won't work for gradients though + bool oldAA = p.testRenderHint(QPainter::Antialiasing); + if (d->smooth) + p.setRenderHint(QPainter::Antialiasing); + if (d->pen && d->pen->isValid()) { + QPen pn(QColor(d->pen->color()), d->pen->width()); + p.setPen(pn); + } else { + p.setPen(Qt::NoPen); + } + p.setBrush(*d->gradient->gradient()); + if (d->radius > 0.) + p.drawRoundedRect(0, 0, width(), height(), d->radius, d->radius); + else + p.drawRect(0, 0, width(), height()); + if (d->smooth) + p.setRenderHint(QPainter::Antialiasing, oldAA); + } else { + bool oldAA = p.testRenderHint(QPainter::Antialiasing); + bool oldSmooth = p.testRenderHint(QPainter::SmoothPixmapTransform); + if (d->smooth) + p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth); + + const int pw = d->pen && d->pen->isValid() ? (d->pen->width()+1)/2*2 : 0; + + if (d->radius > 0) + generateRoundedRect(); + else + generateBorderedRect(); + + int xOffset = (d->rectImage.width()-1)/2; + int yOffset = (d->rectImage.height()-1)/2; + Q_ASSERT(d->rectImage.width() == 2*xOffset + 1); + Q_ASSERT(d->rectImage.height() == 2*yOffset + 1); + + QMargins margins(xOffset, yOffset, xOffset, yOffset); + QTileRules rules(Qt::StretchTile, Qt::StretchTile); + //NOTE: even though our item may have qreal-based width and height, qDrawBorderPixmap only supports QRects + qDrawBorderPixmap(&p, QRect(-pw/2, -pw/2, width()+pw, height()+pw), margins, d->rectImage, d->rectImage.rect(), margins, rules); + + if (d->smooth) { + p.setRenderHint(QPainter::Antialiasing, oldAA); + p.setRenderHint(QPainter::SmoothPixmapTransform, oldSmooth); + } + } +} + +/*! + \qmlproperty bool Rectangle::smooth + + Set this property if you want the item to be smoothly scaled or + transformed. Smooth filtering gives better visual quality, but is slower. If + the item is displayed at its natural size, this property has no visual or + performance effect. + + \note Generally scaling artifacts are only visible if the item is stationary on + the screen. A common pattern when animating an item is to disable smooth + filtering at the beginning of the animation and reenable it at the conclusion. + + \image rect-smooth.png +*/ + +QRectF QmlGraphicsRectangle::boundingRect() const +{ + Q_D(const QmlGraphicsRectangle); + return QRectF(-d->paintmargin, -d->paintmargin, d->width+d->paintmargin*2, d->height+d->paintmargin*2); +} + +QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qmlgraphicsrectangle_p.h b/src/declarative/graphicsitems/qmlgraphicsrectangle_p.h new file mode 100644 index 0000000..2a80619 --- /dev/null +++ b/src/declarative/graphicsitems/qmlgraphicsrectangle_p.h @@ -0,0 +1,189 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the 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 QMLGRAPHICSRECT_H +#define QMLGRAPHICSRECT_H + +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) +class Q_DECLARATIVE_EXPORT QmlGraphicsPen : public QObject +{ + Q_OBJECT + + Q_PROPERTY(int width READ width WRITE setWidth NOTIFY penChanged) + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY penChanged) +public: + QmlGraphicsPen(QObject *parent=0) + : QObject(parent), _width(1), _color("#000000"), _valid(false) + {} + + int width() const { return _width; } + void setWidth(int w); + + QColor color() const { return _color; } + void setColor(const QColor &c); + + bool isValid() { return _valid; }; + +Q_SIGNALS: + void penChanged(); + +private: + int _width; + QColor _color; + bool _valid; +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsGradientStop : public QObject +{ + Q_OBJECT + + Q_PROPERTY(qreal position READ position WRITE setPosition) + Q_PROPERTY(QColor color READ color WRITE setColor) + +public: + QmlGraphicsGradientStop(QObject *parent=0) : QObject(parent) {} + + qreal position() const { return m_position; } + void setPosition(qreal position) { m_position = position; updateGradient(); } + + QColor color() const { return m_color; } + void setColor(const QColor &color) { m_color = color; updateGradient(); } + +private: + void updateGradient(); + +private: + qreal m_position; + QColor m_color; +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsGradient : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QList *stops READ stops) + Q_CLASSINFO("DefaultProperty", "stops") + +public: + QmlGraphicsGradient(QObject *parent=0) : QObject(parent), m_gradient(0) {} + ~QmlGraphicsGradient() { delete m_gradient; } + + QList *stops() { return &m_stops; } + + const QGradient *gradient() const; + +Q_SIGNALS: + void updated(); + +private: + void doUpdate(); + +private: + QList m_stops; + mutable QGradient *m_gradient; + friend class QmlGraphicsGradientStop; +}; + +class QmlGraphicsRectanglePrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsRectangle : public QmlGraphicsItem +{ + Q_OBJECT + + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) + Q_PROPERTY(QmlGraphicsGradient *gradient READ gradient WRITE setGradient) + Q_PROPERTY(QmlGraphicsPen * border READ border CONSTANT) + Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged) +public: + QmlGraphicsRectangle(QmlGraphicsItem *parent=0); + + QColor color() const; + void setColor(const QColor &); + + QmlGraphicsPen *border(); + + QmlGraphicsGradient *gradient() const; + void setGradient(QmlGraphicsGradient *gradient); + + qreal radius() const; + void setRadius(qreal radius); + + QRectF boundingRect() const; + + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + +Q_SIGNALS: + void colorChanged(); + void radiusChanged(); + +private Q_SLOTS: + void doUpdate(); + +private: + void generateRoundedRect(); + void generateBorderedRect(); + void drawRect(QPainter &painter); + +protected: + QmlGraphicsRectangle(QmlGraphicsRectanglePrivate &dd, QmlGraphicsItem *parent); + +private: + Q_DISABLE_COPY(QmlGraphicsRectangle) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsRectangle) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsPen) +QML_DECLARE_TYPE(QmlGraphicsGradientStop) +QML_DECLARE_TYPE(QmlGraphicsGradient) +QML_DECLARE_TYPE(QmlGraphicsRectangle) + +QT_END_HEADER + +#endif // QMLGRAPHICSRECT_H diff --git a/src/declarative/graphicsitems/qmlgraphicsrectangle_p_p.h b/src/declarative/graphicsitems/qmlgraphicsrectangle_p_p.h new file mode 100644 index 0000000..cb914d6 --- /dev/null +++ b/src/declarative/graphicsitems/qmlgraphicsrectangle_p_p.h @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLGRAPHICSRECT_P_H +#define QMLGRAPHICSRECT_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qmlgraphicsitem_p.h" + +QT_BEGIN_NAMESPACE + +class QmlGraphicsGradient; +class QmlGraphicsRectangle; +class QmlGraphicsRectanglePrivate : public QmlGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsRectangle) + +public: + QmlGraphicsRectanglePrivate() : + color(Qt::white), gradient(0), pen(0), radius(0), paintmargin(0) + { + } + + ~QmlGraphicsRectanglePrivate() + { + delete pen; + } + + void init() + { + } + + QColor getColor(); + QColor color; + QmlGraphicsGradient *gradient; + QmlGraphicsPen *getPen() { + if (!pen) { + Q_Q(QmlGraphicsRectangle); + pen = new QmlGraphicsPen; + QObject::connect(pen, SIGNAL(penChanged()), q, SLOT(doUpdate())); + } + return pen; + } + QmlGraphicsPen *pen; + qreal radius; + qreal paintmargin; + QPixmap rectImage; + + void setPaintMargin(qreal margin) + { + Q_Q(QmlGraphicsRectangle); + if (margin == paintmargin) + return; + q->prepareGeometryChange(); + paintmargin = margin; + } +}; + +QT_END_NAMESPACE + +#endif // QMLGRAPHICSRECT_P_H diff --git a/tests/auto/declarative/anchors/tst_anchors.cpp b/tests/auto/declarative/anchors/tst_anchors.cpp index 60c6b3d..2d81b21 100644 --- a/tests/auto/declarative/anchors/tst_anchors.cpp +++ b/tests/auto/declarative/anchors/tst_anchors.cpp @@ -95,41 +95,41 @@ void tst_anchors::basicAnchors() qApp->processEvents(); //sibling horizontal - QCOMPARE(findItem(view->root(), QLatin1String("Rect1"))->x(), 26.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect2"))->x(), 122.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect3"))->x(), 74.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect4"))->x(), 16.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect5"))->x(), 112.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect6"))->x(), 64.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect1"))->x(), 26.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect2"))->x(), 122.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect3"))->x(), 74.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect4"))->x(), 16.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect5"))->x(), 112.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect6"))->x(), 64.0); //parent horizontal - QCOMPARE(findItem(view->root(), QLatin1String("Rect7"))->x(), 0.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect8"))->x(), 240.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect9"))->x(), 120.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect10"))->x(), -10.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect11"))->x(), 230.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect12"))->x(), 110.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect7"))->x(), 0.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect8"))->x(), 240.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect9"))->x(), 120.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect10"))->x(), -10.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect11"))->x(), 230.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect12"))->x(), 110.0); //vertical - QCOMPARE(findItem(view->root(), QLatin1String("Rect13"))->y(), 20.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect14"))->y(), 155.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect13"))->y(), 20.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect14"))->y(), 155.0); //stretch - QCOMPARE(findItem(view->root(), QLatin1String("Rect15"))->x(), 26.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect15"))->width(), 96.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect16"))->x(), 26.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect16"))->width(), 192.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect17"))->x(), -70.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect17"))->width(), 192.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect15"))->x(), 26.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect15"))->width(), 96.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect16"))->x(), 26.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect16"))->width(), 192.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect17"))->x(), -70.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect17"))->width(), 192.0); //vertical stretch - QCOMPARE(findItem(view->root(), QLatin1String("Rect18"))->y(), 20.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect18"))->height(), 40.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect18"))->y(), 20.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect18"))->height(), 40.0); //more parent horizontal - QCOMPARE(findItem(view->root(), QLatin1String("Rect19"))->x(), 115.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect20"))->x(), 235.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect21"))->x(), -5.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect19"))->x(), 115.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect20"))->x(), 235.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect21"))->x(), -5.0); delete view; } @@ -173,7 +173,7 @@ void tst_anchors::illegalSets() view->setUrl(QUrl("file://" SRCDIR "/data/illegal1.qml")); - QString expect = "QML QmlGraphicsRect (" + view->url().toString() + ":7:5" + ") Can't specify left, right, and hcenter anchors."; + QString expect = "QML QmlGraphicsRectangle (" + view->url().toString() + ":7:5" + ") Can't specify left, right, and hcenter anchors."; QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); view->execute(); qApp->processEvents(); @@ -199,7 +199,7 @@ void tst_anchors::illegalSets() view->setUrl(QUrl("file://" SRCDIR "/data/illegal3.qml")); - QString expect = "QML QmlGraphicsRect (" + view->url().toString() + ":9:5" + ") Can't anchor to an item that isn't a parent or sibling."; + QString expect = "QML QmlGraphicsRectangle (" + view->url().toString() + ":9:5" + ") Can't anchor to an item that isn't a parent or sibling."; QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); view->execute(); //qApp->processEvents(); diff --git a/tests/auto/declarative/animations/tst_animations.cpp b/tests/auto/declarative/animations/tst_animations.cpp index 77a31e5..c0e26ca 100644 --- a/tests/auto/declarative/animations/tst_animations.cpp +++ b/tests/auto/declarative/animations/tst_animations.cpp @@ -72,7 +72,7 @@ private slots: void tst_animations::simpleNumber() { - QmlGraphicsRect rect; + QmlGraphicsRectangle rect; QmlNumberAnimation animation; animation.setTarget(&rect); animation.setProperty("x"); @@ -90,7 +90,7 @@ void tst_animations::simpleNumber() void tst_animations::simpleColor() { - QmlGraphicsRect rect; + QmlGraphicsRectangle rect; QmlColorAnimation animation; animation.setTarget(&rect); animation.setProperty("color"); @@ -108,7 +108,7 @@ void tst_animations::simpleColor() void tst_animations::alwaysRunToEnd() { - QmlGraphicsRect rect; + QmlGraphicsRectangle rect; QmlPropertyAnimation animation; animation.setTarget(&rect); animation.setProperty("x"); @@ -126,7 +126,7 @@ void tst_animations::alwaysRunToEnd() void tst_animations::dotProperty() { - QmlGraphicsRect rect; + QmlGraphicsRectangle rect; QmlNumberAnimation animation; animation.setTarget(&rect); animation.setProperty("border.width"); @@ -181,12 +181,12 @@ void tst_animations::badTypes() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/badtype4.qml")); - QmlGraphicsRect *rect = qobject_cast(c.create()); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); rect->setState("state1"); QTest::qWait(1000 + 50); - QmlGraphicsRect *myRect = qobject_cast(rect->QGraphicsObject::children().at(3)); //### not robust + QmlGraphicsRectangle *myRect = qobject_cast(rect->QGraphicsObject::children().at(3)); //### not robust QVERIFY(myRect); QCOMPARE(myRect->x(),qreal(200)); } @@ -198,7 +198,7 @@ void tst_animations::badProperties() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/badproperty1.qml")); - QmlGraphicsRect *rect = qobject_cast(c.create()); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); QTest::ignoreMessage(QtWarningMsg, "QML QmlColorAnimation (file://" SRCDIR "/data/badproperty1.qml:22:9) Cannot animate non-existant property \"pen.colr\""); @@ -214,12 +214,12 @@ void tst_animations::mixedTypes() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/mixedtype1.qml")); - QmlGraphicsRect *rect = qobject_cast(c.create()); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); rect->setState("state1"); QTest::qWait(500); - QmlGraphicsRect *myRect = qobject_cast(rect->QGraphicsObject::children().at(3)); //### not robust + QmlGraphicsRectangle *myRect = qobject_cast(rect->QGraphicsObject::children().at(3)); //### not robust QVERIFY(myRect); //rather inexact -- is there a better way? @@ -230,12 +230,12 @@ void tst_animations::mixedTypes() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/mixedtype2.qml")); - QmlGraphicsRect *rect = qobject_cast(c.create()); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); rect->setState("state1"); QTest::qWait(500); - QmlGraphicsRect *myRect = qobject_cast(rect->QGraphicsObject::children().at(3)); //### not robust + QmlGraphicsRectangle *myRect = qobject_cast(rect->QGraphicsObject::children().at(3)); //### not robust QVERIFY(myRect); //rather inexact -- is there a better way? diff --git a/tests/auto/declarative/behaviors/tst_behaviors.cpp b/tests/auto/declarative/behaviors/tst_behaviors.cpp index aea5604..449deb9 100644 --- a/tests/auto/declarative/behaviors/tst_behaviors.cpp +++ b/tests/auto/declarative/behaviors/tst_behaviors.cpp @@ -66,12 +66,12 @@ void tst_behaviors::simpleBehavior() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/simple.qml")); - QmlGraphicsRect *rect = qobject_cast(c.create()); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); rect->setState("moved"); QTest::qWait(100); - qreal x = qobject_cast(rect->findChild("MyRect"))->x(); + qreal x = qobject_cast(rect->findChild("MyRect"))->x(); QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered } @@ -79,12 +79,12 @@ void tst_behaviors::scriptTriggered() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/scripttrigger.qml")); - QmlGraphicsRect *rect = qobject_cast(c.create()); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); rect->setColor(QColor("red")); QTest::qWait(100); - qreal x = qobject_cast(rect->findChild("MyRect"))->x(); + qreal x = qobject_cast(rect->findChild("MyRect"))->x(); QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered } @@ -92,10 +92,10 @@ void tst_behaviors::cppTriggered() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/cpptrigger.qml")); - QmlGraphicsRect *rect = qobject_cast(c.create()); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); - QmlGraphicsRect *innerRect = qobject_cast(rect->findChild("MyRect")); + QmlGraphicsRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); QVERIFY(innerRect); innerRect->setProperty("x", 200); @@ -108,7 +108,7 @@ void tst_behaviors::loop() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/loop.qml")); - QmlGraphicsRect *rect = qobject_cast(c.create()); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); //don't crash @@ -119,12 +119,12 @@ void tst_behaviors::colorBehavior() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/color.qml")); - QmlGraphicsRect *rect = qobject_cast(c.create()); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); rect->setState("red"); QTest::qWait(100); - QColor color = qobject_cast(rect->findChild("MyRect"))->color(); + QColor color = qobject_cast(rect->findChild("MyRect"))->color(); QVERIFY(color != QColor("red") && color != QColor("green")); //i.e. the behavior has been triggered } @@ -132,12 +132,12 @@ void tst_behaviors::replaceBinding() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/binding.qml")); - QmlGraphicsRect *rect = qobject_cast(c.create()); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); rect->setState("moved"); QTest::qWait(100); - QmlGraphicsRect *innerRect = qobject_cast(rect->findChild("MyRect")); + QmlGraphicsRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); QVERIFY(innerRect); qreal x = innerRect->x(); QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered @@ -167,24 +167,24 @@ void tst_behaviors::group() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/groupProperty.qml")); - QmlGraphicsRect *rect = qobject_cast(c.create()); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); rect->setState("moved"); QTest::qWait(100); - qreal x = qobject_cast(rect->findChild("MyRect"))->x(); + qreal x = qobject_cast(rect->findChild("MyRect"))->x(); QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered } { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/groupProperty2.qml")); - QmlGraphicsRect *rect = qobject_cast(c.create()); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); rect->setState("moved"); QTest::qWait(100); - qreal x = qobject_cast(rect->findChild("MyRect"))->x(); + qreal x = qobject_cast(rect->findChild("MyRect"))->x(); QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered } } diff --git a/tests/auto/declarative/layouts/tst_layouts.cpp b/tests/auto/declarative/layouts/tst_layouts.cpp index fbcc904..ab675b8 100644 --- a/tests/auto/declarative/layouts/tst_layouts.cpp +++ b/tests/auto/declarative/layouts/tst_layouts.cpp @@ -73,13 +73,13 @@ void tst_QmlGraphicsLayouts::test_horizontal() canvas->execute(); qApp->processEvents(); - QmlGraphicsRect *one = canvas->root()->findChild("one"); + QmlGraphicsRectangle *one = canvas->root()->findChild("one"); QVERIFY(one != 0); - QmlGraphicsRect *two = canvas->root()->findChild("two"); + QmlGraphicsRectangle *two = canvas->root()->findChild("two"); QVERIFY(two != 0); - QmlGraphicsRect *three = canvas->root()->findChild("three"); + QmlGraphicsRectangle *three = canvas->root()->findChild("three"); QVERIFY(three != 0); QCOMPARE(one->x(), 0.0); @@ -97,13 +97,13 @@ void tst_QmlGraphicsLayouts::test_horizontal_spacing() canvas->execute(); qApp->processEvents(); - QmlGraphicsRect *one = canvas->root()->findChild("one"); + QmlGraphicsRectangle *one = canvas->root()->findChild("one"); QVERIFY(one != 0); - QmlGraphicsRect *two = canvas->root()->findChild("two"); + QmlGraphicsRectangle *two = canvas->root()->findChild("two"); QVERIFY(two != 0); - QmlGraphicsRect *three = canvas->root()->findChild("three"); + QmlGraphicsRectangle *three = canvas->root()->findChild("three"); QVERIFY(three != 0); QCOMPARE(one->x(), 0.0); @@ -121,13 +121,13 @@ void tst_QmlGraphicsLayouts::test_vertical() canvas->execute(); qApp->processEvents(); - QmlGraphicsRect *one = canvas->root()->findChild("one"); + QmlGraphicsRectangle *one = canvas->root()->findChild("one"); QVERIFY(one != 0); - QmlGraphicsRect *two = canvas->root()->findChild("two"); + QmlGraphicsRectangle *two = canvas->root()->findChild("two"); QVERIFY(two != 0); - QmlGraphicsRect *three = canvas->root()->findChild("three"); + QmlGraphicsRectangle *three = canvas->root()->findChild("three"); QVERIFY(three != 0); QCOMPARE(one->x(), 0.0); @@ -145,13 +145,13 @@ void tst_QmlGraphicsLayouts::test_vertical_spacing() canvas->execute(); qApp->processEvents(); - QmlGraphicsRect *one = canvas->root()->findChild("one"); + QmlGraphicsRectangle *one = canvas->root()->findChild("one"); QVERIFY(one != 0); - QmlGraphicsRect *two = canvas->root()->findChild("two"); + QmlGraphicsRectangle *two = canvas->root()->findChild("two"); QVERIFY(two != 0); - QmlGraphicsRect *three = canvas->root()->findChild("three"); + QmlGraphicsRectangle *three = canvas->root()->findChild("three"); QVERIFY(three != 0); QCOMPARE(one->x(), 0.0); @@ -169,15 +169,15 @@ void tst_QmlGraphicsLayouts::test_grid() canvas->execute(); qApp->processEvents(); - QmlGraphicsRect *one = canvas->root()->findChild("one"); + QmlGraphicsRectangle *one = canvas->root()->findChild("one"); QVERIFY(one != 0); - QmlGraphicsRect *two = canvas->root()->findChild("two"); + QmlGraphicsRectangle *two = canvas->root()->findChild("two"); QVERIFY(two != 0); - QmlGraphicsRect *three = canvas->root()->findChild("three"); + QmlGraphicsRectangle *three = canvas->root()->findChild("three"); QVERIFY(three != 0); - QmlGraphicsRect *four = canvas->root()->findChild("four"); + QmlGraphicsRectangle *four = canvas->root()->findChild("four"); QVERIFY(four != 0); - QmlGraphicsRect *five = canvas->root()->findChild("five"); + QmlGraphicsRectangle *five = canvas->root()->findChild("five"); QVERIFY(five != 0); QCOMPARE(one->x(), 0.0); @@ -199,15 +199,15 @@ void tst_QmlGraphicsLayouts::test_grid_spacing() canvas->execute(); qApp->processEvents(); - QmlGraphicsRect *one = canvas->root()->findChild("one"); + QmlGraphicsRectangle *one = canvas->root()->findChild("one"); QVERIFY(one != 0); - QmlGraphicsRect *two = canvas->root()->findChild("two"); + QmlGraphicsRectangle *two = canvas->root()->findChild("two"); QVERIFY(two != 0); - QmlGraphicsRect *three = canvas->root()->findChild("three"); + QmlGraphicsRectangle *three = canvas->root()->findChild("three"); QVERIFY(three != 0); - QmlGraphicsRect *four = canvas->root()->findChild("four"); + QmlGraphicsRectangle *four = canvas->root()->findChild("four"); QVERIFY(four != 0); - QmlGraphicsRect *five = canvas->root()->findChild("five"); + QmlGraphicsRectangle *five = canvas->root()->findChild("five"); QVERIFY(five != 0); QCOMPARE(one->x(), 0.0); diff --git a/tests/auto/declarative/pathview/tst_pathview.cpp b/tests/auto/declarative/pathview/tst_pathview.cpp index 41decb1..93e4754 100644 --- a/tests/auto/declarative/pathview/tst_pathview.cpp +++ b/tests/auto/declarative/pathview/tst_pathview.cpp @@ -190,7 +190,7 @@ void tst_QmlGraphicsPathView::pathMoved() QmlGraphicsPathView *pathview = findItem(canvas->root(), "view"); QVERIFY(pathview != 0); - QmlGraphicsRect *firstItem = findItem(pathview, "wrapper", 0); + QmlGraphicsRectangle *firstItem = findItem(pathview, "wrapper", 0); QVERIFY(firstItem); QmlGraphicsPath *path = qobject_cast(pathview->path()); QVERIFY(path); @@ -203,7 +203,7 @@ void tst_QmlGraphicsPathView::pathMoved() QTest::qWait(1000);//Moving is animated? for(int i=0; i(pathview, "wrapper", i); + QmlGraphicsRectangle *curItem = findItem(pathview, "wrapper", i); QCOMPARE(curItem->pos() + offset, path->pointAt(0.1 + i*0.25)); } @@ -234,22 +234,22 @@ void tst_QmlGraphicsPathView::limitedItems() pathview->setPathItemCount(10); QCOMPARE(pathview->pathItemCount(), 10); - QmlGraphicsRect *testItem = findItem(pathview, "wrapper", 0); + QmlGraphicsRectangle *testItem = findItem(pathview, "wrapper", 0); QVERIFY(testItem != 0); - testItem = findItem(pathview, "wrapper", 9); + testItem = findItem(pathview, "wrapper", 9); QVERIFY(testItem != 0); - testItem = findItem(pathview, "wrapper", 10); + testItem = findItem(pathview, "wrapper", 10); QVERIFY(testItem == 0); pathview->setCurrentIndex(50); QTest::qWait(5100);//Moving is animated and it's travelling far - should be reconsidered. - testItem = findItem(pathview, "wrapper", 0); + testItem = findItem(pathview, "wrapper", 0); QVERIFY(testItem == 0); - testItem = findItem(pathview, "wrapper", 1); + testItem = findItem(pathview, "wrapper", 1); QVERIFY(testItem == 0); - testItem = findItem(pathview, "wrapper", 9); + testItem = findItem(pathview, "wrapper", 9); QVERIFY(testItem == 0); - testItem = findItem(pathview, "wrapper", 50); + testItem = findItem(pathview, "wrapper", 50); QVERIFY(testItem != 0); } diff --git a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp index 7dfb0ff..128fa87 100644 --- a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp +++ b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp @@ -987,11 +987,11 @@ void tst_qmllanguage::importsLocal_data() QTest::newRow("local import") << "import \"subdir\"\n" // QT-613 "Test {}" - << "QmlGraphicsRect"; + << "QmlGraphicsRectangle"; QTest::newRow("local import as") << "import \"subdir\" as T\n" "T.Test {}" - << "QmlGraphicsRect"; + << "QmlGraphicsRectangle"; QTest::newRow("wrong local import as") << "import \"subdir\" as T\n" "Test {}" @@ -1019,7 +1019,7 @@ void tst_qmllanguage::importsRemote_data() + QtNetworkSettings::serverName() + "/qtest/declarative/qmllanguage"; - QTest::newRow("remote import") << "import \""+serverdir+"\"\nTest {}" << "QmlGraphicsRect"; + QTest::newRow("remote import") << "import \""+serverdir+"\"\nTest {}" << "QmlGraphicsRectangle"; QTest::newRow("remote import with subdir") << "import \""+serverdir+"\"\nTestSubDir {}" << "QmlGraphicsText"; QTest::newRow("remote import with local") << "import \""+serverdir+"\"\nTestLocal {}" << "QmlGraphicsImage"; } @@ -1042,7 +1042,7 @@ void tst_qmllanguage::importsInstalled_data() QTest::newRow("installed import 1") << "import com.nokia.installedtest 1.0\n" "InstalledTest {}" - << "QmlGraphicsRect"; + << "QmlGraphicsRectangle"; QTest::newRow("installed import 2") << "import com.nokia.installedtest 1.4\n" "InstalledTest {}" @@ -1075,7 +1075,7 @@ void tst_qmllanguage::importsOrder_data() "import com.nokia.installedtest 1.4\n" "import com.nokia.installedtest 1.0\n" "InstalledTest {}" - << "QmlGraphicsRect"; + << "QmlGraphicsRectangle"; QTest::newRow("installed import re-overrides 1") << "import com.nokia.installedtest 1.4\n" "import com.nokia.installedtest 1.0\n" @@ -1088,13 +1088,13 @@ void tst_qmllanguage::importsOrder_data() "import com.nokia.installedtest 1.4\n" "import com.nokia.installedtest 1.0\n" "InstalledTest {}" - << "QmlGraphicsRect"; + << "QmlGraphicsRectangle"; QTest::newRow("installed import versus builtin 1") << "import com.nokia.installedtest 1.5\n" "import Qt 4.6\n" "Rectangle {}" - << "QmlGraphicsRect"; + << "QmlGraphicsRectangle"; QTest::newRow("installed import versus builtin 2") << "import Qt 4.6\n" "import com.nokia.installedtest 1.5\n" diff --git a/tests/auto/declarative/states/tst_states.cpp b/tests/auto/declarative/states/tst_states.cpp index 4425eac..e362050 100644 --- a/tests/auto/declarative/states/tst_states.cpp +++ b/tests/auto/declarative/states/tst_states.cpp @@ -62,7 +62,7 @@ void tst_states::basicChanges() { QmlComponent rectComponent(&engine, SRCDIR "/data/basicChanges.qml"); - QmlGraphicsRect *rect = qobject_cast(rectComponent.create()); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); @@ -76,7 +76,7 @@ void tst_states::basicChanges() { QmlComponent rectComponent(&engine, SRCDIR "/data/basicChanges2.qml"); - QmlGraphicsRect *rect = qobject_cast(rectComponent.create()); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); @@ -96,7 +96,7 @@ void tst_states::basicChanges() { QmlComponent rectComponent(&engine, SRCDIR "/data/basicChanges3.qml"); - QmlGraphicsRect *rect = qobject_cast(rectComponent.create()); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); @@ -132,7 +132,7 @@ void tst_states::basicExtension() { QmlComponent rectComponent(&engine, SRCDIR "/data/basicExtension.qml"); - QmlGraphicsRect *rect = qobject_cast(rectComponent.create()); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); @@ -165,7 +165,7 @@ void tst_states::basicExtension() { QmlComponent rectComponent(&engine, SRCDIR "/data/fakeExtension.qml"); - QmlGraphicsRect *rect = qobject_cast(rectComponent.create()); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); @@ -196,7 +196,7 @@ void tst_states::basicBinding() { QmlComponent rectComponent(&engine, SRCDIR "/data/basicBinding.qml"); - QmlGraphicsRect *rect = qobject_cast(rectComponent.create()); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); @@ -223,7 +223,7 @@ void tst_states::basicBinding() { QmlComponent rectComponent(&engine, SRCDIR "/data/basicBinding2.qml"); - QmlGraphicsRect *rect = qobject_cast(rectComponent.create()); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); @@ -253,7 +253,7 @@ void tst_states::basicBinding() { QmlComponent rectComponent(&engine, SRCDIR "/data/basicBinding3.qml"); - QmlGraphicsRect *rect = qobject_cast(rectComponent.create()); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); @@ -277,7 +277,7 @@ void tst_states::basicBinding() { QmlComponent rectComponent(&engine, SRCDIR "/data/basicBinding4.qml"); - QmlGraphicsRect *rect = qobject_cast(rectComponent.create()); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); @@ -303,7 +303,7 @@ void tst_states::basicBinding() } } -class MyRect : public QmlGraphicsRect +class MyRect : public QmlGraphicsRectangle { Q_OBJECT public: @@ -343,7 +343,7 @@ void tst_states::signalOverride() rect->doSomething(); QCOMPARE(rect->color(),QColor("blue")); - QmlGraphicsRect *innerRect = qobject_cast(rect->findChild("extendedRect")); + QmlGraphicsRectangle *innerRect = qobject_cast(rect->findChild("extendedRect")); innerRect->setState("green"); rect->doSomething(); diff --git a/tests/benchmarks/qmlpainting/tst_qmlpainting.cpp b/tests/benchmarks/qmlpainting/tst_qmlpainting.cpp index 0af4858..e268136 100644 --- a/tests/benchmarks/qmlpainting/tst_qmlpainting.cpp +++ b/tests/benchmarks/qmlpainting/tst_qmlpainting.cpp @@ -327,7 +327,7 @@ void tst_QmlPainting::drawTransformedImageRoundedRect() surface.save("ti.png"); } -//code from QmlGraphicsRect for drawing rounded rects +//code from QmlGraphicsRectangle for drawing rounded rects void tst_QmlPainting::drawScaleGridRoundedRect() { //setup image @@ -422,7 +422,7 @@ void tst_QmlPainting::drawScaledScaleGridRoundedRect_data() // QTest::newRow(QString(QLatin1String("scale=%1; imagetype=ARGB8565_Pre")).arg(i).toLatin1()) << i << (int)QImage::Format_ARGB8565_Premultiplied; } -//code from QmlGraphicsRect for drawing rounded rects +//code from QmlGraphicsRectangle for drawing rounded rects void tst_QmlPainting::drawScaledScaleGridRoundedRect() { QFETCH(float, scale); @@ -522,7 +522,7 @@ void tst_QmlPainting::drawTransformedScaleGridRoundedRect_data() } -//code from QmlGraphicsRect for drawing rounded rects +//code from QmlGraphicsRectangle for drawing rounded rects void tst_QmlPainting::drawTransformedScaleGridRoundedRect() { QFETCH(QTransform, transform); -- cgit v0.12 From a0c07728c391f6c209fef7678a708a83084fac6a Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Mon, 2 Nov 2009 16:51:03 +1000 Subject: more renaming --- tests/auto/declarative/anchors/tst_anchors.cpp | 2 +- tests/auto/declarative/animatedimage/tst_animatedimage.cpp | 2 +- tests/auto/declarative/animations/tst_animations.cpp | 2 +- tests/auto/declarative/behaviors/tst_behaviors.cpp | 2 +- tests/auto/declarative/layouts/tst_layouts.cpp | 2 +- tests/auto/declarative/pathview/tst_pathview.cpp | 2 +- tests/auto/declarative/states/tst_states.cpp | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/auto/declarative/anchors/tst_anchors.cpp b/tests/auto/declarative/anchors/tst_anchors.cpp index 2d81b21..8abf04f 100644 --- a/tests/auto/declarative/anchors/tst_anchors.cpp +++ b/tests/auto/declarative/anchors/tst_anchors.cpp @@ -42,7 +42,7 @@ #include #include #include -#include +#include #include diff --git a/tests/auto/declarative/animatedimage/tst_animatedimage.cpp b/tests/auto/declarative/animatedimage/tst_animatedimage.cpp index a82c8e6..f6141cb 100644 --- a/tests/auto/declarative/animatedimage/tst_animatedimage.cpp +++ b/tests/auto/declarative/animatedimage/tst_animatedimage.cpp @@ -42,7 +42,7 @@ #include #include #include -#include +#include #include #include diff --git a/tests/auto/declarative/animations/tst_animations.cpp b/tests/auto/declarative/animations/tst_animations.cpp index c0e26ca..ca383bb 100644 --- a/tests/auto/declarative/animations/tst_animations.cpp +++ b/tests/auto/declarative/animations/tst_animations.cpp @@ -42,7 +42,7 @@ #include #include #include -#include +#include #include class tst_animations : public QObject diff --git a/tests/auto/declarative/behaviors/tst_behaviors.cpp b/tests/auto/declarative/behaviors/tst_behaviors.cpp index 449deb9..9803a9d 100644 --- a/tests/auto/declarative/behaviors/tst_behaviors.cpp +++ b/tests/auto/declarative/behaviors/tst_behaviors.cpp @@ -42,7 +42,7 @@ #include #include #include -#include +#include #include class tst_behaviors : public QObject diff --git a/tests/auto/declarative/layouts/tst_layouts.cpp b/tests/auto/declarative/layouts/tst_layouts.cpp index ab675b8..b0df57ea 100644 --- a/tests/auto/declarative/layouts/tst_layouts.cpp +++ b/tests/auto/declarative/layouts/tst_layouts.cpp @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include class tst_QmlGraphicsLayouts : public QObject diff --git a/tests/auto/declarative/pathview/tst_pathview.cpp b/tests/auto/declarative/pathview/tst_pathview.cpp index 93e4754..57ae8c0 100644 --- a/tests/auto/declarative/pathview/tst_pathview.cpp +++ b/tests/auto/declarative/pathview/tst_pathview.cpp @@ -43,7 +43,7 @@ #include #include #include -#include +#include #include #include diff --git a/tests/auto/declarative/states/tst_states.cpp b/tests/auto/declarative/states/tst_states.cpp index e362050..89e755e 100644 --- a/tests/auto/declarative/states/tst_states.cpp +++ b/tests/auto/declarative/states/tst_states.cpp @@ -41,7 +41,7 @@ #include #include #include -#include +#include class tst_states : public QObject { -- cgit v0.12 From 237ff8235191bdc06f0ef80d76c8f9a0934413b9 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Mon, 2 Nov 2009 17:01:43 +1000 Subject: Doc --- doc/src/declarative/qmlreference.qdoc | 5 ----- doc/src/declarative/tutorial3.qdoc | 2 +- src/declarative/util/qmlbind.cpp | 2 -- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/doc/src/declarative/qmlreference.qdoc b/doc/src/declarative/qmlreference.qdoc index a56813c..f17e9d7 100644 --- a/doc/src/declarative/qmlreference.qdoc +++ b/doc/src/declarative/qmlreference.qdoc @@ -83,9 +83,4 @@ \list \o \l {elements}{QML Elements} \endlist - - \section1 Deprecated - \list - \o \l {tutorials-declarative-contacts.html}{Tutorial: 'Introduction to QML'} - \endlist */ diff --git a/doc/src/declarative/tutorial3.qdoc b/doc/src/declarative/tutorial3.qdoc index 1e67eee..290b535 100644 --- a/doc/src/declarative/tutorial3.qdoc +++ b/doc/src/declarative/tutorial3.qdoc @@ -38,7 +38,7 @@ This is equivalent to writing the two transitions separately. The \l ParallelAnimation element makes sure that the two types of animations (number and color) start at the same time. We could also run them one after the other by using \l SequentialAnimation instead. -For more details on states and transitions, see \l {states-transitions}{States and Transitions}. +For more details on states and transitions, see \l {QML States}. [Previous: \l {Tutorial 2 - QML Component}] [\l {Tutorial}] diff --git a/src/declarative/util/qmlbind.cpp b/src/declarative/util/qmlbind.cpp index eadad08..de6d48a 100644 --- a/src/declarative/util/qmlbind.cpp +++ b/src/declarative/util/qmlbind.cpp @@ -85,8 +85,6 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Binding,QmlBind) If the binding target or binding property is changed, the bound value is immediately pushed onto the new target. - - \sa {qmlforcpp}{Qt Declarative Markup Language For C++ Programmers} */ /*! \internal -- cgit v0.12 From 6891a96bbc818f0bbfb1837d2912bdb24211572e Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 2 Nov 2009 17:12:10 +1000 Subject: NOTIFY ListModel::count --- src/declarative/util/qmllistmodel.cpp | 4 +++- src/declarative/util/qmllistmodel_p.h | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/declarative/util/qmllistmodel.cpp b/src/declarative/util/qmllistmodel.cpp index dba2203..17083db 100644 --- a/src/declarative/util/qmllistmodel.cpp +++ b/src/declarative/util/qmllistmodel.cpp @@ -457,6 +457,7 @@ void QmlListModel::remove(int index) if (node) delete node; emit itemsRemoved(index,1); + emit countChanged(_root->values.count()); } } @@ -488,6 +489,7 @@ void QmlListModel::insert(int index, const QScriptValue& valuemap) mn->setObjectValue(valuemap); _root->values.insert(index,qVariantFromValue(mn)); emit itemsInserted(index,1); + emit countChanged(_root->values.count()); } /*! @@ -563,6 +565,7 @@ void QmlListModel::append(const QScriptValue& valuemap) mn->setObjectValue(valuemap); _root->values << qVariantFromValue(mn); emit itemsInserted(count()-1,1); + emit countChanged(_root->values.count()); } /*! @@ -642,7 +645,6 @@ void QmlListModel::set(int index, const QString& property, const QVariant& value emit itemsChanged(index,1,roles); } - class QmlListModelParser : public QmlCustomParser { public: diff --git a/src/declarative/util/qmllistmodel_p.h b/src/declarative/util/qmllistmodel_p.h index 8676024..31365d1 100644 --- a/src/declarative/util/qmllistmodel_p.h +++ b/src/declarative/util/qmllistmodel_p.h @@ -62,7 +62,7 @@ struct ModelNode; class QmlListModel : public QListModelInterface { Q_OBJECT - Q_PROPERTY(int count READ count) + Q_PROPERTY(int count READ count NOTIFY countChanged) public: QmlListModel(QObject *parent=0); @@ -81,6 +81,9 @@ public: Q_INVOKABLE void set(int index, const QString& property, const QVariant& value); Q_INVOKABLE void move(int from, int to, int count); +Q_SIGNALS: + void countChanged(int); + private: QVariant valueForNode(ModelNode *) const; mutable QStringList roleStrings; -- cgit v0.12 From 7aeefc1e5904517bbc8133c32340379e20a74aca Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 2 Nov 2009 17:27:12 +1000 Subject: Check bug QT-2423 --- tests/auto/declarative/qmltimer/tst_qmltimer.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/auto/declarative/qmltimer/tst_qmltimer.cpp b/tests/auto/declarative/qmltimer/tst_qmltimer.cpp index d3b273c..9c5dc30 100644 --- a/tests/auto/declarative/qmltimer/tst_qmltimer.cpp +++ b/tests/auto/declarative/qmltimer/tst_qmltimer.cpp @@ -53,6 +53,7 @@ private slots: void notRepeating(); void notRepeatingStart(); void repeat(); + void noTriggerIfNotRunning(); void triggeredOnStart(); void triggeredOnStartRepeat(); }; @@ -176,6 +177,22 @@ void tst_qmltimer::triggeredOnStartRepeat() QVERIFY(helper.count > oldCount); } +void tst_qmltimer::noTriggerIfNotRunning() +{ + QmlEngine engine; + QmlComponent component(&engine, QByteArray( + "import Qt 4.6\n" + "Item { property bool ok: true\n" + "Timer { id: t1; interval: 100; repeat: true; running: true; onTriggered: if (!running) ok=false }" + "Timer { interval: 10; running: true; onTriggered: t1.running=false }" + "}" + ), QUrl("file://")); + QObject *item = component.create(); + QVERIFY(item != 0); + QTest::qWait(TIMEOUT_TIMEOUT); + QCOMPARE(item->property("ok").toBool(), true); +} + QTEST_MAIN(tst_qmltimer) #include "tst_qmltimer.moc" -- cgit v0.12 From 8b4cbdbd3bfcdc98ca5f8e728b004596a1213127 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Mon, 2 Nov 2009 18:34:07 +1000 Subject: Qt object test --- doc/src/declarative/globalobject.qdoc | 31 +-- src/declarative/qml/qmlengine.cpp | 33 +++- tests/auto/declarative/qmlqt/data/darker.qml | 8 + tests/auto/declarative/qmlqt/data/enums.qml | 9 + tests/auto/declarative/qmlqt/data/hsla.qml | 11 ++ tests/auto/declarative/qmlqt/data/lighter.qml | 7 + tests/auto/declarative/qmlqt/data/point.qml | 9 + tests/auto/declarative/qmlqt/data/rect.qml | 9 + tests/auto/declarative/qmlqt/data/rgba.qml | 10 + tests/auto/declarative/qmlqt/data/size.qml | 11 ++ tests/auto/declarative/qmlqt/data/tint.qml | 9 + tests/auto/declarative/qmlqt/data/vector.qml | 8 + tests/auto/declarative/qmlqt/qmlqt.pro | 9 + tests/auto/declarative/qmlqt/tst_qmlqt.cpp | 264 ++++++++++++++++++++++++++ 14 files changed, 390 insertions(+), 38 deletions(-) create mode 100644 tests/auto/declarative/qmlqt/data/darker.qml create mode 100644 tests/auto/declarative/qmlqt/data/enums.qml create mode 100644 tests/auto/declarative/qmlqt/data/hsla.qml create mode 100644 tests/auto/declarative/qmlqt/data/lighter.qml create mode 100644 tests/auto/declarative/qmlqt/data/point.qml create mode 100644 tests/auto/declarative/qmlqt/data/rect.qml create mode 100644 tests/auto/declarative/qmlqt/data/rgba.qml create mode 100644 tests/auto/declarative/qmlqt/data/size.qml create mode 100644 tests/auto/declarative/qmlqt/data/tint.qml create mode 100644 tests/auto/declarative/qmlqt/data/vector.qml create mode 100644 tests/auto/declarative/qmlqt/qmlqt.pro create mode 100644 tests/auto/declarative/qmlqt/tst_qmlqt.cpp diff --git a/doc/src/declarative/globalobject.qdoc b/doc/src/declarative/globalobject.qdoc index e327047..f1d440f 100644 --- a/doc/src/declarative/globalobject.qdoc +++ b/doc/src/declarative/globalobject.qdoc @@ -92,34 +92,9 @@ This function returns a Rect with the top-left corner at \c x,\c y and the speci \section3 Qt.point(int x, int y) This function returns a Point with the specified \c x and \c y coordinates. \section3 Qt.size(int width, int height) -returns as Size with the specified width and height. -\section3 Qt.vector(real x, real y, real z) - This function is intended for use inside QML only. In C++ just create a - QVector3D as usual. - - This function takes three numeric components and combines them into a - QVector3D value that can be used with any property that takes a - QVector3D argument. The following QML code: - - \code - transform: Rotation { - id: rotation - origin.x: Container.width / 2; - axis: vector(0, 1, 1) - } - \endcode - - is equivalent to: - - \code - transform: Rotation { - id: rotation - origin.x: Container.width / 2; - axis.x: 0; axis.y: 1; axis.z: 0 - } - \endcode - - +This function returns as Size with the specified width and height. +\section3 Qt.vector3d(real x, real y, real z) +This function returns a Vector3D with the specified x, y and z. \section2 Functions The Qt object also contains the following miscellaneous functions which expose Qt functionality for use in QML. diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 07296d9..7242a1d 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -666,7 +666,7 @@ QScriptValue QmlEnginePrivate::createQmlObject(QScriptContext *ctxt, QScriptEngi QScriptValue QmlEnginePrivate::vector(QScriptContext *ctxt, QScriptEngine *engine) { - if(ctxt->argumentCount() < 3) + if(ctxt->argumentCount() != 3) return engine->nullValue(); qsreal x = ctxt->argument(0).toNumber(); qsreal y = ctxt->argument(1).toNumber(); @@ -677,41 +677,54 @@ QScriptValue QmlEnginePrivate::vector(QScriptContext *ctxt, QScriptEngine *engin QScriptValue QmlEnginePrivate::rgba(QScriptContext *ctxt, QScriptEngine *engine) { int argCount = ctxt->argumentCount(); - if(argCount < 3) + if(argCount < 3 || argCount > 4) return engine->nullValue(); qsreal r = ctxt->argument(0).toNumber(); qsreal g = ctxt->argument(1).toNumber(); qsreal b = ctxt->argument(2).toNumber(); qsreal a = (argCount == 4) ? ctxt->argument(3).toNumber() : 1; + + if (r < 0 || r > 1 || g < 0 || g > 1 || b < 0 || b > 1 || a < 0 || a > 1) + return engine->nullValue(); + return qScriptValueFromValue(engine, qVariantFromValue(QColor::fromRgbF(r, g, b, a))); } QScriptValue QmlEnginePrivate::hsla(QScriptContext *ctxt, QScriptEngine *engine) { int argCount = ctxt->argumentCount(); - if(argCount < 3) + if(argCount < 3 || argCount > 4) return engine->nullValue(); qsreal h = ctxt->argument(0).toNumber(); qsreal s = ctxt->argument(1).toNumber(); qsreal l = ctxt->argument(2).toNumber(); qsreal a = (argCount == 4) ? ctxt->argument(3).toNumber() : 1; + + if (h < 0 || h > 1 || s < 0 || s > 1 || l < 0 || l > 1 || a < 0 || a > 1) + return engine->nullValue(); + return qScriptValueFromValue(engine, qVariantFromValue(QColor::fromHslF(h, s, l, a))); } QScriptValue QmlEnginePrivate::rect(QScriptContext *ctxt, QScriptEngine *engine) { - if(ctxt->argumentCount() < 4) + if(ctxt->argumentCount() != 4) return engine->nullValue(); + qsreal x = ctxt->argument(0).toNumber(); qsreal y = ctxt->argument(1).toNumber(); qsreal w = ctxt->argument(2).toNumber(); qsreal h = ctxt->argument(3).toNumber(); + + if (w < 0 || h < 0) + return engine->nullValue(); + return qScriptValueFromValue(engine, qVariantFromValue(QRectF(x, y, w, h))); } QScriptValue QmlEnginePrivate::point(QScriptContext *ctxt, QScriptEngine *engine) { - if(ctxt->argumentCount() < 2) + if(ctxt->argumentCount() != 2) return engine->nullValue(); qsreal x = ctxt->argument(0).toNumber(); qsreal y = ctxt->argument(1).toNumber(); @@ -720,7 +733,7 @@ QScriptValue QmlEnginePrivate::point(QScriptContext *ctxt, QScriptEngine *engine QScriptValue QmlEnginePrivate::size(QScriptContext *ctxt, QScriptEngine *engine) { - if(ctxt->argumentCount() < 2) + if(ctxt->argumentCount() != 2) return engine->nullValue(); qsreal w = ctxt->argument(0).toNumber(); qsreal h = ctxt->argument(1).toNumber(); @@ -729,7 +742,7 @@ QScriptValue QmlEnginePrivate::size(QScriptContext *ctxt, QScriptEngine *engine) QScriptValue QmlEnginePrivate::lighter(QScriptContext *ctxt, QScriptEngine *engine) { - if(ctxt->argumentCount() < 1) + if(ctxt->argumentCount() != 1) return engine->nullValue(); QVariant v = ctxt->argument(0).toVariant(); QColor color; @@ -748,7 +761,7 @@ QScriptValue QmlEnginePrivate::lighter(QScriptContext *ctxt, QScriptEngine *engi QScriptValue QmlEnginePrivate::darker(QScriptContext *ctxt, QScriptEngine *engine) { - if(ctxt->argumentCount() < 1) + if(ctxt->argumentCount() != 1) return engine->nullValue(); QVariant v = ctxt->argument(0).toVariant(); QColor color; @@ -767,7 +780,7 @@ QScriptValue QmlEnginePrivate::darker(QScriptContext *ctxt, QScriptEngine *engin QScriptValue QmlEnginePrivate::playSound(QScriptContext *ctxt, QScriptEngine *engine) { - if (ctxt->argumentCount() < 1) + if (ctxt->argumentCount() != 1) return engine->undefinedValue(); QUrl url(ctxt->argument(0).toString()); @@ -799,7 +812,7 @@ QScriptValue QmlEnginePrivate::desktopOpenUrl(QScriptContext *ctxt, QScriptEngin QScriptValue QmlEnginePrivate::tint(QScriptContext *ctxt, QScriptEngine *engine) { - if(ctxt->argumentCount() < 2) + if(ctxt->argumentCount() != 2) return engine->nullValue(); //get color QVariant v = ctxt->argument(0).toVariant(); diff --git a/tests/auto/declarative/qmlqt/data/darker.qml b/tests/auto/declarative/qmlqt/data/darker.qml new file mode 100644 index 0000000..6369e8f --- /dev/null +++ b/tests/auto/declarative/qmlqt/data/darker.qml @@ -0,0 +1,8 @@ +import Qt 4.6 + +Object { + property var test1: Qt.darker(Qt.rgba(1, 0.8, 0.3)) + property var test2: Qt.darker() + property var test3: Qt.darker(Qt.rgba(1, 0.8, 0.3), 10) +} + diff --git a/tests/auto/declarative/qmlqt/data/enums.qml b/tests/auto/declarative/qmlqt/data/enums.qml new file mode 100644 index 0000000..f87886e --- /dev/null +++ b/tests/auto/declarative/qmlqt/data/enums.qml @@ -0,0 +1,9 @@ +import Qt 4.6 + +Object { + property int test1: Qt.Key_Escape + property int test2: Qt.DescendingOrder + property int test3: Qt.ElideMiddle + property int test4: Qt.AlignRight +} + diff --git a/tests/auto/declarative/qmlqt/data/hsla.qml b/tests/auto/declarative/qmlqt/data/hsla.qml new file mode 100644 index 0000000..fedb56a --- /dev/null +++ b/tests/auto/declarative/qmlqt/data/hsla.qml @@ -0,0 +1,11 @@ +import Qt 4.6 + +Object { + property color test1: Qt.hsla(1, 0, 0, 0.8); + property color test2: Qt.hsla(1, 0.5, 0.3); + property color test3: Qt.hsla(1, 1); + property color test4: Qt.hsla(1, 1, 1, 1, 1); + property color test5: Qt.hsla(1.2, 1, 1); + property color test6: Qt.hsla(-0.1, 1, 1); +} + diff --git a/tests/auto/declarative/qmlqt/data/lighter.qml b/tests/auto/declarative/qmlqt/data/lighter.qml new file mode 100644 index 0000000..6c888e7 --- /dev/null +++ b/tests/auto/declarative/qmlqt/data/lighter.qml @@ -0,0 +1,7 @@ +import Qt 4.6 + +Object { + property var test1: Qt.lighter(Qt.rgba(1, 0.8, 0.3)) + property var test2: Qt.lighter() + property var test3: Qt.lighter(Qt.rgba(1, 0.8, 0.3), 10) +} diff --git a/tests/auto/declarative/qmlqt/data/point.qml b/tests/auto/declarative/qmlqt/data/point.qml new file mode 100644 index 0000000..582cb00 --- /dev/null +++ b/tests/auto/declarative/qmlqt/data/point.qml @@ -0,0 +1,9 @@ +import Qt 4.6 + +Object { + property var test1: Qt.point(19, 34); + property var test2: Qt.point(-3, 109.2); + property var test3: Qt.point(-3); + property var test4: Qt.point(-3, 109.2, 1); +} + diff --git a/tests/auto/declarative/qmlqt/data/rect.qml b/tests/auto/declarative/qmlqt/data/rect.qml new file mode 100644 index 0000000..53d8c38 --- /dev/null +++ b/tests/auto/declarative/qmlqt/data/rect.qml @@ -0,0 +1,9 @@ +import Qt 4.6 + +Object { + property var test1: Qt.rect(10, 13, 100, 109) + property var test2: Qt.rect(-10, 13, 100, 109.6) + property var test3: Qt.rect(10, 13); + property var test4: Qt.rect(10, 13, 100, 109, 10) + property var test5: Qt.rect(10, 13, 100, -109) +} diff --git a/tests/auto/declarative/qmlqt/data/rgba.qml b/tests/auto/declarative/qmlqt/data/rgba.qml new file mode 100644 index 0000000..3fdfe2c --- /dev/null +++ b/tests/auto/declarative/qmlqt/data/rgba.qml @@ -0,0 +1,10 @@ +import Qt 4.6 + +Object { + property color test1: Qt.rgba(1, 0, 0, 0.8); + property color test2: Qt.rgba(1, 0.5, 0.3); + property color test3: Qt.rgba(1, 1); + property color test4: Qt.rgba(1, 1, 1, 1, 1); + property color test5: Qt.rgba(1.2, 1, 1); + property color test6: Qt.rgba(-0.1, 1, 1); +} diff --git a/tests/auto/declarative/qmlqt/data/size.qml b/tests/auto/declarative/qmlqt/data/size.qml new file mode 100644 index 0000000..f0d2e81 --- /dev/null +++ b/tests/auto/declarative/qmlqt/data/size.qml @@ -0,0 +1,11 @@ +import Qt 4.6 + +Object { + property var test1: Qt.size(19, 34); + property var test2: Qt.size(3, 109.2); + property var test3: Qt.size(-3, 10); + property var test4: Qt.size(3); + property var test5: Qt.size(3, 109.2, 1); +} + + diff --git a/tests/auto/declarative/qmlqt/data/tint.qml b/tests/auto/declarative/qmlqt/data/tint.qml new file mode 100644 index 0000000..31e67ba --- /dev/null +++ b/tests/auto/declarative/qmlqt/data/tint.qml @@ -0,0 +1,9 @@ +import Qt 4.6 + +Object { + 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 test4: Qt.tint("red", Qt.rgba(0, 0, 1, 0.5), 10); + property color test5: Qt.tint("red") +} diff --git a/tests/auto/declarative/qmlqt/data/vector.qml b/tests/auto/declarative/qmlqt/data/vector.qml new file mode 100644 index 0000000..b879bd6 --- /dev/null +++ b/tests/auto/declarative/qmlqt/data/vector.qml @@ -0,0 +1,8 @@ +import Qt 4.6 + +Object { + property var test1: Qt.vector3d(1, 0, 0.9); + property var test2: Qt.vector3d(102, -10, -982.1); + property var test3: Qt.vector3d(102, -10); + property var test4: Qt.vector3d(102, -10, -982.1, 10); +} diff --git a/tests/auto/declarative/qmlqt/qmlqt.pro b/tests/auto/declarative/qmlqt/qmlqt.pro new file mode 100644 index 0000000..5e79ea6 --- /dev/null +++ b/tests/auto/declarative/qmlqt/qmlqt.pro @@ -0,0 +1,9 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +SOURCES += tst_qmlqt.cpp +macx:CONFIG -= app_bundle + +DEFINES += SRCDIR=\\\"$$PWD\\\" + +# QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage +# LIBS += -lgcov diff --git a/tests/auto/declarative/qmlqt/tst_qmlqt.cpp b/tests/auto/declarative/qmlqt/tst_qmlqt.cpp new file mode 100644 index 0000000..10402ae --- /dev/null +++ b/tests/auto/declarative/qmlqt/tst_qmlqt.cpp @@ -0,0 +1,264 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +class tst_qmlqt : public QObject +{ + Q_OBJECT +public: + tst_qmlqt() {} + +private slots: + void enums(); + void rgba(); + void hsla(); + void rect(); + void point(); + void size(); + void vector(); + void lighter(); + void darker(); + void tint(); + void playSound(); + void openUrlExternally(); + +private: + QmlEngine engine; +}; + +inline QUrl TEST_FILE(const QString &filename) +{ + return QUrl::fromLocalFile(QLatin1String(SRCDIR) + QLatin1String("/data/") + filename); +} + +void tst_qmlqt::enums() +{ + QmlComponent component(&engine, TEST_FILE("enums.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("test1").toInt(), (int)Qt::Key_Escape); + QCOMPARE(object->property("test2").toInt(), (int)Qt::DescendingOrder); + QCOMPARE(object->property("test3").toInt(), (int)Qt::ElideMiddle); + QCOMPARE(object->property("test4").toInt(), (int)Qt::AlignRight); + + delete object; +} + +void tst_qmlqt::rgba() +{ + QmlComponent component(&engine, TEST_FILE("rgba.qml")); + + QString warning1 = component.url().toString() + ":6: Unable to assign null to QColor"; + QString warning2 = component.url().toString() + ":7: Unable to assign null to QColor"; + QString warning3 = component.url().toString() + ":8: Unable to assign null to QColor"; + QString warning4 = component.url().toString() + ":9: Unable to assign null to QColor"; + QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1)); + QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2)); + QTest::ignoreMessage(QtWarningMsg, qPrintable(warning3)); + QTest::ignoreMessage(QtWarningMsg, qPrintable(warning4)); + + QObject *object = component.create(); + QVERIFY(object != 0); + + + QCOMPARE(qvariant_cast(object->property("test1")), QColor::fromRgbF(1, 0, 0, 0.8)); + QCOMPARE(qvariant_cast(object->property("test2")), QColor::fromRgbF(1, 0.5, 0.3, 1)); + QCOMPARE(qvariant_cast(object->property("test3")), QColor()); + QCOMPARE(qvariant_cast(object->property("test4")), QColor()); + QCOMPARE(qvariant_cast(object->property("test5")), QColor()); + QCOMPARE(qvariant_cast(object->property("test6")), QColor()); + + delete object; +} + +void tst_qmlqt::hsla() +{ + QmlComponent component(&engine, TEST_FILE("hsla.qml")); + + QString warning1 = component.url().toString() + ":6: Unable to assign null to QColor"; + QString warning2 = component.url().toString() + ":7: Unable to assign null to QColor"; + QString warning3 = component.url().toString() + ":8: Unable to assign null to QColor"; + QString warning4 = component.url().toString() + ":9: Unable to assign null to QColor"; + QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1)); + QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2)); + QTest::ignoreMessage(QtWarningMsg, qPrintable(warning3)); + QTest::ignoreMessage(QtWarningMsg, qPrintable(warning4)); + + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(qvariant_cast(object->property("test1")), QColor::fromHslF(1, 0, 0, 0.8)); + QCOMPARE(qvariant_cast(object->property("test2")), QColor::fromHslF(1, 0.5, 0.3, 1)); + QCOMPARE(qvariant_cast(object->property("test3")), QColor()); + QCOMPARE(qvariant_cast(object->property("test4")), QColor()); + QCOMPARE(qvariant_cast(object->property("test5")), QColor()); + QCOMPARE(qvariant_cast(object->property("test6")), QColor()); + + delete object; +} + +void tst_qmlqt::rect() +{ + QmlComponent component(&engine, TEST_FILE("rect.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(qvariant_cast(object->property("test1")), QRectF(10, 13, 100, 109)); + QCOMPARE(qvariant_cast(object->property("test2")), QRectF(-10, 13, 100, 109.6)); + QCOMPARE(qvariant_cast(object->property("test3")), QRectF()); + QCOMPARE(qvariant_cast(object->property("test4")), QRectF()); + QCOMPARE(qvariant_cast(object->property("test5")), QRectF()); + + delete object; +} + +void tst_qmlqt::point() +{ + QmlComponent component(&engine, TEST_FILE("point.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(qvariant_cast(object->property("test1")), QPointF(19, 34)); + QCOMPARE(qvariant_cast(object->property("test2")), QPointF(-3, 109.2)); + QCOMPARE(qvariant_cast(object->property("test3")), QPointF()); + QCOMPARE(qvariant_cast(object->property("test4")), QPointF()); + + delete object; +} + +void tst_qmlqt::size() +{ + QmlComponent component(&engine, TEST_FILE("size.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(qvariant_cast(object->property("test1")), QSizeF(19, 34)); + QCOMPARE(qvariant_cast(object->property("test2")), QSizeF(3, 109.2)); + QCOMPARE(qvariant_cast(object->property("test3")), QSizeF(-3, 10)); + QCOMPARE(qvariant_cast(object->property("test4")), QSizeF()); + QCOMPARE(qvariant_cast(object->property("test5")), QSizeF()); + + delete object; +} + +void tst_qmlqt::vector() +{ + QmlComponent component(&engine, TEST_FILE("vector.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(qvariant_cast(object->property("test1")), QVector3D(1, 0, 0.9)); + QCOMPARE(qvariant_cast(object->property("test2")), QVector3D(102, -10, -982.1)); + QCOMPARE(qvariant_cast(object->property("test3")), QVector3D()); + QCOMPARE(qvariant_cast(object->property("test4")), QVector3D()); + + delete object; +} + +void tst_qmlqt::lighter() +{ + QmlComponent component(&engine, TEST_FILE("lighter.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(qvariant_cast(object->property("test1")), QColor::fromRgbF(1, 0.8, 0.3).lighter()); + QCOMPARE(qvariant_cast(object->property("test2")), QColor()); + QCOMPARE(qvariant_cast(object->property("test3")), QColor()); + + delete object; +} + +void tst_qmlqt::darker() +{ + QmlComponent component(&engine, TEST_FILE("darker.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(qvariant_cast(object->property("test1")), QColor::fromRgbF(1, 0.8, 0.3).darker()); + QCOMPARE(qvariant_cast(object->property("test2")), QColor()); + QCOMPARE(qvariant_cast(object->property("test3")), QColor()); + + delete object; +} + +void tst_qmlqt::tint() +{ + QmlComponent component(&engine, TEST_FILE("tint.qml")); + + QString warning1 = component.url().toString() + ":7: Unable to assign null to QColor"; + QString warning2 = component.url().toString() + ":8: Unable to assign null to QColor"; + QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1)); + QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2)); + + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(qvariant_cast(object->property("test1")), QColor::fromRgbF(0, 0, 1)); + QCOMPARE(qvariant_cast(object->property("test2")), QColor::fromRgbF(1, 0, 0)); + // Fails due to QT-2424 + QCOMPARE(qvariant_cast(object->property("test3")), QColor::fromRgbF(1, 0, 0)); + QCOMPARE(qvariant_cast(object->property("test4")), QColor()); + QCOMPARE(qvariant_cast(object->property("test5")), QColor()); + + delete object; +} + +void tst_qmlqt::playSound() +{ + QEXPECT_FAIL("", "How do we test this?", Abort); +} + +void tst_qmlqt::openUrlExternally() +{ + QEXPECT_FAIL("", "How do we test this?", Abort); +} + +QTEST_MAIN(tst_qmlqt) + +#include "tst_qmlqt.moc" -- cgit v0.12 From dc9e7a5b231bbd22ee237c1a4c1bc0076aa695fe Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Mon, 2 Nov 2009 09:32:38 +0100 Subject: Doc: Fixed typo --- src/declarative/graphicsitems/qmlgraphicslistview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp index dc8bab2..cf399f9 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp @@ -994,7 +994,7 @@ QmlGraphicsListView::~QmlGraphicsListView() /*! \qmlattachedproperty bool ListView::isCurrentItem - This attched property is true if this delegate is the current item; otherwise false. + This attached property is true if this delegate is the current item; otherwise false. It is attached to each instance of the delegate. -- cgit v0.12 From 7f86f70e98e0b826ad35b8bb744305b5f4dbbfe8 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Mon, 2 Nov 2009 09:32:56 +0100 Subject: Mark Action class as to be exported Used in Bauhaus. --- src/declarative/util/qmlstate_p.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/util/qmlstate_p.h b/src/declarative/util/qmlstate_p.h index 92aef8c..ff42893 100644 --- a/src/declarative/util/qmlstate_p.h +++ b/src/declarative/util/qmlstate_p.h @@ -54,7 +54,7 @@ QT_MODULE(Declarative) class ActionEvent; class QmlBinding; -class Action +class Q_DECLARATIVE_EXPORT Action { public: Action(); -- cgit v0.12 From 23d20f10cc89dedb21424924ef2654705267ba46 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Mon, 2 Nov 2009 16:57:06 +0100 Subject: Fix crash in assistant/WebKit by disabling animated gif declarative-tutorial3_animated.gif let WebKit crash on all platforms. Until this bug is fixed upstream just use a static image. --- doc/src/declarative/tutorial3.qdoc | 2 +- doc/src/images/declarative-tutorial3.gif | Bin 0 -> 3317 bytes 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 doc/src/images/declarative-tutorial3.gif diff --git a/doc/src/declarative/tutorial3.qdoc b/doc/src/declarative/tutorial3.qdoc index 290b535..c13accf 100644 --- a/doc/src/declarative/tutorial3.qdoc +++ b/doc/src/declarative/tutorial3.qdoc @@ -6,7 +6,7 @@ In this chapter, we make this example a little bit more dynamic by introducing s We want our text to move to the bottom of the screen, rotate and become red when clicked. -\image declarative-tutorial3_animation.gif +\image declarative-tutorial3.gif Here is the QML code: diff --git a/doc/src/images/declarative-tutorial3.gif b/doc/src/images/declarative-tutorial3.gif new file mode 100644 index 0000000..e2eae81 Binary files /dev/null and b/doc/src/images/declarative-tutorial3.gif differ -- cgit v0.12 From 170cf2d84158a071f8564c3fa65f6fd6afcada44 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 3 Nov 2009 09:24:55 +1000 Subject: Fix crash. --- doc/src/declarative/tutorial3.qdoc | 2 +- .../webkit/WebCore/platform/graphics/qt/ImageDecoderQt.cpp | 10 +--------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/doc/src/declarative/tutorial3.qdoc b/doc/src/declarative/tutorial3.qdoc index c13accf..290b535 100644 --- a/doc/src/declarative/tutorial3.qdoc +++ b/doc/src/declarative/tutorial3.qdoc @@ -6,7 +6,7 @@ In this chapter, we make this example a little bit more dynamic by introducing s We want our text to move to the bottom of the screen, rotate and become red when clicked. -\image declarative-tutorial3.gif +\image declarative-tutorial3_animation.gif Here is the QML code: diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/qt/ImageDecoderQt.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/qt/ImageDecoderQt.cpp index f8403b7..b6823dd 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/qt/ImageDecoderQt.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/qt/ImageDecoderQt.cpp @@ -145,16 +145,8 @@ RGBA32Buffer* ImageDecoderQt::frameBufferAtIndex(size_t index) return &frame; } -void ImageDecoderQt::clearFrameBufferCache(size_t index) +void ImageDecoderQt::clearFrameBufferCache(size_t /*index*/) { - // Currently QImageReader will be asked to read everything. This - // might change when we read gif images on demand. For now we - // can have a rather simple implementation. - if (index > m_frameBufferCache.size()) - return; - - for (size_t i = 0; i < index; ++index) - m_frameBufferCache[index].clear(); } void ImageDecoderQt::internalDecodeSize() -- cgit v0.12 From 5aea907a86fadf2c4a1223517ad3e28cba71a9d2 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 3 Nov 2009 09:35:08 +1000 Subject: Fix assertion (sc not declared). --- demos/declarative/webbrowser/webbrowser.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/declarative/webbrowser/webbrowser.qml b/demos/declarative/webbrowser/webbrowser.qml index 3b1ea57..cfc2aa7 100644 --- a/demos/declarative/webbrowser/webbrowser.qml +++ b/demos/declarative/webbrowser/webbrowser.qml @@ -271,7 +271,7 @@ Item { } onZooming: { if (centerX) { - sc = zoom/zoomFactor; + var sc = zoom/zoomFactor; scaleAnim.to = sc; flickVX.from = flickable.viewportX flickVX.to = Math.min(Math.max(0,centerX-flickable.width/2),webView.width*sc-flickable.width) -- cgit v0.12 From 1e8034a10d2496d7fb7aa987357333c6e2c3258d Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 3 Nov 2009 09:49:03 +1000 Subject: Accidental commit. --- tools/qdoc3/qmlcodemarker.cpp | 1175 ----------------------------------------- tools/qdoc3/qmlcodemarker.h | 96 ---- 2 files changed, 1271 deletions(-) delete mode 100644 tools/qdoc3/qmlcodemarker.cpp delete mode 100644 tools/qdoc3/qmlcodemarker.h diff --git a/tools/qdoc3/qmlcodemarker.cpp b/tools/qdoc3/qmlcodemarker.cpp deleted file mode 100644 index 1062f9c..0000000 --- a/tools/qdoc3/qmlcodemarker.cpp +++ /dev/null @@ -1,1175 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the tools applications 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$ -** -****************************************************************************/ - -/* - cppcodemarker.cpp -*/ - -#include -#include "atom.h" -#include "cppcodemarker.h" -#include "node.h" -#include "text.h" -#include "tree.h" - -QT_BEGIN_NAMESPACE - -static int insertTagAround(QString &result, int pos, int len, const QString &tagName, - const QString &attributes = QString()) -{ - QString s; - //s.reserve(result.size() + tagName.size() * 2 + attributes.size() + 20); - s += result.midRef(0, pos); - s += QLatin1Char('<'); - s += tagName; - if (!attributes.isEmpty()) { - s += QLatin1Char(' '); - s += attributes; - } - s += QLatin1Char('>'); - s += result.midRef(pos, len); - s += QLatin1String("'); - s += result.midRef(pos + len); - int diff = s.length() - result.length(); - result = s; - return diff; -} - -/*! - The constructor does nothing. - */ -CppCodeMarker::CppCodeMarker() -{ - // nothing. -} - -/*! - The destructor does nothing. - */ -CppCodeMarker::~CppCodeMarker() -{ - // nothing. -} - -/*! - Returns true. - */ -bool CppCodeMarker::recognizeCode(const QString & /* code */) -{ - return true; -} - -/*! - Returns true if \a ext is any of a list of file extensions - for the C++ language. - */ -bool CppCodeMarker::recognizeExtension(const QString& ext) -{ - return ext == "c" || - ext == "c++" || - ext == "cc" || - ext == "cpp" || - ext == "cxx" || - ext == "ch" || - ext == "h" || - ext == "h++" || - ext == "hh" || - ext == "hpp" || - ext == "hxx"; -} - -/*! - Returns true if \a lang is either "C" or "Cpp". - */ -bool CppCodeMarker::recognizeLanguage(const QString &lang) -{ - return lang == "C" || lang == "Cpp"; -} - -/*! - Returns the \a node name, or "()" if \a node is a - Node::Function node. - */ -QString CppCodeMarker::plainName(const Node *node) -{ - QString name = node->name(); - if (node->type() == Node::Function) - name += "()"; - return name; -} - -QString CppCodeMarker::plainFullName(const Node *node, const Node *relative) -{ - if (node->name().isEmpty()) { - return "global"; - } - else { - QString fullName; - for (;;) { - fullName.prepend(plainName(node)); - if (node->parent() == relative || node->parent()->name().isEmpty()) - break; - fullName.prepend("::"); - node = node->parent(); - } - return fullName; - } -} - -QString CppCodeMarker::markedUpCode(const QString &code, - const Node *relative, - const QString &dirPath) -{ - return addMarkUp(protect(code), relative, dirPath); -} - -QString CppCodeMarker::markedUpSynopsis(const Node *node, - const Node * /* relative */, - SynopsisStyle style) -{ - const int MaxEnumValues = 6; - const FunctionNode *func; - const PropertyNode *property; - const VariableNode *variable; - const EnumNode *enume; - const TypedefNode *typedeff; - QString synopsis; - QString extra; - QString name; - - name = taggedNode(node); - if (style != Detailed) - name = linkTag(node, name); - name = "<@name>" + name + ""; - - if (style == Detailed && !node->parent()->name().isEmpty() && - node->type() != Node::Property) - name.prepend(taggedNode(node->parent()) + "::"); - - switch (node->type()) { - case Node::Namespace: - synopsis = "namespace " + name; - break; - case Node::Class: - synopsis = "class " + name; - break; - case Node::Function: - func = (const FunctionNode *) node; - if (style != SeparateList && !func->returnType().isEmpty()) - synopsis = typified(func->returnType()) + " "; - synopsis += name; - if (func->metaness() != FunctionNode::MacroWithoutParams) { - synopsis += " ("; - if (!func->parameters().isEmpty()) { - synopsis += " "; - QList::ConstIterator p = func->parameters().begin(); - while (p != func->parameters().end()) { - if (p != func->parameters().begin()) - synopsis += ", "; - synopsis += typified((*p).leftType()); - if (style != SeparateList && !(*p).name().isEmpty()) - synopsis += - " <@param>" + protect((*p).name()) + ""; - synopsis += protect((*p).rightType()); - if (style != SeparateList && !(*p).defaultValue().isEmpty()) - synopsis += " = " + protect((*p).defaultValue()); - ++p; - } - synopsis += " "; - } - synopsis += ")"; - } - if (func->isConst()) - synopsis += " const"; - - if (style == Summary || style == Accessors) { - if (func->virtualness() != FunctionNode::NonVirtual) - synopsis.prepend("virtual "); - if (func->virtualness() == FunctionNode::PureVirtual) - synopsis.append(" = 0"); - } - else if (style == SeparateList) { - if (!func->returnType().isEmpty() && func->returnType() != "void") - synopsis += " : " + typified(func->returnType()); - } - else { - QStringList bracketed; - if (func->isStatic()) { - bracketed += "static"; - } - else if (func->virtualness() != FunctionNode::NonVirtual) { - if (func->virtualness() == FunctionNode::PureVirtual) - bracketed += "pure"; - bracketed += "virtual"; - } - - if (func->access() == Node::Protected) { - bracketed += "protected"; - } - else if (func->access() == Node::Private) { - bracketed += "private"; - } - - if (func->metaness() == FunctionNode::Signal) { - bracketed += "signal"; - } - else if (func->metaness() == FunctionNode::Slot) { - bracketed += "slot"; - } - if (!bracketed.isEmpty()) - extra += " [" + bracketed.join(" ") + "]"; - } - break; - case Node::Enum: - enume = static_cast(node); - synopsis = "enum " + name; - if (style == Summary) { - synopsis += " { "; - - QStringList documentedItems = enume->doc().enumItemNames(); - if (documentedItems.isEmpty()) { - foreach (const EnumItem &item, enume->items()) - documentedItems << item.name(); - } - QStringList omitItems = enume->doc().omitEnumItemNames(); - foreach (const QString &item, omitItems) - documentedItems.removeAll(item); - - if (documentedItems.size() <= MaxEnumValues) { - for (int i = 0; i < documentedItems.size(); ++i) { - if (i != 0) - synopsis += ", "; - synopsis += documentedItems.at(i); - } - } - else { - for (int i = 0; i < documentedItems.size(); ++i) { - if (i < MaxEnumValues-2 || i == documentedItems.size()-1) { - if (i != 0) - synopsis += ", "; - synopsis += documentedItems.at(i); - } - else if (i == MaxEnumValues - 1) { - synopsis += ", ..."; - } - } - } - if (!documentedItems.isEmpty()) - synopsis += " "; - synopsis += "}"; - } - break; - case Node::Typedef: - typedeff = static_cast(node); - if (typedeff->associatedEnum()) { - synopsis = "flags " + name; - } - else { - synopsis = "typedef " + name; - } - break; - case Node::Property: - property = static_cast(node); - synopsis = name + " : " + typified(property->qualifiedDataType()); - break; - case Node::Variable: - variable = static_cast(node); - if (style == SeparateList) { - synopsis = name + " : " + typified(variable->dataType()); - } - else { - synopsis = typified(variable->leftType()) + " " + - name + protect(variable->rightType()); - } - break; - default: - synopsis = name; - } - - if (style == Summary) { - if (node->status() == Node::Preliminary) { - extra += " (preliminary)"; - } - else if (node->status() == Node::Deprecated) { - extra += " (deprecated)"; - } - else if (node->status() == Node::Obsolete) { - extra += " (obsolete)"; - } - } - - if (!extra.isEmpty()) { - extra.prepend("<@extra>"); - extra.append(""); - } - return synopsis + extra; -} - -#ifdef QDOC_QML -/*! - */ -QString CppCodeMarker::markedUpQmlItem(const Node* node, bool summary) -{ - QString name = taggedQmlNode(node); - if (summary) { - name = linkTag(node,name); - } - name = "<@name>" + name + ""; - QString synopsis = name; - if (node->type() == Node::QmlProperty) { - const QmlPropertyNode* pn = static_cast(node); - synopsis += " : " + typified(pn->dataType()); - } - - QString extra; - if (summary) { - if (node->status() == Node::Preliminary) { - extra += " (preliminary)"; - } - else if (node->status() == Node::Deprecated) { - extra += " (deprecated)"; - } - else if (node->status() == Node::Obsolete) { - extra += " (obsolete)"; - } - } - - if (!extra.isEmpty()) { - extra.prepend("<@extra>"); - extra.append(""); - } - return synopsis + extra; -} -#endif - -QString CppCodeMarker::markedUpName(const Node *node) -{ - QString name = linkTag(node, taggedNode(node)); - if (node->type() == Node::Function) - name += "()"; - return name; -} - -QString CppCodeMarker::markedUpFullName(const Node *node, const Node *relative) -{ - if (node->name().isEmpty()) { - return "global"; - } - else { - QString fullName; - for (;;) { - fullName.prepend(markedUpName(node)); - if (node->parent() == relative || node->parent()->name().isEmpty()) - break; - fullName.prepend("<@op>::"); - node = node->parent(); - } - return fullName; - } -} - -QString CppCodeMarker::markedUpEnumValue(const QString &enumValue, - const Node *relative) -{ - const Node *node = relative->parent(); - QString fullName; - while (node->parent()) { - fullName.prepend(markedUpName(node)); - if (node->parent() == relative || node->parent()->name().isEmpty()) - break; - fullName.prepend("<@op>::"); - node = node->parent(); - } - if (!fullName.isEmpty()) - fullName.append("<@op>::"); - fullName.append(enumValue); - return fullName; -} - -QString CppCodeMarker::markedUpIncludes(const QStringList& includes) -{ - QString code; - - QStringList::ConstIterator inc = includes.begin(); - while (inc != includes.end()) { - code += "#include <<@headerfile>" + *inc + ">\n"; - ++inc; - } - return addMarkUp(code, 0, ""); -} - -QString CppCodeMarker::functionBeginRegExp(const QString& funcName) -{ - return "^" + QRegExp::escape(funcName) + "$"; - -} - -QString CppCodeMarker::functionEndRegExp(const QString& /* funcName */) -{ - return "^\\}$"; -} - -#if 0 - FastSection privateReimpFuncs(classe, - "Private Reimplemented Functions", - "private reimplemented function", - "private reimplemented functions"); - FastSection protectedReimpFuncs(classe, - "Protected Reimplemented Functions", - "protected reimplemented function", - "protected reimplemented functions"); - FastSection publicReimpFuncs(classe, - "Public Reimplemented Functions", - "public reimplemented function", - "public reimplemented functions"); -#endif - -QList
CppCodeMarker::sections(const InnerNode *inner, - SynopsisStyle style, - Status status) -{ - QList
sections; - - if (inner->type() == Node::Class) { - const ClassNode *classe = static_cast(inner); - - if (style == Summary) { - FastSection privateFunctions(classe, - "Private Functions", - "private function", - "private functions"); - FastSection privateSlots(classe, "Private Slots", "private slot", "private slots"); - FastSection privateTypes(classe, "Private Types", "private type", "private types"); - FastSection protectedFunctions(classe, - "Protected Functions", - "protected function", - "protected functions"); - FastSection protectedSlots(classe, - "Protected Slots", - "protected slot", - "protected slots"); - FastSection protectedTypes(classe, - "Protected Types", - "protected type", - "protected types"); - FastSection protectedVariables(classe, - "Protected Variables", - "protected type", - "protected variables"); - FastSection publicFunctions(classe, - "Public Functions", - "public function", - "public functions"); - FastSection publicSignals(classe, "Signals", "signal", "signals"); - FastSection publicSlots(classe, "Public Slots", "public slot", "public slots"); - FastSection publicTypes(classe, "Public Types", "public type", "public types"); - FastSection publicVariables(classe, - "Public Variables", - "public type", - "public variables"); - FastSection properties(classe, "Properties", "property", "properties"); - FastSection relatedNonMembers(classe, - "Related Non-Members", - "related non-member", - "related non-members"); - FastSection staticPrivateMembers(classe, - "Static Private Members", - "static private member", - "static private members"); - FastSection staticProtectedMembers(classe, - "Static Protected Members", - "static protected member", - "static protected members"); - FastSection staticPublicMembers(classe, - "Static Public Members", - "static public member", - "static public members"); - FastSection macros(inner, "Macros", "macro", "macros"); - - NodeList::ConstIterator r = classe->relatedNodes().begin(); - while (r != classe->relatedNodes().end()) { - if ((*r)->type() == Node::Function) { - FunctionNode *func = static_cast(*r); - if (func->isMacro()) - insert(macros, *r, style, status); - else - insert(relatedNonMembers, *r, style, status); - } - else { - insert(relatedNonMembers, *r, style, status); - } - ++r; - } - - QStack stack; - stack.push(classe); - - while (!stack.isEmpty()) { - const ClassNode *ancestorClass = stack.pop(); - - NodeList::ConstIterator c = ancestorClass->childNodes().begin(); - while (c != ancestorClass->childNodes().end()) { - bool isSlot = false; - bool isSignal = false; - bool isStatic = false; - if ((*c)->type() == Node::Function) { - const FunctionNode *func = (const FunctionNode *) *c; - isSlot = (func->metaness() == FunctionNode::Slot); - isSignal = (func->metaness() == FunctionNode::Signal); - isStatic = func->isStatic(); - } - else if ((*c)->type() == Node::Variable) { - const VariableNode *var = static_cast(*c); - isStatic = var->isStatic(); - } - - switch ((*c)->access()) { - case Node::Public: - if (isSlot) { - insert(publicSlots, *c, style, status); - } - else if (isSignal) { - insert(publicSignals, *c, style, status); - } - else if (isStatic) { - if ((*c)->type() != Node::Variable - || !(*c)->doc().isEmpty()) - insert(staticPublicMembers,*c,style,status); - } - else if ((*c)->type() == Node::Property) { - insert(properties, *c, style, status); - } - else if ((*c)->type() == Node::Variable) { - if (!(*c)->doc().isEmpty()) - insert(publicVariables, *c, style, status); - } - else if ((*c)->type() == Node::Function) { - if (!insertReimpFunc(publicFunctions,*c,status)) - insert(publicFunctions, *c, style, status); - } - else { - insert(publicTypes, *c, style, status); - } - break; - case Node::Protected: - if (isSlot) { - insert(protectedSlots, *c, style, status); - } - else if (isStatic) { - if ((*c)->type() != Node::Variable - || !(*c)->doc().isEmpty()) - insert(staticProtectedMembers,*c,style,status); - } - else if ((*c)->type() == Node::Variable) { - if (!(*c)->doc().isEmpty()) - insert(protectedVariables,*c,style,status); - } - else if ((*c)->type() == Node::Function) { - if (!insertReimpFunc(protectedFunctions,*c,status)) - insert(protectedFunctions, *c, style, status); - } - else { - insert(protectedTypes, *c, style, status); - } - break; - case Node::Private: - if (isSlot) { - insert(privateSlots, *c, style, status); - } - else if (isStatic) { - if ((*c)->type() != Node::Variable - || !(*c)->doc().isEmpty()) - insert(staticPrivateMembers,*c,style,status); - } - else if ((*c)->type() == Node::Function) { - if (!insertReimpFunc(privateFunctions,*c,status)) - insert(privateFunctions, *c, style, status); - } - else { - insert(privateTypes,*c,style,status); - } - } - ++c; - } - - QList::ConstIterator r = - ancestorClass->baseClasses().begin(); - while (r != ancestorClass->baseClasses().end()) { - stack.prepend((*r).node); - ++r; - } - } - - append(sections, publicTypes); - append(sections, properties); - append(sections, publicFunctions); - append(sections, publicSlots); - append(sections, publicSignals); - append(sections, publicVariables); - append(sections, staticPublicMembers); - append(sections, protectedTypes); - append(sections, protectedFunctions); - append(sections, protectedSlots); - append(sections, protectedVariables); - append(sections, staticProtectedMembers); - append(sections, privateTypes); - append(sections, privateFunctions); - append(sections, privateSlots); - append(sections, staticPrivateMembers); - append(sections, relatedNonMembers); - append(sections, macros); - } - else if (style == Detailed) { - FastSection memberFunctions(classe,"Member Function Documentation"); - FastSection memberTypes(classe,"Member Type Documentation"); - FastSection memberVariables(classe,"Member Variable Documentation"); - FastSection properties(classe,"Property Documentation"); - FastSection relatedNonMembers(classe,"Related Non-Members"); - FastSection macros(classe,"Macro Documentation"); - - NodeList::ConstIterator r = classe->relatedNodes().begin(); - while (r != classe->relatedNodes().end()) { - if ((*r)->type() == Node::Function) { - FunctionNode *func = static_cast(*r); - if (func->isMacro()) - insert(macros, *r, style, status); - else - insert(relatedNonMembers, *r, style, status); - } - else { - insert(relatedNonMembers, *r, style, status); - } - ++r; - } - - NodeList::ConstIterator c = classe->childNodes().begin(); - while (c != classe->childNodes().end()) { - if ((*c)->type() == Node::Enum || - (*c)->type() == Node::Typedef) { - insert(memberTypes, *c, style, status); - } - else if ((*c)->type() == Node::Property) { - insert(properties, *c, style, status); - } - else if ((*c)->type() == Node::Variable) { - if (!(*c)->doc().isEmpty()) - insert(memberVariables, *c, style, status); - } - else if ((*c)->type() == Node::Function) { - FunctionNode *function = static_cast(*c); - if (!function->associatedProperty()) - insert(memberFunctions, function, style, status); - } - ++c; - } - - append(sections, memberTypes); - append(sections, properties); - append(sections, memberFunctions); - append(sections, memberVariables); - append(sections, relatedNonMembers); - append(sections, macros); - } - else { - FastSection all(classe); - - QStack stack; - stack.push(classe); - - while (!stack.isEmpty()) { - const ClassNode *ancestorClass = stack.pop(); - - NodeList::ConstIterator c = ancestorClass->childNodes().begin(); - while (c != ancestorClass->childNodes().end()) { - if ((*c)->access() != Node::Private && - (*c)->type() != Node::Property) - insert(all, *c, style, status); - ++c; - } - - QList::ConstIterator r = - ancestorClass->baseClasses().begin(); - while (r != ancestorClass->baseClasses().end()) { - stack.prepend((*r).node); - ++r; - } - } - append(sections, all); - } - } - else { - if (style == Summary || style == Detailed) { - FastSection namespaces(inner, - "Namespaces", - "namespace", - "namespaces"); - FastSection classes(inner, - "Classes", - "class", - "classes"); - FastSection types(inner, - style == Summary ? - "Types" : "Type Documentation", - "type", - "types"); - FastSection functions(inner, - style == Summary ? - "Functions" : "Function Documentation", - "function", - "functions"); - FastSection macros(inner, - style == Summary ? - "Macros" : "Macro Documentation", - "macro", - "macros"); - - NodeList nodeList = inner->childNodes(); - nodeList += inner->relatedNodes(); - - NodeList::ConstIterator n = nodeList.begin(); - while (n != nodeList.end()) { - switch ((*n)->type()) { - case Node::Namespace: - insert(namespaces, *n, style, status); - break; - case Node::Class: - insert(classes, *n, style, status); - break; - case Node::Enum: - case Node::Typedef: - insert(types, *n, style, status); - break; - case Node::Function: - { - FunctionNode *func = static_cast(*n); - if (func->isMacro()) - insert(macros, *n, style, status); - else - insert(functions, *n, style, status); - } - break; - default: - ; - } - ++n; - } - append(sections, namespaces); - append(sections, classes); - append(sections, types); - append(sections, functions); - append(sections, macros); - } - } - - return sections; -} - -const Node *CppCodeMarker::resolveTarget(const QString &target, - const Tree *tree, - const Node *relative) -{ - if (target.endsWith("()")) { - const FunctionNode *func; - QString funcName = target; - funcName.chop(2); - - QStringList path = funcName.split("::"); - if ((func = tree->findFunctionNode(path, - relative, - Tree::SearchBaseClasses)) - && func->metaness() != FunctionNode::MacroWithoutParams) - return func; - } - else if (target.contains("#")) { - // ### this doesn't belong here; get rid of TargetNode hack - int hashAt = target.indexOf("#"); - QString link = target.left(hashAt); - QString ref = target.mid(hashAt + 1); - const Node *node; - if (link.isEmpty()) { - node = relative; - } - else { - QStringList path(link); - node = tree->findNode(path, tree->root(), Tree::SearchBaseClasses); - } - if (node && node->isInnerNode()) { - const Atom *atom = node->doc().body().firstAtom(); - while (atom) { - if (atom->type() == Atom::Target && atom->string() == ref) { - Node *parentNode = const_cast(node); - return new TargetNode(static_cast(parentNode), - ref); - } - atom = atom->next(); - } - } - } - else { - QStringList path = target.split("::"); - const Node *node; - if ((node = tree->findNode(path, - relative, - Tree::SearchBaseClasses | - Tree::SearchEnumValues | - Tree::NonFunction))) - return node; - } - return 0; -} - -QString CppCodeMarker::addMarkUp(const QString& protectedCode, - const Node * /* relative */, - const QString& /* dirPath */) -{ - static QRegExp globalInclude("#include +<([^<>&]+)>"); - static QRegExp yHasTypeX("(?:^|\n *)([a-zA-Z_][a-zA-Z_0-9]*)" - "(?:<[^;{}]+>)?(?: *(?:\\*|&) *| +)" - "([a-zA-Z_][a-zA-Z_0-9]*)? *[,;()=]"); - static QRegExp xNewY("([a-zA-Z_][a-zA-Z_0-9]*) *= *new +([a-zA-Z_0-9]+)"); - static QRegExp xDotY("\\b([a-zA-Z_][a-zA-Z_0-9]*) *(?:\\.|->|,[ \n]*S(?:IGNAL|LOT)\\() *" - "([a-zA-Z_][a-zA-Z_0-9]*)(?= *\\()"); - static QRegExp xIsStaticZOfY("[\n:;{(=] *(([a-zA-Z_0-9]+)::([a-zA-Z_0-9]+))(?= *\\()"); - static QRegExp classX("[:,][ \n]*(?:p(?:ublic|r(?:otected|ivate))[ \n]+)?" - "([a-zA-Z_][a-zA-Z_0-9]*)"); - static QRegExp globalX("[\n{()=] *([a-zA-Z_][a-zA-Z_0-9]*)[ \n]*\\("); - static QRegExp multiLineComment("/(?:( )?\\*(?:[^*]+|\\*(?! /))*\\*\\1/)"); - multiLineComment.setMinimal(true); - static QRegExp singleLineComment("//(?!!)[^!\n]*"); - static QRegExp preprocessor("(?:^|\n)(#[ \t]*(?:include|if|elif|endif|error|pragma|define" - "|warning)(?:(?:\\\\\n|\\n#)[^\n]*)*)"); - static QRegExp literals(""(?:[^\\\\&]|\\\\[^\n]|&(?!quot;))*"" - "|'(?:[^\\\\]|\\\\(?:[^x0-9']|x[0-9a-f]{1,4}|[0-9]{1,3}))'"); - - QString result = protectedCode; - int pos; - - if (!hurryUp()) { - /* - Mark global includes. For example: - - #include <<@headerfile>QString - */ - pos = 0; - while ((pos = result.indexOf(globalInclude, pos)) != -1) - pos += globalInclude.matchedLength() - + insertTagAround(result, - globalInclude.pos(1), - globalInclude.cap(1).length(), - "@headerfile"); - - /* - Look for variable definitions and similar constructs, mark - the data type, and remember the type of the variable. - */ - QMap > typesForVariable; - pos = 0; - while ((pos = yHasTypeX.indexIn(result, pos)) != -1) { - QString x = yHasTypeX.cap(1); - QString y = yHasTypeX.cap(2); - - if (!y.isEmpty()) - typesForVariable[y].insert(x); - - /* - Without the minus one at the end, 'void member(Class - var)' would give 'member' as a variable of type 'void', - but would ignore 'Class var'. (### Is that true?) - */ - pos += yHasTypeX.matchedLength() - + insertTagAround(result, - yHasTypeX.pos(1), - x.length(), - "@type") - 1; - } - - /* - Do syntax highlighting of preprocessor directives. - */ - pos = 0; - while ((pos = preprocessor.indexIn(result, pos)) != -1) - pos += preprocessor.matchedLength() - + insertTagAround(result, - preprocessor.pos(1), - preprocessor.cap(1).length(), - "@preprocessor"); - - /* - Deal with string and character literals. - */ - pos = 0; - while ((pos = literals.indexIn(result, pos)) != -1) - pos += literals.matchedLength() - + insertTagAround(result, - pos, - literals.matchedLength(), - result.at(pos) == - QLatin1Char(' ') ? "@string" : "@char"); - - /* - Look for 'var = new Class'. - */ - pos = 0; - while ((pos = xNewY.indexIn(result, pos)) != -1) { - QString x = xNewY.cap(1); - QString y = xNewY.cap(2); - typesForVariable[x].insert(y); - - pos += xNewY.matchedLength() + insertTagAround(result, - xNewY.pos(2), - y.length(), - "@type"); - } - - /* - Insert some stuff that cannot harm. - */ - typesForVariable["qApp"].insert("QApplication"); - - /* - Add link to ': Class'. - */ - pos = 0; - while ((pos = classX.indexIn(result, pos)) != -1) - pos += classX.matchedLength() - + insertTagAround(result, - classX.pos(1), - classX.cap(1).length(), - "@type") - 1; - - /* - Find use of any of - - var.method() - var->method() - var, SIGNAL(method()) - var, SLOT(method()). - */ - pos = 0; - while ((pos = xDotY.indexIn(result, pos)) != -1) { - QString x = xDotY.cap(1); - QString y = xDotY.cap(2); - - QSet types = typesForVariable.value(x); - pos += xDotY.matchedLength() - + insertTagAround(result, - xDotY.pos(2), - xDotY.cap(2).length(), - "@func", - (types.count() == 1) ? "target=\"" - + protect(*types.begin() + "::" + y) - + "()\"" : QString()); - } - - /* - Add link to 'Class::method()'. - */ - pos = 0; - while ((pos = xIsStaticZOfY.indexIn(result, pos)) != -1) { - QString x = xIsStaticZOfY.cap(1); - QString z = xIsStaticZOfY.cap(3); - - pos += insertTagAround(result, - xIsStaticZOfY.pos(3), - z.length(), - "@func", - "target=\"" + protect(x) + "()\""); - pos += insertTagAround(result, - xIsStaticZOfY.pos(2), - xIsStaticZOfY.cap(2).length(), - "@type"); - pos += xIsStaticZOfY.matchedLength() - 1; - } - - /* - Add link to 'globalFunction()'. - */ - pos = 0; - while ((pos = globalX.indexIn(result, pos)) != -1) { - QString x = globalX.cap(1); - if (x != "QT_FORWARD_DECLARE_CLASS") { - pos += globalX.matchedLength() - + insertTagAround(result, - globalX.pos(1), - x.length(), - "@func", - "target=\"" + protect(x) + "()\"") - 1; - } - else - pos += globalX.matchedLength(); - } - } - - /* - Do syntax highlighting of comments. Also alter the code in a - minor way, so that we can include comments in documentation - comments. - */ - pos = 0; - while (pos != -1) { - int mlpos; - int slpos; - int len; - slpos = singleLineComment.indexIn(result, pos); - mlpos = multiLineComment.indexIn(result, pos); - - if (slpos == -1 && mlpos == -1) - break; - - if (slpos == -1) { - pos = mlpos; - len = multiLineComment.matchedLength(); - } - else if (mlpos == -1) { - pos = slpos; - len = singleLineComment.matchedLength(); - } - else { - if (slpos < mlpos) { - pos = slpos; - len = singleLineComment.matchedLength(); - } - else { - pos = mlpos; - len = multiLineComment.matchedLength(); - } - } - - if (result.at(pos + 1) == QLatin1Char(' ')) { - result.remove(pos + len - 2, 1); - result.remove(pos + 1, 1); - len -= 2; - - forever { - int endcodePos = result.indexOf("\\ endcode", pos); - if (endcodePos == -1 || endcodePos >= pos + len) - break; - result.remove(endcodePos + 1, 1); - len -= 1; - } - } - pos += len + insertTagAround(result, pos, len, "@comment"); - } - - return result; -} - -#ifdef QDOC_QML -/*! - This function is for documenting QML properties. It returns - the list of documentation sections for the children of the - \a qmlClassNode. - - Currently, it only handles QML property groups. - */ -QList
CppCodeMarker::qmlSections(const QmlClassNode* qmlClassNode, - SynopsisStyle style) -{ - QList
sections; - if (qmlClassNode) { - if (style == Summary) { - FastSection qmlproperties(qmlClassNode, - "Properties", - "property", - "properties"); - FastSection qmlsignals(qmlClassNode, - "Signals", - "signal", - "signals"); - FastSection qmlmethods(qmlClassNode, - "Methods", - "method", - "methods"); - - NodeList::ConstIterator c = qmlClassNode->childNodes().begin(); - while (c != qmlClassNode->childNodes().end()) { - if ((*c)->subType() == Node::QmlPropertyGroup) { - const QmlPropGroupNode* qpgn = static_cast(*c); - NodeList::ConstIterator p = qpgn->childNodes().begin(); - while (p != qpgn->childNodes().end()) { - if ((*p)->type() == Node::QmlProperty) { - insert(qmlproperties,*p,style,Okay); - } - ++p; - } - } - else if ((*c)->type() == Node::QmlSignal) { - insert(qmlsignals,*c,style,Okay); - } - else if ((*c)->type() == Node::QmlMethod) { - insert(qmlmethods,*c,style,Okay); - } - ++c; - } - append(sections,qmlproperties); - append(sections,qmlsignals); - append(sections,qmlmethods); - } - else if (style == Detailed) { - FastSection qmlproperties(qmlClassNode, "Property Documentation"); - FastSection qmlsignals(qmlClassNode,"Signal Documentation"); - FastSection qmlmethods(qmlClassNode,"Method Documentation"); - NodeList::ConstIterator c = qmlClassNode->childNodes().begin(); - while (c != qmlClassNode->childNodes().end()) { - if ((*c)->subType() == Node::QmlPropertyGroup) { - insert(qmlproperties,*c,style,Okay); - } - else if ((*c)->type() == Node::QmlSignal) { - insert(qmlsignals,*c,style,Okay); - } - else if ((*c)->type() == Node::QmlMethod) { - insert(qmlmethods,*c,style,Okay); - } - ++c; - } - append(sections,qmlproperties); - append(sections,qmlsignals); - append(sections,qmlmethods); - } - } - - return sections; -} -#endif - -QT_END_NAMESPACE diff --git a/tools/qdoc3/qmlcodemarker.h b/tools/qdoc3/qmlcodemarker.h deleted file mode 100644 index 8c83c04..0000000 --- a/tools/qdoc3/qmlcodemarker.h +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the tools applications 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$ -** -****************************************************************************/ - -/* - cppcodemarker.h -*/ - -#ifndef CPPCODEMARKER_H -#define CPPCODEMARKER_H - -#include "codemarker.h" - -QT_BEGIN_NAMESPACE - -class CppCodeMarker : public CodeMarker -{ - public: - CppCodeMarker(); - ~CppCodeMarker(); - - bool recognizeCode(const QString& code); - bool recognizeExtension(const QString& ext); - bool recognizeLanguage(const QString& lang); - QString plainName(const Node *node); - QString plainFullName(const Node *node, const Node *relative); - QString markedUpCode(const QString& code, - const Node *relative, - const QString& dirPath); - QString markedUpSynopsis(const Node *node, - const Node *relative, - SynopsisStyle style); -#ifdef QDOC_QML - QString markedUpQmlItem(const Node *node, bool summary); -#endif - QString markedUpName(const Node *node); - QString markedUpFullName(const Node *node, const Node *relative); - QString markedUpEnumValue(const QString &enumValue, const Node *relative); - QString markedUpIncludes(const QStringList& includes); - QString functionBeginRegExp(const QString& funcName); - QString functionEndRegExp(const QString& funcName); - QList
sections(const InnerNode *innerNode, - SynopsisStyle style, - Status status); - QList
qmlSections(const QmlClassNode* qmlClassNode, - SynopsisStyle style); - const Node *resolveTarget(const QString& target, - const Tree *tree, - const Node *relative); - -private: - QString addMarkUp(const QString& protectedCode, - const Node *relative, - const QString& dirPath); -}; - -QT_END_NAMESPACE - -#endif -- cgit v0.12 From 6d7888aa59f08a0f91aaf844f27dc0c9462707f6 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 3 Nov 2009 10:19:07 +1000 Subject: Fix repeater + positioners. Don't leave empty space (or an empty cell) where the repeater would be. --- .../graphicsitems/qmlgraphicspositioners.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp index ba696e7..35b0833 100644 --- a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp +++ b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp @@ -481,6 +481,11 @@ QmlGraphicsColumn::QmlGraphicsColumn(QmlGraphicsItem *parent) { } +inline bool isInvisible(QmlGraphicsItem *child) +{ + return child->opacity() == 0.0 || !child->isVisible() || !child->width() || !child->height(); +} + void QmlGraphicsColumn::doPositioning() { int voffset = 0; @@ -495,7 +500,7 @@ void QmlGraphicsColumn::doPositioning() QList children = childItems(); for (int ii = 0; ii < children.count(); ++ii) { QmlGraphicsItem *child = qobject_cast(children.at(ii)); - if (!child || child->opacity() == 0.0) + if (!child || isInvisible(child)) continue; bool needMove = (child->y() != voffset || child->x()); @@ -651,7 +656,7 @@ void QmlGraphicsRow::doPositioning() QList children = childItems(); for (int ii = 0; ii < children.count(); ++ii) { QmlGraphicsItem *child = qobject_cast(children.at(ii)); - if (!child || child->opacity() == 0.0) + if (!child || isInvisible(child)) continue; bool needMove = (child->x() != hoffset || child->y()); @@ -668,10 +673,8 @@ void QmlGraphicsRow::doPositioning() child->setX(hoffset); setMovingItem(0); } - if(child->width() && child->height()){//don't advance for invisible children - hoffset += child->width(); - hoffset += spacing(); - } + hoffset += child->width(); + hoffset += spacing(); } } @@ -867,7 +870,7 @@ void QmlGraphicsGrid::doPositioning() if (childIndex == children.count()) continue; QmlGraphicsItem *child = qobject_cast(children.at(childIndex++)); - if (!child || child->opacity() == 0.0) + if (!child || isInvisible(child)) continue; if (child->width() > maxColWidth[j]) maxColWidth[j] = child->width(); @@ -888,7 +891,7 @@ void QmlGraphicsGrid::doPositioning() } foreach(QGraphicsItem* schild, children){ QmlGraphicsItem *child = qobject_cast(schild); - if (!child || child->opacity() == 0.0) + if (!child || isInvisible(child)) continue; bool needMove = (child->x()!=xoffset)||(child->y()!=yoffset); QList > changes; -- cgit v0.12 From 203232ffdc781eff1e320eb8f20311913640e163 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 3 Nov 2009 11:15:43 +1000 Subject: Doc. --- doc/src/declarative/elements.qdoc | 7 +- .../graphicsitems/qmlgraphicsflickable.cpp | 2 +- .../graphicsitems/qmlgraphicsfocuspanel.cpp | 2 +- .../graphicsitems/qmlgraphicsfocusscope.cpp | 2 +- .../graphicsitems/qmlgraphicsgridview.cpp | 2 +- .../graphicsitems/qmlgraphicslistview.cpp | 2 +- .../graphicsitems/qmlgraphicsloader.cpp | 2 +- .../graphicsitems/qmlgraphicsmouseregion.cpp | 2 +- src/declarative/graphicsitems/qmlgraphicspath.cpp | 12 +-- .../graphicsitems/qmlgraphicspathview.cpp | 2 +- .../graphicsitems/qmlgraphicspositioners.cpp | 4 +- .../graphicsitems/qmlgraphicsrepeater.cpp | 2 +- .../graphicsitems/qmlgraphicstextedit.cpp | 2 +- .../graphicsitems/qmlgraphicstextinput.cpp | 2 +- .../graphicsitems/qmlgraphicswebview.cpp | 2 +- src/declarative/util/qmlstategroup.cpp | 85 ++++++++++++++++++++++ 16 files changed, 109 insertions(+), 23 deletions(-) diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc index 0eda95e..69535ce 100644 --- a/doc/src/declarative/elements.qdoc +++ b/doc/src/declarative/elements.qdoc @@ -60,9 +60,10 @@ The following table lists the QML elements provided by the Qt Declarative module \list \o \l State \o \l PropertyChanges -\o \l ParentChange -\o \l StateChangeScript -\o \l AnchorChanges +\o \l StateGroup +\o \l ParentChange (Item-specific) +\o \l StateChangeScript (Item-specific) +\o \l AnchorChanges (Item-specific) \endlist \o diff --git a/src/declarative/graphicsitems/qmlgraphicsflickable.cpp b/src/declarative/graphicsitems/qmlgraphicsflickable.cpp index 8895977..19c5abc 100644 --- a/src/declarative/graphicsitems/qmlgraphicsflickable.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsflickable.cpp @@ -344,7 +344,7 @@ void QmlGraphicsFlickablePrivate::updateBeginningEnd() QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Flickable,QmlGraphicsFlickable) /*! - \qmlclass Flickable QFxFlickable + \qmlclass Flickable QmlGraphicsFlickable \brief The Flickable item provides a surface that can be "flicked". \inherits Item diff --git a/src/declarative/graphicsitems/qmlgraphicsfocuspanel.cpp b/src/declarative/graphicsitems/qmlgraphicsfocuspanel.cpp index d3ee184..a19e355 100644 --- a/src/declarative/graphicsitems/qmlgraphicsfocuspanel.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsfocuspanel.cpp @@ -48,7 +48,7 @@ QT_BEGIN_NAMESPACE QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,FocusPanel,QmlGraphicsFocusPanel) /*! - \qmlclass FocusPanel QFxFocusPanel + \qmlclass FocusPanel QmlGraphicsFocusPanel \brief The FocusPanel item explicitly creates a focus panel. \inherits Item diff --git a/src/declarative/graphicsitems/qmlgraphicsfocusscope.cpp b/src/declarative/graphicsitems/qmlgraphicsfocusscope.cpp index cd30b2b..f03e3f1 100644 --- a/src/declarative/graphicsitems/qmlgraphicsfocusscope.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsfocusscope.cpp @@ -46,7 +46,7 @@ QT_BEGIN_NAMESPACE QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,FocusScope,QmlGraphicsFocusScope) /*! - \qmlclass FocusScope QFxFocusScope + \qmlclass FocusScope QmlGraphicsFocusScope \brief The FocusScope object explicitly creates a focus scope. \inherits Item diff --git a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp index cadd650..1ee4511 100644 --- a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp @@ -658,7 +658,7 @@ void QmlGraphicsGridViewPrivate::updateCurrent(int modelIndex) //---------------------------------------------------------------------------- /*! - \qmlclass GridView QFxGridView + \qmlclass GridView QmlGraphicsGridView \inherits Flickable \brief The GridView item provides a grid view of items provided by a model. diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp index cf399f9..a393cb1 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp @@ -954,7 +954,7 @@ void QmlGraphicsListViewPrivate::flickY(qreal velocity) //---------------------------------------------------------------------------- /*! - \qmlclass ListView QFxListView + \qmlclass ListView QmlGraphicsListView \inherits Flickable \brief The ListView item provides a list view of items provided by a model. diff --git a/src/declarative/graphicsitems/qmlgraphicsloader.cpp b/src/declarative/graphicsitems/qmlgraphicsloader.cpp index 65753d8..4d463ab 100644 --- a/src/declarative/graphicsitems/qmlgraphicsloader.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsloader.cpp @@ -56,7 +56,7 @@ QmlGraphicsLoaderPrivate::~QmlGraphicsLoaderPrivate() QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Loader,QmlGraphicsLoader) /*! - \qmlclass Loader QFxLoader + \qmlclass Loader QmlGraphicsLoader \inherits Item \brief The Loader item allows dynamically loading an Item-based diff --git a/src/declarative/graphicsitems/qmlgraphicsmouseregion.cpp b/src/declarative/graphicsitems/qmlgraphicsmouseregion.cpp index 75e31b8..1a57062 100644 --- a/src/declarative/graphicsitems/qmlgraphicsmouseregion.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsmouseregion.cpp @@ -120,7 +120,7 @@ void QmlGraphicsDrag::setYmax(qreal m) } /*! - \qmlclass MouseRegion QFxMouseRegion + \qmlclass MouseRegion QmlGraphicsMouseRegion \brief The MouseRegion item enables simple mouse handling. \inherits Item diff --git a/src/declarative/graphicsitems/qmlgraphicspath.cpp b/src/declarative/graphicsitems/qmlgraphicspath.cpp index c0e6caf..ed0dfaa 100644 --- a/src/declarative/graphicsitems/qmlgraphicspath.cpp +++ b/src/declarative/graphicsitems/qmlgraphicspath.cpp @@ -57,7 +57,7 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathQuad,QmlGraphicsPathQuad) QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathCubic,QmlGraphicsPathCubic) /*! - \qmlclass PathElement QFxPathElement + \qmlclass PathElement QmlGraphicsPathElement \brief PathElement is the base path type. This type is the base for all path types. It cannot @@ -464,7 +464,7 @@ void QmlGraphicsCurve::setY(qreal y) /****************************************************************************/ /*! - \qmlclass PathAttribute QFxPathAttribute + \qmlclass PathAttribute QmlGraphicsPathAttribute \brief The PathAttribute allows setting an attribute at a given position in a Path. The PathAttribute object allows attibutes consisting of a name and @@ -543,7 +543,7 @@ void QmlGraphicsPathAttribute::setValue(qreal value) /****************************************************************************/ /*! - \qmlclass PathLine QFxPathLine + \qmlclass PathLine QmlGraphicsPathLine \brief The PathLine defines a straight line. The example below creates a path consisting of a straight line from @@ -583,7 +583,7 @@ void QmlGraphicsPathLine::addToPath(QPainterPath &path) /****************************************************************************/ /*! - \qmlclass PathQuad QFxPathQuad + \qmlclass PathQuad QmlGraphicsPathQuad \brief The PathQuad defines a quadratic Bezier curve with a control point. The following QML produces the path shown below: @@ -667,7 +667,7 @@ void QmlGraphicsPathQuad::addToPath(QPainterPath &path) /****************************************************************************/ /*! - \qmlclass PathCubic QFxPathCubic + \qmlclass PathCubic QmlGraphicsPathCubic \brief The PathCubic defines a cubic Bezier curve with two control points. The following QML produces the path shown below: @@ -777,7 +777,7 @@ void QmlGraphicsPathCubic::addToPath(QPainterPath &path) /****************************************************************************/ /*! - \qmlclass PathPercent QFxPathPercent + \qmlclass PathPercent QmlGraphicsPathPercent \brief The PathPercent manipulates the way a path is interpreted. The examples below show the normal distrubution of items along a path diff --git a/src/declarative/graphicsitems/qmlgraphicspathview.cpp b/src/declarative/graphicsitems/qmlgraphicspathview.cpp index 52d2fa9..d2a9be1 100644 --- a/src/declarative/graphicsitems/qmlgraphicspathview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicspathview.cpp @@ -97,7 +97,7 @@ private: */ /*! - \qmlclass PathView QFxPathView + \qmlclass PathView QmlGraphicsPathView \brief The PathView element lays out model-provided items on a path. \inherits Item diff --git a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp index 35b0833..f599025 100644 --- a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp +++ b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp @@ -333,7 +333,7 @@ void QmlGraphicsBasePositioner::applyRemove(const QList QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Column,QmlGraphicsColumn) /*! - \qmlclass Column QFxColumn + \qmlclass Column QmlGraphicsColumn \brief The Column item lines up its children vertically. \inherits Item @@ -524,7 +524,7 @@ void QmlGraphicsColumn::doPositioning() QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Row,QmlGraphicsRow) /*! - \qmlclass Row QFxRow + \qmlclass Row QmlGraphicsRow \brief The Row item lines up its children horizontally. \inherits Item diff --git a/src/declarative/graphicsitems/qmlgraphicsrepeater.cpp b/src/declarative/graphicsitems/qmlgraphicsrepeater.cpp index ba860e9..646374f 100644 --- a/src/declarative/graphicsitems/qmlgraphicsrepeater.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsrepeater.cpp @@ -59,7 +59,7 @@ QmlGraphicsRepeaterPrivate::~QmlGraphicsRepeaterPrivate() QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Repeater,QmlGraphicsRepeater) /*! - \qmlclass Repeater QFxRepeater + \qmlclass Repeater QmlGraphicsRepeater \inherits Item \brief The Repeater item allows you to repeat a component based on a model. diff --git a/src/declarative/graphicsitems/qmlgraphicstextedit.cpp b/src/declarative/graphicsitems/qmlgraphicstextedit.cpp index 0c81dca..13df329 100644 --- a/src/declarative/graphicsitems/qmlgraphicstextedit.cpp +++ b/src/declarative/graphicsitems/qmlgraphicstextedit.cpp @@ -56,7 +56,7 @@ QT_BEGIN_NAMESPACE QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,TextEdit,QmlGraphicsTextEdit) /*! - \qmlclass TextEdit QFxTextEdit + \qmlclass TextEdit QmlGraphicsTextEdit \brief The TextEdit item allows you to add editable formatted text to a scene. It can display both plain and rich text. For example: diff --git a/src/declarative/graphicsitems/qmlgraphicstextinput.cpp b/src/declarative/graphicsitems/qmlgraphicstextinput.cpp index 44ccda1..9a4f627 100644 --- a/src/declarative/graphicsitems/qmlgraphicstextinput.cpp +++ b/src/declarative/graphicsitems/qmlgraphicstextinput.cpp @@ -54,7 +54,7 @@ QML_DEFINE_NOCREATE_TYPE(QValidator); QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,QIntValidator,QIntValidator); /*! - \qmlclass TextInput QFxTextInput + \qmlclass TextInput QmlGraphicsTextInput The TextInput item allows you to add an editable line of text to a scene. TextInput can only display a single line of text, and can only display diff --git a/src/declarative/graphicsitems/qmlgraphicswebview.cpp b/src/declarative/graphicsitems/qmlgraphicswebview.cpp index c6ab4c7..d1da0f2 100644 --- a/src/declarative/graphicsitems/qmlgraphicswebview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicswebview.cpp @@ -208,7 +208,7 @@ public: }; /*! - \qmlclass WebView QFxWebView + \qmlclass WebView QmlGraphicsWebView \brief The WebView item allows you to add web content to a canvas. \inherits Item diff --git a/src/declarative/util/qmlstategroup.cpp b/src/declarative/util/qmlstategroup.cpp index f518ea5..2eb9dca 100644 --- a/src/declarative/util/qmlstategroup.cpp +++ b/src/declarative/util/qmlstategroup.cpp @@ -84,6 +84,34 @@ public: void updateAutoState(); }; +/*! + \qmlclass StateGroup QmlStateGroup + \brief The StateGroup element provides state support for non-Item elements. + + Item (and all dervied elements) provides built in support for states and transitions + via its state, states and transitions properties. StateGroup provides an easy way to + use this support in other (non-Item-derived) elements. + + \qml + MyCustomObject { + StateGroup { + id: myStateGroup + states: State { + name: "state1" + ... + } + transitions: Transition { + ... + } + } + + onSomethingHappened: myStateGroup.state = "state1"; + } + \endqml + + \sa {qmlstate}{States} and {state-transitions}{Transitions} +*/ + QmlStateGroup::QmlStateGroup(QObject *parent) : QObject(*(new QmlStateGroupPrivate(this)), parent) { @@ -99,18 +127,75 @@ QList QmlStateGroup::states() const return d->states; } +/*! + \qmlproperty list StateGroup::states + This property holds a list of states defined by the state group. + + \qml + StateGroup { + states: [ + State { ... }, + State { ... } + ... + ] + } + \endqml + + \sa {qmlstate}{States} +*/ QmlList* QmlStateGroup::statesProperty() { Q_D(QmlStateGroup); return &(d->states); } +/*! + \qmlproperty list StateGroup::transitions + This property holds a list of transitions defined by the state group. + + \qml + StateGroup { + transitions: [ + Transition { ... }, + Transition { ... } + ... + ] + } + \endqml + + \sa {state-transitions}{Transitions} +*/ QmlList* QmlStateGroup::transitionsProperty() { Q_D(QmlStateGroup); return &(d->transitions); } +/*! + \qmlproperty string StateGroup::state + + This property holds the name of the current state of the state group. + + This property is often used in scripts to change between states. For + example: + + \qml + Script { + function toggle() { + if (button.state == 'On') + button.state = 'Off'; + else + button.state = 'On'; + } + } + \endqml + + If the state group is in its base state (i.e. no explicit state has been + set), \c state will be a blank string. Likewise, you can return a + state group to its base state by setting its current state to \c ''. + + \sa {qmlstates}{States} +*/ QString QmlStateGroup::state() const { Q_D(const QmlStateGroup); -- cgit v0.12 From 9063457d08b2bcc8c055f6f0370f73360e6ec1dc Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Tue, 3 Nov 2009 11:54:57 +1000 Subject: * add more font examples * add missing properties to QmlFontValueType --- examples/declarative/fonts/banner.qml | 18 +++++++++++ examples/declarative/fonts/fonts.qml | 56 +++++++++++++++++--------------- examples/declarative/fonts/hello.qml | 27 ++++++++++++++++ src/declarative/qml/qmlvaluetype.cpp | 60 +++++++++++++++++++++++++++++++++++ src/declarative/qml/qmlvaluetype_p.h | 39 +++++++++++++++++++++++ 5 files changed, 174 insertions(+), 26 deletions(-) create mode 100644 examples/declarative/fonts/banner.qml create mode 100644 examples/declarative/fonts/hello.qml diff --git a/examples/declarative/fonts/banner.qml b/examples/declarative/fonts/banner.qml new file mode 100644 index 0000000..ece481b --- /dev/null +++ b/examples/declarative/fonts/banner.qml @@ -0,0 +1,18 @@ +import Qt 4.6 + +Rectangle { + id: screen + width: 640; height: 320; color: "steelblue" + + property int pixelSize: screen.height * 1.25 + property color textColor: "lightsteelblue" + property string text: "Hello world! " + + Row { + y: -screen.height / 4.5 + x: NumberAnimation { from: 0; to: -text.width; duration: 6000; running: true; repeat: true } + Text { id: text; font.pixelSize: screen.pixelSize; color: screen.textColor; text: screen.text } + Text { font.pixelSize: screen.pixelSize; color: screen.textColor; text: screen.text } + Text { font.pixelSize: screen.pixelSize; color: screen.textColor; text: screen.text } + } +} diff --git a/examples/declarative/fonts/fonts.qml b/examples/declarative/fonts/fonts.qml index e68bdb6..80d82ad 100644 --- a/examples/declarative/fonts/fonts.qml +++ b/examples/declarative/fonts/fonts.qml @@ -1,12 +1,10 @@ import Qt 4.6 Rectangle { - property string myText: "Lorem ipsum dolor sit amet, consectetur adipisicing elit" + property string myText: "The quick brown fox jumps over the lazy dog." - width: 800; height: 600 - color: palette.base - - SystemPalette { id: palette; colorGroup: Qt.Active } + width: 800; height: 480 + color: "steelblue" FontLoader { id: fixedFont; name: "Courier" } @@ -17,28 +15,36 @@ Rectangle { FontLoader { id: webFont2; source: "http://wrong.address.org" } Column { - anchors.fill: parent + anchors.fill: parent; spacing: 10 anchors.leftMargin: 10; anchors.rightMargin: 10 Text { - text: myText - color: palette.windowText + text: myText; color: "lightsteelblue" width: parent.width; elide: Text.ElideRight - font.family: "Times" - font.pointSize: 32 + font.family: "Times"; font.pointSize: 36 } Text { - text: myText - color: palette.windowText - width: parent.width; elide: Text.ElideRight - font.family: fixedFont.name - font.pointSize: 32 + text: myText; color: "lightsteelblue" + width: parent.width; elide: Text.ElideLeft + font.family: "Times"; font.pointSize: 36 + font.capitalization: "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" } Text { - text: myText - color: palette.windowText + text: myText; color: "lightsteelblue" width: parent.width; elide: Text.ElideRight - font.family: localFont.name - font.pointSize: 32 + font.family: fixedFont.name; font.pointSize: 36; font.italic: true + font.capitalization: "SmallCaps" + } + Text { + text: myText; color: "lightsteelblue" + width: parent.width; elide: Text.ElideLeft + font.family: localFont.name; font.pointSize: 36 + font.capitalization: "Capitalize" } Text { text: { @@ -46,10 +52,9 @@ Rectangle { else if (webFont.status == 2) "Loading..." else if (webFont.status == 3) "Error loading font" } - color: palette.windowText - width: parent.width; elide: Text.ElideRight - font.family: webFont.name - font.pointSize: 32 + color: "lightsteelblue" + width: parent.width; elide: Text.ElideMiddle + font.family: webFont.name; font.pointSize: 36 } Text { text: { @@ -57,10 +62,9 @@ Rectangle { else if (webFont2.status == 2) "Loading..." else if (webFont2.status == 3) "Error loading font" } - color: palette.windowText + color: "lightsteelblue" width: parent.width; elide: Text.ElideRight - font.family: webFont2.name - font.pointSize: 32 + font.family: webFont2.name; font.pointSize: 36 } } } diff --git a/examples/declarative/fonts/hello.qml b/examples/declarative/fonts/hello.qml new file mode 100644 index 0000000..6aef3e6 --- /dev/null +++ b/examples/declarative/fonts/hello.qml @@ -0,0 +1,27 @@ +import Qt 4.6 + +Rectangle { + id: screen; width: 800; height: 480; color: "black" + + Item { + id: container; x: screen.width / 2; y: screen.height / 2 + Text { + id: text; color: "white"; anchors.centerIn: parent + text: "Hello world!"; font.pixelSize: 60 + + font.letterSpacing: SequentialAnimation { + repeat: true; running: true + NumberAnimation { from: 100; to: 300; easing: "easeInQuad"; duration: 3000 } + ScriptAction { script: { + container.y = (screen.height / 4) + (Math.random() * screen.height / 2) + container.x = (screen.width / 4) + (Math.random() * screen.width / 2) + } } + } + opacity: SequentialAnimation { + repeat: true; running: true + NumberAnimation { from: 1; to: 0; duration: 2600 } + PauseAnimation { duration: 400 } + } + } + } +} diff --git a/src/declarative/qml/qmlvaluetype.cpp b/src/declarative/qml/qmlvaluetype.cpp index 1713205..859a93a 100644 --- a/src/declarative/qml/qmlvaluetype.cpp +++ b/src/declarative/qml/qmlvaluetype.cpp @@ -521,6 +521,16 @@ void QmlFontValueType::setBold(bool b) font.setBold(b); } +QmlFontValueType::FontWeight QmlFontValueType::weight() const +{ + return (QmlFontValueType::FontWeight)font.weight(); +} + +void QmlFontValueType::setWeight(QmlFontValueType::FontWeight w) +{ + font.setWeight((QFont::Weight)w); +} + bool QmlFontValueType::italic() const { return font.italic(); @@ -541,6 +551,26 @@ void QmlFontValueType::setUnderline(bool b) font.setUnderline(b); } +bool QmlFontValueType::overline() const +{ + return font.overline(); +} + +void QmlFontValueType::setOverline(bool b) +{ + font.setOverline(b); +} + +bool QmlFontValueType::strikeout() const +{ + return font.strikeOut(); +} + +void QmlFontValueType::setStrikeout(bool b) +{ + font.setStrikeOut(b); +} + qreal QmlFontValueType::pointSize() const { return font.pointSizeF(); @@ -566,4 +596,34 @@ void QmlFontValueType::setPixelSize(int size) hasPixelSize = true; } +QmlFontValueType::Capitalization QmlFontValueType::capitalization() const +{ + return (QmlFontValueType::Capitalization)font.capitalization(); +} + +void QmlFontValueType::setCapitalization(QmlFontValueType::Capitalization c) +{ + font.setCapitalization((QFont::Capitalization)c); +} + +qreal QmlFontValueType::letterSpacing() const +{ + return font.letterSpacing(); +} + +void QmlFontValueType::setLetterSpacing(qreal size) +{ + font.setLetterSpacing(QFont::PercentageSpacing, size); +} + +qreal QmlFontValueType::wordSpacing() const +{ + return font.wordSpacing(); +} + +void QmlFontValueType::setWordSpacing(qreal size) +{ + font.setWordSpacing(size); +} + QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlvaluetype_p.h b/src/declarative/qml/qmlvaluetype_p.h index 9842c02..0af3813 100644 --- a/src/declarative/qml/qmlvaluetype_p.h +++ b/src/declarative/qml/qmlvaluetype_p.h @@ -258,13 +258,34 @@ private: class QmlFontValueType : public QmlValueType { Q_OBJECT + Q_ENUMS(FontWeight) + Q_ENUMS(Capitalization) + Q_PROPERTY(QString family READ family WRITE setFamily) Q_PROPERTY(bool bold READ bold WRITE setBold) + Q_PROPERTY(FontWeight weight READ weight WRITE setWeight) Q_PROPERTY(bool italic READ italic WRITE setItalic) Q_PROPERTY(bool underline READ underline WRITE setUnderline) + Q_PROPERTY(bool overline READ overline WRITE setOverline) + Q_PROPERTY(bool strikeout READ strikeout WRITE setStrikeout) Q_PROPERTY(qreal pointSize READ pointSize WRITE setPointSize) Q_PROPERTY(int pixelSize READ pixelSize WRITE setPixelSize) + Q_PROPERTY(Capitalization capitalization READ capitalization WRITE setCapitalization) + Q_PROPERTY(qreal letterSpacing READ letterSpacing WRITE setLetterSpacing) + Q_PROPERTY(qreal wordSpacing READ wordSpacing WRITE setWordSpacing) + public: + enum FontWeight { Light = QFont::Light, + Normal = QFont::Normal, + DemiBold = QFont::DemiBold, + Bold = QFont::Bold, + Black = QFont::Black }; + enum Capitalization { MixedCase = QFont::MixedCase, + AllUppercase = QFont::AllUppercase, + AllLowercase = QFont::AllLowercase, + SmallCaps = QFont::SmallCaps, + Capitalize = QFont::Capitalize }; + QmlFontValueType(QObject *parent = 0); virtual void read(QObject *, int); @@ -278,18 +299,36 @@ public: bool bold() const; void setBold(bool b); + FontWeight weight() const; + void setWeight(FontWeight); + bool italic() const; void setItalic(bool b); bool underline() const; void setUnderline(bool b); + bool overline() const; + void setOverline(bool b); + + bool strikeout() const; + void setStrikeout(bool b); + qreal pointSize() const; void setPointSize(qreal size); int pixelSize() const; void setPixelSize(int size); + Capitalization capitalization() const; + void setCapitalization(Capitalization); + + qreal letterSpacing() const; + void setLetterSpacing(qreal spacing); + + qreal wordSpacing() const; + void setWordSpacing(qreal spacing); + private: QFont font; bool hasPixelSize; -- cgit v0.12 From 5f19daab6baba7d09853058355a66090a3781430 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 3 Nov 2009 13:04:03 +1000 Subject: Support Visual (interactive) tests without using images for confirmation. --- .../selftest_noimages/data/selftest_noimages.qml | 470 +++++++++++++++++++++ .../visual/selftest_noimages/selftest_noimages.qml | 9 + tests/auto/declarative/visual/tst_visual.cpp | 64 +-- tools/qmlviewer/main.cpp | 5 +- tools/qmlviewer/qfxtester.cpp | 21 +- tools/qmlviewer/qmlviewer.h | 7 +- 6 files changed, 541 insertions(+), 35 deletions(-) create mode 100644 tests/auto/declarative/visual/selftest_noimages/data/selftest_noimages.qml create mode 100644 tests/auto/declarative/visual/selftest_noimages/selftest_noimages.qml diff --git a/tests/auto/declarative/visual/selftest_noimages/data/selftest_noimages.qml b/tests/auto/declarative/visual/selftest_noimages/data/selftest_noimages.qml new file mode 100644 index 0000000..3104906 --- /dev/null +++ b/tests/auto/declarative/visual/selftest_noimages/data/selftest_noimages.qml @@ -0,0 +1,470 @@ +import Qt.VisualTest 4.6 + +VisualTest { + Frame { + msec: 0 + } + Frame { + msec: 16 + } + Frame { + msec: 32 + } + Frame { + msec: 48 + } + Frame { + msec: 64 + } + Frame { + msec: 80 + } + Frame { + msec: 96 + } + Frame { + msec: 112 + } + Frame { + msec: 128 + } + Frame { + msec: 144 + } + Frame { + msec: 160 + } + Frame { + msec: 176 + } + Frame { + msec: 192 + } + Frame { + msec: 208 + } + Frame { + msec: 224 + } + Frame { + msec: 240 + } + Frame { + msec: 256 + } + Frame { + msec: 272 + } + Frame { + msec: 288 + } + Frame { + msec: 304 + } + Frame { + msec: 320 + } + Frame { + msec: 336 + } + Frame { + msec: 352 + } + Frame { + msec: 368 + } + Frame { + msec: 384 + } + Frame { + msec: 400 + } + Frame { + msec: 416 + } + Frame { + msec: 432 + } + Frame { + msec: 448 + } + Frame { + msec: 464 + } + Frame { + msec: 480 + } + Frame { + msec: 496 + } + Frame { + msec: 512 + } + Frame { + msec: 528 + } + Frame { + msec: 544 + } + Frame { + msec: 560 + } + Frame { + msec: 576 + } + Frame { + msec: 592 + } + Frame { + msec: 608 + } + Frame { + msec: 624 + } + Frame { + msec: 640 + } + Frame { + msec: 656 + } + Frame { + msec: 672 + } + Frame { + msec: 688 + } + Frame { + msec: 704 + } + Frame { + msec: 720 + } + Frame { + msec: 736 + } + Frame { + msec: 752 + } + Frame { + msec: 768 + } + Frame { + msec: 784 + } + Frame { + msec: 800 + } + Frame { + msec: 816 + } + Frame { + msec: 832 + } + Frame { + msec: 848 + } + Frame { + msec: 864 + } + Frame { + msec: 880 + } + Frame { + msec: 896 + } + Frame { + msec: 912 + } + Frame { + msec: 928 + } + Frame { + msec: 944 + } + Frame { + msec: 960 + } + Frame { + msec: 976 + } + Frame { + msec: 992 + } + Frame { + msec: 1008 + } + Frame { + msec: 1024 + } + Frame { + msec: 1040 + } + Frame { + msec: 1056 + } + Frame { + msec: 1072 + } + Frame { + msec: 1088 + } + Frame { + msec: 1104 + } + Frame { + msec: 1120 + } + Frame { + msec: 1136 + } + Frame { + msec: 1152 + } + Frame { + msec: 1168 + } + Frame { + msec: 1184 + } + Frame { + msec: 1200 + } + Frame { + msec: 1216 + } + Frame { + msec: 1232 + } + Frame { + msec: 1248 + } + Frame { + msec: 1264 + } + Frame { + msec: 1280 + } + Frame { + msec: 1296 + } + Frame { + msec: 1312 + } + Frame { + msec: 1328 + } + Frame { + msec: 1344 + } + Frame { + msec: 1360 + } + Mouse { + type: 2 + button: 1 + buttons: 1 + x: 77; y: 7 + modifiers: 0 + sendToViewport: true + } + Frame { + msec: 1376 + } + Frame { + msec: 1392 + } + Frame { + msec: 1408 + } + Frame { + msec: 1424 + } + Frame { + msec: 1440 + } + Mouse { + type: 3 + button: 1 + buttons: 0 + x: 77; y: 7 + modifiers: 0 + sendToViewport: true + } + Frame { + msec: 1456 + } + Frame { + msec: 1472 + } + Frame { + msec: 1488 + } + Frame { + msec: 1504 + } + Frame { + msec: 1520 + } + Frame { + msec: 1536 + } + Frame { + msec: 1552 + } + Frame { + msec: 1568 + } + Frame { + msec: 1584 + } + Frame { + msec: 1600 + } + Frame { + msec: 1616 + } + Frame { + msec: 1632 + } + Frame { + msec: 1648 + } + Frame { + msec: 1664 + } + Frame { + msec: 1680 + } + Frame { + msec: 1696 + } + Frame { + msec: 1712 + } + Frame { + msec: 1728 + } + Frame { + msec: 1744 + } + Frame { + msec: 1760 + } + Frame { + msec: 1776 + } + Frame { + msec: 1792 + } + Frame { + msec: 1808 + } + Frame { + msec: 1824 + } + Frame { + msec: 1840 + } + Frame { + msec: 1856 + } + Frame { + msec: 1872 + } + Frame { + msec: 1888 + } + Frame { + msec: 1904 + } + Frame { + msec: 1920 + } + Frame { + msec: 1936 + } + Frame { + msec: 1952 + } + Frame { + msec: 1968 + } + Frame { + msec: 1984 + } + Frame { + msec: 2000 + } + Frame { + msec: 2016 + } + Frame { + msec: 2032 + } + Frame { + msec: 2048 + } + Frame { + msec: 2064 + } + Frame { + msec: 2080 + } + Frame { + msec: 2096 + } + Frame { + msec: 2112 + } + Frame { + msec: 2128 + } + Frame { + msec: 2144 + } + Frame { + msec: 2160 + } + Frame { + msec: 2176 + } + Frame { + msec: 2192 + } + Frame { + msec: 2208 + } + Frame { + msec: 2224 + } + Frame { + msec: 2240 + } + Frame { + msec: 2256 + } + Frame { + msec: 2272 + } + Frame { + msec: 2288 + } + Frame { + msec: 2304 + } + Frame { + msec: 2320 + } + Frame { + msec: 2336 + } + Frame { + msec: 2352 + } + Frame { + msec: 2368 + } + Frame { + msec: 2384 + } +} diff --git a/tests/auto/declarative/visual/selftest_noimages/selftest_noimages.qml b/tests/auto/declarative/visual/selftest_noimages/selftest_noimages.qml new file mode 100644 index 0000000..21a19bc --- /dev/null +++ b/tests/auto/declarative/visual/selftest_noimages/selftest_noimages.qml @@ -0,0 +1,9 @@ +import Qt 4.6 +Text { + property string error: "not pressed" + text: (new Date()).valueOf() + MouseRegion { + anchors.fill: parent + onPressed: error="" + } +} diff --git a/tests/auto/declarative/visual/tst_visual.cpp b/tests/auto/declarative/visual/tst_visual.cpp index a79b6f9..0cd712b 100644 --- a/tests/auto/declarative/visual/tst_visual.cpp +++ b/tests/auto/declarative/visual/tst_visual.cpp @@ -47,7 +47,7 @@ #include #include -enum Mode { Record, Play, TestVisuals, UpdateVisuals, UpdatePlatformVisuals, Test }; +enum Mode { Record, RecordNoVisuals, Play, TestVisuals, RemoveVisuals, UpdateVisuals, UpdatePlatformVisuals, Test }; static QString testdir; class tst_visual : public QObject @@ -115,7 +115,7 @@ void tst_visual::visual() QStringList arguments; arguments << "-script" << testdata - << "-scriptopts" << "play,testimages,exitoncomplete,exitonfailure" + << "-scriptopts" << "play,testimages,testerror,exitoncomplete,exitonfailure" << file; QProcess p; p.start(qmlviewer, arguments); @@ -208,38 +208,44 @@ void action(Mode mode, const QString &file) QString testdata = tst_visual::toTestScript(file,mode); - if (Record == mode) { - QStringList arguments; - arguments << "-script" << testdata + QStringList arguments; + switch (mode) { + case Test: + // Don't run qmlviewer + break; + case Record: + arguments << "-script" << testdata + << "-scriptopts" << "record,testimages,saveonexit" + << file; + break; + case RecordNoVisuals: + arguments << "-script" << testdata << "-scriptopts" << "record,saveonexit" << file; - QProcess p; - p.setProcessChannelMode(QProcess::ForwardedChannels); - p.start(tst_visual::viewer(), arguments); - p.waitForFinished(); - } else if (Play == mode) { - QStringList arguments; - arguments << "-script" << testdata - << "-scriptopts" << "play,testimages,exitoncomplete" + break; + case Play: + arguments << "-script" << testdata + << "-scriptopts" << "play,testimages,testerror,exitoncomplete" << file; - QProcess p; - p.setProcessChannelMode(QProcess::ForwardedChannels); - p.start(tst_visual::viewer(), arguments); - p.waitForFinished(); - } else if (TestVisuals == mode) { - QStringList arguments; + break; + case TestVisuals: arguments << "-script" << testdata << "-scriptopts" << "play" << file; - QProcess p; - p.setProcessChannelMode(QProcess::ForwardedChannels); - p.start(tst_visual::viewer(), arguments); - p.waitForFinished(); - } else if (UpdateVisuals == mode || UpdatePlatformVisuals == mode) { - QStringList arguments; - arguments << "-script" << testdata + break; + case UpdateVisuals: + case UpdatePlatformVisuals: + arguments << "-script" << testdata + << "-scriptopts" << "play,record,testimages,exitoncomplete,saveonexit" + << file; + break; + case RemoveVisuals: + arguments << "-script" << testdata << "-scriptopts" << "play,record,exitoncomplete,saveonexit" << file; + break; + } + if (!arguments.isEmpty()) { QProcess p; p.setProcessChannelMode(QProcess::ForwardedChannels); p.start(tst_visual::viewer(), arguments); @@ -278,9 +284,15 @@ int main(int argc, char **argv) } else if (arg == "-record" && (ii + 1) < argc) { mode = Record; file = argv[++ii]; + } else if (arg == "-recordnovisuals" && (ii + 1) < argc) { + mode = RecordNoVisuals; + file = argv[++ii]; } else if (arg == "-testvisuals" && (ii + 1) < argc) { mode = TestVisuals; file = argv[++ii]; + } else if (arg == "-removevisuals" && (ii + 1) < argc) { + mode = RemoveVisuals; + file = argv[++ii]; } else if (arg == "-updatevisuals" && (ii + 1) < argc) { mode = UpdateVisuals; file = argv[++ii]; diff --git a/tools/qmlviewer/main.cpp b/tools/qmlviewer/main.cpp index 23194b2..ac0d732 100644 --- a/tools/qmlviewer/main.cpp +++ b/tools/qmlviewer/main.cpp @@ -87,7 +87,8 @@ void scriptOptsUsage() qWarning(" options:"); qWarning(" record ................................... record a new script"); qWarning(" play ..................................... playback an existing script"); - qWarning(" testimages ............................... compare images on playback"); + qWarning(" testimages ............................... record images or compare images on playback"); + qWarning(" testerror ................................ test 'error' property of root item on playback"); qWarning(" exitoncomplete ........................... cleanly exit the viewer on script completion"); qWarning(" exitonfailure ............................ immediately exit the viewer on script failure"); qWarning(" saveonexit ............................... save recording on viewer exit"); @@ -235,6 +236,8 @@ int main(int argc, char ** argv) scriptOptions |= QmlViewer::Record; } else if (option == QLatin1String("testimages")) { scriptOptions |= QmlViewer::TestImages; + } else if (option == QLatin1String("testerror")) { + scriptOptions |= QmlViewer::TestErrorProperty; } else if (option == QLatin1String("exitoncomplete")) { scriptOptions |= QmlViewer::ExitOnComplete; } else if (option == QLatin1String("exitonfailure")) { diff --git a/tools/qmlviewer/qfxtester.cpp b/tools/qmlviewer/qfxtester.cpp index 77e8124..287771b 100644 --- a/tools/qmlviewer/qfxtester.cpp +++ b/tools/qmlviewer/qfxtester.cpp @@ -146,6 +146,13 @@ void QmlGraphicsTester::imagefailure() void QmlGraphicsTester::complete() { + if ((options & QmlViewer::TestErrorProperty) && !hasFailed) { + QString e = m_view->root()->property("error").toString(); + if (!e.isEmpty()) { + qWarning() << "Test failed:" << e; + hasFailed = true; + } + } if (options & QmlViewer::ExitOnComplete) QApplication::exit(hasFailed?-1:0); @@ -240,13 +247,15 @@ void QmlGraphicsTester::updateCurrentTime(int msec) QImage img(m_view->width(), m_view->height(), QImage::Format_RGB32); - QPainter p(&img); - m_view->render(&p); + if (options & QmlViewer::TestImages) { + QPainter p(&img); + m_view->render(&p); + } FrameEvent fe; fe.msec = msec; - if (msec == 0) { - // Skip first frame + if (msec == 0 || !(options & QmlViewer::TestImages)) { + // Skip first frame, skip if not doing images } else if (0 == (m_savedFrameEvents.count() % 60)) { fe.image = img; } else { @@ -297,6 +306,8 @@ void QmlGraphicsTester::updateCurrentTime(int msec) QObject *event = testscript->event(testscriptidx); if (QmlGraphicsVisualTestFrame *frame = qobject_cast(event)) { + if ((options & QmlViewer::TestImages) && (options & QmlViewer::Record)) + break; // recording and playing, no point "testing" results if (frame->msec() < msec) { if (options & QmlViewer::TestImages) { qWarning() << "QmlGraphicsTester: Extra frame. Seen:" @@ -304,7 +315,7 @@ void QmlGraphicsTester::updateCurrentTime(int msec) imagefailure(); } } else if (frame->msec() == msec) { - if (frame->hash().toUtf8() != fe.hash.toHex()) { + if (!frame->hash().isEmpty() && frame->hash().toUtf8() != fe.hash.toHex()) { if (options & QmlViewer::TestImages) { qWarning() << "QmlGraphicsTester: Mismatched frame hash. Seen:" << fe.hash.toHex() << "Expected:" diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h index a63b938..b366401 100644 --- a/tools/qmlviewer/qmlviewer.h +++ b/tools/qmlviewer/qmlviewer.h @@ -66,9 +66,10 @@ public: Play = 0x00000001, Record = 0x00000002, TestImages = 0x00000004, - SaveOnExit = 0x00000008, - ExitOnComplete = 0x00000010, - ExitOnFailure = 0x00000020 + TestErrorProperty = 0x00000008, + SaveOnExit = 0x00000010, + ExitOnComplete = 0x00000020, + ExitOnFailure = 0x00000040 }; Q_DECLARE_FLAGS(ScriptOptions, ScriptOption) void setScript(const QString &s) { m_script = s; } -- cgit v0.12 From 43c15688888b433d6d3c01c0d68168fec81cf06a Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 3 Nov 2009 14:02:37 +1000 Subject: Add QMetaObjectBuilder test --- tests/auto/declarative/declarative.pro | 1 + .../qmetaobjectbuilder/qmetaobjectbuilder.pro | 7 + .../qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp | 1059 ++++++++++++++++++++ 3 files changed, 1067 insertions(+) create mode 100644 tests/auto/declarative/qmetaobjectbuilder/qmetaobjectbuilder.pro create mode 100644 tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 40cdb58..0d55391 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -15,6 +15,7 @@ SUBDIRS += anchors \ qfxtextedit \ qfxtextinput \ qfxwebview \ + qmetaobjectbuilder \ qmlcontext \ qmldom \ qmlecmascript \ diff --git a/tests/auto/declarative/qmetaobjectbuilder/qmetaobjectbuilder.pro b/tests/auto/declarative/qmetaobjectbuilder/qmetaobjectbuilder.pro new file mode 100644 index 0000000..94ffe4b --- /dev/null +++ b/tests/auto/declarative/qmetaobjectbuilder/qmetaobjectbuilder.pro @@ -0,0 +1,7 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +macx:CONFIG -= app_bundle + +SOURCES += \ + tst_qmetaobjectbuilder.cpp + diff --git a/tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp b/tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp new file mode 100644 index 0000000..0dac963 --- /dev/null +++ b/tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp @@ -0,0 +1,1059 @@ +/**************************************************************************** +** +** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +class tst_QMetaObjectBuilder : public QObject +{ + Q_OBJECT +public: + tst_QMetaObjectBuilder() {} + ~tst_QMetaObjectBuilder() {} + +private slots: + void mocVersionCheck(); + void create(); + void className(); + void superClass(); + void method(); + void slot(); + void signal(); + void constructor(); + void property(); + void notifySignal(); + void enumerator(); + void classInfo(); + void relatedMetaObject(); + void staticMetacall(); + void copyMetaObject(); + void serialize(); + +private: + static bool checkForSideEffects + (const QMetaObjectBuilder& builder, + QMetaObjectBuilder::AddMembers members); + static bool sameMetaObject + (const QMetaObject *meta1, const QMetaObject *meta2); +}; + +void tst_QMetaObjectBuilder::mocVersionCheck() +{ + // This test will fail when the moc version number is changed. + // It is intended as a reminder to also update QMetaObjectBuilder + // whenenver moc changes. Once QMetaObjectBuilder has been + // updated, this test can be changed to check for the next version. + QCOMPARE(int(QObject::staticMetaObject.d.data[0]), 2); + QCOMPARE(int(staticMetaObject.d.data[0]), 2); +} + +void tst_QMetaObjectBuilder::create() +{ + QMetaObjectBuilder builder; + QVERIFY(builder.className().isEmpty()); + QVERIFY(builder.superClass() == &QObject::staticMetaObject); + QCOMPARE(builder.methodCount(), 0); + QCOMPARE(builder.constructorCount(), 0); + QCOMPARE(builder.propertyCount(), 0); + QCOMPARE(builder.enumeratorCount(), 0); + QCOMPARE(builder.classInfoCount(), 0); + QCOMPARE(builder.relatedMetaObjectCount(), 0); + QVERIFY(builder.staticMetacallFunction() == 0); +} + +void tst_QMetaObjectBuilder::className() +{ + QMetaObjectBuilder builder; + + // Change the class name. + builder.setClassName("Foo"); + QCOMPARE(builder.className(), QByteArray("Foo")); + + // Change it again. + builder.setClassName("Bar"); + QCOMPARE(builder.className(), QByteArray("Bar")); + + // Clone the class name off a static QMetaObject. + builder.addMetaObject(&QObject::staticMetaObject, QMetaObjectBuilder::ClassName); + QCOMPARE(builder.className(), QByteArray("QObject")); + + // Check that nothing else changed. + QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::ClassName)); +} + +void tst_QMetaObjectBuilder::superClass() +{ + QMetaObjectBuilder builder; + + // Change the super class. + builder.setSuperClass(&QObject::staticMetaObject); + QVERIFY(builder.superClass() == &QObject::staticMetaObject); + + // Change it again. + builder.setSuperClass(&staticMetaObject); + QVERIFY(builder.superClass() == &staticMetaObject); + + // Clone the super class off a static QMetaObject. + builder.addMetaObject(&QObject::staticMetaObject, QMetaObjectBuilder::SuperClass); + QVERIFY(builder.superClass() == 0); + builder.addMetaObject(&staticMetaObject, QMetaObjectBuilder::SuperClass); + QVERIFY(builder.superClass() == staticMetaObject.superClass()); + + // Check that nothing else changed. + QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::SuperClass)); +} + +void tst_QMetaObjectBuilder::method() +{ + QMetaObjectBuilder builder; + + // Add a method and check its attributes. + QMetaMethodBuilder method1 = builder.addMethod("foo(const QString&, int)"); + QCOMPARE(method1.signature(), QByteArray("foo(QString,int)")); + QVERIFY(method1.methodType() == QMetaMethod::Method); + QVERIFY(method1.returnType().isEmpty()); + QVERIFY(method1.parameterNames().isEmpty()); + QVERIFY(method1.tag().isEmpty()); + QVERIFY(method1.access() == QMetaMethod::Public); + QCOMPARE(method1.attributes(), 0); + QCOMPARE(method1.index(), 0); + QCOMPARE(builder.methodCount(), 1); + + // Add another method and check again. + QMetaMethodBuilder method2 = builder.addMethod("bar(QString)"); + QCOMPARE(method2.signature(), QByteArray("bar(QString)")); + QVERIFY(method2.methodType() == QMetaMethod::Method); + QVERIFY(method2.returnType().isEmpty()); + QVERIFY(method2.parameterNames().isEmpty()); + QVERIFY(method2.tag().isEmpty()); + QVERIFY(method2.access() == QMetaMethod::Public); + QCOMPARE(method2.attributes(), 0); + QCOMPARE(method2.index(), 1); + QCOMPARE(builder.methodCount(), 2); + + // Perform index-based lookup. + QCOMPARE(builder.indexOfMethod("foo(const QString&, int)"), 0); + QCOMPARE(builder.indexOfMethod("bar(QString)"), 1); + QCOMPARE(builder.indexOfMethod("baz()"), -1); + + // Modify the attributes on method1. + method1.setReturnType("int"); + method1.setParameterNames(QList() << "a" << "b"); + method1.setTag("tag"); + method1.setAccess(QMetaMethod::Private); + method1.setAttributes(42); + + // Check that method1 is changed, but method2 is not. + QCOMPARE(method1.signature(), QByteArray("foo(QString,int)")); + QVERIFY(method1.methodType() == QMetaMethod::Method); + QCOMPARE(method1.returnType(), QByteArray("int")); + QCOMPARE(method1.parameterNames(), QList() << "a" << "b"); + QCOMPARE(method1.tag(), QByteArray("tag")); + QVERIFY(method1.access() == QMetaMethod::Private); + QCOMPARE(method1.attributes(), 42); + QCOMPARE(method1.index(), 0); + QCOMPARE(method2.signature(), QByteArray("bar(QString)")); + QVERIFY(method2.methodType() == QMetaMethod::Method); + QVERIFY(method2.returnType().isEmpty()); + QVERIFY(method2.parameterNames().isEmpty()); + QVERIFY(method2.tag().isEmpty()); + QVERIFY(method2.access() == QMetaMethod::Public); + QCOMPARE(method2.attributes(), 0); + QCOMPARE(method2.index(), 1); + QCOMPARE(builder.methodCount(), 2); + + // Modify the attributes on method2. + method2.setReturnType("QString"); + method2.setParameterNames(QList() << "c"); + method2.setTag("Q_FOO"); + method2.setAccess(QMetaMethod::Protected); + method2.setAttributes(24); + + // This time check that only method2 changed. + QCOMPARE(method1.signature(), QByteArray("foo(QString,int)")); + QVERIFY(method1.methodType() == QMetaMethod::Method); + QCOMPARE(method1.returnType(), QByteArray("int")); + QCOMPARE(method1.parameterNames(), QList() << "a" << "b"); + QCOMPARE(method1.tag(), QByteArray("tag")); + QVERIFY(method1.access() == QMetaMethod::Private); + QCOMPARE(method1.attributes(), 42); + QCOMPARE(method1.index(), 0); + QCOMPARE(method2.signature(), QByteArray("bar(QString)")); + QVERIFY(method2.methodType() == QMetaMethod::Method); + QCOMPARE(method2.returnType(), QByteArray("QString")); + QCOMPARE(method2.parameterNames(), QList() << "c"); + QCOMPARE(method2.tag(), QByteArray("Q_FOO")); + QVERIFY(method2.access() == QMetaMethod::Protected); + QCOMPARE(method2.attributes(), 24); + QCOMPARE(method2.index(), 1); + QCOMPARE(builder.methodCount(), 2); + + // Remove method1 and check that method2 becomes index 0. + builder.removeMethod(0); + QCOMPARE(builder.methodCount(), 1); + method2 = builder.method(0); + QCOMPARE(method2.signature(), QByteArray("bar(QString)")); + QVERIFY(method2.methodType() == QMetaMethod::Method); + QCOMPARE(method2.returnType(), QByteArray("QString")); + QCOMPARE(method2.parameterNames(), QList() << "c"); + QCOMPARE(method2.tag(), QByteArray("Q_FOO")); + QVERIFY(method2.access() == QMetaMethod::Protected); + QCOMPARE(method2.attributes(), 24); + QCOMPARE(method2.index(), 0); + + // Perform index-based lookup again. + QCOMPARE(builder.indexOfMethod("foo(const QString&, int)"), -1); + QCOMPARE(builder.indexOfMethod("bar(QString)"), 0); + QCOMPARE(builder.indexOfMethod("baz()"), -1); + + // Check that nothing else changed. + QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::Methods)); +} + +void tst_QMetaObjectBuilder::slot() +{ + QMetaObjectBuilder builder; + + // Add a slot and check its attributes. + QMetaMethodBuilder method1 = builder.addSlot("foo(const QString&, int)"); + QCOMPARE(method1.signature(), QByteArray("foo(QString,int)")); + QVERIFY(method1.methodType() == QMetaMethod::Slot); + QVERIFY(method1.returnType().isEmpty()); + QVERIFY(method1.parameterNames().isEmpty()); + QVERIFY(method1.tag().isEmpty()); + QVERIFY(method1.access() == QMetaMethod::Public); + QCOMPARE(method1.attributes(), 0); + QCOMPARE(method1.index(), 0); + QCOMPARE(builder.methodCount(), 1); + + // Add another slot and check again. + QMetaMethodBuilder method2 = builder.addSlot("bar(QString)"); + QCOMPARE(method2.signature(), QByteArray("bar(QString)")); + QVERIFY(method2.methodType() == QMetaMethod::Slot); + QVERIFY(method2.returnType().isEmpty()); + QVERIFY(method2.parameterNames().isEmpty()); + QVERIFY(method2.tag().isEmpty()); + QVERIFY(method2.access() == QMetaMethod::Public); + QCOMPARE(method2.attributes(), 0); + QCOMPARE(method2.index(), 1); + QCOMPARE(builder.methodCount(), 2); + + // Check that nothing else changed. + QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::Methods)); +} + +void tst_QMetaObjectBuilder::signal() +{ + QMetaObjectBuilder builder; + + // Add a signal and check its attributes. + QMetaMethodBuilder method1 = builder.addSignal("foo(const QString&, int)"); + QCOMPARE(method1.signature(), QByteArray("foo(QString,int)")); + QVERIFY(method1.methodType() == QMetaMethod::Signal); + QVERIFY(method1.returnType().isEmpty()); + QVERIFY(method1.parameterNames().isEmpty()); + QVERIFY(method1.tag().isEmpty()); + QVERIFY(method1.access() == QMetaMethod::Protected); + QCOMPARE(method1.attributes(), 0); + QCOMPARE(method1.index(), 0); + QCOMPARE(builder.methodCount(), 1); + + // Add another signal and check again. + QMetaMethodBuilder method2 = builder.addSignal("bar(QString)"); + QCOMPARE(method2.signature(), QByteArray("bar(QString)")); + QVERIFY(method2.methodType() == QMetaMethod::Signal); + QVERIFY(method2.returnType().isEmpty()); + QVERIFY(method2.parameterNames().isEmpty()); + QVERIFY(method2.tag().isEmpty()); + QVERIFY(method2.access() == QMetaMethod::Protected); + QCOMPARE(method2.attributes(), 0); + QCOMPARE(method2.index(), 1); + QCOMPARE(builder.methodCount(), 2); + + // Check that nothing else changed. + QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::Methods)); +} + +void tst_QMetaObjectBuilder::constructor() +{ + QMetaObjectBuilder builder; + + // Add a constructor and check its attributes. + QMetaMethodBuilder ctor1 = builder.addConstructor("foo(const QString&, int)"); + QCOMPARE(ctor1.signature(), QByteArray("foo(QString,int)")); + QVERIFY(ctor1.methodType() == QMetaMethod::Constructor); + QVERIFY(ctor1.returnType().isEmpty()); + QVERIFY(ctor1.parameterNames().isEmpty()); + QVERIFY(ctor1.tag().isEmpty()); + QVERIFY(ctor1.access() == QMetaMethod::Public); + QCOMPARE(ctor1.attributes(), 0); + QCOMPARE(ctor1.index(), 0); + QCOMPARE(builder.constructorCount(), 1); + + // Add another constructor and check again. + QMetaMethodBuilder ctor2 = builder.addConstructor("bar(QString)"); + QCOMPARE(ctor2.signature(), QByteArray("bar(QString)")); + QVERIFY(ctor2.methodType() == QMetaMethod::Constructor); + QVERIFY(ctor2.returnType().isEmpty()); + QVERIFY(ctor2.parameterNames().isEmpty()); + QVERIFY(ctor2.tag().isEmpty()); + QVERIFY(ctor2.access() == QMetaMethod::Public); + QCOMPARE(ctor2.attributes(), 0); + QCOMPARE(ctor2.index(), 1); + QCOMPARE(builder.constructorCount(), 2); + + // Perform index-based lookup. + QCOMPARE(builder.indexOfConstructor("foo(const QString&, int)"), 0); + QCOMPARE(builder.indexOfConstructor("bar(QString)"), 1); + QCOMPARE(builder.indexOfConstructor("baz()"), -1); + + // Modify the attributes on ctor1. + ctor1.setReturnType("int"); + ctor1.setParameterNames(QList() << "a" << "b"); + ctor1.setTag("tag"); + ctor1.setAccess(QMetaMethod::Private); + ctor1.setAttributes(42); + + // Check that ctor1 is changed, but ctor2 is not. + QCOMPARE(ctor1.signature(), QByteArray("foo(QString,int)")); + QVERIFY(ctor1.methodType() == QMetaMethod::Constructor); + QCOMPARE(ctor1.returnType(), QByteArray("int")); + QCOMPARE(ctor1.parameterNames(), QList() << "a" << "b"); + QCOMPARE(ctor1.tag(), QByteArray("tag")); + QVERIFY(ctor1.access() == QMetaMethod::Private); + QCOMPARE(ctor1.attributes(), 42); + QCOMPARE(ctor1.index(), 0); + QCOMPARE(ctor2.signature(), QByteArray("bar(QString)")); + QVERIFY(ctor2.methodType() == QMetaMethod::Constructor); + QVERIFY(ctor2.returnType().isEmpty()); + QVERIFY(ctor2.parameterNames().isEmpty()); + QVERIFY(ctor2.tag().isEmpty()); + QVERIFY(ctor2.access() == QMetaMethod::Public); + QCOMPARE(ctor2.attributes(), 0); + QCOMPARE(ctor2.index(), 1); + QCOMPARE(builder.constructorCount(), 2); + + // Modify the attributes on ctor2. + ctor2.setReturnType("QString"); + ctor2.setParameterNames(QList() << "c"); + ctor2.setTag("Q_FOO"); + ctor2.setAccess(QMetaMethod::Protected); + ctor2.setAttributes(24); + + // This time check that only ctor2 changed. + QCOMPARE(ctor1.signature(), QByteArray("foo(QString,int)")); + QVERIFY(ctor1.methodType() == QMetaMethod::Constructor); + QCOMPARE(ctor1.returnType(), QByteArray("int")); + QCOMPARE(ctor1.parameterNames(), QList() << "a" << "b"); + QCOMPARE(ctor1.tag(), QByteArray("tag")); + QVERIFY(ctor1.access() == QMetaMethod::Private); + QCOMPARE(ctor1.attributes(), 42); + QCOMPARE(ctor1.index(), 0); + QCOMPARE(ctor2.signature(), QByteArray("bar(QString)")); + QVERIFY(ctor2.methodType() == QMetaMethod::Constructor); + QCOMPARE(ctor2.returnType(), QByteArray("QString")); + QCOMPARE(ctor2.parameterNames(), QList() << "c"); + QCOMPARE(ctor2.tag(), QByteArray("Q_FOO")); + QVERIFY(ctor2.access() == QMetaMethod::Protected); + QCOMPARE(ctor2.attributes(), 24); + QCOMPARE(ctor2.index(), 1); + QCOMPARE(builder.constructorCount(), 2); + + // Remove ctor1 and check that ctor2 becomes index 0. + builder.removeConstructor(0); + QCOMPARE(builder.constructorCount(), 1); + ctor2 = builder.constructor(0); + QCOMPARE(ctor2.signature(), QByteArray("bar(QString)")); + QVERIFY(ctor2.methodType() == QMetaMethod::Constructor); + QCOMPARE(ctor2.returnType(), QByteArray("QString")); + QCOMPARE(ctor2.parameterNames(), QList() << "c"); + QCOMPARE(ctor2.tag(), QByteArray("Q_FOO")); + QVERIFY(ctor2.access() == QMetaMethod::Protected); + QCOMPARE(ctor2.attributes(), 24); + QCOMPARE(ctor2.index(), 0); + + // Perform index-based lookup again. + QCOMPARE(builder.indexOfConstructor("foo(const QString&, int)"), -1); + QCOMPARE(builder.indexOfConstructor("bar(QString)"), 0); + QCOMPARE(builder.indexOfConstructor("baz()"), -1); + + // Check that nothing else changed. + QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::Constructors)); +} + +void tst_QMetaObjectBuilder::property() +{ + QMetaObjectBuilder builder; + + // Add a property and check its attributes. + QMetaPropertyBuilder prop1 = builder.addProperty("foo", "const QString &"); + QCOMPARE(prop1.name(), QByteArray("foo")); + QCOMPARE(prop1.type(), QByteArray("QString")); + QVERIFY(!prop1.hasNotifySignal()); + QVERIFY(prop1.isReadable()); + QVERIFY(prop1.isWritable()); + QVERIFY(!prop1.isResettable()); + QVERIFY(!prop1.isDesignable()); + QVERIFY(!prop1.isScriptable()); + QVERIFY(!prop1.isStored()); + QVERIFY(!prop1.isEditable()); + QVERIFY(!prop1.isUser()); + QVERIFY(!prop1.hasStdCppSet()); + QVERIFY(!prop1.isEnumOrFlag()); + QCOMPARE(prop1.index(), 0); + QCOMPARE(builder.propertyCount(), 1); + + // Add another property and check again. + QMetaPropertyBuilder prop2 = builder.addProperty("bar", "int"); + QCOMPARE(prop2.name(), QByteArray("bar")); + QCOMPARE(prop2.type(), QByteArray("int")); + QVERIFY(!prop2.hasNotifySignal()); + QVERIFY(prop2.isReadable()); + QVERIFY(prop2.isWritable()); + QVERIFY(!prop2.isResettable()); + QVERIFY(!prop2.isDesignable()); + QVERIFY(!prop2.isScriptable()); + QVERIFY(!prop2.isStored()); + QVERIFY(!prop2.isEditable()); + QVERIFY(!prop2.isUser()); + QVERIFY(!prop2.hasStdCppSet()); + QVERIFY(!prop2.isEnumOrFlag()); + QCOMPARE(prop2.index(), 1); + QCOMPARE(builder.propertyCount(), 2); + + // Perform index-based lookup. + QCOMPARE(builder.indexOfProperty("foo"), 0); + QCOMPARE(builder.indexOfProperty("bar"), 1); + QCOMPARE(builder.indexOfProperty("baz"), -1); + + // Modify the attributes on prop1. + prop1.setReadable(false); + prop1.setWritable(false); + prop1.setResettable(true); + prop1.setDesignable(true); + prop1.setScriptable(true); + prop1.setStored(true); + prop1.setEditable(true); + prop1.setUser(true); + prop1.setStdCppSet(true); + prop1.setEnumOrFlag(true); + + // Check that prop1 is changed, but prop2 is not. + QCOMPARE(prop1.name(), QByteArray("foo")); + QCOMPARE(prop1.type(), QByteArray("QString")); + QVERIFY(!prop1.isReadable()); + QVERIFY(!prop1.isWritable()); + QVERIFY(prop1.isResettable()); + QVERIFY(prop1.isDesignable()); + QVERIFY(prop1.isScriptable()); + QVERIFY(prop1.isStored()); + QVERIFY(prop1.isEditable()); + QVERIFY(prop1.isUser()); + QVERIFY(prop1.hasStdCppSet()); + QVERIFY(prop1.isEnumOrFlag()); + QVERIFY(prop2.isReadable()); + QVERIFY(prop2.isWritable()); + QCOMPARE(prop2.name(), QByteArray("bar")); + QCOMPARE(prop2.type(), QByteArray("int")); + QVERIFY(!prop2.isResettable()); + QVERIFY(!prop2.isDesignable()); + QVERIFY(!prop2.isScriptable()); + QVERIFY(!prop2.isStored()); + QVERIFY(!prop2.isEditable()); + QVERIFY(!prop2.isUser()); + QVERIFY(!prop2.hasStdCppSet()); + QVERIFY(!prop2.isEnumOrFlag()); + + // Remove prop1 and check that prop2 becomes index 0. + builder.removeProperty(0); + QCOMPARE(builder.propertyCount(), 1); + prop2 = builder.property(0); + QCOMPARE(prop2.name(), QByteArray("bar")); + QCOMPARE(prop2.type(), QByteArray("int")); + QVERIFY(!prop2.isResettable()); + QVERIFY(!prop2.isDesignable()); + QVERIFY(!prop2.isScriptable()); + QVERIFY(!prop2.isStored()); + QVERIFY(!prop2.isEditable()); + QVERIFY(!prop2.isUser()); + QVERIFY(!prop2.hasStdCppSet()); + QVERIFY(!prop2.isEnumOrFlag()); + QCOMPARE(prop2.index(), 0); + + // Perform index-based lookup again. + QCOMPARE(builder.indexOfProperty("foo"), -1); + QCOMPARE(builder.indexOfProperty("bar"), 0); + QCOMPARE(builder.indexOfProperty("baz"), -1); + + // Check for side-effects between the flags on prop2. + // Setting a flag to true shouldn't set any of the others to true. + // This checks for cut-and-paste bugs in the implementation where + // the flag code was pasted but the flag name was not changed. +#define CLEAR_FLAGS() \ + do { \ + prop2.setReadable(false); \ + prop2.setWritable(false); \ + prop2.setResettable(false); \ + prop2.setDesignable(false); \ + prop2.setScriptable(false); \ + prop2.setStored(false); \ + prop2.setEditable(false); \ + prop2.setUser(false); \ + prop2.setStdCppSet(false); \ + prop2.setEnumOrFlag(false); \ + } while (0) +#define COUNT_FLAGS() \ + ((prop2.isReadable() ? 1 : 0) + \ + (prop2.isWritable() ? 1 : 0) + \ + (prop2.isResettable() ? 1 : 0) + \ + (prop2.isDesignable() ? 1 : 0) + \ + (prop2.isScriptable() ? 1 : 0) + \ + (prop2.isStored() ? 1 : 0) + \ + (prop2.isEditable() ? 1 : 0) + \ + (prop2.isUser() ? 1 : 0) + \ + (prop2.hasStdCppSet() ? 1 : 0) + \ + (prop2.isEnumOrFlag() ? 1 : 0)) +#define CHECK_FLAG(setFunc,isFunc) \ + do { \ + CLEAR_FLAGS(); \ + QCOMPARE(COUNT_FLAGS(), 0); \ + prop2.setFunc(true); \ + QVERIFY(prop2.isFunc()); \ + QCOMPARE(COUNT_FLAGS(), 1); \ + } while (0) + CHECK_FLAG(setReadable, isReadable); + CHECK_FLAG(setWritable, isWritable); + CHECK_FLAG(setResettable, isResettable); + CHECK_FLAG(setDesignable, isDesignable); + CHECK_FLAG(setScriptable, isScriptable); + CHECK_FLAG(setStored, isStored); + CHECK_FLAG(setEditable, isEditable); + CHECK_FLAG(setUser, isUser); + CHECK_FLAG(setStdCppSet, hasStdCppSet); + CHECK_FLAG(setEnumOrFlag, isEnumOrFlag); + + // Check that nothing else changed. + QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::Properties)); +} + +void tst_QMetaObjectBuilder::notifySignal() +{ + QMetaObjectBuilder builder; + + QMetaPropertyBuilder prop = builder.addProperty("foo", "const QString &"); + builder.addSlot("setFoo(QString)"); + QMetaMethodBuilder notify = builder.addSignal("fooChanged(QString)"); + + QVERIFY(!prop.hasNotifySignal()); + QCOMPARE(prop.notifySignal().index(), 0); + + prop.setNotifySignal(notify); + QVERIFY(prop.hasNotifySignal()); + QCOMPARE(prop.notifySignal().index(), 1); + + prop.setNotifySignal(QMetaMethodBuilder()); + QVERIFY(!prop.hasNotifySignal()); + QCOMPARE(prop.notifySignal().index(), 0); + + prop.setNotifySignal(notify); + prop.removeNotifySignal(); + QVERIFY(!prop.hasNotifySignal()); + QCOMPARE(prop.notifySignal().index(), 0); + + QCOMPARE(builder.methodCount(), 2); + QCOMPARE(builder.propertyCount(), 1); + + // Check that nothing else changed except methods and properties. + QVERIFY(checkForSideEffects + (builder, QMetaObjectBuilder::Methods | QMetaObjectBuilder::Properties)); +} + +void tst_QMetaObjectBuilder::enumerator() +{ + QMetaObjectBuilder builder; + + // Add an enumerator and check its attributes. + QMetaEnumBuilder enum1 = builder.addEnumerator("foo"); + QCOMPARE(enum1.name(), QByteArray("foo")); + QVERIFY(!enum1.isFlag()); + QCOMPARE(enum1.keyCount(), 0); + QCOMPARE(enum1.index(), 0); + QCOMPARE(builder.enumeratorCount(), 1); + + // Add another enumerator and check again. + QMetaEnumBuilder enum2 = builder.addEnumerator("bar"); + QCOMPARE(enum2.name(), QByteArray("bar")); + QVERIFY(!enum2.isFlag()); + QCOMPARE(enum2.keyCount(), 0); + QCOMPARE(enum2.index(), 1); + QCOMPARE(builder.enumeratorCount(), 2); + + // Perform index-based lookup. + QCOMPARE(builder.indexOfEnumerator("foo"), 0); + QCOMPARE(builder.indexOfEnumerator("bar"), 1); + QCOMPARE(builder.indexOfEnumerator("baz"), -1); + + // Modify the attributes on enum1. + enum1.setIsFlag(true); + QCOMPARE(enum1.addKey("ABC", 0), 0); + QCOMPARE(enum1.addKey("DEF", 1), 1); + QCOMPARE(enum1.addKey("GHI", -1), 2); + + // Check that enum1 is changed, but enum2 is not. + QCOMPARE(enum1.name(), QByteArray("foo")); + QVERIFY(enum1.isFlag()); + QCOMPARE(enum1.keyCount(), 3); + QCOMPARE(enum1.index(), 0); + QCOMPARE(enum1.key(0), QByteArray("ABC")); + QCOMPARE(enum1.key(1), QByteArray("DEF")); + QCOMPARE(enum1.key(2), QByteArray("GHI")); + QCOMPARE(enum1.value(0), 0); + QCOMPARE(enum1.value(1), 1); + QCOMPARE(enum1.value(2), -1); + QCOMPARE(enum2.name(), QByteArray("bar")); + QVERIFY(!enum2.isFlag()); + QCOMPARE(enum2.keyCount(), 0); + QCOMPARE(enum2.index(), 1); + + // Modify the attributes on enum2. + enum2.setIsFlag(true); + QCOMPARE(enum2.addKey("XYZ", 10), 0); + QCOMPARE(enum2.addKey("UVW", 19), 1); + + // This time check that only method2 changed. + QCOMPARE(enum1.name(), QByteArray("foo")); + QVERIFY(enum1.isFlag()); + QCOMPARE(enum1.keyCount(), 3); + QCOMPARE(enum1.index(), 0); + QCOMPARE(enum1.key(0), QByteArray("ABC")); + QCOMPARE(enum1.key(1), QByteArray("DEF")); + QCOMPARE(enum1.key(2), QByteArray("GHI")); + QCOMPARE(enum1.value(0), 0); + QCOMPARE(enum1.value(1), 1); + QCOMPARE(enum1.value(2), -1); + QCOMPARE(enum2.name(), QByteArray("bar")); + QVERIFY(enum2.isFlag()); + QCOMPARE(enum2.keyCount(), 2); + QCOMPARE(enum2.index(), 1); + QCOMPARE(enum2.key(0), QByteArray("XYZ")); + QCOMPARE(enum2.key(1), QByteArray("UVW")); + QCOMPARE(enum2.value(0), 10); + QCOMPARE(enum2.value(1), 19); + + // Remove enum1 and check that enum2 becomes index 0. + builder.removeEnumerator(0); + QCOMPARE(builder.enumeratorCount(), 1); + enum2 = builder.enumerator(0); + QCOMPARE(enum2.name(), QByteArray("bar")); + QVERIFY(enum2.isFlag()); + QCOMPARE(enum2.keyCount(), 2); + QCOMPARE(enum2.index(), 0); + QCOMPARE(enum2.key(0), QByteArray("XYZ")); + QCOMPARE(enum2.key(1), QByteArray("UVW")); + QCOMPARE(enum2.value(0), 10); + QCOMPARE(enum2.value(1), 19); + + // Perform index-based lookup again. + QCOMPARE(builder.indexOfEnumerator("foo"), -1); + QCOMPARE(builder.indexOfEnumerator("bar"), 0); + QCOMPARE(builder.indexOfEnumerator("baz"), -1); + + // Check that nothing else changed. + QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::Enumerators)); +} + +void tst_QMetaObjectBuilder::classInfo() +{ + QMetaObjectBuilder builder; + + // Add two items of class information and check their attributes. + QCOMPARE(builder.addClassInfo("foo", "value1"), 0); + QCOMPARE(builder.addClassInfo("bar", "value2"), 1); + QCOMPARE(builder.classInfoName(0), QByteArray("foo")); + QCOMPARE(builder.classInfoValue(0), QByteArray("value1")); + QCOMPARE(builder.classInfoName(1), QByteArray("bar")); + QCOMPARE(builder.classInfoValue(1), QByteArray("value2")); + QCOMPARE(builder.classInfoCount(), 2); + + // Perform index-based lookup. + QCOMPARE(builder.indexOfClassInfo("foo"), 0); + QCOMPARE(builder.indexOfClassInfo("bar"), 1); + QCOMPARE(builder.indexOfClassInfo("baz"), -1); + + // Remove the first one and check again. + builder.removeClassInfo(0); + QCOMPARE(builder.classInfoName(0), QByteArray("bar")); + QCOMPARE(builder.classInfoValue(0), QByteArray("value2")); + QCOMPARE(builder.classInfoCount(), 1); + + // Perform index-based lookup again. + QCOMPARE(builder.indexOfClassInfo("foo"), -1); + QCOMPARE(builder.indexOfClassInfo("bar"), 0); + QCOMPARE(builder.indexOfClassInfo("baz"), -1); + + // Check that nothing else changed. + QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::ClassInfos)); +} + +void tst_QMetaObjectBuilder::relatedMetaObject() +{ + QMetaObjectBuilder builder; + + // Add two related meta objects and check their attributes. + QCOMPARE(builder.addRelatedMetaObject(&QObject::staticMetaObject), 0); + QCOMPARE(builder.addRelatedMetaObject(&staticMetaObject), 1); + QVERIFY(builder.relatedMetaObject(0) == &QObject::staticMetaObject); + QVERIFY(builder.relatedMetaObject(1) == &staticMetaObject); + QCOMPARE(builder.relatedMetaObjectCount(), 2); + + // Remove the first one and check again. + builder.removeRelatedMetaObject(0); + QVERIFY(builder.relatedMetaObject(0) == &staticMetaObject); + QCOMPARE(builder.relatedMetaObjectCount(), 1); + + // Check that nothing else changed. + QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::RelatedMetaObjects)); +} + +static int smetacall(QMetaObject::Call, int, void **) +{ + return 0; +} + +void tst_QMetaObjectBuilder::staticMetacall() +{ + QMetaObjectBuilder builder; + QVERIFY(!builder.staticMetacallFunction()); + builder.setStaticMetacallFunction(smetacall); + QVERIFY(builder.staticMetacallFunction() == smetacall); + QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::StaticMetacall)); +} + +// Dummy class that has something of every type of thing moc can generate. +class SomethingOfEverything : public QObject +{ + Q_OBJECT + Q_CLASSINFO("ci_foo", "ABC") + Q_CLASSINFO("ci_bar", "DEF") + Q_PROPERTY(QString prop READ prop WRITE setProp NOTIFY propChanged) + Q_PROPERTY(QString prop2 READ prop WRITE setProp) + Q_PROPERTY(SomethingEnum eprop READ eprop) + Q_PROPERTY(SomethingFlagEnum fprop READ fprop) + Q_PROPERTY(QLocale::Language language READ language) + Q_ENUMS(SomethingEnum) + Q_FLAGS(SomethingFlagEnum) +public: + Q_INVOKABLE SomethingOfEverything() {} + ~SomethingOfEverything() {} + + enum SomethingEnum + { + GHI, + JKL = 10 + }; + + enum SomethingFlagEnum + { + XYZ = 1, + UVW = 8 + }; + + Q_INVOKABLE Q_SCRIPTABLE void method1() {} + + QString prop() const { return QString(); } + void setProp(const QString& v) { Q_UNUSED(v); } + + SomethingOfEverything::SomethingEnum eprop() const { return GHI; } + SomethingOfEverything::SomethingFlagEnum fprop() const { return XYZ; } + QLocale::Language language() const { return QLocale::English; } + +public slots: + void slot1(const QString&) {} + void slot2(int, const QString&) {} + +private slots: + void slot3() {} + +protected slots: + Q_SCRIPTABLE void slot4(int) {} + void slot5(int a, const QString& b) { Q_UNUSED(a); Q_UNUSED(b); } + +signals: + void sig1(); + void sig2(int x, const QString& y); + void propChanged(const QString&); +}; + +// Copy the entire contents of a static QMetaObject and then check +// that QMetaObjectBuilder will produce an exact copy as output. +void tst_QMetaObjectBuilder::copyMetaObject() +{ + QMetaObjectBuilder builder(&QObject::staticMetaObject); + QMetaObject *meta = builder.toMetaObject(); + QVERIFY(sameMetaObject(meta, &QObject::staticMetaObject)); + qFree(meta); + + QMetaObjectBuilder builder2(&staticMetaObject); + meta = builder2.toMetaObject(); + QVERIFY(sameMetaObject(meta, &staticMetaObject)); + qFree(meta); + + QMetaObjectBuilder builder3(&SomethingOfEverything::staticMetaObject); + meta = builder3.toMetaObject(); + QVERIFY(sameMetaObject(meta, &SomethingOfEverything::staticMetaObject)); + qFree(meta); +} + +// Serialize and deserialize a meta object and check that +// it round-trips to the exact same value. +void tst_QMetaObjectBuilder::serialize() +{ + QMetaObjectBuilder builder(&SomethingOfEverything::staticMetaObject); + QMetaObject *meta = builder.toMetaObject(); + + QByteArray data; + QDataStream stream(&data, QIODevice::WriteOnly | QIODevice::Append); + builder.serialize(stream); + + QMetaObjectBuilder builder2; + QDataStream stream2(data); + QMap references; + references.insert(QByteArray("QLocale"), &QLocale::staticMetaObject); + builder2.deserialize(stream2, references); + builder2.setStaticMetacallFunction(builder.staticMetacallFunction()); + QMetaObject *meta2 = builder2.toMetaObject(); + + QVERIFY(sameMetaObject(meta, meta2)); + qFree(meta); + qFree(meta2); +} + +// Check that the only changes to a "builder" relative to the default +// state is specified by "members". +bool tst_QMetaObjectBuilder::checkForSideEffects + (const QMetaObjectBuilder& builder, + QMetaObjectBuilder::AddMembers members) +{ + if ((members & QMetaObjectBuilder::ClassName) == 0) { + if (!builder.className().isEmpty()) + return false; + } + + if ((members & QMetaObjectBuilder::SuperClass) == 0) { + if (builder.superClass() != &QObject::staticMetaObject) + return false; + } + + if ((members & QMetaObjectBuilder::Methods) == 0) { + if (builder.methodCount() != 0) + return false; + } + + if ((members & QMetaObjectBuilder::Constructors) == 0) { + if (builder.constructorCount() != 0) + return false; + } + + if ((members & QMetaObjectBuilder::Properties) == 0) { + if (builder.propertyCount() != 0) + return false; + } + + if ((members & QMetaObjectBuilder::Enumerators) == 0) { + if (builder.enumeratorCount() != 0) + return false; + } + + if ((members & QMetaObjectBuilder::ClassInfos) == 0) { + if (builder.classInfoCount() != 0) + return false; + } + + if ((members & QMetaObjectBuilder::RelatedMetaObjects) == 0) { + if (builder.relatedMetaObjectCount() != 0) + return false; + } + + if ((members & QMetaObjectBuilder::StaticMetacall) == 0) { + if (builder.staticMetacallFunction() != 0) + return false; + } + + return true; +} + +static bool sameMethod(const QMetaMethod& method1, const QMetaMethod& method2) +{ + if (QByteArray(method1.signature()) != QByteArray(method2.signature())) + return false; + + if (QByteArray(method1.typeName()) != QByteArray(method2.typeName())) + return false; + + if (method1.parameterNames() != method2.parameterNames()) + return false; + + if (QByteArray(method1.tag()) != QByteArray(method2.tag())) + return false; + + if (method1.access() != method2.access()) + return false; + + if (method1.methodType() != method2.methodType()) + return false; + + if (method1.attributes() != method2.attributes()) + return false; + + return true; +} + +static bool sameProperty(const QMetaProperty& prop1, const QMetaProperty& prop2) +{ + if (QByteArray(prop1.name()) != QByteArray(prop2.name())) + return false; + + if (QByteArray(prop1.typeName()) != QByteArray(prop2.typeName())) + return false; + + if (prop1.isReadable() != prop2.isReadable() || + prop1.isWritable() != prop2.isWritable() || + prop1.isResettable() != prop2.isResettable() || + prop1.isDesignable() != prop2.isDesignable() || + prop1.isScriptable() != prop2.isScriptable() || + prop1.isStored() != prop2.isStored() || + prop1.isEditable() != prop2.isEditable() || + prop1.isUser() != prop2.isUser() || + prop1.isFlagType() != prop2.isFlagType() || + prop1.isEnumType() != prop2.isEnumType() || + prop1.hasNotifySignal() != prop2.hasNotifySignal() || + prop1.hasStdCppSet() != prop2.hasStdCppSet()) + return false; + + if (prop1.hasNotifySignal()) { + if (prop1.notifySignalIndex() != prop2.notifySignalIndex()) + return false; + } + + return true; +} + +static bool sameEnumerator(const QMetaEnum& enum1, const QMetaEnum& enum2) +{ + if (QByteArray(enum1.name()) != QByteArray(enum2.name())) + return false; + + if (enum1.isFlag() != enum2.isFlag()) + return false; + + if (enum1.keyCount() != enum2.keyCount()) + return false; + + for (int index = 0; index < enum1.keyCount(); ++index) { + if (QByteArray(enum1.key(index)) != QByteArray(enum2.key(index))) + return false; + if (enum1.value(index) != enum2.value(index)) + return false; + } + + if (QByteArray(enum1.scope()) != QByteArray(enum2.scope())) + return false; + + return true; +} + +// Determine if two meta objects are identical. +bool tst_QMetaObjectBuilder::sameMetaObject + (const QMetaObject *meta1, const QMetaObject *meta2) +{ + int index; + + if (strcmp(meta1->className(), meta2->className()) != 0) + return false; + + if (meta1->superClass() != meta2->superClass()) + return false; + + if (meta1->constructorCount() != meta2->constructorCount() || + meta1->methodCount() != meta2->methodCount() || + meta1->enumeratorCount() != meta2->enumeratorCount() || + meta1->propertyCount() != meta2->propertyCount() || + meta1->classInfoCount() != meta2->classInfoCount()) + return false; + + for (index = 0; index < meta1->constructorCount(); ++index) { + if (!sameMethod(meta1->constructor(index), meta2->constructor(index))) + return false; + } + + for (index = 0; index < meta1->methodCount(); ++index) { + if (!sameMethod(meta1->method(index), meta2->method(index))) + return false; + } + + for (index = 0; index < meta1->propertyCount(); ++index) { + if (!sameProperty(meta1->property(index), meta2->property(index))) + return false; + } + + for (index = 0; index < meta1->enumeratorCount(); ++index) { + if (!sameEnumerator(meta1->enumerator(index), meta2->enumerator(index))) + return false; + } + + for (index = 0; index < meta1->classInfoCount(); ++index) { + if (QByteArray(meta1->classInfo(index).name()) != + QByteArray(meta2->classInfo(index).name())) + return false; + if (QByteArray(meta1->classInfo(index).value()) != + QByteArray(meta2->classInfo(index).value())) + return false; + } + + const QMetaObject **objects1 = 0; + const QMetaObject **objects2 = 0; + if (meta1->d.data[0] == meta2->d.data[0] && meta1->d.data[0] >= 2) { + QMetaObjectExtraData *extra1 = (QMetaObjectExtraData *)(meta1->d.extradata); + QMetaObjectExtraData *extra2 = (QMetaObjectExtraData *)(meta2->d.extradata); + if (extra1 && !extra2) + return false; + if (extra2 && !extra1) + return false; + if (extra1 && extra2) { + if (extra1->static_metacall != extra2->static_metacall) + return false; + objects1 = extra1->objects; + objects2 = extra1->objects; + } + } else if (meta1->d.data[0] == meta2->d.data[0] && meta1->d.data[0] == 1) { + objects1 = (const QMetaObject **)(meta1->d.extradata); + objects2 = (const QMetaObject **)(meta2->d.extradata); + } + if (objects1 && !objects2) + return false; + if (objects2 && !objects1) + return false; + if (objects1 && objects2) { + while (*objects1 != 0 && *objects2 != 0) { + if (*objects1 != *objects2) + return false; + ++objects1; + ++objects2; + } + } + + return true; +} + +QTEST_MAIN(tst_QMetaObjectBuilder) + +#include "tst_qmetaobjectbuilder.moc" -- cgit v0.12 From c8be1c487994fda855b9f2dc7c005db4686981c0 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 3 Nov 2009 15:31:07 +1000 Subject: Get AnimatedImage + autotests working again. There are still failures, but at least the tests no longer crash. --- .../extra/qmlgraphicsanimatedimageitem.cpp | 48 +++++++++++++++++++--- src/declarative/graphicsitems/qmlgraphicsimage.cpp | 14 +++++-- .../graphicsitems/qmlgraphicsimage_p_p.h | 2 +- .../animatedimage/tst_animatedimage.cpp | 38 +++++++++-------- 4 files changed, 76 insertions(+), 26 deletions(-) diff --git a/src/declarative/extra/qmlgraphicsanimatedimageitem.cpp b/src/declarative/extra/qmlgraphicsanimatedimageitem.cpp index 5dbffc0..f3c2058 100644 --- a/src/declarative/extra/qmlgraphicsanimatedimageitem.cpp +++ b/src/declarative/extra/qmlgraphicsanimatedimageitem.cpp @@ -40,7 +40,6 @@ ****************************************************************************/ #include -#include #include #include "qmlgraphicsanimatedimageitem_p.h" #include "qmlgraphicsanimatedimageitem_p_p.h" @@ -179,6 +178,14 @@ int QmlGraphicsAnimatedImageItem::frameCount() const return d->_movie->frameCount(); } +static QString toLocalFileOrQrc(const QUrl& url) +{ + QString r = url.toLocalFile(); + if (r.isEmpty() && url.scheme() == QLatin1String("qrc")) + r = QLatin1Char(':') + url.path(); + return r; +} + void QmlGraphicsAnimatedImageItem::setSource(const QUrl &url) { Q_D(QmlGraphicsAnimatedImageItem); @@ -193,15 +200,46 @@ void QmlGraphicsAnimatedImageItem::setSource(const QUrl &url) d->reply = 0; } - d->url = qmlContext(this)->resolvedUrl(url); + d->url = url; if (url.isEmpty()) { delete d->_movie; d->status = Null; } else { +#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML + QString lf = toLocalFileOrQrc(url); + if (!lf.isEmpty()) { + //### should be unified with movieRequestFinished + d->_movie = new QMovie(lf); + if (!d->_movie->isValid()){ + qWarning() << "Error Reading Animated Image File " << d->url; + delete d->_movie; + d->_movie = 0; + return; + } + connect(d->_movie, SIGNAL(stateChanged(QMovie::MovieState)), + this, SLOT(playingStatusChanged())); + connect(d->_movie, SIGNAL(frameChanged(int)), + this, SLOT(movieUpdate())); + d->_movie->setCacheMode(QMovie::CacheAll); + if(d->playing) + d->_movie->start(); + else + d->_movie->jumpToFrame(0); + if(d->paused) + d->_movie->setPaused(true); + d->setPixmap(d->_movie->currentPixmap()); + d->status = Ready; + d->progress = 1.0; + emit statusChanged(d->status); + emit sourceChanged(d->url); + emit progressChanged(d->progress); + return; + } +#endif d->status = Loading; QNetworkRequest req(d->url); - d->reply = qmlContext(this)->engine()->networkAccessManager()->get(req); + d->reply = qmlEngine(this)->networkAccessManager()->get(req); QObject::connect(d->reply, SIGNAL(finished()), this, SLOT(movieRequestFinished())); } @@ -230,13 +268,13 @@ void QmlGraphicsAnimatedImageItem::movieRequestFinished() d->_movie->jumpToFrame(0); if(d->paused) d->_movie->setPaused(true); - setPixmap(d->_movie->currentPixmap()); + d->setPixmap(d->_movie->currentPixmap()); } void QmlGraphicsAnimatedImageItem::movieUpdate() { Q_D(QmlGraphicsAnimatedImageItem); - setPixmap(d->_movie->currentPixmap()); + d->setPixmap(d->_movie->currentPixmap()); emit frameChanged(); } diff --git a/src/declarative/graphicsitems/qmlgraphicsimage.cpp b/src/declarative/graphicsitems/qmlgraphicsimage.cpp index fd220a3..938fe2a 100644 --- a/src/declarative/graphicsitems/qmlgraphicsimage.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsimage.cpp @@ -152,12 +152,18 @@ void QmlGraphicsImage::setPixmap(const QPixmap &pix) Q_D(QmlGraphicsImage); if (!d->url.isEmpty()) return; - d->pix = pix; + d->setPixmap(pix); +} + +void QmlGraphicsImagePrivate::setPixmap(const QPixmap &pixmap) +{ + Q_Q(QmlGraphicsImage); + pix = pixmap; - setImplicitWidth(d->pix.width()); - setImplicitHeight(d->pix.height()); + q->setImplicitWidth(pix.width()); + q->setImplicitHeight(pix.height()); - update(); + q->update(); } /*! diff --git a/src/declarative/graphicsitems/qmlgraphicsimage_p_p.h b/src/declarative/graphicsitems/qmlgraphicsimage_p_p.h index 62a4d1e..f6b4e51 100644 --- a/src/declarative/graphicsitems/qmlgraphicsimage_p_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsimage_p_p.h @@ -69,7 +69,7 @@ public: } QmlGraphicsImage::FillMode fillMode; - + void setPixmap(const QPixmap &pix); }; QT_END_NAMESPACE diff --git a/tests/auto/declarative/animatedimage/tst_animatedimage.cpp b/tests/auto/declarative/animatedimage/tst_animatedimage.cpp index f6141cb..6ae2112 100644 --- a/tests/auto/declarative/animatedimage/tst_animatedimage.cpp +++ b/tests/auto/declarative/animatedimage/tst_animatedimage.cpp @@ -61,34 +61,40 @@ private slots: void tst_animatedimage::play() { - QmlGraphicsAnimatedImageItem anim; - anim.setSource(QUrl("file://" SRCDIR "/data/stickman.gif")); - QVERIFY(anim.isPlaying()); + QmlEngine engine; + QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/stickman.qml")); + QmlGraphicsAnimatedImageItem *anim = qobject_cast(component.create()); + QVERIFY(anim); + QVERIFY(anim->isPlaying()); } void tst_animatedimage::pause() { - QmlGraphicsAnimatedImageItem anim; - anim.setSource(QUrl("file://" SRCDIR "/data/stickman.gif")); - anim.setPaused(true); - QVERIFY(!anim.isPlaying()); + QmlEngine engine; + QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/stickmanpause.qml")); + QmlGraphicsAnimatedImageItem *anim = qobject_cast(component.create()); + QVERIFY(anim); + QVERIFY(anim->isPlaying()); + QVERIFY(anim->isPaused()); } void tst_animatedimage::setFrame() { - QmlGraphicsAnimatedImageItem anim; - anim.setSource(QUrl("file://" SRCDIR "/data/stickman.gif")); - anim.setPaused(true); - QVERIFY(!anim.isPlaying()); - anim.setCurrentFrame(2); - QCOMPARE(anim.currentFrame(), 2); + QmlEngine engine; + QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/stickmanpause.qml")); + QmlGraphicsAnimatedImageItem *anim = qobject_cast(component.create()); + QVERIFY(anim); + QVERIFY(anim->isPlaying()); + QCOMPARE(anim->currentFrame(), 2); } void tst_animatedimage::frameCount() { - QmlGraphicsAnimatedImageItem anim; - anim.setSource(QUrl("file://" SRCDIR "/data/stickman.gif")); - QCOMPARE(anim.frameCount(), 299); + QmlEngine engine; + QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/stickman.qml")); + QmlGraphicsAnimatedImageItem *anim = qobject_cast(component.create()); + QVERIFY(anim); + QCOMPARE(anim->frameCount(), 299); } QTEST_MAIN(tst_animatedimage) -- cgit v0.12 From 9b80a6de7fb70abcf5f912133ddc04c617a82922 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 3 Nov 2009 15:41:10 +1000 Subject: Match meta-object version --- tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp b/tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp index 0dac963..9beec17 100644 --- a/tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp +++ b/tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp @@ -52,8 +52,8 @@ void tst_QMetaObjectBuilder::mocVersionCheck() // It is intended as a reminder to also update QMetaObjectBuilder // whenenver moc changes. Once QMetaObjectBuilder has been // updated, this test can be changed to check for the next version. - QCOMPARE(int(QObject::staticMetaObject.d.data[0]), 2); - QCOMPARE(int(staticMetaObject.d.data[0]), 2); + QCOMPARE(int(QObject::staticMetaObject.d.data[0]), 4); + QCOMPARE(int(staticMetaObject.d.data[0]), 4); } void tst_QMetaObjectBuilder::create() -- cgit v0.12 From 36420993cb7572fa630ac88cdd6afefa2ab1c660 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 3 Nov 2009 15:43:56 +1000 Subject: More QmlContext tests --- src/declarative/qml/qmlcontext.cpp | 16 +------ src/declarative/qml/qmlcontext_p.h | 3 -- .../auto/declarative/qmlcontext/tst_qmlcontext.cpp | 49 +++++++++++++++++++++- 3 files changed, 50 insertions(+), 18 deletions(-) diff --git a/src/declarative/qml/qmlcontext.cpp b/src/declarative/qml/qmlcontext.cpp index d37d959..f8e685a 100644 --- a/src/declarative/qml/qmlcontext.cpp +++ b/src/declarative/qml/qmlcontext.cpp @@ -88,18 +88,6 @@ void QmlContextPrivate::addScript(const QString &script, QObject *scopeObject, scripts.append(scope); } -void QmlContextPrivate::dump() -{ - dump(0); -} - -void QmlContextPrivate::dump(int depth) -{ - QByteArray ba(depth * 4, ' '); - if (parent) - parent->d_func()->dump(depth + 1); -} - void QmlContextPrivate::destroyed(ContextGuard *guard) { Q_Q(QmlContext); @@ -382,8 +370,8 @@ void QmlContext::setContextProperty(const QString &name, const QVariant &value) if (d->notifyIndex == -1) d->notifyIndex = this->metaObject()->methodCount(); - if (QmlMetaType::isObject(value.userType())) { - QObject *o = QmlMetaType::toQObject(value); + if (d->engine && QmlEnginePrivate::get(d->engine)->isObject(value.userType())) { + QObject *o = *(QObject **)value.constData(); setContextProperty(name, o); } else { diff --git a/src/declarative/qml/qmlcontext_p.h b/src/declarative/qml/qmlcontext_p.h index cc8fcc6..7f9be0f 100644 --- a/src/declarative/qml/qmlcontext_p.h +++ b/src/declarative/qml/qmlcontext_p.h @@ -101,9 +101,6 @@ public: void init(); - void dump(); - void dump(int depth); - void invalidateEngines(); void refreshExpressions(); QSet childContexts; diff --git a/tests/auto/declarative/qmlcontext/tst_qmlcontext.cpp b/tests/auto/declarative/qmlcontext/tst_qmlcontext.cpp index 69d9091..3c60b2b 100644 --- a/tests/auto/declarative/qmlcontext/tst_qmlcontext.cpp +++ b/tests/auto/declarative/qmlcontext/tst_qmlcontext.cpp @@ -44,6 +44,7 @@ #include #include #include +#include class tst_qmlcontext : public QObject { @@ -58,6 +59,7 @@ private slots: void parentContext(); void setContextProperty(); void addDefaultObject(); + void destruction(); private: QmlEngine engine; @@ -111,6 +113,14 @@ void tst_qmlcontext::resolvedUrl() QCOMPARE(ctxt2.resolvedUrl(QUrl("main2.qml")), QUrl()); } + + // Absolute + { + QmlContext ctxt(&engine); + + QCOMPARE(ctxt.resolvedUrl(QUrl("http://www.nokia.com/main2.qml")), QUrl("http://www.nokia.com/main2.qml")); + QCOMPARE(ctxt.resolvedUrl(QUrl("file:///main2.qml")), QUrl("file:///main2.qml")); + } } void tst_qmlcontext::engineMethod() @@ -256,10 +266,10 @@ void tst_qmlcontext::setContextProperty() // Static context properties ctxt.setContextProperty("a", QVariant(10)); ctxt.setContextProperty("b", QVariant(9)); + ctxt2.setContextProperty("d", &obj2); ctxt2.setContextProperty("b", QVariant(19)); ctxt2.setContextProperty("c", QVariant(QString("Hello World!"))); ctxt.setContextProperty("d", &obj1); - ctxt2.setContextProperty("d", &obj2); ctxt.setContextProperty("e", &obj1); TEST_CONTEXT_PROPERTY(&ctxt2, a, QVariant(10)); @@ -334,6 +344,26 @@ void tst_qmlcontext::setContextProperty() delete obj; } + + // Setting an object-variant context property + { + QmlComponent component(&engine); + component.setData("import Qt 4.6; Object { id: root; property int a: 10; property int test: ctxtProp.a; property var obj: root; }", QUrl()); + + QmlContext ctxt(engine.rootContext()); + ctxt.setContextProperty("ctxtProp", QVariant()); + + QTest::ignoreMessage(QtWarningMsg, ":1: TypeError: Result of expression 'ctxtProp' [undefined] is not an object."); + QObject *obj = component.create(&ctxt); + + QVariant v = obj->property("obj"); + + ctxt.setContextProperty("ctxtProp", v); + + QCOMPARE(obj->property("test"), QVariant(10)); + + delete obj; + } } void tst_qmlcontext::addDefaultObject() @@ -382,6 +412,23 @@ void tst_qmlcontext::addDefaultObject() } } +void tst_qmlcontext::destruction() +{ + QmlContext *ctxt = new QmlContext(&engine); + + QObject obj; + QmlEngine::setContextForObject(&obj, ctxt); + QmlExpression expr(ctxt, "a", 0); + + QCOMPARE(ctxt, QmlEngine::contextForObject(&obj)); + QCOMPARE(ctxt, expr.context()); + + delete ctxt; ctxt = 0; + + QCOMPARE(ctxt, QmlEngine::contextForObject(&obj)); + QCOMPARE(ctxt, expr.context()); +} + QTEST_MAIN(tst_qmlcontext) #include "tst_qmlcontext.moc" -- cgit v0.12 From 0cf756891d94bcfef52c7c18ce4e3e3f7e64e2d7 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 3 Nov 2009 16:10:53 +1000 Subject: Add more Behavior autotests. --- tests/auto/declarative/behaviors/data/simple.qml | 5 ++- tests/auto/declarative/behaviors/tst_behaviors.cpp | 43 ++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/tests/auto/declarative/behaviors/data/simple.qml b/tests/auto/declarative/behaviors/data/simple.qml index a715f7b..37c3915 100644 --- a/tests/auto/declarative/behaviors/data/simple.qml +++ b/tests/auto/declarative/behaviors/data/simple.qml @@ -6,7 +6,10 @@ Rectangle { id: rect objectName: "MyRect" width: 100; height: 100; color: "green" - x: Behavior { NumberAnimation { duration: 200; } } + x: Behavior { + objectName: "MyBehavior"; + NumberAnimation { duration: 200; } + } } MouseRegion { id: clicker diff --git a/tests/auto/declarative/behaviors/tst_behaviors.cpp b/tests/auto/declarative/behaviors/tst_behaviors.cpp index 9803a9d..7bdc82e 100644 --- a/tests/auto/declarative/behaviors/tst_behaviors.cpp +++ b/tests/auto/declarative/behaviors/tst_behaviors.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include class tst_behaviors : public QObject @@ -60,6 +61,9 @@ private slots: void replaceBinding(); //void transitionOverrides(); void group(); + void emptyBehavior(); + void nonSelectingBehavior(); + void reassignedAnimation(); }; void tst_behaviors::simpleBehavior() @@ -68,6 +72,7 @@ void tst_behaviors::simpleBehavior() QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/simple.qml")); QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); + QVERIFY(qobject_cast(rect->findChild("MyBehavior"))->animation()); rect->setState("moved"); QTest::qWait(100); @@ -189,6 +194,44 @@ void tst_behaviors::group() } } +void tst_behaviors::emptyBehavior() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/empty.qml")); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + rect->setState("moved"); + qreal x = qobject_cast(rect->findChild("MyRect"))->x(); + QCOMPARE(x, qreal(200)); //should change immediately +} + +void tst_behaviors::nonSelectingBehavior() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/nonSelecting.qml")); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + rect->setState("moved"); + qreal x = qobject_cast(rect->findChild("MyRect"))->x(); + QCOMPARE(x, qreal(200)); //should change immediately +} + +void tst_behaviors::reassignedAnimation() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/reassignedAnimation.qml")); + QTest::ignoreMessage(QtWarningMsg, "QML QmlBehavior (file://" SRCDIR "/data/reassignedAnimation.qml:9:12) Can't change the animation assigned to a Behavior."); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + rect->setState("moved"); + QTest::qWait(200 + 100); + qreal x = qobject_cast(rect->findChild("MyRect"))->x(); + QVERIFY(x > 0 && x < 200); //i.e. the right behavior has been triggered +} + QTEST_MAIN(tst_behaviors) #include "tst_behaviors.moc" -- cgit v0.12 From 57dadc8606eb0c864ef27e550f9a8ae109de5293 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 3 Nov 2009 16:12:57 +1000 Subject: Fix test. --- tests/auto/declarative/behaviors/tst_behaviors.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/declarative/behaviors/tst_behaviors.cpp b/tests/auto/declarative/behaviors/tst_behaviors.cpp index 7bdc82e..29c631d 100644 --- a/tests/auto/declarative/behaviors/tst_behaviors.cpp +++ b/tests/auto/declarative/behaviors/tst_behaviors.cpp @@ -229,7 +229,7 @@ void tst_behaviors::reassignedAnimation() rect->setState("moved"); QTest::qWait(200 + 100); qreal x = qobject_cast(rect->findChild("MyRect"))->x(); - QVERIFY(x > 0 && x < 200); //i.e. the right behavior has been triggered + QCOMPARE(x, qreal(200)); //i.e. the right behavior has been triggered } QTEST_MAIN(tst_behaviors) -- cgit v0.12 From 6f033b6a46ae5cf3dcfed9a2e17182ae58108a00 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 3 Nov 2009 16:20:41 +1000 Subject: Declare typeinfo for key navigation. --- src/declarative/graphicsitems/qmlgraphicsitem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsitem.cpp b/src/declarative/graphicsitems/qmlgraphicsitem.cpp index 0e741c4..5083f43 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsitem.cpp @@ -2918,5 +2918,5 @@ QML_DECLARE_TYPE(QmlGraphicsKeysAttached) QML_DECLARE_TYPEINFO(QmlGraphicsKeysAttached, QML_HAS_ATTACHED_PROPERTIES) QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Keys,QmlGraphicsKeysAttached) QML_DECLARE_TYPE(QmlGraphicsKeyNavigationAttached) +QML_DECLARE_TYPEINFO(QmlGraphicsKeyNavigationAttached, QML_HAS_ATTACHED_PROPERTIES) QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,KeyNavigation,QmlGraphicsKeyNavigationAttached) - -- cgit v0.12 From 7bc853890bbd8653c3d058d50811ae6dfaad1fd1 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 3 Nov 2009 16:43:50 +1000 Subject: Don't trigger if we've been stopped. Task-number: QT-2423 --- src/declarative/util/qmltimer.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/declarative/util/qmltimer.cpp b/src/declarative/util/qmltimer.cpp index 268d5ec..2e844be 100644 --- a/src/declarative/util/qmltimer.cpp +++ b/src/declarative/util/qmltimer.cpp @@ -57,12 +57,12 @@ public: : interval(1000), running(false), repeating(false), triggeredOnStart(false) , classBegun(false), componentComplete(false) {} int interval; - bool running; - bool repeating; - bool triggeredOnStart; QPauseAnimation pause; - bool classBegun; - bool componentComplete; + bool running : 1; + bool repeating : 1; + bool triggeredOnStart : 1; + bool classBegun : 1; + bool componentComplete : 1; }; /*! @@ -82,6 +82,9 @@ public: } \endqml + QmlTimer is synchronized with the animation timer. Since the animation + timer is usually set to 60fps, the resolution of QmlTimer will be + at best 16ms. */ QmlTimer::QmlTimer(QObject *parent) @@ -89,7 +92,6 @@ QmlTimer::QmlTimer(QObject *parent) { Q_D(QmlTimer); connect(&d->pause, SIGNAL(currentLoopChanged(int)), this, SLOT(ticked())); - connect(&d->pause, SIGNAL(finished()), this, SLOT(ticked())); connect(&d->pause, SIGNAL(stateChanged(QAbstractAnimation::State,QAbstractAnimation::State)) , this, SLOT(stateChanged(QAbstractAnimation::State,QAbstractAnimation::State))); d->pause.setLoopCount(1); @@ -259,7 +261,9 @@ void QmlTimer::componentComplete() */ void QmlTimer::ticked() { - emit triggered(); + Q_D(QmlTimer); + if (d->running) + emit triggered(); } void QmlTimer::stateChanged(QAbstractAnimation::State, QAbstractAnimation::State state) @@ -267,6 +271,7 @@ void QmlTimer::stateChanged(QAbstractAnimation::State, QAbstractAnimation::State Q_D(QmlTimer); if (d->running && state != QAbstractAnimation::Running) { d->running = false; + emit triggered(); emit runningChanged(); } } -- cgit v0.12 From ed82a5dbe57fcc80b9d6244c73295f4b0b6e2835 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 3 Nov 2009 16:45:59 +1000 Subject: Allow example-specific test. Allow examples to report failure via error property. Workaround QTBUG-5296 by running webbrowser demo for longer. --- tests/auto/declarative/examples/data/webbrowser/webbrowser.qml | 6 ++++++ tests/auto/declarative/examples/tst_examples.cpp | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 tests/auto/declarative/examples/data/webbrowser/webbrowser.qml diff --git a/tests/auto/declarative/examples/data/webbrowser/webbrowser.qml b/tests/auto/declarative/examples/data/webbrowser/webbrowser.qml new file mode 100644 index 0000000..bdf3290 --- /dev/null +++ b/tests/auto/declarative/examples/data/webbrowser/webbrowser.qml @@ -0,0 +1,6 @@ +import Qt.VisualTest 4.6 + +VisualTest { + Frame { msec: 0 } + Frame { msec: 1000 } +} diff --git a/tests/auto/declarative/examples/tst_examples.cpp b/tests/auto/declarative/examples/tst_examples.cpp index ac12204..d758101 100644 --- a/tests/auto/declarative/examples/tst_examples.cpp +++ b/tests/auto/declarative/examples/tst_examples.cpp @@ -42,6 +42,7 @@ #include #include #include +#include class tst_examples : public QObject { @@ -179,9 +180,12 @@ void tst_examples::examples() { QFETCH(QString, file); + QFileInfo fi(file); + QFileInfo dir(fi.path()); + QFileInfo testdata("data/"+dir.baseName()+"/"+fi.baseName()); QStringList arguments; - arguments << "-script" << "data/dummytest" - << "-scriptopts" << "play,exitoncomplete,exitonfailure" + arguments << "-script" << (testdata.exists() ? testdata.filePath() : QLatin1String("data/dummytest")) + << "-scriptopts" << "play,testerror,exitoncomplete,exitonfailure" << file; QProcess p; p.start(qmlviewer, arguments); -- cgit v0.12 From 79d35acae62bf28c37022b763b04e94f5e67bf6f Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 3 Nov 2009 16:47:55 +1000 Subject: Define and document deletion of QmlEngine QNetworkAccessManager --- src/declarative/qml/qmlengine.cpp | 14 +++++++------- tools/qmlviewer/qmlviewer.cpp | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 7242a1d..c562e02 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -181,8 +181,6 @@ QmlEnginePrivate::~QmlEnginePrivate() typeNameClass = 0; delete listClass; listClass = 0; - delete networkAccessManager; - networkAccessManager = 0; delete nodeListClass; nodeListClass = 0; delete namedNodeMapClass; @@ -336,14 +334,16 @@ QmlContext *QmlEngine::rootContext() Sets the common QNetworkAccessManager, \a network, used by all QML elements instantiated by this engine. - Any previously set manager is deleted and \a network is owned by the - QmlEngine. This method should only be called before any QmlComponents are - instantiated. + If the parent of \a network is this engine, the engine takes ownership and + will delete it as needed. Otherwise, ownership remains with the caller. + + This method should only be called before any QmlComponents are instantiated. */ void QmlEngine::setNetworkAccessManager(QNetworkAccessManager *network) { Q_D(QmlEngine); - delete d->networkAccessManager; + if (d->networkAccessManager && d->networkAccessManager->parent() == this) + delete d->networkAccessManager; d->networkAccessManager = network; } @@ -358,7 +358,7 @@ QNetworkAccessManager *QmlEngine::networkAccessManager() const { Q_D(const QmlEngine); if (!d->networkAccessManager) - d->networkAccessManager = new QNetworkAccessManager; + d->networkAccessManager = new QNetworkAccessManager(const_cast(this)); return d->networkAccessManager; } diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index 248ff24..b9f3e67 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -249,7 +249,7 @@ private: class ConfiguredNetworkAccessManager : public QNetworkAccessManager { public: - ConfiguredNetworkAccessManager() { } + ConfiguredNetworkAccessManager(QObject *parent) : QNetworkAccessManager(parent) { } QNetworkReply *createRequest (Operation op, const QNetworkRequest &req, QIODevice * outgoingData) { @@ -334,7 +334,7 @@ QmlViewer::QmlViewer(QWidget *parent, Qt::WindowFlags flags) canvas->setAttribute(Qt::WA_OpaquePaintEvent); canvas->setAttribute(Qt::WA_NoSystemBackground); canvas->setContentResizable(!skin || !scaleSkin); - canvas->engine()->setNetworkAccessManager(new ConfiguredNetworkAccessManager); + canvas->engine()->setNetworkAccessManager(new ConfiguredNetworkAccessManager(canvas->engine())); canvas->setFocus(); QObject::connect(canvas, SIGNAL(sceneResized(QSize)), this, SLOT(sceneResized(QSize))); -- cgit v0.12 From 447fea7eb02972f189a468782aa1f48ab796611a Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Tue, 3 Nov 2009 16:56:54 +1000 Subject: add some QmlGraphicsText tests --- tests/auto/declarative/qfxtext/tst_qfxtext.cpp | 67 ++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 9 deletions(-) diff --git a/tests/auto/declarative/qfxtext/tst_qfxtext.cpp b/tests/auto/declarative/qfxtext/tst_qfxtext.cpp index 173a3b4..49fc757 100644 --- a/tests/auto/declarative/qfxtext/tst_qfxtext.cpp +++ b/tests/auto/declarative/qfxtext/tst_qfxtext.cpp @@ -64,6 +64,7 @@ private slots: void font(); void style(); void color(); + void smooth(); private: QStringList standard; @@ -211,30 +212,34 @@ void tst_qfxtext::wrap() { // XXX Poor coverage - should at least be testing an expected height. + int textHeight = 0; // for specified width and wrap set true { - QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"\"; wrap: true; width: 300 }", QUrl("file://")); + QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"Hello\"; wrap: true; width: 300 }", QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + textHeight = textObject->height(); QCOMPARE(textObject->width(), 300.); } for (int i = 0; i < standard.size(); i++) { - QString componentStr = "import Qt 4.6\nText { wrap: true; width: 300; text: \"" + standard.at(i) + "\" }"; + QString componentStr = "import Qt 4.6\nText { wrap: true; width: 30; text: \"" + standard.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->width(), 300.); + QCOMPARE(textObject->width(), 30.); + QVERIFY(textObject->height() > textHeight); } for (int i = 0; i < richText.size(); i++) { - QString componentStr = "import Qt 4.6\nText { wrap: true; width: 300; text: \"" + richText.at(i) + "\" }"; + QString componentStr = "import Qt 4.6\nText { wrap: true; width: 30; text: \"" + richText.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->width(), 300.); + QCOMPARE(textObject->width(), 30.); + QVERIFY(textObject->height() > textHeight); } } @@ -317,7 +322,6 @@ void tst_qfxtext::verticalAlignment() QString componentStr = "import Qt 4.6\nText { verticalAlignment: \"" + verticalAlignmentmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE((int)textObject->vAlign(), (int)verticalAlignmentments.at(j)); } } @@ -339,7 +343,7 @@ void tst_qfxtext::verticalAlignment() void tst_qfxtext::font() { //test size, then bold, then italic, then family - { + { QString componentStr = "import Qt 4.6\nText { font.pointSize: 40; text: \"Hello World\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); @@ -349,6 +353,16 @@ void tst_qfxtext::font() QCOMPARE(textObject->font().italic(), false); } + { + QString componentStr = "import Qt 4.6\nText { font.pixelSize: 40; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->font().pixelSize(), 40); + QCOMPARE(textObject->font().bold(), false); + QCOMPARE(textObject->font().italic(), false); + } + { QString componentStr = "import Qt 4.6\nText { font.bold: true; text: \"Hello World\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); @@ -391,12 +405,12 @@ void tst_qfxtext::style() //test style for (int i = 0; i < styles.size(); i++) { - QString componentStr = "import Qt 4.6\nText { style: \"" + styleStrings.at(i) + "\"; text: \"Hello World\" }"; + QString componentStr = "import Qt 4.6\nText { style: \"" + styleStrings.at(i) + "\"; styleColor: \"white\"; text: \"Hello World\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QCOMPARE((int)textObject->style(), (int)styles.at(i)); - QCOMPARE(textObject->styleColor(), QColor()); + QCOMPARE(textObject->styleColor(), QColor("white")); } } @@ -448,6 +462,41 @@ void tst_qfxtext::color() QCOMPARE(textObject->color(), testColor); } } + +void tst_qfxtext::smooth() +{ + for (int i = 0; i < standard.size(); i++) + { + { + QString componentStr = "import Qt 4.6\nText { smooth: true; text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), true); + } + { + QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), false); + } + } + for (int i = 0; i < richText.size(); i++) + { + { + QString componentStr = "import Qt 4.6\nText { smooth: true; text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), true); + } + { + QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), false); + } + } +} + QTEST_MAIN(tst_qfxtext) #include "tst_qfxtext.moc" -- cgit v0.12 From 8dbea8ec48084b27c56f7d263c38c84ff03ebc3d Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Tue, 3 Nov 2009 17:08:45 +1000 Subject: qmlgraphicstext tests --- tests/auto/declarative/qfxtext/qfxtext.pro | 5 - tests/auto/declarative/qfxtext/tst_qfxtext.cpp | 502 --------------------- .../qmlgraphicstext/qmlgraphicstext.pro | 5 + .../qmlgraphicstext/tst_qmlgraphicstext.cpp | 500 ++++++++++++++++++++ 4 files changed, 505 insertions(+), 507 deletions(-) delete mode 100644 tests/auto/declarative/qfxtext/qfxtext.pro delete mode 100644 tests/auto/declarative/qfxtext/tst_qfxtext.cpp create mode 100644 tests/auto/declarative/qmlgraphicstext/qmlgraphicstext.pro create mode 100644 tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp diff --git a/tests/auto/declarative/qfxtext/qfxtext.pro b/tests/auto/declarative/qfxtext/qfxtext.pro deleted file mode 100644 index 1f3fe37..0000000 --- a/tests/auto/declarative/qfxtext/qfxtext.pro +++ /dev/null @@ -1,5 +0,0 @@ -load(qttest_p4) -contains(QT_CONFIG,declarative): QT += declarative gui -macx:CONFIG -= app_bundle - -SOURCES += tst_qfxtext.cpp diff --git a/tests/auto/declarative/qfxtext/tst_qfxtext.cpp b/tests/auto/declarative/qfxtext/tst_qfxtext.cpp deleted file mode 100644 index 49fc757..0000000 --- a/tests/auto/declarative/qfxtext/tst_qfxtext.cpp +++ /dev/null @@ -1,502 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include -#include -#include -#include -#include -#include - -class tst_qfxtext : public QObject - -{ - Q_OBJECT -public: - tst_qfxtext(); - -private slots: - void text(); - void width(); - void wrap(); - void elide(); - - // ### these tests may be trivial - void horizontalAlignment(); - void verticalAlignment(); - void font(); - void style(); - void color(); - void smooth(); - -private: - QStringList standard; - QStringList richText; - - QStringList horizontalAlignmentmentStrings; - QStringList verticalAlignmentmentStrings; - - QList verticalAlignmentments; - QList horizontalAlignmentments; - - QStringList styleStrings; - QList styles; - - QStringList colorStrings; - - QmlEngine engine; -}; - -tst_qfxtext::tst_qfxtext() -{ - standard << "the quick brown fox jumped over the lazy dog" - << "the quick brown fox\n jumped over the lazy dog"; - - richText << "the quick brown fox jumped over the lazy dog" - << "the quick brown fox
jumped over the lazy dog
"; - - horizontalAlignmentmentStrings << "AlignLeft" - << "AlignRight" - << "AlignHCenter"; - - verticalAlignmentmentStrings << "AlignTop" - << "AlignBottom" - << "AlignVCenter"; - - horizontalAlignmentments << Qt::AlignLeft - << Qt::AlignRight - << Qt::AlignHCenter; - - verticalAlignmentments << Qt::AlignTop - << Qt::AlignBottom - << Qt::AlignVCenter; - - styleStrings << "Normal" - << "Outline" - << "Raised" - << "Sunken"; - - styles << QmlGraphicsText::Normal - << QmlGraphicsText::Outline - << QmlGraphicsText::Raised - << QmlGraphicsText::Sunken; - - colorStrings << "aliceblue" - << "antiquewhite" - << "aqua" - << "darkkhaki" - << "darkolivegreen" - << "dimgray" - << "palevioletred" - << "lightsteelblue" - << "#000000" - << "#AAAAAA" - << "#FFFFFF" - << "#2AC05F"; - // - // need a different test to do alpha channel test - // << "#AA0011DD" - // << "#00F16B11"; - // -} - -void tst_qfxtext::text() -{ - { - QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"\" }", QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QVERIFY(textObject != 0); - QCOMPARE(textObject->text(), QString("")); - } - - for (int i = 0; i < standard.size(); i++) - { - QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QVERIFY(textObject != 0); - QCOMPARE(textObject->text(), standard.at(i)); - } - - for (int i = 0; i < richText.size(); i++) - { - QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QVERIFY(textObject != 0); - QString expected = richText.at(i); - QCOMPARE(textObject->text(), expected.replace("\\\"", "\"")); - } -} - -void tst_qfxtext::width() -{ - // uses Font metrics to find the width for standard and document to find the width for rich - { - QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"\" }", QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->width(), 0.); - } - - for (int i = 0; i < standard.size(); i++) - { - QFont f; - QFontMetrics fm(f); - int metricWidth = fm.size(Qt::TextExpandTabs && Qt::TextShowMnemonic, standard.at(i)).width(); - - QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->width(), qreal(metricWidth)); - } - - for (int i = 0; i < richText.size(); i++) - { - QTextDocument document; - document.setHtml(richText.at(i)); - document.setDocumentMargin(0); - - int documentWidth = document.idealWidth(); - - QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->width(), qreal(documentWidth)); - } -} - -void tst_qfxtext::wrap() -{ - // XXX Poor coverage - should at least be testing an expected height. - - int textHeight = 0; - // for specified width and wrap set true - { - QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"Hello\"; wrap: true; width: 300 }", QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - textHeight = textObject->height(); - - QCOMPARE(textObject->width(), 300.); - } - - for (int i = 0; i < standard.size(); i++) - { - QString componentStr = "import Qt 4.6\nText { wrap: true; width: 30; text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->width(), 30.); - QVERIFY(textObject->height() > textHeight); - } - - for (int i = 0; i < richText.size(); i++) - { - QString componentStr = "import Qt 4.6\nText { wrap: true; width: 30; text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->width(), 30.); - QVERIFY(textObject->height() > textHeight); - } - -} - -void tst_qfxtext::elide() -{ - for (Qt::TextElideMode m = Qt::ElideLeft; m<=Qt::ElideNone; m=Qt::TextElideMode(int(m)+1)) { - const char* elidename[]={"ElideLeft", "ElideRight", "ElideMiddle", "ElideNone"}; - QString elide = "elide: \""+QString(elidename[int(m)])+"\";"; - - // XXX Poor coverage. - - { - QmlComponent textComponent(&engine, ("import Qt 4.6\nText { text: \"\"; "+elide+" width: 300 }").toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->width(), 300.); - } - - for (int i = 0; i < standard.size(); i++) - { - QString componentStr = "import Qt 4.6\nText { "+elide+" width: 300; text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->width(), 300.); - } - - // richtext - does nothing - for (int i = 0; i < richText.size(); i++) - { - QString componentStr = "import Qt 4.6\nText { "+elide+" width: 300; text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->width(), 300.); - } - } -} - -//the alignment tests may be trivial o.oa -void tst_qfxtext::horizontalAlignment() -{ - //test one align each, and then test if two align fails. - - for (int i = 0; i < standard.size(); i++) - { - for (int j=0; j < horizontalAlignmentmentStrings.size(); j++) - { - QString componentStr = "import Qt 4.6\nText { horizontalAlignment: \"" + horizontalAlignmentmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE((int)textObject->hAlign(), (int)horizontalAlignmentments.at(j)); - } - } - - for (int i = 0; i < richText.size(); i++) - { - for (int j=0; j < horizontalAlignmentmentStrings.size(); j++) - { - QString componentStr = "import Qt 4.6\nText { horizontalAlignment: \"" + horizontalAlignmentmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE((int)textObject->hAlign(), (int)horizontalAlignmentments.at(j)); - } - } - -} - -void tst_qfxtext::verticalAlignment() -{ - //test one align each, and then test if two align fails. - - for (int i = 0; i < standard.size(); i++) - { - for (int j=0; j < verticalAlignmentmentStrings.size(); j++) - { - QString componentStr = "import Qt 4.6\nText { verticalAlignment: \"" + verticalAlignmentmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE((int)textObject->vAlign(), (int)verticalAlignmentments.at(j)); - } - } - - for (int i = 0; i < richText.size(); i++) - { - for (int j=0; j < verticalAlignmentmentStrings.size(); j++) - { - QString componentStr = "import Qt 4.6\nText { verticalAlignment: \"" + verticalAlignmentmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE((int)textObject->vAlign(), (int)verticalAlignmentments.at(j)); - } - } - -} - -void tst_qfxtext::font() -{ - //test size, then bold, then italic, then family - { - QString componentStr = "import Qt 4.6\nText { font.pointSize: 40; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->font().pointSize(), 40); - QCOMPARE(textObject->font().bold(), false); - QCOMPARE(textObject->font().italic(), false); - } - - { - QString componentStr = "import Qt 4.6\nText { font.pixelSize: 40; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->font().pixelSize(), 40); - QCOMPARE(textObject->font().bold(), false); - QCOMPARE(textObject->font().italic(), false); - } - - { - QString componentStr = "import Qt 4.6\nText { font.bold: true; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->font().bold(), true); - QCOMPARE(textObject->font().italic(), false); - } - - { - QString componentStr = "import Qt 4.6\nText { font.italic: true; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->font().italic(), true); - QCOMPARE(textObject->font().bold(), false); - } - - { - QString componentStr = "import Qt 4.6\nText { font.family: \"Helvetica\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->font().family(), QString("Helvetica")); - QCOMPARE(textObject->font().bold(), false); - QCOMPARE(textObject->font().italic(), false); - } - - { - QString componentStr = "import Qt 4.6\nText { font.family: \"\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->font().family(), QString("")); - } -} - -void tst_qfxtext::style() -{ - //test style - for (int i = 0; i < styles.size(); i++) - { - QString componentStr = "import Qt 4.6\nText { style: \"" + styleStrings.at(i) + "\"; styleColor: \"white\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE((int)textObject->style(), (int)styles.at(i)); - QCOMPARE(textObject->styleColor(), QColor("white")); - } -} - -void tst_qfxtext::color() -{ - //test style - for (int i = 0; i < colorStrings.size(); i++) - { - QString componentStr = "import Qt 4.6\nText { color: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->color(), QColor(colorStrings.at(i))); - QCOMPARE(textObject->styleColor(), QColor()); - } - - for (int i = 0; i < colorStrings.size(); i++) - { - QString componentStr = "import Qt 4.6\nText { styleColor: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->styleColor(), QColor(colorStrings.at(i))); - // default color to black? - QCOMPARE(textObject->color(), QColor("black")); - } - - for (int i = 0; i < colorStrings.size(); i++) - { - for (int j = 0; j < colorStrings.size(); j++) - { - QString componentStr = "import Qt 4.6\nText { color: \"" + colorStrings.at(i) + "\"; styleColor: \"" + colorStrings.at(j) + "\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->color(), QColor(colorStrings.at(i))); - QCOMPARE(textObject->styleColor(), QColor(colorStrings.at(j))); - } - } - { - QString colorStr = "#AA001234"; - QColor testColor("#001234"); - testColor.setAlpha(170); - - QString componentStr = "import Qt 4.6\nText { color: \"" + colorStr + "\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->color(), testColor); - } -} - -void tst_qfxtext::smooth() -{ - for (int i = 0; i < standard.size(); i++) - { - { - QString componentStr = "import Qt 4.6\nText { smooth: true; text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->smoothTransform(), true); - } - { - QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->smoothTransform(), false); - } - } - for (int i = 0; i < richText.size(); i++) - { - { - QString componentStr = "import Qt 4.6\nText { smooth: true; text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->smoothTransform(), true); - } - { - QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->smoothTransform(), false); - } - } -} - -QTEST_MAIN(tst_qfxtext) - -#include "tst_qfxtext.moc" diff --git a/tests/auto/declarative/qmlgraphicstext/qmlgraphicstext.pro b/tests/auto/declarative/qmlgraphicstext/qmlgraphicstext.pro new file mode 100644 index 0000000..1d8c59f --- /dev/null +++ b/tests/auto/declarative/qmlgraphicstext/qmlgraphicstext.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative gui +macx:CONFIG -= app_bundle + +SOURCES += tst_qmlgraphicstext.cpp diff --git a/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp b/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp new file mode 100644 index 0000000..d53de59 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp @@ -0,0 +1,500 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include +#include +#include + +class tst_qmlgraphicstext : public QObject + +{ + Q_OBJECT +public: + tst_qmlgraphicstext(); + +private slots: + void text(); + void width(); + void wrap(); + void elide(); + + // ### these tests may be trivial + void horizontalAlignment(); + void verticalAlignment(); + void font(); + void style(); + void color(); + void smooth(); + +private: + QStringList standard; + QStringList richText; + + QStringList horizontalAlignmentmentStrings; + QStringList verticalAlignmentmentStrings; + + QList verticalAlignmentments; + QList horizontalAlignmentments; + + QStringList styleStrings; + QList styles; + + QStringList colorStrings; + + QmlEngine engine; +}; + +tst_qmlgraphicstext::tst_qmlgraphicstext() +{ + standard << "the quick brown fox jumped over the lazy dog" + << "the quick brown fox\n jumped over the lazy dog"; + + richText << "the quick brown fox jumped over the lazy dog" + << "the quick brown fox
jumped over the lazy dog
"; + + horizontalAlignmentmentStrings << "AlignLeft" + << "AlignRight" + << "AlignHCenter"; + + verticalAlignmentmentStrings << "AlignTop" + << "AlignBottom" + << "AlignVCenter"; + + horizontalAlignmentments << Qt::AlignLeft + << Qt::AlignRight + << Qt::AlignHCenter; + + verticalAlignmentments << Qt::AlignTop + << Qt::AlignBottom + << Qt::AlignVCenter; + + styleStrings << "Normal" + << "Outline" + << "Raised" + << "Sunken"; + + styles << QmlGraphicsText::Normal + << QmlGraphicsText::Outline + << QmlGraphicsText::Raised + << QmlGraphicsText::Sunken; + + colorStrings << "aliceblue" + << "antiquewhite" + << "aqua" + << "darkkhaki" + << "darkolivegreen" + << "dimgray" + << "palevioletred" + << "lightsteelblue" + << "#000000" + << "#AAAAAA" + << "#FFFFFF" + << "#2AC05F"; + // + // need a different test to do alpha channel test + // << "#AA0011DD" + // << "#00F16B11"; + // +} + +void tst_qmlgraphicstext::text() +{ + { + QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"\" }", QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QVERIFY(textObject != 0); + QCOMPARE(textObject->text(), QString("")); + } + + for (int i = 0; i < standard.size(); i++) + { + QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QVERIFY(textObject != 0); + QCOMPARE(textObject->text(), standard.at(i)); + } + + for (int i = 0; i < richText.size(); i++) + { + QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QVERIFY(textObject != 0); + QString expected = richText.at(i); + QCOMPARE(textObject->text(), expected.replace("\\\"", "\"")); + } +} + +void tst_qmlgraphicstext::width() +{ + // uses Font metrics to find the width for standard and document to find the width for rich + { + QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"\" }", QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->width(), 0.); + } + + for (int i = 0; i < standard.size(); i++) + { + QFont f; + QFontMetrics fm(f); + int metricWidth = fm.size(Qt::TextExpandTabs && Qt::TextShowMnemonic, standard.at(i)).width(); + + QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->width(), qreal(metricWidth)); + } + + for (int i = 0; i < richText.size(); i++) + { + QTextDocument document; + document.setHtml(richText.at(i)); + document.setDocumentMargin(0); + + int documentWidth = document.idealWidth(); + + QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->width(), qreal(documentWidth)); + } +} + +void tst_qmlgraphicstext::wrap() +{ + int textHeight = 0; + // for specified width and wrap set true + { + QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"Hello\"; wrap: true; width: 300 }", QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + textHeight = textObject->height(); + + QCOMPARE(textObject->width(), 300.); + } + + for (int i = 0; i < standard.size(); i++) + { + QString componentStr = "import Qt 4.6\nText { wrap: true; width: 30; text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->width(), 30.); + QVERIFY(textObject->height() > textHeight); + } + + for (int i = 0; i < richText.size(); i++) + { + QString componentStr = "import Qt 4.6\nText { wrap: true; width: 30; text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->width(), 30.); + QVERIFY(textObject->height() > textHeight); + } + +} + +void tst_qmlgraphicstext::elide() +{ + for (Qt::TextElideMode m = Qt::ElideLeft; m<=Qt::ElideNone; m=Qt::TextElideMode(int(m)+1)) { + const char* elidename[]={"ElideLeft", "ElideRight", "ElideMiddle", "ElideNone"}; + QString elide = "elide: \""+QString(elidename[int(m)])+"\";"; + + // XXX Poor coverage. + + { + QmlComponent textComponent(&engine, ("import Qt 4.6\nText { text: \"\"; "+elide+" width: 300 }").toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->width(), 300.); + } + + for (int i = 0; i < standard.size(); i++) + { + QString componentStr = "import Qt 4.6\nText { "+elide+" width: 300; text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->width(), 300.); + } + + // richtext - does nothing + for (int i = 0; i < richText.size(); i++) + { + QString componentStr = "import Qt 4.6\nText { "+elide+" width: 300; text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->width(), 300.); + } + } +} + +//the alignment tests may be trivial o.oa +void tst_qmlgraphicstext::horizontalAlignment() +{ + //test one align each, and then test if two align fails. + + for (int i = 0; i < standard.size(); i++) + { + for (int j=0; j < horizontalAlignmentmentStrings.size(); j++) + { + QString componentStr = "import Qt 4.6\nText { horizontalAlignment: \"" + horizontalAlignmentmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE((int)textObject->hAlign(), (int)horizontalAlignmentments.at(j)); + } + } + + for (int i = 0; i < richText.size(); i++) + { + for (int j=0; j < horizontalAlignmentmentStrings.size(); j++) + { + QString componentStr = "import Qt 4.6\nText { horizontalAlignment: \"" + horizontalAlignmentmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE((int)textObject->hAlign(), (int)horizontalAlignmentments.at(j)); + } + } + +} + +void tst_qmlgraphicstext::verticalAlignment() +{ + //test one align each, and then test if two align fails. + + for (int i = 0; i < standard.size(); i++) + { + for (int j=0; j < verticalAlignmentmentStrings.size(); j++) + { + QString componentStr = "import Qt 4.6\nText { verticalAlignment: \"" + verticalAlignmentmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QCOMPARE((int)textObject->vAlign(), (int)verticalAlignmentments.at(j)); + } + } + + for (int i = 0; i < richText.size(); i++) + { + for (int j=0; j < verticalAlignmentmentStrings.size(); j++) + { + QString componentStr = "import Qt 4.6\nText { verticalAlignment: \"" + verticalAlignmentmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE((int)textObject->vAlign(), (int)verticalAlignmentments.at(j)); + } + } + +} + +void tst_qmlgraphicstext::font() +{ + //test size, then bold, then italic, then family + { + QString componentStr = "import Qt 4.6\nText { font.pointSize: 40; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->font().pointSize(), 40); + QCOMPARE(textObject->font().bold(), false); + QCOMPARE(textObject->font().italic(), false); + } + + { + QString componentStr = "import Qt 4.6\nText { font.pixelSize: 40; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->font().pixelSize(), 40); + QCOMPARE(textObject->font().bold(), false); + QCOMPARE(textObject->font().italic(), false); + } + + { + QString componentStr = "import Qt 4.6\nText { font.bold: true; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->font().bold(), true); + QCOMPARE(textObject->font().italic(), false); + } + + { + QString componentStr = "import Qt 4.6\nText { font.italic: true; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->font().italic(), true); + QCOMPARE(textObject->font().bold(), false); + } + + { + QString componentStr = "import Qt 4.6\nText { font.family: \"Helvetica\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->font().family(), QString("Helvetica")); + QCOMPARE(textObject->font().bold(), false); + QCOMPARE(textObject->font().italic(), false); + } + + { + QString componentStr = "import Qt 4.6\nText { font.family: \"\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->font().family(), QString("")); + } +} + +void tst_qmlgraphicstext::style() +{ + //test style + for (int i = 0; i < styles.size(); i++) + { + QString componentStr = "import Qt 4.6\nText { style: \"" + styleStrings.at(i) + "\"; styleColor: \"white\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE((int)textObject->style(), (int)styles.at(i)); + QCOMPARE(textObject->styleColor(), QColor("white")); + } +} + +void tst_qmlgraphicstext::color() +{ + //test style + for (int i = 0; i < colorStrings.size(); i++) + { + QString componentStr = "import Qt 4.6\nText { color: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->color(), QColor(colorStrings.at(i))); + QCOMPARE(textObject->styleColor(), QColor()); + } + + for (int i = 0; i < colorStrings.size(); i++) + { + QString componentStr = "import Qt 4.6\nText { styleColor: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->styleColor(), QColor(colorStrings.at(i))); + // default color to black? + QCOMPARE(textObject->color(), QColor("black")); + } + + for (int i = 0; i < colorStrings.size(); i++) + { + for (int j = 0; j < colorStrings.size(); j++) + { + QString componentStr = "import Qt 4.6\nText { color: \"" + colorStrings.at(i) + "\"; styleColor: \"" + colorStrings.at(j) + "\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->color(), QColor(colorStrings.at(i))); + QCOMPARE(textObject->styleColor(), QColor(colorStrings.at(j))); + } + } + { + QString colorStr = "#AA001234"; + QColor testColor("#001234"); + testColor.setAlpha(170); + + QString componentStr = "import Qt 4.6\nText { color: \"" + colorStr + "\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->color(), testColor); + } +} + +void tst_qmlgraphicstext::smooth() +{ + for (int i = 0; i < standard.size(); i++) + { + { + QString componentStr = "import Qt 4.6\nText { smooth: true; text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), true); + } + { + QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), false); + } + } + for (int i = 0; i < richText.size(); i++) + { + { + QString componentStr = "import Qt 4.6\nText { smooth: true; text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), true); + } + { + QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), false); + } + } +} + +QTEST_MAIN(tst_qmlgraphicstext) + +#include "tst_qmlgraphicstext.moc" -- cgit v0.12 From 3550d1b22b3a5f8f974ca2ba17a3d4f5d52b3743 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Tue, 3 Nov 2009 17:50:26 +1000 Subject: QmlFontLoader tests --- .../declarative/qmlfontloader/data/Fontin-Bold.ttf | Bin 0 -> 30916 bytes .../declarative/qmlfontloader/qmlfontloader.pro | 5 ++ .../qmlfontloader/tst_qmlfontloader.cpp | 89 +++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 tests/auto/declarative/qmlfontloader/data/Fontin-Bold.ttf create mode 100644 tests/auto/declarative/qmlfontloader/qmlfontloader.pro create mode 100644 tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp diff --git a/tests/auto/declarative/qmlfontloader/data/Fontin-Bold.ttf b/tests/auto/declarative/qmlfontloader/data/Fontin-Bold.ttf new file mode 100644 index 0000000..f6a33b0 Binary files /dev/null and b/tests/auto/declarative/qmlfontloader/data/Fontin-Bold.ttf differ diff --git a/tests/auto/declarative/qmlfontloader/qmlfontloader.pro b/tests/auto/declarative/qmlfontloader/qmlfontloader.pro new file mode 100644 index 0000000..0ecfde0 --- /dev/null +++ b/tests/auto/declarative/qmlfontloader/qmlfontloader.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative gui +macx:CONFIG -= app_bundle + +SOURCES += tst_qmlfontloader.cpp diff --git a/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp b/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp new file mode 100644 index 0000000..a65ecf4 --- /dev/null +++ b/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include + +class tst_qmlfontloader : public QObject + +{ + Q_OBJECT +public: + tst_qmlfontloader(); + +private slots: + void namedfont(); + void localfont(); + +private slots: + +private: + QmlEngine engine; +}; + +tst_qmlfontloader::tst_qmlfontloader() +{ +} + +void tst_qmlfontloader::namedfont() +{ + QString componentStr = "import Qt 4.6\nFontLoader { name: \"Helvetica\" }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlFontLoader *fontObject = qobject_cast(component.create()); + + QVERIFY(fontObject != 0); + QCOMPARE(fontObject->name(), QString("Helvetica")); +} + +void tst_qmlfontloader::localfont() +{ + QString componentStr = "import Qt 4.6\nFontLoader { source: \"data/Fontin-Bold.ttf\" }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlFontLoader *fontObject = qobject_cast(component.create()); + + QVERIFY(fontObject != 0); + QCOMPARE(fontObject->name(), QString("Fontin")); +} + +QTEST_MAIN(tst_qmlfontloader) + +#include "tst_qmlfontloader.moc" -- cgit v0.12 From 0cda0d00f95cbcd292f4b1f5ed4a47d43e0ac825 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 3 Nov 2009 18:29:34 +1000 Subject: QmlMetaType test --- tests/auto/declarative/declarative.pro | 1 + tests/auto/declarative/qmlmetatype/qmlmetatype.pro | 6 + .../declarative/qmlmetatype/tst_qmlmetatype.cpp | 220 +++++++++++++++++++++ 3 files changed, 227 insertions(+) create mode 100644 tests/auto/declarative/qmlmetatype/qmlmetatype.pro create mode 100644 tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 0d55391..26e8346 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -23,6 +23,7 @@ SUBDIRS += anchors \ qmllist \ qmllistaccessor \ qmlmetaproperty \ + qmlmetatype \ qmlpropertymap \ qmltimer \ repeater \ diff --git a/tests/auto/declarative/qmlmetatype/qmlmetatype.pro b/tests/auto/declarative/qmlmetatype/qmlmetatype.pro new file mode 100644 index 0000000..3a9a400 --- /dev/null +++ b/tests/auto/declarative/qmlmetatype/qmlmetatype.pro @@ -0,0 +1,6 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +SOURCES += tst_qmlmetatype.cpp +macx:CONFIG -= app_bundle + +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp b/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp new file mode 100644 index 0000000..06a47c0 --- /dev/null +++ b/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp @@ -0,0 +1,220 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class tst_qmlmetatype : public QObject +{ + Q_OBJECT +public: + tst_qmlmetatype() {} + +private slots: + void copy(); +}; + +#define COPY_TEST(cpptype, metatype, value, defaultvalue) \ +{ \ + cpptype v = (value); cpptype v2 = (value); \ + QVERIFY(QmlMetaType::copy(QMetaType:: metatype, &v, 0)); \ + QVERIFY(v == (defaultvalue)); \ + QVERIFY(QmlMetaType::copy(QMetaType:: metatype, &v, &v2)); \ + QVERIFY(v == (value)); \ +} + +#define QT_COPY_TEST(type, value) \ +{ \ + type v = (value); type v2 = (value); \ + QVERIFY(QmlMetaType::copy(QMetaType:: type, &v, 0)); \ + QVERIFY(v == (type ())); \ + QVERIFY(QmlMetaType::copy(QMetaType:: type, &v, &v2)); \ + QVERIFY(v == (value)); \ +} + +void tst_qmlmetatype::copy() +{ + QVERIFY(QmlMetaType::copy(QMetaType::Void, 0, 0)); + + COPY_TEST(bool, Bool, true, false); + COPY_TEST(int, Int, 10, 0); + COPY_TEST(unsigned int, UInt, 10, 0); + COPY_TEST(long long, LongLong, 10, 0); + COPY_TEST(unsigned long long, ULongLong, 10, 0); + COPY_TEST(double, Double, 19.2, 0); + + QT_COPY_TEST(QChar, QChar('a')); + + QVariantMap variantMap; + variantMap.insert("Hello World!", QVariant(10)); + QT_COPY_TEST(QVariantMap, variantMap); + + QT_COPY_TEST(QVariantList, QVariantList() << QVariant(19.2)); + QT_COPY_TEST(QString, QString("QML Rocks!")); + QT_COPY_TEST(QStringList, QStringList() << "QML" << "Rocks"); + QT_COPY_TEST(QByteArray, QByteArray("0x1102DDD")); + QT_COPY_TEST(QBitArray, QBitArray(102, true)); + QT_COPY_TEST(QDate, QDate::currentDate()); + QT_COPY_TEST(QTime, QTime::currentTime()); + QT_COPY_TEST(QDateTime, QDateTime::currentDateTime()); + QT_COPY_TEST(QUrl, QUrl("http://www.nokia.com")); + QT_COPY_TEST(QLocale, QLocale(QLocale::English, QLocale::Australia)); + QT_COPY_TEST(QRect, QRect(-10, 10, 102, 99)); + QT_COPY_TEST(QRectF, QRectF(-10.2, 1.2, 102, 99.6)); + QT_COPY_TEST(QSize, QSize(100, 2)); + QT_COPY_TEST(QSizeF, QSizeF(20.2, -100234.2)); + QT_COPY_TEST(QLine, QLine(0, 0, 100, 100)); + QT_COPY_TEST(QLineF, QLineF(-10.2, 0, 103, 1)); + QT_COPY_TEST(QPoint, QPoint(-1912, 1613)); + QT_COPY_TEST(QPointF, QPointF(-908.1, 1612)); + QT_COPY_TEST(QRegExp, QRegExp("(\\d+)(?:\\s*)(cm|inch)")); + + QVariantHash variantHash; + variantHash.insert("Hello World!", QVariant(19)); + QT_COPY_TEST(QVariantHash, variantHash); + +#ifdef QT3_SUPPORT + QT_COPY_TEST(QColorGroup, QColorGroup(Qt::red, Qt::red, Qt::red, Qt::red, Qt::red, Qt::red, Qt::red)); +#endif + + QT_COPY_TEST(QFont, QFont("Helvetica", 1024)); + + { + QPixmap v = QPixmap(100, 100); QPixmap v2 = QPixmap(100, 100); + QVERIFY(QmlMetaType::copy(QMetaType::QPixmap, &v, 0)); + QVERIFY(v.size() == QPixmap().size()); + QVERIFY(QmlMetaType::copy(QMetaType::QPixmap , &v, &v2)); + QVERIFY(v.size() == QPixmap(100,100).size()); + } + + QT_COPY_TEST(QBrush, QBrush(Qt::blue)); + QT_COPY_TEST(QColor, QColor("lightsteelblue")); + QT_COPY_TEST(QPalette, QPalette(Qt::green)); + + { + QPixmap icon(100, 100); + + QIcon v = QIcon(icon); QIcon v2 = QIcon(icon); + QVERIFY(QmlMetaType::copy(QMetaType::QIcon, &v, 0)); + QVERIFY(v.isNull() == QIcon().isNull()); + QVERIFY(QmlMetaType::copy(QMetaType::QIcon , &v, &v2)); + QVERIFY(v.isNull() == QIcon(icon).isNull()); + } + + { + QImage v = QImage(100, 100, QImage::Format_RGB32); + QImage v2 = QImage(100, 100, QImage::Format_RGB32); + QVERIFY(QmlMetaType::copy(QMetaType::QImage, &v, 0)); + QVERIFY(v.size() == QImage().size()); + QVERIFY(QmlMetaType::copy(QMetaType::QImage , &v, &v2)); + QVERIFY(v.size() == QImage(100,100, QImage::Format_RGB32).size()); + } + + QT_COPY_TEST(QPolygon, QPolygon(QRect(100, 100, 200, 103))); + QT_COPY_TEST(QRegion, QRegion(QRect(0, 10, 99, 87))); + + { + QBitmap v = QBitmap(100, 100); QBitmap v2 = QBitmap(100, 100); + QVERIFY(QmlMetaType::copy(QMetaType::QBitmap, &v, 0)); + QVERIFY(v.size() == QBitmap().size()); + QVERIFY(QmlMetaType::copy(QMetaType::QBitmap , &v, &v2)); + QVERIFY(v.size() == QBitmap(100,100).size()); + } + + { + QCursor v = QCursor(Qt::SizeFDiagCursor); QCursor v2 = QCursor(Qt::SizeFDiagCursor); + QVERIFY(QmlMetaType::copy(QMetaType::QCursor, &v, 0)); + QVERIFY(v.shape() == QCursor().shape()); + QVERIFY(QmlMetaType::copy(QMetaType::QCursor , &v, &v2)); + QVERIFY(v.shape() == QCursor(Qt::SizeFDiagCursor).shape()); + } + + QT_COPY_TEST(QSizePolicy, QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Maximum)); + QT_COPY_TEST(QKeySequence, QKeySequence("Ctrl+O")); + QT_COPY_TEST(QPen, QPen(Qt::red)); + QT_COPY_TEST(QTextLength, QTextLength(QTextLength::FixedLength, 10.2)); + QT_COPY_TEST(QMatrix, QMatrix().translate(10, 10)); + QT_COPY_TEST(QTransform, QTransform().translate(10, 10)); + QT_COPY_TEST(QMatrix4x4, QMatrix4x4().translate(10, 10)); + QT_COPY_TEST(QVector2D, QVector2D(10.2, 1)); + QT_COPY_TEST(QVector3D, QVector3D(10.2, 1, -2)); + QT_COPY_TEST(QVector4D, QVector4D(10.2, 1, -2, 1.2)); + QT_COPY_TEST(QQuaternion, QQuaternion(1.0, 10.2, 1, -2)); + + int voidValue; + COPY_TEST(void *, VoidStar, (void *)&voidValue, (void *)0); + COPY_TEST(long, Long, 10, 0); + COPY_TEST(short, Short, 10, 0); + COPY_TEST(char, Char, 'a', 0); + COPY_TEST(unsigned long, ULong, 10, 0); + COPY_TEST(unsigned short, UShort, 10, 0); + COPY_TEST(unsigned char, UChar, 'a', 0); + COPY_TEST(float, Float, 10.5, 0); + + QObject objectValue; + QWidget widgetValue; + COPY_TEST(QObject *, QObjectStar, &objectValue, 0); + COPY_TEST(QWidget *, QWidgetStar, &widgetValue, 0); + COPY_TEST(qreal, QReal, 10.2, 0); + + +#if 0 + enum Type { + + QReal = 0, + User = 256 + }; +#endif +} + +QTEST_MAIN(tst_qmlmetatype) + +#include "tst_qmlmetatype.moc" -- cgit v0.12 From feeb75edbbe0912f1719cf405be5927da6890d47 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Tue, 3 Nov 2009 18:32:14 +1000 Subject: autotests --- .../qmlfontloader/tst_qmlfontloader.cpp | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp b/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp index a65ecf4..464ae5d 100644 --- a/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp +++ b/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp @@ -42,6 +42,7 @@ #include #include #include +#include "../../../shared/util.h" class tst_qmlfontloader : public QObject @@ -51,8 +52,10 @@ public: tst_qmlfontloader(); private slots: + void nofont(); void namedfont(); void localfont(); + void webfont(); private slots: @@ -64,6 +67,16 @@ tst_qmlfontloader::tst_qmlfontloader() { } +void tst_qmlfontloader::nofont() +{ + QString componentStr = "import Qt 4.6\nFontLoader { }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlFontLoader *fontObject = qobject_cast(component.create()); + + QVERIFY(fontObject != 0); + QCOMPARE(fontObject->name(), QString("")); +} + void tst_qmlfontloader::namedfont() { QString componentStr = "import Qt 4.6\nFontLoader { name: \"Helvetica\" }"; @@ -84,6 +97,16 @@ void tst_qmlfontloader::localfont() QCOMPARE(fontObject->name(), QString("Fontin")); } +void tst_qmlfontloader::webfont() +{ + QString componentStr = "import Qt 4.6\nFontLoader { source: \"http://www.princexml.com/fonts/steffmann/Starburst.ttf\" }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlFontLoader *fontObject = qobject_cast(component.create()); + + QVERIFY(fontObject != 0); + QTRY_COMPARE(fontObject->name(), QString("Starburst")); +} + QTEST_MAIN(tst_qmlfontloader) #include "tst_qmlfontloader.moc" -- cgit v0.12 From d5c34887e0a563511ff124b497e5e869a64cda34 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 3 Nov 2009 19:14:58 +1000 Subject: Fix incorrect assert QT-2432 --- src/declarative/qml/qmlcompiler.cpp | 2 +- tests/auto/declarative/qmllanguage/data/crash2.qml | 5 +++++ tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qmllanguage/data/crash2.qml diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index b93a9b3..3253e72 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -2366,7 +2366,7 @@ bool QmlCompiler::buildBinding(QmlParser::Value *value, QmlParser::Property *prop, const BindingContext &ctxt) { - Q_ASSERT(prop->index); + Q_ASSERT(prop->index != -1); Q_ASSERT(prop->parent); Q_ASSERT(prop->parent->metaObject()); diff --git a/tests/auto/declarative/qmllanguage/data/crash2.qml b/tests/auto/declarative/qmllanguage/data/crash2.qml new file mode 100644 index 0000000..ae6f650 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/crash2.qml @@ -0,0 +1,5 @@ +import Qt 4.6 + +Object { + objectName: "Hello" + "World" +} diff --git a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp index 128fa87..da586d9 100644 --- a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp +++ b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp @@ -123,6 +123,7 @@ private slots: // regression tests for crashes void crash1(); + void crash2(); private: QmlEngine engine; @@ -1152,6 +1153,11 @@ void tst_qmllanguage::crash1() QmlComponent component(&engine, "Component {}"); } +void tst_qmllanguage::crash2() +{ + QmlComponent component(&engine, TEST_FILE("crash2.qml")); +} + QTEST_MAIN(tst_qmllanguage) #include "tst_qmllanguage.moc" -- cgit v0.12 From 337263994aafa64fd96d503d49a8a3316bdb1827 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 3 Nov 2009 19:16:18 +1000 Subject: Remove dead code --- tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp b/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp index 06a47c0..ed102a5 100644 --- a/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp +++ b/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp @@ -204,15 +204,6 @@ void tst_qmlmetatype::copy() COPY_TEST(QObject *, QObjectStar, &objectValue, 0); COPY_TEST(QWidget *, QWidgetStar, &widgetValue, 0); COPY_TEST(qreal, QReal, 10.2, 0); - - -#if 0 - enum Type { - - QReal = 0, - User = 256 - }; -#endif } QTEST_MAIN(tst_qmlmetatype) -- cgit v0.12 From a36694346164f0865e16003745839279dad7f61e Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 3 Nov 2009 19:16:37 +1000 Subject: qfxtext -> qmlgraphicstext --- tests/auto/declarative/declarative.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 26e8346..73269e1 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -11,7 +11,6 @@ SUBDIRS += anchors \ pathview \ qfxloader \ qfxpixmapcache \ - qfxtext \ qfxtextedit \ qfxtextinput \ qfxwebview \ @@ -19,6 +18,7 @@ SUBDIRS += anchors \ qmlcontext \ qmldom \ qmlecmascript \ + qmlgraphicstext \ qmllanguage \ qmllist \ qmllistaccessor \ -- cgit v0.12 From d6d473534fdb08a417cc113368742c0ec011a97e Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Tue, 3 Nov 2009 22:14:36 +1000 Subject: more qmlfontloader tests --- src/declarative/extra/qmlfontloader.cpp | 2 ++ .../auto/declarative/qmlfontloader/data/dummy.ttf | 0 .../declarative/qmlfontloader/qmlfontloader.pro | 3 ++ .../qmlfontloader/tst_qmlfontloader.cpp | 32 ++++++++++++++++++++-- 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 tests/auto/declarative/qmlfontloader/data/dummy.ttf diff --git a/src/declarative/extra/qmlfontloader.cpp b/src/declarative/extra/qmlfontloader.cpp index 8c17d0f..e8db649 100644 --- a/src/declarative/extra/qmlfontloader.cpp +++ b/src/declarative/extra/qmlfontloader.cpp @@ -163,6 +163,8 @@ void QmlFontLoader::setName(const QString &name) return; d->name = name; emit nameChanged(); + d->status = Ready; + emit statusChanged(); } /*! diff --git a/tests/auto/declarative/qmlfontloader/data/dummy.ttf b/tests/auto/declarative/qmlfontloader/data/dummy.ttf new file mode 100644 index 0000000..e69de29 diff --git a/tests/auto/declarative/qmlfontloader/qmlfontloader.pro b/tests/auto/declarative/qmlfontloader/qmlfontloader.pro index 0ecfde0..bc89639 100644 --- a/tests/auto/declarative/qmlfontloader/qmlfontloader.pro +++ b/tests/auto/declarative/qmlfontloader/qmlfontloader.pro @@ -3,3 +3,6 @@ contains(QT_CONFIG,declarative): QT += declarative gui macx:CONFIG -= app_bundle SOURCES += tst_qmlfontloader.cpp + +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp b/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp index 464ae5d..4bbc595 100644 --- a/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp +++ b/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp @@ -55,7 +55,9 @@ private slots: void nofont(); void namedfont(); void localfont(); + void faillocalfont(); void webfont(); + void failwebfont(); private slots: @@ -75,6 +77,7 @@ void tst_qmlfontloader::nofont() QVERIFY(fontObject != 0); QCOMPARE(fontObject->name(), QString("")); + QTRY_VERIFY(fontObject->status() == QmlFontLoader::Null); } void tst_qmlfontloader::namedfont() @@ -85,16 +88,29 @@ void tst_qmlfontloader::namedfont() QVERIFY(fontObject != 0); QCOMPARE(fontObject->name(), QString("Helvetica")); + QTRY_VERIFY(fontObject->status() == QmlFontLoader::Ready); } void tst_qmlfontloader::localfont() { - QString componentStr = "import Qt 4.6\nFontLoader { source: \"data/Fontin-Bold.ttf\" }"; + QString componentStr = "import Qt 4.6\nFontLoader { source: \"" SRCDIR "/data/Fontin-Bold.ttf\" }"; QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); QmlFontLoader *fontObject = qobject_cast(component.create()); QVERIFY(fontObject != 0); - QCOMPARE(fontObject->name(), QString("Fontin")); + QTRY_COMPARE(fontObject->name(), QString("Fontin")); + QTRY_VERIFY(fontObject->status() == QmlFontLoader::Ready); +} + +void tst_qmlfontloader::faillocalfont() +{ + QString componentStr = "import Qt 4.6\nFontLoader { source: \"" SRCDIR "/data/dummy.ttf\" }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlFontLoader *fontObject = qobject_cast(component.create()); + + QVERIFY(fontObject != 0); + QTRY_COMPARE(fontObject->name(), QString("")); + QTRY_VERIFY(fontObject->status() == QmlFontLoader::Error); } void tst_qmlfontloader::webfont() @@ -105,6 +121,18 @@ void tst_qmlfontloader::webfont() QVERIFY(fontObject != 0); QTRY_COMPARE(fontObject->name(), QString("Starburst")); + QTRY_VERIFY(fontObject->status() == QmlFontLoader::Ready); +} + +void tst_qmlfontloader::failwebfont() +{ + QString componentStr = "import Qt 4.6\nFontLoader { source: \"http://wrong.address.com/Starburst.ttf\" }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlFontLoader *fontObject = qobject_cast(component.create()); + + QVERIFY(fontObject != 0); + QTRY_COMPARE(fontObject->name(), QString("")); + QTRY_VERIFY(fontObject->status() == QmlFontLoader::Error); } QTEST_MAIN(tst_qmlfontloader) -- cgit v0.12 From d1a1d5df2ec9e34cdbed340685fc8e8dd8e9bece Mon Sep 17 00:00:00 2001 From: hjk Date: Mon, 26 Oct 2009 12:40:33 +0100 Subject: introduce int QTextDocument::available{Undo,Redo}Steps() const; Formerly, QTextDocument::revision() could be used to guesstimate the number of available undo steps that was used in Qt Creator to store cursor positions in parallel to the actual text contents. Now that revision() is strictly increasing, another means is needed, therefore the new functions providing the needed data. Reviewed-by: mae --- src/gui/text/qtextdocument.cpp | 27 +++++++++++++++++++++++++++ src/gui/text/qtextdocument.h | 3 +++ src/gui/text/qtextdocument_p.h | 3 +++ 3 files changed, 33 insertions(+) diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index 6978b6c..1aad385 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -958,6 +958,8 @@ QString QTextDocument::defaultStyleSheet() const /*! Returns true if undo is available; otherwise returns false. + + \sa isRedoAvailable(), availableUndoSteps() */ bool QTextDocument::isUndoAvailable() const { @@ -967,6 +969,8 @@ bool QTextDocument::isUndoAvailable() const /*! Returns true if redo is available; otherwise returns false. + + \sa isUndoAvailable(), availableRedoSteps() */ bool QTextDocument::isRedoAvailable() const { @@ -974,6 +978,29 @@ bool QTextDocument::isRedoAvailable() const return d->isRedoAvailable(); } +/*! \since 4.6 + + Returns the number of available undo steps. + + \sa isUndoAvailable() +*/ +int QTextDocument::availableUndoSteps() const +{ + Q_D(const QTextDocument); + return d->availableUndoSteps(); +} + +/*! \since 4.6 + + Returns the number of available redo steps. + + \sa isRedoAvailable() +*/ +int QTextDocument::availableRedoSteps() const +{ + Q_D(const QTextDocument); + return d->availableRedoSteps(); +} /*! \since 4.4 diff --git a/src/gui/text/qtextdocument.h b/src/gui/text/qtextdocument.h index e52716a..d217a4d 100644 --- a/src/gui/text/qtextdocument.h +++ b/src/gui/text/qtextdocument.h @@ -142,6 +142,9 @@ public: bool isUndoAvailable() const; bool isRedoAvailable() const; + int availableUndoSteps() const; + int availableRedoSteps() const; + int revision() const; void setDocumentLayout(QAbstractTextDocumentLayout *layout); diff --git a/src/gui/text/qtextdocument_p.h b/src/gui/text/qtextdocument_p.h index ce25c57..c10855b 100644 --- a/src/gui/text/qtextdocument_p.h +++ b/src/gui/text/qtextdocument_p.h @@ -212,6 +212,9 @@ public: inline bool isUndoAvailable() const { return undoEnabled && undoState > 0; } inline bool isRedoAvailable() const { return undoEnabled && undoState < undoStack.size(); } + inline int availableUndoSteps() const { return undoEnabled ? undoState : 0; } + inline int availableRedoSteps() const { return undoEnabled ? qMax(undoStack.size() - undoState - 1, 0) : 0; } + inline QString buffer() const { return text; } QString plainText() const; inline int length() const { return fragments.length(); } -- cgit v0.12 From 356fe6a0474c07dc6dd8ffd9b52f1e2060e3a450 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 4 Nov 2009 08:28:17 +1000 Subject: Add missing files. --- tests/auto/declarative/animatedimage/data/stickman.qml | 5 +++++ tests/auto/declarative/animatedimage/data/stickmanpause.qml | 7 +++++++ 2 files changed, 12 insertions(+) create mode 100644 tests/auto/declarative/animatedimage/data/stickman.qml create mode 100644 tests/auto/declarative/animatedimage/data/stickmanpause.qml diff --git a/tests/auto/declarative/animatedimage/data/stickman.qml b/tests/auto/declarative/animatedimage/data/stickman.qml new file mode 100644 index 0000000..a70db5d --- /dev/null +++ b/tests/auto/declarative/animatedimage/data/stickman.qml @@ -0,0 +1,5 @@ +import Qt 4.6 + +AnimatedImage { + source: "stickman.gif" +} diff --git a/tests/auto/declarative/animatedimage/data/stickmanpause.qml b/tests/auto/declarative/animatedimage/data/stickmanpause.qml new file mode 100644 index 0000000..7ab17d4 --- /dev/null +++ b/tests/auto/declarative/animatedimage/data/stickmanpause.qml @@ -0,0 +1,7 @@ +import Qt 4.6 + +AnimatedImage { + source: "stickman.gif" + paused: true + currentFrame: 2 +} -- cgit v0.12 From 7ca289fbbef4e8337124ce9e086b2c5b517ecbaa Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 4 Nov 2009 09:12:19 +1000 Subject: tests fixes --- .../qmlfontloader/tst_qmlfontloader.cpp | 26 ++++++------ .../qmlgraphicstext/tst_qmlgraphicstext.cpp | 47 ++++++++++++++++++---- 2 files changed, 54 insertions(+), 19 deletions(-) diff --git a/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp b/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp index 4bbc595..efc86cd 100644 --- a/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp +++ b/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp @@ -52,12 +52,12 @@ public: tst_qmlfontloader(); private slots: - void nofont(); - void namedfont(); - void localfont(); - void faillocalfont(); - void webfont(); - void failwebfont(); + void noFont(); + void namedFont(); + void localFont(); + void failLocalFont(); + void webFont(); + void failWebFont(); private slots: @@ -69,7 +69,7 @@ tst_qmlfontloader::tst_qmlfontloader() { } -void tst_qmlfontloader::nofont() +void tst_qmlfontloader::noFont() { QString componentStr = "import Qt 4.6\nFontLoader { }"; QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); @@ -78,9 +78,11 @@ void tst_qmlfontloader::nofont() QVERIFY(fontObject != 0); QCOMPARE(fontObject->name(), QString("")); QTRY_VERIFY(fontObject->status() == QmlFontLoader::Null); + + delete fontObject; } -void tst_qmlfontloader::namedfont() +void tst_qmlfontloader::namedFont() { QString componentStr = "import Qt 4.6\nFontLoader { name: \"Helvetica\" }"; QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); @@ -91,7 +93,7 @@ void tst_qmlfontloader::namedfont() QTRY_VERIFY(fontObject->status() == QmlFontLoader::Ready); } -void tst_qmlfontloader::localfont() +void tst_qmlfontloader::localFont() { QString componentStr = "import Qt 4.6\nFontLoader { source: \"" SRCDIR "/data/Fontin-Bold.ttf\" }"; QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); @@ -102,7 +104,7 @@ void tst_qmlfontloader::localfont() QTRY_VERIFY(fontObject->status() == QmlFontLoader::Ready); } -void tst_qmlfontloader::faillocalfont() +void tst_qmlfontloader::failLocalFont() { QString componentStr = "import Qt 4.6\nFontLoader { source: \"" SRCDIR "/data/dummy.ttf\" }"; QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); @@ -113,7 +115,7 @@ void tst_qmlfontloader::faillocalfont() QTRY_VERIFY(fontObject->status() == QmlFontLoader::Error); } -void tst_qmlfontloader::webfont() +void tst_qmlfontloader::webFont() { QString componentStr = "import Qt 4.6\nFontLoader { source: \"http://www.princexml.com/fonts/steffmann/Starburst.ttf\" }"; QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); @@ -124,7 +126,7 @@ void tst_qmlfontloader::webfont() QTRY_VERIFY(fontObject->status() == QmlFontLoader::Ready); } -void tst_qmlfontloader::failwebfont() +void tst_qmlfontloader::failWebFont() { QString componentStr = "import Qt 4.6\nFontLoader { source: \"http://wrong.address.com/Starburst.ttf\" }"; QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); diff --git a/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp b/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp index d53de59..b9c12ee 100644 --- a/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp +++ b/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp @@ -57,6 +57,7 @@ private slots: void width(); void wrap(); void elide(); + void textFormat(); // ### these tests may be trivial void horizontalAlignment(); @@ -145,6 +146,9 @@ void tst_qmlgraphicstext::text() QVERIFY(textObject != 0); QCOMPARE(textObject->text(), QString("")); + QVERIFY(textObject->width() == 0); + + delete textObject; } for (int i = 0; i < standard.size(); i++) @@ -155,6 +159,7 @@ void tst_qmlgraphicstext::text() QVERIFY(textObject != 0); QCOMPARE(textObject->text(), standard.at(i)); + QVERIFY(textObject->width() > 0); } for (int i = 0; i < richText.size(); i++) @@ -166,6 +171,7 @@ void tst_qmlgraphicstext::text() QVERIFY(textObject != 0); QString expected = richText.at(i); QCOMPARE(textObject->text(), expected.replace("\\\"", "\"")); + QVERIFY(textObject->width() > 0); } } @@ -176,6 +182,7 @@ void tst_qmlgraphicstext::width() QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"\" }", QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QVERIFY(textObject != 0); QCOMPARE(textObject->width(), 0.); } @@ -189,7 +196,9 @@ void tst_qmlgraphicstext::width() QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QVERIFY(textObject != 0); QCOMPARE(textObject->width(), qreal(metricWidth)); + QVERIFY(textObject->textFormat() == QmlGraphicsText::PlainText); } for (int i = 0; i < richText.size(); i++) @@ -204,7 +213,9 @@ void tst_qmlgraphicstext::width() QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QVERIFY(textObject != 0); QCOMPARE(textObject->width(), qreal(documentWidth)); + QVERIFY(textObject->textFormat() == QmlGraphicsText::RichText); } } @@ -217,6 +228,8 @@ void tst_qmlgraphicstext::wrap() QmlGraphicsText *textObject = qobject_cast(textComponent.create()); textHeight = textObject->height(); + QVERIFY(textObject != 0); + QVERIFY(textObject->wrap() == true); QCOMPARE(textObject->width(), 300.); } @@ -226,6 +239,7 @@ void tst_qmlgraphicstext::wrap() QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QVERIFY(textObject != 0); QCOMPARE(textObject->width(), 30.); QVERIFY(textObject->height() > textHeight); } @@ -236,6 +250,7 @@ void tst_qmlgraphicstext::wrap() QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QVERIFY(textObject != 0); QCOMPARE(textObject->width(), 30.); QVERIFY(textObject->height() > textHeight); } @@ -246,38 +261,56 @@ void tst_qmlgraphicstext::elide() { for (Qt::TextElideMode m = Qt::ElideLeft; m<=Qt::ElideNone; m=Qt::TextElideMode(int(m)+1)) { const char* elidename[]={"ElideLeft", "ElideRight", "ElideMiddle", "ElideNone"}; - QString elide = "elide: \""+QString(elidename[int(m)])+"\";"; + QString elide = "elide: Text." + QString(elidename[int(m)]) + ";"; // XXX Poor coverage. { - QmlComponent textComponent(&engine, ("import Qt 4.6\nText { text: \"\"; "+elide+" width: 300 }").toLatin1(), QUrl("file://")); + QmlComponent textComponent(&engine, ("import Qt 4.6\nText { text: \"\"; "+elide+" width: 100 }").toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->width(), 300.); + QCOMPARE(textObject->width(), 100.); } for (int i = 0; i < standard.size(); i++) { - QString componentStr = "import Qt 4.6\nText { "+elide+" width: 300; text: \"" + standard.at(i) + "\" }"; + QString componentStr = "import Qt 4.6\nText { "+elide+" width: 100; text: \"" + standard.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->width(), 300.); + QCOMPARE(textObject->width(), 100.); } // richtext - does nothing for (int i = 0; i < richText.size(); i++) { - QString componentStr = "import Qt 4.6\nText { "+elide+" width: 300; text: \"" + richText.at(i) + "\" }"; + QString componentStr = "import Qt 4.6\nText { "+elide+" width: 100; text: \"" + richText.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->width(), 300.); + QCOMPARE(textObject->width(), 100.); } } } +void tst_qmlgraphicstext::textFormat() +{ + { + QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"Hello\"; textFormat: Text.RichText }", QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QVERIFY(textObject != 0); + QVERIFY(textObject->textFormat() == QmlGraphicsText::RichText); + } + { + QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"Hello\"; textFormat: Text.PlainText }", QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QVERIFY(textObject != 0); + QVERIFY(textObject->textFormat() == QmlGraphicsText::PlainText); + } +} + //the alignment tests may be trivial o.oa void tst_qmlgraphicstext::horizontalAlignment() { -- cgit v0.12 From 10207df5018a9495849abd7bbd2fa615aab20260 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 4 Nov 2009 09:18:13 +1000 Subject: Don't rely on imprecise boundingRect for space around text for outlines. Fixes tst_visual(flickable) --- src/declarative/graphicsitems/qmlgraphicstext.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicstext.cpp b/src/declarative/graphicsitems/qmlgraphicstext.cpp index 6790923..d640fc9 100644 --- a/src/declarative/graphicsitems/qmlgraphicstext.cpp +++ b/src/declarative/graphicsitems/qmlgraphicstext.cpp @@ -534,7 +534,7 @@ void QmlGraphicsTextPrivate::updateSize() void QmlGraphicsTextPrivate::drawOutline() { - QPixmap img = QPixmap(imgCache.size()); + QPixmap img = QPixmap(imgStyleCache.width()+2,imgStyleCache.height()+2); img.fill(Qt::transparent); QPainter ppm(&img); @@ -558,7 +558,7 @@ void QmlGraphicsTextPrivate::drawOutline() void QmlGraphicsTextPrivate::drawOutline(int yOffset) { - QPixmap img = QPixmap(imgCache.size()); + QPixmap img = QPixmap(imgStyleCache.width()+2,imgStyleCache.height()+2); img.fill(Qt::transparent); QPainter ppm(&img); -- cgit v0.12 From 1c558dafd37f2e750ce9a672ba245f36dda8b42c Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 4 Nov 2009 09:18:40 +1000 Subject: autotests. --- tests/auto/declarative/behaviors/tst_behaviors.cpp | 8 +++----- .../declarative/qmlpropertymap/tst_qmlpropertymap.cpp | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/tests/auto/declarative/behaviors/tst_behaviors.cpp b/tests/auto/declarative/behaviors/tst_behaviors.cpp index 29c631d..da910d9 100644 --- a/tests/auto/declarative/behaviors/tst_behaviors.cpp +++ b/tests/auto/declarative/behaviors/tst_behaviors.cpp @@ -225,11 +225,9 @@ void tst_behaviors::reassignedAnimation() QTest::ignoreMessage(QtWarningMsg, "QML QmlBehavior (file://" SRCDIR "/data/reassignedAnimation.qml:9:12) Can't change the animation assigned to a Behavior."); QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); - - rect->setState("moved"); - QTest::qWait(200 + 100); - qreal x = qobject_cast(rect->findChild("MyRect"))->x(); - QCOMPARE(x, qreal(200)); //i.e. the right behavior has been triggered + QCOMPARE(qobject_cast( + qobject_cast( + rect->findChild("MyBehavior"))->animation())->duration(), 200); } QTEST_MAIN(tst_behaviors) diff --git a/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp b/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp index a7211bd..9be77e8 100644 --- a/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp +++ b/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp @@ -55,6 +55,7 @@ public: private slots: void insert(); void operatorInsert(); + void operatorValue(); void clear(); void changed(); void count(); @@ -66,6 +67,7 @@ void tst_QmlPropertyMap::insert() map.insert(QLatin1String("key1"),100); map.insert(QLatin1String("key2"),200); QVERIFY(map.keys().count() == 2); + QVERIFY(map.contains(QLatin1String("key1"))); QCOMPARE(map.value(QLatin1String("key1")), QVariant(100)); QCOMPARE(map.value(QLatin1String("key2")), QVariant(200)); @@ -88,6 +90,20 @@ void tst_QmlPropertyMap::operatorInsert() QCOMPARE(map.value(QLatin1String("key1")), QVariant("Hello World")); } +void tst_QmlPropertyMap::operatorValue() +{ + QmlPropertyMap map; + map.insert(QLatin1String("key1"),100); + map.insert(QLatin1String("key2"),200); + QVERIFY(map.keys().count() == 2); + QVERIFY(map.contains(QLatin1String("key1"))); + + QCOMPARE(map.value(QLatin1String("key1")), QVariant(100)); + QCOMPARE(map.value(QLatin1String("key2")), QVariant(200)); + QCOMPARE(map[QLatin1String("key1")], map.value(QLatin1String("key1"))); + QCOMPARE(map[QLatin1String("key2")], map.value(QLatin1String("key2"))); +} + void tst_QmlPropertyMap::clear() { QmlPropertyMap map; @@ -98,6 +114,7 @@ void tst_QmlPropertyMap::clear() map.clear(QLatin1String("key1")); QVERIFY(map.keys().count() == 1); + QVERIFY(map.contains(QLatin1String("key1"))); QCOMPARE(map.value(QLatin1String("key1")), QVariant()); } @@ -143,6 +160,7 @@ void tst_QmlPropertyMap::count() //clearing doesn't remove the key map.clear(QLatin1String("key3")); QCOMPARE(map.count(), 3); + QCOMPARE(map.size(), map.count()); } QTEST_MAIN(tst_QmlPropertyMap) -- cgit v0.12 From a200f90d19a8d233e92311d881644424dcde31de Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 4 Nov 2009 09:42:17 +1000 Subject: update .pro file --- tests/auto/declarative/declarative.pro | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 73269e1..86cf175 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -19,6 +19,7 @@ SUBDIRS += anchors \ qmldom \ qmlecmascript \ qmlgraphicstext \ + qmlfontloader \ qmllanguage \ qmllist \ qmllistaccessor \ -- cgit v0.12 From 162f9d19231612f2b5ae55156ecfd449d3f2f8d7 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 4 Nov 2009 10:33:45 +1000 Subject: Fix moving items in visual item model. --- .../graphicsitems/qmlgraphicsvisualitemmodel.cpp | 32 ++++-- .../graphicsitems/qmlgraphicsvisualitemmodel_p.h | 1 + tests/auto/declarative/listview/data/listview.qml | 4 +- tests/auto/declarative/listview/tst_listview.cpp | 120 +++++++++++++++++++++ 4 files changed, 149 insertions(+), 8 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp index 686c0da..80b2458 100644 --- a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp @@ -617,6 +617,8 @@ void QmlGraphicsVisualDataModel::setModel(const QVariant &model) this, SLOT(_q_rowsRemoved(const QModelIndex &,int,int))); QObject::disconnect(d->m_abstractItemModel, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)), this, SLOT(_q_dataChanged(const QModelIndex&,const QModelIndex&))); + QObject::disconnect(d->m_abstractItemModel, SIGNAL(rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int)), + this, SLOT(_q_rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int))); } else if (d->m_visualItemModel) { QObject::disconnect(d->m_visualItemModel, SIGNAL(itemsInserted(int,int)), this, SIGNAL(itemsInserted(int,int))); @@ -654,6 +656,8 @@ void QmlGraphicsVisualDataModel::setModel(const QVariant &model) this, SLOT(_q_rowsRemoved(const QModelIndex &,int,int))); QObject::connect(d->m_abstractItemModel, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)), this, SLOT(_q_dataChanged(const QModelIndex&,const QModelIndex&))); + QObject::connect(d->m_abstractItemModel, SIGNAL(rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int)), + this, SLOT(_q_rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int))); return; } if ((d->m_visualItemModel = qvariant_cast(model))) { @@ -978,9 +982,10 @@ void QmlGraphicsVisualDataModel::_q_itemsMoved(int from, int to, int count) for (QHash::Iterator iter = d->m_cache.begin(); iter != d->m_cache.end(); ) { + int diff = from > to ? count : -count; if (iter.key() >= qMin(from,to) && iter.key() < qMax(from+count,to+count)) { QmlGraphicsVisualDataModelPrivate::ObjectRef objRef = *iter; - int index = iter.key() + from - to; + int index = iter.key() + diff; iter = d->m_cache.erase(iter); items.insert(index, objRef); @@ -996,20 +1001,35 @@ void QmlGraphicsVisualDataModel::_q_itemsMoved(int from, int to, int count) emit itemsMoved(from, to, count); } -void QmlGraphicsVisualDataModel::_q_rowsInserted(const QModelIndex &, int begin, int end) +void QmlGraphicsVisualDataModel::_q_rowsInserted(const QModelIndex &parent, int begin, int end) { - _q_itemsInserted(begin, end - begin + 1); + if (!parent.isValid()) + _q_itemsInserted(begin, end - begin + 1); } -void QmlGraphicsVisualDataModel::_q_rowsRemoved(const QModelIndex &, int begin, int end) +void QmlGraphicsVisualDataModel::_q_rowsRemoved(const QModelIndex &parent, int begin, int end) { - _q_itemsRemoved(begin, end - begin + 1); + if (!parent.isValid()) + _q_itemsRemoved(begin, end - begin + 1); +} + +void QmlGraphicsVisualDataModel::_q_rowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow) +{ + const int count = sourceEnd - sourceStart + 1; + if (!destinationParent.isValid() && !sourceParent.isValid()) { + _q_itemsMoved(sourceStart, destinationRow, count); + } else if (!sourceParent.isValid()) { + _q_itemsRemoved(sourceStart, count); + } else if (!destinationParent.isValid()) { + _q_itemsInserted(destinationRow, count); + } } void QmlGraphicsVisualDataModel::_q_dataChanged(const QModelIndex &begin, const QModelIndex &end) { Q_D(QmlGraphicsVisualDataModel); - _q_itemsChanged(begin.row(), end.row() - begin.row() + 1, d->m_roles); + if (!begin.parent().isValid()) + _q_itemsChanged(begin.row(), end.row() - begin.row() + 1, d->m_roles); } void QmlGraphicsVisualDataModel::_q_createdPackage(int index, QmlPackage *package) diff --git a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h index 8b0a8f5..3ff2a74 100644 --- a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h @@ -183,6 +183,7 @@ private Q_SLOTS: void _q_itemsMoved(int from, int to, int count); void _q_rowsInserted(const QModelIndex &,int,int); void _q_rowsRemoved(const QModelIndex &,int,int); + void _q_rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int); void _q_dataChanged(const QModelIndex&,const QModelIndex&); void _q_createdPackage(int index, QmlPackage *package); void _q_destroyingPackage(QmlPackage *package); diff --git a/tests/auto/declarative/listview/data/listview.qml b/tests/auto/declarative/listview/data/listview.qml index 9039b55..b7b838b 100644 --- a/tests/auto/declarative/listview/data/listview.qml +++ b/tests/auto/declarative/listview/data/listview.qml @@ -6,7 +6,7 @@ Rectangle { color: "#ffffff" resources: [ Component { - id: Delegate + id: myDelegate Rectangle { id: wrapper objectName: "wrapper" @@ -41,6 +41,6 @@ Rectangle { width: 240 height: 320 model: testModel - delegate: Delegate + delegate: myDelegate } } diff --git a/tests/auto/declarative/listview/tst_listview.cpp b/tests/auto/declarative/listview/tst_listview.cpp index 42d4900..441138b 100644 --- a/tests/auto/declarative/listview/tst_listview.cpp +++ b/tests/auto/declarative/listview/tst_listview.cpp @@ -66,11 +66,15 @@ private slots: void qListModelInterface_removed(); void qAbstractItemModel_removed(); + void qListModelInterface_moved(); + void qAbstractItemModel_moved(); + private: template void items(); template void changed(); template void inserted(); template void removed(); + template void moved(); QmlView *createView(const QString &filename); template T *findItem(QmlGraphicsItem *parent, const QString &id, int index=-1); @@ -140,6 +144,11 @@ public: emit itemsRemoved(index, 1); } + void moveItem(int from, int to) { + list.move(from, to); + emit itemsMoved(from, to, 1); + } + void modifyItem(int index, const QString &name, const QString &number) { list[index] = QPair(name, number); emit itemsChanged(index, 1, roles()); @@ -195,6 +204,12 @@ public: emit endRemoveRows(); } + void moveItem(int from, int to) { + emit beginMoveRows(QModelIndex(), from, from, QModelIndex(), to); + list.move(from, to); + emit endMoveRows(); + } + void modifyItem(int idx, const QString &name, const QString &number) { list[idx] = QPair(name, number); emit dataChanged(index(idx,0), index(idx,0)); @@ -454,6 +469,100 @@ void tst_QmlGraphicsListView::removed() delete canvas; } +template +void tst_QmlGraphicsListView::moved() +{ + QmlView *canvas = createView(SRCDIR "/data/listview.qml"); + + T model; + for (int i = 0; i < 30; i++) + model.addItem("Item" + QString::number(i), ""); + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsListView *listview = findItem(canvas->root(), "list"); + QVERIFY(listview != 0); + + QmlGraphicsItem *viewport = listview->viewport(); + QVERIFY(viewport != 0); + + model.moveItem(1, 4); + + // let transitions settle. + QTest::qWait(1000); + + QmlGraphicsText *name = findItem(viewport, "textName", 1); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(1)); + QmlGraphicsText *number = findItem(viewport, "textNumber", 1); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(1)); + + name = findItem(viewport, "textName", 4); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(4)); + number = findItem(viewport, "textNumber", 4); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(4)); + + // Confirm items positioned correctly + int itemCount = findItems(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->y() == i*20); + } + + listview->setViewportY(80); + + // move outside visible area + model.moveItem(1, 18); + + // let transitions settle. + QTest::qWait(1000); + + // Confirm items positioned correctly and indexes correct + for (int i = 3; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->y() == i*20 + 20); + name = findItem(viewport, "textName", i); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(i)); + number = findItem(viewport, "textNumber", i); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(i)); + } + + // move from outside visible into visible + model.moveItem(20, 4); + + // let transitions settle. + QTest::qWait(1000); + + // Confirm items positioned correctly and indexes correct + for (int i = 3; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->y() == i*20 + 20); + name = findItem(viewport, "textName", i); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(i)); + number = findItem(viewport, "textNumber", i); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(i)); + } + + delete canvas; +} + void tst_QmlGraphicsListView::qListModelInterface_items() { items(); @@ -494,6 +603,17 @@ void tst_QmlGraphicsListView::qAbstractItemModel_removed() removed(); } +void tst_QmlGraphicsListView::qListModelInterface_moved() +{ + moved(); +} + +void tst_QmlGraphicsListView::qAbstractItemModel_moved() +{ + moved(); +} + + QmlView *tst_QmlGraphicsListView::createView(const QString &filename) { QmlView *canvas = new QmlView(0); -- cgit v0.12 From 5971999e08e0a6f41e200c20d3ceb5720732ce6b Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 4 Nov 2009 11:35:29 +1000 Subject: QmlGraphicsBorderImage autotests --- tests/auto/declarative/declarative.pro | 1 + .../qmlgraphicsborderimage/data/colors-round.sci | 7 + .../qmlgraphicsborderimage/data/colors.png | Bin 0 -> 1655 bytes .../qmlgraphicsborderimage.pro | 8 + .../tst_qmlgraphicsborderimage.cpp | 162 +++++++++++++++++++++ 5 files changed, 178 insertions(+) create mode 100644 tests/auto/declarative/qmlgraphicsborderimage/data/colors-round.sci create mode 100644 tests/auto/declarative/qmlgraphicsborderimage/data/colors.png create mode 100644 tests/auto/declarative/qmlgraphicsborderimage/qmlgraphicsborderimage.pro create mode 100644 tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 86cf175..321e91b 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -19,6 +19,7 @@ SUBDIRS += anchors \ qmldom \ qmlecmascript \ qmlgraphicstext \ + qmlgraphicsborderimage \ qmlfontloader \ qmllanguage \ qmllist \ diff --git a/tests/auto/declarative/qmlgraphicsborderimage/data/colors-round.sci b/tests/auto/declarative/qmlgraphicsborderimage/data/colors-round.sci new file mode 100644 index 0000000..5d2f49f --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsborderimage/data/colors-round.sci @@ -0,0 +1,7 @@ +border.left:10 +border.top:20 +border.right:30 +border.bottom:40 +horizontalTileRule:Round +verticalTileRule:Repeat +source:colors.png diff --git a/tests/auto/declarative/qmlgraphicsborderimage/data/colors.png b/tests/auto/declarative/qmlgraphicsborderimage/data/colors.png new file mode 100644 index 0000000..dfb62f3 Binary files /dev/null and b/tests/auto/declarative/qmlgraphicsborderimage/data/colors.png differ diff --git a/tests/auto/declarative/qmlgraphicsborderimage/qmlgraphicsborderimage.pro b/tests/auto/declarative/qmlgraphicsborderimage/qmlgraphicsborderimage.pro new file mode 100644 index 0000000..82da769 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsborderimage/qmlgraphicsborderimage.pro @@ -0,0 +1,8 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative gui +macx:CONFIG -= app_bundle + +SOURCES += tst_qmlgraphicsborderimage.cpp + +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp b/tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp new file mode 100644 index 0000000..809d9fd --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp @@ -0,0 +1,162 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include + +class tst_qmlgraphicsborderimage : public QObject + +{ + Q_OBJECT +public: + tst_qmlgraphicsborderimage(); + +private slots: + void simple(); + void resized(); + void smooth(); + void tileModes(); + void sciFile(); + +private: + QmlEngine engine; +}; + +tst_qmlgraphicsborderimage::tst_qmlgraphicsborderimage() +{ +} + +void tst_qmlgraphicsborderimage::simple() +{ + QString componentStr = "import Qt 4.6\nBorderImage { source: \"" SRCDIR "/data/colors.png\" }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsBorderImage *obj = qobject_cast(component.create()); + QVERIFY(obj != 0); + QVERIFY(obj->width() == 120); + QVERIFY(obj->height() == 120); + QVERIFY(obj->horizontalTileMode() == QmlGraphicsBorderImage::Stretch); + QVERIFY(obj->verticalTileMode() == QmlGraphicsBorderImage::Stretch); + + delete obj; +} + +void tst_qmlgraphicsborderimage::resized() +{ + QString componentStr = "import Qt 4.6\nBorderImage { source: \"" SRCDIR "/data/colors.png\"; width: 300; height: 300 }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsBorderImage *obj = qobject_cast(component.create()); + QVERIFY(obj != 0); + QVERIFY(obj->width() == 300); + QVERIFY(obj->height() == 300); + QVERIFY(obj->horizontalTileMode() == QmlGraphicsBorderImage::Stretch); + QVERIFY(obj->verticalTileMode() == QmlGraphicsBorderImage::Stretch); + + delete obj; +} + +void tst_qmlgraphicsborderimage::smooth() +{ + QString componentStr = "import Qt 4.6\nBorderImage { source: \"" SRCDIR "/data/colors.png\"; smooth: true; width: 300; height: 300 }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsBorderImage *obj = qobject_cast(component.create()); + QVERIFY(obj != 0); + QVERIFY(obj->width() == 300); + QVERIFY(obj->height() == 300); + QVERIFY(obj->smoothTransform() == true); + QVERIFY(obj->horizontalTileMode() == QmlGraphicsBorderImage::Stretch); + QVERIFY(obj->verticalTileMode() == QmlGraphicsBorderImage::Stretch); + + delete obj; +} + +void tst_qmlgraphicsborderimage::tileModes() +{ + { + QString componentStr = "import Qt 4.6\nBorderImage { source: \"" SRCDIR "/data/colors.png\"; width: 100; height: 300; horizontalTileMode: BorderImage.Repeat; verticalTileMode: BorderImage.Repeat }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsBorderImage *obj = qobject_cast(component.create()); + QVERIFY(obj != 0); + QVERIFY(obj->width() == 100); + QVERIFY(obj->height() == 300); + QVERIFY(obj->horizontalTileMode() == QmlGraphicsBorderImage::Repeat); + QVERIFY(obj->verticalTileMode() == QmlGraphicsBorderImage::Repeat); + + delete obj; + } + { + QString componentStr = "import Qt 4.6\nBorderImage { source: \"" SRCDIR "/data/colors.png\"; width: 300; height: 150; horizontalTileMode: BorderImage.Round; verticalTileMode: BorderImage.Round }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsBorderImage *obj = qobject_cast(component.create()); + QVERIFY(obj != 0); + QVERIFY(obj->width() == 300); + QVERIFY(obj->height() == 150); + QVERIFY(obj->horizontalTileMode() == QmlGraphicsBorderImage::Round); + QVERIFY(obj->verticalTileMode() == QmlGraphicsBorderImage::Round); + + delete obj; + } +} + +void tst_qmlgraphicsborderimage::sciFile() +{ + QString componentStr = "import Qt 4.6\nBorderImage { source: \"" SRCDIR "/data/colors-round.sci\"; width: 300; height: 300 }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsBorderImage *obj = qobject_cast(component.create()); + QVERIFY(obj != 0); + QVERIFY(obj->width() == 300); + QVERIFY(obj->height() == 300); + QVERIFY(obj->border()->left() == 10); + QVERIFY(obj->border()->top() == 20); + QVERIFY(obj->border()->right() == 30); + QVERIFY(obj->border()->bottom() == 40); + QVERIFY(obj->horizontalTileMode() == QmlGraphicsBorderImage::Round); + QVERIFY(obj->verticalTileMode() == QmlGraphicsBorderImage::Repeat); + + delete obj; +} + +QTEST_MAIN(tst_qmlgraphicsborderimage) + +#include "tst_qmlgraphicsborderimage.moc" -- cgit v0.12 From 8b94bb526e11acca4a479e6e31375128c2b6163c Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 4 Nov 2009 10:58:07 +1000 Subject: Basic autotest for QmlGraphicsParticles --- .../qmlgraphicsparticles/data/particle.png | Bin 0 -> 262 bytes .../qmlgraphicsparticles/data/particles.qml | 15 +++ .../qmlgraphicsparticles/qmlgraphicsparticles.pro | 8 ++ .../tst_qmlgraphicsparticles.cpp | 122 +++++++++++++++++++++ 4 files changed, 145 insertions(+) create mode 100644 tests/auto/declarative/qmlgraphicsparticles/data/particle.png create mode 100644 tests/auto/declarative/qmlgraphicsparticles/data/particles.qml create mode 100644 tests/auto/declarative/qmlgraphicsparticles/qmlgraphicsparticles.pro create mode 100644 tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp diff --git a/tests/auto/declarative/qmlgraphicsparticles/data/particle.png b/tests/auto/declarative/qmlgraphicsparticles/data/particle.png new file mode 100644 index 0000000..defbde5 Binary files /dev/null and b/tests/auto/declarative/qmlgraphicsparticles/data/particle.png differ diff --git a/tests/auto/declarative/qmlgraphicsparticles/data/particles.qml b/tests/auto/declarative/qmlgraphicsparticles/data/particles.qml new file mode 100644 index 0000000..dccd2c7 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsparticles/data/particles.qml @@ -0,0 +1,15 @@ +import Qt 4.6 +Rectangle{ + width: 100 + height: 100 + color: "black" + objectName: "rect" + Particles { id: particles + objectName: "particles" + width:1; height:1; anchors.centerIn: parent; opacity: 1 + lifeSpan: 100; lifeSpanDeviation: 20; count:1000; + fadeInDuration: 20; fadeOutDuration: 20; + angle: 0; angleDeviation: 360; velocity: 500; velocityDeviation:30 + source: "particle.png" + } +} diff --git a/tests/auto/declarative/qmlgraphicsparticles/qmlgraphicsparticles.pro b/tests/auto/declarative/qmlgraphicsparticles/qmlgraphicsparticles.pro new file mode 100644 index 0000000..94eeb4e --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsparticles/qmlgraphicsparticles.pro @@ -0,0 +1,8 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative gui +macx:CONFIG -= app_bundle + +SOURCES += tst_qmlgraphicsparticles.cpp + +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp b/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp new file mode 100644 index 0000000..e50437a --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include + +class tst_QmlGraphicsParticles : public QObject +{ + Q_OBJECT +public: + tst_QmlGraphicsParticles(); + +private slots: + void properties(); + void runs(); +private: + QmlView *createView(const QString &filename); + +}; + +tst_QmlGraphicsParticles::tst_QmlGraphicsParticles() +{ +} + +void tst_QmlGraphicsParticles::properties() +{ + QmlView *canvas = createView(SRCDIR "/data/particles.qml"); + QVERIFY(canvas->root()); + QmlGraphicsParticles* particles = canvas->root()->findChild("particles"); + QVERIFY(particles); + + particles->setSource(QUrl("file://" SRCDIR "/data/particle.png")); + QCOMPARE(particles->source(), QUrl("file://" SRCDIR "/data/particle.png")); + + particles->setLifeSpanDeviation(1000); + QCOMPARE(particles->lifeSpanDeviation(), 1000); + + particles->setFadeInDuration(1000); + QCOMPARE(particles->fadeInDuration(), 1000); + + particles->setFadeOutDuration(1000); + QCOMPARE(particles->fadeOutDuration(), 1000); + + particles->setAngle(100.0); + QCOMPARE(particles->angle(), 100.0); + + particles->setAngleDeviation(100.0); + QCOMPARE(particles->angleDeviation(), 100.0); + + particles->setVelocity(100.0); + QCOMPARE(particles->velocity(), 100.0); + + particles->setVelocityDeviation(100.0); + QCOMPARE(particles->velocityDeviation(), 100.0); + + particles->setEmitting(false); + QCOMPARE(particles->emitting(), false); +} + +void tst_QmlGraphicsParticles::runs() +{ + QmlView *canvas = createView(SRCDIR "/data/particles.qml"); + QVERIFY(canvas->root()); + QmlGraphicsParticles* particles = canvas->root()->findChild("particles"); + QVERIFY(particles); + QTest::qWait(1000);//Run for one second. Test passes if it doesn't crash. +} + +QmlView *tst_QmlGraphicsParticles::createView(const QString &filename) +{ + QmlView *canvas = new QmlView(0); + canvas->setFixedSize(240,320); + + QFile file(filename); + file.open(QFile::ReadOnly); + QString qml = file.readAll(); + canvas->setQml(qml, filename); + canvas->execute(); + + return canvas; +} +QTEST_MAIN(tst_QmlGraphicsParticles) + +#include "tst_qmlgraphicsparticles.moc" -- cgit v0.12 From 15c19e46a330a20700f9dd42162100a12d80dc57 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 4 Nov 2009 12:38:48 +1000 Subject: Test inserting items outside of the visible area. --- tests/auto/declarative/listview/tst_listview.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/auto/declarative/listview/tst_listview.cpp b/tests/auto/declarative/listview/tst_listview.cpp index 441138b..e61dd55 100644 --- a/tests/auto/declarative/listview/tst_listview.cpp +++ b/tests/auto/declarative/listview/tst_listview.cpp @@ -356,6 +356,26 @@ void tst_QmlGraphicsListView::inserted() QVERIFY(item->y() == i*20); } + for (int i = model.count(); i < 30; ++i) + model.insertItem(i, "Hello", QString::number(i)); + QTest::qWait(1000); + + listview->setViewportY(80); + QTest::qWait(1000); + + // Insert item outside visible area + model.insertItem(1, "Hello", "1324"); + QTest::qWait(1000); + + QVERIFY(listview->viewportY() == 80); + + // Confirm items positioned correctly + int itemCount = findItems(viewport, "wrapper").count() - 1; + for (int i = 5; i < 5+itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + QVERIFY(item->y() == i*20 - 20); + } + delete canvas; } -- cgit v0.12 From 240f2732b808d4c23366f8a432136832b6dd86d5 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 4 Nov 2009 12:45:16 +1000 Subject: use same name for setter/getter and property --- src/declarative/graphicsitems/qmlgraphicsitem.cpp | 8 ++++---- src/declarative/graphicsitems/qmlgraphicsitem.h | 6 +++--- src/declarative/graphicsitems/qmlgraphicstextedit.cpp | 2 +- src/declarative/graphicsitems/qmlgraphicstextinput.cpp | 2 +- .../qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp | 2 +- tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp | 8 ++++---- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsitem.cpp b/src/declarative/graphicsitems/qmlgraphicsitem.cpp index 5083f43..51b8365 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsitem.cpp @@ -2667,9 +2667,9 @@ void QmlGraphicsItem::setTransformOrigin(TransformOrigin origin) The default is false. - \sa setSmoothTransform() + \sa setSmooth() */ -bool QmlGraphicsItem::smoothTransform() const +bool QmlGraphicsItem::smooth() const { Q_D(const QmlGraphicsItem); return d->smooth; @@ -2679,9 +2679,9 @@ bool QmlGraphicsItem::smoothTransform() const Sets whether the item should be drawn with antialiasing and smooth pixmap filtering to \a smooth. - \sa smoothTransform() + \sa smooth() */ -void QmlGraphicsItem::setSmoothTransform(bool smooth) +void QmlGraphicsItem::setSmooth(bool smooth) { Q_D(QmlGraphicsItem); if (d->smooth == smooth) diff --git a/src/declarative/graphicsitems/qmlgraphicsitem.h b/src/declarative/graphicsitems/qmlgraphicsitem.h index bdfc245..f64964c 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem.h +++ b/src/declarative/graphicsitems/qmlgraphicsitem.h @@ -91,7 +91,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsItem : public QGraphicsObject, public QmlP Q_PROPERTY(bool wantsFocus READ wantsFocus NOTIFY wantsFocusChanged) Q_PROPERTY(QmlList* transform READ transform DESIGNABLE false FINAL) Q_PROPERTY(TransformOrigin transformOrigin READ transformOrigin WRITE setTransformOrigin) - Q_PROPERTY(bool smooth READ smoothTransform WRITE setSmoothTransform) + Q_PROPERTY(bool smooth READ smooth WRITE setSmooth) Q_PROPERTY(QGraphicsEffect *effect READ graphicsEffect WRITE setGraphicsEffect) Q_ENUMS(TransformOrigin) Q_CLASSINFO("DefaultProperty", "data") @@ -144,8 +144,8 @@ public: TransformOrigin transformOrigin() const; void setTransformOrigin(TransformOrigin); - bool smoothTransform() const; - void setSmoothTransform(bool); + bool smooth() const; + void setSmooth(bool); QRectF boundingRect() const; virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); diff --git a/src/declarative/graphicsitems/qmlgraphicstextedit.cpp b/src/declarative/graphicsitems/qmlgraphicstextedit.cpp index 13df329..e84f514 100644 --- a/src/declarative/graphicsitems/qmlgraphicstextedit.cpp +++ b/src/declarative/graphicsitems/qmlgraphicstextedit.cpp @@ -946,7 +946,7 @@ void QmlGraphicsTextEditPrivate::init() { Q_Q(QmlGraphicsTextEdit); - q->setSmoothTransform(smooth); + q->setSmooth(smooth); q->setAcceptedMouseButtons(Qt::LeftButton); q->setFlag(QGraphicsItem::ItemHasNoContents, false); q->setFlag(QGraphicsItem::ItemAcceptsInputMethod); diff --git a/src/declarative/graphicsitems/qmlgraphicstextinput.cpp b/src/declarative/graphicsitems/qmlgraphicstextinput.cpp index 9a4f627..42de2b6 100644 --- a/src/declarative/graphicsitems/qmlgraphicstextinput.cpp +++ b/src/declarative/graphicsitems/qmlgraphicstextinput.cpp @@ -673,7 +673,7 @@ void QmlGraphicsTextInputPrivate::init() control->setCursorWidth(1); control->setPasswordCharacter(QLatin1Char('*')); control->setLayoutDirection(Qt::LeftToRight); - q->setSmoothTransform(smooth); + q->setSmooth(smooth); q->setAcceptedMouseButtons(Qt::LeftButton); q->setFlag(QGraphicsItem::ItemHasNoContents, false); q->setFlag(QGraphicsItem::ItemAcceptsInputMethod); diff --git a/tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp b/tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp index 809d9fd..4174ccf 100644 --- a/tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp +++ b/tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp @@ -104,7 +104,7 @@ void tst_qmlgraphicsborderimage::smooth() QVERIFY(obj != 0); QVERIFY(obj->width() == 300); QVERIFY(obj->height() == 300); - QVERIFY(obj->smoothTransform() == true); + QVERIFY(obj->smooth() == true); QVERIFY(obj->horizontalTileMode() == QmlGraphicsBorderImage::Stretch); QVERIFY(obj->verticalTileMode() == QmlGraphicsBorderImage::Stretch); diff --git a/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp b/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp index b9c12ee..1a90575 100644 --- a/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp +++ b/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp @@ -502,13 +502,13 @@ void tst_qmlgraphicstext::smooth() QString componentStr = "import Qt 4.6\nText { smooth: true; text: \"" + standard.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->smoothTransform(), true); + QCOMPARE(textObject->smooth(), true); } { QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->smoothTransform(), false); + QCOMPARE(textObject->smooth(), false); } } for (int i = 0; i < richText.size(); i++) @@ -517,13 +517,13 @@ void tst_qmlgraphicstext::smooth() QString componentStr = "import Qt 4.6\nText { smooth: true; text: \"" + richText.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->smoothTransform(), true); + QCOMPARE(textObject->smooth(), true); } { QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->smoothTransform(), false); + QCOMPARE(textObject->smooth(), false); } } } -- cgit v0.12 From 182e09689623679c46feedc66b44e27c558d575b Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 4 Nov 2009 10:55:21 +1000 Subject: DateTimeFormatter autotests. --- .../declarative/datetimeformatter/tst_datetimeformatter.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/auto/declarative/datetimeformatter/tst_datetimeformatter.cpp b/tests/auto/declarative/datetimeformatter/tst_datetimeformatter.cpp index 1712b86..5899d8d 100644 --- a/tests/auto/declarative/datetimeformatter/tst_datetimeformatter.cpp +++ b/tests/auto/declarative/datetimeformatter/tst_datetimeformatter.cpp @@ -67,12 +67,16 @@ void tst_datetimeformatter::date() 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()); @@ -91,6 +95,7 @@ void tst_datetimeformatter::time() QTime time(14,15,38,200); QCOMPARE(formatter->time(),time); + QCOMPARE(formatter->dateTime().time(),time); QCOMPARE(formatter->timeText(),time.toString(Qt::SystemLocaleShortDate)); @@ -98,6 +103,7 @@ void tst_datetimeformatter::time() 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"); @@ -117,12 +123,16 @@ void tst_datetimeformatter::dateTime() 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")); } -- cgit v0.12 From 89b7c36a40afa536c77fc1f3088a3747c070f887 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 4 Nov 2009 12:49:19 +1000 Subject: States autotest + missing files. --- tests/auto/declarative/behaviors/data/empty.qml | 23 +++++ .../declarative/behaviors/data/nonSelecting.qml | 26 +++++ .../behaviors/data/reassignedAnimation.qml | 27 +++++ .../auto/declarative/states/data/anchorChanges.qml | 22 ++++ .../declarative/states/data/anchorChanges2.qml | 21 ++++ .../auto/declarative/states/data/parentChange.qml | 36 +++++++ .../auto/declarative/states/data/parentChange2.qml | 31 ++++++ .../auto/declarative/states/data/parentChange3.qml | 42 ++++++++ tests/auto/declarative/states/data/script.qml | 10 ++ tests/auto/declarative/states/tst_states.cpp | 113 +++++++++++++++++++++ 10 files changed, 351 insertions(+) create mode 100644 tests/auto/declarative/behaviors/data/empty.qml create mode 100644 tests/auto/declarative/behaviors/data/nonSelecting.qml create mode 100644 tests/auto/declarative/behaviors/data/reassignedAnimation.qml create mode 100644 tests/auto/declarative/states/data/anchorChanges.qml create mode 100644 tests/auto/declarative/states/data/anchorChanges2.qml create mode 100644 tests/auto/declarative/states/data/parentChange.qml create mode 100644 tests/auto/declarative/states/data/parentChange2.qml create mode 100644 tests/auto/declarative/states/data/parentChange3.qml create mode 100644 tests/auto/declarative/states/data/script.qml diff --git a/tests/auto/declarative/behaviors/data/empty.qml b/tests/auto/declarative/behaviors/data/empty.qml new file mode 100644 index 0000000..412e26c --- /dev/null +++ b/tests/auto/declarative/behaviors/data/empty.qml @@ -0,0 +1,23 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + x: Behavior {} + } + MouseRegion { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + x: 200 + } + } +} diff --git a/tests/auto/declarative/behaviors/data/nonSelecting.qml b/tests/auto/declarative/behaviors/data/nonSelecting.qml new file mode 100644 index 0000000..ae9a9f5 --- /dev/null +++ b/tests/auto/declarative/behaviors/data/nonSelecting.qml @@ -0,0 +1,26 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + x: Behavior { + objectName: "MyBehavior"; + NumberAnimation { target: rect; property: "y"; duration: 200; } + } + } + MouseRegion { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + x: 200 + } + } +} diff --git a/tests/auto/declarative/behaviors/data/reassignedAnimation.qml b/tests/auto/declarative/behaviors/data/reassignedAnimation.qml new file mode 100644 index 0000000..693a595 --- /dev/null +++ b/tests/auto/declarative/behaviors/data/reassignedAnimation.qml @@ -0,0 +1,27 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + x: Behavior { + objectName: "MyBehavior" + NumberAnimation { duration: 200 } + NumberAnimation { duration: 1000 } + } + } + MouseRegion { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + x: 200 + } + } +} diff --git a/tests/auto/declarative/states/data/anchorChanges.qml b/tests/auto/declarative/states/data/anchorChanges.qml new file mode 100644 index 0000000..bb17840 --- /dev/null +++ b/tests/auto/declarative/states/data/anchorChanges.qml @@ -0,0 +1,22 @@ +import Qt 4.6 + +Rectangle { + id: container + width: 200; height: 200 + Rectangle { + id: myRect + objectName: "MyRect" + width: 50; height: 50 + color: "green"; + anchors.left: parent.left + anchors.leftMargin: 5 + } + states: State { + name: "right" + AnchorChanges { + target: myRect; + reset: "left" + right: container.right + } + } +} diff --git a/tests/auto/declarative/states/data/anchorChanges2.qml b/tests/auto/declarative/states/data/anchorChanges2.qml new file mode 100644 index 0000000..545345e --- /dev/null +++ b/tests/auto/declarative/states/data/anchorChanges2.qml @@ -0,0 +1,21 @@ +import Qt 4.6 + +Rectangle { + width: 200; height: 200 + Rectangle { + id: myRect + objectName: "MyRect" + width: 50; height: 50 + color: "green"; + anchors.left: parent.left + anchors.leftMargin: 5 + } + states: State { + name: "right" + AnchorChanges { + target: myRect; + reset: "left" + right: parent.right + } + } +} diff --git a/tests/auto/declarative/states/data/parentChange.qml b/tests/auto/declarative/states/data/parentChange.qml new file mode 100644 index 0000000..94fbd69 --- /dev/null +++ b/tests/auto/declarative/states/data/parentChange.qml @@ -0,0 +1,36 @@ +import Qt 4.6 + +Rectangle { + width: 400; height: 400 + Item { + x: 10; y: 10 + Rectangle { + id: myRect + objectName: "MyRect" + x: 5 + width: 100; height: 100 + color: "red" + } + } + MouseRegion { + id: Clickable + anchors.fill: parent + } + + Item { + x: -100; y: -50 + Item { + id: newParent + x: 248; y: 360 + } + } + + states: State { + name: "reparented" + when: Clickable.pressed + ParentChange { + target: myRect + parent: newParent + } + } +} diff --git a/tests/auto/declarative/states/data/parentChange2.qml b/tests/auto/declarative/states/data/parentChange2.qml new file mode 100644 index 0000000..d1c6d6a --- /dev/null +++ b/tests/auto/declarative/states/data/parentChange2.qml @@ -0,0 +1,31 @@ +import Qt 4.6 + +Rectangle { + id: newParent + width: 400; height: 400 + Item { + scale: .5 + rotation: 15 + x: 10; y: 10 + Rectangle { + id: myRect + objectName: "MyRect" + x: 5 + width: 100; height: 100 + color: "red" + } + } + MouseRegion { + id: Clickable + anchors.fill: parent + } + + states: State { + name: "reparented" + when: Clickable.pressed + ParentChange { + target: myRect + parent: newParent + } + } +} diff --git a/tests/auto/declarative/states/data/parentChange3.qml b/tests/auto/declarative/states/data/parentChange3.qml new file mode 100644 index 0000000..c7b7bee --- /dev/null +++ b/tests/auto/declarative/states/data/parentChange3.qml @@ -0,0 +1,42 @@ +import Qt 4.6 + +Rectangle { + width: 400; height: 400 + Item { + scale: .5 + rotation: 15 + transformOrigin: "Center" + x: 10; y: 10 + Rectangle { + id: myRect + objectName: "MyRect" + x: 5 + width: 100; height: 100 + transformOrigin: "BottomLeft" + color: "red" + } + } + MouseRegion { + id: Clickable + anchors.fill: parent + } + + Item { + x: 200; y: 200 + rotation: 52; + scale: 2 + Item { + id: newParent + x: 100; y: 100 + } + } + + states: State { + name: "reparented" + when: Clickable.pressed + ParentChange { + target: myRect + parent: newParent + } + } +} diff --git a/tests/auto/declarative/states/data/script.qml b/tests/auto/declarative/states/data/script.qml new file mode 100644 index 0000000..6983419 --- /dev/null +++ b/tests/auto/declarative/states/data/script.qml @@ -0,0 +1,10 @@ +import Qt 4.6 +Rectangle { + id: MyRectangle + width: 100; height: 100 + color: "red" + states: State { + name: "blue" + StateChangeScript { script: MyRectangle.color = "blue"; } + } +} diff --git a/tests/auto/declarative/states/tst_states.cpp b/tests/auto/declarative/states/tst_states.cpp index 89e755e..a215ed8 100644 --- a/tests/auto/declarative/states/tst_states.cpp +++ b/tests/auto/declarative/states/tst_states.cpp @@ -54,6 +54,9 @@ private slots: void basicExtension(); void basicBinding(); void signalOverride(); + void parentChange(); + void anchorChanges(); + void script(); }; void tst_states::basicChanges() @@ -353,6 +356,116 @@ void tst_states::signalOverride() } } +void tst_states::parentChange() +{ + QmlEngine engine; + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/parentChange.qml"); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); + + QmlGraphicsRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); + QVERIFY(innerRect != 0); + + rect->setState("reparented"); + QCOMPARE(innerRect->rotation(), qreal(0)); + QCOMPARE(innerRect->scale(), qreal(1)); + QCOMPARE(innerRect->x(), qreal(-133)); + QCOMPARE(innerRect->y(), qreal(-300)); + } + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/parentChange2.qml"); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); + + QmlGraphicsRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); + QVERIFY(innerRect != 0); + + rect->setState("reparented"); + QCOMPARE(innerRect->rotation(), qreal(15)); + QCOMPARE(innerRect->scale(), qreal(.5)); + QCOMPARE(QString("%1").arg(innerRect->x()), QString("%1").arg(12.4148145657)); + QCOMPARE(QString("%1").arg(innerRect->y()), QString("%1").arg(10.6470476128)); + } + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/parentChange3.qml"); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); + + QmlGraphicsRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); + QVERIFY(innerRect != 0); + + rect->setState("reparented"); + QCOMPARE(innerRect->rotation(), qreal(-37)); + QCOMPARE(innerRect->scale(), qreal(.25)); + QCOMPARE(QString("%1").arg(innerRect->x()), QString("%1").arg(-217.305)); + QCOMPARE(QString("%1").arg(innerRect->y()), QString("%1").arg(-164.413)); + + rect->setState(""); + QCOMPARE(innerRect->rotation(), qreal(0)); + QCOMPARE(innerRect->scale(), qreal(1)); + QCOMPARE(innerRect->x(), qreal(5)); + QCOMPARE(innerRect->y(), qreal(0)); + } +} + +void tst_states::anchorChanges() +{ + QmlEngine engine; + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/anchorChanges.qml"); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); + + QmlGraphicsRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); + QVERIFY(innerRect != 0); + + rect->setState("right"); + QCOMPARE(innerRect->x(), qreal(150)); + + rect->setState(""); + QCOMPARE(innerRect->x(), qreal(5)); + } + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/anchorChanges2.qml"); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); + + QmlGraphicsRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); + QVERIFY(innerRect != 0); + + rect->setState("right"); + QCOMPARE(innerRect->x(), qreal(150)); + + rect->setState(""); + QCOMPARE(innerRect->x(), qreal(5)); + } +} + +void tst_states::script() +{ + QmlEngine engine; + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/script.qml"); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("blue")); // a script isn't reverted + } +} + QTEST_MAIN(tst_states) #include "tst_states.moc" -- cgit v0.12 From d11f0b71ba8cae27aafc70fedf027f20180837e2 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 4 Nov 2009 13:06:09 +1000 Subject: Rename QmlGraphicsPixmapCache to QmlPixmapCache. --- src/declarative/extra/qmlgraphicsparticles.cpp | 10 +- src/declarative/graphicsitems/graphicsitems.pri | 2 - .../graphicsitems/qmlgraphicsborderimage.cpp | 14 +- .../graphicsitems/qmlgraphicsimagebase.cpp | 10 +- .../graphicsitems/qmlgraphicspixmapcache.cpp | 282 -------------------- .../graphicsitems/qmlgraphicspixmapcache_p.h | 71 ------ .../graphicsitems/qmlgraphicsscalegrid_p_p.h | 2 +- src/declarative/util/qmlpixmapcache.cpp | 283 +++++++++++++++++++++ src/declarative/util/qmlpixmapcache_p.h | 71 ++++++ src/declarative/util/util.pri | 6 +- 10 files changed, 376 insertions(+), 375 deletions(-) delete mode 100644 src/declarative/graphicsitems/qmlgraphicspixmapcache.cpp delete mode 100644 src/declarative/graphicsitems/qmlgraphicspixmapcache_p.h create mode 100644 src/declarative/util/qmlpixmapcache.cpp create mode 100644 src/declarative/util/qmlpixmapcache_p.h diff --git a/src/declarative/extra/qmlgraphicsparticles.cpp b/src/declarative/extra/qmlgraphicsparticles.cpp index aba7e27..0349a4e 100644 --- a/src/declarative/extra/qmlgraphicsparticles.cpp +++ b/src/declarative/extra/qmlgraphicsparticles.cpp @@ -50,7 +50,7 @@ #ifndef INT_MAX #define INT_MAX 2147483647 #endif -#include +#include #include #include #include @@ -619,7 +619,7 @@ QmlGraphicsParticles::~QmlGraphicsParticles() { Q_D(QmlGraphicsParticles); if (d->pendingPixmapCache) - QmlGraphicsPixmapCache::cancelGet(d->url, this); + QmlPixmapCache::cancelGet(d->url, this); } /*! @@ -641,7 +641,7 @@ void QmlGraphicsParticles::imageLoaded() { Q_D(QmlGraphicsParticles); d->pendingPixmapCache = false; - QmlGraphicsPixmapCache::find(d->url, &d->image); + QmlPixmapCache::find(d->url, &d->image); d->paintItem->updateSize(); d->paintItem->update(); } @@ -654,7 +654,7 @@ void QmlGraphicsParticles::setSource(const QUrl &name) return; if (d->pendingPixmapCache) { - QmlGraphicsPixmapCache::cancelGet(d->url, this); + QmlPixmapCache::cancelGet(d->url, this); d->pendingPixmapCache = false; } if (name.isEmpty()) { @@ -665,7 +665,7 @@ void QmlGraphicsParticles::setSource(const QUrl &name) } else { d->url = name; Q_ASSERT(!name.isRelative()); - QNetworkReply *reply = QmlGraphicsPixmapCache::get(qmlEngine(this), d->url, &d->image); + QNetworkReply *reply = QmlPixmapCache::get(qmlEngine(this), d->url, &d->image); if (reply) { connect(reply, SIGNAL(finished()), this, SLOT(imageLoaded())); d->pendingPixmapCache = true; diff --git a/src/declarative/graphicsitems/graphicsitems.pri b/src/declarative/graphicsitems/graphicsitems.pri index 15d775c..cf71451 100644 --- a/src/declarative/graphicsitems/graphicsitems.pri +++ b/src/declarative/graphicsitems/graphicsitems.pri @@ -39,7 +39,6 @@ HEADERS += \ graphicsitems/qmlgraphicstextedit_p_p.h \ graphicsitems/qmlgraphicstext_p.h \ graphicsitems/qmlgraphicstext_p_p.h \ - graphicsitems/qmlgraphicspixmapcache_p.h \ graphicsitems/qmlgraphicsvisualitemmodel_p.h \ graphicsitems/qmlgraphicslistview_p.h \ graphicsitems/qmlgraphicsgraphicsobjectcontainer_p.h \ @@ -70,7 +69,6 @@ SOURCES += \ graphicsitems/qmlgraphicstextinput.cpp \ graphicsitems/qmlgraphicstext.cpp \ graphicsitems/qmlgraphicstextedit.cpp \ - graphicsitems/qmlgraphicspixmapcache.cpp \ graphicsitems/qmlgraphicsvisualitemmodel.cpp \ graphicsitems/qmlgraphicslistview.cpp \ graphicsitems/qmlgraphicsgraphicsobjectcontainer.cpp \ diff --git a/src/declarative/graphicsitems/qmlgraphicsborderimage.cpp b/src/declarative/graphicsitems/qmlgraphicsborderimage.cpp index ed39a2b..89bbe91 100644 --- a/src/declarative/graphicsitems/qmlgraphicsborderimage.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsborderimage.cpp @@ -80,7 +80,7 @@ QmlGraphicsBorderImage::~QmlGraphicsBorderImage() if (d->sciReply) d->sciReply->deleteLater(); if (d->sciPendingPixmapCache) - QmlGraphicsPixmapCache::cancelGet(d->sciurl, this); + QmlPixmapCache::cancelGet(d->sciurl, this); } /*! \qmlproperty enum BorderImage::status @@ -160,11 +160,11 @@ void QmlGraphicsBorderImage::setSource(const QUrl &url) } if (d->pendingPixmapCache) { - QmlGraphicsPixmapCache::cancelGet(d->url, this); + QmlPixmapCache::cancelGet(d->url, this); d->pendingPixmapCache = false; } if (d->sciPendingPixmapCache) { - QmlGraphicsPixmapCache::cancelGet(d->sciurl, this); + QmlPixmapCache::cancelGet(d->sciurl, this); d->sciPendingPixmapCache = false; } @@ -203,7 +203,7 @@ void QmlGraphicsBorderImage::setSource(const QUrl &url) this, SLOT(sciRequestFinished())); } } else { - QNetworkReply *reply = QmlGraphicsPixmapCache::get(qmlEngine(this), d->url, &d->pix); + QNetworkReply *reply = QmlPixmapCache::get(qmlEngine(this), d->url, &d->pix); if (reply) { d->pendingPixmapCache = true; connect(reply, SIGNAL(finished()), this, SLOT(requestFinished())); @@ -320,7 +320,7 @@ void QmlGraphicsBorderImage::setGridScaledImage(const QmlGraphicsGridScaledImage d->verticalTileMode = sci.verticalTileRule(); d->sciurl = d->url.resolved(QUrl(sci.pixmapUrl())); - QNetworkReply *reply = QmlGraphicsPixmapCache::get(qmlEngine(this), d->sciurl, &d->pix); + QNetworkReply *reply = QmlPixmapCache::get(qmlEngine(this), d->sciurl, &d->pix); if (reply) { d->sciPendingPixmapCache = true; connect(reply, SIGNAL(finished()), this, SLOT(requestFinished())); @@ -348,10 +348,10 @@ void QmlGraphicsBorderImage::requestFinished() if (d->url.path().endsWith(QLatin1String(".sci"))) { d->sciPendingPixmapCache = false; - QmlGraphicsPixmapCache::find(d->sciurl, &d->pix); + QmlPixmapCache::find(d->sciurl, &d->pix); } else { d->pendingPixmapCache = false; - if (!QmlGraphicsPixmapCache::find(d->url, &d->pix)) + if (!QmlPixmapCache::find(d->url, &d->pix)) d->status = Error; } setImplicitWidth(d->pix.width()); diff --git a/src/declarative/graphicsitems/qmlgraphicsimagebase.cpp b/src/declarative/graphicsitems/qmlgraphicsimagebase.cpp index 283fb04..e86b53d 100644 --- a/src/declarative/graphicsitems/qmlgraphicsimagebase.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsimagebase.cpp @@ -45,7 +45,7 @@ #include #include #include -#include +#include QT_BEGIN_NAMESPACE @@ -65,7 +65,7 @@ QmlGraphicsImageBase::~QmlGraphicsImageBase() { Q_D(QmlGraphicsImageBase); if (d->pendingPixmapCache) - QmlGraphicsPixmapCache::cancelGet(d->url, this); + QmlPixmapCache::cancelGet(d->url, this); } QmlGraphicsImageBase::Status QmlGraphicsImageBase::status() const @@ -95,7 +95,7 @@ void QmlGraphicsImageBase::setSource(const QUrl &url) return; if (d->pendingPixmapCache) { - QmlGraphicsPixmapCache::cancelGet(d->url, this); + QmlPixmapCache::cancelGet(d->url, this); d->pendingPixmapCache = false; } @@ -117,7 +117,7 @@ void QmlGraphicsImageBase::setSource(const QUrl &url) update(); } else { d->status = Loading; - QNetworkReply *reply = QmlGraphicsPixmapCache::get(qmlEngine(this), d->url, &d->pix); + QNetworkReply *reply = QmlPixmapCache::get(qmlEngine(this), d->url, &d->pix); if (reply) { d->pendingPixmapCache = true; connect(reply, SIGNAL(finished()), this, SLOT(requestFinished())); @@ -147,7 +147,7 @@ void QmlGraphicsImageBase::requestFinished() d->pendingPixmapCache = false; - if (!QmlGraphicsPixmapCache::find(d->url, &d->pix)) + if (!QmlPixmapCache::find(d->url, &d->pix)) d->status = Error; setImplicitWidth(d->pix.width()); setImplicitHeight(d->pix.height()); diff --git a/src/declarative/graphicsitems/qmlgraphicspixmapcache.cpp b/src/declarative/graphicsitems/qmlgraphicspixmapcache.cpp deleted file mode 100644 index fdf489c..0000000 --- a/src/declarative/graphicsitems/qmlgraphicspixmapcache.cpp +++ /dev/null @@ -1,282 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the 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 "qmlgraphicspixmapcache_p.h" -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE -class QSharedNetworkReply; -typedef QHash QmlGraphicsSharedNetworkReplyHash; -static QmlGraphicsSharedNetworkReplyHash qfxActiveNetworkReplies; - -class QSharedNetworkReply -{ -public: - QSharedNetworkReply(QNetworkReply *r) : reply(r), refCount(1) {} - ~QSharedNetworkReply() - { - reply->deleteLater(); - } - QNetworkReply *reply; - QPixmap pixmap; // ensure reference to pixmap to QPixmapCache does not discard - - int refCount; - void addRef() - { - ++refCount; - } - void release() - { - Q_ASSERT(refCount > 0); - --refCount; - if (refCount == 0) { - QString key = reply->url().toString(); - qfxActiveNetworkReplies.remove(key); - delete this; - } - } -}; - -static bool readImage(QIODevice *dev, QPixmap *pixmap) - { - QImageReader imgio(dev); - -//#define QT_TEST_SCALED_SIZE -#ifdef QT_TEST_SCALED_SIZE - /* - Some mechanism is needed for loading images at a limited size, especially - for remote images. Loading only thumbnails of remote progressive JPEG - images can be efficient. (Qt jpeg handler does not do so currently) - */ - - QSize limit(60,60); - QSize sz = imgio.size(); - if (sz.width() > limit.width() || sz.height() > limit.height()) { - sz.scale(limit,Qt::KeepAspectRatio); - imgio.setScaledSize(sz); - } -#endif - - QImage img; - if (imgio.read(&img)) { -#ifdef QT_TEST_SCALED_SIZE - if (!sz.isValid()) - img = img.scaled(limit,Qt::KeepAspectRatio); -#endif - *pixmap = QPixmap::fromImage(img); - return true; - } else { - qWarning() << imgio.errorString(); - return false; - } - } - -/*! - \internal - \class QmlGraphicsPixmapCache - \brief Enacapsultes a pixmap for QmlGraphics items. - - This class is NOT reentrant. - */ - -static QString toLocalFileOrQrc(const QUrl& url) -{ - QString r = url.toLocalFile(); - if (r.isEmpty() && url.scheme() == QLatin1String("qrc")) - r = QLatin1Char(':') + url.path(); - return r; -} - -/*! - Finds the cached pixmap corresponding to \a url. - A previous call to get() must have requested the URL, - and the QNetworkReply must have finished before calling - this function. - - Returns true if the image was loaded without error. -*/ -bool QmlGraphicsPixmapCache::find(const QUrl& url, QPixmap *pixmap) -{ -#ifdef Q_ENABLE_PERFORMANCE_LOG - QmlPerfTimer perf; -#endif - - QString key = url.toString(); - bool ok = true; - if (!QPixmapCache::find(key,pixmap)) { -#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML - QString lf = toLocalFileOrQrc(url); - if (!lf.isEmpty()) { - QFile f(lf); - if (f.open(QIODevice::ReadOnly)) { - if (!readImage(&f, pixmap)) { - qWarning() << "Format error loading" << url; - *pixmap = QPixmap(); - ok = false; - } - } else { - *pixmap = QPixmap(); - ok = false; - } - } else -#endif - { - QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); - if (iter == qfxActiveNetworkReplies.end()) { - // API usage error - qWarning() << "QmlGraphicsPixmapCache: URL not loaded" << url; - ok = false; - } else { - if ((*iter)->reply->error()) { - qWarning() << "Network error loading" << url << (*iter)->reply->errorString(); - *pixmap = QPixmap(); - ok = false; - } else if (!readImage((*iter)->reply, pixmap)) { - qWarning() << "Format error loading" << url; - *pixmap = QPixmap(); - ok = false; - } else { - if ((*iter)->refCount > 1) - (*iter)->pixmap = *pixmap; - } - (*iter)->release(); - } - } - QPixmapCache::insert(key, *pixmap); - } else { - ok = !pixmap->isNull(); -#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML - if (url.scheme()!=QLatin1String("file")) -#endif - // We may be the second finder. Still need to check for active replies. - { - QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); - if (iter != qfxActiveNetworkReplies.end()) - (*iter)->release(); - } - } - return ok; -} - -/*! - Starts a network request to load \a url. - - Returns a QNetworkReply if the image is not immediately available, otherwise - returns 0. Caller should connect to QNetworkReply::finished() to then call - find() when the image is available. - - The returned QNetworkReply will be deleted when all get() calls are - matched by a corresponding find() call. -*/ -QNetworkReply *QmlGraphicsPixmapCache::get(QmlEngine *engine, const QUrl& url, QPixmap *pixmap) -{ -#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML - QString lf = toLocalFileOrQrc(url); - if (!lf.isEmpty()) { - QString key = url.toString(); - if (!QPixmapCache::find(key,pixmap)) { - QFile f(lf); - if (f.open(QIODevice::ReadOnly)) { - if (!readImage(&f, pixmap)) { - qWarning() << "Format error loading" << url; - *pixmap = QPixmap(); - } - } else - *pixmap = QPixmap(); - QPixmapCache::insert(key, *pixmap); - } - return 0; - } -#endif - - QString key = url.toString(); - if (QPixmapCache::find(key,pixmap)) { - return 0; - } - - QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); - if (iter == qfxActiveNetworkReplies.end()) { - QNetworkRequest req(url); - QSharedNetworkReply *item = new QSharedNetworkReply(engine->networkAccessManager()->get(req)); - iter = qfxActiveNetworkReplies.insert(key, item); - } else { - (*iter)->addRef(); - } - - return (*iter)->reply; -} - -/*! - Cancels a previous call to get(). - - May also cancel loading (eg. if no other pending request). - - Any connections from the QNetworkReply returned by get() to \a obj will be - disconnected. -*/ -void QmlGraphicsPixmapCache::cancelGet(const QUrl& url, QObject* obj) -{ - QString key = url.toString(); - QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); - if (iter == qfxActiveNetworkReplies.end()) - return; - if (obj) - QObject::disconnect((*iter)->reply, 0, obj, 0); - (*iter)->release(); -} - -/*! - This function is mainly for test verification. It returns the number of - requests that are still unfinished. -*/ -int QmlGraphicsPixmapCache::pendingRequests() -{ - return qfxActiveNetworkReplies.count(); -} - -QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qmlgraphicspixmapcache_p.h b/src/declarative/graphicsitems/qmlgraphicspixmapcache_p.h deleted file mode 100644 index 29de98d..0000000 --- a/src/declarative/graphicsitems/qmlgraphicspixmapcache_p.h +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the 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 QMLGRAPHICSPIXMAPCACHE_H -#define QMLGRAPHICSPIXMAPCACHE_H - -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class QmlEngine; -class QNetworkReply; -class Q_DECLARATIVE_EXPORT QmlGraphicsPixmapCache -{ -public: - static QNetworkReply *get(QmlEngine *, const QUrl& url, QPixmap *pixmap); - static void cancelGet(const QUrl& url, QObject* obj); - - static bool find(const QUrl& url, QPixmap *pixmap); // url must have been passed to QmlGraphicsPixmapCache::get, and any returned reply finished. - - static int pendingRequests(); // mainly for test verification -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMLGRAPHICSPIXMAPCACHE_H diff --git a/src/declarative/graphicsitems/qmlgraphicsscalegrid_p_p.h b/src/declarative/graphicsitems/qmlgraphicsscalegrid_p_p.h index b66a5a5..d4ae0a6 100644 --- a/src/declarative/graphicsitems/qmlgraphicsscalegrid_p_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsscalegrid_p_p.h @@ -44,7 +44,7 @@ #include #include -#include +#include #include #include "qmlgraphicsborderimage_p.h" diff --git a/src/declarative/util/qmlpixmapcache.cpp b/src/declarative/util/qmlpixmapcache.cpp new file mode 100644 index 0000000..f5904c0 --- /dev/null +++ b/src/declarative/util/qmlpixmapcache.cpp @@ -0,0 +1,283 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the 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 "qmlpixmapcache_p.h" +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QSharedNetworkReply; +typedef QHash QmlGraphicsSharedNetworkReplyHash; +static QmlGraphicsSharedNetworkReplyHash qfxActiveNetworkReplies; + +class QSharedNetworkReply +{ +public: + QSharedNetworkReply(QNetworkReply *r) : reply(r), refCount(1) {} + ~QSharedNetworkReply() + { + reply->deleteLater(); + } + QNetworkReply *reply; + QPixmap pixmap; // ensure reference to pixmap to QPixmapCache does not discard + + int refCount; + void addRef() + { + ++refCount; + } + void release() + { + Q_ASSERT(refCount > 0); + --refCount; + if (refCount == 0) { + QString key = reply->url().toString(); + qfxActiveNetworkReplies.remove(key); + delete this; + } + } +}; + +static bool readImage(QIODevice *dev, QPixmap *pixmap) + { + QImageReader imgio(dev); + +//#define QT_TEST_SCALED_SIZE +#ifdef QT_TEST_SCALED_SIZE + /* + Some mechanism is needed for loading images at a limited size, especially + for remote images. Loading only thumbnails of remote progressive JPEG + images can be efficient. (Qt jpeg handler does not do so currently) + */ + + QSize limit(60,60); + QSize sz = imgio.size(); + if (sz.width() > limit.width() || sz.height() > limit.height()) { + sz.scale(limit,Qt::KeepAspectRatio); + imgio.setScaledSize(sz); + } +#endif + + QImage img; + if (imgio.read(&img)) { +#ifdef QT_TEST_SCALED_SIZE + if (!sz.isValid()) + img = img.scaled(limit,Qt::KeepAspectRatio); +#endif + *pixmap = QPixmap::fromImage(img); + return true; + } else { + qWarning() << imgio.errorString(); + return false; + } + } + +/*! + \internal + \class QmlPixmapCache + \brief Enacapsultes a pixmap for QmlGraphics items. + + This class is NOT reentrant. + */ + +static QString toLocalFileOrQrc(const QUrl& url) +{ + QString r = url.toLocalFile(); + if (r.isEmpty() && url.scheme() == QLatin1String("qrc")) + r = QLatin1Char(':') + url.path(); + return r; +} + +/*! + Finds the cached pixmap corresponding to \a url. + A previous call to get() must have requested the URL, + and the QNetworkReply must have finished before calling + this function. + + Returns true if the image was loaded without error. +*/ +bool QmlPixmapCache::find(const QUrl& url, QPixmap *pixmap) +{ +#ifdef Q_ENABLE_PERFORMANCE_LOG + QmlPerfTimer perf; +#endif + + QString key = url.toString(); + bool ok = true; + if (!QPixmapCache::find(key,pixmap)) { +#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML + QString lf = toLocalFileOrQrc(url); + if (!lf.isEmpty()) { + QFile f(lf); + if (f.open(QIODevice::ReadOnly)) { + if (!readImage(&f, pixmap)) { + qWarning() << "Format error loading" << url; + *pixmap = QPixmap(); + ok = false; + } + } else { + *pixmap = QPixmap(); + ok = false; + } + } else +#endif + { + QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); + if (iter == qfxActiveNetworkReplies.end()) { + // API usage error + qWarning() << "QmlPixmapCache: URL not loaded" << url; + ok = false; + } else { + if ((*iter)->reply->error()) { + qWarning() << "Network error loading" << url << (*iter)->reply->errorString(); + *pixmap = QPixmap(); + ok = false; + } else if (!readImage((*iter)->reply, pixmap)) { + qWarning() << "Format error loading" << url; + *pixmap = QPixmap(); + ok = false; + } else { + if ((*iter)->refCount > 1) + (*iter)->pixmap = *pixmap; + } + (*iter)->release(); + } + } + QPixmapCache::insert(key, *pixmap); + } else { + ok = !pixmap->isNull(); +#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML + if (url.scheme()!=QLatin1String("file")) +#endif + // We may be the second finder. Still need to check for active replies. + { + QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); + if (iter != qfxActiveNetworkReplies.end()) + (*iter)->release(); + } + } + return ok; +} + +/*! + Starts a network request to load \a url. + + Returns a QNetworkReply if the image is not immediately available, otherwise + returns 0. Caller should connect to QNetworkReply::finished() to then call + find() when the image is available. + + The returned QNetworkReply will be deleted when all get() calls are + matched by a corresponding find() call. +*/ +QNetworkReply *QmlPixmapCache::get(QmlEngine *engine, const QUrl& url, QPixmap *pixmap) +{ +#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML + QString lf = toLocalFileOrQrc(url); + if (!lf.isEmpty()) { + QString key = url.toString(); + if (!QPixmapCache::find(key,pixmap)) { + QFile f(lf); + if (f.open(QIODevice::ReadOnly)) { + if (!readImage(&f, pixmap)) { + qWarning() << "Format error loading" << url; + *pixmap = QPixmap(); + } + } else + *pixmap = QPixmap(); + QPixmapCache::insert(key, *pixmap); + } + return 0; + } +#endif + + QString key = url.toString(); + if (QPixmapCache::find(key,pixmap)) { + return 0; + } + + QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); + if (iter == qfxActiveNetworkReplies.end()) { + QNetworkRequest req(url); + QSharedNetworkReply *item = new QSharedNetworkReply(engine->networkAccessManager()->get(req)); + iter = qfxActiveNetworkReplies.insert(key, item); + } else { + (*iter)->addRef(); + } + + return (*iter)->reply; +} + +/*! + Cancels a previous call to get(). + + May also cancel loading (eg. if no other pending request). + + Any connections from the QNetworkReply returned by get() to \a obj will be + disconnected. +*/ +void QmlPixmapCache::cancelGet(const QUrl& url, QObject* obj) +{ + QString key = url.toString(); + QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); + if (iter == qfxActiveNetworkReplies.end()) + return; + if (obj) + QObject::disconnect((*iter)->reply, 0, obj, 0); + (*iter)->release(); +} + +/*! + This function is mainly for test verification. It returns the number of + requests that are still unfinished. +*/ +int QmlPixmapCache::pendingRequests() +{ + return qfxActiveNetworkReplies.count(); +} + +QT_END_NAMESPACE diff --git a/src/declarative/util/qmlpixmapcache_p.h b/src/declarative/util/qmlpixmapcache_p.h new file mode 100644 index 0000000..e6ed452 --- /dev/null +++ b/src/declarative/util/qmlpixmapcache_p.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the 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 QMLPIXMAPCACHE_H +#define QMLPIXMAPCACHE_H + +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) +class QmlEngine; +class QNetworkReply; +class Q_DECLARATIVE_EXPORT QmlPixmapCache +{ +public: + static QNetworkReply *get(QmlEngine *, const QUrl& url, QPixmap *pixmap); + static void cancelGet(const QUrl& url, QObject* obj); + + static bool find(const QUrl& url, QPixmap *pixmap); // url must have been passed to QmlPixmapCache::get, and any returned reply finished. + + static int pendingRequests(); // mainly for test verification +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMLPIXMAPCACHE_H diff --git a/src/declarative/util/util.pri b/src/declarative/util/util.pri index 87ccb58..f955ef6 100644 --- a/src/declarative/util/util.pri +++ b/src/declarative/util/util.pri @@ -20,7 +20,8 @@ SOURCES += \ util/qmltimeline.cpp \ util/qmltimer.cpp \ util/qmlbind.cpp \ - util/qmlpropertymap.cpp + util/qmlpropertymap.cpp \ + util/qmlpixmapcache.cpp HEADERS += \ util/qmlview.h \ @@ -47,4 +48,5 @@ HEADERS += \ util/qmltimeline_p_p.h \ util/qmltimer_p.h \ util/qmlbind_p.h \ - util/qmlpropertymap_p.h + util/qmlpropertymap_p.h \ + util/qmlpixmapcache_p.h -- cgit v0.12 From 630d3b9ba9da12331c72406c311ca26f88c6061a Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 4 Nov 2009 13:21:38 +1000 Subject: Fix test after rename. --- tests/auto/declarative/declarative.pro | 2 +- .../declarative/qfxpixmapcache/data/exists.png | Bin 2738 -> 0 bytes .../declarative/qfxpixmapcache/data/exists1.png | Bin 2738 -> 0 bytes .../declarative/qfxpixmapcache/data/exists2.png | Bin 2738 -> 0 bytes .../declarative/qfxpixmapcache/qfxpixmapcache.pro | 9 - .../qfxpixmapcache/tst_qfxpixmapcache.cpp | 275 --------------------- .../declarative/qmlpixmapcache/data/exists.png | Bin 0 -> 2738 bytes .../declarative/qmlpixmapcache/data/exists1.png | Bin 0 -> 2738 bytes .../declarative/qmlpixmapcache/data/exists2.png | Bin 0 -> 2738 bytes .../declarative/qmlpixmapcache/qmlpixmapcache.pro | 9 + .../qmlpixmapcache/tst_qmlpixmapcache.cpp | 275 +++++++++++++++++++++ 11 files changed, 285 insertions(+), 285 deletions(-) delete mode 100644 tests/auto/declarative/qfxpixmapcache/data/exists.png delete mode 100644 tests/auto/declarative/qfxpixmapcache/data/exists1.png delete mode 100644 tests/auto/declarative/qfxpixmapcache/data/exists2.png delete mode 100644 tests/auto/declarative/qfxpixmapcache/qfxpixmapcache.pro delete mode 100644 tests/auto/declarative/qfxpixmapcache/tst_qfxpixmapcache.cpp create mode 100644 tests/auto/declarative/qmlpixmapcache/data/exists.png create mode 100644 tests/auto/declarative/qmlpixmapcache/data/exists1.png create mode 100644 tests/auto/declarative/qmlpixmapcache/data/exists2.png create mode 100644 tests/auto/declarative/qmlpixmapcache/qmlpixmapcache.pro create mode 100644 tests/auto/declarative/qmlpixmapcache/tst_qmlpixmapcache.cpp diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 321e91b..7e3bf1e 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -10,7 +10,7 @@ SUBDIRS += anchors \ numberformatter \ pathview \ qfxloader \ - qfxpixmapcache \ + qmlpixmapcache \ qfxtextedit \ qfxtextinput \ qfxwebview \ diff --git a/tests/auto/declarative/qfxpixmapcache/data/exists.png b/tests/auto/declarative/qfxpixmapcache/data/exists.png deleted file mode 100644 index 399bd0b..0000000 Binary files a/tests/auto/declarative/qfxpixmapcache/data/exists.png and /dev/null differ diff --git a/tests/auto/declarative/qfxpixmapcache/data/exists1.png b/tests/auto/declarative/qfxpixmapcache/data/exists1.png deleted file mode 100644 index 399bd0b..0000000 Binary files a/tests/auto/declarative/qfxpixmapcache/data/exists1.png and /dev/null differ diff --git a/tests/auto/declarative/qfxpixmapcache/data/exists2.png b/tests/auto/declarative/qfxpixmapcache/data/exists2.png deleted file mode 100644 index 399bd0b..0000000 Binary files a/tests/auto/declarative/qfxpixmapcache/data/exists2.png and /dev/null differ diff --git a/tests/auto/declarative/qfxpixmapcache/qfxpixmapcache.pro b/tests/auto/declarative/qfxpixmapcache/qfxpixmapcache.pro deleted file mode 100644 index 218eeff..0000000 --- a/tests/auto/declarative/qfxpixmapcache/qfxpixmapcache.pro +++ /dev/null @@ -1,9 +0,0 @@ -load(qttest_p4) -contains(QT_CONFIG,declarative): QT += declarative -QT += network -macx:CONFIG -= app_bundle - -SOURCES += tst_qfxpixmapcache.cpp - -# QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage -# LIBS += -lgcov diff --git a/tests/auto/declarative/qfxpixmapcache/tst_qfxpixmapcache.cpp b/tests/auto/declarative/qfxpixmapcache/tst_qfxpixmapcache.cpp deleted file mode 100644 index 88fbdab..0000000 --- a/tests/auto/declarative/qfxpixmapcache/tst_qfxpixmapcache.cpp +++ /dev/null @@ -1,275 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include -#include -#include -#include -#include - -// These don't let normal people run tests! -//#include "../network-settings.h" - -class tst_qfxpixmapcache : public QObject -{ - Q_OBJECT -public: - tst_qfxpixmapcache() : - thisfile("file://" __FILE__) - { - } - -private slots: - void single(); - void single_data(); - void parallel(); - void parallel_data(); - -private: - QmlEngine engine; - QUrl thisfile; -}; - - -static int slotters=0; - -class Slotter : public QObject -{ - Q_OBJECT -public: - Slotter() - { - gotslot = false; - slotters++; - } - bool gotslot; - -public slots: - void got() - { - gotslot = true; - --slotters; - if (slotters==0) - QTestEventLoop::instance().exitLoop(); - } -}; - -#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML -static const bool localfile_optimized = true; -#else -static const bool localfile_optimized = false; -#endif - -void tst_qfxpixmapcache::single_data() -{ - // Note, since QmlGraphicsPixmapCache is shared, tests affect each other! - // so use different files fore all test functions. - - QTest::addColumn("target"); - QTest::addColumn("incache"); - QTest::addColumn("exists"); - QTest::addColumn("neterror"); - - // File URLs are optimized - QTest::newRow("local") << thisfile.resolved(QUrl("data/exists.png")) << localfile_optimized << true << false; - QTest::newRow("local") << thisfile.resolved(QUrl("data/notexists.png")) << localfile_optimized << false << false; - QTest::newRow("remote") << QUrl("http://qt.nokia.com/logo.png") << false << true << false; - QTest::newRow("remote") << QUrl("http://qt.nokia.com/thereisnologo.png") << false << false << true; -} - -void tst_qfxpixmapcache::single() -{ - QFETCH(QUrl, target); - QFETCH(bool, incache); - QFETCH(bool, exists); - QFETCH(bool, neterror); - - if (neterror) { - QString expected = "Network error loading QUrl( \"" - +target.toString()+"\" ) \"Error downloading " - +target.toString()+" - server replied: Not Found\" "; - QTest::ignoreMessage(QtWarningMsg, expected.toLatin1()); - } - - QPixmap pixmap; - QVERIFY(pixmap.width() <= 0); // Check Qt assumption - QNetworkReply *reply= QmlGraphicsPixmapCache::get(&engine, target, &pixmap); - - if (incache) { - QVERIFY(!reply); - if (exists) - QVERIFY(pixmap.width() > 0); - else - QVERIFY(pixmap.width() <= 0); - } else { - QVERIFY(reply); - QVERIFY(pixmap.width() <= 0); - - Slotter getter; - connect(reply, SIGNAL(finished()), &getter, SLOT(got())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); - QVERIFY(getter.gotslot); - if (exists) { - QVERIFY(QmlGraphicsPixmapCache::find(target, &pixmap)); - QVERIFY(pixmap.width() > 0); - } else { - QVERIFY(!QmlGraphicsPixmapCache::find(target, &pixmap)); - QVERIFY(pixmap.width() <= 0); - } - } - - QCOMPARE(QmlGraphicsPixmapCache::pendingRequests(), 0); -} - -void tst_qfxpixmapcache::parallel_data() -{ - // Note, since QmlGraphicsPixmapCache is shared, tests affect each other! - // so use different files fore all test functions. - - QTest::addColumn("target1"); - QTest::addColumn("target2"); - QTest::addColumn("incache"); - QTest::addColumn("cancel"); // which one to cancel - QTest::addColumn("requests"); - - QTest::newRow("local") - << thisfile.resolved(QUrl("data/exists1.png")) - << thisfile.resolved(QUrl("data/exists2.png")) - << (localfile_optimized ? 2 : 0) - << -1 - << (localfile_optimized ? 0 : 2) - ; - - QTest::newRow("remote") - << QUrl("http://qt.nokia.com/images/template/checkbox-on.png") - << QUrl("http://qt.nokia.com/images/products/qt-logo/image_tile") - << 0 - << -1 - << 2 - ; - - QTest::newRow("remoteagain") - << QUrl("http://qt.nokia.com/images/template/checkbox-on.png") - << QUrl("http://qt.nokia.com/images/products/qt-logo/image_tile") - << 2 - << -1 - << 0 - ; - - QTest::newRow("remotecopy") - << QUrl("http://qt.nokia.com/images/template/checkbox-off.png") - << QUrl("http://qt.nokia.com/images/template/checkbox-off.png") - << 0 - << -1 - << 1 - ; - - QTest::newRow("remotecopycancel") - << QUrl("http://qt.nokia.com/rounded_block_bg.png") - << QUrl("http://qt.nokia.com/rounded_block_bg.png") - << 0 - << 0 - << 1 - ; -} - -void tst_qfxpixmapcache::parallel() -{ - QFETCH(QUrl, target1); - QFETCH(QUrl, target2); - QFETCH(int, incache); - QFETCH(int, cancel); - QFETCH(int, requests); - - QList targets; - targets << target1 << target2; - - QList replies; - QList getters; - for (int i=0; i 0); - getters.append(0); - } else { - QVERIFY(pixmap.width() <= 0); - getters.append(new Slotter); - connect(reply, SIGNAL(finished()), getters[i], SLOT(got())); - } - } - - QCOMPARE(incache+slotters, targets.count()); - QCOMPARE(QmlGraphicsPixmapCache::pendingRequests(), requests); - - if (cancel >= 0) { - QmlGraphicsPixmapCache::cancelGet(targets.at(cancel), getters[cancel]); - slotters--; - } - - if (slotters) { - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); - } - - for (int i=0; igotslot); - } else { - QVERIFY(getters[i]->gotslot); - QPixmap pixmap; - QVERIFY(QmlGraphicsPixmapCache::find(targets[i], &pixmap)); - QVERIFY(pixmap.width() > 0); - } - delete getters[i]; - } - } - - QCOMPARE(QmlGraphicsPixmapCache::pendingRequests(), 0); -} - -QTEST_MAIN(tst_qfxpixmapcache) - -#include "tst_qfxpixmapcache.moc" diff --git a/tests/auto/declarative/qmlpixmapcache/data/exists.png b/tests/auto/declarative/qmlpixmapcache/data/exists.png new file mode 100644 index 0000000..399bd0b Binary files /dev/null and b/tests/auto/declarative/qmlpixmapcache/data/exists.png differ diff --git a/tests/auto/declarative/qmlpixmapcache/data/exists1.png b/tests/auto/declarative/qmlpixmapcache/data/exists1.png new file mode 100644 index 0000000..399bd0b Binary files /dev/null and b/tests/auto/declarative/qmlpixmapcache/data/exists1.png differ diff --git a/tests/auto/declarative/qmlpixmapcache/data/exists2.png b/tests/auto/declarative/qmlpixmapcache/data/exists2.png new file mode 100644 index 0000000..399bd0b Binary files /dev/null and b/tests/auto/declarative/qmlpixmapcache/data/exists2.png differ diff --git a/tests/auto/declarative/qmlpixmapcache/qmlpixmapcache.pro b/tests/auto/declarative/qmlpixmapcache/qmlpixmapcache.pro new file mode 100644 index 0000000..423fa2f --- /dev/null +++ b/tests/auto/declarative/qmlpixmapcache/qmlpixmapcache.pro @@ -0,0 +1,9 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +QT += network +macx:CONFIG -= app_bundle + +SOURCES += tst_qmlpixmapcache.cpp + +# QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage +# LIBS += -lgcov diff --git a/tests/auto/declarative/qmlpixmapcache/tst_qmlpixmapcache.cpp b/tests/auto/declarative/qmlpixmapcache/tst_qmlpixmapcache.cpp new file mode 100644 index 0000000..88d9df5 --- /dev/null +++ b/tests/auto/declarative/qmlpixmapcache/tst_qmlpixmapcache.cpp @@ -0,0 +1,275 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include +#include + +// These don't let normal people run tests! +//#include "../network-settings.h" + +class tst_qmlpixmapcache : public QObject +{ + Q_OBJECT +public: + tst_qmlpixmapcache() : + thisfile("file://" __FILE__) + { + } + +private slots: + void single(); + void single_data(); + void parallel(); + void parallel_data(); + +private: + QmlEngine engine; + QUrl thisfile; +}; + + +static int slotters=0; + +class Slotter : public QObject +{ + Q_OBJECT +public: + Slotter() + { + gotslot = false; + slotters++; + } + bool gotslot; + +public slots: + void got() + { + gotslot = true; + --slotters; + if (slotters==0) + QTestEventLoop::instance().exitLoop(); + } +}; + +#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML +static const bool localfile_optimized = true; +#else +static const bool localfile_optimized = false; +#endif + +void tst_qmlpixmapcache::single_data() +{ + // Note, since QmlPixmapCache is shared, tests affect each other! + // so use different files fore all test functions. + + QTest::addColumn("target"); + QTest::addColumn("incache"); + QTest::addColumn("exists"); + QTest::addColumn("neterror"); + + // File URLs are optimized + QTest::newRow("local") << thisfile.resolved(QUrl("data/exists.png")) << localfile_optimized << true << false; + QTest::newRow("local") << thisfile.resolved(QUrl("data/notexists.png")) << localfile_optimized << false << false; + QTest::newRow("remote") << QUrl("http://qt.nokia.com/logo.png") << false << true << false; + QTest::newRow("remote") << QUrl("http://qt.nokia.com/thereisnologo.png") << false << false << true; +} + +void tst_qmlpixmapcache::single() +{ + QFETCH(QUrl, target); + QFETCH(bool, incache); + QFETCH(bool, exists); + QFETCH(bool, neterror); + + if (neterror) { + QString expected = "Network error loading QUrl( \"" + +target.toString()+"\" ) \"Error downloading " + +target.toString()+" - server replied: Not Found\" "; + QTest::ignoreMessage(QtWarningMsg, expected.toLatin1()); + } + + QPixmap pixmap; + QVERIFY(pixmap.width() <= 0); // Check Qt assumption + QNetworkReply *reply= QmlPixmapCache::get(&engine, target, &pixmap); + + if (incache) { + QVERIFY(!reply); + if (exists) + QVERIFY(pixmap.width() > 0); + else + QVERIFY(pixmap.width() <= 0); + } else { + QVERIFY(reply); + QVERIFY(pixmap.width() <= 0); + + Slotter getter; + connect(reply, SIGNAL(finished()), &getter, SLOT(got())); + QTestEventLoop::instance().enterLoop(10); + QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(getter.gotslot); + if (exists) { + QVERIFY(QmlPixmapCache::find(target, &pixmap)); + QVERIFY(pixmap.width() > 0); + } else { + QVERIFY(!QmlPixmapCache::find(target, &pixmap)); + QVERIFY(pixmap.width() <= 0); + } + } + + QCOMPARE(QmlPixmapCache::pendingRequests(), 0); +} + +void tst_qmlpixmapcache::parallel_data() +{ + // Note, since QmlPixmapCache is shared, tests affect each other! + // so use different files fore all test functions. + + QTest::addColumn("target1"); + QTest::addColumn("target2"); + QTest::addColumn("incache"); + QTest::addColumn("cancel"); // which one to cancel + QTest::addColumn("requests"); + + QTest::newRow("local") + << thisfile.resolved(QUrl("data/exists1.png")) + << thisfile.resolved(QUrl("data/exists2.png")) + << (localfile_optimized ? 2 : 0) + << -1 + << (localfile_optimized ? 0 : 2) + ; + + QTest::newRow("remote") + << QUrl("http://qt.nokia.com/images/template/checkbox-on.png") + << QUrl("http://qt.nokia.com/images/products/qt-logo/image_tile") + << 0 + << -1 + << 2 + ; + + QTest::newRow("remoteagain") + << QUrl("http://qt.nokia.com/images/template/checkbox-on.png") + << QUrl("http://qt.nokia.com/images/products/qt-logo/image_tile") + << 2 + << -1 + << 0 + ; + + QTest::newRow("remotecopy") + << QUrl("http://qt.nokia.com/images/template/checkbox-off.png") + << QUrl("http://qt.nokia.com/images/template/checkbox-off.png") + << 0 + << -1 + << 1 + ; + + QTest::newRow("remotecopycancel") + << QUrl("http://qt.nokia.com/rounded_block_bg.png") + << QUrl("http://qt.nokia.com/rounded_block_bg.png") + << 0 + << 0 + << 1 + ; +} + +void tst_qmlpixmapcache::parallel() +{ + QFETCH(QUrl, target1); + QFETCH(QUrl, target2); + QFETCH(int, incache); + QFETCH(int, cancel); + QFETCH(int, requests); + + QList targets; + targets << target1 << target2; + + QList replies; + QList getters; + for (int i=0; i 0); + getters.append(0); + } else { + QVERIFY(pixmap.width() <= 0); + getters.append(new Slotter); + connect(reply, SIGNAL(finished()), getters[i], SLOT(got())); + } + } + + QCOMPARE(incache+slotters, targets.count()); + QCOMPARE(QmlPixmapCache::pendingRequests(), requests); + + if (cancel >= 0) { + QmlPixmapCache::cancelGet(targets.at(cancel), getters[cancel]); + slotters--; + } + + if (slotters) { + QTestEventLoop::instance().enterLoop(10); + QVERIFY(!QTestEventLoop::instance().timeout()); + } + + for (int i=0; igotslot); + } else { + QVERIFY(getters[i]->gotslot); + QPixmap pixmap; + QVERIFY(QmlPixmapCache::find(targets[i], &pixmap)); + QVERIFY(pixmap.width() > 0); + } + delete getters[i]; + } + } + + QCOMPARE(QmlPixmapCache::pendingRequests(), 0); +} + +QTEST_MAIN(tst_qmlpixmapcache) + +#include "tst_qmlpixmapcache.moc" -- cgit v0.12 From 684fe7af0b6d8133973132fd5b6b01cc16957a10 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 4 Nov 2009 13:47:40 +1000 Subject: Add closestAngle function to Qt object to help with rotation animations. Includes test and doc. --- doc/src/declarative/globalobject.qdoc | 3 +++ src/declarative/qml/qmlengine.cpp | 20 ++++++++++++++++++++ src/declarative/qml/qmlengine_p.h | 1 + tests/auto/declarative/qmlqt/data/closestangle.qml | 12 ++++++++++++ tests/auto/declarative/qmlqt/tst_qmlqt.cpp | 18 ++++++++++++++++++ 5 files changed, 54 insertions(+) create mode 100644 tests/auto/declarative/qmlqt/data/closestangle.qml diff --git a/doc/src/declarative/globalobject.qdoc b/doc/src/declarative/globalobject.qdoc index f1d440f..06f6bdc 100644 --- a/doc/src/declarative/globalobject.qdoc +++ b/doc/src/declarative/globalobject.qdoc @@ -114,6 +114,9 @@ This function returns a color 50% darker than \c baseColor. See QColor::lighter( \image declarative-rect_tint.png Tint is most useful when a subtle change is intended to be conveyed due to some event; you can then use tinting to more effectively tune the visible color. +\section3 Qt.closestAngle(number fromAngle, number toAngle) +This function returns an equivalent angle to toAngle, such that the difference between fromAngle and toAngle is never more than 180 degrees. This is useful when animating angles using a NumberAnimation, which does not know about equivalent angles, when you always want to take the shortest path. + \section3 Qt.playSound(url soundLocation) This function plays the audio file located at \c soundLocation. Only .wav files are supported. diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index c562e02..2926791 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -147,6 +147,7 @@ QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) qtObject.setProperty(QLatin1String("tint"), scriptEngine.newFunction(QmlEnginePrivate::tint, 2)); //misc methods + qtObject.setProperty(QLatin1String("closestAngle"), scriptEngine.newFunction(QmlEnginePrivate::closestAngle, 2)); qtObject.setProperty(QLatin1String("playSound"), scriptEngine.newFunction(QmlEnginePrivate::playSound, 1)); qtObject.setProperty(QLatin1String("openUrlExternally"),scriptEngine.newFunction(desktopOpenUrl, 1)); @@ -810,6 +811,25 @@ QScriptValue QmlEnginePrivate::desktopOpenUrl(QScriptContext *ctxt, QScriptEngin return e->newVariant(QVariant(ret)); } +QScriptValue QmlEnginePrivate::closestAngle(QScriptContext *ctxt, QScriptEngine *e) +{ + if(ctxt->argumentCount() < 2) + return e->newVariant(QVariant(0.0)); + qreal a = ctxt->argument(0).toNumber(); + qreal b = ctxt->argument(1).toNumber(); + qreal ret = b; + qreal diff = b-a; + while(diff > 180.0){ + ret -= 360.0; + diff -= 360.0; + } + while(diff < -180.0){ + ret += 360.0; + diff += 360.0; + } + return e->newVariant(QVariant(ret)); +} + QScriptValue QmlEnginePrivate::tint(QScriptContext *ctxt, QScriptEngine *engine) { if(ctxt->argumentCount() != 2) diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index b050ef6..3c60b5c 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -269,6 +269,7 @@ public: static QScriptValue darker(QScriptContext*, QScriptEngine*); static QScriptValue tint(QScriptContext*, QScriptEngine*); + static QScriptValue closestAngle(QScriptContext*, QScriptEngine*); static QScriptValue playSound(QScriptContext*, QScriptEngine*); static QScriptValue desktopOpenUrl(QScriptContext*, QScriptEngine*); diff --git a/tests/auto/declarative/qmlqt/data/closestangle.qml b/tests/auto/declarative/qmlqt/data/closestangle.qml new file mode 100644 index 0000000..8f999e3 --- /dev/null +++ b/tests/auto/declarative/qmlqt/data/closestangle.qml @@ -0,0 +1,12 @@ +import Qt 4.6 + +Object { + property var testSame: Qt.closestAngle(0,1) + property var testLess: Qt.closestAngle(0,-359) + property var testMore: Qt.closestAngle(0,361) + property var testFail: Qt.closestAngle(0) + property var test5: Qt.closestAngle(0,1,2) + property var test6: Qt.closestAngle(123.45465768,1.11) + property var test7: Qt.closestAngle(-3.1415,1.11) +} + diff --git a/tests/auto/declarative/qmlqt/tst_qmlqt.cpp b/tests/auto/declarative/qmlqt/tst_qmlqt.cpp index 10402ae..cc9b94d 100644 --- a/tests/auto/declarative/qmlqt/tst_qmlqt.cpp +++ b/tests/auto/declarative/qmlqt/tst_qmlqt.cpp @@ -64,6 +64,7 @@ private slots: void lighter(); void darker(); void tint(); + void closestAngle(); void playSound(); void openUrlExternally(); @@ -249,6 +250,23 @@ void tst_qmlqt::tint() delete object; } +void tst_qmlqt::closestAngle() +{ + QmlComponent component(&engine, TEST_FILE("closestangle.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(qvariant_cast(object->property("testSame")), 1.0); + QCOMPARE(qvariant_cast(object->property("testLess")), 1.0); + QCOMPARE(qvariant_cast(object->property("testMore")), 1.0); + QCOMPARE(qvariant_cast(object->property("testFail")), 0.0); + QCOMPARE(qvariant_cast(object->property("test5")), 1.0); + QCOMPARE(qvariant_cast(object->property("test6")), 1.11); + QCOMPARE(qvariant_cast(object->property("test7")), 1.11); + + delete object; +} + void tst_qmlqt::playSound() { QEXPECT_FAIL("", "How do we test this?", Abort); -- cgit v0.12 From 99fe55b3b4c031f1288f9e1c16455ca08663059c Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 4 Nov 2009 14:15:20 +1000 Subject: Start on QmlXmlListModel autotest. --- tests/auto/declarative/declarative.pro | 1 + .../declarative/qmlxmllistmodel/data/model.qml | 10 +++ .../declarative/qmlxmllistmodel/data/model.xml | 56 +++++++++++++++ .../qmlxmllistmodel/qmlxmllistmodel.pro | 7 ++ .../qmlxmllistmodel/tst_qmlxmllistmodel.cpp | 80 ++++++++++++++++++++++ 5 files changed, 154 insertions(+) create mode 100644 tests/auto/declarative/qmlxmllistmodel/data/model.qml create mode 100644 tests/auto/declarative/qmlxmllistmodel/data/model.xml create mode 100644 tests/auto/declarative/qmlxmllistmodel/qmlxmllistmodel.pro create mode 100644 tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 7e3bf1e..f09d6cf 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -28,6 +28,7 @@ SUBDIRS += anchors \ qmlmetatype \ qmlpropertymap \ qmltimer \ + qmlxmllistmodel \ repeater \ sql \ states \ diff --git a/tests/auto/declarative/qmlxmllistmodel/data/model.qml b/tests/auto/declarative/qmlxmllistmodel/data/model.qml new file mode 100644 index 0000000..199a447 --- /dev/null +++ b/tests/auto/declarative/qmlxmllistmodel/data/model.qml @@ -0,0 +1,10 @@ +import Qt 4.6 + +XmlListModel { + source: "model.xml" + query: "/ListModel/ListElement" + XmlRole { name: "name"; query: "name/string()" } + XmlRole { name: "type"; query: "type/string()" } + XmlRole { name: "age"; query: "age/number()" } + XmlRole { name: "size"; query: "size/string()" } +} diff --git a/tests/auto/declarative/qmlxmllistmodel/data/model.xml b/tests/auto/declarative/qmlxmllistmodel/data/model.xml new file mode 100644 index 0000000..f1fe742 --- /dev/null +++ b/tests/auto/declarative/qmlxmllistmodel/data/model.xml @@ -0,0 +1,56 @@ + + + Polly + Parrot + 12 + Small + + + Penny + Turtle + 4 + Small + + + Warren + Rabbit + 2 + Small + + + Spot + Dog + 9 + Medium + + + Whiskers + Cat + 2 + Medium + + + Joey + Kangaroo + 1 + Medium + + + Kimba + Bunny + 65 + Large + + + Rover + Dog + 5 + Large + + + Tiny + Elephant + 15 + Large + + diff --git a/tests/auto/declarative/qmlxmllistmodel/qmlxmllistmodel.pro b/tests/auto/declarative/qmlxmllistmodel/qmlxmllistmodel.pro new file mode 100644 index 0000000..462723e --- /dev/null +++ b/tests/auto/declarative/qmlxmllistmodel/qmlxmllistmodel.pro @@ -0,0 +1,7 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative gui +macx:CONFIG -= app_bundle + +SOURCES += tst_qmlxmllistmodel.cpp + +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp b/tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp new file mode 100644 index 0000000..0fc9006 --- /dev/null +++ b/tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include +#include "../../../shared/util.h" + +class tst_qmlxmllistmodel : public QObject + +{ + Q_OBJECT +public: + tst_qmlxmllistmodel() {} + +private slots: + void buildModel(); + +private: + QmlEngine engine; +}; + +void tst_qmlxmllistmodel::buildModel() +{ + QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/model.qml")); + QmlXmlListModel *listModel = qobject_cast(component.create()); + QVERIFY(listModel != 0); + QTRY_COMPARE(listModel->count(), 9); + + QList roles; + roles << Qt::UserRole << Qt::UserRole + 1 << Qt::UserRole + 2 << Qt::UserRole + 3; + QHash data = listModel->data(3, roles); + QVERIFY(data.count() == 4); + QCOMPARE(data.value(Qt::UserRole).toString(), QLatin1String("Spot")); + QCOMPARE(data.value(Qt::UserRole+1).toString(), QLatin1String("Dog")); + QCOMPARE(data.value(Qt::UserRole+2).toInt(), 9); + QCOMPARE(data.value(Qt::UserRole+3).toString(), QLatin1String("Medium")); +} + +QTEST_MAIN(tst_qmlxmllistmodel) + +#include "tst_qmlxmllistmodel.moc" -- cgit v0.12 From 2c6d4485b7a0c8c819a225e56ca9a43ab4fcccf4 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 4 Nov 2009 14:15:46 +1000 Subject: Doc. --- src/declarative/qml/qmlmetaproperty.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index 8385352..f340612 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -558,6 +558,9 @@ QmlAbstractBinding *QmlMetaProperty::binding() const Ownership of \a newBinding transfers to QML. Ownership of the return value is assumed by the caller. + + \a flags is passed through to the binding and is used for the initial update (when + the binding sets the intial value, it will use these flags for the write). */ QmlAbstractBinding * QmlMetaProperty::setBinding(QmlAbstractBinding *newBinding, QmlMetaProperty::WriteFlags flags) const -- cgit v0.12