diff options
author | Peter Yard <peter.yard@nokia.com> | 2010-04-27 00:39:42 (GMT) |
---|---|---|
committer | Peter Yard <peter.yard@nokia.com> | 2010-04-27 00:39:42 (GMT) |
commit | 88b2bf18c558d0e2f8a9268802f277212f17e61e (patch) | |
tree | d41ca52003037fba9b45605aa6d2ed86f73b940a /doc/src/declarative | |
parent | 4f3a7b5992b5aed67cced46d5d8c8c2f052dfb66 (diff) | |
parent | 09293f1d07b019dc7bfe95afb93364cc87774e82 (diff) | |
download | Qt-88b2bf18c558d0e2f8a9268802f277212f17e61e.zip Qt-88b2bf18c558d0e2f8a9268802f277212f17e61e.tar.gz Qt-88b2bf18c558d0e2f8a9268802f277212f17e61e.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into 4.7
Diffstat (limited to 'doc/src/declarative')
-rw-r--r-- | doc/src/declarative/advtutorial.qdoc | 22 | ||||
-rw-r--r-- | doc/src/declarative/codingconventions.qdoc | 1 | ||||
-rw-r--r-- | doc/src/declarative/declarativeui.qdoc | 2 | ||||
-rw-r--r-- | doc/src/declarative/elements.qdoc | 7 | ||||
-rw-r--r-- | doc/src/declarative/examples.qdoc | 39 | ||||
-rw-r--r-- | doc/src/declarative/extending-examples.qdoc | 5 | ||||
-rw-r--r-- | doc/src/declarative/extending.qdoc | 86 | ||||
-rw-r--r-- | doc/src/declarative/globalobject.qdoc | 91 | ||||
-rw-r--r-- | doc/src/declarative/integrating.qdoc | 3 | ||||
-rw-r--r-- | doc/src/declarative/javascriptblocks.qdoc | 20 | ||||
-rw-r--r-- | doc/src/declarative/network.qdoc | 6 | ||||
-rw-r--r-- | doc/src/declarative/propertybinding.qdoc | 56 | ||||
-rw-r--r-- | doc/src/declarative/qdeclarativemodels.qdoc | 14 | ||||
-rw-r--r-- | doc/src/declarative/qdeclarativereference.qdoc | 4 | ||||
-rw-r--r-- | doc/src/declarative/qdeclarativesecurity.qdoc | 4 | ||||
-rw-r--r-- | doc/src/declarative/qtdeclarative.qdoc | 65 | ||||
-rw-r--r-- | doc/src/declarative/snippets/integrating/graphicswidgets/bluecircle.h | 3 | ||||
-rw-r--r-- | doc/src/declarative/snippets/integrating/graphicswidgets/redsquare.h | 3 |
18 files changed, 282 insertions, 149 deletions
diff --git a/doc/src/declarative/advtutorial.qdoc b/doc/src/declarative/advtutorial.qdoc index 751bf00..c465da4 100644 --- a/doc/src/declarative/advtutorial.qdoc +++ b/doc/src/declarative/advtutorial.qdoc @@ -67,7 +67,7 @@ Tutorial chapters: \list 1 \o \l {QML Advanced Tutorial 1 - Creating the Game Canvas and Blocks}{Creating the Game Canvas and Blocks} -\o \l {QML Advanced Tutorial 2 - Populating the Game Canvas}{Populating the Game Canvas}} +\o \l {QML Advanced Tutorial 2 - Populating the Game Canvas}{Populating the Game Canvas} \o \l {QML Advanced Tutorial 3 - Implementing the Game Logic}{Implementing the Game Logic} \o \l {QML Advanced Tutorial 4 - Finishing Touches}{Finishing Touches} \endlist @@ -83,10 +83,6 @@ directory. \previouspage QML Advanced Tutorial \nextpage QML Advanced Tutorial 2 - Populating the Game Canvas -In this chapter: - -\tableofcontents - The files referenced on this page can be found in \c $QTDIR\examples\tutorials\samegame\samegame1. \section2 Creating the application screen @@ -109,7 +105,7 @@ is the \l SystemPalette item. This provides access to the Qt system palette and is used to give the button a more native look-and-feel. Notice the anchors for the \c Item, \c Button and \c Text elements are set using -\l {Grouped Properties}{group notation} for readability. +\l {codingconventions.html#Grouped-properties}{group notation} for readability. \section2 Adding \c Button and \c Block components @@ -152,10 +148,6 @@ elements to get started. Next, we will populate the game canvas with some blocks \previouspage QML Advanced Tutorial 1 - Creating the Game Canvas and Blocks \nextpage QML Advanced Tutorial 3 - Implementing the Game Logic -In this chapter: - -\tableofcontents - The files referenced on this page can be found in \c $QTDIR\examples\tutorials\samegame\samegame2. @@ -224,10 +216,6 @@ Now, we have a screen of blocks, and we can begin to add the game mechanics. \previouspage QML Advanced Tutorial 2 - Populating the Game Canvas \nextpage QML Advanced Tutorial 4 - Finishing Touches -In this chapter: - -\tableofcontents - The files referenced on this page can be found in \c $QTDIR\examples\tutorials\samegame\samegame3. \section2 Making a playable game @@ -313,10 +301,6 @@ until the next chapter - where your application becomes alive! \contentspage QML Advanced Tutorial \previouspage QML Advanced Tutorial 3 - Implementing the Game Logic -In this chapter: - -\tableofcontents - The files referenced on this page can be found in \c $QTDIR\examples\tutorials\samegame\samegame4. \section2 Adding some flair @@ -432,7 +416,7 @@ If the player enters a name, we send the data to the service using this code in \snippet declarative/tutorials/samegame/samegame4/content/samegame.js 1 -The \c XMLHttpRequest in this code is the same \c XMLHttpRequest() as you'll find in standard browser JavaScript, and can be used in the same way to dynamically get XML +The \l XMLHttpRequest in this code is the same as the \c XMLHttpRequest() as you'll find in standard browser JavaScript, and can be used in the same way to dynamically get XML or QML from the web service to display the high scores. We don't worry about the response in this case - we just post the high score data to the web server. If it had returned a QML file (or a URL to a QML file) you could instantiate it in much the same way as you did with the blocks. diff --git a/doc/src/declarative/codingconventions.qdoc b/doc/src/declarative/codingconventions.qdoc index 7ae5cbd..7ca206b 100644 --- a/doc/src/declarative/codingconventions.qdoc +++ b/doc/src/declarative/codingconventions.qdoc @@ -72,6 +72,7 @@ For example, a hypothetical \e photo QML object would look like this: \snippet doc/src/snippets/declarative/codingconventions/photo.qml 0 +\target Grouped properties \section1 Grouped properties If using multiple properties from a group of properties, diff --git a/doc/src/declarative/declarativeui.qdoc b/doc/src/declarative/declarativeui.qdoc index 2d646b9..3ee7fc1 100644 --- a/doc/src/declarative/declarativeui.qdoc +++ b/doc/src/declarative/declarativeui.qdoc @@ -84,7 +84,7 @@ completely new applications. QML is fully \l {Extending QML in C++}{extensible \o \l {Introduction to the QML language} \o \l {QML Tutorial}{Tutorial: 'Hello World'} \o \l {QML Advanced Tutorial}{Tutorial: 'Same Game'} -\o \l {QML Examples and Walkthroughs} +\o \l {QML Examples and Demos} \o \l {Using QML in C++ Applications} \o \l {QML for Qt programmers} \endlist diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc index 8318392..6495f58 100644 --- a/doc/src/declarative/elements.qdoc +++ b/doc/src/declarative/elements.qdoc @@ -46,8 +46,6 @@ The following table lists the QML elements provided by the \l {QtDeclarative}{Qt Declarative} module. -\bold {Standard Qt Declarative Elements} - \table 80% \header \o \bold {States} @@ -81,6 +79,7 @@ The following table lists the QML elements provided by the \l {QtDeclarative}{Qt \o \l PropertyAction \o \l ScriptAction \o \l Transition +\o \l SmoothedFollow \o \l SpringFollow \o \l Behavior \endlist @@ -109,11 +108,7 @@ The following table lists the QML elements provided by the \l {QtDeclarative}{Qt \o \l QtObject \o \l WorkerScript \endlist -\endtable -\bold {QML Items} - -\table 80% \header \o \bold {Basic Visual Items} \o \bold {Basic Interaction Items} diff --git a/doc/src/declarative/examples.qdoc b/doc/src/declarative/examples.qdoc index 3d8325e..dc6b76c 100644 --- a/doc/src/declarative/examples.qdoc +++ b/doc/src/declarative/examples.qdoc @@ -41,18 +41,22 @@ /*! \page qdeclarativeexamples.html -\title QML Examples and Walkthroughs +\title QML Examples and Demos -\section1 Running Examples and Demos +\previouspage Graphics View Examples +\contentspage Qt Examples +\nextpage Painting Examples + +\section1 Running the examples You can find many simple examples in the \c examples/declarative sub-directory that show how to use various aspects of QML. In addition, the \c demos/declarative sub-directory contains more sophisticated demos of large applications. These demos are intended to show integrated functionality -rather than being instructive on specifice elements. +rather than being instructive on specific elements. -To run the examples and demos, use the included \l {Qt Declarative UI Runtime}{qml} -application. It has some useful options, revealed by: +To run the examples and demos, you can use Qt Creator or the included \l {Qt Declarative UI Runtime}{qml} +command-line application. It has some useful options, revealed by: \code bin/qml -help @@ -66,18 +70,19 @@ For example, from your build directory, run: \section1 Examples -These will be documented, and demonstrate how to achieve various things in QML. +\list +\o \l{declarative/focus}{Focus} +\endlist + +\section1 Demos -\table -\row - \o Elastic Dial - \o \image dial-example.gif -\row - \o \l{qdeclarativeexampletoggleswitch.html}{Toggle Switch} - \o \image switch-example.gif -\row - \o \l{QML Advanced Tutorial}{SameGame} - \o \image declarative-adv-tutorial4.gif -\endtable +\list +\o \l{demos/declarative/calculator}{Calculator} +\o \l{demos/declarative/minehunt}{Minehunt} +\o \l{demos/declarative/photoviewer}{Photo Viewer} +\o \l{demos/declarative/flickr}{Flickr Mobile} +\o \l{demos/declarative/samegame}{Same Game} +\o \l{demos/declarative/snake}{Snake} +\endlist */ diff --git a/doc/src/declarative/extending-examples.qdoc b/doc/src/declarative/extending-examples.qdoc index cc66838..307162e 100644 --- a/doc/src/declarative/extending-examples.qdoc +++ b/doc/src/declarative/extending-examples.qdoc @@ -57,11 +57,6 @@ element, the C++ class can be named differently, or appear in a namespace. \snippet examples/declarative/extending/adding/person.h 0 -Following the class declaration, we include the QML_DECLARE_TYPE() macro. This -is necessary to declare the type to QML. It also includes the logic necessary -to expose the class to Qt's meta system - that is, it includes the -Q_DECLARE_METATYPE() functionality. - \section1 Define the Person class \snippet examples/declarative/extending/adding/person.cpp 0 diff --git a/doc/src/declarative/extending.qdoc b/doc/src/declarative/extending.qdoc index e1c6469..c27d091 100644 --- a/doc/src/declarative/extending.qdoc +++ b/doc/src/declarative/extending.qdoc @@ -59,7 +59,7 @@ QML for their own independent use. \snippet examples/declarative/extending/adding/example.qml 0 The QML snippet shown above instantiates one \c Person instance and sets -the name and shoeSize properties on it. Everything in QML ultimately comes down +the \c name and \c shoeSize properties on it. Everything in QML ultimately comes down to either instantiating an object instance, or assigning a property a value. QML relies heavily on Qt's meta object system and can only instantiate classes that derive from QObject. @@ -67,12 +67,11 @@ that derive from QObject. The QML engine has no intrinsic knowledge of any class types. Instead the programmer must define the C++ types, and their corresponding QML name. -Custom C++ types are declared QML types using a macro and a template function: +Custom C++ types are registered using a template function: \quotation \code -#define QML_DECLARE_TYPE(T) template<typename T> int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const char *qmlName) \endcode @@ -81,10 +80,6 @@ Calling qmlRegisterType() registers the C++ type \a T with the QML system, and m under the name \a qmlName in library \a uri version \a versionMajor.versionMinor. The \a qmlName can be the same as the C++ type name. -Generally the QML_DECLARE_TYPE() macro should be included immediately following -the type declaration (usually in its header file), and the template function qmlRegisterType() -called by the implementation. - Type \a T must be a concrete type that inherits QObject and has a default constructor. \endquotation @@ -129,7 +124,7 @@ the \c Person type. \snippet examples/declarative/extending/properties/example.qml 0 The QML snippet shown above assigns a \c Person object to the \c BirthdayParty's -celebrant property, and assigns three \c Person objects to the guests property. +\c host property, and assigns three \c Person objects to the guests property. QML can set properties of types that are more complex than basic intrinsics like integers and strings. Properties can also be object pointers, Qt interface @@ -138,42 +133,37 @@ is typesafe it ensures that only valid types are assigned to these properties, just like it does for primitive types. Properties that are pointers to objects or Qt interfaces are declared with the -Q_PROPERTY() macro, just like other properties. The celebrant property +Q_PROPERTY() macro, just like other properties. The \c host property declaration looks like this: \snippet examples/declarative/extending/properties/birthdayparty.h 1 -As long as the property type, in this case Person, is registered with QML the +As long as the property type, in this case \c Person, is registered with QML the property can be assigned. QML also supports assigning Qt interfaces. To assign to a property whose type is a Qt interface pointer, the interface must also be registered with QML. As they cannot be instantiated directly, registering a Qt interface is different -from registering a new QML type. The following macro and function are used instead: +from registering a new QML type. The following function is used instead: \quotation \code -#define QML_DECLARE_INTERFACE(T) template<typename T> int qmlRegisterInterface(const char *typeName) \endcode Registers the C++ interface \a T with the QML system as \a typeName. -Generally the QML_DECLARE_INTERFACE() macro should be included immediately -following the interface declaration (usually in its header file), and the -qmlRegisterInterface() template function called by the implementation. - Following registration, QML can coerce objects that implement this interface for assignment to appropriately typed properties. \endquotation -The guests property is a list of \c Person objects. Properties that are lists +The \c guests property is a list of \c Person objects. Properties that are lists of objects or Qt interfaces are also declared with the Q_PROPERTY() macro, just like other properties. List properties must have the type \c {QDeclarativeListProperty<T>}. As with object properties, the type \a T must be registered with QML. -The guest property declaration looks like this: +The \c guest property declaration looks like this: \snippet examples/declarative/extending/properties/birthdayparty.h 2 @@ -185,24 +175,23 @@ code used to create the \c BirthdayParty type. \snippet examples/declarative/extending/coercion/example.qml 0 The QML snippet shown above assigns a \c Boy object to the \c BirthdayParty's -celebrant property, and assigns three other objects to the guests property. +\c host property, and assigns three other objects to the \c guests property. -QML supports C++ inheritance heirarchies and can freely coerce between known, +QML supports C++ inheritance hierarchies and can freely coerce between known, valid object types. This enables the creation of common base classes that allow the assignment of specialized classes to object or list properties. In the -snippet shown, both the celebrant and the guests properties retain the Person -type used in the previous section, but the assignment is valid as both the Boy -and Girl objects inherit from Person. +snippet shown, both the \c host and the \c guests properties retain the \c Person +type used in the previous section, but the assignment is valid as both the \c Boy +and \c Girl objects inherit from \c Person. To assign to a property, the property's type must have been registered with QML. Both the qmlRegisterType() and qmlRegisterInterface() template functions already shown can be used to register a type with QML. Additionally, if a type that acts purely as a base class that cannot be instantiated from QML needs to be -registered these macro and function can be used: +registered, the following function can be used: \quotation \code - #define QML_DECLARE_TYPE(T) template<typename T> int qmlRegisterType() \endcode @@ -212,10 +201,6 @@ function qmlRegisterType() does not define a mapping between the C++ class and a QML element name, so the type is not instantiable from QML, but it is available for type coercion. -Generally the QML_DECLARE_TYPE() macro should be included immediately following -the type declaration (usually in its header file), and the -qmlRegisterType() template function called from the implementation. - Type \a T must inherit QObject, but there are no restrictions on whether it is concrete or the signature of its constructor. \endquotation @@ -234,7 +219,7 @@ code used to create the \c Boy and \c Girl types. The QML snippet shown above assigns a collection of objects to the \c BirthdayParty's default property. -The default property is a syntactic convenience that allows a type designer to +The \e {default property} is a syntactic convenience that allows a type designer to specify a single property as the type's default. The default property is assigned to whenever no explicit property is specified. As a convenience, it is behaviorally identical to assigning the default property explicitly by name. @@ -272,12 +257,12 @@ may also simplify the implementation of common property collections across different types through implementation reuse. A grouped property block is implemented as a read-only object property. The -shoe property shown is declared like this: +\c shoe property shown is declared like this: \snippet examples/declarative/extending/grouped/person.h 1 -The ShoeDescription type declares the properties available to the grouped -property block - in this case the size, color, brand and price properties. +The \c ShoeDescription type declares the properties available to the grouped +property block - in this case the \c size, \c color, \c brand and \c price properties. Grouped property blocks may declared and accessed be recusively. @@ -288,7 +273,7 @@ implement the \c shoe property grouping. \snippet examples/declarative/extending/attached/example.qml 1 -The QML snippet shown above assigns the rsvp property using the attached +The QML snippet shown above assigns the \c rsvp property using the attached property syntax. Attached properties allow unrelated types to annotate other types with some @@ -297,7 +282,7 @@ identified through the use of the attacher type name, in the case shown \c BirthdayParty, as a suffix to the property name. In the example shown, \c BirthdayParty is called the attaching type, and the -Boy instance the attachee object instance. +\c Boy instance the attachee object instance. For the attaching type, an attached property block is implemented as a new QObject derived type, called the attachment object. The properties on the @@ -320,7 +305,6 @@ public: }; QML_DECLARE_TYPEINFO(MyType, QML_HAS_ATTACHED_PROPERTIES) -QML_DECLARE_TYPE(MyType) \endcode Return an attachment object, of type \a AttachedPropertiesType, for the attachee \a object instance. It is customary, though not strictly required, for @@ -342,7 +326,7 @@ their effect may be so limited. For example, a common usage scenario is for a type to enhance the properties available to its children in order to gather instance specific data. Here we -add a rsvp field to all the guests coming to a birthday party: +add a \c rsvp field to all the guests coming to a birthday party: \code BirthdayParty { Boy { BirthdayParty.rsvp: "2009-06-01" } @@ -378,7 +362,7 @@ implement the rsvp attached property. \section1 Memory Management and QVariant types -It is an elements responsibility to ensure that it does not access or return +It is an element's responsibility to ensure that it does not access or return pointers to invalid objects. QML makes the following guarentees: \list @@ -443,7 +427,7 @@ implement the onPartyStarted signal property. \snippet examples/declarative/extending/valuesource/example.qml 0 \snippet examples/declarative/extending/valuesource/example.qml 1 -The QML snippet shown above assigns a property value to the speaker property. +The QML snippet shown above applies a property value source to the \c announcment property. A property value source generates a value for a property that changes over time. Property value sources are most commonly used to do animation. Rather than @@ -451,9 +435,9 @@ constructing an animation object and manually setting the animation's "target" property, a property value source can be assigned directly to a property of any type and automatically set up this association. -The example shown here is rather contrived: the speaker property of the -BirthdayParty object is a string that is printed every time it is assigned and -the HappyBirthday value source generates the lyrics of the song +The example shown here is rather contrived: the \c announcment property of the +\c BirthdayParty object is a string that is printed every time it is assigned and +the \c HappyBirthdaySong value source generates the lyrics of the song "Happy Birthday". \snippet examples/declarative/extending/valuesource/birthdayparty.h 0 @@ -467,11 +451,11 @@ Property value sources are special types that derive from the QDeclarativePropertyValueSource base class. This base class contains a single method, QDeclarativePropertyValueSource::setTarget(), that the QML engine invokes when associating the property value source with a property. The relevant part of -the HappyBirthday type declaration looks like this: +the \c HappyBirthdaySong type declaration looks like this: -\snippet examples/declarative/extending/valuesource/happybirthday.h 0 -\snippet examples/declarative/extending/valuesource/happybirthday.h 1 -\snippet examples/declarative/extending/valuesource/happybirthday.h 2 +\snippet examples/declarative/extending/valuesource/happybirthdaysong.h 0 +\snippet examples/declarative/extending/valuesource/happybirthdaysong.h 1 +\snippet examples/declarative/extending/valuesource/happybirthdaysong.h 2 In all other respects, property value sources are regular QML types. They must be registered with the QML engine using the same macros as other types, and can @@ -479,11 +463,11 @@ contain properties, signals and methods just like other types. When a property value source object is assigned to a property, QML first tries to assign it normally, as though it were a regular QML type. Only if this -assignment fails does the engine call the setTarget() method. This allows +assignment fails does the engine call the \l {QDeclarativePropertyValueSource::}{setTarget()} method. This allows the type to also be used in contexts other than just as a value source. \l {Extending QML - Property Value Source Example} shows the complete code used -implement the HappyBirthday property value source. +implement the \c HappyBirthdaySong property value source. \section1 Property Binding @@ -491,7 +475,7 @@ implement the HappyBirthday property value source. \snippet examples/declarative/extending/binding/example.qml 1 The QML snippet shown above uses a property binding to ensure the -HappyBirthday's name property remains up to date with the celebrant. +\c HappyBirthdaySong's \c name property remains up to date with the \c host. Property binding is a core feature of QML. In addition to assigning literal values, property bindings allow the developer to assign an arbitrarily complex @@ -504,9 +488,9 @@ All properties on custom types automatically support property binding. However, for binding to work correctly, QML must be able to reliably determine when a property has changed so that it knows to reevaluate any bindings that depend on the property's value. QML relies on the presence of a -\c {Qt's Property System}{NOTIFY signal} for this determination. +\l {Qt's Property System}{NOTIFY signal} for this determination. -Here is the celebrant property declaration: +Here is the \c host property declaration: \snippet examples/declarative/extending/binding/birthdayparty.h 0 diff --git a/doc/src/declarative/globalobject.qdoc b/doc/src/declarative/globalobject.qdoc index 97f5d91..6709ab4 100644 --- a/doc/src/declarative/globalobject.qdoc +++ b/doc/src/declarative/globalobject.qdoc @@ -190,10 +190,10 @@ This function attempts to open the specified \c target url in an external applic This function returns a hex string of the md5 hash of \c data. \section3 Qt.btoa(data) -This function returns a base64 encoding of \c data. +Binary to ASCII - this function returns a base64 encoding of \c data. \section3 Qt.atob(data) -This function returns a base64 decoding of \c data. +ASCII to binary - this function returns a base64 decoding of \c data. \section3 Qt.quit() This function causes the QML engine to emit the quit signal, which in @@ -258,6 +258,11 @@ of their use. } \endcode + The methods and properties of the Component element are defined in its own + page, but when using it dynamically only two methods are usually used. + Component.createObject() returns the created object or null if there is an error. + If there is an error, Component.errorsString() describes what the error was. + If you want to just create an arbitrary string of QML, instead of loading a QML file, consider the createQmlObject() function. @@ -277,7 +282,9 @@ of their use. similarly to eval, but for creating QML elements. Returns the created object, or null if there is an error. In the case of an - error, details of the error are output using qWarning(). + error, a QtScript Error object is thrown. This object has the additional property, + qmlErrors, which is an array of all the errors encountered when trying to execute the + QML. Each object in the array has the members: lineNumber, columnNumber, fileName and message. Note that this function returns immediately, and therefore may not work if the QML loads new components. If you are trying to load a new component, @@ -286,11 +293,81 @@ of their use. been loaded, and so it is safe to use createQmlObject to load built-in components. -\section1 Asynchronous JavaScript and XML -QML script supports the XMLHttpRequest object, which can be used to asynchronously obtain data from over a network. -\section2 XMLHttpRequest() -In QML you can construct an XMLHttpRequest object just like in a web browser! TODO: Real documentation for this object. +\section1 XMLHttpRequest + +\target XMLHttpRequest + +QML script supports the XMLHttpRequest object, which can be used to asynchronously obtain +data from over a network. + +The XMLHttpRequest API implements the same \l {http://www.w3.org/TR/XMLHttpRequest/}{W3C standard} +as many popular web browsers with following exceptions: +\list +\i QML's XMLHttpRequest does not enforce the same origin policty. +\i QML's XMLHttpRequest does not support \e synchronous requests. +\endlist + +Additionally, the \c responseXML XML DOM tree currently supported by QML is a reduced subset +of the \l {http://www.w3.org/TR/DOM-Level-3-Core/}{DOM Level 3 Core} API supported in a web +browser. The following objects and properties are supported by the QML implementation: +\table +\header +\o \bold {Node} +\o \bold {Document} +\o \bold {Element} +\o \bold {Attr} +\o \bold {CharacterData} +\o \bold {Text} + +\row +\o +\list +\o nodeName +\o nodeValue +\o nodeType +\o parentNode +\o childNodes +\o firstChild +\o lastChild +\o previousSibling +\o nextSibling +\o attribtes +\endlist + +\o +\list +\o xmlVersion +\o xmlEncoding +\o xmlStandalone +\o documentElement +\endlist + +\o +\list +\o tagName +\endlist + +\o +\list +\o name +\o value +\o ownerElement +\endlist + +\o +\list +\o data +\o length +\endlist + +\o +\list +\o isElementContentWhitespace +\o wholeText +\endlist + +\endtable \section1 Offline Storage API diff --git a/doc/src/declarative/integrating.qdoc b/doc/src/declarative/integrating.qdoc index d4034fa..65413ec 100644 --- a/doc/src/declarative/integrating.qdoc +++ b/doc/src/declarative/integrating.qdoc @@ -115,8 +115,7 @@ any custom C++ types and create a plugin that registers the custom types so that they can be used from your QML file. Here is an example. Suppose you have two classes, \c RedSquare and \c BlueCircle, -that both inherit from QGraphicsWidget. First, you need to register these two types -using the \c QML_DECLARE_TYPE macro from \c <QtDeclarative/qdeclarative.h>, like this: +that both inherit from QGraphicsWidget: \c [graphicswidgets/redsquare.h] \snippet doc/src/declarative/snippets/integrating/graphicswidgets/redsquare.h 0 diff --git a/doc/src/declarative/javascriptblocks.qdoc b/doc/src/declarative/javascriptblocks.qdoc index 8ffe58c..7c0570e 100644 --- a/doc/src/declarative/javascriptblocks.qdoc +++ b/doc/src/declarative/javascriptblocks.qdoc @@ -47,7 +47,7 @@ QML encourages building UIs declaratively, using \l {Property Binding} and the composition of existing \l {QML Elements}. To allow the implementation of more advanced behavior, QML integrates tightly with imperative JavaScript code. -The JavaScript environment provided by QML is stricter than that in a webbrowser. +The JavaScript environment provided by QML is stricter than that in a web browser. In QML you cannot add, or modify, members of the JavaScript global object. It is possible to do this accidentally by using a variable without declaring it. In QML this will throw an exception, so all local variables should be explicitly @@ -66,7 +66,7 @@ them. \code Item { function factorial(a) { - a = Integer(a); + a = parseInt(a); if (a <= 0) return 1; else @@ -104,12 +104,12 @@ Item { } \endcode -Both relative and absolute JavaScript URLs can be imported. In the case of a -relative URL, the location is resolved relative to the location of the -\l {QML Document} that contains the import. If the script file is not accessible, -an error will occur. If the JavaScript needs to be fetched from a network +Both relative and absolute JavaScript URLs can be imported. In the case of a +relative URL, the location is resolved relative to the location of the +\l {QML Document} that contains the import. If the script file is not accessible, +an error will occur. If the JavaScript needs to be fetched from a network resource, the QML document has a "Loading" -\l {QDeclarativeComponent::status()}{status} until the script has been +\l {QDeclarativeComponent::status()}{status} until the script has been downloaded. Imported JavaScript files are always qualified using the "as" keyword. The @@ -143,7 +143,7 @@ stateless library through the use of a pragma, as shown in the following example .pragma library function factorial(a) { - a = Integer(a); + a = parseInt(a); if (a <= 0) return 1; else @@ -160,7 +160,7 @@ parameters. \section1 Running JavaScript at Startup It is occasionally necessary to run some imperative code at application (or -component instance) "startup". While it is tempting to just include the startup +component instance) startup. While it is tempting to just include the startup script as \e {global code} in an external script file, this can have severe limitations as the QML environment may not have been fully established. For example, some objects might not have been created or some \l {Property Binding}s may not have been run. @@ -180,7 +180,7 @@ Rectangle { } \endcode -Any element in a QML file - including nested elements and nested QML component +Any element in a QML file - including nested elements and nested QML component instances - can use this attached property. If there is more than one \c onCompleted() handler to execute at startup, they are run sequentially in an undefined order. diff --git a/doc/src/declarative/network.qdoc b/doc/src/declarative/network.qdoc index 0a26c68..d268a13 100644 --- a/doc/src/declarative/network.qdoc +++ b/doc/src/declarative/network.qdoc @@ -69,8 +69,10 @@ Network transparency is supported throughout QML, for example: \endlist Even QML types themselves can be on the network - if the \l {Qt Declarative UI Runtime}{qml} tool is used to load -\tt http://example.com/mystuff/Hello.qml and that content refers to a type "World", this -will load from \tt http://example.com/mystuff/World.qml just as it would for a local file. +\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 +\tt http://example.com/mystuff/World.qml Any other resources that \tt Hello.qml referred to, usually by a relative URL, would similarly be loaded from the network. diff --git a/doc/src/declarative/propertybinding.qdoc b/doc/src/declarative/propertybinding.qdoc index 02f9868..ab3682d 100644 --- a/doc/src/declarative/propertybinding.qdoc +++ b/doc/src/declarative/propertybinding.qdoc @@ -78,16 +78,52 @@ Rectangle { } \endcode -Being JavaScript expressions, bindings are evaluated in a scope chain. The \l {QML Scope} -documentation covers the specifics of scoping in QML. - -\list -\o When does a binding not get updated? -\o Scope -\o Assigning a constant/other binding clears existing binding -\o Loops -\o Using model data -\endlist +While syntactically bindings can be of arbitrary complexity, if a binding starts to become +overly complex - such as involving multiple lines, or imperative loops - it may be better +to refactor the component entirely, or at least factor the binding out into a separate +function. + +\section1 Changing Bindings + +The \l PropertyChanges element can be used within a state change to modify the bindings on +properties. + +This example modifies the \l Rectangle's width property binding to be \c {otherItem.height} +when in the "square" state. When it returns to its default state, width's original property +binding will have been restored. + +\code +Rectangle { + id: rectangle + width: otherItem.width + height: otherItem.height + + states: State { + name: "square" + PropertyChanges { + target: rectangle + width: otherItem.height + } + } +} +\endcode + +Imperatively assigning a value directly to a property will also implicitly remove a binding +on a property. A property can only have one value at a time, and if code explicitly sets +this value the binding must be removed. The \l Rectangle in the example below will have +a width of 13, regardless of the otherItem's width. + +\code +Rectangle { + width: otherItem.width + + Component.onCompleted: { + width = 13; + } +} +\endcode + +There is no way to create a property binding directly from imperative JavaScript code. \section1 Binding Element diff --git a/doc/src/declarative/qdeclarativemodels.qdoc b/doc/src/declarative/qdeclarativemodels.qdoc index d8b2a5d..91acb3c 100644 --- a/doc/src/declarative/qdeclarativemodels.qdoc +++ b/doc/src/declarative/qdeclarativemodels.qdoc @@ -206,8 +206,16 @@ The default role names set by Qt are: \endtable QAbstractItemModel presents a heirachy of tables. Views currently provided by QML -can only display list data. In order to display child lists of a heirachical model -use the VisualDataModel element with \e rootIndex set to a parent node. +can only display list data. +In order to display child lists of a heirachical 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 +\o \l VisualDataModel::modelIndex() returns a QModelIndex which can be assigned to VisualDataModel::rootIndex +\o \l VisualDataModel::parentModelIndex() returns a QModelIndex which can be assigned to VisualDataModel::rootIndex +\endlist \section2 QStringList @@ -225,7 +233,7 @@ dataList.append("Ginger"); dataList.append("Skipper"); QDeclarativeContext *ctxt = view.rootContext(); -ctxt->setContextProperty("myModel", QVariant::fromValue(&dataList)); +ctxt->setContextProperty("myModel", QVariant::fromValue(dataList)); \endcode \o diff --git a/doc/src/declarative/qdeclarativereference.qdoc b/doc/src/declarative/qdeclarativereference.qdoc index b2cfba8..4c1f449 100644 --- a/doc/src/declarative/qdeclarativereference.qdoc +++ b/doc/src/declarative/qdeclarativereference.qdoc @@ -55,7 +55,7 @@ That is, you specify \e what the UI should look like and how it should behave rather than specifying step-by-step \e how to build it. Specifying a UI declaratively does not just include the layout of the interface items, but also the way each - individual item looks and behaves and the overall flow of the application. + individual item looks and behaves and the overall flow of the application. The QML elements provide a sophisticated set of graphical and behavioral building blocks. These different elements are combined together in \l {QML Documents}{QML documents} to build components @@ -67,7 +67,7 @@ \o \l {Introduction to the QML language} \o \l {QML Tutorial}{Tutorial: 'Hello World'} \o \l {QML Advanced Tutorial}{Advanced Tutorial: 'Same Game'} - \o \l {QML Examples and Walkthroughs} + \o \l {QML Examples and Demos} \endlist \section1 Core QML Features: diff --git a/doc/src/declarative/qdeclarativesecurity.qdoc b/doc/src/declarative/qdeclarativesecurity.qdoc index 290d78f..91d6d87 100644 --- a/doc/src/declarative/qdeclarativesecurity.qdoc +++ b/doc/src/declarative/qdeclarativesecurity.qdoc @@ -72,7 +72,7 @@ A non-exhaustive list of the ways you could shoot yourself in the foot is: \list \i Using \c import to import QML or JavaScript you do not control. BAD \i Using \l Loader to import QML you do not control. BAD - \i Using \l{XMLHttpRequest()}{XMLHttpRequest} to load data you do not control and executing it. BAD + \i Using \l{XMLHttpRequest}{XMLHttpRequest} to load data you do not control and executing it. BAD \endlist However, the above does not mean that you have no use for the network transparency of QML. @@ -81,7 +81,7 @@ There are many good and useful things you \e can do: \list \i Create \l Image elements with source URLs of any online images. GOOD \i Use XmlListModel to present online content. GOOD - \i Use \l{XMLHttpRequest()}{XMLHttpRequest} to interact with online services. GOOD + \i Use \l{XMLHttpRequest}{XMLHttpRequest} to interact with online services. GOOD \endlist The only reason this page is necessary at all is that JavaScript, when run in a \e{web browser}, diff --git a/doc/src/declarative/qtdeclarative.qdoc b/doc/src/declarative/qtdeclarative.qdoc index cbb2146..670a218 100644 --- a/doc/src/declarative/qtdeclarative.qdoc +++ b/doc/src/declarative/qtdeclarative.qdoc @@ -70,9 +70,7 @@ \macro QML_DECLARE_TYPE() \relates QDeclarativeEngine - Declares a C++ type to be usable in the QML system. In addition - to this, a type must also be registered with the QML system using - qmlRegisterType(). + Equivalent to Q_DECLARE_METATYPE(TYPE) and Q_DECLARE_METATYPE(QDeclarativeListProperty<TYPE>) */ @@ -81,9 +79,8 @@ \relates QDeclarativeEngine This template function registers the C++ type in the QML system with - the name \a qmlName. in the library imported from \a uri having the + the name \a qmlName, in the library imported from \a uri having the version number composed from \a versionMajor and \a versionMinor. - The type should also haved been declared with the QML_DECLARE_TYPE() macro. Returns the QML type id. @@ -94,6 +91,63 @@ qmlRegisterType<MinehuntGame>("MinehuntCore", 0, 1, "Game"); \endcode + Note that it's perfectly reasonable for a library to register types to older versions + than the actual version of the library. Indeed, it is normal for the new library to allow + QML written to previous versions to continue to work, even if more advanced versions of + some of its types are available. +*/ + +/*! + \fn int qmlRegisterUncreatableType(const char *uri, int versionMajor, int versionMinor, const char *qmlName, const QString& message) + \relates QDeclarativeEngine + + This template function registers the C++ type in the QML system with + the name \a qmlName, in the library imported from \a uri having the + version number composed from \a versionMajor and \a versionMinor. + + While the type has a name and a type, it cannot be created, and the + given error \a message will result if creation is attempted. + + This is useful where the type is only intended for providing attached properties or enum values. + + Returns the QML type id. + + \sa qmlRegisterTypeNotAvailable +*/ + +/*! + \fn int qmlRegisterTypeNotAvailable(const char *uri, int versionMajor, int versionMinor, const char *qmlName, const QString& message) + \relates QDeclarativeEngine + + This function registers a type in the QML system with the name \a qmlName, in the library imported from \a uri having the + version number composed from \a versionMajor and \a versionMinor, but any attempt to instantiate the type + will produce the given error \a message. + + Normally, the types exported by a module should be fixed. However, if a C++ type is not available, you should + at least "reserve" the QML type name, and give the user of your module a meaningful error message. + + Returns the QML type id. + + Example: + + \code + #ifdef NO_GAMES_ALLOWED + qmlRegisterTypeNotAvailable("MinehuntCore", 0, 1, "Game", "Get back to work, slacker!"); + #else + qmlRegisterType<MinehuntGame>("MinehuntCore", 0, 1, "Game"); + #endif + \endcode + + This will cause any QML which uses this module and attempts to use the type to produce an error message: + \code +fun.qml: Get back to work, slacker! + Game { + ^ + \endcode + + Without this, a generic "Game is not a type" message would be given. + + \sa qmlRegisterUncreatableType */ /*! @@ -114,7 +168,6 @@ This template function registers the C++ type in the QML system under the name \a typeName. - The type should also haved been declared with the QML_DECLARE_TYPE() macro. Returns the QML type id. diff --git a/doc/src/declarative/snippets/integrating/graphicswidgets/bluecircle.h b/doc/src/declarative/snippets/integrating/graphicswidgets/bluecircle.h index 028718f..73d66b7 100644 --- a/doc/src/declarative/snippets/integrating/graphicswidgets/bluecircle.h +++ b/doc/src/declarative/snippets/integrating/graphicswidgets/bluecircle.h @@ -39,7 +39,6 @@ ** ****************************************************************************/ //![0] -#include <QtDeclarative/qdeclarative.h> #include <QGraphicsWidget> #include <QPainter> @@ -53,6 +52,4 @@ public: painter->drawEllipse(0, 0, size().width(), size().height()); } }; - -QML_DECLARE_TYPE(BlueCircle) //![0] diff --git a/doc/src/declarative/snippets/integrating/graphicswidgets/redsquare.h b/doc/src/declarative/snippets/integrating/graphicswidgets/redsquare.h index 76e7d11..3050662 100644 --- a/doc/src/declarative/snippets/integrating/graphicswidgets/redsquare.h +++ b/doc/src/declarative/snippets/integrating/graphicswidgets/redsquare.h @@ -39,7 +39,6 @@ ** ****************************************************************************/ //![0] -#include <QtDeclarative/qdeclarative.h> #include <QGraphicsWidget> #include <QPainter> @@ -52,6 +51,4 @@ public: painter->fillRect(0, 0, size().width(), size().height(), QColor(Qt::red)); } }; - -QML_DECLARE_TYPE(RedSquare) //![0] |