summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2009-11-05 04:51:40 (GMT)
committerMartin Jones <martin.jones@nokia.com>2009-11-05 04:51:40 (GMT)
commit7d290c0a38f325a3c024a38bcd5da94877d7fd64 (patch)
tree756d57096d1aeede61d2c4ae483ed4fdc7b9f225 /src/declarative
parent8fbff4dffd53546e4c3acecd0a9700a7ad970c83 (diff)
downloadQt-7d290c0a38f325a3c024a38bcd5da94877d7fd64.zip
Qt-7d290c0a38f325a3c024a38bcd5da94877d7fd64.tar.gz
Qt-7d290c0a38f325a3c024a38bcd5da94877d7fd64.tar.bz2
Loader cleanup and testing.
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsloader.cpp89
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsloader_p.h1
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsloader_p_p.h5
3 files changed, 53 insertions, 42 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicsloader.cpp b/src/declarative/graphicsitems/qmlgraphicsloader.cpp
index 4d463ab..d42e559 100644
--- a/src/declarative/graphicsitems/qmlgraphicsloader.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicsloader.cpp
@@ -45,7 +45,8 @@
QT_BEGIN_NAMESPACE
QmlGraphicsLoaderPrivate::QmlGraphicsLoaderPrivate()
-: item(0), component(0), ownComponent(false), resizeMode(QmlGraphicsLoader::SizeLoaderToItem)
+ : item(0), component(0), ownComponent(false)
+ , resizeMode(QmlGraphicsLoader::SizeLoaderToItem)
{
}
@@ -53,6 +54,36 @@ QmlGraphicsLoaderPrivate::~QmlGraphicsLoaderPrivate()
{
}
+void QmlGraphicsLoaderPrivate::clear()
+{
+ if (ownComponent) {
+ delete component;
+ component = 0;
+ ownComponent = false;
+ }
+ source = QUrl();
+
+ delete item;
+ item = 0;
+}
+
+void QmlGraphicsLoaderPrivate::initResize()
+{
+ Q_Q(QmlGraphicsLoader);
+
+ QmlGraphicsItem *resizeItem = 0;
+ if (resizeMode == QmlGraphicsLoader::SizeLoaderToItem)
+ resizeItem = item;
+ else if (resizeMode == QmlGraphicsLoader::SizeItemToLoader)
+ resizeItem = q;
+ if (resizeItem) {
+ QObject::connect(resizeItem, SIGNAL(widthChanged()), q, SLOT(_q_updateSize()));
+ QObject::connect(resizeItem, SIGNAL(heightChanged()), q, SLOT(_q_updateSize()));
+ }
+ _q_updateSize();
+}
+
+
QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Loader,QmlGraphicsLoader)
/*!
@@ -74,6 +105,17 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Loader,QmlGraphicsLoader)
MouseRegion { anchors.fill: parent; onClicked: pageLoader.source = "Page1.qml" }
}
\endcode
+
+ If the Loader source is changed, any previous items instantiated
+ will be destroyed. Setting \c source to an empty string
+ will destroy the currently instantiated items, freeing resources
+ and leaving the Loader empty. For example:
+
+ \code
+ pageLoader.source = ""
+ \endcode
+
+ unloads "Page1.qml" and frees resources consumed by it.
*/
/*!
@@ -102,7 +144,7 @@ QmlGraphicsLoader::~QmlGraphicsLoader()
This property holds the URL of the QML component to
instantiate.
- \sa status, progress
+ \sa sourceComponent, status, progress
*/
QUrl QmlGraphicsLoader::source() const
{
@@ -116,12 +158,7 @@ void QmlGraphicsLoader::setSource(const QUrl &url)
if (d->source == url)
return;
- if (d->ownComponent) {
- delete d->component;
- d->component = 0;
- }
- delete d->item;
- d->item = 0;
+ d->clear();
d->source = url;
if (d->source.isEmpty()) {
@@ -164,7 +201,7 @@ void QmlGraphicsLoader::setSource(const QUrl &url)
}
\endqml
- \sa source
+ \sa source, progress
*/
QmlComponent *QmlGraphicsLoader::sourceComponent() const
@@ -179,13 +216,7 @@ void QmlGraphicsLoader::setSourceComponent(QmlComponent *comp)
if (comp == d->component)
return;
- d->source = QUrl();
- if (d->ownComponent) {
- delete d->component;
- d->component = 0;
- }
- delete d->item;
- d->item = 0;
+ d->clear();
d->component = comp;
d->ownComponent = false;
@@ -233,16 +264,7 @@ void QmlGraphicsLoaderPrivate::_q_sourceLoaded()
if (item) {
item->setParentItem(q);
// item->setFocus(true);
- QmlGraphicsItem *resizeItem = 0;
- if (resizeMode == QmlGraphicsLoader::SizeLoaderToItem)
- resizeItem = item;
- else if (resizeMode == QmlGraphicsLoader::SizeItemToLoader)
- resizeItem = q;
- if (resizeItem) {
- QObject::connect(resizeItem, SIGNAL(widthChanged()), q, SLOT(_q_updateSize()));
- QObject::connect(resizeItem, SIGNAL(heightChanged()), q, SLOT(_q_updateSize()));
- }
- _q_updateSize();
+ initResize();
}
} else {
delete obj;
@@ -340,20 +362,7 @@ void QmlGraphicsLoader::setResizeMode(ResizeMode mode)
}
d->resizeMode = mode;
-
- if (d->item) {
- QmlGraphicsItem *resizeItem = 0;
- if (d->resizeMode == SizeLoaderToItem)
- resizeItem = d->item;
- else if (d->resizeMode == SizeItemToLoader)
- resizeItem = this;
- if (resizeItem) {
- connect(resizeItem, SIGNAL(widthChanged()), this, SLOT(_q_updateSize()));
- connect(resizeItem, SIGNAL(heightChanged()), this, SLOT(_q_updateSize()));
- }
-
- d->_q_updateSize();
- }
+ d->initResize();
}
void QmlGraphicsLoaderPrivate::_q_updateSize()
diff --git a/src/declarative/graphicsitems/qmlgraphicsloader_p.h b/src/declarative/graphicsitems/qmlgraphicsloader_p.h
index 8cd1819..ad516b4 100644
--- a/src/declarative/graphicsitems/qmlgraphicsloader_p.h
+++ b/src/declarative/graphicsitems/qmlgraphicsloader_p.h
@@ -63,7 +63,6 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsLoader : public QmlGraphicsItem
Q_PROPERTY(QmlGraphicsItem *item READ item NOTIFY itemChanged)
Q_PROPERTY(Status status READ status NOTIFY statusChanged)
Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged)
- //### sourceItem
public:
QmlGraphicsLoader(QmlGraphicsItem *parent=0);
diff --git a/src/declarative/graphicsitems/qmlgraphicsloader_p_p.h b/src/declarative/graphicsitems/qmlgraphicsloader_p_p.h
index 23fedb7..cd7316d 100644
--- a/src/declarative/graphicsitems/qmlgraphicsloader_p_p.h
+++ b/src/declarative/graphicsitems/qmlgraphicsloader_p_p.h
@@ -67,10 +67,13 @@ public:
QmlGraphicsLoaderPrivate();
~QmlGraphicsLoaderPrivate();
+ void clear();
+ void initResize();
+
QUrl source;
QmlGraphicsItem *item;
QmlComponent *component;
- bool ownComponent;
+ bool ownComponent : 1;
QmlGraphicsLoader::ResizeMode resizeMode;
void _q_sourceLoaded();