summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2010-05-12 01:09:44 (GMT)
committerMartin Jones <martin.jones@nokia.com>2010-05-12 01:09:44 (GMT)
commita19df56265e59bb26f927638aa5c75ccd666c388 (patch)
treec3eb1175e4a59893bd3d0762207bb446405ea2b4 /src/declarative
parent6527735ff53a8ec593f5f85b037de46059e1207e (diff)
parent1b2b9ba6b4cea31d679aeae915e590ddbf1da945 (diff)
downloadQt-a19df56265e59bb26f927638aa5c75ccd666c388.zip
Qt-a19df56265e59bb26f927638aa5c75ccd666c388.tar.gz
Qt-a19df56265e59bb26f927638aa5c75ccd666c388.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/util/qdeclarativeview.cpp45
-rw-r--r--src/declarative/util/qdeclarativeview.h3
-rw-r--r--src/declarative/util/qdeclarativexmllistmodel.cpp84
3 files changed, 97 insertions, 35 deletions
diff --git a/src/declarative/util/qdeclarativeview.cpp b/src/declarative/util/qdeclarativeview.cpp
index 833e284..e68ef94 100644
--- a/src/declarative/util/qdeclarativeview.cpp
+++ b/src/declarative/util/qdeclarativeview.cpp
@@ -128,19 +128,18 @@ void FrameBreakAnimation::updateCurrentTime(int msecs)
server->frameBreak();
}
-class QDeclarativeViewPrivate : public QDeclarativeItemChangeListener
+class QDeclarativeViewPrivate : public QGraphicsViewPrivate, public QDeclarativeItemChangeListener
{
+ Q_DECLARE_PUBLIC(QDeclarativeView)
public:
- QDeclarativeViewPrivate(QDeclarativeView *view)
- : q(view), root(0), declarativeItemRoot(0), graphicsWidgetRoot(0), component(0), resizeMode(QDeclarativeView::SizeViewToRootObject) {}
+ QDeclarativeViewPrivate()
+ : root(0), declarativeItemRoot(0), graphicsWidgetRoot(0), component(0), resizeMode(QDeclarativeView::SizeViewToRootObject) {}
~QDeclarativeViewPrivate() { delete root; }
void execute();
void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry);
void initResize();
void updateSize();
- inline QSize rootObjectSize();
-
- QDeclarativeView *q;
+ inline QSize rootObjectSize() const;
QDeclarativeGuard<QGraphicsObject> root;
QDeclarativeGuard<QDeclarativeItem> declarativeItemRoot;
@@ -162,6 +161,7 @@ public:
void QDeclarativeViewPrivate::execute()
{
+ Q_Q(QDeclarativeView);
if (root) {
delete root;
root = 0;
@@ -182,6 +182,7 @@ void QDeclarativeViewPrivate::execute()
void QDeclarativeViewPrivate::itemGeometryChanged(QDeclarativeItem *resizeItem, const QRectF &newGeometry, const QRectF &oldGeometry)
{
+ Q_Q(QDeclarativeView);
if (resizeItem == root && resizeMode == QDeclarativeView::SizeViewToRootObject) {
// wait for both width and height to be changed
resizetimer.start(0,q);
@@ -250,8 +251,9 @@ void QDeclarativeViewPrivate::itemGeometryChanged(QDeclarativeItem *resizeItem,
Constructs a QDeclarativeView with the given \a parent.
*/
QDeclarativeView::QDeclarativeView(QWidget *parent)
-: QGraphicsView(parent), d(new QDeclarativeViewPrivate(this))
+ : QGraphicsView(*(new QDeclarativeViewPrivate), parent)
{
+ Q_D(QDeclarativeView);
setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
d->init();
}
@@ -262,8 +264,9 @@ QDeclarativeView::QDeclarativeView(QWidget *parent)
Constructs a QDeclarativeView with the given QML \a source and \a parent.
*/
QDeclarativeView::QDeclarativeView(const QUrl &source, QWidget *parent)
-: QGraphicsView(parent), d(new QDeclarativeViewPrivate(this))
+ : QGraphicsView(*(new QDeclarativeViewPrivate), parent)
{
+ Q_D(QDeclarativeView);
setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
d->init();
setSource(source);
@@ -271,6 +274,7 @@ QDeclarativeView::QDeclarativeView(const QUrl &source, QWidget *parent)
void QDeclarativeViewPrivate::init()
{
+ Q_Q(QDeclarativeView);
q->setScene(&scene);
q->setOptimizationFlags(QGraphicsView::DontSavePainterState);
@@ -288,12 +292,10 @@ void QDeclarativeViewPrivate::init()
}
/*!
- The destructor clears the view's \l {QGraphicsObject} {items} and
- deletes the internal representation.
+ Destroys the view.
*/
QDeclarativeView::~QDeclarativeView()
{
- delete d;
}
/*! \property QDeclarativeView::source
@@ -316,6 +318,7 @@ QDeclarativeView::~QDeclarativeView()
*/
void QDeclarativeView::setSource(const QUrl& url)
{
+ Q_D(QDeclarativeView);
d->source = url;
d->execute();
}
@@ -327,6 +330,7 @@ void QDeclarativeView::setSource(const QUrl& url)
*/
QUrl QDeclarativeView::source() const
{
+ Q_D(const QDeclarativeView);
return d->source;
}
@@ -336,6 +340,7 @@ QUrl QDeclarativeView::source() const
*/
QDeclarativeEngine* QDeclarativeView::engine()
{
+ Q_D(QDeclarativeView);
return &d->engine;
}
@@ -348,6 +353,7 @@ QDeclarativeEngine* QDeclarativeView::engine()
*/
QDeclarativeContext* QDeclarativeView::rootContext()
{
+ Q_D(QDeclarativeView);
return d->engine.rootContext();
}
@@ -376,6 +382,7 @@ QDeclarativeContext* QDeclarativeView::rootContext()
QDeclarativeView::Status QDeclarativeView::status() const
{
+ Q_D(const QDeclarativeView);
if (!d->component)
return QDeclarativeView::Null;
@@ -388,6 +395,7 @@ QDeclarativeView::Status QDeclarativeView::status() const
*/
QList<QDeclarativeError> QDeclarativeView::errors() const
{
+ Q_D(const QDeclarativeView);
if (d->component)
return d->component->errors();
return QList<QDeclarativeError>();
@@ -410,6 +418,7 @@ QList<QDeclarativeError> QDeclarativeView::errors() const
void QDeclarativeView::setResizeMode(ResizeMode mode)
{
+ Q_D(QDeclarativeView);
if (d->resizeMode == mode)
return;
@@ -433,6 +442,7 @@ void QDeclarativeView::setResizeMode(ResizeMode mode)
void QDeclarativeViewPrivate::initResize()
{
+ Q_Q(QDeclarativeView);
if (declarativeItemRoot) {
if (resizeMode == QDeclarativeView::SizeViewToRootObject) {
QDeclarativeItemPrivate *p =
@@ -449,6 +459,7 @@ void QDeclarativeViewPrivate::initResize()
void QDeclarativeViewPrivate::updateSize()
{
+ Q_Q(QDeclarativeView);
if (!root)
return;
if (declarativeItemRoot) {
@@ -479,7 +490,7 @@ void QDeclarativeViewPrivate::updateSize()
q->updateGeometry();
}
-QSize QDeclarativeViewPrivate::rootObjectSize()
+QSize QDeclarativeViewPrivate::rootObjectSize() const
{
QSize rootObjectSize(0,0);
int widthCandidate = -1;
@@ -500,6 +511,7 @@ QSize QDeclarativeViewPrivate::rootObjectSize()
QDeclarativeView::ResizeMode QDeclarativeView::resizeMode() const
{
+ Q_D(const QDeclarativeView);
return d->resizeMode;
}
@@ -508,7 +520,7 @@ QDeclarativeView::ResizeMode QDeclarativeView::resizeMode() const
*/
void QDeclarativeView::continueExecute()
{
-
+ Q_D(QDeclarativeView);
disconnect(d->component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), this, SLOT(continueExecute()));
if (d->component->isError()) {
@@ -541,6 +553,7 @@ void QDeclarativeView::continueExecute()
*/
void QDeclarativeView::setRootObject(QObject *obj)
{
+ Q_D(QDeclarativeView);
if (d->root == obj)
return;
if (QDeclarativeItem *declarativeItem = qobject_cast<QDeclarativeItem *>(obj)) {
@@ -590,6 +603,7 @@ void QDeclarativeView::setRootObject(QObject *obj)
*/
void QDeclarativeView::timerEvent(QTimerEvent* e)
{
+ Q_D(QDeclarativeView);
if (!e || e->timerId() == d->resizetimer.timerId()) {
d->updateSize();
d->resizetimer.stop();
@@ -599,6 +613,7 @@ void QDeclarativeView::timerEvent(QTimerEvent* e)
/*! \reimp */
bool QDeclarativeView::eventFilter(QObject *watched, QEvent *e)
{
+ Q_D(QDeclarativeView);
if (watched == d->root && d->resizeMode == SizeViewToRootObject) {
if (d->graphicsWidgetRoot) {
if (e->type() == QEvent::GraphicsSceneResize) {
@@ -615,6 +630,7 @@ bool QDeclarativeView::eventFilter(QObject *watched, QEvent *e)
*/
QSize QDeclarativeView::sizeHint() const
{
+ Q_D(const QDeclarativeView);
QSize rootObjectSize = d->rootObjectSize();
if (rootObjectSize.isEmpty()) {
return size();
@@ -628,6 +644,7 @@ QSize QDeclarativeView::sizeHint() const
*/
QGraphicsObject *QDeclarativeView::rootObject() const
{
+ Q_D(const QDeclarativeView);
return d->root;
}
@@ -638,6 +655,7 @@ QGraphicsObject *QDeclarativeView::rootObject() const
*/
void QDeclarativeView::resizeEvent(QResizeEvent *e)
{
+ Q_D(QDeclarativeView);
if (d->resizeMode == SizeRootObjectToView) {
d->updateSize();
}
@@ -657,6 +675,7 @@ void QDeclarativeView::resizeEvent(QResizeEvent *e)
*/
void QDeclarativeView::paintEvent(QPaintEvent *event)
{
+ Q_D(QDeclarativeView);
int time = 0;
if (frameRateDebug() || QDeclarativeViewDebugServer::isDebuggingEnabled())
time = d->frameTimer.restart();
diff --git a/src/declarative/util/qdeclarativeview.h b/src/declarative/util/qdeclarativeview.h
index 3513c04..e9cff32 100644
--- a/src/declarative/util/qdeclarativeview.h
+++ b/src/declarative/util/qdeclarativeview.h
@@ -106,9 +106,8 @@ protected:
virtual bool eventFilter(QObject *watched, QEvent *e);
private:
- friend class QDeclarativeViewPrivate;
- QDeclarativeViewPrivate *d;
Q_DISABLE_COPY(QDeclarativeView)
+ Q_DECLARE_PRIVATE(QDeclarativeView)
};
QT_END_NAMESPACE
diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp
index ae3b5d7..f02ed16 100644
--- a/src/declarative/util/qdeclarativexmllistmodel.cpp
+++ b/src/declarative/util/qdeclarativexmllistmodel.cpp
@@ -472,40 +472,71 @@ void QDeclarativeXmlListModelPrivate::clear_role(QDeclarativeListProperty<QDecla
\since 4.7
\brief The XmlListModel element is used to specify a model using XPath expressions.
- XmlListModel is used to create a model from XML data that can be used as a data source
+ XmlListModel is used to create a model from XML data. XmlListModel can be used as a data source
for the view classes (such as ListView, PathView, GridView) and other classes that interact with model
- data (such as Repeater).
+ data (such as \l Repeater).
+
+ For example, if there is a XML document at http://www.mysite.com/feed.xml like this:
+
+ \code
+ <?xml version="1.0" encoding="utf-8"?>
+ <rss version="2.0">
+ ...
+ <channel>
+ <item>
+ <title>Item A</title>
+ <pubDate>Sat, 07 Sep 2010 10:00:01 GMT</pubDate>
+ </item>
+ <item>
+ <title>Item B</title>
+ <pubDate>Sat, 07 Sep 2010 15:35:01 GMT</pubDate>
+ </item>
+ </channel>
+ </rss>
+ \endcode
+
+ Then it could be used to create the following model:
- Here is an example of a model containing news from a Yahoo RSS feed:
\qml
XmlListModel {
- id: feedModel
- source: "http://rss.news.yahoo.com/rss/oceania"
+ source: "http://www.mysite.com/feed.xml"
query: "/rss/channel/item"
XmlRole { name: "title"; query: "title/string()" }
XmlRole { name: "pubDate"; query: "pubDate/string()" }
- XmlRole { name: "description"; query: "description/string()" }
}
\endqml
- You can also define certain roles as "keys" so that the model only adds data
- that contains new values for these keys when reload() is called.
+ The \l {XmlListModel::query}{query} value of "/rss/channel/item" specifies that the XmlListModel should generate
+ a model item for each \c <item> in the XML document. The XmlRole objects define the
+ 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>.
- For example, if the roles above were defined like this:
+
+ \section2 Using key XML roles
+
+ You can define certain roles as "keys" so that when reload() is called,
+ the model will only add and refresh data that contains new values for
+ these keys.
+
+ For example, if above role for "pubDate" was defined like this instead:
\qml
- XmlRole { name: "title"; query: "title/string()"; isKey: true }
XmlRole { name: "pubDate"; query: "pubDate/string()"; isKey: true }
\endqml
- Then when reload() is called, the model will only add new items with a
- "title" and "pubDate" value combination that is not already present in
- the model.
+ Then when reload() is called, the model will only add and reload
+ items with a "pubDate" value that is not already
+ present in the model.
- This is useful to provide incremental updates and avoid repainting an
- entire model in a view.
+ This is useful when displaying the contents of XML documents that
+ are incrementally updated (such as RSS feeds) to avoid repainting the
+ entire contents of a model in a view.
- \sa {QtDeclarative}
+ If multiple key roles are specified, the model only adds and reload items
+ with a combined value of all key roles that is not already present in
+ the model.
+
+ \sa {declarative/xmldata}{XML data example}
*/
QDeclarativeXmlListModel::QDeclarativeXmlListModel(QObject *parent)
@@ -626,8 +657,8 @@ void QDeclarativeXmlListModel::setXml(const QString &xml)
/*!
\qmlproperty string XmlListModel::query
- An absolute XPath query representing the base query for the model items. The query should start with
- '/' or '//'.
+ An absolute XPath query representing the base query for creating model items
+ from this model's XmlRole objects. The query should start with '/' or '//'.
*/
QString QDeclarativeXmlListModel::query() const
{
@@ -652,7 +683,20 @@ void QDeclarativeXmlListModel::setQuery(const QString &query)
/*!
\qmlproperty string XmlListModel::namespaceDeclarations
- A set of declarations for the namespaces used in the query.
+ The namespace declarations to be used in the XPath queries.
+
+ The namespaces should be declared as in XQuery. For example, if a requested document
+ at http://mysite.com/feed.xml uses the namespace "http://www.w3.org/2005/Atom",
+ this can be declared as the default namespace:
+
+ \qml
+ XmlListModel {
+ source: "http://mysite.com/feed.xml"
+ query: "/feed/entry"
+ namespaceDeclarations: "declare default element namespace 'http://www.w3.org/2005/Atom';"
+ XmlRole { name: "title"; query: "title/string()" }
+ }
+ \endqml
*/
QString QDeclarativeXmlListModel::namespaceDeclarations() const
{
@@ -735,7 +779,7 @@ void QDeclarativeXmlListModel::componentComplete()
Otherwise, items are only added if the model does not already
contain items with matching key role values.
- \sa XmlRole::isKey
+ \sa {Using key XML roles}, XmlRole::isKey
*/
void QDeclarativeXmlListModel::reload()
{