diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-05-20 06:15:25 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-05-20 06:15:25 (GMT) |
commit | 74fd2979aed842bee3b841974c6b13c466d272a6 (patch) | |
tree | 8b63bfe458be97eba7eac2894fe28dcf991b9922 /src/declarative/extra/qmlxmllistmodel.cpp | |
parent | 63b7592be90d17be954bbfb9fd194dccb09741ea (diff) | |
download | Qt-74fd2979aed842bee3b841974c6b13c466d272a6.zip Qt-74fd2979aed842bee3b841974c6b13c466d272a6.tar.gz Qt-74fd2979aed842bee3b841974c6b13c466d272a6.tar.bz2 |
Add status and feedback info to XmlListModel
Diffstat (limited to 'src/declarative/extra/qmlxmllistmodel.cpp')
-rw-r--r-- | src/declarative/extra/qmlxmllistmodel.cpp | 40 |
1 files changed, 36 insertions, 4 deletions
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) |