From c8e266aaf21f470fd45ac61244466583b503fda2 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 18 Feb 2010 16:05:50 +1000 Subject: QmlView API review. See QmlChanges.txt for details. --- demos/declarative/minehunt/main.cpp | 5 +- demos/declarative/minehunt/minehunt.qml | 14 +- doc/src/declarative/integrating.qdoc | 9 + examples/declarative/imageprovider/main.cpp | 2 +- examples/declarative/objectlistmodel/main.cpp | 2 +- src/declarative/QmlChanges.txt | 18 +- src/declarative/util/qmlview.cpp | 389 ++++++++++----------- src/declarative/util/qmlview.h | 49 ++- tests/auto/declarative/layouts/tst_layouts.cpp | 26 +- .../qmlanimations/tst_qmlanimations.cpp | 2 +- .../qmlgraphicsanchors/tst_qmlgraphicsanchors.cpp | 102 +++--- .../tst_qmlgraphicsgridview.cpp | 38 +- .../qmlgraphicsitem/tst_qmlgraphicsitem.cpp | 22 +- .../tst_qmlgraphicslistview.cpp | 60 ++-- .../tst_qmlgraphicsmouseregion.cpp | 13 +- .../tst_qmlgraphicsparticles.cpp | 13 +- .../tst_qmlgraphicspathview.cpp | 23 +- .../tst_qmlgraphicspositioners.cpp | 77 ++-- .../tst_qmlgraphicsrepeater.cpp | 35 +- .../tst_qmlgraphicstextedit.cpp | 45 ++- .../tst_qmlgraphicstextinput.cpp | 35 +- tools/qmlviewer/qfxtester.cpp | 2 +- tools/qmlviewer/qmlviewer.cpp | 37 +- tools/qmlviewer/qmlviewer.h | 3 +- 24 files changed, 499 insertions(+), 522 deletions(-) diff --git a/demos/declarative/minehunt/main.cpp b/demos/declarative/minehunt/main.cpp index c756e66..ac01196 100644 --- a/demos/declarative/minehunt/main.cpp +++ b/demos/declarative/minehunt/main.cpp @@ -167,10 +167,7 @@ MyWidget::MyWidget(int width, int height, QWidget *parent, Qt::WindowFlags flags canvas->setFixedSize(width, height); vbox->addWidget(canvas); - QFile file(fileName); - file.open(QFile::ReadOnly); - QString qml = file.readAll(); - canvas->setQml(qml, fileName); + canvas->setSource(QUrl::fromLocalFile(fileName)); QmlContext *ctxt = canvas->rootContext(); ctxt->addDefaultObject(this); diff --git a/demos/declarative/minehunt/minehunt.qml b/demos/declarative/minehunt/minehunt.qml index ff00d83..033a865 100644 --- a/demos/declarative/minehunt/minehunt.qml +++ b/demos/declarative/minehunt/minehunt.qml @@ -31,7 +31,7 @@ Item { anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter source: "pics/flag.png" - opacity: modelData.hasFlag + opacity: model.hasFlag opacity: Behavior { NumberAnimation { property: "opacity" @@ -47,16 +47,16 @@ Item { Text { anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter - text: modelData.hint + text: model.hint color: "white" font.bold: true - opacity: !modelData.hasMine && modelData.hint > 0 + opacity: !model.hasMine && model.hint > 0 } Image { anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter source: "pics/bomb.png" - opacity: modelData.hasMine + opacity: model.hasMine } Explosion { id: expl @@ -65,7 +65,7 @@ Item { states: [ State { name: "back" - when: modelData.flipped + when: model.flipped PropertyChanges { target: flipable; angle: 180 } } ] @@ -81,7 +81,7 @@ Item { else ret = 0; if (ret > 0) { - if (modelData.hasMine && modelData.flipped) { + if (model.hasMine && model.flipped) { ret*3; } else { ret; @@ -96,7 +96,7 @@ Item { matchProperties: "angle" } ScriptAction{ - script: if(modelData.hasMine && modelData.flipped){expl.explode = true;} + script: if(model.hasMine && model.flipped){expl.explode = true;} } } } diff --git a/doc/src/declarative/integrating.qdoc b/doc/src/declarative/integrating.qdoc index d93a6ff..b1095a7 100644 --- a/doc/src/declarative/integrating.qdoc +++ b/doc/src/declarative/integrating.qdoc @@ -84,6 +84,15 @@ QGraphicsObject *object = scene->addItem(object); \endcode +The following QGraphicsView options are recommended for optimal performance +of QML UIs: + +\list +\o QGraphicsView::setOptimizationFlags(QGraphicsView::DontSavePainterState); +\o QGraphicsView::setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); +\o QGraphicsScene::setItemIndexMethod(QGraphicsScene::NoIndex); +\endlist + \section1 Using existing QGraphicsWidgets in QML Another way of integrating with a QGraphicsView based UI is to expose your existing QGraphicsWidgets to QML, and constructing your scene in QML. Note that diff --git a/examples/declarative/imageprovider/main.cpp b/examples/declarative/imageprovider/main.cpp index 718e9bb..6e97513 100644 --- a/examples/declarative/imageprovider/main.cpp +++ b/examples/declarative/imageprovider/main.cpp @@ -75,7 +75,7 @@ int main(int argc, char ** argv) QApplication app(argc, argv); QmlView view; - view.setUrl(QUrl("qrc:view.qml")); + view.setSource(QUrl("qrc:view.qml")); view.engine()->addImageProvider("colors", new ColorImageProvider); diff --git a/examples/declarative/objectlistmodel/main.cpp b/examples/declarative/objectlistmodel/main.cpp index 3f2ac6d..d76a15d 100644 --- a/examples/declarative/objectlistmodel/main.cpp +++ b/examples/declarative/objectlistmodel/main.cpp @@ -59,7 +59,7 @@ int main(int argc, char ** argv) QApplication app(argc, argv); QmlView view; - view.setUrl(QUrl("qrc:view.qml")); + view.setSource(QUrl("qrc:view.qml")); QList dataList; dataList.append(new DataObject("Item 1", "red")); diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index e54ec95..3a709e8 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -1,6 +1,22 @@ +============================================================================= +The changes below are pre Qt 4.7.0 alpha +QmlView +------- +The API of QmlView has been narrowed and its role as a convenience class +reinforced. +- remove addItem() +- remove clearItems() - use 'delete root()' +- remove reset() +- resizeContent -> enum ResizeMode { SizeViewToRootObject, SizeRootObjectToView } +- remove setQml(), qml() +- rename setUrl(), ur() to setSource(), source() +- root() -> rootObject(), returns QGraphicsObject rather than QmlGraphicsItem +- remove quit() signal -> use quit() signal of engine() +- initialSize() signal removed +- Added status() to determine status of the internal QmlComponent -Listview: sectionExpression has been replaced by section.property, section.criteria +sectionExpression has been replaced by section.property, section.criteria ============================================================================= diff --git a/src/declarative/util/qmlview.cpp b/src/declarative/util/qmlview.cpp index 690924f..be67b16 100644 --- a/src/declarative/util/qmlview.cpp +++ b/src/declarative/util/qmlview.cpp @@ -64,6 +64,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -125,24 +126,24 @@ void FrameBreakAnimation::updateCurrentTime(int msecs) server->frameBreak(); } -class QmlViewPrivate +class QmlViewPrivate : public QGraphicsViewPrivate { + Q_DECLARE_PUBLIC(QmlView) public: - QmlViewPrivate(QmlView *w) - : q(w), root(0), component(0), resizable(false) {} + QmlViewPrivate() + : root(0), component(0), resizeMode(QmlView::SizeViewToRootObject) {} - QmlView *q; - QmlGraphicsItem *root; + QGuard root; + QGuard qmlRoot; QUrl source; - QString qml; QmlEngine engine; QmlComponent *component; QBasicTimer resizetimer; - QSize initialSize; - bool resizable; + mutable QSize initialSize; + QmlView::ResizeMode resizeMode; QTime frameTimer; void init(); @@ -154,9 +155,30 @@ public: \class QmlView \brief The QmlView class provides a widget for displaying a Qt Declarative user interface. - QmlView currently provides a minimal interface for displaying QML + Any QGraphicsObject or QmlGraphicsItem + created via QML can be placed on a standard QGraphicsScene and viewed with a standard + QGraphicsView. + + QmlView is a QGraphicsView subclass provided as a convenience for displaying QML files, and connecting between QML and C++ Qt objects. + QmlView performs the following functions: + + \list + \o Manages QmlComponent loading and object creation. + \o Initializes QGraphicsView for optimal performance with QML: + \list + \o QGraphicsView::setOptimizationFlags(QGraphicsView::DontSavePainterState); + \o QGraphicsView::setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); + \o QGraphicsScene::setItemIndexMethod(QGraphicsScene::NoIndex); + \endlist + \o Initializes QGraphicsView for QML key handling: + \list + \o QGraphicsView::viewport()->setFocusPolicy(Qt::NoFocus); + \o QGraphicsScene::setStickyFocus(true); + \endlist + \endlist + Typical usage: \code ... @@ -164,7 +186,7 @@ public: vbox->addWidget(view); QUrl url(fileName); - view->setUrl(url); + view->setSource(url); ... view->execute(); ... @@ -172,7 +194,17 @@ public: \endcode To receive errors related to loading and executing QML with QmlView, - you can connect to the errors() signal. + you can connect to the statusChanged() signal and monitor for QmlView::Error. + The errors are available via QmlView::errors(). +*/ + + +/*! \fn void QmlView::sceneResized(QSize size) + This signal is emitted when the view is resized to \a size. +*/ + +/*! \fn void QmlView::statusChanged(QmlView::Status status) + This signal is emitted when the component's current \l{QmlView::Status} {status} changes. */ /*! @@ -181,14 +213,16 @@ public: Constructs a QmlView with the given \a parent. */ QmlView::QmlView(QWidget *parent) -: QGraphicsView(parent), d(new QmlViewPrivate(this)) +: QGraphicsView(*(new QmlViewPrivate), parent) { + Q_D(QmlView); setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred); d->init(); } void QmlViewPrivate::init() { + Q_Q(QmlView); #ifdef Q_ENABLE_PERFORMANCE_LOG { QmlPerfTimer perf; @@ -212,61 +246,46 @@ void QmlViewPrivate::init() } /*! - The destructor clears the view's \l {QmlGraphicsItem} {items} and + The destructor clears the view's \l {QGraphicsObject} {items} and deletes the internal representation. - - \sa clearItems() */ QmlView::~QmlView() { - clearItems(); - delete d; d = 0; + Q_D(QmlView); + delete d->root; } /*! - Sets the source to the \a url. The QML string is set to - empty. + Sets the source to the \a url. + + Call \l execute() to load the QML and instantiate the component. + + \sa execute() */ -void QmlView::setUrl(const QUrl& url) +void QmlView::setSource(const QUrl& url) { + Q_D(QmlView); d->source = url; - d->qml = QString(); } /*! Returns the source URL, if set. - \sa setUrl() + \sa setSource() */ -QUrl QmlView::url() const +QUrl QmlView::source() const { + Q_D(const QmlView); return d->source; } /*! - Sets the source to the URL from the \a filename, and sets - the QML string to \a qml. - */ -void QmlView::setQml(const QString &qml, const QString &filename) -{ - d->source = QUrl::fromLocalFile(filename); - d->qml = qml; -} - -/*! - Returns the QML string. - */ -QString QmlView::qml() const -{ - return d->qml; -} - -/*! Returns a pointer to the QmlEngine used for instantiating QML Components. */ QmlEngine* QmlView::engine() { + Q_D(QmlView); return &d->engine; } @@ -279,21 +298,21 @@ QmlEngine* QmlView::engine() */ QmlContext* QmlView::rootContext() { + Q_D(QmlView); return d->engine.rootContext(); } /*! - Displays the Qt Declarative user interface. + Loads and instantiates the QML component set by the \l setSource() method. + + \sa setSource() */ void QmlView::execute() { - if (d->qml.isEmpty()) { - d->component = new QmlComponent(&d->engine, d->source, this); - } else { - d->component = new QmlComponent(&d->engine, this); - d->component->setData(d->qml.toUtf8(), d->source); - } - connect (&d->engine, SIGNAL (quit ()), this, SIGNAL (quit ())); + Q_D(QmlView); + delete d->root; + delete d->component; + d->component = new QmlComponent(&d->engine, d->source, this); if (!d->component->isLoading()) { continueExecute(); @@ -302,26 +321,100 @@ void QmlView::execute() } } +/*! + \enum QmlView::Status + + Specifies the loading status of the QmlView. + + \value Null This QmlView has no source set. + \value Ready This QmlView has loaded and created the QML component. + \value Loading This QmlView is loading network data. + \value Error An error has occured. Calling errorDescription() to retrieve a description. +*/ + +/*! + \property QmlView::status + The component's current \l{QmlView::Status} {status}. +*/ + +QmlView::Status QmlView::status() const +{ + Q_D(const QmlView); + if (!d->component) + return QmlView::Null; + + return QmlView::Status(d->component->status()); +} + +/*! + Return the list of errors that occured during the last compile or create + operation. An empty list is returned if isError() is not set. +*/ +QList QmlView::errors() const +{ + Q_D(const QmlView); + if (d->component) + return d->component->errors(); + return QList(); +} + + +/*! + \property QmlView::resizeMode + \brief whether the view should resize the canvas contents + + If this property is set to SizeViewToRootObject (the default), the view + resizes with the root item in the QML. + + If this property is set to SizeRootObjectToView, the view will + automatically resize the root item. + + Regardless of this property, the sizeHint of the view + is the initial size of the root item. Note though that + since QML may load dynamically, that size may change. + + \sa initialSize() +*/ + +void QmlView::setResizeMode(ResizeMode mode) +{ + Q_D(QmlView); + if (d->resizeMode == mode) + return; + + d->resizeMode = mode; + if (d->qmlRoot) { + if (d->resizeMode == SizeRootObjectToView) { + d->qmlRoot->setWidth(width()); + d->qmlRoot->setHeight(height()); + } else { + d->qmlRoot->setWidth(d->initialSize.width()); + d->qmlRoot->setHeight(d->initialSize.height()); + } + } +} + +QmlView::ResizeMode QmlView::resizeMode() const +{ + Q_D(const QmlView); + return d->resizeMode; +} /*! \internal */ void QmlView::continueExecute() { - disconnect(d->component, SIGNAL(statusChanged(QmlComponent::Status)), this, SLOT(continueExecute())); + Q_D(QmlView); - if (!d->component) { - qWarning() << "Error in loading" << d->source; - return; - } + disconnect(d->component, SIGNAL(statusChanged(QmlComponent::Status)), this, SLOT(continueExecute())); - if(d->component->isError()) { + if (d->component->isError()) { QList errorList = d->component->errors(); foreach (const QmlError &error, errorList) { qWarning() << error; } - emit errors(errorList); - + emit statusChanged(status()); return; } @@ -332,8 +425,7 @@ void QmlView::continueExecute() foreach (const QmlError &error, errorList) { qWarning() << error; } - emit errors(errorList); - + emit statusChanged(status()); return; } @@ -345,24 +437,27 @@ void QmlView::continueExecute() QPerformanceLog::displayData(); QPerformanceLog::clear(); d->root = item; + d->qmlRoot = item; connect(item, SIGNAL(widthChanged()), this, SLOT(sizeChanged())); connect(item, SIGNAL(heightChanged()), this, SLOT(sizeChanged())); - if (d->initialSize.height() <= 0 && d->root->width() > 0) - d->initialSize.setWidth(d->root->width()); - if (d->initialSize.height() <= 0 && d->root->height() > 0) - d->initialSize.setHeight(d->root->height()); + if (d->initialSize.height() <= 0 && d->qmlRoot->width() > 0) + d->initialSize.setWidth(d->qmlRoot->width()); + if (d->initialSize.height() <= 0 && d->qmlRoot->height() > 0) + d->initialSize.setHeight(d->qmlRoot->height()); resize(d->initialSize); - if (d->resizable) { - d->root->setWidth(width()); - d->root->setHeight(height()); + if (d->resizeMode == SizeRootObjectToView) { + d->qmlRoot->setWidth(width()); + d->qmlRoot->setHeight(height()); } else { - QSize sz(d->root->width(),d->root->height()); + QSize sz(d->qmlRoot->width(),d->qmlRoot->height()); emit sceneResized(sz); resize(sz); } updateGeometry(); - emit initialSize(d->initialSize); + } else if (QGraphicsObject *item = qobject_cast(obj)) { + d->scene.addItem(item); + qWarning() << "QmlView::resizeMode is not honored for components of type QGraphicsObject"; } else if (QWidget *wid = qobject_cast(obj)) { window()->setAttribute(Qt::WA_OpaquePaintEvent, false); window()->setAttribute(Qt::WA_NoSystemBackground, false); @@ -377,41 +472,32 @@ void QmlView::continueExecute() } layout()->addWidget(wid); emit sceneResized(wid->size()); - emit initialSize(wid->size()); } } + emit statusChanged(status()); } -/*! \fn void QmlView::sceneResized(QSize size) - This signal is emitted when the view is resized to \a size. - */ - -/*! \fn void QmlView::initialSize(QSize size) - This signal is emitted when the initial \a size of the root item is known. - */ - -/*! \fn void QmlView::errors(const QList &errors) - This signal is emitted when the qml loaded contains \a errors. - */ - /*! \internal */ void QmlView::sizeChanged() { + Q_D(QmlView); // delay, so we catch both width and height changing. d->resizetimer.start(0,this); } /*! + \internal If the \l {QTimerEvent} {timer event} \a e is this view's resize timer, sceneResized() is emitted. */ void QmlView::timerEvent(QTimerEvent* e) { + Q_D(QmlView); if (!e || e->timerId() == d->resizetimer.timerId()) { - if (d->root) { - QSize sz(d->root->width(),d->root->height()); + if (d->qmlRoot) { + QSize sz(d->qmlRoot->width(),d->qmlRoot->height()); emit sceneResized(sz); //if (!d->resizable) //resize(sz); @@ -421,147 +507,47 @@ void QmlView::timerEvent(QTimerEvent* e) } } -// modelled on QScrollArea::widgetResizable -/*! - \property QmlView::contentResizable - \brief whether the view should resize the canvas contents - - If this property is set to false (the default), the view - resizes with the root item in the QML. - - If this property is set to true, the view will - automatically resize the root item. - - Regardless of this property, the sizeHint of the view - is the initial size of the root item. Note though that - since QML may load dynamically, that size may change. - - \sa initialSize() -*/ - -void QmlView::setContentResizable(bool on) -{ - if (d->resizable != on) { - d->resizable = on; - if (d->root) { - if (on) { - d->root->setWidth(width()); - d->root->setHeight(height()); - } else { - d->root->setWidth(d->initialSize.width()); - d->root->setHeight(d->initialSize.height()); - } - } - } -} - -bool QmlView::contentResizable() const -{ - return d->resizable; -} - - /*! + \internal The size hint is the size of the root item. */ QSize QmlView::sizeHint() const { - if (d->root) { + Q_D(const QmlView); + if (d->qmlRoot) { if (d->initialSize.width() <= 0) - d->initialSize.setWidth(d->root->width()); + d->initialSize.setWidth(d->qmlRoot->width()); if (d->initialSize.height() <= 0) - d->initialSize.setHeight(d->root->height()); + d->initialSize.setHeight(d->qmlRoot->height()); } return d->initialSize; } /*! - Creates a \l{QmlComponent} {component} from the \a qml - string, and returns it as an \l {QmlGraphicsItem} {item}. If the - \a parent item is provided, it becomes the new item's - parent. \a parent should be in this view's item hierarchy. + Returns the view's root \l {QGraphicsObject} {item}. */ -QmlGraphicsItem* QmlView::addItem(const QString &qml, QmlGraphicsItem* parent) -{ - if (!d->root) - return 0; - - QmlComponent component(&d->engine); - component.setData(qml.toUtf8(), QUrl()); - if(d->component->isError()) { - QList errorList = d->component->errors(); - foreach (const QmlError &error, errorList) { - qWarning() << error; - } - emit errors(errorList); - - return 0; - } - - QObject *obj = component.create(); - if(d->component->isError()) { - QList errorList = d->component->errors(); - foreach (const QmlError &error, errorList) { - qWarning() << error; - } - emit errors(errorList); - - return 0; - } - - if (obj){ - QmlGraphicsItem *item = static_cast(obj); - if (!parent) - parent = d->root; - - item->setParentItem(parent); - return item; - } - return 0; -} - -/*! - Deletes the view's \l {QmlGraphicsItem} {items} and clears the \l {QmlEngine} - {QML engine's} Component cache. - */ -void QmlView::reset() -{ - clearItems(); - d->engine.clearComponentCache(); - d->initialSize = QSize(); -} - -/*! - Deletes the view's \l {QmlGraphicsItem} {items}. - */ -void QmlView::clearItems() -{ - if (!d->root) - return; - delete d->root; - d->root = 0; -} - -/*! - Returns the view's root \l {QmlGraphicsItem} {item}. - */ -QmlGraphicsItem *QmlView::root() const +QGraphicsObject *QmlView::rootObject() const { + Q_D(const QmlView); return d->root; } /*! + \internal This function handles the \l {QResizeEvent} {resize event} \a e. */ void QmlView::resizeEvent(QResizeEvent *e) { - if (d->resizable && d->root) { - d->root->setWidth(width()); - d->root->setHeight(height()); + Q_D(QmlView); + if (d->resizeMode == SizeRootObjectToView && d->qmlRoot) { + d->qmlRoot->setWidth(width()); + d->qmlRoot->setHeight(height()); } - if (d->root) { - setSceneRect(QRectF(0, 0, d->root->width(), d->root->height())); + if (d->qmlRoot) { + setSceneRect(QRectF(0, 0, d->qmlRoot->width(), d->qmlRoot->height())); + } else if (d->root) { + setSceneRect(d->root->boundingRect()); } else { setSceneRect(rect()); } @@ -569,10 +555,11 @@ void QmlView::resizeEvent(QResizeEvent *e) } /*! - \reimp + \internal */ void QmlView::paintEvent(QPaintEvent *event) { + Q_D(QmlView); int time = 0; if (frameRateDebug() || QmlViewDebugServer::isDebuggingEnabled()) time = d->frameTimer.restart(); diff --git a/src/declarative/util/qmlview.h b/src/declarative/util/qmlview.h index f4f58fd..556a42c 100644 --- a/src/declarative/util/qmlview.h +++ b/src/declarative/util/qmlview.h @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#ifndef QFXVIEW_H -#define QFXVIEW_H +#ifndef QMLVIEW_H +#define QMLVIEW_H #include #include @@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QmlGraphicsItem; +class QGraphicsObject; class QmlEngine; class QmlContext; class QmlError; @@ -62,35 +62,38 @@ class QmlViewPrivate; class Q_DECLARATIVE_EXPORT QmlView : public QGraphicsView { Q_OBJECT - Q_PROPERTY(bool contentResizable READ contentResizable WRITE setContentResizable) + Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode) + Q_PROPERTY(Status status READ status NOTIFY statusChanged) + + Q_DECLARE_PRIVATE(QmlView) + public: explicit QmlView(QWidget *parent = 0); - virtual ~QmlView(); - void setUrl(const QUrl&); - QUrl url() const; - void setQml(const QString &qml, const QString &filename=QString()); - QString qml() const; + QUrl source() const; + void setSource(const QUrl&); + QmlEngine* engine(); QmlContext* rootContext(); - virtual void execute(); - virtual void reset(); + void execute(); - virtual QmlGraphicsItem* addItem(const QString &qml, QmlGraphicsItem* parent=0); - virtual void clearItems(); + QGraphicsObject *rootObject() const; - virtual QmlGraphicsItem *root() const; + enum ResizeMode { SizeViewToRootObject, SizeRootObjectToView }; + ResizeMode resizeMode() const; + void setResizeMode(ResizeMode); + + enum Status { Null, Ready, Loading, Error }; + Status status() const; + + QList errors() const; - void setContentResizable(bool); - bool contentResizable() const; QSize sizeHint() const; Q_SIGNALS: - void initialSize(QSize size); - void sceneResized(QSize size); - void errors(const QList &error); - void quit (); + void sceneResized(QSize size); // ??? + void statusChanged(QmlView::Status); private Q_SLOTS: void continueExecute(); @@ -100,14 +103,10 @@ protected: virtual void resizeEvent(QResizeEvent *); virtual void paintEvent(QPaintEvent *event); void timerEvent(QTimerEvent*); - -private: - friend class QmlViewPrivate; - QmlViewPrivate *d; }; QT_END_NAMESPACE QT_END_HEADER -#endif // QFXVIEW_H +#endif // QMLVIEW_H diff --git a/tests/auto/declarative/layouts/tst_layouts.cpp b/tests/auto/declarative/layouts/tst_layouts.cpp index 0f832bf..54ca761 100644 --- a/tests/auto/declarative/layouts/tst_layouts.cpp +++ b/tests/auto/declarative/layouts/tst_layouts.cpp @@ -69,10 +69,10 @@ void tst_QmlGraphicsLayouts::test_qml() canvas->execute(); qApp->processEvents(); - QmlGraphicsLayoutItem *left = static_cast(canvas->root()->findChild("left")); + QmlGraphicsLayoutItem *left = static_cast(canvas->rootObject()->findChild("left")); QVERIFY(left != 0); - QmlGraphicsLayoutItem *right = static_cast(canvas->root()->findChild("right")); + QmlGraphicsLayoutItem *right = static_cast(canvas->rootObject()->findChild("right")); QVERIFY(right != 0); qreal l = QApplication::style()->pixelMetric(QStyle::PM_LayoutLeftMargin); @@ -81,9 +81,13 @@ void tst_QmlGraphicsLayouts::test_qml() qreal b = QApplication::style()->pixelMetric(QStyle::PM_LayoutBottomMargin); QVERIFY2(l == r && r == t && t == b, "Test assumes equal margins."); qreal gvMargin = l; + + QmlGraphicsItem *rootItem = qobject_cast(canvas->rootObject()); + QVERIFY(rootItem != 0); + //Preferred Size - canvas->root()->setWidth(300 + 2*gvMargin); - canvas->root()->setHeight(300 + 2*gvMargin); + rootItem->setWidth(300 + 2*gvMargin); + rootItem->setHeight(300 + 2*gvMargin); QCOMPARE(left->x(), gvMargin); QCOMPARE(left->y(), gvMargin); @@ -96,8 +100,8 @@ void tst_QmlGraphicsLayouts::test_qml() QCOMPARE(right->height(), 300.0); //Minimum Size - canvas->root()->setWidth(10+2*gvMargin); - canvas->root()->setHeight(10+2*gvMargin); + rootItem->setWidth(10+2*gvMargin); + rootItem->setHeight(10+2*gvMargin); QCOMPARE(left->x(), gvMargin); QCOMPARE(left->width(), 100.0); @@ -111,8 +115,8 @@ void tst_QmlGraphicsLayouts::test_qml() /*Note that if set to maximum size (or above) GraphicsLinearLayout behavior is to shrink them down to preferred size. So the exact maximum size can't be used*/ - canvas->root()->setWidth(670 + 2*gvMargin); - canvas->root()->setHeight(300 + 2*gvMargin); + rootItem->setWidth(670 + 2*gvMargin); + rootItem->setHeight(300 + 2*gvMargin); QCOMPARE(left->x(), gvMargin); QCOMPARE(left->width(), 270.0); @@ -133,11 +137,7 @@ void tst_QmlGraphicsLayouts::test_cpp() QmlView *tst_QmlGraphicsLayouts::createView(const QString &filename) { QmlView *canvas = new QmlView(0); - - QFile file(filename); - file.open(QFile::ReadOnly); - QString qml = file.readAll(); - canvas->setQml(qml, filename); + canvas->setSource(QUrl::fromLocalFile(filename)); return canvas; } diff --git a/tests/auto/declarative/qmlanimations/tst_qmlanimations.cpp b/tests/auto/declarative/qmlanimations/tst_qmlanimations.cpp index 92b0bf2..39d4326 100644 --- a/tests/auto/declarative/qmlanimations/tst_qmlanimations.cpp +++ b/tests/auto/declarative/qmlanimations/tst_qmlanimations.cpp @@ -258,7 +258,7 @@ void tst_qmlanimations::badTypes() //don't crash { QmlView *view = new QmlView; - view->setUrl(QUrl::fromLocalFile(SRCDIR "/data/badtype1.qml")); + view->setSource(QUrl::fromLocalFile(SRCDIR "/data/badtype1.qml")); view->execute(); qApp->processEvents(); diff --git a/tests/auto/declarative/qmlgraphicsanchors/tst_qmlgraphicsanchors.cpp b/tests/auto/declarative/qmlgraphicsanchors/tst_qmlgraphicsanchors.cpp index b8e54c0..1d2d12f 100644 --- a/tests/auto/declarative/qmlgraphicsanchors/tst_qmlgraphicsanchors.cpp +++ b/tests/auto/declarative/qmlgraphicsanchors/tst_qmlgraphicsanchors.cpp @@ -58,7 +58,7 @@ public: tst_qmlgraphicsanchors() {} template - T *findItem(QmlGraphicsItem *parent, const QString &id); + T *findItem(QGraphicsObject *parent, const QString &id); private slots: void basicAnchors(); @@ -80,7 +80,7 @@ private slots: Find an item with the specified id. */ template -T *tst_qmlgraphicsanchors::findItem(QmlGraphicsItem *parent, const QString &objectName) +T *tst_qmlgraphicsanchors::findItem(QGraphicsObject *parent, const QString &objectName) { const QMetaObject &mo = T::staticMetaObject; QList children = parent->childItems(); @@ -102,66 +102,66 @@ T *tst_qmlgraphicsanchors::findItem(QmlGraphicsItem *parent, const QString &obje void tst_qmlgraphicsanchors::basicAnchors() { QmlView *view = new QmlView; - view->setUrl(QUrl::fromLocalFile(SRCDIR "/data/anchors.qml")); + view->setSource(QUrl::fromLocalFile(SRCDIR "/data/anchors.qml")); view->execute(); 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->rootObject(), QLatin1String("rect1"))->x(), 26.0); + QCOMPARE(findItem(view->rootObject(), QLatin1String("rect2"))->x(), 122.0); + QCOMPARE(findItem(view->rootObject(), QLatin1String("rect3"))->x(), 74.0); + QCOMPARE(findItem(view->rootObject(), QLatin1String("rect4"))->x(), 16.0); + QCOMPARE(findItem(view->rootObject(), QLatin1String("rect5"))->x(), 112.0); + QCOMPARE(findItem(view->rootObject(), 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->rootObject(), QLatin1String("rect7"))->x(), 0.0); + QCOMPARE(findItem(view->rootObject(), QLatin1String("rect8"))->x(), 240.0); + QCOMPARE(findItem(view->rootObject(), QLatin1String("rect9"))->x(), 120.0); + QCOMPARE(findItem(view->rootObject(), QLatin1String("rect10"))->x(), -10.0); + QCOMPARE(findItem(view->rootObject(), QLatin1String("rect11"))->x(), 230.0); + QCOMPARE(findItem(view->rootObject(), 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->rootObject(), QLatin1String("rect13"))->y(), 20.0); + QCOMPARE(findItem(view->rootObject(), 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->rootObject(), QLatin1String("rect15"))->x(), 26.0); + QCOMPARE(findItem(view->rootObject(), QLatin1String("rect15"))->width(), 96.0); + QCOMPARE(findItem(view->rootObject(), QLatin1String("rect16"))->x(), 26.0); + QCOMPARE(findItem(view->rootObject(), QLatin1String("rect16"))->width(), 192.0); + QCOMPARE(findItem(view->rootObject(), QLatin1String("rect17"))->x(), -70.0); + QCOMPARE(findItem(view->rootObject(), 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->rootObject(), QLatin1String("rect18"))->y(), 20.0); + QCOMPARE(findItem(view->rootObject(), 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->rootObject(), QLatin1String("rect19"))->x(), 115.0); + QCOMPARE(findItem(view->rootObject(), QLatin1String("rect20"))->x(), 235.0); + QCOMPARE(findItem(view->rootObject(), QLatin1String("rect21"))->x(), -5.0); //centerIn - QCOMPARE(findItem(view->root(), QLatin1String("rect22"))->x(), 69.0); - QCOMPARE(findItem(view->root(), QLatin1String("rect22"))->y(), 5.0); + QCOMPARE(findItem(view->rootObject(), QLatin1String("rect22"))->x(), 69.0); + QCOMPARE(findItem(view->rootObject(), QLatin1String("rect22"))->y(), 5.0); //margins - QCOMPARE(findItem(view->root(), QLatin1String("rect23"))->x(), 31.0); - QCOMPARE(findItem(view->root(), QLatin1String("rect23"))->y(), 5.0); - QCOMPARE(findItem(view->root(), QLatin1String("rect23"))->width(), 86.0); - QCOMPARE(findItem(view->root(), QLatin1String("rect23"))->height(), 10.0); + QCOMPARE(findItem(view->rootObject(), QLatin1String("rect23"))->x(), 31.0); + QCOMPARE(findItem(view->rootObject(), QLatin1String("rect23"))->y(), 5.0); + QCOMPARE(findItem(view->rootObject(), QLatin1String("rect23"))->width(), 86.0); + QCOMPARE(findItem(view->rootObject(), QLatin1String("rect23"))->height(), 10.0); // offsets - QCOMPARE(findItem(view->root(), QLatin1String("rect24"))->x(), 26.0); - QCOMPARE(findItem(view->root(), QLatin1String("rect25"))->y(), 60.0); - QCOMPARE(findItem(view->root(), QLatin1String("rect26"))->y(), 5.0); + QCOMPARE(findItem(view->rootObject(), QLatin1String("rect24"))->x(), 26.0); + QCOMPARE(findItem(view->rootObject(), QLatin1String("rect25"))->y(), 60.0); + QCOMPARE(findItem(view->rootObject(), QLatin1String("rect26"))->y(), 5.0); //baseline - QmlGraphicsText *text1 = findItem(view->root(), QLatin1String("text1")); - QmlGraphicsText *text2 = findItem(view->root(), QLatin1String("text2")); + QmlGraphicsText *text1 = findItem(view->rootObject(), QLatin1String("text1")); + QmlGraphicsText *text2 = findItem(view->rootObject(), QLatin1String("text2")); QCOMPARE(text1->y(), text2->y()); delete view; @@ -173,9 +173,9 @@ void tst_qmlgraphicsanchors::loops() { QmlView *view = new QmlView; - view->setUrl(QUrl::fromLocalFile(SRCDIR "/data/loop1.qml")); + view->setSource(QUrl::fromLocalFile(SRCDIR "/data/loop1.qml")); - QString expect = "QML Text (" + view->url().toString() + ":6:5" + ") Possible anchor loop detected on horizontal anchor."; + QString expect = "QML Text (" + view->source().toString() + ":6:5" + ") Possible anchor loop detected on horizontal anchor."; QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); @@ -188,9 +188,9 @@ void tst_qmlgraphicsanchors::loops() { QmlView *view = new QmlView; - view->setUrl(QUrl::fromLocalFile(SRCDIR "/data/loop2.qml")); + view->setSource(QUrl::fromLocalFile(SRCDIR "/data/loop2.qml")); - QString expect = "QML Image (" + view->url().toString() + ":8:3" + ") Possible anchor loop detected on horizontal anchor."; + QString expect = "QML Image (" + view->source().toString() + ":8:3" + ") Possible anchor loop detected on horizontal anchor."; QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); view->execute(); qApp->processEvents(); @@ -372,9 +372,9 @@ void tst_qmlgraphicsanchors::crash1() { QmlView *view = new QmlView; - view->setUrl(QUrl::fromLocalFile(SRCDIR "/data/crash1.qml")); + view->setSource(QUrl::fromLocalFile(SRCDIR "/data/crash1.qml")); - QString expect = "QML Text (" + view->url().toString() + ":4:5" + ") Possible anchor loop detected on fill."; + QString expect = "QML Text (" + view->source().toString() + ":4:5" + ") Possible anchor loop detected on fill."; QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); // XXX ideally, should be one message view->execute(); @@ -387,11 +387,11 @@ void tst_qmlgraphicsanchors::fill() { QmlView *view = new QmlView; - view->setUrl(QUrl::fromLocalFile(SRCDIR "/data/fill.qml")); + view->setSource(QUrl::fromLocalFile(SRCDIR "/data/fill.qml")); view->execute(); qApp->processEvents(); - QmlGraphicsRectangle* rect = findItem(view->root(), QLatin1String("filler")); + QmlGraphicsRectangle* rect = findItem(view->rootObject(), QLatin1String("filler")); QCOMPARE(rect->x(), 0.0 + 10.0); QCOMPARE(rect->y(), 0.0 + 30.0); QCOMPARE(rect->width(), 200.0 - 10.0 - 20.0); @@ -413,11 +413,11 @@ void tst_qmlgraphicsanchors::centerIn() { QmlView *view = new QmlView; - view->setUrl(QUrl::fromLocalFile(SRCDIR "/data/centerin.qml")); + view->setSource(QUrl::fromLocalFile(SRCDIR "/data/centerin.qml")); view->execute(); qApp->processEvents(); - QmlGraphicsRectangle* rect = findItem(view->root(), QLatin1String("centered")); + QmlGraphicsRectangle* rect = findItem(view->rootObject(), QLatin1String("centered")); QCOMPARE(rect->x(), 75.0 + 10); QCOMPARE(rect->y(), 75.0 + 30); //Alter Offsets (QTBUG-6631) @@ -433,11 +433,11 @@ void tst_qmlgraphicsanchors::margins() { QmlView *view = new QmlView; - view->setUrl(QUrl::fromLocalFile(SRCDIR "/data/margins.qml")); + view->setSource(QUrl::fromLocalFile(SRCDIR "/data/margins.qml")); view->execute(); qApp->processEvents(); - QmlGraphicsRectangle* rect = findItem(view->root(), QLatin1String("filler")); + QmlGraphicsRectangle* rect = findItem(view->rootObject(), QLatin1String("filler")); QCOMPARE(rect->x(), 5.0); QCOMPARE(rect->y(), 6.0); QCOMPARE(rect->width(), 200.0 - 5.0 - 10.0); diff --git a/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp b/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp index c157e62..b161b01 100644 --- a/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp +++ b/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp @@ -70,9 +70,9 @@ private slots: private: QmlView *createView(const QString &filename); template - T *findItem(QmlGraphicsItem *parent, const QString &id, int index=-1); + T *findItem(QGraphicsObject *parent, const QString &id, int index=-1); template - QList findItems(QmlGraphicsItem *parent, const QString &objectName); + QList findItems(QGraphicsObject *parent, const QString &objectName); void dumpTree(QmlGraphicsItem *parent, int depth = 0); }; @@ -160,7 +160,7 @@ void tst_QmlGraphicsGridView::items() canvas->execute(); qApp->processEvents(); - QmlGraphicsGridView *gridview = findItem(canvas->root(), "grid"); + QmlGraphicsGridView *gridview = findItem(canvas->rootObject(), "grid"); QVERIFY(gridview != 0); QmlGraphicsItem *viewport = gridview->viewport(); @@ -208,7 +208,7 @@ void tst_QmlGraphicsGridView::changed() canvas->execute(); qApp->processEvents(); - QmlGraphicsFlickable *gridview = findItem(canvas->root(), "grid"); + QmlGraphicsFlickable *gridview = findItem(canvas->rootObject(), "grid"); QVERIFY(gridview != 0); QmlGraphicsItem *viewport = gridview->viewport(); @@ -241,7 +241,7 @@ void tst_QmlGraphicsGridView::inserted() canvas->execute(); qApp->processEvents(); - QmlGraphicsGridView *gridview = findItem(canvas->root(), "grid"); + QmlGraphicsGridView *gridview = findItem(canvas->rootObject(), "grid"); QVERIFY(gridview != 0); QmlGraphicsItem *viewport = gridview->viewport(); @@ -322,7 +322,7 @@ void tst_QmlGraphicsGridView::removed() canvas->execute(); qApp->processEvents(); - QmlGraphicsGridView *gridview = findItem(canvas->root(), "grid"); + QmlGraphicsGridView *gridview = findItem(canvas->rootObject(), "grid"); QVERIFY(gridview != 0); QmlGraphicsItem *viewport = gridview->viewport(); @@ -482,7 +482,7 @@ void tst_QmlGraphicsGridView::moved() canvas->execute(); qApp->processEvents(); - QmlGraphicsGridView *gridview = findItem(canvas->root(), "grid"); + QmlGraphicsGridView *gridview = findItem(canvas->rootObject(), "grid"); QVERIFY(gridview != 0); QmlGraphicsItem *viewport = gridview->viewport(); @@ -578,15 +578,12 @@ void tst_QmlGraphicsGridView::currentIndex() ctxt->setContextProperty("testModel", &model); QString filename(SRCDIR "/data/gridview-initCurrent.qml"); - QFile file(filename); - file.open(QFile::ReadOnly); - QString qml = file.readAll(); - canvas->setQml(qml, filename); + canvas->setSource(QUrl::fromLocalFile(filename)); canvas->execute(); qApp->processEvents(); - QmlGraphicsGridView *gridview = findItem(canvas->root(), "grid"); + QmlGraphicsGridView *gridview = findItem(canvas->rootObject(), "grid"); QVERIFY(gridview != 0); QmlGraphicsItem *viewport = gridview->viewport(); @@ -722,7 +719,7 @@ void tst_QmlGraphicsGridView::changeFlow() canvas->execute(); qApp->processEvents(); - QmlGraphicsGridView *gridview = findItem(canvas->root(), "grid"); + QmlGraphicsGridView *gridview = findItem(canvas->rootObject(), "grid"); QVERIFY(gridview != 0); QmlGraphicsItem *viewport = gridview->viewport(); @@ -827,7 +824,7 @@ void tst_QmlGraphicsGridView::positionViewAtIndex() canvas->execute(); qApp->processEvents(); - QmlGraphicsGridView *gridview = findItem(canvas->root(), "grid"); + QmlGraphicsGridView *gridview = findItem(canvas->rootObject(), "grid"); QVERIFY(gridview != 0); QmlGraphicsItem *viewport = gridview->viewport(); @@ -907,10 +904,7 @@ QmlView *tst_QmlGraphicsGridView::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->setSource(QUrl::fromLocalFile(filename)); return canvas; } @@ -920,10 +914,10 @@ QmlView *tst_QmlGraphicsGridView::createView(const QString &filename) item must also evaluate the {index} expression equal to index */ template -T *tst_QmlGraphicsGridView::findItem(QmlGraphicsItem *parent, const QString &objectName, int index) +T *tst_QmlGraphicsGridView::findItem(QGraphicsObject *parent, const QString &objectName, int index) { const QMetaObject &mo = T::staticMetaObject; - //qDebug() << parent->QGraphicsObject::children().count() << "children"; + //qDebug() << parent->childItems().count() << "children"; for (int i = 0; i < parent->childItems().count(); ++i) { QmlGraphicsItem *item = qobject_cast(parent->childItems().at(i)); if(!item) @@ -950,11 +944,11 @@ T *tst_QmlGraphicsGridView::findItem(QmlGraphicsItem *parent, const QString &obj } template -QList tst_QmlGraphicsGridView::findItems(QmlGraphicsItem *parent, const QString &objectName) +QList tst_QmlGraphicsGridView::findItems(QGraphicsObject *parent, const QString &objectName) { QList items; const QMetaObject &mo = T::staticMetaObject; - //qDebug() << parent->QGraphicsObject::children().count() << "children"; + //qDebug() << parent->childItems().count() << "children"; for (int i = 0; i < parent->childItems().count(); ++i) { QmlGraphicsItem *item = qobject_cast(parent->childItems().at(i)); if(!item) diff --git a/tests/auto/declarative/qmlgraphicsitem/tst_qmlgraphicsitem.cpp b/tests/auto/declarative/qmlgraphicsitem/tst_qmlgraphicsitem.cpp index 639f64c..dd0687c 100644 --- a/tests/auto/declarative/qmlgraphicsitem/tst_qmlgraphicsitem.cpp +++ b/tests/auto/declarative/qmlgraphicsitem/tst_qmlgraphicsitem.cpp @@ -61,7 +61,7 @@ private slots: private: template - T *findItem(QmlGraphicsItem *parent, const QString &objectName); + T *findItem(QGraphicsObject *parent, const QString &objectName); QmlEngine engine; }; @@ -112,7 +112,7 @@ void tst_QmlGraphicsItem::keys() QmlView *canvas = new QmlView(0); canvas->setFixedSize(240,320); - canvas->setUrl(QUrl::fromLocalFile(SRCDIR "/data/keys.qml")); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/keys.qml")); KeysTestObject *testObject = new KeysTestObject; canvas->rootContext()->setContextProperty("keysTestObject", testObject); @@ -194,7 +194,7 @@ void tst_QmlGraphicsItem::keyNavigation() QmlView *canvas = new QmlView(0); canvas->setFixedSize(240,320); - canvas->setUrl(QUrl::fromLocalFile(SRCDIR "/data/keynavigation.qml")); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/keynavigation.qml")); canvas->execute(); canvas->show(); qApp->processEvents(); @@ -204,7 +204,7 @@ void tst_QmlGraphicsItem::keyNavigation() QFocusEvent fe(QEvent::FocusIn); QApplication::sendEvent(canvas, &fe); - QmlGraphicsItem *item = findItem(canvas->root(), "item1"); + QmlGraphicsItem *item = findItem(canvas->rootObject(), "item1"); QVERIFY(item); QVERIFY(item->hasFocus()); @@ -213,7 +213,7 @@ void tst_QmlGraphicsItem::keyNavigation() QApplication::sendEvent(canvas, &key); QVERIFY(key.isAccepted()); - item = findItem(canvas->root(), "item2"); + item = findItem(canvas->rootObject(), "item2"); QVERIFY(item); QVERIFY(item->hasFocus()); @@ -222,7 +222,7 @@ void tst_QmlGraphicsItem::keyNavigation() QApplication::sendEvent(canvas, &key); QVERIFY(key.isAccepted()); - item = findItem(canvas->root(), "item4"); + item = findItem(canvas->rootObject(), "item4"); QVERIFY(item); QVERIFY(item->hasFocus()); @@ -231,7 +231,7 @@ void tst_QmlGraphicsItem::keyNavigation() QApplication::sendEvent(canvas, &key); QVERIFY(key.isAccepted()); - item = findItem(canvas->root(), "item3"); + item = findItem(canvas->rootObject(), "item3"); QVERIFY(item); QVERIFY(item->hasFocus()); @@ -240,7 +240,7 @@ void tst_QmlGraphicsItem::keyNavigation() QApplication::sendEvent(canvas, &key); QVERIFY(key.isAccepted()); - item = findItem(canvas->root(), "item1"); + item = findItem(canvas->rootObject(), "item1"); QVERIFY(item); QVERIFY(item->hasFocus()); } @@ -292,15 +292,15 @@ void tst_QmlGraphicsItem::clip() } template -T *tst_QmlGraphicsItem::findItem(QmlGraphicsItem *parent, const QString &objectName) +T *tst_QmlGraphicsItem::findItem(QGraphicsObject *parent, const QString &objectName) { if (!parent) return 0; const QMetaObject &mo = T::staticMetaObject; //qDebug() << parent->QGraphicsObject::children().count() << "children"; - for (int i = 0; i < parent->QGraphicsObject::children().count(); ++i) { - QmlGraphicsItem *item = qobject_cast(parent->QGraphicsObject::children().at(i)); + for (int i = 0; i < parent->childItems().count(); ++i) { + QmlGraphicsItem *item = qobject_cast(parent->childItems().at(i)); if(!item) continue; //qDebug() << "try" << item; diff --git a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp index 6f97030..faa19eb 100644 --- a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp +++ b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp @@ -90,9 +90,9 @@ private: template void clear(); QmlView *createView(const QString &filename); template - T *findItem(QmlGraphicsItem *parent, const QString &id, int index=-1); + T *findItem(QGraphicsObject *parent, const QString &id, int index=-1); template - QList findItems(QmlGraphicsItem *parent, const QString &objectName); + QList findItems(QGraphicsObject *parent, const QString &objectName); void dumpTree(QmlGraphicsItem *parent, int depth = 0); }; @@ -316,13 +316,13 @@ void tst_QmlGraphicsListView::items() canvas->execute(); qApp->processEvents(); - QmlGraphicsListView *listview = findItem(canvas->root(), "list"); + QmlGraphicsListView *listview = findItem(canvas->rootObject(), "list"); QVERIFY(listview != 0); QmlGraphicsItem *viewport = listview->viewport(); QVERIFY(viewport != 0); - QMetaObject::invokeMethod(canvas->root(), "checkProperties"); + QMetaObject::invokeMethod(canvas->rootObject(), "checkProperties"); QVERIFY(testObject->error() == false); QVERIFY(listview->highlightItem() != 0); @@ -343,20 +343,20 @@ void tst_QmlGraphicsListView::items() // switch to other delegate testObject->setAnimate(true); - QMetaObject::invokeMethod(canvas->root(), "checkProperties"); + QMetaObject::invokeMethod(canvas->rootObject(), "checkProperties"); QVERIFY(testObject->error() == false); QVERIFY(listview->currentItem()); // set invalid highlight testObject->setInvalidHighlight(true); - QMetaObject::invokeMethod(canvas->root(), "checkProperties"); + QMetaObject::invokeMethod(canvas->rootObject(), "checkProperties"); QVERIFY(testObject->error() == false); QVERIFY(listview->currentItem()); QVERIFY(listview->highlightItem() == 0); // back to normal highlight testObject->setInvalidHighlight(false); - QMetaObject::invokeMethod(canvas->root(), "checkProperties"); + QMetaObject::invokeMethod(canvas->rootObject(), "checkProperties"); QVERIFY(testObject->error() == false); QVERIFY(listview->currentItem()); QVERIFY(listview->highlightItem() != 0); @@ -396,7 +396,7 @@ void tst_QmlGraphicsListView::changed() canvas->execute(); qApp->processEvents(); - QmlGraphicsFlickable *listview = findItem(canvas->root(), "list"); + QmlGraphicsFlickable *listview = findItem(canvas->rootObject(), "list"); QVERIFY(listview != 0); QmlGraphicsItem *viewport = listview->viewport(); @@ -432,7 +432,7 @@ void tst_QmlGraphicsListView::inserted() canvas->execute(); qApp->processEvents(); - QmlGraphicsListView *listview = findItem(canvas->root(), "list"); + QmlGraphicsListView *listview = findItem(canvas->rootObject(), "list"); QVERIFY(listview != 0); QmlGraphicsItem *viewport = listview->viewport(); @@ -501,6 +501,8 @@ void tst_QmlGraphicsListView::inserted() QCOMPARE(item->y(), i*20.0 - 20.0); } +// QCOMPARE(listview->viewportHeight(), model.count() * 20.0); + delete canvas; } @@ -523,7 +525,7 @@ void tst_QmlGraphicsListView::removed(bool animated) canvas->execute(); qApp->processEvents(); - QmlGraphicsListView *listview = findItem(canvas->root(), "list"); + QmlGraphicsListView *listview = findItem(canvas->rootObject(), "list"); QVERIFY(listview != 0); QmlGraphicsItem *viewport = listview->viewport(); @@ -665,7 +667,7 @@ void tst_QmlGraphicsListView::clear() canvas->execute(); qApp->processEvents(); - QmlGraphicsListView *listview = findItem(canvas->root(), "list"); + QmlGraphicsListView *listview = findItem(canvas->rootObject(), "list"); QVERIFY(listview != 0); QmlGraphicsItem *viewport = listview->viewport(); @@ -702,7 +704,7 @@ void tst_QmlGraphicsListView::moved() canvas->execute(); qApp->processEvents(); - QmlGraphicsListView *listview = findItem(canvas->root(), "list"); + QmlGraphicsListView *listview = findItem(canvas->rootObject(), "list"); QVERIFY(listview != 0); QmlGraphicsItem *viewport = listview->viewport(); @@ -795,7 +797,7 @@ void tst_QmlGraphicsListView::enforceRange() canvas->execute(); qApp->processEvents(); - QmlGraphicsListView *listview = findItem(canvas->root(), "list"); + QmlGraphicsListView *listview = findItem(canvas->rootObject(), "list"); QVERIFY(listview != 0); QCOMPARE(listview->preferredHighlightBegin(), 100.0); @@ -843,7 +845,7 @@ void tst_QmlGraphicsListView::spacing() canvas->execute(); qApp->processEvents(); - QmlGraphicsListView *listview = findItem(canvas->root(), "list"); + QmlGraphicsListView *listview = findItem(canvas->rootObject(), "list"); QVERIFY(listview != 0); QmlGraphicsItem *viewport = listview->viewport(); @@ -898,7 +900,7 @@ void tst_QmlGraphicsListView::sections() canvas->execute(); qApp->processEvents(); - QmlGraphicsListView *listview = findItem(canvas->root(), "list"); + QmlGraphicsListView *listview = findItem(canvas->rootObject(), "list"); QVERIFY(listview != 0); QmlGraphicsItem *viewport = listview->viewport(); @@ -971,15 +973,12 @@ void tst_QmlGraphicsListView::currentIndex() ctxt->setContextProperty("testWrap", QVariant(false)); QString filename(SRCDIR "/data/listview-initCurrent.qml"); - QFile file(filename); - file.open(QFile::ReadOnly); - QString qml = file.readAll(); - canvas->setQml(qml, filename); + canvas->setSource(QUrl::fromLocalFile(filename)); canvas->execute(); qApp->processEvents(); - QmlGraphicsListView *listview = findItem(canvas->root(), "list"); + QmlGraphicsListView *listview = findItem(canvas->rootObject(), "list"); QVERIFY(listview != 0); QmlGraphicsItem *viewport = listview->viewport(); @@ -1061,13 +1060,13 @@ void tst_QmlGraphicsListView::itemList() canvas->execute(); qApp->processEvents(); - QmlGraphicsListView *listview = findItem(canvas->root(), "view"); + QmlGraphicsListView *listview = findItem(canvas->rootObject(), "view"); QVERIFY(listview != 0); QmlGraphicsItem *viewport = listview->viewport(); QVERIFY(viewport != 0); - QmlGraphicsVisualItemModel *model = canvas->root()->findChild("itemModel"); + QmlGraphicsVisualItemModel *model = canvas->rootObject()->findChild("itemModel"); QVERIFY(model != 0); QVERIFY(model->count() == 3); @@ -1112,7 +1111,7 @@ void tst_QmlGraphicsListView::cacheBuffer() canvas->execute(); qApp->processEvents(); - QmlGraphicsListView *listview = findItem(canvas->root(), "list"); + QmlGraphicsListView *listview = findItem(canvas->rootObject(), "list"); QVERIFY(listview != 0); QmlGraphicsItem *viewport = listview->viewport(); @@ -1164,7 +1163,7 @@ void tst_QmlGraphicsListView::positionViewAtIndex() canvas->execute(); qApp->processEvents(); - QmlGraphicsListView *listview = findItem(canvas->root(), "list"); + QmlGraphicsListView *listview = findItem(canvas->rootObject(), "list"); QVERIFY(listview != 0); QmlGraphicsItem *viewport = listview->viewport(); @@ -1301,10 +1300,7 @@ QmlView *tst_QmlGraphicsListView::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->setSource(QUrl::fromLocalFile(filename)); return canvas; } @@ -1314,10 +1310,10 @@ QmlView *tst_QmlGraphicsListView::createView(const QString &filename) item must also evaluate the {index} expression equal to index */ template -T *tst_QmlGraphicsListView::findItem(QmlGraphicsItem *parent, const QString &objectName, int index) +T *tst_QmlGraphicsListView::findItem(QGraphicsObject *parent, const QString &objectName, int index) { const QMetaObject &mo = T::staticMetaObject; - //qDebug() << parent->QGraphicsObject::children().count() << "children"; + //qDebug() << parent->childItems().count() << "children"; for (int i = 0; i < parent->childItems().count(); ++i) { QmlGraphicsItem *item = qobject_cast(parent->childItems().at(i)); if(!item) @@ -1342,11 +1338,11 @@ T *tst_QmlGraphicsListView::findItem(QmlGraphicsItem *parent, const QString &obj } template -QList tst_QmlGraphicsListView::findItems(QmlGraphicsItem *parent, const QString &objectName) +QList tst_QmlGraphicsListView::findItems(QGraphicsObject *parent, const QString &objectName) { QList items; const QMetaObject &mo = T::staticMetaObject; - //qDebug() << parent->QGraphicsObject::children().count() << "children"; + //qDebug() << parent->childItems().count() << "children"; for (int i = 0; i < parent->childItems().count(); ++i) { QmlGraphicsItem *item = qobject_cast(parent->childItems().at(i)); if(!item) diff --git a/tests/auto/declarative/qmlgraphicsmouseregion/tst_qmlgraphicsmouseregion.cpp b/tests/auto/declarative/qmlgraphicsmouseregion/tst_qmlgraphicsmouseregion.cpp index 7ba076c..82da9c8 100644 --- a/tests/auto/declarative/qmlgraphicsmouseregion/tst_qmlgraphicsmouseregion.cpp +++ b/tests/auto/declarative/qmlgraphicsmouseregion/tst_qmlgraphicsmouseregion.cpp @@ -59,18 +59,18 @@ void tst_QmlGraphicsMouseRegion::dragProperties() canvas->execute(); canvas->show(); canvas->setFocus(); - QVERIFY(canvas->root() != 0); + QVERIFY(canvas->rootObject() != 0); - QmlGraphicsMouseRegion *mouseRegion = canvas->root()->findChild("mouseregion"); + QmlGraphicsMouseRegion *mouseRegion = canvas->rootObject()->findChild("mouseregion"); QmlGraphicsDrag *drag = mouseRegion->drag(); QVERIFY(mouseRegion != 0); QVERIFY(drag != 0); // target - QmlGraphicsItem *blackRect = canvas->root()->findChild("blackrect"); + QmlGraphicsItem *blackRect = canvas->rootObject()->findChild("blackrect"); QVERIFY(blackRect != 0); QVERIFY(blackRect == drag->target()); - QmlGraphicsItem *rootItem = qobject_cast(canvas->root()); + QmlGraphicsItem *rootItem = qobject_cast(canvas->rootObject()); QVERIFY(rootItem != 0); QSignalSpy targetSpy(drag, SIGNAL(targetChanged())); drag->setTarget(rootItem); @@ -129,10 +129,7 @@ QmlView *tst_QmlGraphicsMouseRegion::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->setSource(QUrl::fromLocalFile(filename)); return canvas; } diff --git a/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp b/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp index 5458d68..5b75b32 100644 --- a/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp +++ b/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp @@ -63,8 +63,8 @@ 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(canvas->rootObject()); + QmlGraphicsParticles* particles = canvas->rootObject()->findChild("particles"); QVERIFY(particles); particles->setSource(QUrl::fromLocalFile(SRCDIR "/data/particle.png")); @@ -101,8 +101,8 @@ void tst_QmlGraphicsParticles::properties() void tst_QmlGraphicsParticles::runs() { QmlView *canvas = createView(SRCDIR "/data/particles.qml"); - QVERIFY(canvas->root()); - QmlGraphicsParticles* particles = canvas->root()->findChild("particles"); + QVERIFY(canvas->rootObject()); + QmlGraphicsParticles* particles = canvas->rootObject()->findChild("particles"); QVERIFY(particles); QTest::qWait(1000);//Run for one second. Test passes if it doesn't crash. } @@ -112,10 +112,7 @@ 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->setSource(QUrl::fromLocalFile(filename)); canvas->execute(); return canvas; diff --git a/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp b/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp index 4c2ecbd..9f67962 100644 --- a/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp +++ b/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp @@ -71,9 +71,9 @@ private slots: private: QmlView *createView(const QString &filename); template - T *findItem(QmlGraphicsItem *parent, const QString &objectName, int index=-1); + T *findItem(QGraphicsObject *parent, const QString &objectName, int index=-1); template - QList findItems(QmlGraphicsItem *parent, const QString &objectName); + QList findItems(QGraphicsObject *parent, const QString &objectName); }; class TestObject : public QObject @@ -204,7 +204,7 @@ void tst_QmlGraphicsPathView::items() canvas->execute(); qApp->processEvents(); - QmlGraphicsPathView *pathview = findItem(canvas->root(), "view"); + QmlGraphicsPathView *pathview = findItem(canvas->rootObject(), "view"); QVERIFY(pathview != 0); QCOMPARE(pathview->childItems().count(), model.count()); // assumes all are visible @@ -326,10 +326,10 @@ void tst_QmlGraphicsPathView::dataModel() canvas->execute(); qApp->processEvents(); - QmlGraphicsPathView *pathview = qobject_cast(canvas->root()); + QmlGraphicsPathView *pathview = qobject_cast(canvas->rootObject()); QVERIFY(pathview != 0); - QMetaObject::invokeMethod(canvas->root(), "checkProperties"); + QMetaObject::invokeMethod(canvas->rootObject(), "checkProperties"); QVERIFY(testObject->error() == false); QmlGraphicsItem *item = findItem(pathview, "wrapper", 0); @@ -352,7 +352,7 @@ void tst_QmlGraphicsPathView::dataModel() QCOMPARE(text->text(), model.name(2)); testObject->setPathItemCount(5); - QMetaObject::invokeMethod(canvas->root(), "checkProperties"); + QMetaObject::invokeMethod(canvas->rootObject(), "checkProperties"); QVERIFY(testObject->error() == false); itemCount = findItems(pathview, "wrapper").count(); @@ -398,7 +398,7 @@ void tst_QmlGraphicsPathView::pathMoved() canvas->execute(); qApp->processEvents(); - QmlGraphicsPathView *pathview = findItem(canvas->root(), "view"); + QmlGraphicsPathView *pathview = findItem(canvas->rootObject(), "view"); QVERIFY(pathview != 0); QmlGraphicsRectangle *firstItem = findItem(pathview, "wrapper", 0); @@ -430,10 +430,7 @@ QmlView *tst_QmlGraphicsPathView::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->setSource(QUrl::fromLocalFile(filename)); return canvas; } @@ -443,7 +440,7 @@ QmlView *tst_QmlGraphicsPathView::createView(const QString &filename) item must also evaluate the {index} expression equal to index */ template -T *tst_QmlGraphicsPathView::findItem(QmlGraphicsItem *parent, const QString &objectName, int index) +T *tst_QmlGraphicsPathView::findItem(QGraphicsObject *parent, const QString &objectName, int index) { const QMetaObject &mo = T::staticMetaObject; //qDebug() << parent->childItems().count() << "children"; @@ -471,7 +468,7 @@ T *tst_QmlGraphicsPathView::findItem(QmlGraphicsItem *parent, const QString &obj } template -QList tst_QmlGraphicsPathView::findItems(QmlGraphicsItem *parent, const QString &objectName) +QList tst_QmlGraphicsPathView::findItems(QGraphicsObject *parent, const QString &objectName) { QList items; const QMetaObject &mo = T::staticMetaObject; diff --git a/tests/auto/declarative/qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp b/tests/auto/declarative/qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp index 42d6da9..924ce58 100644 --- a/tests/auto/declarative/qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp +++ b/tests/auto/declarative/qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp @@ -77,13 +77,13 @@ void tst_QmlGraphicsPositioners::test_horizontal() canvas->execute(); - QmlGraphicsRectangle *one = canvas->root()->findChild("one"); + QmlGraphicsRectangle *one = canvas->rootObject()->findChild("one"); QVERIFY(one != 0); - QmlGraphicsRectangle *two = canvas->root()->findChild("two"); + QmlGraphicsRectangle *two = canvas->rootObject()->findChild("two"); QVERIFY(two != 0); - QmlGraphicsRectangle *three = canvas->root()->findChild("three"); + QmlGraphicsRectangle *three = canvas->rootObject()->findChild("three"); QVERIFY(three != 0); QCOMPARE(one->x(), 0.0); @@ -100,13 +100,13 @@ void tst_QmlGraphicsPositioners::test_horizontal_spacing() canvas->execute(); - QmlGraphicsRectangle *one = canvas->root()->findChild("one"); + QmlGraphicsRectangle *one = canvas->rootObject()->findChild("one"); QVERIFY(one != 0); - QmlGraphicsRectangle *two = canvas->root()->findChild("two"); + QmlGraphicsRectangle *two = canvas->rootObject()->findChild("two"); QVERIFY(two != 0); - QmlGraphicsRectangle *three = canvas->root()->findChild("three"); + QmlGraphicsRectangle *three = canvas->rootObject()->findChild("three"); QVERIFY(three != 0); QCOMPARE(one->x(), 0.0); @@ -123,13 +123,13 @@ void tst_QmlGraphicsPositioners::test_horizontal_animated() canvas->execute(); - QmlGraphicsRectangle *one = canvas->root()->findChild("one"); + QmlGraphicsRectangle *one = canvas->rootObject()->findChild("one"); QVERIFY(one != 0); - QmlGraphicsRectangle *two = canvas->root()->findChild("two"); + QmlGraphicsRectangle *two = canvas->rootObject()->findChild("two"); QVERIFY(two != 0); - QmlGraphicsRectangle *three = canvas->root()->findChild("three"); + QmlGraphicsRectangle *three = canvas->rootObject()->findChild("three"); QVERIFY(three != 0); //Note that they animate in @@ -165,13 +165,13 @@ void tst_QmlGraphicsPositioners::test_vertical() canvas->execute(); - QmlGraphicsRectangle *one = canvas->root()->findChild("one"); + QmlGraphicsRectangle *one = canvas->rootObject()->findChild("one"); QVERIFY(one != 0); - QmlGraphicsRectangle *two = canvas->root()->findChild("two"); + QmlGraphicsRectangle *two = canvas->rootObject()->findChild("two"); QVERIFY(two != 0); - QmlGraphicsRectangle *three = canvas->root()->findChild("three"); + QmlGraphicsRectangle *three = canvas->rootObject()->findChild("three"); QVERIFY(three != 0); QCOMPARE(one->x(), 0.0); @@ -188,13 +188,13 @@ void tst_QmlGraphicsPositioners::test_vertical_spacing() canvas->execute(); - QmlGraphicsRectangle *one = canvas->root()->findChild("one"); + QmlGraphicsRectangle *one = canvas->rootObject()->findChild("one"); QVERIFY(one != 0); - QmlGraphicsRectangle *two = canvas->root()->findChild("two"); + QmlGraphicsRectangle *two = canvas->rootObject()->findChild("two"); QVERIFY(two != 0); - QmlGraphicsRectangle *three = canvas->root()->findChild("three"); + QmlGraphicsRectangle *three = canvas->rootObject()->findChild("three"); QVERIFY(three != 0); QCOMPARE(one->x(), 0.0); @@ -212,15 +212,15 @@ void tst_QmlGraphicsPositioners::test_vertical_animated() canvas->execute(); //Note that they animate in - QmlGraphicsRectangle *one = canvas->root()->findChild("one"); + QmlGraphicsRectangle *one = canvas->rootObject()->findChild("one"); QVERIFY(one != 0); QCOMPARE(one->y(), -100.0); - QmlGraphicsRectangle *two = canvas->root()->findChild("two"); + QmlGraphicsRectangle *two = canvas->rootObject()->findChild("two"); QVERIFY(two != 0); QCOMPARE(two->y(), -100.0); - QmlGraphicsRectangle *three = canvas->root()->findChild("three"); + QmlGraphicsRectangle *three = canvas->rootObject()->findChild("three"); QVERIFY(three != 0); QCOMPARE(three->y(), -100.0); @@ -253,15 +253,15 @@ void tst_QmlGraphicsPositioners::test_grid() canvas->execute(); - QmlGraphicsRectangle *one = canvas->root()->findChild("one"); + QmlGraphicsRectangle *one = canvas->rootObject()->findChild("one"); QVERIFY(one != 0); - QmlGraphicsRectangle *two = canvas->root()->findChild("two"); + QmlGraphicsRectangle *two = canvas->rootObject()->findChild("two"); QVERIFY(two != 0); - QmlGraphicsRectangle *three = canvas->root()->findChild("three"); + QmlGraphicsRectangle *three = canvas->rootObject()->findChild("three"); QVERIFY(three != 0); - QmlGraphicsRectangle *four = canvas->root()->findChild("four"); + QmlGraphicsRectangle *four = canvas->rootObject()->findChild("four"); QVERIFY(four != 0); - QmlGraphicsRectangle *five = canvas->root()->findChild("five"); + QmlGraphicsRectangle *five = canvas->rootObject()->findChild("five"); QVERIFY(five != 0); QCOMPARE(one->x(), 0.0); @@ -282,15 +282,15 @@ void tst_QmlGraphicsPositioners::test_grid_spacing() canvas->execute(); - QmlGraphicsRectangle *one = canvas->root()->findChild("one"); + QmlGraphicsRectangle *one = canvas->rootObject()->findChild("one"); QVERIFY(one != 0); - QmlGraphicsRectangle *two = canvas->root()->findChild("two"); + QmlGraphicsRectangle *two = canvas->rootObject()->findChild("two"); QVERIFY(two != 0); - QmlGraphicsRectangle *three = canvas->root()->findChild("three"); + QmlGraphicsRectangle *three = canvas->rootObject()->findChild("three"); QVERIFY(three != 0); - QmlGraphicsRectangle *four = canvas->root()->findChild("four"); + QmlGraphicsRectangle *four = canvas->rootObject()->findChild("four"); QVERIFY(four != 0); - QmlGraphicsRectangle *five = canvas->root()->findChild("five"); + QmlGraphicsRectangle *five = canvas->rootObject()->findChild("five"); QVERIFY(five != 0); QCOMPARE(one->x(), 0.0); @@ -311,27 +311,27 @@ void tst_QmlGraphicsPositioners::test_grid_animated() canvas->execute(); //Note that all animate in - QmlGraphicsRectangle *one = canvas->root()->findChild("one"); + QmlGraphicsRectangle *one = canvas->rootObject()->findChild("one"); QVERIFY(one != 0); QCOMPARE(one->x(), -100.0); QCOMPARE(one->y(), -100.0); - QmlGraphicsRectangle *two = canvas->root()->findChild("two"); + QmlGraphicsRectangle *two = canvas->rootObject()->findChild("two"); QVERIFY(two != 0); QCOMPARE(two->x(), -100.0); QCOMPARE(two->y(), -100.0); - QmlGraphicsRectangle *three = canvas->root()->findChild("three"); + QmlGraphicsRectangle *three = canvas->rootObject()->findChild("three"); QVERIFY(three != 0); QCOMPARE(three->x(), -100.0); QCOMPARE(three->y(), -100.0); - QmlGraphicsRectangle *four = canvas->root()->findChild("four"); + QmlGraphicsRectangle *four = canvas->rootObject()->findChild("four"); QVERIFY(four != 0); QCOMPARE(four->x(), -100.0); QCOMPARE(four->y(), -100.0); - QmlGraphicsRectangle *five = canvas->root()->findChild("five"); + QmlGraphicsRectangle *five = canvas->rootObject()->findChild("five"); QVERIFY(five != 0); QCOMPARE(five->x(), -100.0); QCOMPARE(five->y(), -100.0); @@ -385,13 +385,13 @@ void tst_QmlGraphicsPositioners::test_repeater() canvas->execute(); - QmlGraphicsRectangle *one = canvas->root()->findChild("one"); + QmlGraphicsRectangle *one = canvas->rootObject()->findChild("one"); QVERIFY(one != 0); - QmlGraphicsRectangle *two = canvas->root()->findChild("two"); + QmlGraphicsRectangle *two = canvas->rootObject()->findChild("two"); QVERIFY(two != 0); - QmlGraphicsRectangle *three = canvas->root()->findChild("three"); + QmlGraphicsRectangle *three = canvas->rootObject()->findChild("three"); QVERIFY(three != 0); QCOMPARE(one->x(), 0.0); @@ -406,10 +406,7 @@ QmlView *tst_QmlGraphicsPositioners::createView(const QString &filename) { QmlView *canvas = new QmlView(0); - QFile file(filename); - file.open(QFile::ReadOnly); - QString xml = file.readAll(); - canvas->setQml(xml, filename); + canvas->setSource(QUrl::fromLocalFile(filename)); return canvas; } diff --git a/tests/auto/declarative/qmlgraphicsrepeater/tst_qmlgraphicsrepeater.cpp b/tests/auto/declarative/qmlgraphicsrepeater/tst_qmlgraphicsrepeater.cpp index ef0ca1d..b759ef5 100644 --- a/tests/auto/declarative/qmlgraphicsrepeater/tst_qmlgraphicsrepeater.cpp +++ b/tests/auto/declarative/qmlgraphicsrepeater/tst_qmlgraphicsrepeater.cpp @@ -70,7 +70,7 @@ private slots: private: QmlView *createView(const QString &filename); template - T *findItem(QmlGraphicsItem *parent, const QString &id); + T *findItem(QGraphicsObject *parent, const QString &id); }; class TestObject : public QObject @@ -174,11 +174,11 @@ void tst_QmlGraphicsRepeater::numberModel() canvas->execute(); qApp->processEvents(); - QmlGraphicsRepeater *repeater = findItem(canvas->root(), "repeater"); + QmlGraphicsRepeater *repeater = findItem(canvas->rootObject(), "repeater"); QVERIFY(repeater != 0); QCOMPARE(repeater->parentItem()->childItems().count(), 5+1); - QMetaObject::invokeMethod(canvas->root(), "checkProperties"); + QMetaObject::invokeMethod(canvas->rootObject(), "checkProperties"); QVERIFY(testObject->error() == false); delete canvas; @@ -200,7 +200,7 @@ void tst_QmlGraphicsRepeater::objectList() canvas->execute(); qApp->processEvents(); - QmlGraphicsRepeater *repeater = findItem(canvas->root(), "repeater"); + QmlGraphicsRepeater *repeater = findItem(canvas->rootObject(), "repeater"); QVERIFY(repeater != 0); QCOMPARE(repeater->property("errors").toInt(), 0);//If this fails either they are out of order or can't find the object's data QCOMPARE(repeater->property("instantiated").toInt(), 100); @@ -227,10 +227,10 @@ void tst_QmlGraphicsRepeater::stringList() canvas->execute(); qApp->processEvents(); - QmlGraphicsRepeater *repeater = findItem(canvas->root(), "repeater"); + QmlGraphicsRepeater *repeater = findItem(canvas->rootObject(), "repeater"); QVERIFY(repeater != 0); - QmlGraphicsItem *container = findItem(canvas->root(), "container"); + QmlGraphicsItem *container = findItem(canvas->rootObject(), "container"); QVERIFY(container != 0); QCOMPARE(container->childItems().count(), data.count() + 3); @@ -280,10 +280,10 @@ void tst_QmlGraphicsRepeater::dataModel() canvas->execute(); qApp->processEvents(); - QmlGraphicsRepeater *repeater = findItem(canvas->root(), "repeater"); + QmlGraphicsRepeater *repeater = findItem(canvas->rootObject(), "repeater"); QVERIFY(repeater != 0); - QmlGraphicsItem *container = findItem(canvas->root(), "container"); + QmlGraphicsItem *container = findItem(canvas->rootObject(), "container"); QVERIFY(container != 0); QCOMPARE(container->childItems().count(), 4); @@ -305,16 +305,16 @@ void tst_QmlGraphicsRepeater::itemModel() canvas->execute(); qApp->processEvents(); - QmlGraphicsRepeater *repeater = findItem(canvas->root(), "repeater"); + QmlGraphicsRepeater *repeater = findItem(canvas->rootObject(), "repeater"); QVERIFY(repeater != 0); - QmlGraphicsItem *container = findItem(canvas->root(), "container"); + QmlGraphicsItem *container = findItem(canvas->rootObject(), "container"); QVERIFY(container != 0); QCOMPARE(container->childItems().count(), 1); testObject->setUseModel(true); - QMetaObject::invokeMethod(canvas->root(), "checkProperties"); + QMetaObject::invokeMethod(canvas->rootObject(), "checkProperties"); QVERIFY(testObject->error() == false); QCOMPARE(container->childItems().count(), 4); @@ -331,10 +331,10 @@ void tst_QmlGraphicsRepeater::properties() QmlEngine engine; QmlComponent component(&engine, TEST_FILE("/properties.qml")); - QmlGraphicsItem *root = qobject_cast(component.create()); - QVERIFY(root); + QmlGraphicsItem *rootObject = qobject_cast(component.create()); + QVERIFY(rootObject); - QmlGraphicsRepeater *repeater = findItem(root, "repeater"); + QmlGraphicsRepeater *repeater = findItem(rootObject, "repeater"); QVERIFY(repeater); QSignalSpy modelSpy(repeater, SIGNAL(modelChanged())); @@ -359,16 +359,13 @@ QmlView *tst_QmlGraphicsRepeater::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->setSource(QUrl::fromLocalFile(filename)); return canvas; } template -T *tst_QmlGraphicsRepeater::findItem(QmlGraphicsItem *parent, const QString &objectName) +T *tst_QmlGraphicsRepeater::findItem(QGraphicsObject *parent, const QString &objectName) { const QMetaObject &mo = T::staticMetaObject; if (mo.cast(parent) && (objectName.isEmpty() || parent->objectName() == objectName)) diff --git a/tests/auto/declarative/qmlgraphicstextedit/tst_qmlgraphicstextedit.cpp b/tests/auto/declarative/qmlgraphicstextedit/tst_qmlgraphicstextedit.cpp index a197ced..2b0131b 100644 --- a/tests/auto/declarative/qmlgraphicstextedit/tst_qmlgraphicstextedit.cpp +++ b/tests/auto/declarative/qmlgraphicstextedit/tst_qmlgraphicstextedit.cpp @@ -608,8 +608,8 @@ void tst_qmlgraphicstextedit::inputMethodHints() canvas->show(); canvas->setFocus(); - QVERIFY(canvas->root() != 0); - QmlGraphicsTextEdit *textEditObject = qobject_cast(canvas->root()); + QVERIFY(canvas->rootObject() != 0); + QmlGraphicsTextEdit *textEditObject = qobject_cast(canvas->rootObject()); QVERIFY(textEditObject != 0); QVERIFY(textEditObject->inputMethodHints() & Qt::ImhNoPredictiveText); textEditObject->setInputMethodHints(Qt::ImhUppercaseOnly); @@ -622,7 +622,7 @@ void tst_qmlgraphicstextedit::cursorDelegate() view->execute(); view->show(); view->setFocus(); - QmlGraphicsTextEdit *textEditObject = view->root()->findChild("textEditObject"); + QmlGraphicsTextEdit *textEditObject = view->rootObject()->findChild("textEditObject"); QVERIFY(textEditObject != 0); QVERIFY(textEditObject->findChild("cursorInstance")); //Test Delegate gets created @@ -650,40 +650,40 @@ void tst_qmlgraphicstextedit::delegateLoading() server.serveDirectory(SRCDIR "/data/httpslow", TestHTTPServer::Delay); server.serveDirectory(SRCDIR "/data/http"); QmlView* view = new QmlView(0); - view->setUrl(QUrl("http://localhost:42332/cursorHttpTestPass.qml")); + view->setSource(QUrl("http://localhost:42332/cursorHttpTestPass.qml")); view->execute(); view->show(); view->setFocus(); - QTRY_VERIFY(view->root());//Wait for loading to finish. - QmlGraphicsTextEdit *textEditObject = view->root()->findChild("textEditObject"); - // view->root()->dumpObjectTree(); + QTRY_VERIFY(view->rootObject());//Wait for loading to finish. + QmlGraphicsTextEdit *textEditObject = view->rootObject()->findChild("textEditObject"); + // view->rootObject()->dumpObjectTree(); QVERIFY(textEditObject != 0); textEditObject->setFocus(true); QmlGraphicsItem *delegate; - delegate = view->root()->findChild("delegateOkay"); + delegate = view->rootObject()->findChild("delegateOkay"); QVERIFY(delegate); - delegate = view->root()->findChild("delegateSlow"); + delegate = view->rootObject()->findChild("delegateSlow"); QVERIFY(delegate); - view->setUrl(QUrl("http://localhost:42332/cursorHttpTestFail1.qml")); + view->setSource(QUrl("http://localhost:42332/cursorHttpTestFail1.qml")); view->execute(); view->show(); view->setFocus(); - delegate = view->root()->findChild("delegateOkay"); + delegate = view->rootObject()->findChild("delegateOkay"); QVERIFY(delegate); - delegate = view->root()->findChild("delegateFail"); + delegate = view->rootObject()->findChild("delegateFail"); QVERIFY(!delegate); - view->setUrl(QUrl("http://localhost:42332/cursorHttpTestFail2.qml")); + view->setSource(QUrl("http://localhost:42332/cursorHttpTestFail2.qml")); view->execute(); view->show(); view->setFocus(); - delegate = view->root()->findChild("delegateOkay"); + delegate = view->rootObject()->findChild("delegateOkay"); QVERIFY(delegate); - delegate = view->root()->findChild("delegateErrorA"); + delegate = view->rootObject()->findChild("delegateErrorA"); QVERIFY(!delegate); //ErrorB should get a component which is ready but component.create() returns null //Not sure how to accomplish this with QmlGraphicsTextEdits cursor delegate //###This could be a case of overzealous defensive programming - //delegate = view->root()->findChild("delegateErrorB"); + //delegate = view->rootObject()->findChild("delegateErrorB"); //QVERIFY(!delegate); } @@ -698,9 +698,9 @@ void tst_qmlgraphicstextedit::navigation() canvas->show(); canvas->setFocus(); - QVERIFY(canvas->root() != 0); + QVERIFY(canvas->rootObject() != 0); - QmlGraphicsItem *input = qobject_cast(qvariant_cast(canvas->root()->property("myInput"))); + QmlGraphicsItem *input = qobject_cast(qvariant_cast(canvas->rootObject()->property("myInput"))); QVERIFY(input != 0); QTRY_VERIFY(input->hasFocus() == true); @@ -721,9 +721,9 @@ void tst_qmlgraphicstextedit::readOnly() canvas->show(); canvas->setFocus(); - QVERIFY(canvas->root() != 0); + QVERIFY(canvas->rootObject() != 0); - QmlGraphicsTextEdit *edit = qobject_cast(qvariant_cast(canvas->root()->property("myInput"))); + QmlGraphicsTextEdit *edit = qobject_cast(qvariant_cast(canvas->rootObject()->property("myInput"))); QVERIFY(edit != 0); QTRY_VERIFY(edit->hasFocus() == true); @@ -750,10 +750,7 @@ QmlView *tst_qmlgraphicstextedit::createView(const QString &filename) { QmlView *canvas = new QmlView(0); - QFile file(filename); - file.open(QFile::ReadOnly); - QString xml = file.readAll(); - canvas->setQml(xml, filename); + canvas->setSource(QUrl::fromLocalFile(filename)); return canvas; } diff --git a/tests/auto/declarative/qmlgraphicstextinput/tst_qmlgraphicstextinput.cpp b/tests/auto/declarative/qmlgraphicstextinput/tst_qmlgraphicstextinput.cpp index b7ae4a2..d68964b 100644 --- a/tests/auto/declarative/qmlgraphicstextinput/tst_qmlgraphicstextinput.cpp +++ b/tests/auto/declarative/qmlgraphicstextinput/tst_qmlgraphicstextinput.cpp @@ -352,8 +352,8 @@ void tst_qmlgraphicstextinput::maxLength() canvas->execute(); canvas->show(); canvas->setFocus(); - QVERIFY(canvas->root() != 0); - QmlGraphicsTextInput *textinputObject = qobject_cast(canvas->root()); + QVERIFY(canvas->rootObject() != 0); + QmlGraphicsTextInput *textinputObject = qobject_cast(canvas->rootObject()); QVERIFY(textinputObject != 0); QVERIFY(textinputObject->text().isEmpty()); QVERIFY(textinputObject->maxLength() == 10); @@ -381,8 +381,8 @@ void tst_qmlgraphicstextinput::masks() canvas->execute(); canvas->show(); canvas->setFocus(); - QVERIFY(canvas->root() != 0); - QmlGraphicsTextInput *textinputObject = qobject_cast(canvas->root()); + QVERIFY(canvas->rootObject() != 0); + QmlGraphicsTextInput *textinputObject = qobject_cast(canvas->rootObject()); QVERIFY(textinputObject != 0); QTRY_VERIFY(textinputObject->hasFocus() == true); QVERIFY(textinputObject->text().length() == 0); @@ -407,9 +407,9 @@ void tst_qmlgraphicstextinput::validators() canvas->show(); canvas->setFocus(); - QVERIFY(canvas->root() != 0); + QVERIFY(canvas->rootObject() != 0); - QmlGraphicsTextInput *intInput = qobject_cast(qvariant_cast(canvas->root()->property("intInput"))); + QmlGraphicsTextInput *intInput = qobject_cast(qvariant_cast(canvas->rootObject()->property("intInput"))); QVERIFY(intInput); intInput->setFocus(true); QTRY_VERIFY(intInput->hasFocus()); @@ -430,7 +430,7 @@ void tst_qmlgraphicstextinput::validators() QCOMPARE(intInput->text(), QLatin1String("11")); QCOMPARE(intInput->hasAcceptableInput(), true); - QmlGraphicsTextInput *dblInput = qobject_cast(qvariant_cast(canvas->root()->property("dblInput"))); + QmlGraphicsTextInput *dblInput = qobject_cast(qvariant_cast(canvas->rootObject()->property("dblInput"))); QTRY_VERIFY(dblInput); dblInput->setFocus(true); QVERIFY(dblInput->hasFocus() == true); @@ -459,7 +459,7 @@ void tst_qmlgraphicstextinput::validators() QCOMPARE(dblInput->text(), QLatin1String("12.11")); QCOMPARE(dblInput->hasAcceptableInput(), true); - QmlGraphicsTextInput *strInput = qobject_cast(qvariant_cast(canvas->root()->property("strInput"))); + QmlGraphicsTextInput *strInput = qobject_cast(qvariant_cast(canvas->rootObject()->property("strInput"))); QTRY_VERIFY(strInput); strInput->setFocus(true); QVERIFY(strInput->hasFocus() == true); @@ -497,8 +497,8 @@ void tst_qmlgraphicstextinput::inputMethodHints() canvas->show(); canvas->setFocus(); - QVERIFY(canvas->root() != 0); - QmlGraphicsTextInput *textinputObject = qobject_cast(canvas->root()); + QVERIFY(canvas->rootObject() != 0); + QmlGraphicsTextInput *textinputObject = qobject_cast(canvas->rootObject()); QVERIFY(textinputObject != 0); QVERIFY(textinputObject->inputMethodHints() & Qt::ImhNoPredictiveText); textinputObject->setInputMethodHints(Qt::ImhUppercaseOnly); @@ -517,9 +517,9 @@ void tst_qmlgraphicstextinput::navigation() canvas->show(); canvas->setFocus(); - QVERIFY(canvas->root() != 0); + QVERIFY(canvas->rootObject() != 0); - QmlGraphicsTextInput *input = qobject_cast(qvariant_cast(canvas->root()->property("myInput"))); + QmlGraphicsTextInput *input = qobject_cast(qvariant_cast(canvas->rootObject()->property("myInput"))); QVERIFY(input != 0); input->setCursorPosition(0); @@ -549,7 +549,7 @@ void tst_qmlgraphicstextinput::cursorDelegate() view->execute(); view->show(); view->setFocus(); - QmlGraphicsTextInput *textInputObject = view->root()->findChild("textInputObject"); + QmlGraphicsTextInput *textInputObject = view->rootObject()->findChild("textInputObject"); QVERIFY(textInputObject != 0); QVERIFY(textInputObject->findChild("cursorInstance")); //Test Delegate gets created @@ -578,9 +578,9 @@ void tst_qmlgraphicstextinput::readOnly() canvas->show(); canvas->setFocus(); - QVERIFY(canvas->root() != 0); + QVERIFY(canvas->rootObject() != 0); - QmlGraphicsTextInput *input = qobject_cast(qvariant_cast(canvas->root()->property("myInput"))); + QmlGraphicsTextInput *input = qobject_cast(qvariant_cast(canvas->rootObject()->property("myInput"))); QVERIFY(input != 0); QTRY_VERIFY(input->hasFocus() == true); @@ -607,10 +607,7 @@ QmlView *tst_qmlgraphicstextinput::createView(const QString &filename) { QmlView *canvas = new QmlView(0); - QFile file(filename); - file.open(QFile::ReadOnly); - QString xml = file.readAll(); - canvas->setQml(xml, filename); + canvas->setSource(QUrl::fromLocalFile(filename)); return canvas; } diff --git a/tools/qmlviewer/qfxtester.cpp b/tools/qmlviewer/qfxtester.cpp index bd96545..8eceb4c 100644 --- a/tools/qmlviewer/qfxtester.cpp +++ b/tools/qmlviewer/qfxtester.cpp @@ -147,7 +147,7 @@ void QmlGraphicsTester::imagefailure() void QmlGraphicsTester::complete() { if ((options & QmlViewer::TestErrorProperty) && !hasFailed) { - QString e = m_view->root()->property("error").toString(); + QString e = m_view->rootObject()->property("error").toString(); if (!e.isEmpty()) { qWarning() << "Test failed:" << e; hasFailed = true; diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index 7c620ef..3cfbee2 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -80,6 +80,7 @@ #include #include #include +#include #include #include #include @@ -473,13 +474,12 @@ QmlViewer::QmlViewer(QWidget *parent, Qt::WindowFlags flags) canvas = new QmlView(this); canvas->setAttribute(Qt::WA_OpaquePaintEvent); canvas->setAttribute(Qt::WA_NoSystemBackground); - canvas->setContentResizable(!skin || !scaleSkin); + canvas->setResizeMode((!skin || !scaleSkin) ? QmlView::SizeRootObjectToView : QmlView::SizeViewToRootObject); canvas->setFocus(); QObject::connect(canvas, SIGNAL(sceneResized(QSize)), this, SLOT(sceneResized(QSize))); - QObject::connect(canvas, SIGNAL(initialSize(QSize)), this, SLOT(adjustSizeSlot())); - QObject::connect(canvas, SIGNAL(errors(QList)), this, SLOT(executeErrors())); - QObject::connect(canvas, SIGNAL(quit()), QCoreApplication::instance (), SLOT(quit())); + QObject::connect(canvas, SIGNAL(statusChanged(QmlView::Status)), this, SLOT(statusChanged())); + QObject::connect(canvas->engine(), SIGNAL(quit()), QCoreApplication::instance (), SLOT(quit())); if (!(flags & Qt::FramelessWindowHint)) { createMenu(menuBar(),0); @@ -516,11 +516,6 @@ QmlViewer::~QmlViewer() delete namFactory; } -void QmlViewer::adjustSizeSlot() -{ - resize(sizeHint()); -} - QMenuBar *QmlViewer::menuBar() const { #if !defined(Q_OS_SYMBIAN) @@ -731,7 +726,7 @@ void QmlViewer::setScaleSkin() if (scaleSkin) return; scaleSkin = true; - canvas->setContentResizable(!skin || !scaleSkin); + canvas->setResizeMode((!skin || !scaleSkin) ? QmlView::SizeRootObjectToView : QmlView::SizeViewToRootObject); if (skin) { canvas->setFixedSize(canvas->sizeHint()); skin->setScreenSize(canvas->sizeHint()); @@ -744,7 +739,7 @@ void QmlViewer::setScaleView() return; scaleSkin = false; if (skin) { - canvas->setContentResizable(!skin || !scaleSkin); + canvas->setResizeMode((!skin || !scaleSkin) ? QmlView::SizeRootObjectToView : QmlView::SizeViewToRootObject); canvas->setMinimumSize(QSize(0,0)); canvas->setMaximumSize(QSize(16777215,16777215)); canvas->resize(skin->standardScreenSize()); @@ -889,7 +884,8 @@ void QmlViewer::openWgt(const QString& doc) QUrl url(doc); if (url.isRelative()) url = QUrl::fromLocalFile(doc); - canvas->reset(); + delete canvas->rootObject(); + canvas->engine()->clearComponentCache(); QNetworkAccessManager * nam = canvas->engine()->networkAccessManager(); wgtreply = nam->get(QNetworkRequest(url)); connect(wgtreply,SIGNAL(finished()),this,SLOT(unpackWgt())); @@ -971,7 +967,7 @@ void QmlViewer::unpackWgt() void QmlViewer::openFile() { - QString cur = canvas->url().toLocalFile(); + QString cur = canvas->source().toLocalFile(); if (useQmlFileBrowser) { openQml("qrc:/content/Browser.qml"); } else { @@ -983,9 +979,13 @@ void QmlViewer::openFile() } } -void QmlViewer::executeErrors() +void QmlViewer::statusChanged() { - if (tester) tester->executefailure(); + if (canvas->status() == QmlView::Error && tester) + tester->executefailure(); + + if (canvas->status() == QmlView::Ready) + resize(sizeHint()); } void QmlViewer::launch(const QString& file_or_url) @@ -1008,7 +1008,8 @@ void QmlViewer::openQml(const QString& file_or_url) if (!m_script.isEmpty()) tester = new QmlGraphicsTester(m_script, m_scriptOptions, canvas); - canvas->reset(); + delete canvas->rootObject(); + canvas->engine()->clearComponentCache(); QmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("qmlViewer", this); #ifdef Q_OS_SYMBIAN @@ -1058,7 +1059,7 @@ void QmlViewer::openQml(const QString& file_or_url) } } - canvas->setUrl(url); + canvas->setSource(url); QTime t; t.start(); @@ -1125,7 +1126,7 @@ void QmlViewer::setSkin(const QString& skinDirOrName) skin->deleteLater(); } - canvas->setContentResizable(!skin || !scaleSkin); + canvas->setResizeMode((!skin || !scaleSkin) ? QmlView::SizeRootObjectToView : QmlView::SizeViewToRootObject); DeviceSkinParameters parameters; if (!skinDirectory.isEmpty() && parameters.read(skinDirectory,DeviceSkinParameters::ReadAll,&err)) { diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h index 6b05584..fbb5aa5 100644 --- a/tools/qmlviewer/qmlviewer.h +++ b/tools/qmlviewer/qmlviewer.h @@ -116,7 +116,7 @@ public slots: void showProxySettings (); void proxySettingsChanged (); void setScaleView(); - void executeErrors(); + void statusChanged(); void setSlowMode(bool); void launch(const QString &); @@ -132,7 +132,6 @@ private slots: void chooseRecordingOptions(); void pickRecordingFile(); void setScaleSkin(); - void adjustSizeSlot(); void setPortrait(); void setLandscape(); void toggleOrientation(); -- cgit v0.12