From 6ae0b924102384d088c9a7f9b43170cf0d2668bd Mon Sep 17 00:00:00 2001 From: Joona Petrell Date: Wed, 14 Apr 2010 17:15:22 +1000 Subject: Image with PreserveAspect enabled with either width or height defined should implicitly update the undefined axis to follow the aspect ratio Task-number: Reviewed-by: Martin Jones --- .../graphicsitems/qdeclarativeimage.cpp | 6 ++++++ .../qdeclarativeimage/data/aspectratio.qml | 6 ++++++ .../qdeclarativeimage/tst_qdeclarativeimage.cpp | 25 +++++++++++++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qdeclarativeimage/data/aspectratio.qml diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp index e4f3464..ca86637 100644 --- a/src/declarative/graphicsitems/qdeclarativeimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp @@ -311,6 +311,12 @@ void QDeclarativeImage::updatePaintedGeometry() d->paintedWidth = heightScale * qreal(d->pix.width()); d->paintedHeight = height(); } + if (widthValid() && !heightValid()) { + setImplicitHeight(d->paintedHeight); + } + if (heightValid() && !widthValid()) { + setImplicitWidth(d->paintedWidth); + } } else { d->paintedWidth = width(); d->paintedHeight = height(); diff --git a/tests/auto/declarative/qdeclarativeimage/data/aspectratio.qml b/tests/auto/declarative/qdeclarativeimage/data/aspectratio.qml new file mode 100644 index 0000000..402d33e --- /dev/null +++ b/tests/auto/declarative/qdeclarativeimage/data/aspectratio.qml @@ -0,0 +1,6 @@ +import Qt 4.7 + +Image { + source: "heart.png" + fillMode: Image.PreserveAspectFit; +} diff --git a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp index 52d7c16..53c208e 100644 --- a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp +++ b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp @@ -46,6 +46,7 @@ #include #include +#include #include #include #include @@ -80,6 +81,7 @@ private slots: void imageSource_data(); void clearSource(); void resized(); + void preserveAspectRatio(); void smooth(); void pixmap(); void svg(); @@ -209,10 +211,31 @@ void tst_qdeclarativeimage::resized() QCOMPARE(obj->width(), 300.); QCOMPARE(obj->height(), 300.); QCOMPARE(obj->fillMode(), QDeclarativeImage::Stretch); - delete obj; } + +void tst_qdeclarativeimage::preserveAspectRatio() +{ + QDeclarativeView *canvas = new QDeclarativeView(0); + canvas->show(); + + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/aspectratio.qml")); + QDeclarativeImage *image = qobject_cast(canvas->rootObject()); + QVERIFY(image != 0); + image->setWidth(80.0); + QCOMPARE(image->width(), 80.); + QCOMPARE(image->height(), 80.); + + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/aspectratio.qml")); + image = qobject_cast(canvas->rootObject()); + image->setHeight(60.0); + QVERIFY(image != 0); + QCOMPARE(image->height(), 60.); + QCOMPARE(image->width(), 60.); + delete canvas; +} + void tst_qdeclarativeimage::smooth() { QString componentStr = "import Qt 4.7\nImage { source: \"" SRCDIR "/data/colors.png\"; smooth: true; width: 300; height: 300 }"; -- cgit v0.12 From 62b264e90a48997e1736d7a335bad99e2c52a50d Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 14 Apr 2010 17:27:45 +1000 Subject: Reduce warnings at shutdown QTBUG-9799 Reviewed-by: Alexis Menard --- .../graphicsitems/qdeclarativevisualitemmodel.cpp | 2 +- src/declarative/qml/qdeclarativecomponent.cpp | 5 +++++ src/declarative/qml/qdeclarativecontext.cpp | 21 +++++++++++++++++++++ src/declarative/qml/qdeclarativecontext.h | 2 ++ src/declarative/qml/qdeclarativecontext_p.h | 2 +- src/gui/graphicsview/qgraphicsitem.cpp | 12 ++++++++++-- .../qdeclarativeecmascript/data/SpuriousWarning.qml | 5 +++++ .../data/noSpuriousWarningsAtShutdown.2.qml | 10 ++++++++++ .../tst_qdeclarativeecmascript.cpp | 18 ++++++++++++++++++ 9 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/SpuriousWarning.qml create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/noSpuriousWarningsAtShutdown.2.qml diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index dc325ce..03e4703 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -243,7 +243,7 @@ public: QString m_part; QDeclarativeComponent *m_delegate; - QDeclarativeContext *m_context; + QDeclarativeGuard m_context; QList m_roles; QHash m_roleNames; void ensureRoles() { diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index d319e8f..5f26ad5 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -597,6 +597,11 @@ QDeclarativeComponentPrivate::beginCreate(QDeclarativeContextData *context, cons return 0; } + if (!context->isValid()) { + qWarning("QDeclarativeComponent::beginCreate(): Cannot create a component in an invalid context"); + return 0; + } + if (context->engine != engine) { qWarning("QDeclarativeComponent::beginCreate(): Must create component in context from the same QDeclarativeEngine"); return 0; diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp index 9307bcc..ba4da95 100644 --- a/src/declarative/qml/qdeclarativecontext.cpp +++ b/src/declarative/qml/qdeclarativecontext.cpp @@ -202,6 +202,12 @@ QDeclarativeContext::~QDeclarativeContext() d->data->destroy(); } +bool QDeclarativeContext::isValid() const +{ + Q_D(const QDeclarativeContext); + return d->data && d->data->isValid(); +} + /*! Return the context's QDeclarativeEngine, or 0 if the context has no QDeclarativeEngine or the QDeclarativeEngine was destroyed. @@ -245,6 +251,11 @@ void QDeclarativeContext::setContextObject(QObject *object) return; } + if (!isValid()) { + qWarning("QDeclarativeContext: Cannot set context object on invalid context."); + return; + } + data->contextObject = object; } @@ -264,6 +275,11 @@ void QDeclarativeContext::setContextProperty(const QString &name, const QVariant return; } + if (!isValid()) { + qWarning("QDeclarativeContext: Cannot set property on invalid context."); + return; + } + if (data->engine) { bool ok; QObject *o = QDeclarativeEnginePrivate::get(data->engine)->toQObject(value, &ok); @@ -305,6 +321,11 @@ void QDeclarativeContext::setContextProperty(const QString &name, QObject *value return; } + if (!isValid()) { + qWarning("QDeclarativeContext: Cannot set property on invalid context."); + return; + } + if (!data->propertyNames) data->propertyNames = new QDeclarativeIntegerCache(data->engine); int idx = data->propertyNames->value(name); diff --git a/src/declarative/qml/qdeclarativecontext.h b/src/declarative/qml/qdeclarativecontext.h index 11b4771..94c9f4a 100644 --- a/src/declarative/qml/qdeclarativecontext.h +++ b/src/declarative/qml/qdeclarativecontext.h @@ -71,6 +71,8 @@ public: QDeclarativeContext(QDeclarativeContext *parent, QObject *objParent=0); virtual ~QDeclarativeContext(); + bool isValid() const; + QDeclarativeEngine *engine() const; QDeclarativeContext *parentContext() const; diff --git a/src/declarative/qml/qdeclarativecontext_p.h b/src/declarative/qml/qdeclarativecontext_p.h index 6059f72..7a16179 100644 --- a/src/declarative/qml/qdeclarativecontext_p.h +++ b/src/declarative/qml/qdeclarativecontext_p.h @@ -115,7 +115,7 @@ public: void destroy(); inline bool isValid() const { - return engine && (!isInternal || contextObject && !QObjectPrivate::get(contextObject)->wasDeleted); + return engine && (!isInternal || !contextObject || !QObjectPrivate::get(contextObject)->wasDeleted); } // My parent context and engine diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 150343e..9e0ec2e 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -1408,8 +1408,16 @@ QGraphicsItem::QGraphicsItem(QGraphicsItemPrivate &dd, QGraphicsItem *parent, */ QGraphicsItem::~QGraphicsItem() { - if (d_ptr->isObject) - QObjectPrivate::get(static_cast(this))->wasDeleted = true; + if (d_ptr->isObject) { + QGraphicsObject *o = static_cast(this); + QObjectPrivate *p = QObjectPrivate::get(o); + p->wasDeleted = true; + if (p->declarativeData) { + QDeclarativeData::destroyed(p->declarativeData, o); + p->declarativeData = 0; + } + } + d_ptr->inDestructor = 1; d_ptr->removeExtraItemCache(); diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/SpuriousWarning.qml b/tests/auto/declarative/qdeclarativeecmascript/data/SpuriousWarning.qml new file mode 100644 index 0000000..86c312c --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/SpuriousWarning.qml @@ -0,0 +1,5 @@ +import Qt 4.6 + +Item { + property int children: root.children.length +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/noSpuriousWarningsAtShutdown.2.qml b/tests/auto/declarative/qdeclarativeecmascript/data/noSpuriousWarningsAtShutdown.2.qml new file mode 100644 index 0000000..a762d6d --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/noSpuriousWarningsAtShutdown.2.qml @@ -0,0 +1,10 @@ +import Qt 4.6 + +Item { + id: root + + Item {} + + SpuriousWarning {} +} + diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 12a065e..35b4d99 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -2242,6 +2242,7 @@ void tst_qdeclarativeecmascript::qtbug_9792() // Test that we shut down without stupid warnings void tst_qdeclarativeecmascript::noSpuriousWarningsAtShutdown() { + { QDeclarativeComponent component(&engine, TEST_FILE("noSpuriousWarningsAtShutdown.qml")); QObject *o = component.create(); @@ -2254,6 +2255,23 @@ void tst_qdeclarativeecmascript::noSpuriousWarningsAtShutdown() qInstallMsgHandler(old); QCOMPARE(transientErrorsMsgCount, 0); + } + + + { + QDeclarativeComponent component(&engine, TEST_FILE("noSpuriousWarningsAtShutdown.2.qml")); + + QObject *o = component.create(); + + transientErrorsMsgCount = 0; + QtMsgHandler old = qInstallMsgHandler(transientErrorsMsgHandler); + + delete o; + + qInstallMsgHandler(old); + + QCOMPARE(transientErrorsMsgCount, 0); + } } QTEST_MAIN(tst_qdeclarativeecmascript) -- cgit v0.12 From 72fe46a6c72eb14cfc50cf59f372eb2872e867a0 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 14 Apr 2010 19:08:12 +1000 Subject: qdeclarativefocusscope works fine as a parallel test --- tests/auto/declarative/qdeclarativefocusscope/qdeclarativefocusscope.pro | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/auto/declarative/qdeclarativefocusscope/qdeclarativefocusscope.pro b/tests/auto/declarative/qdeclarativefocusscope/qdeclarativefocusscope.pro index 687c80c..ec64480 100644 --- a/tests/auto/declarative/qdeclarativefocusscope/qdeclarativefocusscope.pro +++ b/tests/auto/declarative/qdeclarativefocusscope/qdeclarativefocusscope.pro @@ -5,3 +5,4 @@ macx:CONFIG -= app_bundle DEFINES += SRCDIR=\\\"$$PWD\\\" +CONFIG += parallel_test -- cgit v0.12 From 9ae50ce40c1bc571c867bc698f2c53839c2c6932 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 14 Apr 2010 19:16:14 +1000 Subject: Revert "qdeclarativefocusscope works fine as a parallel test" Scratch that, qdeclarativefocusscope does not work fine as a parallel test. This reverts commit 72fe46a6c72eb14cfc50cf59f372eb2872e867a0. --- tests/auto/declarative/qdeclarativefocusscope/qdeclarativefocusscope.pro | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/auto/declarative/qdeclarativefocusscope/qdeclarativefocusscope.pro b/tests/auto/declarative/qdeclarativefocusscope/qdeclarativefocusscope.pro index ec64480..687c80c 100644 --- a/tests/auto/declarative/qdeclarativefocusscope/qdeclarativefocusscope.pro +++ b/tests/auto/declarative/qdeclarativefocusscope/qdeclarativefocusscope.pro @@ -5,4 +5,3 @@ macx:CONFIG -= app_bundle DEFINES += SRCDIR=\\\"$$PWD\\\" -CONFIG += parallel_test -- cgit v0.12