summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2010-04-21 04:52:21 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2010-04-21 04:52:21 (GMT)
commitbb334b925483a9b8bda70e40cfae8a2d26e43757 (patch)
tree4d877771c2088fbd3b1ba8d43bf43d096357b252
parentd363b2ed7517dbbc8a54c02d8b606f4b52b54047 (diff)
parent045539e38b606814a3a3f5fb37f871f03fb2a53b (diff)
downloadQt-bb334b925483a9b8bda70e40cfae8a2d26e43757.zip
Qt-bb334b925483a9b8bda70e40cfae8a2d26e43757.tar.gz
Qt-bb334b925483a9b8bda70e40cfae8a2d26e43757.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7
-rw-r--r--doc/src/declarative/advtutorial.qdoc22
-rw-r--r--doc/src/declarative/codingconventions.qdoc1
-rw-r--r--doc/src/declarative/extending.qdoc375
-rw-r--r--src/declarative/graphicsitems/qdeclarativeflickable.cpp4
-rw-r--r--src/declarative/graphicsitems/qdeclarativegridview.cpp65
-rw-r--r--src/declarative/graphicsitems/qdeclarativegridview_p.h1
-rw-r--r--src/declarative/graphicsitems/qdeclarativelistview.cpp111
-rw-r--r--src/declarative/qml/qdeclarativebinding.cpp4
-rw-r--r--src/declarative/qml/qdeclarativepropertyvaluesource.cpp6
-rw-r--r--src/declarative/util/qdeclarativestateoperations.cpp5
-rw-r--r--tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp4
-rw-r--r--tests/auto/declarative/qdeclarativedebugclient/tst_qdeclarativedebugclient.cpp4
-rw-r--r--tests/auto/declarative/qdeclarativedebugservice/tst_qdeclarativedebugservice.cpp3
-rw-r--r--tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp6
-rw-r--r--tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp5
-rw-r--r--tools/qml/loggerwidget.cpp4
-rw-r--r--tools/qml/loggerwidget.h3
-rw-r--r--tools/qml/main.cpp57
18 files changed, 363 insertions, 317 deletions
diff --git a/doc/src/declarative/advtutorial.qdoc b/doc/src/declarative/advtutorial.qdoc
index 751bf00..c465da4 100644
--- a/doc/src/declarative/advtutorial.qdoc
+++ b/doc/src/declarative/advtutorial.qdoc
@@ -67,7 +67,7 @@ Tutorial chapters:
\list 1
\o \l {QML Advanced Tutorial 1 - Creating the Game Canvas and Blocks}{Creating the Game Canvas and Blocks}
-\o \l {QML Advanced Tutorial 2 - Populating the Game Canvas}{Populating the Game Canvas}}
+\o \l {QML Advanced Tutorial 2 - Populating the Game Canvas}{Populating the Game Canvas}
\o \l {QML Advanced Tutorial 3 - Implementing the Game Logic}{Implementing the Game Logic}
\o \l {QML Advanced Tutorial 4 - Finishing Touches}{Finishing Touches}
\endlist
@@ -83,10 +83,6 @@ directory.
\previouspage QML Advanced Tutorial
\nextpage QML Advanced Tutorial 2 - Populating the Game Canvas
-In this chapter:
-
-\tableofcontents
-
The files referenced on this page can be found in \c $QTDIR\examples\tutorials\samegame\samegame1.
\section2 Creating the application screen
@@ -109,7 +105,7 @@ is the \l SystemPalette item. This provides access to the Qt system palette
and is used to give the button a more native look-and-feel.
Notice the anchors for the \c Item, \c Button and \c Text elements are set using
-\l {Grouped Properties}{group notation} for readability.
+\l {codingconventions.html#Grouped-properties}{group notation} for readability.
\section2 Adding \c Button and \c Block components
@@ -152,10 +148,6 @@ elements to get started. Next, we will populate the game canvas with some blocks
\previouspage QML Advanced Tutorial 1 - Creating the Game Canvas and Blocks
\nextpage QML Advanced Tutorial 3 - Implementing the Game Logic
-In this chapter:
-
-\tableofcontents
-
The files referenced on this page can be found in \c $QTDIR\examples\tutorials\samegame\samegame2.
@@ -224,10 +216,6 @@ Now, we have a screen of blocks, and we can begin to add the game mechanics.
\previouspage QML Advanced Tutorial 2 - Populating the Game Canvas
\nextpage QML Advanced Tutorial 4 - Finishing Touches
-In this chapter:
-
-\tableofcontents
-
The files referenced on this page can be found in \c $QTDIR\examples\tutorials\samegame\samegame3.
\section2 Making a playable game
@@ -313,10 +301,6 @@ until the next chapter - where your application becomes alive!
\contentspage QML Advanced Tutorial
\previouspage QML Advanced Tutorial 3 - Implementing the Game Logic
-In this chapter:
-
-\tableofcontents
-
The files referenced on this page can be found in \c $QTDIR\examples\tutorials\samegame\samegame4.
\section2 Adding some flair
@@ -432,7 +416,7 @@ If the player enters a name, we send the data to the service using this code in
\snippet declarative/tutorials/samegame/samegame4/content/samegame.js 1
-The \c XMLHttpRequest in this code is the same \c XMLHttpRequest() as you'll find in standard browser JavaScript, and can be used in the same way to dynamically get XML
+The \l XMLHttpRequest in this code is the same as the \c XMLHttpRequest() as you'll find in standard browser JavaScript, and can be used in the same way to dynamically get XML
or QML from the web service to display the high scores. We don't worry about the response in this case - we just post the high
score data to the web server. If it had returned a QML file (or a URL to a QML file) you could instantiate it in much the same
way as you did with the blocks.
diff --git a/doc/src/declarative/codingconventions.qdoc b/doc/src/declarative/codingconventions.qdoc
index 7ae5cbd..7ca206b 100644
--- a/doc/src/declarative/codingconventions.qdoc
+++ b/doc/src/declarative/codingconventions.qdoc
@@ -72,6 +72,7 @@ For example, a hypothetical \e photo QML object would look like this:
\snippet doc/src/snippets/declarative/codingconventions/photo.qml 0
+\target Grouped properties
\section1 Grouped properties
If using multiple properties from a group of properties,
diff --git a/doc/src/declarative/extending.qdoc b/doc/src/declarative/extending.qdoc
index 9844804..c27d091 100644
--- a/doc/src/declarative/extending.qdoc
+++ b/doc/src/declarative/extending.qdoc
@@ -43,86 +43,53 @@
\page qml-extending.html
\title Extending QML in C++
-The QtDeclarative module provides a set of APIs for extending QML through
-C++ extensions. You can write extensions to add your own QML types, extend existing
-Qt types, or call C/C++ functions that are not accessible from ordinary QML code.
-
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.
+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
\target adding-types
-QML can easily be extended to support new types.
-
-Let's create a new QML type called "Person" that has two properties, a name and a
-shoe size. We will make it available in a \l {Modules}{module} called "People", with
-a module version of 1.0. We want this \c Person type to be usable from QML like this:
-
\snippet examples/declarative/extending/adding/example.qml 0
-To do this, we need a C++ class that encapsulates this \c Person type and its two
-properties. Since QML relies heavily on Qt's \l{Meta-Object System}{meta object system},
-this new class must:
-
-\list
-\o inherit from QObject
-\o declare its properties using the Q_PROPERTY() macro
-\endlist
-
-Here is the \c Person class:
-
-\snippet examples/declarative/extending/adding/person.h 0
+The QML snippet shown above instantiates one \c Person instance and sets
+the \c name and \c shoeSize properties on it. Everything in QML ultimately comes down
+to either instantiating an object instance, or assigning a property a value.
+QML relies heavily on Qt's meta object system and can only instantiate classes
+that derive from QObject.
-Now that the \c Person type is defined, it needs to be registered with QML
-to make it available to QML code. To do this, call the qmlRegisterType()
-template function. For example, this registers the \c Person type as a type called
-"Person", to a module named "People", with a module version of 1.0:
+The QML engine has no intrinsic knowledge of any class types. Instead the
+programmer must define the C++ types, and their corresponding QML name.
-\snippet examples/declarative/extending/adding/main.cpp 0
+Custom C++ types are registered using a template function:
-Types can be registered by libraries (as Qt does), application code,
-or by plugins (see QDeclarativeExtensionPlugin).
-
-Now the \c Person type can be used from QML as shown above. When we create a
-\c Person item in QML, an instance of the C++ \c Person class is created, and the
-\c name and \c shoeSize properties of the \c Person class can be set. All of
-the properties of a registered type that are declared with Q_PROPERTY can be used
-from QML.
-
-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:
+\quotation
\code
-Person {
- // Will NOT work
- name: 12
-}
+template<typename T>
+int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const char *qmlName)
\endcode
-See \l {Extending QML - Adding Types Example} for the complete code used to create
-the \c Person type.
-
-\section2 Interfaces
-
-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. Instead of registering the type with
-qmlRegisterType(), use qmlRegisterInterface().
+Calling qmlRegisterType() registers the C++ type \a T with the QML system, and makes it available in QML
+under the name \a qmlName in library \a uri version \a versionMajor.versionMinor.
+The \a qmlName can be the same as the C++ type name.
+Type \a T must be a concrete type that inherits QObject and has a default
+constructor.
+\endquotation
-\section1 Supporting object and list property types
+Types can be registered by libraries (such as Qt does), application code,
+or by plugins (see QDeclarativeExtensionPlugin).
-When a new type is registered with QML, all of its properties declared with
-Q_PROPERTY are available from QML. QML has intrinsic support for properties of
-these types:
+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
@@ -138,82 +105,105 @@ these types:
\o QVariant
\endlist
-The \c Person type in the previous example had basic property types - a string
-for \c name, and an integer for \c shoeSize. However, 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 pointers, and lists of Qt interface pointers.
+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:
-Let's create a new QML type, "BirthdayParty", that has two properties
-with more complex types:
+\code
+Person {
+ // Will NOT work
+ name: 12
+}
+\endcode
-\list
-\o A \c host property whose value is a \c Person item
-\o A \c guests property whose value is a list of \c Person items
-\endlist
+\l {Extending QML - Adding Types Example} shows the complete code used to create
+the \c Person type.
-We want to use it from QML like this:
+\section1 Object and List Property Types
\snippet examples/declarative/extending/properties/example.qml 0
-This will assign a \c Person object to the \c BirthdayParty's \c host property,
-and assigns three other \c Person objects in a list to the \c guests property.
+The QML snippet shown above assigns a \c Person object to the \c BirthdayParty's
+\c host property, and assigns three \c Person objects to the guests property.
+
+QML can set properties of types that are more complex than basic intrinsics like
+integers and strings. Properties can also be object pointers, Qt interface
+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.
-To do this, we define a \c BirthdayParty class with the two properties.
-The \c host property stores a \c Person* pointer. It is declared like this:
+Properties that are pointers to objects or Qt interfaces are declared with the
+Q_PROPERTY() macro, just like other properties. The \c host property
+declaration looks like this:
\snippet examples/declarative/extending/properties/birthdayparty.h 1
-Note the type of the property (\c Person in this case) must be registered with QML with
-qmlRegisterType() or qmlRegisterInterface(). Otherwise, the property cannot be assigned in QML.
+As long as the property type, in this case \c Person, is registered with QML the
+property can be assigned.
+
+QML also supports assigning Qt interfaces. To assign to a property whose type
+is a Qt interface pointer, the interface must also be registered with QML. As
+they cannot be instantiated directly, registering a Qt interface is different
+from registering a new QML type. The following function is used instead:
+
+\quotation
+\code
+template<typename T>
+int qmlRegisterInterface(const char *typeName)
+\endcode
+
+Registers the C++ interface \a T with the QML system as \a typeName.
+
+Following registration, QML can coerce objects that implement this interface
+for assignment to appropriately typed properties.
+\endquotation
-The \c guests property is a list of \c Person* objects. Properties that are lists
+The \c guests property is a list of \c Person objects. Properties that are lists
of objects or Qt interfaces are also declared with the Q_PROPERTY() macro, just
like other properties. List properties must have the type \c {QDeclarativeListProperty<T>}.
As with object properties, the type \a T must be registered with QML.
-The guest property declaration looks like this:
-
-\snippet examples/declarative/extending/properties/birthdayparty.h 2
-
-So, here is the complete \c BirthdayParty class declaration:
+The \c guest property declaration looks 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 \c BirthdayClass type is also registered using qmlRegisterType() so
-it can be used from QML.
\l {Extending QML - Object and List Property Types Example} shows the complete
code used to create the \c BirthdayParty type.
\section1 Inheritance and Coercion
-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.
+\snippet examples/declarative/extending/coercion/example.qml 0
-For example, if classes \c Girl and \c Boy both inherit from \c Person, then
-\c Girl and \c Boy objects can be assigned in place of \c Person objects, like this:
+The QML snippet shown above assigns a \c Boy object to the \c BirthdayParty's
+\c host property, and assigns three other objects to the \c guests property.
-\snippet examples/declarative/extending/coercion/example.qml 0
+QML supports C++ inheritance hierarchies and can freely coerce between known,
+valid object types. This enables the creation of common base classes that allow
+the assignment of specialized classes to object or list properties. In the
+snippet shown, both the \c host and the \c guests properties retain the \c Person
+type used in the previous section, but the assignment is valid as both the \c Boy
+and \c Girl objects inherit from \c Person.
-To assign to a property, the property's type (in this case, \c Girl and \c Boy)
-must be registered with QML.
-Both the qmlRegisterType() and qmlRegisterInterface() template functions previously
-discussed can be used to register a type with QML. Additionally, in the case of the
-\c Person class, which now acts purely as a base class and should no longer be instantiated from QML,
-the following function can be used:
+To assign to a property, the property's type must have been registered with QML.
+Both the qmlRegisterType() and qmlRegisterInterface() template functions already
+shown can be used to register a type with QML. Additionally, if a type that acts purely
+as a base class that cannot be instantiated from QML needs to be
+registered, the following function can be used:
+\quotation
\code
template<typename T>
int qmlRegisterType()
\endcode
-Calling the parameterless qmlRegisterType() ensures the type is available
-to QML for type coercion but cannot be created as a type from QML.
+Registers the C++ type \a T with the QML system. The parameterless call to the template
+function qmlRegisterType() does not define a mapping between the
+C++ class and a QML element name, so the type is not instantiable from QML, but
+it is available for type coercion.
+
+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
@@ -224,110 +214,110 @@ code used to create the \c Boy and \c Girl types.
\section1 Default Property
-The \e {default property} is a syntactic convenience that allows a type designer to
-specify a single property as the type's default.
-
-This QML snippet assigns a collection of objects - two \c Boy and one
-\c Girl objects - to the \c BirthdayParty's default property:
-
\snippet examples/declarative/extending/default/example.qml 0
-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.
+The QML snippet shown above assigns a collection of objects to the
+\c BirthdayParty's default property.
+
+The \e {default property} is a syntactic convenience that allows a type designer to
+specify a single property as the type's default. The default property is
+assigned to whenever no explicit property is specified. As a convenience, it is
+behaviorally identical to assigning the default property explicitly by name.
From C++, type designers mark the default property using a Q_CLASSINFO()
annotation:
+\quotation
\code
- Q_CLASSINFO("DefaultProperty", "property")
+Q_CLASSINFO("DefaultProperty", "property")
\endcode
-The \c property must be either an object property, or a list property. The
-\c property can refer to a property declared in the class itself, or a property
-inherited from a base class.
+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.
+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.
-This QML snippet assigns a number properties to the \c Boy object,
-including four properties using the grouped property syntax:
-
-\snippet examples/declarative/extending/grouped/example.qml 1
-
A grouped property block is implemented as a read-only object property. The
-shoe property shown is declared like this:
+\c shoe property shown is declared like this:
\snippet examples/declarative/extending/grouped/person.h 1
The \c ShoeDescription type declares the properties available to the grouped
property block - in this case the \c size, \c color, \c brand and \c price properties.
-Grouped property blocks may be declared and accessed recusively.
+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
-Attached properties allow unrelated types to annotate other types with some
-additional properties, generally for their own use. This QML snippet assigns
-an \c rsvp property using the attached property syntax:
-
\snippet examples/declarative/extending/attached/example.qml 1
-Attached properties are identified through the use of the attacher type name; in the case shown
+The QML snippet shown above assigns the \c rsvp property using the attached
+property syntax.
+
+Attached properties allow unrelated types to annotate other types with some
+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
-Boy instance the attachee object instance.
+\c Boy instance the attachee object instance.
For the attaching type, an attached property block is implemented as a new
QObject derived type, called the attachment object. The properties on the
attachment object are those that become available for use as the attached
property block.
-Any QML type can become an attaching type by declaring a
+Any QML type can become an attaching type by declaring the
\c qmlAttachedProperties() public function and declaring that the class has
QML_HAS_ATTACHED_PROPERTIES:
+\quotation
\code
- class MyType : public QObject {
- Q_OBJECT
- public:
+class MyType : public QObject {
+ Q_OBJECT
+public:
- ...
+ ...
- static AttachedPropertiesType *qmlAttachedProperties(QObject *object);
- };
+ static AttachedPropertiesType *qmlAttachedProperties(QObject *object);
+};
- QML_DECLARE_TYPEINFO(MyType, QML_HAS_ATTACHED_PROPERTIES)
+QML_DECLARE_TYPEINFO(MyType, QML_HAS_ATTACHED_PROPERTIES)
\endcode
-
-The qmlAttachedProperties() method returns an attachment object, of type \a AttachedPropertiesType, for the
+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.
-The returned \a AttachedPropertiesType must be a QObject derived type. The properties on
+\a AttachedPropertiesType must be a QObject derived type. The properties on
this type will be accessible through the attached properties syntax.
-This method is called at most once for each attachee object instance. The
+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.
-
-\section2 Use of attached properties
+\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
@@ -337,17 +327,14 @@ 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 \c 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" }
@@ -406,24 +393,21 @@ this situation, but it must not crash.
\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 JavaScript expression
+with the emission of a Qt signal.
+
All Qt signals on a registered class become available as special "signal
properties" within QML to which the user can assign a single JavaScript
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, if the \c BirthdayParty class has a signal like this:
+cased. For example, the signal used in the example above has the following
+C++ signature:
\snippet examples/declarative/extending/signal/birthdayparty.h 0
-This signal can be connected to from QML like this:
-
-\snippet examples/declarative/extending/signal/example.qml 0
-\snippet examples/declarative/extending/signal/example.qml 1
-
-This associates the evaluation of a JavaScript expression
-with the emission of a Qt signal.
-
In classes with multiple signals with the same name, only the final signal
is accessible as a signal property. Note that signals with the same name
but different parameters cannot be distinguished.
@@ -440,31 +424,34 @@ implement the onPartyStarted signal property.
\section1 Property Value Sources
-A property value source is an element that generates a value for a
-property that changes over time. Property value sources are most commonly used to
-create animations; QML's built-in \l {Behavior}{Behavior} and various
-\l {QML Animation}{animation} elements are actually property value sources.
-
-The \c BirthdayParty class has an \c announcement string property
-whose value is printed to the console whenever it changes. Using a property value
-source called \c HappyBirthdaySong, the value of this property can be changed,
-over time, to each lyric in the song "Happy Birthday". For further customization,
-a \c name property allows the song lyrics to be personalized with a particular name.
-The \c HappyBirthdaySong property value source would be used in QML like this:
-
\snippet examples/declarative/extending/valuesource/example.qml 0
\snippet examples/declarative/extending/valuesource/example.qml 1
-(Normally, assigning an object to a string property would not be allowed. In
+The QML snippet shown above applies a property value source to the \c announcment property.
+A property value source generates a value for a property that changes over time.
+
+Property value sources are most commonly used to do animation. Rather than
+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 \c announcment property of the
+\c BirthdayParty object is a string that is printed every time it is assigned and
+the \c HappyBirthdaySong value source generates the lyrics of the song
+"Happy Birthday".
+
+\snippet examples/declarative/extending/valuesource/birthdayparty.h 0
+
+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.)
+the property.
Property value sources are special types that derive from the
QDeclarativePropertyValueSource base class. This base class contains a single method,
QDeclarativePropertyValueSource::setTarget(), that the QML engine invokes when
-associating the property value source with a property. Here is the relevant part of
-the \c HappyBirthdaySong type declaration:
+associating the property value source with a property. The relevant part of
+the \c HappyBirthdaySong type declaration looks like this:
\snippet examples/declarative/extending/valuesource/happybirthdaysong.h 0
\snippet examples/declarative/extending/valuesource/happybirthdaysong.h 1
@@ -476,15 +463,20 @@ 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
-\l {QDeclarativePropertyValueSource::setTarget()}{setTarget()} method. This allows
+assignment fails does the engine call the \l {QDeclarativePropertyValueSource::}{setTarget()} method. This allows
the type to also be used in contexts other than just as a value source.
\l {Extending QML - Property Value Source Example} shows the complete code used
-implement the HappyBirthdaySong property value source.
+implement the \c HappyBirthdaySong 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
+\c HappyBirthdaySong's \c name property remains up to date with the \c host.
+
Property binding is a core feature of QML. In addition to assigning literal
values, property bindings allow the developer to assign an arbitrarily complex
JavaScript expression that may include dependencies on other property values.
@@ -498,21 +490,13 @@ 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
\l {Qt's Property System}{NOTIFY signal} for this determination.
-For example, to enable property binding for the \c host property in \c BirthdayParty,
-add a \c hostChanged signal that is emitted when the \c host value changes, and
-declare the \c host property like this:
+Here is the \c host property declaration:
\snippet examples/declarative/extending/binding/birthdayparty.h 0
-This enables the use of a property binding to ensure the \c name value of the
-\c HappyBirthdaySong is updated if the \c host value changes:
-
-\snippet examples/declarative/extending/binding/example.qml 0
-\snippet examples/declarative/extending/binding/example.qml 1
-
-It is the responsibility of the class implementer to ensure that whenever the
-property's value changes, the associated NOTIFY signal is emitted. The
-signature of the NOTIFY signal is not important to QML.
+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
@@ -520,8 +504,6 @@ 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.
-\section2 Use of notify signals
-
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
@@ -561,6 +543,11 @@ 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
@@ -574,11 +561,6 @@ type definition allows the programmer to supply an additional type - known as th
extension type - when registering the target class whose properties are
transparently merged with the original target class when used from within QML.
-Here is a QML snippet that adds a new property to an existing C++ type without
-modifying its source code:
-
-\snippet examples/declarative/extending/extended/example.qml 0
-
An extension class is a regular QObject, with a constructor that takes a QObject
pointer. When needed (extension classes are delay created until the first extended
property is accessed) the extension class is created and the target object is
@@ -590,7 +572,6 @@ When an extended type is installed, one of the
#define QML_REGISTER_EXTENDED_TYPE(URI, VMAJ, VFROM, VTO, QDeclarativeName,T, ExtendedT)
#define QML_REGISTER_EXTENDED_NOCREATE_TYPE(T, ExtendedT)
\endcode
-
macros should be used instead of the regular \c QML_REGISTER_TYPE or
\c QML_REGISTER_NOCREATE_TYPE. The arguments are identical to the corresponding
non-extension object macro, except for the ExtendedT parameter which is the type
diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp
index a76d88e..7b9b5e0 100644
--- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp
@@ -655,7 +655,7 @@ void QDeclarativeFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent
rejectY = true;
}
if (!rejectY && stealMouse) {
- vData.move.setValue(newY);
+ vData.move.setValue(qRound(newY));
moved = true;
}
if (qAbs(dy) > QApplication::startDragDistance())
@@ -682,7 +682,7 @@ void QDeclarativeFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent
rejectX = true;
}
if (!rejectX && stealMouse) {
- hData.move.setValue(newX);
+ hData.move.setValue(qRound(newX));
moved = true;
}
diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp
index 23140fa..f6666f2 100644
--- a/src/declarative/graphicsitems/qdeclarativegridview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp
@@ -347,6 +347,7 @@ public:
void QDeclarativeGridViewPrivate::init()
{
Q_Q(QDeclarativeGridView);
+ QObject::connect(q, SIGNAL(movementEnded()), q, SLOT(animStopped()));
q->setFlag(QGraphicsItem::ItemIsFocusScope);
q->setFlickDirection(QDeclarativeFlickable::VerticalFlick);
addItemChangeListener(this, Geometry);
@@ -747,18 +748,31 @@ void QDeclarativeGridViewPrivate::fixupPosition()
void QDeclarativeGridViewPrivate::fixup(AxisData &data, qreal minExtent, qreal maxExtent)
{
Q_Q(QDeclarativeGridView);
+ if ((flow == QDeclarativeGridView::TopToBottom && &data == &vData)
+ || (flow == QDeclarativeGridView::LeftToRight && &data == &hData))
+ return;
+
int oldDuration = fixupDuration;
fixupDuration = moveReason == Mouse ? fixupDuration : 0;
if (haveHighlightRange && highlightRange == QDeclarativeGridView::StrictlyEnforceRange) {
- if (currentItem && currentItem->rowPos() - position() != highlightRangeStart) {
- qreal pos = currentItem->rowPos() - highlightRangeStart;
+ if (currentItem) {
+ updateHighlight();
+ qreal pos = currentItem->rowPos();
+ qreal viewPos = position();
+ if (viewPos < pos + rowSize() - highlightRangeEnd)
+ viewPos = pos + rowSize() - highlightRangeEnd;
+ if (viewPos > pos - highlightRangeStart)
+ viewPos = pos - highlightRangeStart;
+
timeline.reset(data.move);
- if (fixupDuration) {
- timeline.move(data.move, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2);
- } else {
- data.move.setValue(-pos);
- q->viewportMoved();
+ if (viewPos != position()) {
+ if (fixupDuration) {
+ timeline.move(data.move, -viewPos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2);
+ } else {
+ data.move.setValue(-viewPos);
+ q->viewportMoved();
+ }
}
vTime = timeline.time();
}
@@ -803,7 +817,7 @@ void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal m
maxDistance = qAbs(minExtent - data.move.value());
}
}
- if (snapMode != QDeclarativeGridView::SnapToRow && highlightRange != QDeclarativeGridView::StrictlyEnforceRange)
+ if (snapMode == QDeclarativeGridView::NoSnap && highlightRange != QDeclarativeGridView::StrictlyEnforceRange)
data.flickTarget = minExtent;
} else {
if (data.move.value() > maxExtent) {
@@ -814,7 +828,7 @@ void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal m
maxDistance = qAbs(maxExtent - data.move.value());
}
}
- if (snapMode != QDeclarativeGridView::SnapToRow && highlightRange != QDeclarativeGridView::StrictlyEnforceRange)
+ if (snapMode == QDeclarativeGridView::NoSnap && highlightRange != QDeclarativeGridView::StrictlyEnforceRange)
data.flickTarget = maxExtent;
}
if (maxDistance > 0 || overShoot) {
@@ -1510,12 +1524,12 @@ void QDeclarativeGridView::viewportMoved()
if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange && d->highlight) {
// reposition highlight
qreal pos = d->highlight->rowPos();
- qreal viewPos = qRound(d->position());
- if (pos > viewPos + d->highlightRangeEnd - 1 - d->rowSize())
- pos = viewPos + d->highlightRangeEnd - 1 - d->rowSize();
+ qreal viewPos = d->position();
+ if (pos > viewPos + d->highlightRangeEnd - d->rowSize())
+ pos = viewPos + d->highlightRangeEnd - d->rowSize();
if (pos < viewPos + d->highlightRangeStart)
pos = viewPos + d->highlightRangeStart;
- d->highlight->setPosition(d->highlight->colPos(), pos);
+ d->highlight->setPosition(d->highlight->colPos(), qRound(pos));
// update current index
int idx = d->snapIndex();
@@ -1538,8 +1552,10 @@ qreal QDeclarativeGridView::minYExtent() const
if (d->flow == QDeclarativeGridView::TopToBottom)
return QDeclarativeFlickable::minYExtent();
qreal extent = -d->startPosition();
- if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange)
+ if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) {
extent += d->highlightRangeStart;
+ extent = qMax(extent, -(d->rowPosAt(0) + d->rowSize() - d->highlightRangeEnd));
+ }
return extent;
}
@@ -1550,8 +1566,9 @@ qreal QDeclarativeGridView::maxYExtent() const
return QDeclarativeFlickable::maxYExtent();
qreal extent;
if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) {
- extent = -(d->endPosition() - d->highlightRangeEnd);
- extent = qMax(extent, -(d->rowPosAt(d->model->count()-1) - d->highlightRangeStart));
+ extent = -(d->rowPosAt(d->model->count()-1) - d->highlightRangeStart);
+ if (d->highlightRangeEnd != d->highlightRangeStart)
+ extent = qMin(extent, -(d->endPosition() - d->highlightRangeEnd + 1));
} else {
extent = -(d->endPosition() - height());
}
@@ -1567,8 +1584,10 @@ qreal QDeclarativeGridView::minXExtent() const
if (d->flow == QDeclarativeGridView::LeftToRight)
return QDeclarativeFlickable::minXExtent();
qreal extent = -d->startPosition();
- if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange)
+ if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) {
extent += d->highlightRangeStart;
+ extent = qMax(extent, -(d->rowPosAt(0) + d->rowSize() - d->highlightRangeEnd));
+ }
return extent;
}
@@ -1579,8 +1598,9 @@ qreal QDeclarativeGridView::maxXExtent() const
return QDeclarativeFlickable::maxXExtent();
qreal extent;
if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) {
- extent = -(d->endPosition() - d->highlightRangeEnd);
- extent = qMax(extent, -(d->rowPosAt(d->model->count()-1) - d->highlightRangeStart));
+ extent = -(d->rowPosAt(d->model->count()-1) - d->highlightRangeStart);
+ if (d->highlightRangeEnd != d->highlightRangeStart)
+ extent = qMin(extent, -(d->endPosition() - d->highlightRangeEnd + 1));
} else {
extent = -(d->endPosition() - height());
}
@@ -2250,6 +2270,13 @@ void QDeclarativeGridView::destroyingItem(QDeclarativeItem *item)
d->unrequestedItems.remove(item);
}
+void QDeclarativeGridView::animStopped()
+{
+ Q_D(QDeclarativeGridView);
+ d->bufferMode = QDeclarativeGridViewPrivate::NoBuffer;
+ if (d->haveHighlightRange && d->highlightRange == QDeclarativeGridView::StrictlyEnforceRange)
+ d->updateHighlight();
+}
void QDeclarativeGridView::refill()
{
diff --git a/src/declarative/graphicsitems/qdeclarativegridview_p.h b/src/declarative/graphicsitems/qdeclarativegridview_p.h
index 5baa1dd..c06879e 100644
--- a/src/declarative/graphicsitems/qdeclarativegridview_p.h
+++ b/src/declarative/graphicsitems/qdeclarativegridview_p.h
@@ -192,6 +192,7 @@ private Q_SLOTS:
void destroyRemoved();
void createdItem(int index, QDeclarativeItem *item);
void destroyingItem(QDeclarativeItem *item);
+ void animStopped();
private:
void refill();
diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp
index 672f723..a4ca651 100644
--- a/src/declarative/graphicsitems/qdeclarativelistview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp
@@ -271,6 +271,28 @@ public:
return 0;
}
+ qreal endPositionAt(int modelIndex) const {
+ if (FxListItem *item = visibleItem(modelIndex))
+ return item->endPosition();
+ if (!visibleItems.isEmpty()) {
+ if (modelIndex < visibleIndex) {
+ int count = visibleIndex - modelIndex;
+ return (*visibleItems.constBegin())->position() - (count - 1) * (averageSize + spacing) - spacing - 1;
+ } else {
+ int idx = visibleItems.count() - 1;
+ while (idx >= 0 && visibleItems.at(idx)->index == -1)
+ --idx;
+ if (idx < 0)
+ idx = visibleIndex;
+ else
+ idx = visibleItems.at(idx)->index;
+ int count = modelIndex - idx - 1;
+ return (*(--visibleItems.constEnd()))->endPosition() + count * (averageSize + spacing);
+ }
+ }
+ return 0;
+ }
+
QString sectionAt(int modelIndex) {
if (FxListItem *item = visibleItem(modelIndex))
return item->attached->section();
@@ -396,13 +418,16 @@ public:
}
void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) {
+ Q_Q(QDeclarativeListView);
QDeclarativeFlickablePrivate::itemGeometryChanged(item, newGeometry, oldGeometry);
- if (item != viewport) {
+ if (item != viewport && (!highlight || item != highlight->item)) {
if ((orient == QDeclarativeListView::Vertical && newGeometry.height() != oldGeometry.height())
|| (orient == QDeclarativeListView::Horizontal && newGeometry.width() != oldGeometry.width())) {
scheduleLayout();
}
}
+ if (trackedItem && trackedItem->item == item)
+ q->trackedPositionChanged();
}
// for debugging only
@@ -567,13 +592,8 @@ void QDeclarativeListViewPrivate::releaseItem(FxListItem *item)
Q_Q(QDeclarativeListView);
if (!item || !model)
return;
- if (trackedItem == item) {
- const char *notifier1 = orient == QDeclarativeListView::Vertical ? SIGNAL(yChanged()) : SIGNAL(xChanged());
- const char *notifier2 = orient == QDeclarativeListView::Vertical ? SIGNAL(heightChanged()) : SIGNAL(widthChanged());
- QObject::disconnect(trackedItem->item, notifier1, q, SLOT(trackedPositionChanged()));
- QObject::disconnect(trackedItem->item, notifier2, q, SLOT(trackedPositionChanged()));
+ if (trackedItem == item)
trackedItem = 0;
- }
QDeclarativeItemPrivate *itemPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(item->item));
itemPrivate->removeItemChangeListener(this, QDeclarativeItemPrivate::Geometry);
if (model->release(item->item) == 0) {
@@ -770,21 +790,7 @@ void QDeclarativeListViewPrivate::updateTrackedItem()
FxListItem *item = currentItem;
if (highlight)
item = highlight;
-
- const char *notifier1 = orient == QDeclarativeListView::Vertical ? SIGNAL(yChanged()) : SIGNAL(xChanged());
- const char *notifier2 = orient == QDeclarativeListView::Vertical ? SIGNAL(heightChanged()) : SIGNAL(widthChanged());
-
- if (trackedItem && item != trackedItem) {
- QObject::disconnect(trackedItem->item, notifier1, q, SLOT(trackedPositionChanged()));
- QObject::disconnect(trackedItem->item, notifier2, q, SLOT(trackedPositionChanged()));
- trackedItem = 0;
- }
-
- if (!trackedItem && item) {
- trackedItem = item;
- QObject::connect(trackedItem->item, notifier1, q, SLOT(trackedPositionChanged()));
- QObject::connect(trackedItem->item, notifier2, q, SLOT(trackedPositionChanged()));
- }
+ trackedItem = item;
if (trackedItem)
q->trackedPositionChanged();
}
@@ -833,6 +839,8 @@ void QDeclarativeListViewPrivate::createHighlight()
highlight->item->setWidth(currentItem->item->width());
}
}
+ QDeclarativeItemPrivate *itemPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(item));
+ itemPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry);
const QLatin1String posProp(orient == QDeclarativeListView::Vertical ? "y" : "x");
highlightPosAnimator = new QSmoothedAnimation(q);
highlightPosAnimator->target = QDeclarativeProperty(highlight->item, posProp);
@@ -1106,14 +1114,23 @@ void QDeclarativeListViewPrivate::fixup(AxisData &data, qreal minExtent, qreal m
fixupDuration = moveReason == Mouse ? fixupDuration : 0;
if (haveHighlightRange && highlightRange == QDeclarativeListView::StrictlyEnforceRange) {
- if (currentItem && currentItem->position() - position() != highlightRangeStart) {
- qreal pos = currentItem->position() - highlightRangeStart;
+ if (currentItem) {
+ updateHighlight();
+ qreal pos = currentItem->position();
+ qreal viewPos = position();
+ if (viewPos < pos + currentItem->size() - highlightRangeEnd)
+ viewPos = pos + currentItem->size() - highlightRangeEnd;
+ if (viewPos > pos - highlightRangeStart)
+ viewPos = pos - highlightRangeStart;
+
timeline.reset(data.move);
- if (fixupDuration) {
- timeline.move(data.move, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2);
- } else {
- data.move.setValue(-pos);
- q->viewportMoved();
+ if (viewPos != position()) {
+ if (fixupDuration) {
+ timeline.move(data.move, -viewPos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2);
+ } else {
+ data.move.setValue(-viewPos);
+ q->viewportMoved();
+ }
}
vTime = timeline.time();
}
@@ -2066,12 +2083,12 @@ void QDeclarativeListView::viewportMoved()
if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange && d->highlight) {
// reposition highlight
qreal pos = d->highlight->position();
- qreal viewPos = qRound(d->position());
- if (pos > viewPos + d->highlightRangeEnd - 1 - d->highlight->size())
- pos = viewPos + d->highlightRangeEnd - 1 - d->highlight->size();
+ qreal viewPos = d->position();
+ if (pos > viewPos + d->highlightRangeEnd - d->highlight->size())
+ pos = viewPos + d->highlightRangeEnd - d->highlight->size();
if (pos < viewPos + d->highlightRangeStart)
pos = viewPos + d->highlightRangeStart;
- d->highlight->setPosition(pos);
+ d->highlight->setPosition(qRound(pos));
// update current index
int idx = d->snapIndex();
@@ -2128,8 +2145,10 @@ qreal QDeclarativeListView::minYExtent() const
d->minExtent = -d->startPosition();
if (d->header && d->visibleItems.count())
d->minExtent += d->header->size();
- if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange)
+ if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) {
d->minExtent += d->highlightRangeStart;
+ d->minExtent = qMax(d->minExtent, -(d->endPositionAt(0) - d->highlightRangeEnd + 1));
+ }
d->minExtentDirty = false;
}
@@ -2143,10 +2162,12 @@ qreal QDeclarativeListView::maxYExtent() const
return height();
if (d->maxExtentDirty) {
if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) {
- d->maxExtent = -(d->endPosition() - d->highlightRangeEnd);
- d->maxExtent = qMax(d->maxExtent, -(d->positionAt(d->model->count()-1) - d->highlightRangeStart));
- } else
+ d->maxExtent = -(d->positionAt(d->model->count()-1) - d->highlightRangeStart);
+ if (d->highlightRangeEnd != d->highlightRangeStart)
+ d->maxExtent = qMin(d->maxExtent, -(d->endPosition() - d->highlightRangeEnd + 1));
+ } else {
d->maxExtent = -(d->endPosition() - height() + 1);
+ }
if (d->footer)
d->maxExtent -= d->footer->size();
qreal minY = minYExtent();
@@ -2166,8 +2187,10 @@ qreal QDeclarativeListView::minXExtent() const
d->minExtent = -d->startPosition();
if (d->header)
d->minExtent += d->header->size();
- if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange)
+ if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) {
d->minExtent += d->highlightRangeStart;
+ d->minExtent = qMax(d->minExtent, -(d->endPositionAt(0) - d->highlightRangeEnd + 1));
+ }
d->minExtentDirty = false;
}
@@ -2181,10 +2204,12 @@ qreal QDeclarativeListView::maxXExtent() const
return width();
if (d->maxExtentDirty) {
if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) {
- d->maxExtent = -(d->endPosition() - d->highlightRangeEnd);
- d->maxExtent = qMax(d->maxExtent, -(d->positionAt(d->model->count()-1) - d->highlightRangeStart));
- } else
+ d->maxExtent = -(d->positionAt(d->model->count()-1) - d->highlightRangeStart);
+ if (d->highlightRangeEnd != d->highlightRangeStart)
+ d->maxExtent = qMin(d->maxExtent, -(d->endPosition() - d->highlightRangeEnd + 1));
+ } else {
d->maxExtent = -(d->endPosition() - width() + 1);
+ }
if (d->footer)
d->maxExtent -= d->footer->size();
qreal minX = minXExtent();
@@ -2393,7 +2418,7 @@ void QDeclarativeListView::trackedPositionChanged()
if (!d->trackedItem || !d->currentItem)
return;
if (!isFlicking() && !d->moving && d->moveReason == QDeclarativeListViewPrivate::SetIndex) {
- const qreal trackedPos = d->trackedItem->position();
+ const qreal trackedPos = qCeil(d->trackedItem->position());
const qreal viewPos = d->position();
if (d->haveHighlightRange) {
if (d->highlightRange == StrictlyEnforceRange) {
@@ -2827,6 +2852,8 @@ void QDeclarativeListView::animStopped()
{
Q_D(QDeclarativeListView);
d->bufferMode = QDeclarativeListViewPrivate::NoBuffer;
+ if (d->haveHighlightRange && d->highlightRange == QDeclarativeListView::StrictlyEnforceRange)
+ d->updateHighlight();
}
QDeclarativeListViewAttached *QDeclarativeListView::qmlAttachedProperties(QObject *obj)
diff --git a/src/declarative/qml/qdeclarativebinding.cpp b/src/declarative/qml/qdeclarativebinding.cpp
index 95520da..d44e7fb 100644
--- a/src/declarative/qml/qdeclarativebinding.cpp
+++ b/src/declarative/qml/qdeclarativebinding.cpp
@@ -361,8 +361,10 @@ void QDeclarativeAbstractBinding::removeFromObject()
void QDeclarativeAbstractBinding::clear()
{
- if (m_mePtr)
+ if (m_mePtr) {
*m_mePtr = 0;
+ m_mePtr = 0;
+ }
}
QString QDeclarativeAbstractBinding::expression() const
diff --git a/src/declarative/qml/qdeclarativepropertyvaluesource.cpp b/src/declarative/qml/qdeclarativepropertyvaluesource.cpp
index b106d4f..a0ed78f 100644
--- a/src/declarative/qml/qdeclarativepropertyvaluesource.cpp
+++ b/src/declarative/qml/qdeclarativepropertyvaluesource.cpp
@@ -47,8 +47,10 @@ QT_BEGIN_NAMESPACE
/*!
\class QDeclarativePropertyValueSource
- \brief The QDeclarativePropertyValueSource class is inherited by property value sources such as animations and bindings.
- \internal
+ \brief The QDeclarativePropertyValueSource class is an interface for property value sources such as animations and bindings.
+
+ See \l{Property Value Sources} for information on writing custom property
+ value sources.
*/
/*!
diff --git a/src/declarative/util/qdeclarativestateoperations.cpp b/src/declarative/util/qdeclarativestateoperations.cpp
index 8f22de5..0aad498 100644
--- a/src/declarative/util/qdeclarativestateoperations.cpp
+++ b/src/declarative/util/qdeclarativestateoperations.cpp
@@ -124,6 +124,10 @@ void QDeclarativeParentChangePrivate::doChange(QDeclarativeItem *targetParent, Q
const QPointF &point = transform.map(QPointF(target->x(),target->y()));
qreal x = point.x();
qreal y = point.y();
+
+ // setParentItem will update the transformOriginPoint if needed
+ target->setParentItem(targetParent);
+
if (ok && target->transformOrigin() != QDeclarativeItem::TopLeft) {
qreal tempxt = target->transformOriginPoint().x();
qreal tempyt = target->transformOriginPoint().y();
@@ -137,7 +141,6 @@ void QDeclarativeParentChangePrivate::doChange(QDeclarativeItem *targetParent, Q
y += offset.y();
}
- target->setParentItem(targetParent);
if (ok) {
//qDebug() << x << y << rotation << scale;
target->setX(x);
diff --git a/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp b/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp
index 49d430e..e2d3ee4 100644
--- a/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp
+++ b/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp
@@ -276,6 +276,7 @@ void tst_QDeclarativeDebug::initTestCase()
{
qRegisterMetaType<QDeclarativeDebugWatch::State>();
+ QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Waiting for connection on port 3768...");
qputenv("QML_DEBUG_SERVER_PORT", "3768");
m_engine = new QDeclarativeEngine(this);
@@ -301,13 +302,14 @@ void tst_QDeclarativeDebug::initTestCase()
}
m_rootItem = qobject_cast<QDeclarativeItem*>(m_components.first());
-
// add an extra context to test for multiple contexts
QDeclarativeContext *context = new QDeclarativeContext(m_engine->rootContext(), this);
context->setObjectName("tst_QDeclarativeDebug_childContext");
m_conn = new QDeclarativeDebugConnection(this);
m_conn->connectToHost("127.0.0.1", 3768);
+
+ QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Connection established");
bool ok = m_conn->waitForConnected();
Q_ASSERT(ok);
QTRY_VERIFY(QDeclarativeDebugService::hasDebuggingClient());
diff --git a/tests/auto/declarative/qdeclarativedebugclient/tst_qdeclarativedebugclient.cpp b/tests/auto/declarative/qdeclarativedebugclient/tst_qdeclarativedebugclient.cpp
index 102b2be..a19c2c2 100644
--- a/tests/auto/declarative/qdeclarativedebugclient/tst_qdeclarativedebugclient.cpp
+++ b/tests/auto/declarative/qdeclarativedebugclient/tst_qdeclarativedebugclient.cpp
@@ -74,11 +74,15 @@ private slots:
void tst_QDeclarativeDebugClient::initTestCase()
{
+ QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Waiting for connection on port 3770...");
+
qputenv("QML_DEBUG_SERVER_PORT", "3770");
new QDeclarativeEngine(this);
m_conn = new QDeclarativeDebugConnection(this);
m_conn->connectToHost("127.0.0.1", 3770);
+
+ QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Connection established");
bool ok = m_conn->waitForConnected();
Q_ASSERT(ok);
diff --git a/tests/auto/declarative/qdeclarativedebugservice/tst_qdeclarativedebugservice.cpp b/tests/auto/declarative/qdeclarativedebugservice/tst_qdeclarativedebugservice.cpp
index 5da3359..9ebbbaf 100644
--- a/tests/auto/declarative/qdeclarativedebugservice/tst_qdeclarativedebugservice.cpp
+++ b/tests/auto/declarative/qdeclarativedebugservice/tst_qdeclarativedebugservice.cpp
@@ -76,11 +76,14 @@ private slots:
void tst_QDeclarativeDebugService::initTestCase()
{
+ QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Waiting for connection on port 3769...");
qputenv("QML_DEBUG_SERVER_PORT", "3769");
new QDeclarativeEngine(this);
m_conn = new QDeclarativeDebugConnection(this);
m_conn->connectToHost("127.0.0.1", 3769);
+
+ QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Connection established");
bool ok = m_conn->waitForConnected();
Q_ASSERT(ok);
diff --git a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp
index bbea98a..e4c296f 100644
--- a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp
+++ b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp
@@ -326,6 +326,12 @@ void tst_qdeclarativelistmodel::dynamic_worker()
if (QByteArray(QTest::currentDataTag()).startsWith("nested"))
QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML ListModel: Cannot add nested list values when modifying or after modification from a worker script");
+ if (QByteArray(QTest::currentDataTag()).startsWith("nested-append")) {
+ int callsToGet = script.count(QLatin1String(";get("));
+ for (int i=0; i<callsToGet; i++)
+ QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML ListModel: get: index 0 out of range");
+ }
+
QVERIFY(QMetaObject::invokeMethod(item, "evalExpressionViaWorker",
Q_ARG(QVariant, operations.mid(0, operations.length()-1))));
waitForWorker(item);
diff --git a/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp b/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp
index a5f75bd..7cdadb4 100644
--- a/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp
+++ b/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp
@@ -538,9 +538,8 @@ void tst_QDeclarativeLoader::nonItem()
void tst_QDeclarativeLoader::vmeErrors()
{
QDeclarativeComponent component(&engine, TEST_FILE("vmeErrors.qml"));
- //ignore message for now
- //QString err = QUrl::fromLocalFile(SRCDIR "/data/VmeError.qml:6: Cannot assign object type QObject with no default method\n onSomethingHappened: QtObject {}) ");
- //QTest::ignoreMessage(QtWarningMsg, err.toLatin1().constData());
+ QString err = QUrl::fromLocalFile(SRCDIR).toString() + "/data/VmeError.qml:6: Cannot assign object type QObject with no default method";
+ QTest::ignoreMessage(QtWarningMsg, err.toLatin1().constData());
QDeclarativeLoader *loader = qobject_cast<QDeclarativeLoader*>(component.create());
QVERIFY(loader);
QVERIFY(loader->item() == 0);
diff --git a/tools/qml/loggerwidget.cpp b/tools/qml/loggerwidget.cpp
index c5548b7..015d1b0 100644
--- a/tools/qml/loggerwidget.cpp
+++ b/tools/qml/loggerwidget.cpp
@@ -53,9 +53,9 @@ LoggerWidget::LoggerWidget(QWidget *parent) :
setWindowTitle(tr("Qt Declarative UI Viewer - Logger"));
}
-void LoggerWidget::append(QtMsgType /*type*/, const char *msg)
+void LoggerWidget::append(const QString &msg)
{
- appendPlainText(QString::fromAscii(msg));
+ appendPlainText(msg);
if (!m_keepClosed && !isVisible())
setVisible(true);
diff --git a/tools/qml/loggerwidget.h b/tools/qml/loggerwidget.h
index 938431c..5c4a701 100644
--- a/tools/qml/loggerwidget.h
+++ b/tools/qml/loggerwidget.h
@@ -50,7 +50,8 @@ class LoggerWidget : public QPlainTextEdit {
Q_OBJECT
public:
LoggerWidget(QWidget *parent=0);
- void append(QtMsgType type, const char *msg);
+public slots:
+ void append(const QString &msg);
protected:
void closeEvent(QCloseEvent *event);
private:
diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp
index a79e1b1..cba5650 100644
--- a/tools/qml/main.cpp
+++ b/tools/qml/main.cpp
@@ -93,7 +93,8 @@ void showWarnings()
void myMessageOutput(QtMsgType type, const char *msg)
{
if (!logger.isNull()) {
- logger.data()->append(type, msg);
+ QString strMsg = QString::fromAscii(msg);
+ QMetaObject::invokeMethod(logger.data(), "append", Q_ARG(QString, strMsg));
} else {
warnings += msg;
warnings += QLatin1Char('\n');
@@ -346,7 +347,7 @@ int main(int argc, char ** argv)
}
#endif
- QDeclarativeViewer viewer(0, wflags);
+ QDeclarativeViewer *viewer = new QDeclarativeViewer(0, wflags);
if (!scriptopts.isEmpty()) {
QStringList options =
scriptopts.split(QLatin1Char(','), QString::SkipEmptyParts);
@@ -382,45 +383,45 @@ int main(int argc, char ** argv)
if (!(scriptOptions & QDeclarativeViewer::Record) && !(scriptOptions & QDeclarativeViewer::Play))
scriptOptsUsage();
- viewer.setScriptOptions(scriptOptions);
- viewer.setScript(script);
+ viewer->setScriptOptions(scriptOptions);
+ viewer->setScript(script);
} else if (!script.isEmpty()) {
usage();
}
- viewer.addLibraryPath(QCoreApplication::applicationDirPath());
+ viewer->addLibraryPath(QCoreApplication::applicationDirPath());
foreach (QString lib, imports)
- viewer.addLibraryPath(lib);
+ viewer->addLibraryPath(lib);
foreach (QString plugin, plugins)
- viewer.addPluginPath(plugin);
+ viewer->addPluginPath(plugin);
- viewer.setNetworkCacheSize(cache);
- viewer.setRecordFile(recordfile);
- viewer.setSizeToView(sizeToView);
+ viewer->setNetworkCacheSize(cache);
+ viewer->setRecordFile(recordfile);
+ viewer->setSizeToView(sizeToView);
if (resizeview)
- viewer.setScaleView();
+ viewer->setScaleView();
if (fps>0)
- viewer.setRecordRate(fps);
+ viewer->setRecordRate(fps);
if (autorecord_to)
- viewer.setAutoRecord(autorecord_from,autorecord_to);
+ viewer->setAutoRecord(autorecord_from,autorecord_to);
if (!skin.isEmpty()) {
if (skin == "list") {
- foreach (QString s, viewer.builtinSkins())
+ foreach (QString s, viewer->builtinSkins())
qWarning() << qPrintable(s);
exit(0);
} else {
- viewer.setSkin(skin);
+ viewer->setSkin(skin);
}
}
if (devkeys)
- viewer.setDeviceKeys(true);
- viewer.setRecordDither(dither);
+ viewer->setDeviceKeys(true);
+ viewer->setRecordDither(dither);
if (recordargs.count())
- viewer.setRecordArgs(recordargs);
+ viewer->setRecordArgs(recordargs);
- viewer.setUseNativeFileBrowser(useNativeFileBrowser);
+ viewer->setUseNativeFileBrowser(useNativeFileBrowser);
if (fullScreen && maximized)
qWarning() << "Both -fullscreen and -maximized specified. Using -fullscreen.";
@@ -439,17 +440,19 @@ int main(int argc, char ** argv)
}
if (!fileName.isEmpty()) {
- viewer.open(fileName);
- fullScreen ? viewer.showFullScreen() : maximized ? viewer.showMaximized() : viewer.show();
+ viewer->open(fileName);
+ fullScreen ? viewer->showFullScreen() : maximized ? viewer->showMaximized() : viewer->show();
} else {
if (!useNativeFileBrowser)
- viewer.openFile();
- fullScreen ? viewer.showFullScreen() : maximized ? viewer.showMaximized() : viewer.show();
+ viewer->openFile();
+ fullScreen ? viewer->showFullScreen() : maximized ? viewer->showMaximized() : viewer->show();
if (useNativeFileBrowser)
- viewer.openFile();
+ viewer->openFile();
}
- viewer.setUseGL(useGL);
- viewer.raise();
+ viewer->setUseGL(useGL);
+ viewer->raise();
- exit(app.exec());
+ int rv = app.exec();
+ delete viewer;
+ exit(rv);
}