diff options
-rw-r--r-- | src/declarative/items/qsgview.cpp | 3 | ||||
-rw-r--r-- | src/qtquick1/util/qdeclarativeview.cpp | 3 | ||||
-rw-r--r-- | tests/auto/declarative/qsgview/data/error1.qml | 5 | ||||
-rw-r--r-- | tests/auto/declarative/qsgview/data/resizemodeitem.qml | 5 | ||||
-rw-r--r-- | tests/auto/declarative/qsgview/qsgview.pro | 14 | ||||
-rw-r--r-- | tests/auto/declarative/qsgview/tst_qsgview.cpp | 197 | ||||
-rw-r--r-- | tests/auto/qtquick1/qdeclarativeview/tst_qdeclarativeview.cpp | 17 |
7 files changed, 242 insertions, 2 deletions
diff --git a/src/declarative/items/qsgview.cpp b/src/declarative/items/qsgview.cpp index 1d1118950a..416b803814 100644 --- a/src/declarative/items/qsgview.cpp +++ b/src/declarative/items/qsgview.cpp @@ -351,7 +351,8 @@ void QSGViewPrivate::setRootObject(QObject *obj) if (root) { initialSize = rootObjectSize(); - if (initialSize != q->size()) { + if ((resizeMode == QSGView::SizeViewToRootObject || !q->testAttribute(Qt::WA_Resized)) + && initialSize != q->size()) { if (!(q->parentWidget() && q->parentWidget()->layout())) { q->resize(initialSize); } diff --git a/src/qtquick1/util/qdeclarativeview.cpp b/src/qtquick1/util/qdeclarativeview.cpp index 396cd399aa..ae7e07d0ce 100644 --- a/src/qtquick1/util/qdeclarativeview.cpp +++ b/src/qtquick1/util/qdeclarativeview.cpp @@ -603,7 +603,8 @@ void QDeclarativeView::setRootObject(QObject *obj) if (d->root) { d->initialSize = d->rootObjectSize(); - if (d->initialSize != size()) { + if ((d->resizeMode == QDeclarativeView::SizeViewToRootObject || !testAttribute(Qt::WA_Resized)) + && d->initialSize != size()) { if (!(parentWidget() && parentWidget()->layout())) { resize(d->initialSize); } diff --git a/tests/auto/declarative/qsgview/data/error1.qml b/tests/auto/declarative/qsgview/data/error1.qml new file mode 100644 index 0000000000..09df679555 --- /dev/null +++ b/tests/auto/declarative/qsgview/data/error1.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +Rectangle { + nonExistentProperty: 5 +} diff --git a/tests/auto/declarative/qsgview/data/resizemodeitem.qml b/tests/auto/declarative/qsgview/data/resizemodeitem.qml new file mode 100644 index 0000000000..ed73009b26 --- /dev/null +++ b/tests/auto/declarative/qsgview/data/resizemodeitem.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 +Item { + width: 200 + height: 200 +} diff --git a/tests/auto/declarative/qsgview/qsgview.pro b/tests/auto/declarative/qsgview/qsgview.pro new file mode 100644 index 0000000000..e6cb0785bb --- /dev/null +++ b/tests/auto/declarative/qsgview/qsgview.pro @@ -0,0 +1,14 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative gui +macx:CONFIG -= app_bundle + +SOURCES += tst_qsgview.cpp + +symbian: { + importFiles.files = data + importFiles.path = . + DEPLOYMENT += importFiles +} else { + DEFINES += SRCDIR=\\\"$$PWD\\\" +} +QT += core-private gui-private declarative-private diff --git a/tests/auto/declarative/qsgview/tst_qsgview.cpp b/tests/auto/declarative/qsgview/tst_qsgview.cpp new file mode 100644 index 0000000000..f2913cbd63 --- /dev/null +++ b/tests/auto/declarative/qsgview/tst_qsgview.cpp @@ -0,0 +1,197 @@ +/**************************************************************************** +** +** Copyright (C) 2011 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$ +** GNU Lesser General Public License Usage +** 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. +** +** 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. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <qtest.h> +#include <QtTest/QSignalSpy> +#include <QtDeclarative/qdeclarativecomponent.h> +#include <QtDeclarative/qdeclarativecontext.h> +#include <QtDeclarative/qsgview.h> +#include <QtDeclarative/qsgitem.h> +#include "../../../shared/util.h" + +#ifdef Q_OS_SYMBIAN +// In Symbian OS test data is located in applications private dir +#define SRCDIR "." +#endif + +class tst_QSGView : public QObject + +{ + Q_OBJECT +public: + tst_QSGView(); + +private slots: + void resizemodeitem(); + void errors(); +}; + + +tst_QSGView::tst_QSGView() +{ +} + +void tst_QSGView::resizemodeitem() +{ + QWidget window; + QSGView *canvas = new QSGView(&window); + QVERIFY(canvas); + canvas->setResizeMode(QSGView::SizeRootObjectToView); + QCOMPARE(QSize(0,0), canvas->initialSize()); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/resizemodeitem.qml")); + QSGItem* item = qobject_cast<QSGItem*>(canvas->rootObject()); + QVERIFY(item); + window.show(); + + // initial size from root object + QCOMPARE(item->width(), 200.0); + QCOMPARE(item->height(), 200.0); + QCOMPARE(canvas->size(), QSize(200, 200)); + QCOMPARE(canvas->size(), canvas->sizeHint()); + QCOMPARE(canvas->size(), canvas->initialSize()); + + // size update from view + canvas->resize(QSize(80,100)); + QCOMPARE(item->width(), 80.0); + QCOMPARE(item->height(), 100.0); + QCOMPARE(canvas->size(), QSize(80, 100)); + QCOMPARE(canvas->size(), canvas->sizeHint()); + + canvas->setResizeMode(QSGView::SizeViewToRootObject); + + // size update from view disabled + canvas->resize(QSize(60,80)); + QCOMPARE(item->width(), 80.0); + QCOMPARE(item->height(), 100.0); + QCOMPARE(canvas->size(), QSize(60, 80)); + + // size update from root object + item->setWidth(250); + item->setHeight(350); + QCOMPARE(item->width(), 250.0); + QCOMPARE(item->height(), 350.0); + QTRY_COMPARE(canvas->size(), QSize(250, 350)); + QCOMPARE(canvas->size(), QSize(250, 350)); + QCOMPARE(canvas->size(), canvas->sizeHint()); + + // reset canvas + window.hide(); + delete canvas; + canvas = new QSGView(&window); + QVERIFY(canvas); + canvas->setResizeMode(QSGView::SizeViewToRootObject); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/resizemodeitem.qml")); + item = qobject_cast<QSGItem*>(canvas->rootObject()); + QVERIFY(item); + window.show(); + + // initial size for root object + QCOMPARE(item->width(), 200.0); + QCOMPARE(item->height(), 200.0); + QCOMPARE(canvas->size(), canvas->sizeHint()); + QCOMPARE(canvas->size(), canvas->initialSize()); + + // size update from root object + item->setWidth(80); + item->setHeight(100); + QCOMPARE(item->width(), 80.0); + QCOMPARE(item->height(), 100.0); + QTRY_COMPARE(canvas->size(), QSize(80, 100)); + QCOMPARE(canvas->size(), QSize(80, 100)); + QCOMPARE(canvas->size(), canvas->sizeHint()); + + // size update from root object disabled + canvas->setResizeMode(QSGView::SizeRootObjectToView); + item->setWidth(60); + item->setHeight(80); + QCOMPARE(canvas->width(), 80); + QCOMPARE(canvas->height(), 100); + QCOMPARE(QSize(item->width(), item->height()), canvas->sizeHint()); + + // size update from view + canvas->resize(QSize(200,300)); + QCOMPARE(item->width(), 200.0); + QCOMPARE(item->height(), 300.0); + QCOMPARE(canvas->size(), QSize(200, 300)); + QCOMPARE(canvas->size(), canvas->sizeHint()); + + delete canvas; + + // if we set a specific size for the view then it should keep that size + // for SizeRootObjectToView mode. + canvas = new QSGView(&window); + canvas->resize(300, 300); + canvas->setResizeMode(QSGView::SizeRootObjectToView); + QCOMPARE(QSize(0,0), canvas->initialSize()); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/resizemodeitem.qml")); + item = qobject_cast<QSGItem*>(canvas->rootObject()); + QVERIFY(item); + window.show(); + + // initial size from root object + QCOMPARE(item->width(), 300.0); + QCOMPARE(item->height(), 300.0); + QCOMPARE(canvas->size(), QSize(300, 300)); + QCOMPARE(canvas->size(), canvas->sizeHint()); + QCOMPARE(canvas->initialSize(), QSize(200, 200)); // initial object size + + delete canvas; +} + +static void silentErrorsMsgHandler(QtMsgType, const char *) +{ +} + +void tst_QSGView::errors() +{ + QSGView *canvas = new QSGView; + QVERIFY(canvas); + QtMsgHandler old = qInstallMsgHandler(silentErrorsMsgHandler); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/error1.qml")); + qInstallMsgHandler(old); + QVERIFY(canvas->status() == QSGView::Error); + QVERIFY(canvas->errors().count() == 1); + delete canvas; +} + + +QTEST_MAIN(tst_QSGView) + +#include "tst_qsgview.moc" diff --git a/tests/auto/qtquick1/qdeclarativeview/tst_qdeclarativeview.cpp b/tests/auto/qtquick1/qdeclarativeview/tst_qdeclarativeview.cpp index d98215126b..325071f489 100644 --- a/tests/auto/qtquick1/qdeclarativeview/tst_qdeclarativeview.cpp +++ b/tests/auto/qtquick1/qdeclarativeview/tst_qdeclarativeview.cpp @@ -192,6 +192,23 @@ void tst_QDeclarativeView::resizemodedeclarativeitem() QCOMPARE(sceneResizedSpy2.count(), 3); delete canvas; + + canvas = new QDeclarativeView(&window); + canvas->resize(300, 300); + canvas->setResizeMode(QDeclarativeView::SizeRootObjectToView); + QCOMPARE(QSize(0,0), canvas->initialSize()); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/resizemodedeclarativeitem.qml")); + declarativeItem = qobject_cast<QDeclarativeItem*>(canvas->rootObject()); + QVERIFY(declarativeItem); + window.show(); + + // initial size from root object + QCOMPARE(declarativeItem->width(), 300.0); + QCOMPARE(declarativeItem->height(), 300.0); + QCOMPARE(canvas->size(), QSize(300, 300)); + QCOMPARE(canvas->size(), canvas->sizeHint()); + QCOMPARE(canvas->initialSize(), QSize(200, 200)); + delete canvas; } void tst_QDeclarativeView::resizemodegraphicswidget() |