summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--demos/declarative/flickr/flickr.qml2
-rw-r--r--src/declarative/extra/qmlxmllistmodel.cpp40
-rw-r--r--src/declarative/extra/qmlxmllistmodel.h12
3 files changed, 50 insertions, 4 deletions
diff --git a/demos/declarative/flickr/flickr.qml b/demos/declarative/flickr/flickr.qml
index b113f56..da77d93 100644
--- a/demos/declarative/flickr/flickr.qml
+++ b/demos/declarative/flickr/flickr.qml
@@ -122,6 +122,8 @@ Item {
Image { source: "content/pics/background.png"; opaque: true; anchors.fill: parent }
+ Loading { anchors.centeredIn: parent; visible: FeedModel.status != 0 }
+
GridView {
id: PhotoGridView; model: FeedModel; delegate: PhotoDelegate; cacheBuffer: 100
cellWidth: 105; cellHeight: 105; x:32; y: 80; width: 800; height: 330; z: 1
diff --git a/src/declarative/extra/qmlxmllistmodel.cpp b/src/declarative/extra/qmlxmllistmodel.cpp
index 3732323..9259c83 100644
--- a/src/declarative/extra/qmlxmllistmodel.cpp
+++ b/src/declarative/extra/qmlxmllistmodel.cpp
@@ -266,7 +266,8 @@ class QmlXmlListModelPrivate : public QObjectPrivate
public:
QmlXmlListModelPrivate()
: isClassComplete(false), size(-1), highestRole(Qt::UserRole)
- , reply(0), queryId(-1), roleObjects(this) {}
+ , reply(0), status(QmlXmlListModel::Idle), progress(0.0)
+ , queryId(-1), roleObjects(this) {}
bool isClassComplete;
QString src;
@@ -277,6 +278,8 @@ public:
QStringList roleNames;
int highestRole;
QNetworkReply *reply;
+ QmlXmlListModel::Status status;
+ qreal progress;
QmlXmlQuery qmlXmlQuery;
int queryId;
QmlXmlRoleList roleObjects;
@@ -344,7 +347,6 @@ QmlXmlListModel::QmlXmlListModel(QObject *parent)
QmlXmlListModel::~QmlXmlListModel()
{
- Q_D(QmlXmlListModel);
}
QmlList<XmlListModelRole *> *QmlXmlListModel::roleObjects()
@@ -430,6 +432,17 @@ void QmlXmlListModel::setNamespaceDeclarations(const QString &declarations)
reload();
}
}
+QmlXmlListModel::Status QmlXmlListModel::status() const
+{
+ Q_D(const QmlXmlListModel);
+ return d->status;
+}
+
+qreal QmlXmlListModel::progress() const
+{
+ Q_D(const QmlXmlListModel);
+ return d->progress;
+}
void QmlXmlListModel::classComplete()
{
@@ -465,12 +478,17 @@ void QmlXmlListModel::reload()
d->reply->deleteLater();
d->reply = 0;
}
+ d->progress = 0.0;
+ d->status = Loading;
+ emit progressChanged(d->progress);
+ emit statusChanged(d->status);
QNetworkRequest req((QUrl(d->src)));
req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
d->reply = qmlContext(this)->engine()->networkAccessManager()->get(req);
- QObject::connect(d->reply, SIGNAL(finished()),
- this, SLOT(requestFinished()));
+ QObject::connect(d->reply, SIGNAL(finished()), this, SLOT(requestFinished()));
+ QObject::connect(d->reply, SIGNAL(downloadProgress(qint64,qint64)),
+ this, SLOT(requestProgress(qint64,qint64)));
}
void QmlXmlListModel::requestFinished()
@@ -479,12 +497,26 @@ void QmlXmlListModel::requestFinished()
if (d->reply->error() != QNetworkReply::NoError) {
d->reply->deleteLater();
d->reply = 0;
+ d->status = Error;
} else {
+ d->status = Idle;
QByteArray data = d->reply->readAll();
d->queryId = d->qmlXmlQuery.doQuery(d->query, d->namespaces, data, &d->roleObjects);
d->reply->deleteLater();
d->reply = 0;
}
+ d->progress = 1.0;
+ emit progressChanged(d->progress);
+ emit statusChanged(d->status);
+}
+
+void QmlXmlListModel::requestProgress(qint64 received, qint64 total)
+{
+ Q_D(QmlXmlListModel);
+ if (d->status == Loading && total > 0) {
+ d->progress = qreal(received)/total;
+ emit progressChanged(d->progress);
+ }
}
void QmlXmlListModel::queryCompleted(int id, int size)
diff --git a/src/declarative/extra/qmlxmllistmodel.h b/src/declarative/extra/qmlxmllistmodel.h
index f837040..cf2f5f4 100644
--- a/src/declarative/extra/qmlxmllistmodel.h
+++ b/src/declarative/extra/qmlxmllistmodel.h
@@ -89,7 +89,10 @@ class Q_DECLARATIVE_EXPORT QmlXmlListModel : public QListModelInterface, public
{
Q_OBJECT
Q_INTERFACES(QmlParserStatus)
+ Q_ENUMS(Status)
+ Q_PROPERTY(Status status READ status NOTIFY statusChanged)
+ Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged)
Q_PROPERTY(QString source READ source WRITE setSource)
Q_PROPERTY(QString query READ query WRITE setQuery)
Q_PROPERTY(QString namespaceDeclarations READ namespaceDeclarations WRITE setNamespaceDeclarations)
@@ -115,13 +118,22 @@ public:
QString namespaceDeclarations() const;
void setNamespaceDeclarations(const QString&);
+ enum Status { Idle, Loading, Error };
+ Status status() const;
+ qreal progress() const;
+
virtual void classComplete();
+signals:
+ void statusChanged(Status);
+ void progressChanged(qreal progress);
+
public Q_SLOTS:
void reload();
private Q_SLOTS:
void requestFinished();
+ void requestProgress(qint64,qint64);
void queryCompleted(int,int);
private: