summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2011-01-10 02:13:00 (GMT)
committerBea Lam <bea.lam@nokia.com>2011-01-10 02:15:39 (GMT)
commit82ff3f484c7ec49e60b7fddf23794937974a6768 (patch)
treed83bea1b2480fbe6a3d06c258ee6e9d580705dc5 /src
parent2707cdd482c975e58a4736ac85c32af45435f561 (diff)
downloadQt-82ff3f484c7ec49e60b7fddf23794937974a6768.zip
Qt-82ff3f484c7ec49e60b7fddf23794937974a6768.tar.gz
Qt-82ff3f484c7ec49e60b7fddf23794937974a6768.tar.bz2
Fix loaded() signal to be emitted only once
Task-number: QTBUG-16319 Reviewed-by: Martin Jones
Diffstat (limited to 'src')
-rw-r--r--src/declarative/graphicsitems/qdeclarativeloader.cpp60
-rw-r--r--src/declarative/graphicsitems/qdeclarativeloader_p_p.h2
2 files changed, 35 insertions, 27 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeloader.cpp b/src/declarative/graphicsitems/qdeclarativeloader.cpp
index 1119b92..22ec019 100644
--- a/src/declarative/graphicsitems/qdeclarativeloader.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeloader.cpp
@@ -48,7 +48,7 @@
QT_BEGIN_NAMESPACE
QDeclarativeLoaderPrivate::QDeclarativeLoaderPrivate()
- : item(0), component(0), ownComponent(false)
+ : item(0), component(0), ownComponent(false), isComponentComplete(false)
{
}
@@ -262,6 +262,7 @@ void QDeclarativeLoader::setSource(const QUrl &url)
d->clear();
d->source = url;
+
if (d->source.isEmpty()) {
emit sourceChanged();
emit statusChanged();
@@ -272,18 +273,9 @@ void QDeclarativeLoader::setSource(const QUrl &url)
d->component = new QDeclarativeComponent(qmlEngine(this), d->source, this);
d->ownComponent = true;
- if (!d->component->isLoading()) {
- d->_q_sourceLoaded();
- } else {
- connect(d->component, SIGNAL(statusChanged(QDeclarativeComponent::Status)),
- this, SLOT(_q_sourceLoaded()));
- connect(d->component, SIGNAL(progressChanged(qreal)),
- this, SIGNAL(progressChanged()));
- emit statusChanged();
- emit progressChanged();
- emit sourceChanged();
- emit itemChanged();
- }
+
+ if (d->isComponentComplete)
+ d->load();
}
/*!
@@ -324,6 +316,7 @@ void QDeclarativeLoader::setSourceComponent(QDeclarativeComponent *comp)
d->component = comp;
d->ownComponent = false;
+
if (!d->component) {
emit sourceChanged();
emit statusChanged();
@@ -332,18 +325,8 @@ void QDeclarativeLoader::setSourceComponent(QDeclarativeComponent *comp)
return;
}
- if (!d->component->isLoading()) {
- d->_q_sourceLoaded();
- } else {
- connect(d->component, SIGNAL(statusChanged(QDeclarativeComponent::Status)),
- this, SLOT(_q_sourceLoaded()));
- connect(d->component, SIGNAL(progressChanged(qreal)),
- this, SIGNAL(progressChanged()));
- emit progressChanged();
- emit sourceChanged();
- emit statusChanged();
- emit itemChanged();
- }
+ if (d->isComponentComplete)
+ d->load();
}
void QDeclarativeLoader::resetSourceComponent()
@@ -351,6 +334,27 @@ void QDeclarativeLoader::resetSourceComponent()
setSourceComponent(0);
}
+void QDeclarativeLoaderPrivate::load()
+{
+ Q_Q(QDeclarativeLoader);
+
+ if (!isComponentComplete || !component)
+ return;
+
+ if (!component->isLoading()) {
+ _q_sourceLoaded();
+ } else {
+ QObject::connect(component, SIGNAL(statusChanged(QDeclarativeComponent::Status)),
+ q, SLOT(_q_sourceLoaded()));
+ QObject::connect(component, SIGNAL(progressChanged(qreal)),
+ q, SIGNAL(progressChanged()));
+ emit q->statusChanged();
+ emit q->progressChanged();
+ emit q->sourceChanged();
+ emit q->itemChanged();
+ }
+}
+
void QDeclarativeLoaderPrivate::_q_sourceLoaded()
{
Q_Q(QDeclarativeLoader);
@@ -465,9 +469,11 @@ QDeclarativeLoader::Status QDeclarativeLoader::status() const
void QDeclarativeLoader::componentComplete()
{
+ Q_D(QDeclarativeLoader);
+
QDeclarativeItem::componentComplete();
- if (status() == Ready)
- emit loaded();
+ d->isComponentComplete = true;
+ d->load();
}
diff --git a/src/declarative/graphicsitems/qdeclarativeloader_p_p.h b/src/declarative/graphicsitems/qdeclarativeloader_p_p.h
index 0d4c4d0..bc65781 100644
--- a/src/declarative/graphicsitems/qdeclarativeloader_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeloader_p_p.h
@@ -72,11 +72,13 @@ public:
void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry);
void clear();
void initResize();
+ void load();
QUrl source;
QGraphicsObject *item;
QDeclarativeComponent *component;
bool ownComponent : 1;
+ bool isComponentComplete : 1;
void _q_sourceLoaded();
void _q_updateSize(bool loaderGeometryChanged = true);