summaryrefslogtreecommitdiffstats
path: root/src/declarative/extra
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2009-05-07 01:32:17 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2009-05-07 01:32:17 (GMT)
commit990e4215926c5fd2327e379f6ef872b8274a7f67 (patch)
tree38c2520f7d16c1b6e201260a9968ff30ad362795 /src/declarative/extra
parent2dd06e645cb6e1ffca1274864a62418a2ebe6504 (diff)
downloadQt-990e4215926c5fd2327e379f6ef872b8274a7f67.zip
Qt-990e4215926c5fd2327e379f6ef872b8274a7f67.tar.gz
Qt-990e4215926c5fd2327e379f6ef872b8274a7f67.tar.bz2
Fix QmlXmlListModel on property changes, on empty results.
Tags in flickr demo.
Diffstat (limited to 'src/declarative/extra')
-rw-r--r--src/declarative/extra/qmlxmllistmodel.cpp42
-rw-r--r--src/declarative/extra/qmlxmllistmodel.h2
2 files changed, 34 insertions, 10 deletions
diff --git a/src/declarative/extra/qmlxmllistmodel.cpp b/src/declarative/extra/qmlxmllistmodel.cpp
index af72ecc..bba817d 100644
--- a/src/declarative/extra/qmlxmllistmodel.cpp
+++ b/src/declarative/extra/qmlxmllistmodel.cpp
@@ -90,8 +90,9 @@ class QmlXmlListModelPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QmlXmlListModel)
public:
- QmlXmlListModelPrivate() : size(-1), highestRole(Qt::UserRole), reply(0), roleObjects(this) {}
+ QmlXmlListModelPrivate() : isClassComplete(false), size(-1), highestRole(Qt::UserRole), reply(0), roleObjects(this) {}
+ bool isClassComplete;
QString src;
QString query;
QString namespaces;
@@ -204,7 +205,10 @@ QString QmlXmlListModel::source() const
void QmlXmlListModel::setSource(const QString &src)
{
Q_D(QmlXmlListModel);
- d->src = src;
+ if (d->src != src) {
+ d->src = src;
+ reload();
+ }
}
QString QmlXmlListModel::query() const
@@ -216,7 +220,10 @@ QString QmlXmlListModel::query() const
void QmlXmlListModel::setQuery(const QString &query)
{
Q_D(QmlXmlListModel);
- d->query = query;
+ if (d->query != query) {
+ d->query = query;
+ reload();
+ }
}
QString QmlXmlListModel::namespaceDeclarations() const
@@ -228,29 +235,44 @@ QString QmlXmlListModel::namespaceDeclarations() const
void QmlXmlListModel::setNamespaceDeclarations(const QString &declarations)
{
Q_D(QmlXmlListModel);
- d->namespaces = declarations;
+ if (d->namespaces != declarations) {
+ d->namespaces = declarations;
+ reload();
+ }
}
void QmlXmlListModel::classComplete()
{
- fetch();
+ Q_D(QmlXmlListModel);
+ d->isClassComplete = true;
+ reload();
}
-void QmlXmlListModel::fetch()
+void QmlXmlListModel::reload()
{
Q_D(QmlXmlListModel);
+ if (!d->isClassComplete)
+ return;
+
//clear existing data
d->size = 0;
int count = d->data.count();
d->data.clear();
- emit itemsRemoved(0, count);
+ if (count > 0)
+ emit itemsRemoved(0, count);
if (d->src.isEmpty()) {
- qWarning() << "Can't fetch empty src string";
+ qWarning() << "Can't load empty src string";
return;
}
+ if (d->reply) {
+ d->reply->abort();
+ d->reply->deleteLater();
+ d->reply = 0;
+ }
+
QNetworkRequest req((QUrl(d->src)));
req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
d->reply = qmlContext(this)->engine()->networkAccessManager()->get(req);
@@ -316,7 +338,9 @@ void QmlXmlListModel::doQuery(QByteArray &rawData)
d->xml = xml;
d->size = count;
- emit itemsInserted(0, count);
+
+ if (count > 0)
+ emit itemsInserted(0, count);
}
void QmlXmlListModel::doSubquery(int index) const
diff --git a/src/declarative/extra/qmlxmllistmodel.h b/src/declarative/extra/qmlxmllistmodel.h
index acc54a9..2e932cb 100644
--- a/src/declarative/extra/qmlxmllistmodel.h
+++ b/src/declarative/extra/qmlxmllistmodel.h
@@ -118,7 +118,7 @@ public:
virtual void classComplete();
public Q_SLOTS:
- void fetch();
+ void reload();
protected:
void doQuery(QByteArray &rawData);