summaryrefslogtreecommitdiffstats
path: root/src/declarative/extra
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2009-08-31 03:37:14 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2009-08-31 03:37:14 (GMT)
commit85da2a5d07bf8c56f55a7c89d45d66ef35af0c68 (patch)
treeea25714fb0ad98655e1afccf4e507c563525c7b1 /src/declarative/extra
parent25dffe6b5367518486edf8a91d5674be4852c50e (diff)
downloadQt-85da2a5d07bf8c56f55a7c89d45d66ef35af0c68.zip
Qt-85da2a5d07bf8c56f55a7c89d45d66ef35af0c68.tar.gz
Qt-85da2a5d07bf8c56f55a7c89d45d66ef35af0c68.tar.bz2
Add xml property to XmlListModel so we can set XML data directly.
Diffstat (limited to 'src/declarative/extra')
-rw-r--r--src/declarative/extra/qmlxmllistmodel.cpp40
-rw-r--r--src/declarative/extra/qmlxmllistmodel.h4
2 files changed, 39 insertions, 5 deletions
diff --git a/src/declarative/extra/qmlxmllistmodel.cpp b/src/declarative/extra/qmlxmllistmodel.cpp
index 816c3fd..60a28b4 100644
--- a/src/declarative/extra/qmlxmllistmodel.cpp
+++ b/src/declarative/extra/qmlxmllistmodel.cpp
@@ -76,8 +76,6 @@ struct QmlXmlRoleList : public QmlConcreteList<XmlListModelRole *>
QmlXmlListModelPrivate *model;
};
-
-
class QmlXmlQuery : public QThread
{
Q_OBJECT
@@ -295,6 +293,7 @@ public:
bool isComponentComplete;
QUrl src;
+ QString xml;
QString query;
QString namespaces;
int size;
@@ -460,6 +459,8 @@ QString QmlXmlListModel::toString(int role) const
/*!
\qmlproperty url XmlListModel::source
The location of the XML data source.
+
+ If both source and xml are set, xml will be used.
*/
QUrl QmlXmlListModel::source() const
{
@@ -477,6 +478,27 @@ void QmlXmlListModel::setSource(const QUrl &src)
}
/*!
+ \qmlproperty string XmlListModel::xml
+ This property holds XML text set directly.
+
+ The text is assumed to be UTF-8 encoded.
+
+ If both source and xml are set, xml will be used.
+*/
+QString QmlXmlListModel::xml() const
+{
+ Q_D(const QmlXmlListModel);
+ return d->xml;
+}
+
+void QmlXmlListModel::setXml(const QString &xml)
+{
+ Q_D(QmlXmlListModel);
+ d->xml = xml;
+ reload();
+}
+
+/*!
\qmlproperty url XmlListModel::query
An absolute XPath query representing the base query for the model items. The query should start with
a '/' or '//'.
@@ -589,16 +611,24 @@ void QmlXmlListModel::reload()
if (count > 0)
emit itemsRemoved(0, count);
- if (d->src.isEmpty()) {
- qmlInfo(this) << "Can't load empty src string";
+ if (d->src.isEmpty() && d->xml.isEmpty())
return;
- }
if (d->reply) {
d->reply->abort();
d->reply->deleteLater();
d->reply = 0;
}
+
+ if (!d->xml.isEmpty()) {
+ d->queryId = d->qmlXmlQuery.doQuery(d->query, d->namespaces, d->xml.toUtf8(), &d->roleObjects);
+ d->progress = 1.0;
+ d->status = Idle;
+ emit progressChanged(d->progress);
+ emit statusChanged(d->status);
+ return;
+ }
+
d->progress = 0.0;
d->status = Loading;
emit progressChanged(d->progress);
diff --git a/src/declarative/extra/qmlxmllistmodel.h b/src/declarative/extra/qmlxmllistmodel.h
index 18d33fb..fbf95db 100644
--- a/src/declarative/extra/qmlxmllistmodel.h
+++ b/src/declarative/extra/qmlxmllistmodel.h
@@ -95,6 +95,7 @@ class Q_DECLARATIVE_EXPORT QmlXmlListModel : public QListModelInterface, public
Q_PROPERTY(Status status READ status NOTIFY statusChanged)
Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged)
Q_PROPERTY(QUrl source READ source WRITE setSource)
+ Q_PROPERTY(QString xml READ xml WRITE setXml)
Q_PROPERTY(QString query READ query WRITE setQuery)
Q_PROPERTY(QString namespaceDeclarations READ namespaceDeclarations WRITE setNamespaceDeclarations)
Q_PROPERTY(QmlList<XmlListModelRole *> *roles READ roleObjects)
@@ -115,6 +116,9 @@ public:
QUrl source() const;
void setSource(const QUrl&);
+ QString xml() const;
+ void setXml(const QString&);
+
QString query() const;
void setQuery(const QString&);