diff options
author | Joona Petrell <joona.t.petrell@nokia.com> | 2010-02-23 05:41:25 (GMT) |
---|---|---|
committer | Joona Petrell <joona.t.petrell@nokia.com> | 2010-02-23 07:34:07 (GMT) |
commit | 23fb8f6e4f3f6fe4ae7611de84f09cc0095e240c (patch) | |
tree | 1a750425c167e2184c565345ff76886ab1871d8c | |
parent | cb3cd645082bda7b5142ceff31e5795f2d047c39 (diff) | |
download | Qt-23fb8f6e4f3f6fe4ae7611de84f09cc0095e240c.zip Qt-23fb8f6e4f3f6fe4ae7611de84f09cc0095e240c.tar.gz Qt-23fb8f6e4f3f6fe4ae7611de84f09cc0095e240c.tar.bz2 |
Add missing NOTIFY signals to positioners, particles and webview
Reviewed-by: Aaron Kennedy
12 files changed, 521 insertions, 43 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicsparticles.cpp b/src/declarative/graphicsitems/qmlgraphicsparticles.cpp index 08fce74..e23f6f0 100644 --- a/src/declarative/graphicsitems/qmlgraphicsparticles.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsparticles.cpp @@ -188,13 +188,13 @@ void QmlGraphicsParticleMotionLinear::advance(QmlGraphicsParticle &p, int interv */ /*! - \qmlproperty int ParticleMotionGravity::xattractor - \qmlproperty int ParticleMotionGravity::yattractor + \qmlproperty qreal ParticleMotionGravity::xattractor + \qmlproperty qreal ParticleMotionGravity::yattractor These properties hold the x and y coordinates of the point attracting the particles. */ /*! - \qmlproperty int ParticleMotionGravity::acceleration + \qmlproperty qreal ParticleMotionGravity::acceleration This property holds the acceleration to apply to the particles. */ @@ -213,6 +213,31 @@ void QmlGraphicsParticleMotionLinear::advance(QmlGraphicsParticle &p, int interv \brief the acceleration to apply to the particles. */ +void QmlGraphicsParticleMotionGravity::setXAttractor(qreal x) +{ + if (qFuzzyCompare(x, _xAttr)) + return; + _xAttr = x; + emit xattractorChanged(); +} + +void QmlGraphicsParticleMotionGravity::setYAttractor(qreal y) +{ + if (qFuzzyCompare(y, _yAttr)) + return; + _yAttr = y; + emit yattractorChanged(); +} + +void QmlGraphicsParticleMotionGravity::setAcceleration(qreal accel) +{ + qreal scaledAccel = accel/1000000.0; + if (qFuzzyCompare(scaledAccel, _accel)) + return; + _accel = scaledAccel; + emit accelerationChanged(); +} + void QmlGraphicsParticleMotionGravity::advance(QmlGraphicsParticle &p, int interval) { qreal xdiff = p.x - _xAttr; @@ -276,14 +301,14 @@ Rectangle { */ /*! - \qmlproperty int QmlGraphicsParticleMotionWander::xvariance - \qmlproperty int QmlGraphicsParticleMotionWander::yvariance + \qmlproperty qreal QmlGraphicsParticleMotionWander::xvariance + \qmlproperty qreal QmlGraphicsParticleMotionWander::yvariance These properties set the amount to wander in the x and y directions. */ /*! - \qmlproperty int QmlGraphicsParticleMotionWander::pace + \qmlproperty qreal QmlGraphicsParticleMotionWander::pace This property holds how quickly the paricles will move from side to side. */ @@ -335,6 +360,33 @@ void QmlGraphicsParticleMotionWander::destroy(QmlGraphicsParticle &p) delete (Data*)p.data; } +void QmlGraphicsParticleMotionWander::setXVariance(qreal var) +{ + qreal scaledVar = var / 1000.0; + if (qFuzzyCompare(scaledVar, _xvariance)) + return; + _xvariance = scaledVar; + emit xvarianceChanged(); +} + +void QmlGraphicsParticleMotionWander::setYVariance(qreal var) +{ + qreal scaledVar = var / 1000.0; + if (qFuzzyCompare(scaledVar, _yvariance)) + return; + _yvariance = scaledVar; + emit yvarianceChanged(); +} + +void QmlGraphicsParticleMotionWander::setPace(qreal pace) +{ + qreal scaledPace = pace / 1000.0; + if (qFuzzyCompare(scaledPace, _pace)) + return; + _pace = scaledPace; + emit paceChanged(); +} + //--------------------------------------------------------------------------- class QmlGraphicsParticlesPainter : public QmlGraphicsItem { @@ -1125,7 +1177,10 @@ QmlGraphicsParticleMotion *QmlGraphicsParticles::motion() const void QmlGraphicsParticles::setMotion(QmlGraphicsParticleMotion *motion) { Q_D(QmlGraphicsParticles); + if (motion == d->motion) + return; d->motion = motion; + emit motionChanged(); } /*! diff --git a/src/declarative/graphicsitems/qmlgraphicsparticles_p.h b/src/declarative/graphicsitems/qmlgraphicsparticles_p.h index 7f0f9cd..8e66335 100644 --- a/src/declarative/graphicsitems/qmlgraphicsparticles_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsparticles_p.h @@ -77,27 +77,32 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotionGravity : public QmlGraphics { Q_OBJECT - Q_PROPERTY(int xattractor READ xAttractor WRITE setXAttractor) - Q_PROPERTY(int yattractor READ yAttractor WRITE setYAttractor) - Q_PROPERTY(int acceleration READ acceleration WRITE setAcceleration) + Q_PROPERTY(qreal xattractor READ xAttractor WRITE setXAttractor NOTIFY xattractorChanged) + Q_PROPERTY(qreal yattractor READ yAttractor WRITE setYAttractor NOTIFY yattractorChanged) + Q_PROPERTY(qreal acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged) public: QmlGraphicsParticleMotionGravity(QObject *parent=0) - : QmlGraphicsParticleMotion(parent), _xAttr(0), _yAttr(0), _accel(0.00005) {} + : QmlGraphicsParticleMotion(parent), _xAttr(0.0), _yAttr(0.0), _accel(0.00005) {} - int xAttractor() const { return _xAttr; } - void setXAttractor(int x) { _xAttr = x; } + qreal xAttractor() const { return _xAttr; } + void setXAttractor(qreal x); - int yAttractor() const { return _yAttr; } - void setYAttractor(int y) { _yAttr = y; } + qreal yAttractor() const { return _yAttr; } + void setYAttractor(qreal y); - int acceleration() const { return int(_accel * 1000000); } - void setAcceleration(int accel) { _accel = qreal(accel)/1000000.0; } + qreal acceleration() const { return _accel * 1000000; } + void setAcceleration(qreal accel); virtual void advance(QmlGraphicsParticle &, int interval); +Q_SIGNALS: + void xattractorChanged(); + void yattractorChanged(); + void accelerationChanged(); + private: - int _xAttr; - int _yAttr; + qreal _xAttr; + qreal _yAttr; qreal _accel; }; @@ -121,18 +126,23 @@ public: qreal y_var; }; - Q_PROPERTY(int xvariance READ xVariance WRITE setXVariance) - int xVariance() const { return int(_xvariance * 1000); } - void setXVariance(int var) { _xvariance = var / 1000.0; } + Q_PROPERTY(qreal xvariance READ xVariance WRITE setXVariance NOTIFY xvarianceChanged) + qreal xVariance() const { return _xvariance * 1000.0; } + void setXVariance(qreal var); - Q_PROPERTY(int yvariance READ yVariance WRITE setYVariance) - int yVariance() const { return int(_yvariance * 1000); } - void setYVariance(int var) { _yvariance = var / 1000.0; } + Q_PROPERTY(qreal yvariance READ yVariance WRITE setYVariance NOTIFY yvarianceChanged) + qreal yVariance() const { return _yvariance * 1000.0; } + void setYVariance(qreal var); - Q_PROPERTY(int pace READ pace WRITE setPace) - int pace() const { return int(_pace * 1000); } - void setPace(int pace) { _pace = pace / 1000.0; } + Q_PROPERTY(qreal pace READ pace WRITE setPace NOTIFY paceChanged) + qreal pace() const { return _pace * 1000.0; } + void setPace(qreal pace); +Q_SIGNALS: + void xvarianceChanged(); + void yvarianceChanged(); + void paceChanged(); + private: QmlGraphicsParticles *particles; qreal _xvariance; @@ -157,7 +167,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsParticles : public QmlGraphicsItem Q_PROPERTY(qreal angleDeviation READ angleDeviation WRITE setAngleDeviation NOTIFY angleDeviationChanged) Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity NOTIFY velocityChanged) Q_PROPERTY(qreal velocityDeviation READ velocityDeviation WRITE setVelocityDeviation NOTIFY velocityDeviationChanged) - Q_PROPERTY(QmlGraphicsParticleMotion *motion READ motion WRITE setMotion) + Q_PROPERTY(QmlGraphicsParticleMotion *motion READ motion WRITE setMotion NOTIFY motionChanged) Q_CLASSINFO("DefaultProperty", "motion") public: @@ -225,6 +235,7 @@ Q_SIGNALS: void velocityChanged(); void velocityDeviationChanged(); void emittingChanged(); + void motionChanged(); private Q_SLOTS: void imageLoaded(); diff --git a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp index 8adf239..805c912 100644 --- a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp +++ b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp @@ -138,7 +138,10 @@ QmlTransition *QmlGraphicsBasePositioner::move() const void QmlGraphicsBasePositioner::setMove(QmlTransition *mt) { Q_D(QmlGraphicsBasePositioner); + if (mt == d->moveTransition) + return; d->moveTransition = mt; + emit moveChanged(); } QmlTransition *QmlGraphicsBasePositioner::add() const @@ -150,7 +153,11 @@ QmlTransition *QmlGraphicsBasePositioner::add() const void QmlGraphicsBasePositioner::setAdd(QmlTransition *add) { Q_D(QmlGraphicsBasePositioner); + if (add == d->addTransition) + return; + d->addTransition = add; + emit addChanged(); } void QmlGraphicsBasePositioner::componentComplete() @@ -362,7 +369,7 @@ Column { move: Transition { NumberAnimation { properties: "y" - ease: "easeOutBounce" + easing: "easeOutBounce" } } } @@ -647,6 +654,24 @@ QmlGraphicsGrid::QmlGraphicsGrid(QmlGraphicsItem *parent) : many rows some rows will be of zero width. */ +void QmlGraphicsGrid::setColumns(const int columns) +{ + if (columns == _columns) + return; + _columns = columns; + prePositioning(); + emit columnsChanged(); +} + +void QmlGraphicsGrid::setRows(const int rows) +{ + if (rows == _rows) + return; + _rows = rows; + prePositioning(); + emit rowsChanged(); +} + void QmlGraphicsGrid::doPositioning() { int c=_columns,r=_rows;//Actual number of rows/columns diff --git a/src/declarative/graphicsitems/qmlgraphicspositioners_p.h b/src/declarative/graphicsitems/qmlgraphicspositioners_p.h index 1fb687a..2f905e5 100644 --- a/src/declarative/graphicsitems/qmlgraphicspositioners_p.h +++ b/src/declarative/graphicsitems/qmlgraphicspositioners_p.h @@ -62,8 +62,8 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsBasePositioner : public QmlGraphicsItem Q_OBJECT Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) - Q_PROPERTY(QmlTransition *move READ move WRITE setMove) - Q_PROPERTY(QmlTransition *add READ add WRITE setAdd) + Q_PROPERTY(QmlTransition *move READ move WRITE setMove NOTIFY moveChanged) + Q_PROPERTY(QmlTransition *add READ add WRITE setAdd NOTIFY addChanged) public: enum PositionerType { None = 0x0, Horizontal = 0x1, Vertical = 0x2, Both = 0x3 }; QmlGraphicsBasePositioner(PositionerType, QmlGraphicsItem *parent); @@ -86,6 +86,8 @@ protected: Q_SIGNALS: void spacingChanged(); + void moveChanged(); + void addChanged(); protected Q_SLOTS: virtual void doPositioning()=0; @@ -134,16 +136,21 @@ private: class Q_DECLARATIVE_EXPORT QmlGraphicsGrid : public QmlGraphicsBasePositioner { Q_OBJECT - Q_PROPERTY(int rows READ rows WRITE setRows) - Q_PROPERTY(int columns READ columns WRITE setcolumns) + Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowChanged) + Q_PROPERTY(int columns READ columns WRITE setColumns NOTIFY columnsChanged) public: QmlGraphicsGrid(QmlGraphicsItem *parent=0); int rows() const {return _rows;} - void setRows(const int rows){_rows = rows;} + void setRows(const int rows); int columns() const {return _columns;} - void setcolumns(const int columns){_columns = columns;} + void setColumns(const int columns); + +Q_SIGNALS: + void rowsChanged(); + void columnsChanged(); + protected Q_SLOTS: virtual void doPositioning(); diff --git a/src/declarative/graphicsitems/qmlgraphicswebview.cpp b/src/declarative/graphicsitems/qmlgraphicswebview.cpp index 0c21f75..f9bbb22 100644 --- a/src/declarative/graphicsitems/qmlgraphicswebview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicswebview.cpp @@ -483,6 +483,8 @@ void QmlGraphicsWebView::setRenderingEnabled(bool enabled) if (d->rendering == enabled) return; d->rendering = enabled; + emit renderingEnabledChanged(); + setCacheFrozen(!enabled); if (enabled) clearCache(); @@ -596,7 +598,10 @@ int QmlGraphicsWebView::pressGrabTime() const void QmlGraphicsWebView::setPressGrabTime(int ms) { Q_D(QmlGraphicsWebView); + if (d->pressTime == ms) + return; d->pressTime = ms; + emit pressGrabTimeChanged(); } void QmlGraphicsWebView::mousePressEvent(QGraphicsSceneMouseEvent *event) @@ -1024,6 +1029,7 @@ void QmlGraphicsWebView::setHtml(const QString &html, const QUrl &baseUrl) d->pending_url = baseUrl; d->pending_string = html; } + emit htmlChanged(); } void QmlGraphicsWebView::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl) @@ -1116,8 +1122,10 @@ QmlComponent *QmlGraphicsWebView::newWindowComponent() const void QmlGraphicsWebView::setNewWindowComponent(QmlComponent *newWindow) { Q_D(QmlGraphicsWebView); - delete d->newWindowComponent; + if (newWindow == d->newWindowComponent) + return; d->newWindowComponent = newWindow; + emit newWindowComponentChanged(); } @@ -1137,8 +1145,16 @@ QmlGraphicsItem *QmlGraphicsWebView::newWindowParent() const void QmlGraphicsWebView::setNewWindowParent(QmlGraphicsItem *parent) { Q_D(QmlGraphicsWebView); - delete d->newWindowParent; + if (parent == d->newWindowParent) + return; + if (d->newWindowParent && parent) { + QList<QGraphicsItem *> children = d->newWindowParent->childItems(); + for (int i = 0; i < children.count(); ++i) { + children.at(i)->setParentItem(parent); + } + } d->newWindowParent = parent; + emit newWindowParentChanged(); } /*! diff --git a/src/declarative/graphicsitems/qmlgraphicswebview_p.h b/src/declarative/graphicsitems/qmlgraphicswebview_p.h index 30ba0e4..ca63be9 100644 --- a/src/declarative/graphicsitems/qmlgraphicswebview_p.h +++ b/src/declarative/graphicsitems/qmlgraphicswebview_p.h @@ -97,9 +97,9 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsWebView : public QmlGraphicsPaintedItem Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged) Q_PROPERTY(QString statusText READ statusText NOTIFY statusTextChanged) - Q_PROPERTY(QString html READ html WRITE setHtml) + Q_PROPERTY(QString html READ html WRITE setHtml NOTIFY htmlChanged) - Q_PROPERTY(int pressGrabTime READ pressGrabTime WRITE setPressGrabTime) + Q_PROPERTY(int pressGrabTime READ pressGrabTime WRITE setPressGrabTime NOTIFY pressGrabTimeChanged) Q_PROPERTY(int preferredWidth READ preferredWidth WRITE setPreferredWidth NOTIFY preferredWidthChanged) Q_PROPERTY(int preferredHeight READ preferredHeight WRITE setPreferredHeight NOTIFY preferredHeightChanged) @@ -116,10 +116,10 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsWebView : public QmlGraphicsPaintedItem Q_PROPERTY(QmlListProperty<QObject> javaScriptWindowObjects READ javaScriptWindowObjects CONSTANT) - Q_PROPERTY(QmlComponent* newWindowComponent READ newWindowComponent WRITE setNewWindowComponent) - Q_PROPERTY(QmlGraphicsItem* newWindowParent READ newWindowParent WRITE setNewWindowParent) + Q_PROPERTY(QmlComponent* newWindowComponent READ newWindowComponent WRITE setNewWindowComponent NOTIFY newWindowComponentChanged) + Q_PROPERTY(QmlGraphicsItem* newWindowParent READ newWindowParent WRITE setNewWindowParent NOTIFY newWindowParentChanged) - Q_PROPERTY(bool renderingEnabled READ renderingEnabled WRITE setRenderingEnabled) + Q_PROPERTY(bool renderingEnabled READ renderingEnabled WRITE setRenderingEnabled NOTIFY renderingEnabledChanged) public: QmlGraphicsWebView(QmlGraphicsItem *parent=0); @@ -192,7 +192,12 @@ Q_SIGNALS: void titleChanged(const QString&); void iconChanged(); void statusTextChanged(); + void htmlChanged(); + void pressGrabTimeChanged(); void zoomFactorChanged(); + void newWindowComponentChanged(); + void newWindowParentChanged(); + void renderingEnabledChanged(); void loadStarted(); void loadFinished(); diff --git a/tests/auto/declarative/qmlgraphicsparticles/data/particlemotion.qml b/tests/auto/declarative/qmlgraphicsparticles/data/particlemotion.qml new file mode 100644 index 0000000..ace61fe --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsparticles/data/particlemotion.qml @@ -0,0 +1,33 @@ +import Qt 4.6 +Rectangle { + width: 240 + height: 320 + color: "black" + Particles { + objectName: "particles" + anchors.fill: parent + width: 1 + height: 1 + source: "particle.png" + lifeSpan: 5000 + count: 200 + angle: 270 + angleDeviation: 45 + velocity: 50 + velocityDeviation: 30 + ParticleMotionGravity { + objectName: "motionGravity" + yattractor: 1000 + xattractor: 0 + acceleration: 25 + } + } + resources: [ + ParticleMotionWander { + objectName: "motionWander" + xvariance: 30 + yvariance: 30 + pace: 100 + } + ] +}
\ No newline at end of file diff --git a/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp b/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp index 195c367..9436772 100644 --- a/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp +++ b/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ #include <QtTest/QtTest> +#include <QtTest/QSignalSpy> #include <qmlview.h> #include <private/qmlgraphicsparticles_p.h> @@ -50,6 +51,8 @@ public: private slots: void properties(); + void motionGravity(); + void motionWander(); void runs(); private: QmlView *createView(const QString &filename); @@ -98,6 +101,91 @@ void tst_QmlGraphicsParticles::properties() QCOMPARE(particles->emissionRate(), 12); } +void tst_QmlGraphicsParticles::motionGravity() +{ + QmlView *canvas = createView(SRCDIR "/data/particlemotion.qml"); + QVERIFY(canvas->rootObject()); + QmlGraphicsParticles* particles = canvas->rootObject()->findChild<QmlGraphicsParticles*>("particles"); + QVERIFY(particles); + + QmlGraphicsParticleMotionGravity* motionGravity = canvas->rootObject()->findChild<QmlGraphicsParticleMotionGravity*>("motionGravity"); + QCOMPARE(particles->motion(), motionGravity); + + QSignalSpy xattractorSpy(motionGravity, SIGNAL(xattractorChanged())); + QSignalSpy yattractorSpy(motionGravity, SIGNAL(yattractorChanged())); + QSignalSpy accelerationSpy(motionGravity, SIGNAL(accelerationChanged())); + + QCOMPARE(motionGravity->xAttractor(), 0.0); + QCOMPARE(motionGravity->yAttractor(), 1000.0); + QCOMPARE(motionGravity->acceleration(), 25.0); + + motionGravity->setXAttractor(20.0); + motionGravity->setYAttractor(10.0); + motionGravity->setAcceleration(10.0); + + QCOMPARE(motionGravity->xAttractor(), 20.0); + QCOMPARE(motionGravity->yAttractor(), 10.0); + QCOMPARE(motionGravity->acceleration(), 10.0); + + QCOMPARE(xattractorSpy.count(), 1); + QCOMPARE(yattractorSpy.count(), 1); + QCOMPARE(accelerationSpy.count(), 1); + + motionGravity->setXAttractor(20.0); + motionGravity->setYAttractor(10.0); + motionGravity->setAcceleration(10.0); + + QCOMPARE(xattractorSpy.count(), 1); + QCOMPARE(yattractorSpy.count(), 1); + QCOMPARE(accelerationSpy.count(), 1); +} + +void tst_QmlGraphicsParticles::motionWander() +{ + QmlView *canvas = createView(SRCDIR "/data/particlemotion.qml"); + QVERIFY(canvas->rootObject()); + QmlGraphicsParticles* particles = canvas->rootObject()->findChild<QmlGraphicsParticles*>("particles"); + QVERIFY(particles); + + QSignalSpy motionSpy(particles, SIGNAL(motionChanged())); + QmlGraphicsParticleMotionWander* motionWander = canvas->rootObject()->findChild<QmlGraphicsParticleMotionWander*>("motionWander"); + + particles->setMotion(motionWander); + QCOMPARE(particles->motion(),motionWander); + QCOMPARE(motionSpy.count(), 1); + + particles->setMotion(motionWander); + QCOMPARE(motionSpy.count(), 1); + + QSignalSpy xvarianceSpy(motionWander, SIGNAL(xvarianceChanged())); + QSignalSpy yvarianceSpy(motionWander, SIGNAL(yvarianceChanged())); + QSignalSpy paceSpy(motionWander, SIGNAL(paceChanged())); + + QCOMPARE(motionWander->xVariance(), 30.0); + QCOMPARE(motionWander->yVariance(), 30.0); + QCOMPARE(motionWander->pace(), 100.0); + + motionWander->setXVariance(20.0); + motionWander->setYVariance(10.0); + motionWander->setPace(10.0); + + QCOMPARE(motionWander->xVariance(), 20.0); + QCOMPARE(motionWander->yVariance(), 10.0); + QCOMPARE(motionWander->pace(), 10.0); + + QCOMPARE(xvarianceSpy.count(), 1); + QCOMPARE(yvarianceSpy.count(), 1); + QCOMPARE(paceSpy.count(), 1); + + motionWander->setXVariance(20.0); + motionWander->setYVariance(10.0); + motionWander->setPace(10.0); + + QCOMPARE(xvarianceSpy.count(), 1); + QCOMPARE(yvarianceSpy.count(), 1); + QCOMPARE(paceSpy.count(), 1); +} + void tst_QmlGraphicsParticles::runs() { QmlView *canvas = createView(SRCDIR "/data/particles.qml"); diff --git a/tests/auto/declarative/qmlgraphicspositioners/data/propertychanges.qml b/tests/auto/declarative/qmlgraphicspositioners/data/propertychanges.qml new file mode 100644 index 0000000..c3dc7bf --- /dev/null +++ b/tests/auto/declarative/qmlgraphicspositioners/data/propertychanges.qml @@ -0,0 +1,39 @@ +import Qt 4.6 + +Grid { + id: myGrid + + width: 270 + height: 270 + x: 3 + y: 3 + columns: 4 + spacing: 3 + + add: columnTransition + move: columnTransition + + Repeater { + model: 20 + Rectangle { color: "black"; width: 50; height: 50 } + } + + data: [ + Transition { + id: rowTransition + objectName: "rowTransition" + NumberAnimation { + properties: "x,y"; + easing: "easeOutInCubic" + } + }, + Transition { + id: columnTransition + objectName: "columnTransition" + NumberAnimation { + properties: "x,y"; + easing: "easeOutInCubic" + } + } + ] +} diff --git a/tests/auto/declarative/qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp b/tests/auto/declarative/qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp index 348f59b..5089dc5 100644 --- a/tests/auto/declarative/qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp +++ b/tests/auto/declarative/qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp @@ -42,6 +42,8 @@ #include <private/qlistmodelinterface_p.h> #include <qmlview.h> #include <private/qmlgraphicsrectangle_p.h> +#include <private/qmlgraphicspositioners_p.h> +#include <private/qmltransition_p.h> #include <qmlexpression.h> #include "../../../shared/util.h" @@ -61,7 +63,7 @@ private slots: void test_grid(); void test_grid_spacing(); void test_grid_animated(); - + void test_propertychanges(); void test_repeater(); private: QmlView *createView(const QString &filename); @@ -361,6 +363,61 @@ void tst_QmlGraphicsPositioners::test_grid_animated() QTRY_COMPARE(five->y(), 50.0); } +void tst_QmlGraphicsPositioners::test_propertychanges() +{ + QmlView *canvas = createView("data/propertychanges.qml"); + + QmlGraphicsGrid *grid = qobject_cast<QmlGraphicsGrid*>(canvas->rootObject()); + QmlTransition *rowTransition = canvas->rootObject()->findChild<QmlTransition*>("rowTransition"); + QmlTransition *columnTransition = canvas->rootObject()->findChild<QmlTransition*>("columnTransition"); + + QSignalSpy addSpy(grid, SIGNAL(addChanged())); + QSignalSpy moveSpy(grid, SIGNAL(moveChanged())); + QSignalSpy columnsSpy(grid, SIGNAL(columnsChanged())); + QSignalSpy rowsSpy(grid, SIGNAL(rowsChanged())); + + QVERIFY(grid); + QVERIFY(rowTransition); + QVERIFY(columnTransition); + QCOMPARE(grid->add(), columnTransition); + QCOMPARE(grid->move(), columnTransition); + QCOMPARE(grid->columns(), 4); + QCOMPARE(grid->rows(), -1); + + grid->setAdd(rowTransition); + grid->setMove(rowTransition); + QCOMPARE(grid->add(), rowTransition); + QCOMPARE(grid->move(), rowTransition); + QCOMPARE(addSpy.count(),1); + QCOMPARE(moveSpy.count(),1); + + grid->setAdd(rowTransition); + grid->setMove(rowTransition); + QCOMPARE(addSpy.count(),1); + QCOMPARE(moveSpy.count(),1); + + grid->setAdd(0); + grid->setMove(0); + QCOMPARE(addSpy.count(),2); + QCOMPARE(moveSpy.count(),2); + + grid->setColumns(-1); + grid->setRows(3); + QCOMPARE(grid->columns(), -1); + QCOMPARE(grid->rows(), 3); + QCOMPARE(columnsSpy.count(),1); + QCOMPARE(rowsSpy.count(),1); + + grid->setColumns(-1); + grid->setRows(3); + QCOMPARE(columnsSpy.count(),1); + QCOMPARE(rowsSpy.count(),1); + + grid->setColumns(2); + grid->setRows(2); + QCOMPARE(columnsSpy.count(),2); + QCOMPARE(rowsSpy.count(),2); +} void tst_QmlGraphicsPositioners::test_repeater() { diff --git a/tests/auto/declarative/qmlgraphicswebview/data/propertychanges.qml b/tests/auto/declarative/qmlgraphicswebview/data/propertychanges.qml new file mode 100644 index 0000000..3dd4e51 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicswebview/data/propertychanges.qml @@ -0,0 +1,33 @@ +import Qt 4.6 + +Item { + width: 240 + height: 160 + Grid { + anchors.fill: parent + objectName: "newWindowParent" + id: newWindowParent + } + + Row { + anchors.fill: parent + id: oldWindowParent + objectName: "oldWindowParent" + } + + Loader { + sourceComponent: webViewComponent + } + Component { + id: webViewComponent + WebView { + id: webView + objectName: "webView" + newWindowComponent: webViewComponent + newWindowParent: oldWindowParent + url: "basic.html" + renderingEnabled: true + pressGrabTime: 200 + } + } +}
\ No newline at end of file diff --git a/tests/auto/declarative/qmlgraphicswebview/tst_qmlgraphicswebview.cpp b/tests/auto/declarative/qmlgraphicswebview/tst_qmlgraphicswebview.cpp index f3c39f8..5815e22 100644 --- a/tests/auto/declarative/qmlgraphicswebview/tst_qmlgraphicswebview.cpp +++ b/tests/auto/declarative/qmlgraphicswebview/tst_qmlgraphicswebview.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ #include <qtest.h> +#include <QtTest/QSignalSpy> #include "../../../shared/util.h" #include <QtDeclarative/qmlengine.h> #include <QtDeclarative/qmlcomponent.h> @@ -69,6 +70,10 @@ private slots: void javaScript(); void cleanupTestCase(); void pixelCache(); + void newWindowParent(); + void newWindowComponent(); + void renderingEnabled(); + void pressGrabTime(); private: void checkNoErrors(const QmlComponent& component); @@ -335,6 +340,10 @@ void tst_qmlgraphicswebview::setHtml() QmlGraphicsWebView *wv = qobject_cast<QmlGraphicsWebView*>(component.create()); QVERIFY(wv != 0); QCOMPARE(wv->html(),QString("<html><head></head><body><p>This is a <b>string</b> set on the WebView</p></body></html>")); + + QSignalSpy spy(wv, SIGNAL(htmlChanged())); + wv->setHtml(QString("<html><head><title>Basic</title></head><body><p>text</p></body></html>")); + QCOMPARE(spy.count(),1); } void tst_qmlgraphicswebview::elementAreaAt() @@ -391,6 +400,106 @@ void tst_qmlgraphicswebview::pixelCache() QCOMPARE(wv->pixelsPainted(), expected*3); // repainted } +void tst_qmlgraphicswebview::newWindowParent() +{ + QmlComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + checkNoErrors(component); + QmlGraphicsItem *rootItem = qobject_cast<QmlGraphicsItem*>(component.create()); + QmlGraphicsWebView *wv = rootItem->findChild<QmlGraphicsWebView*>("webView"); + QVERIFY(rootItem != 0); + QVERIFY(wv != 0); + QTRY_COMPARE(wv->progress(), 1.0); + + QmlGraphicsItem* oldWindowParent = rootItem->findChild<QmlGraphicsItem*>("oldWindowParent"); + QCOMPARE(wv->newWindowParent(), oldWindowParent); + QSignalSpy newWindowParentSpy(wv, SIGNAL(newWindowParentChanged())); + + QmlGraphicsItem* newWindowParent = rootItem->findChild<QmlGraphicsItem*>("newWindowParent"); + wv->setNewWindowParent(newWindowParent); + QVERIFY(oldWindowParent); + QVERIFY(oldWindowParent->childItems().count() == 0); + QCOMPARE(wv->newWindowParent(), newWindowParent); + QCOMPARE(newWindowParentSpy.count(),1); + + wv->setNewWindowParent(newWindowParent); + QCOMPARE(newWindowParentSpy.count(),1); + + wv->setNewWindowParent(0); + QCOMPARE(newWindowParentSpy.count(),2); +} + +void tst_qmlgraphicswebview::newWindowComponent() +{ + QmlComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + checkNoErrors(component); + QmlGraphicsItem *rootItem = qobject_cast<QmlGraphicsItem*>(component.create()); + QmlGraphicsWebView *wv = rootItem->findChild<QmlGraphicsWebView*>("webView"); + QVERIFY(rootItem != 0); + QVERIFY(wv != 0); + QTRY_COMPARE(wv->progress(), 1.0); + + QmlComponent substituteComponent(&engine); + substituteComponent.setData("import Qt 4.6; WebView { objectName: 'newWebView'; url: 'basic.html'; }", QUrl::fromLocalFile("")); + QSignalSpy newWindowComponentSpy(wv, SIGNAL(newWindowComponentChanged())); + + wv->setNewWindowComponent(&substituteComponent); + QCOMPARE(wv->newWindowComponent(), &substituteComponent); + QCOMPARE(newWindowComponentSpy.count(),1); + + wv->setNewWindowComponent(&substituteComponent); + QCOMPARE(newWindowComponentSpy.count(),1); + + wv->setNewWindowComponent(0); + QCOMPARE(newWindowComponentSpy.count(),2); +} + +void tst_qmlgraphicswebview::renderingEnabled() +{ + QmlComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + checkNoErrors(component); + QmlGraphicsItem *rootItem = qobject_cast<QmlGraphicsItem*>(component.create()); + QmlGraphicsWebView *wv = rootItem->findChild<QmlGraphicsWebView*>("webView"); + QVERIFY(rootItem != 0); + QVERIFY(wv != 0); + QTRY_COMPARE(wv->progress(), 1.0); + + QVERIFY(wv->renderingEnabled()); + QSignalSpy renderingEnabledSpy(wv, SIGNAL(renderingEnabledChanged())); + + wv->setRenderingEnabled(false); + QVERIFY(!wv->renderingEnabled()); + QCOMPARE(renderingEnabledSpy.count(),1); + + wv->setRenderingEnabled(false); + QCOMPARE(renderingEnabledSpy.count(),1); + + wv->setRenderingEnabled(true); + QCOMPARE(renderingEnabledSpy.count(),2); +} + +void tst_qmlgraphicswebview::pressGrabTime() +{ + QmlComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + checkNoErrors(component); + QmlGraphicsItem *rootItem = qobject_cast<QmlGraphicsItem*>(component.create()); + QmlGraphicsWebView *wv = rootItem->findChild<QmlGraphicsWebView*>("webView"); + QVERIFY(rootItem != 0); + QVERIFY(wv != 0); + QTRY_COMPARE(wv->progress(), 1.0); + QCOMPARE(wv->pressGrabTime(), 200); + QSignalSpy pressGrabTimeSpy(wv, SIGNAL(pressGrabTimeChanged())); + + wv->setPressGrabTime(100); + QCOMPARE(wv->pressGrabTime(), 100); + QCOMPARE(pressGrabTimeSpy.count(),1); + + wv->setPressGrabTime(100); + QCOMPARE(pressGrabTimeSpy.count(),1); + + wv->setPressGrabTime(0); + QCOMPARE(pressGrabTimeSpy.count(),2); +} + QTEST_MAIN(tst_qmlgraphicswebview) #include "tst_qmlgraphicswebview.moc" |