diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-04-30 11:43:12 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-04-30 11:43:12 (GMT) |
commit | 6103c282707bac2d585473d45900d69d475cf0c2 (patch) | |
tree | c36bd5818b85bcdc62226b6f430576f08c303e1c /doc/src | |
parent | 3e6a12e90d05d24bca68128d60215c207a416ef6 (diff) | |
parent | 0b7a84684e0b2065208172d7145e838c7a653b83 (diff) | |
download | Qt-6103c282707bac2d585473d45900d69d475cf0c2.zip Qt-6103c282707bac2d585473d45900d69d475cf0c2.tar.gz Qt-6103c282707bac2d585473d45900d69d475cf0c2.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/qt-qml: (68 commits)
Don't create an anchors element so that we can check that there aren't any
Ensure eval and Function are in the correct scope
Add availableFonts.qml for fonts examples.
Add Qt.fontFamilies() method
Avoid regenerating PathView delegates needlessly
When a model delegate is released, remove it from the scene immediately.
Fix assignment of value types to javascript var.
More doc fixes
Make QDeclarativeParserStatus method pure virtual to encourage right code.
Doc fixes
Fix error string
Add QML value types for math3d types
Fix assert in qdeclarativepathview
Avoid divisions by zero in qdeclarativetimeline
Initialize variable.
Doc: mention that size of delegate affects flicking performance.
buffer new items on initialization.
Compile with QT_NO_GRAPHICSEFFECT.
Fix translation context when qsTr is used in PropertyChanges.
missed files
...
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/declarative/advtutorial.qdoc | 2 | ||||
-rw-r--r-- | doc/src/declarative/codingconventions.qdoc | 6 | ||||
-rw-r--r-- | doc/src/declarative/dynamicobjects.qdoc | 149 | ||||
-rw-r--r-- | doc/src/declarative/globalobject.qdoc | 167 | ||||
-rw-r--r-- | doc/src/declarative/integrating.qdoc | 12 | ||||
-rw-r--r-- | doc/src/declarative/qtbinding.qdoc | 26 | ||||
-rw-r--r-- | doc/src/snippets/declarative/Sprite.qml | 3 | ||||
-rw-r--r-- | doc/src/snippets/declarative/componentCreation.js | 51 | ||||
-rw-r--r-- | doc/src/snippets/declarative/createComponent.qml | 9 | ||||
-rw-r--r-- | doc/src/snippets/declarative/createQmlObject.qml | 18 | ||||
-rw-r--r-- | doc/src/snippets/declarative/graphicswidgets/bluecircle.h (renamed from doc/src/declarative/snippets/integrating/graphicswidgets/bluecircle.h) | 0 | ||||
-rw-r--r-- | doc/src/snippets/declarative/graphicswidgets/graphicswidgets.pro (renamed from doc/src/declarative/snippets/integrating/graphicswidgets/graphicswidgets.pro) | 0 | ||||
-rw-r--r-- | doc/src/snippets/declarative/graphicswidgets/main.qml (renamed from doc/src/declarative/snippets/integrating/graphicswidgets/main.qml) | 0 | ||||
-rw-r--r-- | doc/src/snippets/declarative/graphicswidgets/qmldir (renamed from doc/src/declarative/snippets/integrating/graphicswidgets/qmldir) | 0 | ||||
-rw-r--r-- | doc/src/snippets/declarative/graphicswidgets/redsquare.h (renamed from doc/src/declarative/snippets/integrating/graphicswidgets/redsquare.h) | 0 | ||||
-rw-r--r-- | doc/src/snippets/declarative/graphicswidgets/shapesplugin.cpp (renamed from doc/src/declarative/snippets/integrating/graphicswidgets/shapesplugin.cpp) | 0 | ||||
-rw-r--r-- | doc/src/snippets/declarative/mouseregion.qml | 14 | ||||
-rw-r--r-- | doc/src/snippets/declarative/qtbinding/contextproperties/contextproperties.pro (renamed from doc/src/declarative/snippets/qtbinding/contextproperties/contextproperties.pro) | 0 | ||||
-rw-r--r-- | doc/src/snippets/declarative/qtbinding/contextproperties/main.cpp (renamed from doc/src/declarative/snippets/qtbinding/contextproperties/main.cpp) | 0 | ||||
-rw-r--r-- | doc/src/snippets/declarative/qtbinding/contextproperties/main.qml (renamed from doc/src/declarative/snippets/qtbinding/contextproperties/main.qml) | 0 | ||||
-rw-r--r-- | doc/src/snippets/declarative/qtbinding/custompalette/custompalette.h (renamed from doc/src/declarative/snippets/qtbinding/custompalette/custompalette.h) | 0 | ||||
-rw-r--r-- | doc/src/snippets/declarative/qtbinding/custompalette/custompalette.pro (renamed from doc/src/declarative/snippets/qtbinding/custompalette/custompalette.pro) | 0 | ||||
-rw-r--r-- | doc/src/snippets/declarative/qtbinding/custompalette/main.cpp (renamed from doc/src/declarative/snippets/qtbinding/custompalette/main.cpp) | 0 | ||||
-rw-r--r-- | doc/src/snippets/declarative/qtbinding/custompalette/main.qml (renamed from doc/src/declarative/snippets/qtbinding/custompalette/main.qml) | 0 | ||||
-rw-r--r-- | doc/src/snippets/declarative/qtbinding/resources/example.qrc (renamed from doc/src/declarative/snippets/qtbinding/resources/example.qrc) | 0 | ||||
-rw-r--r-- | doc/src/snippets/declarative/qtbinding/resources/images/background.png (renamed from doc/src/declarative/snippets/qtbinding/resources/images/background.png) | 0 | ||||
-rw-r--r-- | doc/src/snippets/declarative/qtbinding/resources/main.cpp (renamed from doc/src/declarative/snippets/qtbinding/resources/main.cpp) | 0 | ||||
-rw-r--r-- | doc/src/snippets/declarative/qtbinding/resources/main.qml (renamed from doc/src/declarative/snippets/qtbinding/resources/main.qml) | 0 | ||||
-rw-r--r-- | doc/src/snippets/declarative/qtbinding/resources/resources.pro (renamed from doc/src/declarative/snippets/qtbinding/resources/resources.pro) | 0 | ||||
-rw-r--r-- | doc/src/snippets/declarative/qtbinding/stopwatch/main.cpp (renamed from doc/src/declarative/snippets/qtbinding/stopwatch/main.cpp) | 0 | ||||
-rw-r--r-- | doc/src/snippets/declarative/qtbinding/stopwatch/main.qml (renamed from doc/src/declarative/snippets/qtbinding/stopwatch/main.qml) | 0 | ||||
-rw-r--r-- | doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.cpp (renamed from doc/src/declarative/snippets/qtbinding/stopwatch/stopwatch.cpp) | 0 | ||||
-rw-r--r-- | doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.h (renamed from doc/src/declarative/snippets/qtbinding/stopwatch/stopwatch.h) | 0 | ||||
-rw-r--r-- | doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.pro (renamed from doc/src/declarative/snippets/qtbinding/stopwatch/stopwatch.pro) | 0 |
34 files changed, 267 insertions, 190 deletions
diff --git a/doc/src/declarative/advtutorial.qdoc b/doc/src/declarative/advtutorial.qdoc index 2d05850..42ce246 100644 --- a/doc/src/declarative/advtutorial.qdoc +++ b/doc/src/declarative/advtutorial.qdoc @@ -174,7 +174,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 {createComponent(url file)}{createComponent()} is called to generate an element from \c Block.qml. +\o \l {Qt.createComponent(url file)}{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/codingconventions.qdoc b/doc/src/declarative/codingconventions.qdoc index 7ca206b..d0f873d 100644 --- a/doc/src/declarative/codingconventions.qdoc +++ b/doc/src/declarative/codingconventions.qdoc @@ -57,7 +57,7 @@ Through our documentation and examples, QML objects are always structured in the \o id \o property declarations \o signal declarations -\o javascript functions +\o JavaScript functions \o object properties \o child objects \o states @@ -102,7 +102,7 @@ we will write this: \snippet doc/src/snippets/declarative/codingconventions/lists.qml 1 -\section1 Javascript code +\section1 JavaScript code If the script is a single expression, we recommend writing it inline: @@ -116,7 +116,7 @@ If the script is more than a couple of lines long or can be used by different ob \snippet doc/src/snippets/declarative/codingconventions/javascript.qml 2 -For long scripts, we will put the functions in their own javascript file and import it like this: +For long scripts, we will put the functions in their own JavaScript file and import it like this: \snippet doc/src/snippets/declarative/codingconventions/javascript-imports.qml 0 diff --git a/doc/src/declarative/dynamicobjects.qdoc b/doc/src/declarative/dynamicobjects.qdoc index 4cb5198..5cdd768 100644 --- a/doc/src/declarative/dynamicobjects.qdoc +++ b/doc/src/declarative/dynamicobjects.qdoc @@ -43,84 +43,66 @@ \page qdeclarativedynamicobjects.html \title Dynamic Object Management -QML has some support for dynamically loading and managing QML objects from -within Javascript blocks. It is preferable to use the existing QML elements for -dynamic object management wherever possible; these are \l{Loader}, -\l{Repeater}, \l{ListView}, \l{GridView} and \l{PathView}. It is also possible -to dynamically create and manage objects from C++, and this is preferable for -hybrid QML/C++ applications - see \l{Using QML in C++ Applications}. -Dynamically creating and managing objects from -within Javascript blocks is intended for when none of the existing QML elements -fit the needs of your application, and you do not desire for your application -to involve C++ code. +QML provides a number of ways to dynamically create and manage QML objects. +The \l{Loader}, \l{Repeater}, \l{ListView}, \l{GridView} and \l{PathView} elements +all support dynamic object management. Objects can also be created and managed +from C++, and this is the preferred method for hybrid QML/C++ applications +(see \l{Using QML in C++ Applications}). + +QML also supports the dynamic creation of objects from within JavaScript +code. This is useful if the existing QML elements do not fit the needs of your +application, and there are no C++ components involved. + \section1 Creating Objects Dynamically -There are two ways of creating objects dynamically. You can either create -a component which instantiates items, or create an item from a string of QML. -Creating a component is better for the situation where you have a predefined -item which you want to manage dynamic instances of, and creating an item from -a string of QML is intended for when the QML itself is generated at runtime. +There are two ways to create objects dynamically from JavaScript. You can either call +\l {Qt.createComponent(url file)}{Qt.createComponent()} to create +a component which instantiates items, or use \l{Qt.createQmlObject(string qml, object parent, string filepath)}{Qt.createQmlObject()} +to create an item from a string of QML. +Creating a component is better if you have a predefined +item, and you want to create dynamic instances of that item; creating an item from +a string of QML is useful when the item QML itself is generated at runtime. If you have a component specified in a QML file, you can dynamically load it with -the \l {createComponent(url file)}{createComponent()} function on the \l{QML Global Object}. +the \l {Qt.createComponent(url file)}{Qt.createComponent()} function on the \l{QML Global Object}. This function takes the URL of the QML file as its only argument and returns a component object which can be used to create and load that QML file. -Once you have a component you can use its \c createObject() method to create an instance of -the component. Example QML script is below. Remember that QML files that might be loaded - over the network cannot be expected to be ready immediately. - \code - var component; - var sprite; - function finishCreation() { - if(component.isReady()) { - sprite = component.createObject(); - if(sprite == 0) { - // Error Handling - } else { - sprite.parent = page; - sprite.x = 200; - //... - } - } else if(component.isError()) { - // Error Handling - } - } +Once you have a component you can use its \l {Component::createObject()}{createObject()} method to create an instance of +the component. - component = createComponent("Sprite.qml"); - if(component.isReady()) { - finishCreation(); - } else { - component.statusChanged.connect(finishCreation); - } - \endcode - - If you are certain the files will be local, you could simplify to - - \code - component = createComponent("Sprite.qml"); - sprite = component.createObject(); - if(sprite == 0) { - // Error Handling - console.log(component.errorsString()); - } else { - sprite.parent = page; - sprite.x = 200; - //... - } - \endcode +Here is an example. Here is a \c Sprite.qml, which defines a simple QML component: + +\quotefile doc/src/snippets/declarative/Sprite.qml + +Our main application file, \c main.qml, imports a \c componentCreation.js JavaScript file +that will create \c Sprite objects: + +\quotefile doc/src/snippets/declarative/createComponent.qml + +Here is \c componentCreation.js. Remember that QML files that might be loaded +over the network cannot be expected to be ready immediately: -After creating the item, remember to set its parent to an item within the scene. -Otherwise your dynamically created item will not appear in the scene. When using files with relative paths, the path should -be relative to the file where \c createComponent() is executed. +\snippet doc/src/snippets/declarative/componentCreation.js 0 +\codeline +\snippet doc/src/snippets/declarative/componentCreation.js 1 -If the QML does not exist until runtime, you can create a QML item from -a string of QML using the \l{createQmlObject(string qml, object parent, string filepath)}{createQmlObject()} function, as in the following example: +If you are certain the files will be local, you could simplify to: + +\snippet doc/src/snippets/declarative/componentCreation.js 2 + +Notice that once a \c Sprite object is created, its parent is set to \c appWindow (defined +in \c main.qml). After creating an item, you must set its parent to an item within the scene. +Otherwise your dynamically created item will not appear in the scene. + +When using files with relative paths, the path should +be relative to the file where \l {Qt.createComponent(url file)}{Qt.createComponent()} is executed. + +If the QML component does not exist until runtime, you can create a QML item from +a string of QML using the \l{Qt.createQmlObject(string qml, object parent, string filepath)}{Qt.createQmlObject()} function, as in the following example: + +\snippet doc/src/snippets/declarative/createQmlObject.qml 0 - \code - newObject = createQmlObject('import Qt 4.7; Rectangle { color: "red"; width: 20; height: 20 }', - targetItem, "dynamicSnippet1"); - \endcode The first argument is the string of QML to create. Just like in a new file, you will need to import any types you wish to use. For importing files with relative paths, the path should be relative to the file where the item in the second argument is defined. Remember to set the parent after @@ -130,16 +112,24 @@ item, which is used for error reporting. \section1 Maintaining Dynamically Created Objects -Dynamically created objects may be used the same as other objects, however they -will not have an id in QML. +When managing dynamically created items, you must ensure the creation context +outlives the created item. Otherwise, if the creation context is destroyed first, +the bindings in the dynamic item will no longer work. + +The actual creation context depends on how an item is created: + +\list +\o If \l {Qt.createComponent(url file)}{Qt.createComponent()} is used, the creation context + is the QDeclarativeContext in which this method is called +\o If \l{Qt.createQmlObject(string qml, object parent, string filepath)}{Qt.createQmlObject()} + if called, it is the context of the item used as the second argument to this method +\o If a \c {Component{}} item is defined and \l {Component::createObject()}{createObject()} + is called on that item, it is the context in which the \c Component is defined +\endlist + +Also, note that while dynamically created objects may be used the same as other objects, they +do not have an id in QML. -A restriction which you need to manage with dynamically created items, -is that the creation context must outlive the -created item. The creation context is the QDeclarativeContext in which \c createComponent() -was called, or the context in which the Component element, or the item used as the -second argument to \c createQmlObject(), was specified. If the creation -context is destroyed before the dynamic item is, then bindings in the dynamic item will -fail to work. \section1 Deleting Objects Dynamically You should generally avoid dynamically deleting objects that you did not @@ -150,7 +140,7 @@ a worthwhile performance benefit. Note that you should never manually delete items which were dynamically created by QML Elements such as \l{Loader}. To manually delete a QML item, call its destroy method. This method has one -argument, which is an approximate delay in ms and which defaults to zero. This +argument, which is an approximate delay in milliseconds and which defaults to zero. This allows you to wait until the completion of an animation or transition. An example: \code @@ -169,8 +159,9 @@ allows you to wait until the completion of an animation or transition. An exampl object.parent = parentItem; } \endcode -In the above example, the dynamically created rectangle calls destroy as soon as it's created, - but delays long enough for its fade out animation to play. + +In the above example, the dynamically created rectangle calls destroy as soon as it is created, + but delays long enough for its fade out animation to be played. */ diff --git a/doc/src/declarative/globalobject.qdoc b/doc/src/declarative/globalobject.qdoc index 57eaae7..7c27ae4 100644 --- a/doc/src/declarative/globalobject.qdoc +++ b/doc/src/declarative/globalobject.qdoc @@ -166,10 +166,33 @@ If no format is specified the locale's short format is used. Alternatively, you \section2 Functions The Qt object also contains the following miscellaneous functions which expose Qt functionality for use in QML. -\section3 Qt.lighter(color baseColor) -This function returns a color 50% lighter than \c baseColor. See QColor::lighter() for further details. -\section3 Qt.darker(color baseColor) -This function returns a color 50% darker than \c baseColor. See QColor::darker() for further details. +\section3 Qt.lighter(color baseColor, real factor) +This function returns a color lighter than \c baseColor by the \c factor provided. + +If the factor is greater than 1.0, this functions returns a lighter color. +Setting factor to 1.5 returns a color that is 50% brighter. If the factor is less than 1.0, +the return color is darker, but we recommend using the Qt.darker() function for this purpose. +If the factor is 0 or negative, the return value is unspecified. + +The function converts the current RGB color to HSV, multiplies the value (V) component +by factor and converts the color back to RGB. + +If \c factor is not supplied, returns a color 50% lighter than \c baseColor (factor 1.5). + +\section3 Qt.darker(color baseColor, real factor) +This function returns a color darker than \c baseColor by the \c factor provided. + +If the factor is greater than 1.0, this function returns a darker color. +Setting factor to 3.0 returns a color that has one-third the brightness. +If the factor is less than 1.0, the return color is lighter, but we recommend using +the Qt.lighter() function for this purpose. If the factor is 0 or negative, the return +value is unspecified. + +The function converts the current RGB color to HSV, divides the value (V) component +by factor and converts the color back to RGB. + +If \c factor is not supplied, returns a color 50% darker than \c baseColor (factor 2.0). + \section3 Qt.tint(color baseColor, color tintColor) This function allows tinting one color with another. @@ -203,6 +226,9 @@ This function causes the QML engine to emit the quit signal, which in This function returns \c url resolved relative to the URL of the caller. +\section3 Qt.fontFamilies() +This function returns a list of the font families available to the application. + \section3 Qt.isQtObject(object) Returns true if \c object is a valid reference to a Qt or QML object, otherwise false. @@ -211,87 +237,58 @@ The following functions on the global object allow you to dynamically create QML items from files or strings. See \l{Dynamic Object Management} for an overview of their use. -\section2 createComponent(url file) - This function takes the URL of a QML file as its only argument. It returns - a component object which can be used to create and load that QML file. - - Example QML script is below. Remember that QML files that might be loaded - over the network cannot be expected to be ready immediately. - \code - var component; - var sprite; - function finishCreation(){ - if(component.isReady()){ - sprite = component.createObject(); - if(sprite == null){ - // Error Handling - }else{ - sprite.parent = page; - sprite.x = 200; - //... - } - }else if(component.isError()){ - // Error Handling - } - } - - component = createComponent("Sprite.qml"); - if(component.isReady()){ - finishCreation(); - }else{ - component.statusChanged.connect(finishCreation); - } - \endcode - - If you are certain the files will be local, you could simplify to - - \code - component = createComponent("Sprite.qml"); - sprite = component.createObject(); - if(sprite == null){ - // Error Handling - console.log(component.errorsString()); - }else{ - sprite.parent = page; - sprite.x = 200; - //... - } - \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. - -\section2 createQmlObject(string qml, object parent, string filepath) - Creates a new object from the specified string of QML. It requires a - second argument, which is the id of an existing QML object to use as - the new object's parent. If a third argument is provided, this is used - for error reporting as the filepath that the QML came from. - - Example (where targetItem is the id of an existing QML item): - \code - newObject = createQmlObject('import Qt 4.7; Rectangle {color: "red"; width: 20; height: 20}', - targetItem, "dynamicSnippet1"); - \endcode - - This function is intended for use inside QML only. It is intended to behave - 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, 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, - for example from a QML file, consider the createComponent() function - instead. 'New components' refers to external QML files that have not yet - been loaded, and so it is safe to use createQmlObject to load built-in - components. + +\section2 Qt.createComponent(url file) + +This function takes the URL of a QML file as its only argument. It returns +a component object which can be used to create and load that QML file. + +Here is an example. Remember that QML files that might be loaded +over the network cannot be expected to be ready immediately. + +\snippet doc/src/snippets/declarative/componentCreation.js 0 +\codeline +\snippet doc/src/snippets/declarative/componentCreation.js 1 + +If you are certain the files will be local, you could simplify to: + +\snippet doc/src/snippets/declarative/componentCreation.js 2 + +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. +\c Component.createObject() returns the created object or \c null if there is an error. +If there is an error, \l {Component::errorsString()}{Component.errorsString()} describes +the error that occurred. + +If you want to just create an arbitrary string of QML, instead of +loading a QML file, consider the \l{Qt.createQmlObject(string qml, object parent, string filepath)}{Qt.createQmlObject()} function. + + +\section2 Qt.createQmlObject(string qml, object parent, string filepath) + +Creates a new object from the specified string of QML. It requires a +second argument, which is the id of an existing QML object to use as +the new object's parent. If a third argument is provided, this is used +for error reporting as the filepath that the QML came from. + +Example (where \c targetItem is the id of an existing QML item): + +\snippet doc/src/snippets/declarative/createQmlObject.qml 0 + +This function is intended for use inside QML only. It is intended to behave +similarly to eval, but for creating QML elements. + +Returns the created object, \c or null if there is an error. In the case of an +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 \c lineNumber, \c columnNumber, \c fileName and \c 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, +for example from a QML file, consider the \l{Qt.createComponent(url file)}{Qt.createComponent()} function +instead. 'New components' refers to external QML files that have not yet +been loaded, and so it is safe to use \c Qt.createQmlObject() to load built-in +components. \section1 XMLHttpRequest diff --git a/doc/src/declarative/integrating.qdoc b/doc/src/declarative/integrating.qdoc index 0051f09..1c07f8e 100644 --- a/doc/src/declarative/integrating.qdoc +++ b/doc/src/declarative/integrating.qdoc @@ -118,34 +118,34 @@ Here is an example. Suppose you have two classes, \c RedSquare and \c BlueCircle that both inherit from QGraphicsWidget: \c [graphicswidgets/redsquare.h] -\snippet doc/src/declarative/snippets/integrating/graphicswidgets/redsquare.h 0 +\snippet doc/src/snippets/declarative/graphicswidgets/redsquare.h 0 \c [graphicswidgets/bluecircle.h] -\snippet doc/src/declarative/snippets/integrating/graphicswidgets/bluecircle.h 0 +\snippet doc/src/snippets/declarative/graphicswidgets/bluecircle.h 0 Then, create a plugin by subclassing QDeclarativeExtensionPlugin, and register the types by calling qmlRegisterType(). Also export the plugin with Q_EXPORT_PLUGIN2. \c [graphicswidgets/shapesplugin.cpp] -\snippet doc/src/declarative/snippets/integrating/graphicswidgets/shapesplugin.cpp 0 +\snippet doc/src/snippets/declarative/graphicswidgets/shapesplugin.cpp 0 Now write a project file that creates the plugin: \c [graphicswidgets/graphicswidgets.pro] -\quotefile doc/src/declarative/snippets/integrating/graphicswidgets/graphicswidgets.pro +\quotefile doc/src/snippets/declarative/graphicswidgets/graphicswidgets.pro And add a \c qmldir file that includes the \c graphicswidgets plugin from the \c lib subdirectory (as defined in the project file): \c [graphicswidgets/qmldir] -\quotefile doc/src/declarative/snippets/integrating/graphicswidgets/qmldir +\quotefile doc/src/snippets/declarative/graphicswidgets/qmldir Now, we can write a QML file that uses the \c RedSquare and \c BlueCircle widgets. (As an example, we can also create \c QGraphicsWidget items if we import the \c Qt.widgets module.) \c [main.qml] -\quotefile doc/src/declarative/snippets/integrating/graphicswidgets/main.qml +\quotefile doc/src/snippets/declarative/graphicswidgets/main.qml Here is a screenshot of the result: diff --git a/doc/src/declarative/qtbinding.qdoc b/doc/src/declarative/qtbinding.qdoc index d024ff2..7d696d7 100644 --- a/doc/src/declarative/qtbinding.qdoc +++ b/doc/src/declarative/qtbinding.qdoc @@ -97,17 +97,17 @@ The following example shows how to expose a background color to a QML file throu \row \o \c {// main.cpp} -\snippet doc/src/declarative/snippets/qtbinding/contextproperties/main.cpp 0 +\snippet doc/src/snippets/declarative/qtbinding/contextproperties/main.cpp 0 \o \c {// main.qml} -\snippet doc/src/declarative/snippets/qtbinding/contextproperties/main.qml 0 +\snippet doc/src/snippets/declarative/qtbinding/contextproperties/main.qml 0 \endtable Or, if you want \c main.cpp to create the component without showing it in a QDeclarativeView, you could create an instance of QDeclarativeContext using QDeclarativeEngine::rootContext() instead: -\snippet doc/src/declarative/snippets/qtbinding/contextproperties/main.cpp 1 +\snippet doc/src/snippets/declarative/qtbinding/contextproperties/main.cpp 1 Context properties work just like normal properties in QML bindings - if the \c backgroundColor context property in this example was changed to red, the component object instances would @@ -135,15 +135,15 @@ allow QML to set values. The following example creates a \c CustomPalette object, and sets it as the \c palette context property. -\snippet doc/src/declarative/snippets/qtbinding/custompalette/custompalette.h 0 +\snippet doc/src/snippets/declarative/qtbinding/custompalette/custompalette.h 0 -\snippet doc/src/declarative/snippets/qtbinding/custompalette/main.cpp 0 +\snippet doc/src/snippets/declarative/qtbinding/custompalette/main.cpp 0 The QML that follows references the palette object, and its properties, to set the appropriate background and text colors. When the window is clicked, the palette's text color is changed, and the window text will update accordingly. -\snippet doc/src/declarative/snippets/qtbinding/custompalette/main.qml 0 +\snippet doc/src/snippets/declarative/qtbinding/custompalette/main.qml 0 To detect when a C++ property value - in this case the \c CustomPalette's \c text property - changes, the property must have a corresponding NOTIFY signal. The NOTIFY signal specifies a signal @@ -185,12 +185,12 @@ This example toggles the "Stopwatch" object on/off when the MouseArea is clicked \row \o \c {// main.cpp} -\snippet doc/src/declarative/snippets/qtbinding/stopwatch/stopwatch.h 0 -\snippet doc/src/declarative/snippets/qtbinding/stopwatch/main.cpp 0 +\snippet doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.h 0 +\snippet doc/src/snippets/declarative/qtbinding/stopwatch/main.cpp 0 \o \c {// main.qml} -\snippet doc/src/declarative/snippets/qtbinding/stopwatch/main.qml 0 +\snippet doc/src/snippets/declarative/qtbinding/stopwatch/main.qml 0 \endtable @@ -258,16 +258,16 @@ QML content can be loaded from \l {The Qt Resource System} using the \e qrc: URL For example: \c [project/example.qrc] -\quotefile doc/src/declarative/snippets/qtbinding/resources/example.qrc +\quotefile doc/src/snippets/declarative/qtbinding/resources/example.qrc \c [project/project.pro] -\quotefile doc/src/declarative/snippets/qtbinding/resources/resources.pro +\quotefile doc/src/snippets/declarative/qtbinding/resources/resources.pro \c [project/main.cpp] -\snippet doc/src/declarative/snippets/qtbinding/resources/main.cpp 0 +\snippet doc/src/snippets/declarative/qtbinding/resources/main.cpp 0 \c [project/main.qml] -\snippet doc/src/declarative/snippets/qtbinding/resources/main.qml 0 +\snippet doc/src/snippets/declarative/qtbinding/resources/main.qml 0 */ diff --git a/doc/src/snippets/declarative/Sprite.qml b/doc/src/snippets/declarative/Sprite.qml new file mode 100644 index 0000000..6670703 --- /dev/null +++ b/doc/src/snippets/declarative/Sprite.qml @@ -0,0 +1,3 @@ +import Qt 4.7 + +Rectangle { width: 80; height: 50; color: "red" } diff --git a/doc/src/snippets/declarative/componentCreation.js b/doc/src/snippets/declarative/componentCreation.js new file mode 100644 index 0000000..be928f0 --- /dev/null +++ b/doc/src/snippets/declarative/componentCreation.js @@ -0,0 +1,51 @@ +//![0] +var component; +var sprite; + +function finishCreation() { + if (component.status == Component.Ready) { + sprite = component.createObject(); + if (sprite == null) { + // Error Handling + } else { + sprite.parent = appWindow; + sprite.x = 100; + sprite.y = 100; + // ... + } + } else if (component.status == Component.Error) { + // Error Handling + console.log("Error loading component:", component.errorsString()); + } +} +//![0] + +function createSpriteObjects() { + +//![1] +component = Qt.createComponent("Sprite.qml"); +if (component.status == Component.Ready) + finishCreation(); +else + component.statusChanged.connect(finishCreation); +//![1] + +//![2] +component = Qt.createComponent("Sprite.qml"); +sprite = component.createObject(); + +if (sprite == null) { + // Error Handling + console.log("Error loading component:", component.errorsString()); +} else { + sprite.parent = appWindow; + sprite.x = 100; + sprite.y = 100; + // ... +} +//![2] + +} + +createSpriteObjects(); + diff --git a/doc/src/snippets/declarative/createComponent.qml b/doc/src/snippets/declarative/createComponent.qml new file mode 100644 index 0000000..c4a1617 --- /dev/null +++ b/doc/src/snippets/declarative/createComponent.qml @@ -0,0 +1,9 @@ +import Qt 4.7 +import "componentCreation.js" as MyModule + +Rectangle { + id: appWindow + width: 300; height: 300 + + Component.onCompleted: MyModule.createSpriteObjects(); +} diff --git a/doc/src/snippets/declarative/createQmlObject.qml b/doc/src/snippets/declarative/createQmlObject.qml new file mode 100644 index 0000000..6b331c4 --- /dev/null +++ b/doc/src/snippets/declarative/createQmlObject.qml @@ -0,0 +1,18 @@ +import Qt 4.7 + +Rectangle { + id: targetItem + property QtObject newObject + + width: 100 + height: 100 + + function createIt() { +//![0] +newObject = Qt.createQmlObject('import Qt 4.7; Rectangle {color: "red"; width: 20; height: 20}', + targetItem, "dynamicSnippet1"); +//![0] + } + + Component.onCompleted: createIt() +} diff --git a/doc/src/declarative/snippets/integrating/graphicswidgets/bluecircle.h b/doc/src/snippets/declarative/graphicswidgets/bluecircle.h index 73d66b7..73d66b7 100644 --- a/doc/src/declarative/snippets/integrating/graphicswidgets/bluecircle.h +++ b/doc/src/snippets/declarative/graphicswidgets/bluecircle.h diff --git a/doc/src/declarative/snippets/integrating/graphicswidgets/graphicswidgets.pro b/doc/src/snippets/declarative/graphicswidgets/graphicswidgets.pro index 21c8a37..21c8a37 100644 --- a/doc/src/declarative/snippets/integrating/graphicswidgets/graphicswidgets.pro +++ b/doc/src/snippets/declarative/graphicswidgets/graphicswidgets.pro diff --git a/doc/src/declarative/snippets/integrating/graphicswidgets/main.qml b/doc/src/snippets/declarative/graphicswidgets/main.qml index ffcf79d..ffcf79d 100644 --- a/doc/src/declarative/snippets/integrating/graphicswidgets/main.qml +++ b/doc/src/snippets/declarative/graphicswidgets/main.qml diff --git a/doc/src/declarative/snippets/integrating/graphicswidgets/qmldir b/doc/src/snippets/declarative/graphicswidgets/qmldir index f94dad2..f94dad2 100644 --- a/doc/src/declarative/snippets/integrating/graphicswidgets/qmldir +++ b/doc/src/snippets/declarative/graphicswidgets/qmldir diff --git a/doc/src/declarative/snippets/integrating/graphicswidgets/redsquare.h b/doc/src/snippets/declarative/graphicswidgets/redsquare.h index 3050662..3050662 100644 --- a/doc/src/declarative/snippets/integrating/graphicswidgets/redsquare.h +++ b/doc/src/snippets/declarative/graphicswidgets/redsquare.h diff --git a/doc/src/declarative/snippets/integrating/graphicswidgets/shapesplugin.cpp b/doc/src/snippets/declarative/graphicswidgets/shapesplugin.cpp index 4c18ef3..4c18ef3 100644 --- a/doc/src/declarative/snippets/integrating/graphicswidgets/shapesplugin.cpp +++ b/doc/src/snippets/declarative/graphicswidgets/shapesplugin.cpp diff --git a/doc/src/snippets/declarative/mouseregion.qml b/doc/src/snippets/declarative/mouseregion.qml index a464069..683770b 100644 --- a/doc/src/snippets/declarative/mouseregion.qml +++ b/doc/src/snippets/declarative/mouseregion.qml @@ -3,13 +3,21 @@ import Qt 4.7 Rectangle { width: 200; height: 100 Row { //! [0] -Rectangle { width: 100; height: 100; color: "green" - MouseArea { anchors.fill: parent; onClicked: { parent.color = 'red' } } +Rectangle { + width: 100; height: 100 + color: "green" + + MouseArea { + anchors.fill: parent + onClicked: { parent.color = 'red' } + } } //! [0] //! [1] Rectangle { - width: 100; height: 100; color: "green" + width: 100; height: 100 + color: "green" + MouseArea { anchors.fill: parent acceptedButtons: Qt.LeftButton | Qt.RightButton diff --git a/doc/src/declarative/snippets/qtbinding/contextproperties/contextproperties.pro b/doc/src/snippets/declarative/qtbinding/contextproperties/contextproperties.pro index 68eeaf2..68eeaf2 100644 --- a/doc/src/declarative/snippets/qtbinding/contextproperties/contextproperties.pro +++ b/doc/src/snippets/declarative/qtbinding/contextproperties/contextproperties.pro diff --git a/doc/src/declarative/snippets/qtbinding/contextproperties/main.cpp b/doc/src/snippets/declarative/qtbinding/contextproperties/main.cpp index 4073a6c..4073a6c 100644 --- a/doc/src/declarative/snippets/qtbinding/contextproperties/main.cpp +++ b/doc/src/snippets/declarative/qtbinding/contextproperties/main.cpp diff --git a/doc/src/declarative/snippets/qtbinding/contextproperties/main.qml b/doc/src/snippets/declarative/qtbinding/contextproperties/main.qml index 1053f73..1053f73 100644 --- a/doc/src/declarative/snippets/qtbinding/contextproperties/main.qml +++ b/doc/src/snippets/declarative/qtbinding/contextproperties/main.qml diff --git a/doc/src/declarative/snippets/qtbinding/custompalette/custompalette.h b/doc/src/snippets/declarative/qtbinding/custompalette/custompalette.h index d0d253a..d0d253a 100644 --- a/doc/src/declarative/snippets/qtbinding/custompalette/custompalette.h +++ b/doc/src/snippets/declarative/qtbinding/custompalette/custompalette.h diff --git a/doc/src/declarative/snippets/qtbinding/custompalette/custompalette.pro b/doc/src/snippets/declarative/qtbinding/custompalette/custompalette.pro index e6af0d0..e6af0d0 100644 --- a/doc/src/declarative/snippets/qtbinding/custompalette/custompalette.pro +++ b/doc/src/snippets/declarative/qtbinding/custompalette/custompalette.pro diff --git a/doc/src/declarative/snippets/qtbinding/custompalette/main.cpp b/doc/src/snippets/declarative/qtbinding/custompalette/main.cpp index dc651f6..dc651f6 100644 --- a/doc/src/declarative/snippets/qtbinding/custompalette/main.cpp +++ b/doc/src/snippets/declarative/qtbinding/custompalette/main.cpp diff --git a/doc/src/declarative/snippets/qtbinding/custompalette/main.qml b/doc/src/snippets/declarative/qtbinding/custompalette/main.qml index f1a3b4f..f1a3b4f 100644 --- a/doc/src/declarative/snippets/qtbinding/custompalette/main.qml +++ b/doc/src/snippets/declarative/qtbinding/custompalette/main.qml diff --git a/doc/src/declarative/snippets/qtbinding/resources/example.qrc b/doc/src/snippets/declarative/qtbinding/resources/example.qrc index 5e49415..5e49415 100644 --- a/doc/src/declarative/snippets/qtbinding/resources/example.qrc +++ b/doc/src/snippets/declarative/qtbinding/resources/example.qrc diff --git a/doc/src/declarative/snippets/qtbinding/resources/images/background.png b/doc/src/snippets/declarative/qtbinding/resources/images/background.png index e69de29..e69de29 100644 --- a/doc/src/declarative/snippets/qtbinding/resources/images/background.png +++ b/doc/src/snippets/declarative/qtbinding/resources/images/background.png diff --git a/doc/src/declarative/snippets/qtbinding/resources/main.cpp b/doc/src/snippets/declarative/qtbinding/resources/main.cpp index 5459b9e..5459b9e 100644 --- a/doc/src/declarative/snippets/qtbinding/resources/main.cpp +++ b/doc/src/snippets/declarative/qtbinding/resources/main.cpp diff --git a/doc/src/declarative/snippets/qtbinding/resources/main.qml b/doc/src/snippets/declarative/qtbinding/resources/main.qml index dfe923f..dfe923f 100644 --- a/doc/src/declarative/snippets/qtbinding/resources/main.qml +++ b/doc/src/snippets/declarative/qtbinding/resources/main.qml diff --git a/doc/src/declarative/snippets/qtbinding/resources/resources.pro b/doc/src/snippets/declarative/qtbinding/resources/resources.pro index cc01ee1..cc01ee1 100644 --- a/doc/src/declarative/snippets/qtbinding/resources/resources.pro +++ b/doc/src/snippets/declarative/qtbinding/resources/resources.pro diff --git a/doc/src/declarative/snippets/qtbinding/stopwatch/main.cpp b/doc/src/snippets/declarative/qtbinding/stopwatch/main.cpp index 537a288..537a288 100644 --- a/doc/src/declarative/snippets/qtbinding/stopwatch/main.cpp +++ b/doc/src/snippets/declarative/qtbinding/stopwatch/main.cpp diff --git a/doc/src/declarative/snippets/qtbinding/stopwatch/main.qml b/doc/src/snippets/declarative/qtbinding/stopwatch/main.qml index 2efa542..2efa542 100644 --- a/doc/src/declarative/snippets/qtbinding/stopwatch/main.qml +++ b/doc/src/snippets/declarative/qtbinding/stopwatch/main.qml diff --git a/doc/src/declarative/snippets/qtbinding/stopwatch/stopwatch.cpp b/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.cpp index 4954a5f..4954a5f 100644 --- a/doc/src/declarative/snippets/qtbinding/stopwatch/stopwatch.cpp +++ b/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.cpp diff --git a/doc/src/declarative/snippets/qtbinding/stopwatch/stopwatch.h b/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.h index 8d17121..8d17121 100644 --- a/doc/src/declarative/snippets/qtbinding/stopwatch/stopwatch.h +++ b/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.h diff --git a/doc/src/declarative/snippets/qtbinding/stopwatch/stopwatch.pro b/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.pro index d803e6a..d803e6a 100644 --- a/doc/src/declarative/snippets/qtbinding/stopwatch/stopwatch.pro +++ b/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.pro |