summaryrefslogtreecommitdiffstats
path: root/doc/src/declarative
diff options
context:
space:
mode:
Diffstat (limited to 'doc/src/declarative')
-rw-r--r--doc/src/declarative/advtutorial.qdoc2
-rw-r--r--doc/src/declarative/elements.qdoc264
-rw-r--r--doc/src/declarative/examples.qdoc20
-rw-r--r--doc/src/declarative/extending-tutorial.qdoc14
-rw-r--r--doc/src/declarative/focus.qdoc2
-rw-r--r--doc/src/declarative/globalobject.qdoc8
-rw-r--r--doc/src/declarative/modules.qdoc4
-rw-r--r--doc/src/declarative/network.qdoc4
-rw-r--r--doc/src/declarative/qdeclarativedebugging.qdoc8
-rw-r--r--doc/src/declarative/qdeclarativei18n.qdoc8
-rw-r--r--doc/src/declarative/qdeclarativemodels.qdoc349
-rw-r--r--doc/src/declarative/qml-intro.qdoc10
-rw-r--r--doc/src/declarative/qmlviewer.qdoc4
-rw-r--r--doc/src/declarative/tutorial.qdoc4
14 files changed, 343 insertions, 358 deletions
diff --git a/doc/src/declarative/advtutorial.qdoc b/doc/src/declarative/advtutorial.qdoc
index 9c72e95..2c3610c 100644
--- a/doc/src/declarative/advtutorial.qdoc
+++ b/doc/src/declarative/advtutorial.qdoc
@@ -164,7 +164,7 @@ The \c createBlock() function creates a block from the \c Block.qml file
and moves the new block to its position on the game canvas. This involves several steps:
\list
-\o \l {Qt::createComponent()}{Qt.createComponent()} is called to generate an element from \c Block.qml.
+\o \l {QML:Qt::createComponent()}{Qt.createComponent()} is called to generate an element from \c Block.qml.
If the component is ready, we can call \c createObject() to create an instance of the \c Block item.
\o If \c createObject() returned null (i.e. if there was an error while
loading the object), print the error information.
diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc
index 2c36d12..48eb09f 100644
--- a/doc/src/declarative/elements.qdoc
+++ b/doc/src/declarative/elements.qdoc
@@ -32,169 +32,107 @@
The following table lists the QML elements provided by the \l {QtDeclarative}{Qt Declarative} module.
-\table 80%
-\header
-\o \bold {States}
-\o \bold {Animation and Transitions}
-\o \bold {Working with Data}
-\o \bold {Utility}
-\row
-
-\o
-\list
-\o \l State
-\o \l PropertyChanges
-\o \l StateGroup
-\o \l StateChangeScript
-\o \l ParentChange (Item-specific)
-\o \l AnchorChanges (Item-specific)
-\endlist
-
-\o
-\list
-\o \l PropertyAnimation
-\o \l NumberAnimation
-\o \l ColorAnimation
-\o \l RotationAnimation
-\o \l SequentialAnimation
-\o \l ParallelAnimation
-\o \l PauseAnimation
-\o \l ParentAnimation
-\o \l AnchorAnimation
-\o \l SmoothedAnimation
-\o \l Vector3dAnimation
-\o \l PropertyAction
-\o \l ScriptAction
-\o \l Transition
-\o \l SmoothedFollow
-\o \l SpringFollow
-\o \l Behavior
-\endlist
-
-\o
-\list
-\o \l Binding
-\o \l ListModel
-\list
-\o \l ListElement
-\endlist
-\o \l VisualItemModel
-\o \l VisualDataModel
-\o \l Package
-\o \l XmlListModel
-\list
-\o \l XmlRole
-\endlist
-\endlist
-
-\o
-\list
-\o \l Connections
-\o \l Component
-\o \l Timer
-\o \l QtObject
-\o \l WorkerScript
-\endlist
-
-\header
-\o \bold {Basic Visual Items}
-\o \bold {Basic Interaction Items}
-\o \bold {Utility}
-\o \bold {Transforms}
-
-\row
-\o
-\list
-\o \l Item
-\o \l Rectangle
- \list
- \o \l Gradient
- \list
- \o \l GradientStop
- \endlist
- \endlist
-\o \l Image
-\o \l BorderImage
-\o \l AnimatedImage
-\o \l Text
-\o \l TextInput
- \list
- \o \l IntValidator
- \o \l DoubleValidator
- \o \l RegExpValidator
- \endlist
-\o \l TextEdit
-\endlist
-
-\o
-\list
-\o \l MouseArea
-\o \l FocusScope
-\o \l Flickable
-\o \l Flipable
-\o \l GestureArea (experimental)
-\endlist
-
-\o
-\list
-\o \l Loader
-\o \l Repeater
-\o \l SystemPalette
-\o \l FontLoader
-\o \l LayoutItem
-\endlist
-
-\o
-\list
-\o \l Scale
-\o \l Rotation
-\o \l Translate
-\endlist
-
-\header
-\o \bold {Views}
-\o \bold {Positioners}
-\o \bold {Effects}
-\o
-
-\row
-\o
-
-\target xmlViews
-\list
-\o \l ListView
-\o \l GridView
-\o \l PathView
- \list
- \o \l Path
- \list
- \o \l PathLine
- \o \l PathQuad
- \o \l PathCubic
- \o \l PathAttribute
- \o \l PathPercent
- \endlist
- \endlist
-\o \l WebView
-\endlist
-
-\o
-\list
-\o \l Column
-\o \l Row
-\o \l Grid
-\o \l Flow
-\endlist
-
-\o
-\list
-\o \l Particles (experimental)
- \list
- \o \l ParticleMotionLinear
- \o \l ParticleMotionGravity
- \o \l ParticleMotionWander
- \endlist
-\endlist
+\table
+\header \o {2,1} \bold {Basic Visual Items}
+\row \o \l {Item} \o Basic item element inherited by all visual items in QML
+\row \o \l {Rectangle} \o Basic visual rectangle element
+\row \o \l {Gradient} \o Defines a gradient between two or more colors
+\row \o \l {GradientStop} \o Defines a color used in a \l {Gradient}
+\row \o \l {Image} \o Allows the use of bitmaps to a scene
+\row \o \l {BorderImage} (Item-specific) \o Defines an image as a border
+\row \o \l {AnimatedImage} \o For playing animations stored as a series of frames
+\row \o \l {Text} \o Allows the use of formatted text in a scene
+\row \o \l {TextInput} \o Displays an editable line of text
+\row \o \l {IntValidator} \o Validator for integer values
+\row \o \l {DoubleValidator} \o Validator for non-integer values
+\row \o \l {RegExpValidator} \o Validator for string regular expressions
+\row \o \l {TextEdit} \o Displays multiple lines of editable formatted text
+
+\header \o {2,1} \bold {Basic Interaction Items}
+\row \o \l {MouseArea} \o Handles mouse interactions
+\row \o \l {FocusScope} \o For keyboard focus handling
+\row \o \l {Flickable} \o Provides a surface that can be "flicked"
+\row \o \l {Flipable} \o Provides a surface that produces flipping effects
+\row \o \l {GestureArea} (experimental) \o Enables simple gesture handling
+
+\header \o {2,1} \bold {States}
+\row \o \l {State} \o Defines sets of configurations of objects and properties
+\row \o \l {PropertyChanges} \o Describes property changes within a state
+\row \o \l {StateGroup} \o Contains a set of states and state transitions
+\row \o \l {StateChangeScript} \o Allows script binding in a state
+\row \o \l {ParentChange} (Item-specific) \o Re-parent an Item in a state change
+\row \o \l {AnchorChanges} \o Change the anchors of an item in a state
+
+\header \o {2,1} \bold {Animation and Transitions}
+\row \o \l {Behavior} \o Specifies a default animation for property changes
+\row \o \l {SequentialAnimation} \o Runs animations sequentially
+\row \o \l {ParallelAnimation} \o Runs animations in parallel
+\row \o \l {PropertyAnimation} \o Animates property changes
+\row \o \l {NumberAnimation} \o Animates properties of type qreal
+\row \o \l {Vector3dAnimation} \o Animates properties of type QVector3d
+\row \o \l {ColorAnimation} \o Animates color changes
+\row \o \l {RotationAnimation} \o Animates rotations
+\row \o \l {ParentAnimation} \o Animates parent changes
+\row \o \l {AnchorAnimation} \o Animates anchor changes
+\row \o \l {PauseAnimation} \o Pauses an animation
+\row \o \l {SmoothedAnimation} \o Allows a property to smoothly track a value
+\row \o \l {PropertyAction} \o Sets immediate property changes during animation
+\row \o \l {ScriptAction} \o Runs scripts during an animation
+\row \o \l {Transition} \o Animates transitions during state changes
+\row \o \l {SpringFollow} \o Allows a property to follow value changes
+\row \o \l {SmoothedFollow} \o Allows animation to smoothly follow value changes
+
+\header \o {2,1} \bold {Working with Data}
+\row \o \l {Binding} \o Binds any value to any property
+\row \o \l {ListModel} \o Defines a list of data
+\row \o \l {ListElement} \o Defines a data item in a \l {ListModel}
+\row \o \l {VisualItemModel} \o Contains items that already defines its own visual delegate
+\row \o \l {VisualDataModel} \o Encapsulates a model and a delegate
+\row \o \l {Package} \o Collection that enables sharing of items within different views
+\row \o \l {XmlListModel} \o Specifies a model using XPath expressions
+\row \o \l {XmlRole} \o Specifies a role for an \l {XmlListModel}
+
+\header \o {2,1} \bold {Views}
+\row \o \l {ListView} \o Provides a list visualization of a model
+\row \o \l {GridView} \o Provides a grid visualization of a model
+\row \o \l {PathView} \o Visualizes a model's contents along a path
+\row \o \l {Path} \o Defines a path used by \l {PathView}
+\row \o \l {PathLine} \o Defines a line in \l {Path}
+\row \o \l {PathQuad} \o Defines a quadratic Bezier curve in a \l {Path}
+\row \o \l {PathCubic} \o Defines a cubic Bezier curve in a \l {Path}
+\row \o \l {PathAttribute} \o Allows the setting of attributes along a \l {Path}
+\row \o \l {PathPercent} \o Modifies the item distribution along a \l {Path}
+\row \o \l {WebView} \o Allows the addition of web content to a canvas
+
+\header \o {2,1} \bold {Positioners}
+\row \o \l {Column} \o Arranges its children vertically
+\row \o \l {Row} \o Arranges its children horizontally
+\row \o \l {Grid} \o Positions its children in a grid
+\row \o \l {Flow} \o Positions its children with wrapping support
+
+\header \o {2,1} \bold {Utility}
+\row \o \l {Connections} \o Explicitly connects signals and signal handlers
+\row \o \l {Component} \o Encapsulate QML items as a component
+\row \o \l {Timer} \o Provides timed triggers
+\row \o \l {QtObject} \o Basic element containing only the objectName property
+\row \o \l {WorkerScript} \o Enables the use of threads in QML
+\row \o \l {Loader} \o Controls the loading of items or components
+\row \o \l {Repeater} \o Uses a model to create multiples of components
+\row \o \l {SystemPalette} \o Provides access to the Qt palettes
+\row \o \l {FontLoader} \o Loads fonts by name or URL
+\row \o \l {LayoutItem} \o Allows declarative UI elements inside Qt's Graphics View layouts
+
+\header \o {2,1} \bold {Transforms}
+\row \o \l {Scale} \o Assigns item scaling behaviors
+\row \o \l {Rotation} \o Assigns item rotation behaviors
+\row \o \l {Translate} \o Assigns item translation behaviors
+
+\header \o {2,1} \bold {Effects}
+\row \o \l {Particles} (experimental) \o Generates and animates particles
+\row \o \l {ParticleMotionLinear} \o Adds linear motion behavior to \l {Particles}
+\row \o \l {ParticleMotionGravity} \o Adds gravitational motion to \l {Particles}
+\row \o \l {ParticleMotionWander} \o Adds varied motions to \l {Particles}
\endtable
+
*/
diff --git a/doc/src/declarative/examples.qdoc b/doc/src/declarative/examples.qdoc
index 7b02d33..8a24228 100644
--- a/doc/src/declarative/examples.qdoc
+++ b/doc/src/declarative/examples.qdoc
@@ -36,11 +36,18 @@ Qt includes a set of examples and demos that show how to use various aspects
of QML. The examples are small demonstrations of particular QML components,
while the demos contain more complete and functional applications.
-To run the examples and demos, you can use Qt Creator or the included \l {Qt Declarative UI Runtime}{qmlviewer}
-command-line application. For example, from your build directory, run:
+To run the examples and demos, open them in Qt Creator or use the included
+\l {QML Viewer} tool. The \l {QML Viewer} can be run from the command line:
\code
- bin/qmlviewer $QTDIR/demos/declarative/samegame/samegame.qml
+ qmlviewer $QTDIR/demos/declarative/samegame/samegame.qml
+\endcode
+
+On Mac OS X, you can run the included "QMLViewer" application from the
+Finder, or use the command line:
+
+\code
+ QMLViewer.app/Contents/MacOS/QMLViewer $QTDIR/demos/declarative/samegame/samegame.qml
\endcode
@@ -168,11 +175,14 @@ The examples can be found in Qt's \c examples/declarative directory.
\list
\o \l{declarative/modelviews/gridview}{GridView}
\o \l{declarative/modelviews/listview}{ListView}
-\o \l{declarative/modelviews/objectlistmodel}{Object ListModel}
\o \l{declarative/modelviews/package}{Package}
\o \l{declarative/modelviews/parallax}{Parallax}
-\o \l{declarative/modelviews/stringlistmodel}{String ListModel}
\o \l{declarative/modelviews/visualitemmodel}{VisualItemModel}
+
+\o \l{declarative/modelviews/stringlistmodel}{String ListModel}
+\o \l{declarative/modelviews/objectlistmodel}{Object ListModel}
+\o \l{declarative/modelviews/abstractitemmodel}{AbstractItemModel}
+
\o \l{declarative/modelviews/webview}{WebView}
\endlist
diff --git a/doc/src/declarative/extending-tutorial.qdoc b/doc/src/declarative/extending-tutorial.qdoc
index 0cb3a7d..2cf00b9 100644
--- a/doc/src/declarative/extending-tutorial.qdoc
+++ b/doc/src/declarative/extending-tutorial.qdoc
@@ -116,9 +116,9 @@ Now we can build and run the application. Try it yourself with the code in Qt's
\example declarative/tutorials/extending/chapter1-basics
At the moment, the \c app.qml is run from within a C++ application.
-This may seem odd if you're used to running QML files with the standard \c qml tool.
+This may seem odd if you're used to running QML files with the \l {QML Viewer}.
Later on, we'll show how to create a plugin so that you can run \c app.qml using the
-\c qml tool instead.
+\l {QML Viewer} instead.
*/
@@ -301,8 +301,8 @@ Try it out with the code in Qt's \c examples/tutorials/extending/chapter4-custom
Currently the \c Musician and \c Instrument types are used by \c app.qml,
which is displayed using a QDeclarativeView in a C++ application. An alternative
way to use our QML extension is to create a plugin library to make it available
-to the QML engine. This means we could load \c app.qml using the standard \c qml tool
-(or some other QML runtime application) instead of writing a \c main.cpp file and
+to the QML engine. This means we could load \c app.qml using the \l {QML Viewer}
+(or some other QML \l{Qt Declarative UI Runtime}{runtime} application) instead of writing a \c main.cpp file and
loading our own C++ application.
To create a plugin library, we need:
@@ -337,12 +337,14 @@ of the example project) can be found in the "lib" subdirectory:
\quotefile declarative/tutorials/extending/chapter5-plugins/qmldir
Now we have a plugin, and instead of having a main.cpp and an executable, we can build
-the project and then run the QML file directly using the \c qml tool:
+the project and then load the QML file in the \l {QML Viewer}:
\code
- qml app.qml
+ qmlviewer app.qml
\endcode
+(On Mac OS X, you can launch the "QMLViewer" application instead.)
+
Notice the "import Music 1.0" statement has disappeared from \c app.qml. This is
because the \c qmldir file is in the same directory as \c app.qml: this is equivalent to
having Musician.qml and Instrument.qml files inside the project directory, which could both
diff --git a/doc/src/declarative/focus.qdoc b/doc/src/declarative/focus.qdoc
index cc546c0..0dd5eb3 100644
--- a/doc/src/declarative/focus.qdoc
+++ b/doc/src/declarative/focus.qdoc
@@ -87,7 +87,7 @@ Text {
An \l Item requests focus by setting the \c {Item::focus} property to true.
For very simple cases simply setting the \c {Item::focus} property is sometimes
-sufficient. If we run the following example with the \l {Qt Declarative UI Runtime}{qml} tool, we see that
+sufficient. If we run the following example with the \l {QML Viewer}, we see that
the \c {keyHandler} element has \e {active focus} and pressing the 'A', 'B'
or 'C' keys modifies the text appropriately.
diff --git a/doc/src/declarative/globalobject.qdoc b/doc/src/declarative/globalobject.qdoc
index 40fc3eb..a9aee2f 100644
--- a/doc/src/declarative/globalobject.qdoc
+++ b/doc/src/declarative/globalobject.qdoc
@@ -35,7 +35,7 @@ Contains all the properties of the JavaScript global object, plus:
\section1 Qt Object
-The \l{Qt}{Qt object} provides useful enums and functions from Qt, for use in all QML
+The \l{QmlGlobalQtObject}{Qt object} provides useful enums and functions from Qt, for use in all QML
files.
\section1 XMLHttpRequest
@@ -114,7 +114,8 @@ browser. The following objects and properties are supported by the QML implemen
\endtable
-\sa {declarative/xml/xmlhttprequest}{XMLHttpRequest example}
+The \l{declarative/xml/xmlhttprequest}{XMLHttpRequest example} demonstrates how to
+use the XMLHttpRequest object to make a request and read the response headers.
\section1 Offline Storage API
@@ -134,7 +135,8 @@ The API can be used from JavaScript functions in your QML:
The API conforms to the Synchronous API of the HTML5 Web Database API,
\link http://www.w3.org/TR/2009/WD-webdatabase-20091029/ W3C Working Draft 29 October 2009\endlink.
-\sa {declarative/sqllocalstorage}{SQL Local Storage example}
+The \l{declarative/sqllocalstorage}{SQL Local Storage example} demonstrates the basics of
+using the Offline Storage API.
\section3 db = openDatabaseSync(identifier, version, description, estimated_size, callback(db))
diff --git a/doc/src/declarative/modules.qdoc b/doc/src/declarative/modules.qdoc
index 02a2f5f..a77c64e 100644
--- a/doc/src/declarative/modules.qdoc
+++ b/doc/src/declarative/modules.qdoc
@@ -72,7 +72,7 @@ The second exception is explained in more detail in the section below on Namespa
\section2 The Import Path
Installed modules are searched for on the import path.
-The \c -I option to the \l {Qt Declarative UI Runtime}{qml} runtime adds paths to the import path.
+The \c -I option to the \l {QML Viewer} adds paths to the import path.
From C++, the path is available via \l QDeclarativeEngine::importPathList() and can be prepended to
using \l QDeclarativeEngine::addImportPath().
@@ -122,7 +122,7 @@ to the module.
of the plugin binary, which is platform dependent; e.g. the library MyAppTypes would produce
a libMyAppTypes.so on Linux and MyAppTypes.dll on Windows.
By default the engine searches for the plugin library in the directory containing the \c qmldir
-file. The \c -P option to the \l {Qt Declarative UI Runtime}{qml} runtime adds paths to the
+file. The \c -P option to the \l {QML Viewer} adds paths to the
plugin search path.
From C++, the path is available via \l QDeclarativeEngine::pluginPathList() and can be prepended to
using \l QDeclarativeEngine::addPluginPath().
diff --git a/doc/src/declarative/network.qdoc b/doc/src/declarative/network.qdoc
index b0d19e2..60359de 100644
--- a/doc/src/declarative/network.qdoc
+++ b/doc/src/declarative/network.qdoc
@@ -54,7 +54,7 @@ Network transparency is supported throughout QML, for example:
\o WebViews - the \c url property of WebView (obviously!)
\endlist
-Even QML types themselves can be on the network - if the \l {Qt Declarative UI Runtime}{qml} tool is used to load
+Even QML types themselves can be on the network - if the \l {QML Viewer} is used to load
\tt http://example.com/mystuff/Hello.qml and that content refers to a type "World", the engine
will load \tt http://example.com/mystuff/qmldir and resolve the type just as it would for a local file.
For example if the qmldir file contains the line "World World.qml", it will load
@@ -119,7 +119,7 @@ All network access from QML is managed by a QNetworkAccessManager set on the QDe
By default, this is an unmodified Qt QNetworkAccessManager. You may set a different manager by
providing a QDeclarativeNetworkAccessManagerFactory and setting it via
QDeclarativeEngine::setNetworkAccessManagerFactory().
-For example, the \l {Qt Declarative UI Runtime}{qml} tool sets a QDeclarativeNetworkAccessManagerFactory which
+For example, the \l {QML Viewer} sets a QDeclarativeNetworkAccessManagerFactory which
creates QNetworkAccessManager that trusts HTTP Expiry headers to avoid network cache checks,
allows HTTP Pipelining, adds a persistent HTTP CookieJar, a simple disk cache, and supports proxy settings.
diff --git a/doc/src/declarative/qdeclarativedebugging.qdoc b/doc/src/declarative/qdeclarativedebugging.qdoc
index da6e407..ea21852 100644
--- a/doc/src/declarative/qdeclarativedebugging.qdoc
+++ b/doc/src/declarative/qdeclarativedebugging.qdoc
@@ -47,7 +47,7 @@ Rectangle {
When a transition doesn't look quite right, it can be helpful to view it in slow
motion to see what is happening more clearly. This functionality is supported
-in the \l {Qt Declarative UI Runtime}{qmlviewer} tool: to enable this,
+in the \l {QML Viewer} tool: to enable this,
click on the "Debugging" menu, then "Slow Down Animations".
@@ -64,7 +64,7 @@ import Qt 4.7
Rectangle { width: 100; height: 100 }
\endqml
-If you set \c {QML_IMPORT_TRACE=1} before running the \l {Qt Declarative UI Runtime}{qmlviewer}
+If you set \c {QML_IMPORT_TRACE=1} before running the \l {QML Viewer}
(or your QML C++ application), you will see output similar to this:
\code
@@ -85,11 +85,11 @@ show QML debugging information and options for your application, including
object inspection, property monitoring and application frame-rate analysis.
Creator can be used to debug both local and remote QML applications. To
-enable remote debugging, start the \l {Qt Declarative UI Runtime}{qml} tool
+enable remote debugging, start the \l {QML Viewer}
on the remote device with a debugging port defined, like this:
\code
- QML_DEBUG_SERVER_PORT=3768 qml myqmlfile.qml
+ QML_DEBUG_SERVER_PORT=3768 qmlviewer myqmlfile.qml
\endcode
In Creator, open the project settings pane and set the server and port
diff --git a/doc/src/declarative/qdeclarativei18n.qdoc b/doc/src/declarative/qdeclarativei18n.qdoc
index 40f7919..b6e6c6e 100644
--- a/doc/src/declarative/qdeclarativei18n.qdoc
+++ b/doc/src/declarative/qdeclarativei18n.qdoc
@@ -49,7 +49,7 @@ capabilities are described more fully in:
\o \l {Qt Linguist Manual}
\endlist
-You can test a translation with the \l {Qt Declarative UI Runtime}{qml} tool using the -translation option.
+You can test a translation with the \l {QML Viewer} using the -translation option.
\section1 Example
@@ -61,8 +61,8 @@ hello.qml:
import Qt 4.7
Rectangle {
- width: 200; height: 200
- Text { text: qsTr("Hello"); anchors.centerIn: parent }
+ width: 200; height: 200
+ Text { text: qsTr("Hello"); anchors.centerIn: parent }
}
\endqml
@@ -76,7 +76,7 @@ a translation and create the release file \c hello.qm.
Finally, we can test the translation:
\code
-qml -translation hello.qm hello.qml
+qmlviewer -translation hello.qm hello.qml
\endcode
diff --git a/doc/src/declarative/qdeclarativemodels.qdoc b/doc/src/declarative/qdeclarativemodels.qdoc
index 7671eb3..b44e6f2 100644
--- a/doc/src/declarative/qdeclarativemodels.qdoc
+++ b/doc/src/declarative/qdeclarativemodels.qdoc
@@ -30,63 +30,67 @@
\target qmlmodels
\title Data Models
-Some QML Items use Data Models to provide the data to be displayed.
+QML items such as ListView, GridView and \l Repeater require Data Models
+that provide the data to be displayed.
These items typically require a \e delegate component that
creates an instance for each item in the model. Models may be static, or
have items modified, inserted, removed or moved dynamically.
Data is provided to the delegate via named data roles which the
-delegate may bind to. The roles are exposed as properties of the
-\e model context property, though this property is set as a default property
-of the delegate so, unless there is a naming clash with a
-property in the delegate, the roles are usually accessed unqualified. The
-example below would have a clash between the \e color role of the model and
-the \e color property of the Rectangle. The clash is avoided by referencing
-the \e color property of the model by its full name: \e model.color.
+delegate may bind to. Here is a ListModel with two roles, \e type and \e age,
+and a ListView with a delegate that binds to these roles to display their
+values:
-\code
-ListModel {
- id: myModel
- ListElement { color: "red" }
- ListElement { color: "green" }
-}
+\qml
+import Qt 4.7
+
+Item {
+ width: 200; height: 250
+
+ ListModel {
+ id: myModel
+ ListElement { type: "Dog"; age: 8 }
+ ListElement { type: "Cat"; age: 5 }
+ }
-Component {
- id: myDelegate
- Rectangle {
- width: 20; height: 20
- color: model.color
+ Component {
+ id: myDelegate
+ Text { text: type + ", " + age }
+ }
+
+ ListView {
+ anchors.fill: parent
+ model: myModel
+ delegate: myDelegate
}
}
-\endcode
+\endqml
-A special \e index role containing the index of the item in the model
-is also available.
+If there is a naming clash between the model's properties and the delegate's
+properties, the roles can be accessed with the qualified \e model name instead.
+For example, if a \l Text element had \e type or \e age properties, the text in the
+above example would display those property values instead of the \e type and \e age values
+from the model item. In this case, the properties could have been referenced as
+\c model.type and \c model.age instead to ensure the delegate displays the
+property values from the model item.
-\e Note: the index role will be set to -1 if the item is removed from
+A special \e index role containing the index of the item in the model
+is also available to the delegate. Note this index is set to -1 if the item is removed from
the model. If you bind to the index role, be sure that the logic
accounts for the possibility of index being -1, i.e. that the item
-is no longer valid. Usually the item will shortly be destroyed, but
-it is possible to delay delegate destruction in some views via a delayRemove
-attached property.
+is no longer valid. (Usually the item will shortly be destroyed, but
+it is possible to delay delegate destruction in some views via a \c delayRemove
+attached property.)
-Models that do not have named roles will have the data provided via
-the \e modelData role. The \e modelData role is also provided for
-Models that have only one role. In this case the \e modelData role
+Models that do not have named roles (such as the QStringList model shown below)
+will have the data provided via the \e modelData role. The \e modelData role is also provided for
+models that have only one role. In this case the \e modelData role
contains the same data as the named role.
-There are a number of QML elements that operate using data models:
+QML provides several types of data models among the built-in set of
+QML elements. In addition, models can be created with C++ and then
+made available to QML components.
-\list
-\o ListView
-\o GridView
-\o PathView
-\o \l Repeater
-\endlist
-
-QML supports several types of data model, which may be provided by QML
-or C++ (via QDeclarativeContext::setContextProperty() or as plugin types,
-for example).
\section1 QML Data Models
@@ -98,6 +102,7 @@ available roles are specified by the \l ListElement properties.
\code
ListModel {
id: fruitModel
+
ListElement {
name: "Apple"
cost: 2.45
@@ -117,30 +122,26 @@ The above model has two roles, \e name and \e cost. These can be bound
to by a ListView delegate, for example:
\code
-Component {
- id: fruitDelegate
- Row {
+ListView {
+ width: 200; height: 250
+ model: fruitModel
+ delegate: Row {
Text { text: "Fruit: " + name }
Text { text: "Cost: $" + cost }
}
}
-ListView {
- model: fruitModel
- delegate: fruitDelegate
-}
\endcode
-It is also possible to manipulate the ListModel directly via JavaScript.
-In this case, the first item inserted will determine the roles available
-to any views using the model. For example, if an empty ListModel is
-created and populated via JavaScript the roles provided by the first
+ListModel provides methods to manipulate the ListModel directly via JavaScript.
+In this case, the first item inserted determines the roles available
+to any views that are using the model. For example, if an empty ListModel is
+created and populated via JavaScript, the roles provided by the first
insertion are the only roles that will be shown in the view:
\code
Item {
- ListModel {
- id: fruitModel
- }
+ ListModel { id: fruitModel }
+
MouseArea {
anchors.fill: parent
onClicked: fruitModel.append({"cost": 5.95, "name":"Pizza"})
@@ -148,9 +149,9 @@ Item {
}
\endcode
-When the MouseArea is clicked fruitModel will have two roles, "cost" and "name".
+When the MouseArea is clicked, \c fruitModel will have two roles, \e cost and \e name.
Even if subsequent roles are added, only the first two will be handled by views
-using the model.
+using the model. To reset the roles available in the model, call ListModel::clear().
\section2 XmlListModel
@@ -170,11 +171,17 @@ XmlListModel {
}
\endcode
+The \l{demos/declarative/rssnews}{RSS News demo} shows how XmlListModel can
+be used to display an RSS feed.
+
\section2 VisualItemModel
-VisualItemModel allows QML items to be provided as a model. This model contains
-both the data and delegate (its child items). This model does not provide any roles.
+VisualItemModel allows QML items to be provided as a model.
+
+This model contains both the data and delegate; the child items of a
+VisualItemModel provide the contents of the delegate. The model
+does not provide any roles.
\code
VisualItemModel {
@@ -197,15 +204,74 @@ will be positioned by the view.
\section1 C++ Data Models
-Models defined in C++ can be made available to QML either from a C++ application or from a
-\l{QDeclarativeExtensionPlugin}{QML C++ plugin}.
+Models can be defined in C++ and then made available to QML. This is useful
+for exposing existing C++ data models or otherwise complex datasets to QML.
+
+A C++ model class can be defined as a QStringList, a QList<QObject*> or a
+QAbstractItemModel.
+
+\section2 QStringList
+
+A model may be a simple QStringList, which provides the contents of the list via the \e modelData role.
+
+Here is a ListView with a delegate that references its model item's
+value using the \c modelData role:
+
+\snippet examples/declarative/modelviews/stringlistmodel/view.qml 0
+
+A Qt application can load this QML document and set the value of \c myModel
+to a QStringList:
+
+\snippet examples/declarative/modelviews/stringlistmodel/main.cpp 0
+
+The complete example is available in Qt's \l {declarative/modelviews/stringlistmodel}{examples/declarative/modelviews/stringlistmodel} directory.
+
+\note There is no way for the view to know that the contents of a QStringList
+have changed. If the QStringList changes, it will be necessary to reset
+the model by calling QDeclarativeContext::setContextProperty() again.
+
+
+\section2 QList<QObject*>
+
+A list of QObject* values can also be used as a model. A QList<QObject*> provides
+the properties of the objects in the list as roles.
+
+The following application creates a \c DataObject class that with
+Q_PROPERTY values that will be accessible as named roles when a
+QList<DataObject*> is exposed to QML:
+
+\snippet examples/declarative/modelviews/objectlistmodel/dataobject.h 0
+\dots 4
+\snippet examples/declarative/modelviews/objectlistmodel/dataobject.h 1
+\codeline
+\snippet examples/declarative/modelviews/objectlistmodel/main.cpp 0
+\dots
+
+The QObject* is available as the \c modelData property. As a convenience,
+the properties of the object are also made available directly in the
+delegate's context. Here, \c view.qml references the \c DataModel properties in
+the ListView delegate:
+
+\snippet examples/declarative/modelviews/objectlistmodel/view.qml 0
+
+Note the use of the fully qualified access to the \c color property.
+The properties of the object are not replicated in the \c model
+object, since they are easily available via the \c modelData
+object.
+
+The complete example is available in Qt's \l {declarative/modelviews/objectlistmodel}{examples/declarative/modelviews/objectlistmodel} directory.
+
+Note: There is no way for the view to know that the contents of a QList
+have changed. If the QList changes, it will be necessary to reset
+the model by calling QDeclarativeContext::setContextProperty() again.
+
\section2 QAbstractItemModel
A model can be defined by subclassing QAbstractItemModel.
-QAbstractItemModel provides the roles set via the QAbstractItemModel::setRoleNames() method.
-The default role names set by Qt are:
+The roles of a QAbstractItemModel subclass can be exposed to QML by calling
+QAbstractItemModel::setRoleNames(). The default role names set by Qt are:
\table
\header
@@ -219,22 +285,34 @@ The default role names set by Qt are:
\o decoration
\endtable
-The model could be made available to QML either directly:
+Here is an application with a QAbstractListModel subclass named \c AnimalModel
+that has \e type and \e size roles. It calls QAbstractItemModel::setRoleNames() to set the
+role names for accessing the properties via QML:
-\code
-QDeclarativeContext *ctxt = view.rootContext();
-MyModel *model = new MyModel; // subclass of QAbstractItemModel
-ctxt->setContextProperty("myModel", model);
-\endcode
+\snippet examples/declarative/modelviews/abstractitemmodel/model.h 0
+\dots
+\snippet examples/declarative/modelviews/abstractitemmodel/model.h 1
+\dots
+\snippet examples/declarative/modelviews/abstractitemmodel/model.h 2
+\codeline
+\snippet examples/declarative/modelviews/abstractitemmodel/model.cpp 0
+\codeline
+\snippet examples/declarative/modelviews/abstractitemmodel/main.cpp 0
+\dots
+
+This model is displayed by a ListView delegate that accesses the \e type and \e size
+roles:
+
+\snippet examples/declarative/modelviews/abstractitemmodel/view.qml 0
-or by registering the subclass as a new QML type in
-a \l{QDeclarativeExtensionPlugin}{QML C++ plugin}.
+The complete example is available in Qt's \l {declarative/modelviews/abstractitemmodel}{examples/declarative/modelviews/abstractitemmodel} directory.
-QAbstractItemModel presents a heirachy of tables, but views currently provided by QML
+QAbstractItemModel presents a hierarchy of tables, but the views currently provided by QML
can only display list data.
-In order to display child lists of a heirachical model
+In order to display child lists of a hierarchical model
the VisualDataModel element provides several properties and functions for use
with models of type QAbstractItemModel:
+
\list
\o \e hasModelChildren role property to determine whether a node has child nodes.
\o \l VisualDataModel::rootIndex allows the root node to be specifed
@@ -243,104 +321,51 @@ with models of type QAbstractItemModel:
\endlist
-\section2 QStringList
+\section2 Exposing C++ data models to QML
-A model may be a simple QStringList, which provides the contents of the list via the \e modelData role:
+The above examples use QDeclarativeContext::setContextProperty() to set
+model values directly in QML components. An alternative to this is to
+register the C++ model class as a QML type from a QML C++ plugin using
+QDeclarativeExtensionPlugin. This would allow the model classes to be
+created directly as elements within QML:
\table
-\row
-\o
-\code
-// main.cpp
-QStringList dataList;
-dataList.append("Fred");
-dataList.append("Ginger");
-dataList.append("Skipper");
-
-QDeclarativeContext *ctxt = view.rootContext();
-ctxt->setContextProperty("myModel", QVariant::fromValue(dataList));
-\endcode
+\row
\o
\code
-// main.qml
-ListView {
- width: 100
- height: 100
- anchors.fill: parent
- model: myModel
- delegate: Component {
- Rectangle {
- height: 25
- Text { text: modelData }
- }
- }
-}
-\endcode
-\endtable
-
-The complete example is available in \l {declarative/modelviews/stringlistmodel}.
-
-\note There is no way for the view to know that the contents of a QStringList
-have changed. If the QStringList is changed, it will be necessary to reset
-the model by calling QDeclarativeContext::setContextProperty() again.
-
-
-\section2 QList<QObject*>
-
-QList<QObject*> provides the properties of the objects in the list as roles.
-
-\code
-class DataObject : public QObject
+class MyModelPlugin : public QDeclarativeExtensionPlugin
{
- Q_OBJECT
-
- Q_PROPERTY(QString name READ name WRITE setName)
- Q_PROPERTY(QString color READ color WRITE setColor)
-...
-};
-
-QList<QObject*> dataList;
-dataList.append(new DataObject("Item 1", "red"));
-dataList.append(new DataObject("Item 2", "green"));
-dataList.append(new DataObject("Item 3", "blue"));
-dataList.append(new DataObject("Item 4", "yellow"));
+public:
+ void registerTypes(const char *uri)
+ {
+ qmlRegisterType<MyModel>(uri, 1, 0,
+ "MyModel");
+ }
+}
-QDeclarativeContext *ctxt = view.rootContext();
-ctxt->setContextProperty("myModel", QVariant::fromValue(dataList));
+Q_EXPORT_PLUGIN2(mymodelplugin, MyModelPlugin);
\endcode
-The QObject* is available as the \c modelData property. As a convenience,
-the properties of the object are also made available directly in the
-delegate's context:
+\o
+\qml
+MyModel {
+ id: myModel
+ ListElement { someProperty: "some value" }
+}
-\code
ListView {
- width: 100
- height: 100
- anchors.fill: parent
- model: myModel
- delegate: Component {
- Rectangle {
- height: 25
- width: 100
- color: model.modelData.color
- Text { text: name }
- }
- }
+ width: 200; height: 250
+ model: myModel
+ delegate: Text { text: someProperty }
}
-\endcode
+\endqml
-The complete example is available in \l {declarative/modelviews/objectlistmodel}.
+\endtable
-Note the use of the fully qualified access to the \c color property.
-The properties of the object are not replicated in the \c model
-object, since they are easily available via the modelData
-object.
+See \l {Tutorial: Writing QML extensions with C++} for details on writing QML C++
+plugins.
-Note: There is no way for the view to know that the contents of a QList
-have changed. If the QList is changed, it will be necessary to reset
-the model by calling QDeclarativeContext::setContextProperty() again.
\section1 Other Data Models
@@ -348,14 +373,13 @@ the model by calling QDeclarativeContext::setContextProperty() again.
\section2 An Integer
-An Integer specifies a model containing the integer number of elements.
-There are no data roles.
+An integer can be used to specify a model that contains a certain number
+of elements. In this case, the model does not have any data roles.
The following example creates a ListView with five elements:
\code
Item {
- width: 200
- height: 250
+ width: 200; height: 250
Component {
id: itemDelegate
@@ -374,7 +398,7 @@ Item {
\section2 An Object Instance
-An Object Instance specifies a model with a single Object element. The
+An object instance can be used to specify a model with a single object element. The
properties of the object are provided as roles.
The example below creates a list with one item, showing the color of the
@@ -383,6 +407,8 @@ to avoid clashing with \e color property of the Text element in the delegate.
\code
Rectangle {
+ width: 200; height: 250
+
Text {
id: myText
text: "Hello"
@@ -391,10 +417,9 @@ Rectangle {
Component {
id: myDelegate
- Text {
- text: model.color
- }
+ Text { text: model.color }
}
+
ListView {
anchors.fill: parent
anchors.topMargin: 30
diff --git a/doc/src/declarative/qml-intro.qdoc b/doc/src/declarative/qml-intro.qdoc
index ac79496..21ce2dd 100644
--- a/doc/src/declarative/qml-intro.qdoc
+++ b/doc/src/declarative/qml-intro.qdoc
@@ -105,9 +105,17 @@ This is a valid QML script. To run it, copy it and save it to a file, say
myexample.qml, and on the command line run the command
\code
- qml myexample.qml
+ qmlviewer myexample.qml
\endcode
+On Mac OS X, open the "QMLViewer" application instead and open the
+\c myexample.qml file, or run it from the command line:
+
+ \code
+ QMLViewer.app/Contents/MacOS/QMLViewer myexample.qml
+ \endcode
+
+
It will create a very boring rectangle in its own window.
diff --git a/doc/src/declarative/qmlviewer.qdoc b/doc/src/declarative/qmlviewer.qdoc
index efff9cc..5efc0ce 100644
--- a/doc/src/declarative/qmlviewer.qdoc
+++ b/doc/src/declarative/qmlviewer.qdoc
@@ -42,7 +42,7 @@ deployment of QML applications. In those cases, the QML runtime should be invoke
from a Qt application instead; see \l {Qt Declarative UI Runtime} for more
information.
-The viewer is located at QTDIR/bin/qmlviewer. To load a \c .qml file
+The viewer is located at \c QTDIR/bin/qmlviewer. To load a \c .qml file
with the viewer, run the viewer and select the file to be opened, or provide the
file path on the command line:
@@ -50,7 +50,7 @@ file path on the command line:
qmlviewer myqmlfile.qml
\endcode
-On Mac OS X, the QML Viewer application is named \c QMLViewer.app instead. You
+On Mac OS X, the QML Viewer application is named "QMLViewer" instead. You
can launch the viewer by opening the QMLViewer application from the Finder, or
from the command line:
diff --git a/doc/src/declarative/tutorial.qdoc b/doc/src/declarative/tutorial.qdoc
index c884486..7a97eb1 100644
--- a/doc/src/declarative/tutorial.qdoc
+++ b/doc/src/declarative/tutorial.qdoc
@@ -101,11 +101,11 @@ The \c font.pointSize and \c font.bold properties are related to fonts and use t
\section2 Viewing the example
-To view what you have created, run the \l{Qt Declarative UI Runtime}{qml} tool (located in the \c bin directory) with your filename as the first argument.
+To view what you have created, run the \l{QML Viewer} tool (located in the \c bin directory) with your filename as the first argument.
For example, to run the provided completed Tutorial 1 example from the install location, you would type:
\code
-bin/qml $QTDIR/examples/declarative/tutorials/helloworld/tutorial1.qml
+bin/qmlviewer $QTDIR/examples/declarative/tutorials/helloworld/tutorial1.qml
\endcode
*/