summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2010-02-23 06:46:44 (GMT)
committerMartin Jones <martin.jones@nokia.com>2010-02-23 06:46:44 (GMT)
commit5ffd6c0fba0ecc709551e414ed0649de15ac3754 (patch)
tree7db7006ef6349b48a75729766362e44d06999442 /src
parent113e350e36c0ff31824bc238160094814dc3fb4f (diff)
downloadQt-5ffd6c0fba0ecc709551e414ed0649de15ac3754.zip
Qt-5ffd6c0fba0ecc709551e414ed0649de15ac3754.tar.gz
Qt-5ffd6c0fba0ecc709551e414ed0649de15ac3754.tar.bz2
Remove QmlView::execute(). QmlView::setSource() does it all now.
Task-number: QT-2538
Diffstat (limited to 'src')
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp3
-rw-r--r--src/declarative/util/qmlview.cpp60
-rw-r--r--src/declarative/util/qmlview.h3
3 files changed, 37 insertions, 29 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp
index bfa9e9b..a9d67ab 100644
--- a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp
@@ -802,11 +802,10 @@ void QmlGraphicsVisualDataModel::setDelegate(QmlComponent *delegate)
QApplication app(argc, argv);
QmlView view;
- view.setSource(QUrl("qrc:view.qml"));
MyModel model(view.rootContext());
- view.execute();
+ view.setSource(QUrl("qrc:view.qml"));
view.show();
return app.exec();
diff --git a/src/declarative/util/qmlview.cpp b/src/declarative/util/qmlview.cpp
index 400ae52..05c6460 100644
--- a/src/declarative/util/qmlview.cpp
+++ b/src/declarative/util/qmlview.cpp
@@ -132,6 +132,8 @@ public:
QmlViewPrivate(QmlView *view)
: q(view), root(0), component(0), resizeMode(QmlView::SizeViewToRootObject) {}
+ void execute();
+
QmlView *q;
QGuard<QGraphicsObject> root;
@@ -152,6 +154,20 @@ public:
QGraphicsScene scene;
};
+void QmlViewPrivate::execute()
+{
+ delete root;
+ delete component;
+ component = new QmlComponent(&engine, source, q);
+
+ if (!component->isLoading()) {
+ q->continueExecute();
+ } else {
+ QObject::connect(component, SIGNAL(statusChanged(QmlComponent::Status)), q, SLOT(continueExecute()));
+ }
+}
+
+
/*!
\class QmlView
\brief The QmlView class provides a widget for displaying a Qt Declarative user interface.
@@ -188,9 +204,6 @@ public:
QUrl url(fileName);
view->setSource(url);
- ...
- view->execute();
- ...
view->show();
\endcode
@@ -220,6 +233,19 @@ QmlView::QmlView(QWidget *parent)
d->init();
}
+/*!
+ \fn QmlView::QmlView(const QUrl &source, QWidget *parent)
+
+ Constructs a QmlView with the given QML \a source and \a parent.
+*/
+QmlView::QmlView(const QUrl &source, QWidget *parent)
+: QGraphicsView(parent), d(new QmlViewPrivate(this))
+{
+ setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
+ d->init();
+ setSource(source);
+}
+
void QmlViewPrivate::init()
{
#ifdef Q_ENABLE_PERFORMANCE_LOG
@@ -254,15 +280,14 @@ QmlView::~QmlView()
}
/*!
- Sets the source to the \a url.
-
- Call \l execute() to load the QML and instantiate the component.
-
- \sa execute()
+ Sets the source to the \a url, loads the QML component and instantiates it.
*/
void QmlView::setSource(const QUrl& url)
{
- d->source = url;
+ if (url != d->source) {
+ d->source = url;
+ d->execute();
+ }
}
/*!
@@ -296,23 +321,6 @@ QmlContext* QmlView::rootContext()
return d->engine.rootContext();
}
-/*!
- Loads and instantiates the QML component set by the \l setSource() method.
-
- \sa setSource()
-*/
-void QmlView::execute()
-{
- delete d->root;
- delete d->component;
- d->component = new QmlComponent(&d->engine, d->source, this);
-
- if (!d->component->isLoading()) {
- continueExecute();
- } else {
- connect(d->component, SIGNAL(statusChanged(QmlComponent::Status)), this, SLOT(continueExecute()));
- }
-}
/*!
\enum QmlView::Status
diff --git a/src/declarative/util/qmlview.h b/src/declarative/util/qmlview.h
index 1d6ef1c..5f72781 100644
--- a/src/declarative/util/qmlview.h
+++ b/src/declarative/util/qmlview.h
@@ -67,6 +67,7 @@ class Q_DECLARATIVE_EXPORT QmlView : public QGraphicsView
public:
explicit QmlView(QWidget *parent = 0);
+ QmlView(const QUrl &source, QWidget *parent = 0);
virtual ~QmlView();
QUrl source() const;
@@ -74,7 +75,6 @@ public:
QmlEngine* engine();
QmlContext* rootContext();
- void execute();
QGraphicsObject *rootObject() const;
@@ -102,6 +102,7 @@ protected:
virtual void paintEvent(QPaintEvent *event);
void timerEvent(QTimerEvent*);
+ friend class QmlViewPrivate;
QmlViewPrivate *d;
};