summaryrefslogtreecommitdiffstats
path: root/doc/src/declarative
diff options
context:
space:
mode:
Diffstat (limited to 'doc/src/declarative')
-rw-r--r--doc/src/declarative/animation.qdoc25
-rw-r--r--doc/src/declarative/components.qdoc92
-rw-r--r--doc/src/declarative/elements.qdoc8
-rw-r--r--doc/src/declarative/extending-examples.qdoc309
-rw-r--r--doc/src/declarative/extending.qdoc881
-rw-r--r--doc/src/declarative/qmlforcpp.qdoc61
-rw-r--r--doc/src/declarative/qmlformat.qdoc6
-rw-r--r--doc/src/declarative/qtdeclarative.qdoc6
-rw-r--r--doc/src/declarative/tutorial3.qdoc32
9 files changed, 1227 insertions, 193 deletions
diff --git a/doc/src/declarative/animation.qdoc b/doc/src/declarative/animation.qdoc
index f17f5c9..57881a8 100644
--- a/doc/src/declarative/animation.qdoc
+++ b/doc/src/declarative/animation.qdoc
@@ -25,7 +25,7 @@ Other Features:
\o Animation synchronization
\endlist
-The simplest form of animation is using \l NumericAnimation
+The simplest form of animation is using \l NumberAnimation
The following example creates a bouncing effect:
\code
@@ -40,9 +40,9 @@ Rect {
y: SequentialAnimation {
running: true
repeat: true
- NumericAnimation { to: 200-img.height; easing: "easeOutBounce"; duration: 2000 }
+ NumberAnimation { to: 200-img.height; easing: "easeOutBounce"; duration: 2000 }
PauseAnimation { duration: 1000 }
- NumericAnimation { to: 0; easing: "easeOutQuad"; duration: 1000 }
+ NumberAnimation { to: 0; easing: "easeOutQuad"; duration: 1000 }
}
}
}
@@ -89,15 +89,13 @@ Item {
states: [
State {
name: "moved"
- SetProperty {
+ SetProperties {
target: myrect
- property: "x"
- value: 50
+ x: 50
}
- SetProperty {
+ SetProperties {
target: myrect
- property: "y"
- value: 50
+ y: 50
}
}
]
@@ -113,7 +111,7 @@ For the previous example, a transition could describe how \c myrect moved from i
\code
transitions: [
Transition {
- NumericAnimation {
+ NumberAnimation {
properties: "x,y"
easing: "easeOutBounce"
duration: 200
@@ -132,7 +130,7 @@ Transition {
}
\endcode
-Transitions can happen in parallel, in sequence, or in any combination of the two:;
+Transitions can happen in parallel, in sequence, or in any combination of the two:
\code
Transition {
@@ -141,19 +139,20 @@ Transition {
reversible: true
SequentialAnimation {
ColorAnimation {
+ property: "color"
duration: 1000
}
PauseAnimation {
duration: 1000
}
ParallelAnimation {
- NumericAnimation {
+ NumberAnimation {
duration: 1000
easing: "easeOutBounce"
target: box1
properties: "x,y"
}
- NumericAnimation {
+ NumberAnimation {
duration: 1000
target: box2
properties: "x,y"
diff --git a/doc/src/declarative/components.qdoc b/doc/src/declarative/components.qdoc
deleted file mode 100644
index d7a4ba6..0000000
--- a/doc/src/declarative/components.qdoc
+++ /dev/null
@@ -1,92 +0,0 @@
-/*!
-\page components.html
-\target components
-\title Components
-
-A \bold component is a reusable, encapsulated Qml element with a well-defined interface.
-
-Writing and using components allows you to:
-\list
-\o Reuse sections of Qml without copy-and-paste.
-\o Have consistent Look and Feel between different parts of your UI.
-\o Create new Qml elements without writing a new C++ class. (See \l {cppitem}{Creating Qml elements in C++})
-\endlist
-
-Components are placed in \e <Name>.qml files, allowing \e <Name> to then be used as a tag
-elsewhere. For example, if you have a Slider.qml file, you can then use \c {Slider { ... }} to
-make a slider, just as if it was a built-in type.
-
-Components may be collected into \l {qmlmodules}{modules}.
-
-\section1 Example: Creating a MyButton Component
-
-This example describes how to create a component from an existing snippet of Qml.
-
-Assume you have an existing UI with a single 'Save' button, defined as follows:
-
-\code
-Image {
- source: "pics/button-background.png"
- Text {
- text: "Save"
- anchors.horizontalCenter: parent.horizontalCenter
- anchors.verticalCenter: parent.verticalCenter
- }
- MouseRegion {
- anchors.fill: parent
- onClick: { saveData() }
- }
-}
-\endcode
-
-For the next release, you plan to add 'Cancel' and 'Reset' buttons. Rather than copying and pasting the above markup, you can create a component:
-
-\list 1
-\o Create a file called MyButton.qml, and copy the relevant Qml snippet into that file.
-\o Make some minor changes to define the component's interface:
-
-\code
-Image {
- property string label
- signal clicked
- source: "pics/button-background.png"
- Text {
- text: parent.label
- anchors.horizontalCenter: parent.horizontalCenter
- anchors.verticalCenter: parent.verticalCenter
- }
- MouseRegion {
- anchors.fill: parent
- onClick: { parent.click.emit() }
- }
-}
-\endcode
-
-The \a label property and \a click signal that were added effectively become part of the 'public API' of the MyButton component. In a similar manner, the Text and MouseRegion elements become invisible to anyone using the component. Note that the Text element now binds in its data from \a label, and the MouseRegion emits a generic signal.
-
-\o The component can now be used elsewhere as MyButton:
-
-\code
-MyButton { label: "Save"; onClicked: saveData() }
-...
-MyButton { label: "Cancel"; onClicked: cancelData() }
-...
-MyButton { label: "Reset"; onClicked: resetData() }
-\endcode
-
-\endlist
-
-\section1 Placing .qml Files
-
-When one component refers to a another, the second must be found either in the same directory
-as the first, or in a directory imported using the \c import statement:
-
-\code
-import "library"
-\endcode
-
-\section1 Namespaces
-
-Namespaces for QML will be supported in Qt 4.6.
-
-*/
diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc
index 35d746b..eda9079 100644
--- a/doc/src/declarative/elements.qdoc
+++ b/doc/src/declarative/elements.qdoc
@@ -18,7 +18,6 @@ The following table lists the Qml elements provided by the Qt Declarative module
\o
\list
\o \l State
-\o \l SetProperty
\o \l SetProperties
\o \l ParentChange
\o \l RunScript
@@ -26,9 +25,9 @@ The following table lists the Qml elements provided by the Qt Declarative module
\o
\list
-\o \l NumericAnimation
+\o \l PropertyAnimation
+\o \l NumberAnimation
\o \l ColorAnimation
-\o \l VariantAnimation
\o \l PauseAnimation
\o \l SequentialAnimation
\o \l ParallelAnimation
@@ -43,7 +42,7 @@ The following table lists the Qml elements provided by the Qt Declarative module
\list
\o \l Bind
\o \l ListModel
-\o \l XmlListModel
+\o \l XmlListModel and XmlRole
\o \l SqlQuery, \l SqlConnection, and \l SqlBind
\o \l DateTimeFormatter
\o \l NumberFormatter
@@ -140,6 +139,7 @@ The following table lists the Qml elements provided by the Qt Declarative module
\o
\list
+\o \l Scale
\o \l Rotation
\o \l Squish
\o \l Rotation3D
diff --git a/doc/src/declarative/extending-examples.qdoc b/doc/src/declarative/extending-examples.qdoc
new file mode 100644
index 0000000..4fc1bee
--- /dev/null
+++ b/doc/src/declarative/extending-examples.qdoc
@@ -0,0 +1,309 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+\example declarative/extending/adding
+\title Extending QML - Adding Types Example
+
+The Adding Types Example shows how to add a new element type, \c Person, to QML.
+The \c Person type can be used from QML like this:
+
+\snippet examples/declarative/extending/adding/example.qml 0
+
+\section1 Declare the Person class
+
+All QML elements map to C++ types. Here we declare a basic C++ Person class
+with the two properties we want accessible on the QML type - name and shoeSize.
+Although in this example we use the same name for the C++ class as the QML
+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
+
+The Person class implementation is quite basic. The property accessors simply
+return members of the object instance.
+
+The implementation must also include the QML_DEFINE_TYPE() macro. This macro
+registers the Person class with QML, and defines the mapping between the C++
+and QML class names.
+
+\section1 Running the example
+
+The main.cpp file in the example includes a simple shell application that
+loads and runs the QML snippet shown at the beginning of this page.
+*/
+
+/*!
+\example declarative/extending/properties
+\title Extending QML - Object and List Property Types Example
+
+This example builds on:
+\list
+\o \l {Extending QML - Adding Types Example}
+\endlist
+
+The Object and List Property Types example shows how to add object and list
+properties in QML. This example adds a BirthdayParty element that specifies
+a birthday party, consisting of a celebrant and a list of guests. People are
+specified using the People QML type built in the previous example.
+
+\snippet examples/declarative/extending/properties/example.qml 0
+
+\section1 Declare the BirthdayParty
+
+The BirthdayParty class is declared like this:
+
+\snippet examples/declarative/extending/properties/birthdayparty.h 0
+\snippet examples/declarative/extending/properties/birthdayparty.h 1
+\snippet examples/declarative/extending/properties/birthdayparty.h 2
+\snippet examples/declarative/extending/properties/birthdayparty.h 3
+
+The class contains a member to store the celebrant object, and also a
+QmlConcreteList<Person *> member.
+
+In QML, the type of a list properties - and the guests property is a list of
+people - are all of type QmlList<T *>*. QmlList is an abstract list interface
+that allows a developer to react to QML accessing and modifying the contents of
+the list. This is useful for implementing "virtual lists" or other advanced
+scenarios, but can't be used directly for the common case of just wanting a
+regular list of things. For this a concrete implementation, QmlConcreteList, is
+provided and that is used here.
+
+\section2 Define the BirthdayParty
+
+The implementation of BirthdayParty property accessors is straight forward.
+
+\snippet examples/declarative/extending/properties/birthdayparty.cpp 0
+
+\section1 Running the example
+
+The main.cpp file in the example includes a simple shell application that
+loads and runs the QML snippet shown at the beginning of this page.
+*/
+
+/*!
+\example declarative/extending/coercion
+\title Extending QML - Inheritance and Coercion Example
+
+This example builds on:
+\list
+\o \l {Extending QML - Object and List Property Types Example}
+\o \l {Extending QML - Adding Types Example}
+\endlist
+
+The Inheritance and Coercion Example shows how to use base classes to assign
+elements of more than one type to a property. It specializes the Person element
+developed in the previous examples into two elements - a \c Boy and a \c Girl.
+
+\snippet examples/declarative/extending/coercion/example.qml 0
+
+\section1 Declare Boy and Girl
+
+\snippet examples/declarative/extending/coercion/person.h 0
+
+The Person class remains unaltered in this example and the Boy and Girl C++
+classes are trivial extensions of it. As an example, the inheritance used here
+is a little contrived, but in real applications it is likely that the two
+extensions would add additional properties or modify the Person classes
+behavior.
+
+\section2 Define People as a base class
+
+The implementation of the People class itself has not changed since the the
+previous example. However, as we have repurposed the People class as a common
+base for Boy and Girl, we want to prevent it from being instantiated from QML
+directly - an explicit Boy or Girl should be instantiated instead.
+
+\snippet examples/declarative/extending/coercion/person.cpp 0
+
+While we want to disallow instantiating Person from within QML, it still needs
+to be registered with the QML engine, so that it can be used as a property type
+and other types can be coerced to it. To register a type, without defining a
+named mapping into QML, we use the QML_DEFINE_NOCREATE_TYPE() macro instead of
+the QML_DEFINE_TYPE() macro used previously.
+
+\section2 Define Boy and Girl
+
+The implementation of Boy and Girl are trivial.
+
+\snippet examples/declarative/extending/coercion/person.cpp 1
+
+All that is necessary is to implement the constructor, and to register the types
+and their QML name with the QML engine.
+
+\section1 Running the example
+
+The BirthdayParty element has not changed since the previous example. The
+celebrant and guests property still use the People type.
+
+\snippet examples/declarative/extending/coercion/birthdayparty.h 0
+
+However, as all three types, Person, Boy and Girl, have been registered with the
+QML system, on assignment QML automatically (and type-safely) converts the Boy
+and Girl objects into a Person.
+
+The main.cpp file in the example includes a simple shell application that
+loads and runs the QML snippet shown at the beginning of this page.
+*/
+
+/*!
+\example declarative/extending/default
+\title Extending QML - Default Property Example
+
+This example builds on:
+\list
+\o \l {Extending QML - Inheritance and Coercion Example}
+\o \l {Extending QML - Object and List Property Types Example}
+\o \l {Extending QML - Adding Types Example}
+\endlist
+
+The Default Property Example is a minor modification of the
+\l {Extending QML - Inheritance and Coercion Example} that simplifies the
+specification of a BirthdayParty through the use of a default property.
+
+\snippet examples/declarative/extending/default/example.qml 0
+
+\section1 Declaring the BirthdayParty class
+
+The only difference between this example and the last, is the addition of the
+\c DefaultProperty class info annotation.
+
+\snippet examples/declarative/extending/default/birthdayparty.h 0
+
+The default property specifies the property to assign to whenever an explicit
+property is not specified, in the case of the BirthdayParty element the guest
+property. It is purely a syntactic simplification, the behavior is identical
+to specifying the property by name, but it can add a more natural feel in many
+situations. The default property must be either an object or list property.
+
+\section1 Running the example
+
+The main.cpp file in the example includes a simple shell application that
+loads and runs the QML snippet shown at the beginning of this page.
+*/
+
+/*!
+\example declarative/extending/grouped
+\title Extending QML - Grouped Properties Example
+
+This example builds on:
+\list
+\o \l {Extending QML - Default Property Example}
+\o \l {Extending QML - Inheritance and Coercion Example}
+\o \l {Extending QML - Object and List Property Types Example}
+\o \l {Extending QML - Adding Types Example}
+\endlist
+
+*/
+
+/*!
+\example declarative/extending/grouped
+\title Extending QML - Attached Properties Example
+
+This example builds on:
+\list
+\o \l {Extending QML - Grouped Properties Example}
+\o \l {Extending QML - Default Property Example}
+\o \l {Extending QML - Inheritance and Coercion Example}
+\o \l {Extending QML - Object and List Property Types Example}
+\o \l {Extending QML - Adding Types Example}
+\endlist
+
+*/
+
+/*!
+\example declarative/extending/signal
+\title Extending QML - Signal Support Example
+
+This example builds on:
+\list
+\o \l {Extending QML - Attached Properties Example}
+\o \l {Extending QML - Grouped Properties Example}
+\o \l {Extending QML - Default Property Example}
+\o \l {Extending QML - Inheritance and Coercion Example}
+\o \l {Extending QML - Object and List Property Types Example}
+\o \l {Extending QML - Adding Types Example}
+\endlist
+
+*/
+
+/*!
+\example declarative/extending/valuesource
+\title Extending QML - Property Value Source Example
+
+This example builds on:
+\list
+\o \l {Extending QML - Signal Support Example}
+\o \l {Extending QML - Attached Properties Example}
+\o \l {Extending QML - Grouped Properties Example}
+\o \l {Extending QML - Default Property Example}
+\o \l {Extending QML - Inheritance and Coercion Example}
+\o \l {Extending QML - Object and List Property Types Example}
+\o \l {Extending QML - Adding Types Example}
+\endlist
+
+*/
+
+/*!
+\example declarative/extending/binding
+\title Extending QML - Binding Example
+
+This example builds on:
+\list
+\o \l {Extending QML - Property Value Source Example}
+\o \l {Extending QML - Signal Support Example}
+\o \l {Extending QML - Attached Properties Example}
+\o \l {Extending QML - Grouped Properties Example}
+\o \l {Extending QML - Default Property Example}
+\o \l {Extending QML - Inheritance and Coercion Example}
+\o \l {Extending QML - Object and List Property Types Example}
+\o \l {Extending QML - Adding Types Example}
+\endlist
+
+*/
diff --git a/doc/src/declarative/extending.qdoc b/doc/src/declarative/extending.qdoc
new file mode 100644
index 0000000..ac3dc41
--- /dev/null
+++ b/doc/src/declarative/extending.qdoc
@@ -0,0 +1,881 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+\page qml-extending.html
+\title Extending QML
+
+The QML syntax declaratively describes how to construct an in memory object
+tree. In Qt, QML is mainly used to describe a visual scene graph, but it is
+not conceptually limited to this: the QML format is an abstract description of
+any object tree. All the QML element types included in Qt are implemented using
+the C++ extension mechanisms describe on this page. Programmers can use these
+APIs to add new types that interact with the existing Qt types, or to repurpose
+QML for their own independent use.
+
+\tableofcontents
+
+\section1 Adding Types
+
+\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
+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.
+
+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 made available to QML using these two macros:
+
+\quotation
+\code
+#define QML_DECLARE_TYPE(T)
+#define QML_DEFINE_TYPE(T,QmlName)
+\endcode
+
+Register the C++ type \a T with the QML system, and make it available in QML
+under the name \a QmlName. \a T and \a QmlName may be the same.
+
+Generally the QML_DECLARE_TYPE() macro should be included immediately following
+the type declaration (usually in its header file), and the QML_DEFINE_TYPE()
+macro in the implementation file. QML_DEFINE_TYPE() must not be present in
+a header file.
+
+Type \a T must be a concrete type that inherits QObject and has a default
+constructor.
+\endquotation
+
+Once registered, all of the \l {Qt's Property System}{properties} of a supported
+type are available for use within QML. QML has intrinsic support for properties
+of these types:
+
+\list
+\o bool
+\o unsigned int, int
+\o float, double, qreal
+\o QString
+\o QUrl
+\o QColor
+\o QDate, QTime, QDateTime
+\o QPoint, QPointF
+\o QSize, QSizeF
+\o QRect, QRectF
+\o QVariant
+\endlist
+
+QML is typesafe. Attempting to assign an invalid value to a property will
+generate an error. For example, assuming the name property of the \c Person
+element had a type of QString, this would cause an error:
+
+\code
+Person {
+ // Will NOT work
+ name: 12
+}
+\endcode
+
+\l {Extending QML - Adding Types Example} shows the complete code used to create
+the \c Person type.
+
+\section1 Object and List Property Types
+
+\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.
+
+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
+pointers, lists of object points, and lists of Qt interface pointers. As QML
+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
+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
+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 macros are used instead:
+
+\quotation
+\code
+ #define QML_DECLARE_INTERFACE(T)
+ #define QML_DEFINE_INTERFACE(T)
+\endcode
+
+Register the C++ interface \a T with the QML system.
+
+Generally the QML_DECLARE_INTERFACE() macro should be included immediately
+following the interface declaration (usually in its header file), and the
+QML_DEFINE_INTERFACE() macro in an implementation file. QML_DEFINE_INTERFACE()
+must not be present in a header file.
+
+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
+of objects or Qt interfaces are also declared with the Q_PROPERTY() macro, just
+like other properties. List properties must have the type \c {QmlList<T *>*}.
+As with object properties, the type \a T must be registered with QML.
+
+The guest property declaration looks like this:
+
+\snippet examples/declarative/extending/properties/birthdayparty.h 2
+
+\l {Extending QML - Object and List Property Types Example} shows the complete
+code used to create the \c BirthdayParty type.
+
+\section1 Inheritance and Coercion
+
+\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.
+
+QML supports C++ inheritance heirarchies 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.
+
+To assign to a property, the property's type must have been registered with QML.
+Both the QML_DEFINE_TYPE() and QML_DEFINE_INTERFACE() macros 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 macros can be used:
+
+\quotation
+\code
+ #define QML_DECLARE_TYPE(T)
+ #define QML_DEFINE_NOCREATE_TYPE(T)
+\endcode
+
+Register the C++ type \a T with the QML system. QML_DEFINE_NOCREATE_TYPE()
+differs from QML_DEFINE_TYPE() in that it 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
+QML_DEFINE_NOCREATE_TYPE() macro in the implementation file.
+QML_DEFINE_NOCREATE_TYPE() must not be present in a header file.
+
+Type \a T must inherit QObject, but there are no restrictions on whether it is
+concrete or the signature of its constructor.
+\endquotation
+
+QML will automatically coerce C++ types when assigning to either an object
+property, or to a list property. Only if coercion fails does an assignment
+error occur.
+
+\l {Extending QML - Inheritance and Coercion Example} shows the complete
+code used to create the \c Boy and \c Girl types.
+
+\section1 Default Property
+
+\snippet examples/declarative/extending/default/example.qml 0
+
+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
+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.
+
+From C++, type designers mark the default property using a Q_CLASSINFO()
+annotation:
+
+\quotation
+\code
+Q_CLASSINFO("DefaultProperty", "property")
+\endcode
+
+Mark \a property as the class's default property. \a property must be either
+an object property, or a list property.
+
+A default property is optional. A derived class inherits its base class's
+default property, but may override it in its own declaration. \a property can
+refer to a property declared in the class itself, or a property inherited from a
+base class.
+\endquotation
+
+\l {Extending QML - Default Property Example} shows the complete code used to
+specify a default property.
+
+\section1 Grouped Properties
+
+\snippet examples/declarative/extending/grouped/example.qml 1
+
+The QML snippet shown above assigns a number properties to the \c Boy object,
+including four properties using the grouped property syntax.
+
+Grouped properties collect similar properties together into a single named
+block. Grouped properties can be used to present a nicer API to developers, and
+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:
+
+\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.
+
+Grouped property blocks may declared and accessed be recusively.
+
+\l {Extending QML - Grouped Properties Example} shows the complete code used to
+implement the \c shoe property grouping.
+
+\section1 Attached Properties
+
+\snippet examples/declarative/extending/attached/example.qml 1
+
+The QML snippet shown above assigns the rsvp property using the attached
+property syntax.
+
+Attached properties allow unrelated types to annotate other types with some
+additional properties, generally for their own use. Attached properties are
+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
+Box 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
+attachment object are those that become available for use as the attached
+property block.
+
+Any QML type can become an attaching type by declaring the
+\c qmlAttachedProperties() public function:
+
+\quotation
+\code
+static AttachedPropertiesType *qmlAttachedProperties(QObject *object)
+\endcode
+Return an attachment object, of type \a AttachedPropertiesType, for the
+attachee \a object instance. It is customary, though not strictly required, for
+the attachment object to be parented to \a object to prevent memory leaks.
+
+\a AttachedPropertiesType must be a QObject derived type. The properties on
+this type will be accessible through the attached properties syntax.
+
+This method will be called at most once for each attachee object instance. The
+QML engine will cache the returned instance pointer for subsequent attached
+property accesses. Consequently the attachment object may not be deleted until
+\a object is destroyed.
+\endquotation
+
+Conceptually, attached properties are a \e type exporting a set of additional
+properties that can be set on \e any other object instance. Attached properties
+cannot be limited to only attaching to a sub-set of object instances, although
+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:
+\code
+BirthdayParty {
+ Boy { BirthdayParty.rsvp: "2009-06-01" }
+}
+\endcode
+However, as a type cannot limit the instances to which the attachment object
+must attach, the following is also allowed, even though adding a birthday party
+rsvp in this context will have no effect.
+\code
+GraduationParty {
+ Boy { BirthdayParty.rsvp: "2009-06-01" }
+}
+\endcode
+
+From C++, including the attaching type implementation, the attachment object for
+an instance can be accessed using the following method:
+
+\quotation
+\code
+template<typename T>
+QObject *qmlAttachedPropertiesObject<T>(QObject *attachee, bool create = true);
+\endcode
+Returns the attachment object attached to \a attachee by the attaching type
+\a T. If type \a T is not a valid attaching type, this method always returns 0.
+
+If \a create is true, a valid attachment object will always be returned,
+creating it if it does not already exist. If \a create is false, the attachment
+object will only be returned if it has previously been created.
+\endquotation
+
+\l {Extending QML - Attached Properties Example} shows the complete code used to
+implement the rsvp attached property.
+
+\section1 Signal Support
+
+\snippet examples/declarative/extending/signal/example.qml 0
+\snippet examples/declarative/extending/signal/example.qml 1
+
+The QML snippet shown above associates the evaluation of a ECMAScript expression
+with the emission of a Qt signal.
+
+All Qt signals on a registered class become available as special "signal
+propeties" within QML to which the user can assign a single ECMAScript
+expression. The signal property's name is a transformed version of the Qt
+signal name: "on" is prepended, and the first letter of the signal name upper
+cased. For example, the signal used in the example above has the following
+C++ signature:
+
+\snippet examples/declarative/extending/signal/birthdayparty.h 0
+
+In classes with multiple signals with the same name, only the final signal
+is accessible as a signal property. Although QML provides an element,
+\l Connection, for accessing the other signals it is less elegant. For the best
+QML API, class developers should avoid overloading signal names.
+
+Signal parameters become accessible by name to the assigned script. An
+unnamed parameter cannot be accessed, so care should be taken to name all the
+signal parameters in the C++ class declaration. The intrinsic types
+listed in \l {Adding Types}, as well registered object types are permitted as
+signal parameter types. Using other types is not an error, but the parameter
+value will not be accessible from script.
+
+\l {Extending QML - Signal Support Example} shows the complete code used to
+implement the onPartyStarted signal property.
+
+\section1 Property Value Sources
+
+\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.
+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
+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
+"Happy Birthday".
+
+\snippet examples/declarative/extending/valuesource/birthdayparty.h 0
+
+Normally, assigning an object to a string property would not be allowed. In
+the case of a property value source, rather than assigning the object instance
+itself, the QML engine sets up an association between the value source and
+the property.
+
+Property value sources are special types that derive from the
+QmlPropertyValueSource base class. This base class contains a single method,
+QmlPropertyValueSource::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:
+
+\snippet examples/declarative/extending/valuesource/happybirthday.h 0
+\snippet examples/declarative/extending/valuesource/happybirthday.h 1
+\snippet examples/declarative/extending/valuesource/happybirthday.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
+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
+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.
+
+\section1 Property Binding
+
+\snippet examples/declarative/extending/binding/example.qml 0
+\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.
+
+Property binding is a core feature of QML. In addition to assigning literal
+values, property bindings allow the developer to assign an arbitrarily complex
+ECMAScript expression that may include dependencies on other property values.
+Whenever the expression's result changes - through a change in one of its
+constituent values - the expression is automatically reevaluated and
+the new result assigned to the property.
+
+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.
+
+Here is the celebrant property declaration:
+
+\snippet examples/declarative/extending/binding/birthdayparty.h 0
+
+The NOTIFY attribute is followed by a signal name. It is the responsibility of
+the class implementer to ensure that whenever the property's value changes, the
+NOTIFY signal is emitted. The signature of the NOTIFY signal is not important to QML.
+
+To prevent loops or excessive evaluation, developers should ensure that the
+signal is only emitted whenever the property's value is actually changed. If
+a property, or group of properties, is infrequently used it is permitted to use
+the same NOTIFY signal for several properties. This should be done with care to
+ensure that performance doesn't suffer.
+
+To keep QML reliable, if a property does not have a NOTIFY signal, it cannot be
+used in a binding expression. However, the property can still be assigned
+a binding as QML does not need to monitor the property for change in that
+scenario.
+
+Consider a custom type, \c TestElement, that has two properties, "a" and "b".
+Property "a" does not have a NOTIFY signal, and property "b" does have a NOTIFY
+signal.
+
+\code
+TestElement {
+ // This is OK
+ a: b
+}
+TestElement {
+ // Will NOT work
+ b: a
+}
+\endcode
+
+The presence of a NOTIFY signal does incur a small overhead. There are cases
+where a property's value is set at object construction time, and does not
+subsequently change. The most common case of this is when a type uses
+\l {Grouped Properties}, and the grouped property object is allocated once, and
+only freed when the object is deleted. In these cases, the CONSTANT attribute
+may be added to the property declaration instead of a NOTIFY signal.
+
+\snippet examples/declarative/extending/binding/person.h 0
+
+Extreme care must be taken here or applications using your type may misbehave.
+The CONSTANT attribute should only be used for properties whose value is set,
+and finalized, only in the class constructor. All other properties that want
+to be used in bindings should have a NOTIFY signal instead.
+
+\l {Extending QML - Binding Example} shows the BirthdayParty example updated to
+include NOTIFY signals for use in binding.
+
+\section1 Extension Objects
+
+\snippet examples/declarative/extending/extended/example.qml 0
+
+The QML snippet shown above adds a new property to an existing C++ type without
+modifying its source code.
+
+When integrating existing classes and technology into QML, their APIs will often
+need to be tweaked to fit better into the declarative environment. Although
+the best results are usually obtained by modifying the original classes
+directly, if this is either not possible or is complicated by some other
+concerns extension objects allow limited extension possibilities without
+direct modifications.
+
+Extension objects can only add properties.
+
+\section1 Optimization
+
+*/
+
+
+/*!
+\page qml-extending-types.html
+\title Extending types from QML
+
+Many of the elements available for use in QML are implemented in
+\l {QML for C++ Programmers}{C++}. These types are know as "core types". QML
+allows programmers to build new, fully functional elements without using C++.
+Existing core types can be extended, and new types defined entirely in the QML
+language.
+
+\tableofcontents
+
+\section1 Adding new properties
+
+New properties can be added to an existing type. These new properties are
+available for use within QML, and also appear as regular Qt properties on the
+C++ object, accessible through the regular property access mechanisms.
+
+Like all properties in QML, custom properties are typed. The type is used to
+define the property's behavior, and also determines the C++ type of the created
+Qt property. The following table shows the list of types available when
+declaring a new property, and the corresponding C++ type.
+
+\table
+\header \o QML Type Name \o C++ Type Name
+\row \o int \o int
+\row \o bool \o bool
+\row \o double \o double
+\row \o real \o double
+\row \o string \o QString
+\row \o url \o QUrl
+\row \o color \o QColor
+\row \o date \o QDate
+\row \o var \o QVariant
+\row \o variant \o QVariant
+\endtable
+
+QML supports two methods for adding a new property to a type - a new property
+definition, and a property alias.
+
+\section2 Property definitions
+
+Property definitions add a new property to an existing type. The storage of the
+property is managed by QML. The defined property may be read, written and bound
+to and from.
+
+The syntax for defining a new property is:
+\code
+ [default] property <type> <name>[: defaultValue]
+\endcode
+
+This declaration may appear anywhere within a type body, but it is customary to
+include it at the top. Attempting to declare two properties with the same name
+in the same type block is an error. However, a new property may reuse the name
+of an existing property on the type. This should be done with caution, as the
+existing property will be hidden, and become inaccessible.
+
+The <type> must be one of the QML type names shown in the above table.
+Additionally, an optional default value of the property can be provided. The
+default value is a convenient shortcut, but is behaviorally identical to doing
+it in two steps, like this:
+
+\code
+ // Use default value
+ property int myProperty: 10
+
+ // Longer, but behaviorally identical
+ property int myProperty
+ myProperty: 10
+\endcode
+
+If specified, the optional "default" attribute marks the new property as the
+types default property, overriding any existing default property. Using the
+default attribute twice in the same type block is an error.
+
+The following example shows how to declare a new "innerColor" property that
+controls the color of the inner rectangle.
+
+\code
+ Rect {
+ property color innerColor: "black"
+
+ color: "red"; width: 100; height: 100
+ Rect {
+ anchors.centeredIn: parent
+ width: parent.width - 10
+ height: parent.height - 10
+ color: innerColor
+ }
+ }
+\endcode
+
+\section2 Property aliases
+
+Property aliases are a more advanced form of property declaration. Unlike a
+property definition, that allocates a new, unique storage space for the
+property, a property alias connects the newly declared property (called the
+aliasing property) to an existing property (the aliased property). Read
+operations on the aliasing property act as read operations on the aliased
+property, and write operations on the aliasing property as write operations on
+the aliased property.
+
+A property alias declaration looks a lot like a property definition:
+\code
+ [default] property alias <name>: <alias reference>
+\endcode
+
+As the aliasing property has the same type as the aliased property, an explicit
+type is omitted, and the special "alias" keyword is used. Instead of a default
+value, a property alias includes a compulsary alias reference. The alias
+reference is used to locate the aliased property. While similar to a property
+binding, the alias reference syntax is highly restricted.
+
+An alias reference takes the form
+\code
+ <Id>.<property>
+\endcode
+where <Id> must refer to an object id within the same component as the type
+declaring the alias, and <property> refers to a property on this object. The
+alias reference syntax may become more flexibly in future releases.
+
+Here is the property definition example rewritten to use property aliases.
+\code
+Rect {
+ property alias innerColor: InnerRect.color
+
+ color: "red"; width: 100; height: 100
+ Rect {
+ id: InnerRect
+ anchors.centeredIn: parent
+ width: parent.width - 10
+ height: parent.height - 10
+ color: "black"
+ }
+}
+\endcode
+
+Aliases are most useful when \l {Defining new Components}. Consequently
+they have several apparent limitations that only make sense in this context.
+
+Aliases are only activated once the component specifying them is completed. The
+most obvious consequence of this is that the component itself cannot generally
+use the aliased property directly. For example, this will not work:
+
+\code
+ // Does NOT work
+ property alias innerColor: InnerRect.color
+ innerColor: "black"
+\endcode
+
+This behavior is required to allow type developers to redefine the behavior
+of existing property names while continuing to use the existing behavior within
+the type they are building, something that is not possible with property
+definitions. In the example used so far, this could allows the developer to fix
+the external rectangle's color as "red" and redefine the "color" property to
+refer to the inner rectangle, like this:
+
+\code
+Rect {
+ property alias color: InnerRect.color
+
+ color: "red"; width: 100; height: 100
+ Rect {
+ id: InnerRect
+ anchors.centeredIn: parent
+ width: parent.width - 10
+ height: parent.height - 10
+ color: "black"
+ }
+}
+\endcode
+
+Users of this type would not be able to affect the color of the red rectangle,
+but would find using the "color" property, rather than the strange new
+"innerColor" property, much more familiar.
+
+A second, much less significant, consequence of the delayed activation of
+aliases is that an alias reference cannot refer to another aliasing property
+declared within the same component. This will not work:
+
+\code
+ // Does NOT work
+ id: Root
+ property alias innerColor: InnerRect.color
+ property alias innerColor2: Root.innerColor
+\endcode
+
+From outside the component, aliasing properties appear as regular Qt properties
+and consequently can be used in alias references.
+
+\section1 Adding new signals
+
+New signals can be added to an existing type. These new signals are available
+for use within QML, and also appear as regular Qt signals on the C++ object that
+can be used in Qt signal/slot connections.
+
+The syntax for defining a new signal is:
+\code
+signal <name>[([<type> <parameter name>[, ...]])]
+\endcode
+
+This declaration may appear anywhere within a type body, but it is customary to
+include it at the top. Attempting to declare two signals or methods with the
+same name in the same type block is an error. However, a new signal may reuse
+the name of an existing signal on the type. This should be done with caution,
+as the existing signal may be hidden and become inaccessible.
+
+The options for parameter types are the same as for property types (see
+\l {Adding new properties}. If this signal has no parameters, the parameter
+list may be omitted entirely.
+
+Here are three examples of signal declarations:
+\code
+ Item {
+ signal clicked
+ signal hovered()
+ signal performAction(string action, var actionArgument)
+ }
+\endcode
+
+\section1 Adding new methods
+
+New methods can be added to an existing type. These new methods are available
+for use within QML, and also appear as regular Qt slots on the C++ object that
+can be used in Qt signal/slot connections.
+
+\code
+function <name>([<parameter name>[, ...]]) { <body> }
+\endcode
+
+This declaration may appear anywhere within a type body, but it is customary to
+include it at the top. Attempting to declare two methods or signals with the
+same name in the same type block is an error. However, a new method may reuse
+the name of an existing method on the type. This should be done with caution,
+as the existing method may be hidden and become inaccessible.
+
+Methods parameters are not typed. In C++ these parameters are of type QVariant.
+The body of the method is written in JavaScript and may access the parameters by
+name.
+
+This example adds a new method that behaves like a child:
+\code
+Item {
+ function say(text) {
+ print("You said " + text);
+ }
+}
+\endcode
+
+\section1 Defining new Components
+
+A component is a reusable type with a well-defined interface built entirely in
+QML. Components appear as regular QML elements, and can be used interchangably
+with core types. Components allow developers to create new types to be reused
+in other projects without the use of C++. Components can also help to reduce
+duplication inside one project by limiting the need for large numbers of
+copy-and-pasted blocks.
+
+Any snippet of QML code can become a component, just by placing it in the file
+"<Name>.qml" where <Name> is the new element name, and begins with an uppercase
+letter. These QML files automatically become available as new QML element types
+to other QML components and applications in the same directory.
+
+For example, here we show how a component named "Box" is defined and used
+multiple times by an application.
+
+\table
+\row
+\o application.qml
+\code
+Rect {
+ width: 100; height: 400;
+ Box { x: 0; y: 0 }
+ Box { x: 0; y: 150 }
+ Box { x: 0; y: 300 }
+}
+\endcode
+\o Box.qml
+\code
+Rect {
+ width: 100; height: 100;
+ color: "blue"
+}
+\endcode
+\endtable
+
+Components may be collected into \l {Modules of Components} that gives the
+developer more freedom than just putting files in the same directory.
+
+\section2 Building reusable components
+
+A component type built to be reused by others must have a well defined
+interface. In QML, an interface consists of a defined collection of
+properties, signals and methods. Users of a component have access to all the
+properties, signals and methods defined on the root element of the component.
+
+In the component example above, the root element of the "Box" component is a
+Rect. As the Rect type has a "color" property, this property is accessible to
+users of the Box component. For example, the application.qml can be modified
+to show three different colored boxes like this:
+\code
+Rect {
+ width: 100; height: 400;
+ Box { x: 0; y: 0; color: "red"; }
+ Box { x: 0; y: 150; color: "yellow"; }
+ Box { x: 0; y: 300; color: "green"; }
+}
+\endcode
+
+As expected, adding additional properties to the root element of Box, makes them
+available externally. Here we add a "text" property:
+
+\table
+\row
+\o application.qml
+\code
+Rect {
+ width: 100; height: 400;
+ Box { x: 0; y: 0; color: "red"; text: "stop" }
+ Box { x: 0; y: 150; color: "yellow"; text: "slow" }
+ Box { x: 0; y: 300; color: "green"; text: "go" }
+}
+\endcode
+\o Box.qml
+\code
+Rect {
+ property alias text: MyText.text
+ width: 100; height: 100;
+ color: "blue"
+ Text {
+ id: MyText
+ anchors.centeredIn: parent
+ }
+}
+\endcode
+\endtable
+
+Methods and signals may be added in the same way.
+
+As all external methods, signals and properties are accessible to external
+users, developers should ensure that setting these properties does not have
+any undesirable side-effects. For most resiliance, root level properties should
+only be used for literal default values. When a root level property must be
+used inside the component - such as the children property - property aliases
+can be used to redirect this property to a "safe" location for external users.
+Try to think of the root level properties as being "owned" by the components
+user, rather than the component itself.
+*/
diff --git a/doc/src/declarative/qmlforcpp.qdoc b/doc/src/declarative/qmlforcpp.qdoc
index 4095071..38f5665 100644
--- a/doc/src/declarative/qmlforcpp.qdoc
+++ b/doc/src/declarative/qmlforcpp.qdoc
@@ -438,7 +438,7 @@
\code
Button {
id: MyButton
- onClicked: NumericAnimation {
+ onClicked: NumberAnimation {
target: MyButton
property: "x"
to: 100
@@ -555,73 +555,18 @@
\code
Rect {
- x: NumericAnimation { running: true; repeat; true; from: 0; to: 100; }
+ x: NumberAnimation { running: true; repeat; true; from: 0; to: 100; }
}
\endcode
Here the \c x property of the rectangle will be animated from 0 to 100.
- To support this, the NumericAnimation class inherits the
+ To support this, the NumberAnimation class inherits the
QmlPropertyValueSource class. If a type inherits this class and is assigned
to a property for which type assignment would otherwise fail (ie. the
property itself doesn't have a type of QmlPropertyValueSource *), the QML
engine will automatically set the property as the target of the value
source.
- \section1 Extending types in QML
-
- QML is designed to allow you to build fully working types without writing
- a line of C++ code. This is, for example, used extensively when designing
- applications using the Fluid UI primitives. To create new types, it is
- necessary to be able to define new signals, slots and properties in QML.
-
- In this example, a Button is extended to have an additional
- "text2" property (which always returns "Hello world!") and an additional
- signal "clicked2" that is also emitted when the button is clicked. Not
- a very useful extension, but an extension nonetheless.
-
- \table
- \row
- \o
- \code
- QmlEngine engine;
- QmlComponent component(&engine, qmlData);
- QObject *object = component.create();
- // Will print "Hello world!"
- qDebug() << object->property("text2");
- // Will be emitted whenever the button is clicked
- QObject::connect(object, SIGNAL(clicked2()), this, SLOT(...));
- \endcode
- \o
- \code
- Button {
- property string text2
- signal clicked2
-
- text: "Hello!"
- text2: "Hello world!"
- onClicked: clicked2.emit()
- }
- \endcode
- \endtable
-
- The general syntax for defining new properties and signals is:
-
- \list
- \o
- \code
- [default] property <type> <name> [: <default value>]
- \endcode
-
- Where type can be one of \e int, \e bool, \e double, \e real, \e string,
- \e color, \e date, \e var or \e variant.
-
- \o
- \code
- signal <name>
- \endcode
- Currently only parameterless signals are supported.
- \endlist
-
\section1 Parser Status
Generally using QML is a breeze - you implement your classes in C++, add
diff --git a/doc/src/declarative/qmlformat.qdoc b/doc/src/declarative/qmlformat.qdoc
new file mode 100644
index 0000000..fd22ab5
--- /dev/null
+++ b/doc/src/declarative/qmlformat.qdoc
@@ -0,0 +1,6 @@
+/*!
+ \page qmlformat.html
+ \title QML Format
+
+ Format reference here...
+*/
diff --git a/doc/src/declarative/qtdeclarative.qdoc b/doc/src/declarative/qtdeclarative.qdoc
index 4fe9994..c5d32fe 100644
--- a/doc/src/declarative/qtdeclarative.qdoc
+++ b/doc/src/declarative/qtdeclarative.qdoc
@@ -68,24 +68,26 @@
\o \l {qmlforcpp}{QML For C++ Programmers}
\endlist
- Core Features:
+ Core QML Features:
\list
\o \l {binding}{Data Binding}
\o \l {anchor-layout}{Layout Anchors}
\o \l {qmlanimation}{Animation}
\o \l {qmleffects}{Visual Effects}
- \o \l {components}{Components}
\o \l {qmlmodules}{Modules}
\o \l {qmlfocus}{Keyboard Focus}
+ \o \l {Extending types from QML}
\endlist
QML Reference:
\list
+ \o \l {QML Format}
\o \l {elements}{Qml Elements}
\endlist
C++ Reference:
\list
+ \o \l {Extending QML}
\o \l {qtbinding}{C++ Data Binding}
\o \l {cppitem}{C++ Components}
\endlist
diff --git a/doc/src/declarative/tutorial3.qdoc b/doc/src/declarative/tutorial3.qdoc
index 0b97e63..9ae56c1 100644
--- a/doc/src/declarative/tutorial3.qdoc
+++ b/doc/src/declarative/tutorial3.qdoc
@@ -28,16 +28,8 @@ Rect {
State {
name: "down"
when: MouseRegion.pressed == true
- SetProperty {
- target: HelloText
- property: "y"
- value: 160
- }
- SetProperty {
- target: HelloText
- property: "color"
- value: "red"
- }
+ SetProperties { target: HelloText; y: 160 }
+ SetProperties { target: HelloText color: "red" }
}
]
transitions: [
@@ -46,12 +38,12 @@ Rect {
toState: "down"
reversible: true
ParallelAnimation {
- NumericAnimation {
+ NumberAnimation {
properties: "y"
duration: 500
easing: "easeOutBounce"
}
- ColorAnimation { duration: 500 }
+ ColorAnimation { property: "color"; duration: 500 }
}
}
]
@@ -80,16 +72,8 @@ states: [
State {
name: "down"
when: MouseRegion.pressed == true
- SetProperty {
- target: HelloText
- property: "y"
- value: 160
- }
- SetProperty {
- target: HelloText
- property: "color"
- value: "red"
- }
+ SetProperties { target: HelloText; y: 160 }
+ SetProperties { target: HelloText; color: "red" }
}
]
\endcode
@@ -114,12 +98,12 @@ Because we want the same transition to be run in reverse when changing back from
\code
ParallelAnimation {
- NumericAnimation {
+ NumberAnimation {
properties: "y"
duration: 500
easing: "easeOutBounce"
}
- ColorAnimation { duration: 500 }
+ ColorAnimation { property: "color"; duration: 500 }
}
\endcode