summaryrefslogtreecommitdiffstats
path: root/src/declarative/util/qmlview.cpp
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2010-02-23 08:44:01 (GMT)
committerRoberto Raggi <roberto.raggi@nokia.com>2010-02-23 08:44:01 (GMT)
commitab3a625e1bc03481f740a32cdbe8c4559cf7cb1e (patch)
tree01adb2ad207b9a2980492a24cb820925f7e48635 /src/declarative/util/qmlview.cpp
parent20fc9f2e264f34dd8580949ddbe5511b78ab0ac4 (diff)
parent48161233af2a6071bc0ba99e546da98f705b8281 (diff)
downloadQt-ab3a625e1bc03481f740a32cdbe8c4559cf7cb1e.zip
Qt-ab3a625e1bc03481f740a32cdbe8c4559cf7cb1e.tar.gz
Qt-ab3a625e1bc03481f740a32cdbe8c4559cf7cb1e.tar.bz2
Merge remote branch 'origin/master' into qtruntime
Diffstat (limited to 'src/declarative/util/qmlview.cpp')
-rw-r--r--src/declarative/util/qmlview.cpp60
1 files changed, 34 insertions, 26 deletions
diff --git a/src/declarative/util/qmlview.cpp b/src/declarative/util/qmlview.cpp
index 8844430..9e95b66 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