summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/util/qdeclarativexmllistmodel.cpp28
-rw-r--r--src/declarative/util/qdeclarativexmllistmodel_p.h2
-rw-r--r--tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp9
3 files changed, 37 insertions, 2 deletions
diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp
index 4a374a5..cae1d3a 100644
--- a/src/declarative/util/qdeclarativexmllistmodel.cpp
+++ b/src/declarative/util/qdeclarativexmllistmodel.cpp
@@ -423,6 +423,7 @@ public:
int highestRole;
QNetworkReply *reply;
QDeclarativeXmlListModel::Status status;
+ QString errorString;
qreal progress;
int queryId;
QStringList keyRoleResultsCache;
@@ -495,10 +496,11 @@ void QDeclarativeXmlListModelPrivate::clear_role(QDeclarativeListProperty<QDecla
</rss>
\endcode
- Then it could be used to create the following model:
+ A XmlListModel could create a model from this data, like this:
\qml
XmlListModel {
+ id: xmlModel
source: "http://www.mysite.com/feed.xml"
query: "/rss/channel/item"
XmlRole { name: "title"; query: "title/string()" }
@@ -511,6 +513,16 @@ void QDeclarativeXmlListModelPrivate::clear_role(QDeclarativeListProperty<QDecla
model item attributes; here, each model item will have \c title and \c pubDate
attributes that match the \c title and \c pubDate values of its corresponding \c <item>.
+ The model could be used in a ListView, like this:
+
+ \qml
+ ListView {
+ width: 180; height: 300
+ model: xmlModel
+ delegate: Text { title + " (" + pubDate + ")" }
+ }
+ \endqml
+
\section2 Using key XML roles
@@ -722,7 +734,8 @@ void QDeclarativeXmlListModel::setNamespaceDeclarations(const QString &declarati
\o XmlListModel.Null - No XML data has been set for this model.
\o XmlListModel.Ready - The XML data has been loaded into the model.
\o XmlListModel.Loading - The model is in the process of reading and loading XML data.
- \o XmlListModel.Error - An error occurred while the model was loading.
+ \o XmlListModel.Error - An error occurred while the model was loading. See errorString() for details
+ about the error.
\endlist
\sa progress
@@ -755,6 +768,12 @@ qreal QDeclarativeXmlListModel::progress() const
return d->progress;
}
+QString QDeclarativeXmlListModel::errorString() const
+{
+ Q_D(const QDeclarativeXmlListModel);
+ return d->errorString;
+}
+
void QDeclarativeXmlListModel::classBegin()
{
Q_D(QDeclarativeXmlListModel);
@@ -807,6 +826,7 @@ void QDeclarativeXmlListModel::reload()
d->queryId = globalXmlQuery()->doQuery(d->query, d->namespaces, d->xml.toUtf8(), &d->roleObjects, d->keyRoleResultsCache);
d->progress = 1.0;
d->status = Loading;
+ d->errorString.clear();
emit progressChanged(d->progress);
emit statusChanged(d->status);
return;
@@ -816,6 +836,7 @@ void QDeclarativeXmlListModel::reload()
d->queryId = XMLLISTMODEL_CLEAR_ID;
d->progress = 1.0;
d->status = Loading;
+ d->errorString.clear();
emit progressChanged(d->progress);
emit statusChanged(d->status);
QTimer::singleShot(0, this, SLOT(dataCleared()));
@@ -824,6 +845,7 @@ void QDeclarativeXmlListModel::reload()
d->progress = 0.0;
d->status = Loading;
+ d->errorString.clear();
emit progressChanged(d->progress);
emit statusChanged(d->status);
@@ -854,6 +876,7 @@ void QDeclarativeXmlListModel::requestFinished()
d->redirectCount = 0;
if (d->reply->error() != QNetworkReply::NoError) {
+ d->errorString = d->reply->errorString();
disconnect(d->reply, 0, this, 0);
d->reply->deleteLater();
d->reply = 0;
@@ -919,6 +942,7 @@ void QDeclarativeXmlListModel::queryCompleted(const QDeclarativeXmlQueryResult &
d->data = result.data;
d->keyRoleResultsCache = result.keyRoleResultsCache;
d->status = Ready;
+ d->errorString.clear();
d->queryId = -1;
bool hasKeys = false;
diff --git a/src/declarative/util/qdeclarativexmllistmodel_p.h b/src/declarative/util/qdeclarativexmllistmodel_p.h
index 7b85476..7101c57 100644
--- a/src/declarative/util/qdeclarativexmllistmodel_p.h
+++ b/src/declarative/util/qdeclarativexmllistmodel_p.h
@@ -113,6 +113,8 @@ public:
Status status() const;
qreal progress() const;
+ Q_INVOKABLE QString errorString() const;
+
virtual void classBegin();
virtual void componentComplete();
diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp
index 4173a44..7769979 100644
--- a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp
+++ b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp
@@ -268,10 +268,12 @@ void tst_qdeclarativexmllistmodel::xml()
QDeclarativeXmlListModel *model = qobject_cast<QDeclarativeXmlListModel*>(component.create());
QSignalSpy spy(model, SIGNAL(statusChanged(QDeclarativeXmlListModel::Status)));
+ QVERIFY(model->errorString().isEmpty());
QCOMPARE(model->progress(), qreal(0.0));
QCOMPARE(model->status(), QDeclarativeXmlListModel::Loading);
QTRY_COMPARE(spy.count(), 1); spy.clear();
QCOMPARE(model->status(), QDeclarativeXmlListModel::Ready);
+ QVERIFY(model->errorString().isEmpty());
QCOMPARE(model->progress(), qreal(1.0));
QCOMPARE(model->count(), 9);
@@ -284,6 +286,7 @@ void tst_qdeclarativexmllistmodel::xml()
QCOMPARE(model->status(), QDeclarativeXmlListModel::Loading);
QTRY_COMPARE(spy.count(), 1); spy.clear();
QCOMPARE(model->status(), QDeclarativeXmlListModel::Ready);
+ QVERIFY(model->errorString().isEmpty());
QCOMPARE(model->count(), count);
delete model;
@@ -309,10 +312,12 @@ void tst_qdeclarativexmllistmodel::source()
QDeclarativeXmlListModel *model = qobject_cast<QDeclarativeXmlListModel*>(component.create());
QSignalSpy spy(model, SIGNAL(statusChanged(QDeclarativeXmlListModel::Status)));
+ QVERIFY(model->errorString().isEmpty());
QCOMPARE(model->progress(), qreal(0.0));
QCOMPARE(model->status(), QDeclarativeXmlListModel::Loading);
QTRY_COMPARE(spy.count(), 1); spy.clear();
QCOMPARE(model->status(), QDeclarativeXmlListModel::Ready);
+ QVERIFY(model->errorString().isEmpty());
QCOMPARE(model->progress(), qreal(1.0));
QCOMPARE(model->count(), 9);
@@ -320,6 +325,7 @@ void tst_qdeclarativexmllistmodel::source()
QCOMPARE(model->progress(), qreal(0.0));
QTRY_COMPARE(spy.count(), 1); spy.clear();
QCOMPARE(model->status(), QDeclarativeXmlListModel::Loading);
+ QVERIFY(model->errorString().isEmpty());
QEventLoop loop;
QTimer timer;
@@ -337,9 +343,12 @@ void tst_qdeclarativexmllistmodel::source()
QCOMPARE(model->status(), status);
QCOMPARE(model->count(), count);
+
if (status == QDeclarativeXmlListModel::Ready)
QCOMPARE(model->progress(), qreal(1.0));
+ QCOMPARE(model->errorString().isEmpty(), status == QDeclarativeXmlListModel::Ready);
+
delete model;
}