From db506f31cf98d050aef10534fb5dad7058f64caf Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 6 Dec 2010 08:57:21 +1000 Subject: Doc: make it clear that "z" affects sibling stacking order. Task-number: QTBUG-15802 --- src/declarative/graphicsitems/qdeclarativeitem.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 9d6fe12..932e68f 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -1809,9 +1809,9 @@ void QDeclarativeItem::setClip(bool c) /*! \qmlproperty real Item::z - Sets the stacking order of the item. By default the stacking order is 0. + Sets the stacking order of sibling items. By default the stacking order is 0. - Items with a higher stacking value are drawn on top of items with a + Items with a higher stacking value are drawn on top of siblings with a lower stacking order. Items with the same stacking value are drawn bottom up in the order they appear. Items with a negative stacking value are drawn under their parent's content. -- cgit v0.12 From ac977c4d57eba8fe2b71e51fc3d0b5eddd416e17 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Mon, 6 Dec 2010 12:46:35 +1000 Subject: Qt.include() docs weren't being picked up by qdoc This moves the Qt.include() docs to qdeclarativeengine.cpp and also documents it in the "Integrating JavaScript" page. Task-number: QTBUG-15855 --- doc/src/declarative/javascriptblocks.qdoc | 25 ++++++++++ .../integrating-javascript/includejs/app.qml | 56 ++++++++++++++++++++++ .../integrating-javascript/includejs/factorial.js | 49 +++++++++++++++++++ .../integrating-javascript/includejs/script.js | 48 +++++++++++++++++++ src/declarative/qml/qdeclarativeengine.cpp | 27 +++++++++++ src/declarative/qml/qdeclarativeinclude.cpp | 24 +--------- 6 files changed, 207 insertions(+), 22 deletions(-) create mode 100644 doc/src/snippets/declarative/integrating-javascript/includejs/app.qml create mode 100644 doc/src/snippets/declarative/integrating-javascript/includejs/factorial.js create mode 100644 doc/src/snippets/declarative/integrating-javascript/includejs/script.js diff --git a/doc/src/declarative/javascriptblocks.qdoc b/doc/src/declarative/javascriptblocks.qdoc index 16d0633..41b64da 100644 --- a/doc/src/declarative/javascriptblocks.qdoc +++ b/doc/src/declarative/javascriptblocks.qdoc @@ -143,6 +143,31 @@ As they are shared, stateless library files cannot access QML component instance objects or properties directly, although QML values can be passed as function parameters. + +\section2 Importing One JavaScript File From Another + +If a JavaScript file needs to use functions defined inside another JavaScript file, +the other file can be imported using the \l {QML:Qt::include()}{Qt.include()} +function. This imports all functions from the other file into the current file's +namespace. + +For example, the QML code below left calls \c showCalculations() in \c script.js, +which in turn can call \c factorial() in \c factorial.js, as it has included +\c factorial.js using \l {QML:Qt::include()}{Qt.include()}. + +\table +\row +\o {1,2} \snippet doc/src/snippets/declarative/integrating-javascript/includejs/app.qml 0 +\o \snippet doc/src/snippets/declarative/integrating-javascript/includejs/script.js 0 +\row +\o \snippet doc/src/snippets/declarative/integrating-javascript/includejs/factorial.js 0 +\endtable + +Notice that calling \l {QML:Qt::include()}{Qt.include()} imports all functions from +\c factorial.js into the \c MyScript namespace, which means the QML component can also +access \c factorial() directly as \c MyScript.factorial(). + + \section1 Running JavaScript at Startup It is occasionally necessary to run some imperative code at application (or diff --git a/doc/src/snippets/declarative/integrating-javascript/includejs/app.qml b/doc/src/snippets/declarative/integrating-javascript/includejs/app.qml new file mode 100644 index 0000000..2ecc475 --- /dev/null +++ b/doc/src/snippets/declarative/integrating-javascript/includejs/app.qml @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** 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:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +//![0] +import QtQuick 1.0 +import "script.js" as MyScript + +Item { + width: 100; height: 100 + + MouseArea { + anchors.fill: parent + onClicked: { + MyScript.showCalculations(10) + console.log("Call factorial() from QML:", + MyScript.factorial(10)) + } + } +} +//![0] diff --git a/doc/src/snippets/declarative/integrating-javascript/includejs/factorial.js b/doc/src/snippets/declarative/integrating-javascript/includejs/factorial.js new file mode 100644 index 0000000..0a01e9e --- /dev/null +++ b/doc/src/snippets/declarative/integrating-javascript/includejs/factorial.js @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** 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:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +//![0] +// factorial.js +function factorial(a) { + a = parseInt(a); + if (a <= 0) + return 1; + else + return a * factorial(a - 1); +} +//![0] diff --git a/doc/src/snippets/declarative/integrating-javascript/includejs/script.js b/doc/src/snippets/declarative/integrating-javascript/includejs/script.js new file mode 100644 index 0000000..7380412 --- /dev/null +++ b/doc/src/snippets/declarative/integrating-javascript/includejs/script.js @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** 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:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +//![0] +// script.js +Qt.include("factorial.js") + +function showCalculations(value) { + console.log("Call factorial() from script.js:", + factorial(value)); +} +//![0] diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index a8404f0..201e675 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -261,6 +261,33 @@ of their use. \endlist */ +/*! +\qmlmethod object Qt::include(string url, jsobject callback) + +Includes another JavaScript file. This method can only be used from within JavaScript files, +and not regular QML files. + +This imports all functions from \a url into the current script's namespace. + +Qt.include() returns an object that describes the status of the operation. The object has +a single property, \c {status}, that is set to one of the following values: + +\table +\header \o Symbol \o Value \o Description +\row \o result.OK \o 0 \o The include completed successfully. +\row \o result.LOADING \o 1 \o Data is being loaded from the network. +\row \o result.NETWORK_ERROR \o 2 \o A network error occurred while fetching the url. +\row \o result.EXCEPTION \o 3 \o A JavaScript exception occurred while executing the included code. +An additional \c exception property will be set in this case. +\endtable + +The \c status property will be updated as the operation progresses. + +If provided, \a callback is invoked when the operation completes. The callback is passed +the same object as is returned from the Qt.include() call. +*/ +// Qt.include() is implemented in qdeclarativeinclude.cpp + QDeclarativeEnginePrivate::QDeclarativeEnginePrivate(QDeclarativeEngine *e) : captureProperties(false), rootContext(0), isDebugging(false), diff --git a/src/declarative/qml/qdeclarativeinclude.cpp b/src/declarative/qml/qdeclarativeinclude.cpp index 1e240d7..a9ecdda 100644 --- a/src/declarative/qml/qdeclarativeinclude.cpp +++ b/src/declarative/qml/qdeclarativeinclude.cpp @@ -172,28 +172,8 @@ void QDeclarativeInclude::callback(QScriptEngine *engine, QScriptValue &callback } } -/*! -\qmlmethod object Qt::include(string url, jsobject callback) - -Include another JavaScript file. This method can only be used from within JavaScript files, -and not regular QML files. - -Qt.include() returns an object that describes the status of the operation. The object has -a single property, \c {status} that is set to one of the following values: - -\table -\header \o Symbol \o Value \o Description -\row \o result.OK \o 0 \o The include completed successfully. -\row \o result.LOADING \o 1 \o Data is being loaded from the network. -\row \o result.NETWORK_ERROR \o 2 \o A network error occurred while fetching the url. -\row \o result.EXCEPTION \o 3 \o A JavaScript exception occurred while executing the included code. -An additional \c exception property will be set in this case. -\endtable - -The return object's properties will be updated as the operation progresses. - -If provided, \a callback is invoked when the operation completes. The callback is passed -the same object as is returned from the Qt.include() call. +/* + Documented in qdeclarativeengine.cpp */ QScriptValue QDeclarativeInclude::include(QScriptContext *ctxt, QScriptEngine *engine) { -- cgit v0.12 From b74ec2156b2a1f1acd38443047da5bb26cb082b1 Mon Sep 17 00:00:00 2001 From: Christopher Ham Date: Mon, 6 Dec 2010 15:46:47 +1000 Subject: Cursor shouldn't blink while dragging cursor position A function resetCursorBlinkerTimer was introduced to QLineControl. Each time the cursor position in a textInput is updated, the blinker timer is reset. Task-number: QTBUG-15815 Reviewed-by: Martin Jones --- src/declarative/graphicsitems/qdeclarativetextinput.cpp | 1 + src/gui/widgets/qlinecontrol.cpp | 9 +++++++++ src/gui/widgets/qlinecontrol_p.h | 1 + 3 files changed, 11 insertions(+) diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index f8421a3..df103de 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -1479,6 +1479,7 @@ void QDeclarativeTextInput::cursorPosChanged() updateRect();//TODO: Only update rect between pos's updateMicroFocus(); emit cursorPositionChanged(); + d->control->resetCursorBlinkTimer(); if(!d->control->hasSelectedText()){ if(d->lastSelectionStart != d->control->cursor()){ diff --git a/src/gui/widgets/qlinecontrol.cpp b/src/gui/widgets/qlinecontrol.cpp index f338f40..5ea9dc4 100644 --- a/src/gui/widgets/qlinecontrol.cpp +++ b/src/gui/widgets/qlinecontrol.cpp @@ -1308,6 +1308,15 @@ void QLineControl::setCursorBlinkPeriod(int msec) m_blinkPeriod = msec; } +void QLineControl::resetCursorBlinkTimer() +{ + if (m_blinkPeriod == 0 || m_blinkTimer == 0) + return; + killTimer(m_blinkTimer); + m_blinkTimer = startTimer(m_blinkPeriod / 2); + m_blinkStatus = 1; +} + void QLineControl::timerEvent(QTimerEvent *event) { if (event->timerId() == m_blinkTimer) { diff --git a/src/gui/widgets/qlinecontrol_p.h b/src/gui/widgets/qlinecontrol_p.h index 7068f62..d881acf 100644 --- a/src/gui/widgets/qlinecontrol_p.h +++ b/src/gui/widgets/qlinecontrol_p.h @@ -296,6 +296,7 @@ public: int cursorBlinkPeriod() const { return m_blinkPeriod; } void setCursorBlinkPeriod(int msec); + void resetCursorBlinkTimer(); QString cancelText() const { return m_cancelText; } void setCancelText(const QString &text) { m_cancelText = text; } -- cgit v0.12 From 2051459dd9a257c6492c755a583ff331e7009012 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Mon, 6 Dec 2010 17:49:04 +1000 Subject: Some doc clarification for components and javascript integration --- doc/src/declarative/javascriptblocks.qdoc | 5 ++--- src/declarative/qml/qdeclarativecomponent.cpp | 28 +++++++++++++++------------ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/doc/src/declarative/javascriptblocks.qdoc b/doc/src/declarative/javascriptblocks.qdoc index 41b64da..155bd6e 100644 --- a/doc/src/declarative/javascriptblocks.qdoc +++ b/doc/src/declarative/javascriptblocks.qdoc @@ -94,9 +94,8 @@ Both relative and absolute JavaScript URLs can be imported. In the case of a relative URL, the location is resolved relative to the location of the \l {QML Document} that contains the import. If the script file is not accessible, an error will occur. If the JavaScript needs to be fetched from a network -resource, the QML document has a "Loading" -\l {QDeclarativeComponent::status()}{status} until the script has been -downloaded. +resource, the component's \l {QDeclarativeComponent::status()}{status} is set to +"Loading" until the script has been downloaded. Imported JavaScript files are always qualified using the "as" keyword. The qualifier for JavaScript files must be unique, so there is always a one-to-one diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index 63bde0f..77fc925 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -147,32 +147,36 @@ class QByteArray; Components are reusable, encapsulated QML elements with well-defined interfaces. Components are often defined by \l {qdeclarativedocuments.html}{component files} - - that is, \c .qml files. The \e Component element allows components to be defined - within QML items rather than in a separate file. This may be useful for reusing - a small component within a QML file, or for defining a component that logically - belongs with other QML components within a file. + that is, \c .qml files. The \e Component element essentially allows QML components + to be defined inline, within a \l {QML Document}{QML document}, rather than as a separate QML file. + This may be useful for reusing a small component within a QML file, or for defining + a component that logically belongs with other QML components within a file. For example, here is a component that is used by multiple \l Loader objects. - It contains a top level \l Rectangle item: + It contains a single item, a \l Rectangle: \snippet doc/src/snippets/declarative/component.qml 0 Notice that while a \l Rectangle by itself would be automatically rendered and displayed, this is not the case for the above rectangle because it is defined inside a \c Component. The component encapsulates the - QML elements within, as if they were defined in a separate \c .qml + QML elements within, as if they were defined in a separate QML file, and is not loaded until requested (in this case, by the two \l Loader objects). - A Component cannot contain anything other - than an \c id and a single top level item. While the \c id is optional, - the top level item is not; you cannot define an empty component. + Defining a \c Component is similar to defining a \l {QML Document}{QML document}. + A QML document has a single top-level item that defines the behaviors and + properties of that component, and cannot define properties or behaviors outside + of that top-level item. In the same way, a \c Component definition contains a single + top level item (which in the above example is a \l Rectangle) and cannot define any + data outside of this item, with the exception of an \e id (which in the above example + is \e redSquare). - The Component element is commonly used to provide graphical components - for views. For example, the ListView::delegate property requires a Component + The \c Component element is commonly used to provide graphical components + for views. For example, the ListView::delegate property requires a \c Component to specify how each list item is to be displayed. - Component objects can also be dynamically created using + \c Component objects can also be created dynamically using \l{QML:Qt::createComponent()}{Qt.createComponent()}. */ -- cgit v0.12 From 2e7cfca6089a0923698b9cd208f79a660e058caa Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Mon, 6 Dec 2010 17:49:17 +1000 Subject: Document support for QVariantList and QVariantMap type conversion --- doc/src/declarative/qtbinding.qdoc | 34 ++++++++++- .../qtbinding/variantlistmap/MyItem.qml | 54 +++++++++++++++++ .../declarative/qtbinding/variantlistmap/main.cpp | 67 ++++++++++++++++++++++ .../qtbinding/variantlistmap/variantlistmap.pro | 2 + 4 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 doc/src/snippets/declarative/qtbinding/variantlistmap/MyItem.qml create mode 100644 doc/src/snippets/declarative/qtbinding/variantlistmap/main.cpp create mode 100644 doc/src/snippets/declarative/qtbinding/variantlistmap/variantlistmap.pro diff --git a/doc/src/declarative/qtbinding.qdoc b/doc/src/declarative/qtbinding.qdoc index 71f41bc..04b8ca6 100644 --- a/doc/src/declarative/qtbinding.qdoc +++ b/doc/src/declarative/qtbinding.qdoc @@ -426,6 +426,7 @@ By default, QML recognizes the following data types: \o QSize, QSizeF \o QRect, QRectF \o QVariant +\o QVariantList, QVariantMap \o QObject* \o Enumerations declared with Q_ENUMS() \endlist @@ -434,6 +435,37 @@ To allow a custom C++ type to be created or used in QML, the C++ class must be r type using qmlRegisterType(), as shown in the \l {Defining new QML elements} section above. +\section2 JavaScript arrays and objects + +There is built-in support for automatic type conversion between QVariantList and JavaScript +arrays, and QVariantMap and JavaScript objects. + +For example, the function defined in QML below left expects two arguments, an array and an object, and prints +their contents using the standard JavaScript syntax for array and object item access. The C++ code +below right calls this function, passing a QVariantList and a QVariantMap, which are automatically +converted to JavaScript array and object values, repectively: + +\table +\row +\o \snippet doc/src/snippets/declarative/qtbinding/variantlistmap/MyItem.qml 0 +\o \snippet doc/src/snippets/declarative/qtbinding/variantlistmap/main.cpp 0 +\endtable + +This produces output like: + +\code +Array item: 10 +Array item: #00ff00 +Array item: bottles +Object item: language = QML +Object item: released = Tue Sep 21 2010 00:00:00 GMT+1000 (EST) +\endcode + +Similarly, if a C++ type uses a QVariantList or QVariantMap type for a property or method +parameter, the value can be created as a JavaScript array or object in the QML +side, and is automatically converted to a QVariantList or QVariantMap when it is passed to C++. + + \section2 Using enumerations of a custom type To use an enumeration from a custom C++ component, the enumeration must be declared with Q_ENUMS() to @@ -455,7 +487,7 @@ See the \l {Tutorial: Writing QML extensions with C++}{Writing QML extensions wi the \l {Extending QML in C++} reference documentation for more information. -\section2 Automatic type conversion +\section2 Automatic type conversion from strings As a convenience, some basic types can be specified in QML using format strings to make it easier to pass simple values from QML to C++. diff --git a/doc/src/snippets/declarative/qtbinding/variantlistmap/MyItem.qml b/doc/src/snippets/declarative/qtbinding/variantlistmap/MyItem.qml new file mode 100644 index 0000000..dd59fed --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/variantlistmap/MyItem.qml @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** 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:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 1.0 + +//![0] +// MyItem.qml +Item { + function readValues(anArray, anObject) { + for (var i=0; i +#include + +int main(int argc, char *argv[]) { + QApplication app(argc, argv); + +//![0] +// C++ +QDeclarativeView view(QUrl::fromLocalFile("MyItem.qml")); + +QVariantList list; +list << 10 << Qt::green << "bottles"; + +QVariantMap map; +map.insert("language", "QML"); +map.insert("released", QDate(2010, 9, 21)); + +QMetaObject::invokeMethod(view.rootObject(), "readValues", + Q_ARG(QVariant, QVariant::fromValue(list)), + Q_ARG(QVariant, QVariant::fromValue(map))); +//![0] + + view.setSource(QUrl::fromLocalFile("MyItem.qml")); + view.show(); + + return app.exec(); +} + diff --git a/doc/src/snippets/declarative/qtbinding/variantlistmap/variantlistmap.pro b/doc/src/snippets/declarative/qtbinding/variantlistmap/variantlistmap.pro new file mode 100644 index 0000000..68eeaf2 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/variantlistmap/variantlistmap.pro @@ -0,0 +1,2 @@ +QT += declarative +SOURCES += main.cpp -- cgit v0.12 From 16447b1193fedf5fdcf1f3d270fa73c5036a1ba0 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 7 Dec 2010 10:41:10 +1000 Subject: Fix openDatabaseSync() to not create unused directory Task-number: QTBUG-15909 Reviewed-by: Warwick Allison --- src/declarative/qml/qdeclarativesqldatabase.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/declarative/qml/qdeclarativesqldatabase.cpp b/src/declarative/qml/qdeclarativesqldatabase.cpp index 45f277e..3f53111 100644 --- a/src/declarative/qml/qdeclarativesqldatabase.cpp +++ b/src/declarative/qml/qdeclarativesqldatabase.cpp @@ -375,7 +375,6 @@ static QScriptValue qmlsqldatabase_open_sync(QScriptContext *context, QScriptEng } else { created = !QFile::exists(basename+QLatin1String(".sqlite")); database = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"), dbid); - QDir().mkpath(basename); if (created) { ini.setValue(QLatin1String("Name"), dbname); if (dbcreationCallback.isFunction()) -- cgit v0.12 From f3a7c4e458edb40957186e52012f15767eb8c1f4 Mon Sep 17 00:00:00 2001 From: Joona Petrell Date: Tue, 7 Dec 2010 12:49:54 +1000 Subject: Update QtGui def files Task-number: QTBUG-15815 --- src/s60installs/bwins/QtGuiu.def | 1 + src/s60installs/eabi/QtGuiu.def | 1 + 2 files changed, 2 insertions(+) diff --git a/src/s60installs/bwins/QtGuiu.def b/src/s60installs/bwins/QtGuiu.def index 6a33fc3..355b46a 100644 --- a/src/s60installs/bwins/QtGuiu.def +++ b/src/s60installs/bwins/QtGuiu.def @@ -12905,4 +12905,5 @@ EXPORTS ?reactivateDeferredActiveObjects@QEventDispatcherS60@@UAEXXZ @ 12904 NONAME ; void QEventDispatcherS60::reactivateDeferredActiveObjects(void) ?userData@QStaticTextItem@@QBEPAVQStaticTextUserData@@XZ @ 12905 NONAME ; class QStaticTextUserData * QStaticTextItem::userData(void) const ?populate@QTextureGlyphCache@@QAE_NPAVQFontEngine@@HPBIPBUQFixedPoint@@@Z @ 12906 NONAME ; bool QTextureGlyphCache::populate(class QFontEngine *, int, unsigned int const *, struct QFixedPoint const *) + ?resetCursorBlinkTimer@QLineControl@@QAEXXZ @ 12907 NONAME ; void QLineControl::resetCursorBlinkTimer(void) diff --git a/src/s60installs/eabi/QtGuiu.def b/src/s60installs/eabi/QtGuiu.def index 54768a1..6b8dd7c 100644 --- a/src/s60installs/eabi/QtGuiu.def +++ b/src/s60installs/eabi/QtGuiu.def @@ -12105,4 +12105,5 @@ EXPORTS _ZN15QStaticTextItemD1Ev @ 12104 NONAME _ZN15QStaticTextItemD2Ev @ 12105 NONAME _ZN19QEventDispatcherS6031reactivateDeferredActiveObjectsEv @ 12106 NONAME + _ZN12QLineControl21resetCursorBlinkTimerEv @ 12107 NONAME -- cgit v0.12 From ddeae91ab54bb92b813304778ab8dc4037937274 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 8 Dec 2010 16:22:04 +1000 Subject: ListView: Fix calculation of currentItem position when out of view. The calculation of position of currentItem when it is out of the visible area was bogus. Task-number: QTBUG-15525 Reviewed-by: Bea Lam --- .../graphicsitems/qdeclarativelistview.cpp | 12 ++- .../qdeclarativelistview/data/displaylist.qml | 9 ++- .../tst_qdeclarativelistview.cpp | 86 ++++++++++++++++++++++ 3 files changed, 102 insertions(+), 5 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 845da79..2dfee3b 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -739,16 +739,20 @@ void QDeclarativeListViewPrivate::layout() return; } if (!visibleItems.isEmpty()) { - qreal oldEnd = visibleItems.last()->endPosition(); + bool fixedCurrent = currentItem && visibleItems.first()->item == currentItem->item; + qreal sum = visibleItems.first()->size(); qreal pos = visibleItems.first()->position() + visibleItems.first()->size() + spacing; for (int i=1; i < visibleItems.count(); ++i) { FxListItem *item = visibleItems.at(i); item->setPosition(pos); pos += item->size() + spacing; + sum += item->size(); + fixedCurrent = fixedCurrent || (currentItem && item->item == currentItem->item); } - // move current item if it is after the visible items. - if (currentItem && currentIndex > lastVisibleIndex()) - currentItem->setPosition(currentItem->position() + (visibleItems.last()->endPosition() - oldEnd)); + averageSize = qRound(sum / visibleItems.count()); + // move current item if it is not a visible item. + if (currentIndex >= 0 && currentItem && !fixedCurrent) + currentItem->setPosition(positionAt(currentIndex)); } q->refill(); minExtentDirty = true; diff --git a/tests/auto/declarative/qdeclarativelistview/data/displaylist.qml b/tests/auto/declarative/qdeclarativelistview/data/displaylist.qml index 487b70e..9d58530 100644 --- a/tests/auto/declarative/qdeclarativelistview/data/displaylist.qml +++ b/tests/auto/declarative/qdeclarativelistview/data/displaylist.qml @@ -1,6 +1,8 @@ import QtQuick 1.0 Rectangle { + id: root + property real delegateHeight: 20 width: 240 height: 320 color: "#ffffff" @@ -10,7 +12,8 @@ Rectangle { Rectangle { id: wrapper objectName: "wrapper" - height: 20 + height: root.delegateHeight + Behavior on height { NumberAnimation {} } width: 240 Text { text: index @@ -20,6 +23,10 @@ Rectangle { objectName: "displayText" text: display } + Text { + x: 200 + text: wrapper.y + } color: ListView.isCurrentItem ? "lightsteelblue" : "white" } }, diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp index 759caf2..22ebb1a 100644 --- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp +++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp @@ -103,6 +103,7 @@ private slots: void resizeView(); void sizeLessThan1(); void QTBUG_14821(); + void resizeDelegate(); private: template void items(); @@ -1406,6 +1407,8 @@ void tst_QDeclarativeListView::resetModel() QTRY_VERIFY(display != 0); QTRY_COMPARE(display->text(), strings.at(i)); } + + delete canvas; } void tst_QDeclarativeListView::propertyChanges() @@ -1613,6 +1616,8 @@ void tst_QDeclarativeListView::manualHighlight() QTRY_COMPARE(listview->currentIndex(), 2); QTRY_COMPARE(listview->currentItem(), findItem(contentItem, "wrapper", 2)); QTRY_COMPARE(listview->highlightItem()->y(), listview->currentItem()->y()); + + delete canvas; } void tst_QDeclarativeListView::QTBUG_11105() @@ -1752,6 +1757,8 @@ void tst_QDeclarativeListView::footer() model.clear(); QTRY_COMPARE(footer->y(), 0.0); + + delete canvas; } void tst_QDeclarativeListView::resizeView() @@ -1794,6 +1801,8 @@ void tst_QDeclarativeListView::resizeView() QMetaObject::invokeMethod(canvas->rootObject(), "heightRatio", Q_RETURN_ARG(QVariant, heightRatio)); QCOMPARE(heightRatio.toReal(), 0.25); + + delete canvas; } void tst_QDeclarativeListView::sizeLessThan1() @@ -1849,6 +1858,83 @@ void tst_QDeclarativeListView::QTBUG_14821() listview->incrementCurrentIndex(); QCOMPARE(listview->currentIndex(), 0); + + delete canvas; +} + +void tst_QDeclarativeListView::resizeDelegate() +{ + QDeclarativeView *canvas = createView(); + + QStringList strings; + for (int i = 0; i < 30; ++i) + strings << QString::number(i); + QStringListModel model(strings); + + QDeclarativeContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/displaylist.qml")); + qApp->processEvents(); + + QDeclarativeListView *listview = findItem(canvas->rootObject(), "list"); + QTRY_VERIFY(listview != 0); + + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); + + QTRY_COMPARE(listview->count(), model.rowCount()); + + listview->setCurrentIndex(25); + listview->setContentY(0); + + for (int i = 0; i < 16; ++i) { + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); + QVERIFY(item != 0); + QCOMPARE(item->y(), i*20.0); + } + + QCOMPARE(listview->currentItem()->y(), 500.0); + QTRY_COMPARE(listview->highlightItem()->y(), 500.0); + + canvas->rootObject()->setProperty("delegateHeight", 30); + qApp->processEvents(); + + for (int i = 0; i < 11; ++i) { + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); + QVERIFY(item != 0); + QTRY_COMPARE(item->y(), i*30.0); + } + + QTRY_COMPARE(listview->currentItem()->y(), 750.0); + QTRY_COMPARE(listview->highlightItem()->y(), 750.0); + + listview->setCurrentIndex(1); + listview->positionViewAtIndex(25, QDeclarativeListView::Beginning); + listview->positionViewAtIndex(5, QDeclarativeListView::Beginning); + + for (int i = 5; i < 16; ++i) { + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); + QVERIFY(item != 0); + QCOMPARE(item->y(), i*30.0); + } + + QTRY_COMPARE(listview->currentItem()->y(), 30.0); + QTRY_COMPARE(listview->highlightItem()->y(), 30.0); + + canvas->rootObject()->setProperty("delegateHeight", 20); + qApp->processEvents(); + + for (int i = 5; i < 11; ++i) { + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); + QVERIFY(item != 0); + QTRY_COMPARE(item->y(), 150 + (i-5)*20.0); + } + + QTRY_COMPARE(listview->currentItem()->y(), 70.0); + QTRY_COMPARE(listview->highlightItem()->y(), 70.0); + + delete canvas; } void tst_QDeclarativeListView::qListModelInterface_items() -- cgit v0.12 From 58ae252e5555dc379b4ed500532bc51ff7bebc25 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 9 Dec 2010 10:12:35 +1000 Subject: highlightFollowsCurrentItem: false was not always honored In some cases ListView and GridView would position the highlight despite highlightFollowsCurrentItem: false being specified. Task-number: QTBUG-15972 Reviewed-by: Michael Brasser --- src/declarative/graphicsitems/qdeclarativegridview.cpp | 14 +++++++++----- src/declarative/graphicsitems/qdeclarativelistview.cpp | 18 ++++++++++++------ .../qdeclarativegridview/data/manual-highlight.qml | 4 ++-- .../qdeclarativegridview/tst_qdeclarativegridview.cpp | 15 +++++++++++---- .../qdeclarativelistview/data/manual-highlight.qml | 2 +- .../qdeclarativelistview/tst_qdeclarativelistview.cpp | 11 +++++++++-- 6 files changed, 44 insertions(+), 20 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index 1615b0f..4a6a9dc 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -735,7 +735,7 @@ void QDeclarativeGridViewPrivate::createHighlight() QDeclarative_setParent_noEvent(item, q->contentItem()); item->setParentItem(q->contentItem()); highlight = new FxGridItem(item, q); - if (currentItem) + if (currentItem && autoHighlight) highlight->setPosition(currentItem->colPos(), currentItem->rowPos()); highlightXAnimator = new QSmoothedAnimation(q); highlightXAnimator->target = QDeclarativeProperty(highlight->item, QLatin1String("x")); @@ -1253,7 +1253,8 @@ void QDeclarativeGridView::setModel(const QVariant &model) d->moveReason = QDeclarativeGridViewPrivate::SetIndex; d->updateCurrent(d->currentIndex); if (d->highlight && d->currentItem) { - d->highlight->setPosition(d->currentItem->colPos(), d->currentItem->rowPos()); + if (d->autoHighlight) + d->highlight->setPosition(d->currentItem->colPos(), d->currentItem->rowPos()); d->updateTrackedItem(); } d->moveReason = QDeclarativeGridViewPrivate::Other; @@ -1321,7 +1322,8 @@ void QDeclarativeGridView::setDelegate(QDeclarativeComponent *delegate) d->moveReason = QDeclarativeGridViewPrivate::SetIndex; d->updateCurrent(d->currentIndex); if (d->highlight && d->currentItem) { - d->highlight->setPosition(d->currentItem->colPos(), d->currentItem->rowPos()); + if (d->autoHighlight) + d->highlight->setPosition(d->currentItem->colPos(), d->currentItem->rowPos()); d->updateTrackedItem(); } d->moveReason = QDeclarativeGridViewPrivate::Other; @@ -2241,7 +2243,8 @@ void QDeclarativeGridView::componentComplete() else d->updateCurrent(d->currentIndex); if (d->highlight && d->currentItem) { - d->highlight->setPosition(d->currentItem->colPos(), d->currentItem->rowPos()); + if (d->autoHighlight) + d->highlight->setPosition(d->currentItem->colPos(), d->currentItem->rowPos()); d->updateTrackedItem(); } d->moveReason = QDeclarativeGridViewPrivate::Other; @@ -2649,7 +2652,8 @@ void QDeclarativeGridView::modelReset() d->moveReason = QDeclarativeGridViewPrivate::SetIndex; d->updateCurrent(d->currentIndex); if (d->highlight && d->currentItem) { - d->highlight->setPosition(d->currentItem->colPos(), d->currentItem->rowPos()); + if (d->autoHighlight) + d->highlight->setPosition(d->currentItem->colPos(), d->currentItem->rowPos()); d->updateTrackedItem(); } d->moveReason = QDeclarativeGridViewPrivate::Other; diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 2dfee3b..d008f91 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -1571,7 +1571,8 @@ void QDeclarativeListView::setModel(const QVariant &model) d->moveReason = QDeclarativeListViewPrivate::SetIndex; d->updateCurrent(d->currentIndex); if (d->highlight && d->currentItem) { - d->highlight->setPosition(d->currentItem->position()); + if (d->autoHighlight) + d->highlight->setPosition(d->currentItem->position()); d->updateTrackedItem(); } } @@ -1642,7 +1643,8 @@ void QDeclarativeListView::setDelegate(QDeclarativeComponent *delegate) d->moveReason = QDeclarativeListViewPrivate::SetIndex; d->updateCurrent(d->currentIndex); if (d->highlight && d->currentItem) { - d->highlight->setPosition(d->currentItem->position()); + if (d->autoHighlight) + d->highlight->setPosition(d->currentItem->position()); d->updateTrackedItem(); } } @@ -2632,8 +2634,10 @@ void QDeclarativeListView::positionViewAtIndex(int index, int mode) cancelFlick(); d->setPosition(pos); if (d->highlight) { - d->highlight->setPosition(d->currentItem->itemPosition()); - d->highlight->setSize(d->currentItem->itemSize()); + if (d->autoHighlight) { + d->highlight->setPosition(d->currentItem->itemPosition()); + d->highlight->setSize(d->currentItem->itemSize()); + } d->updateHighlight(); } } @@ -2679,7 +2683,8 @@ void QDeclarativeListView::componentComplete() else d->updateCurrent(d->currentIndex); if (d->highlight && d->currentItem) { - d->highlight->setPosition(d->currentItem->position()); + if (d->autoHighlight) + d->highlight->setPosition(d->currentItem->position()); d->updateTrackedItem(); } d->moveReason = QDeclarativeListViewPrivate::Other; @@ -3142,7 +3147,8 @@ void QDeclarativeListView::modelReset() d->moveReason = QDeclarativeListViewPrivate::SetIndex; d->updateCurrent(d->currentIndex); if (d->highlight && d->currentItem) { - d->highlight->setPosition(d->currentItem->position()); + if (d->autoHighlight) + d->highlight->setPosition(d->currentItem->position()); d->updateTrackedItem(); } d->moveReason = QDeclarativeListViewPrivate::Other; diff --git a/tests/auto/declarative/qdeclarativegridview/data/manual-highlight.qml b/tests/auto/declarative/qdeclarativegridview/data/manual-highlight.qml index 7bb2c95..d082847 100644 --- a/tests/auto/declarative/qdeclarativegridview/data/manual-highlight.qml +++ b/tests/auto/declarative/qdeclarativegridview/data/manual-highlight.qml @@ -28,8 +28,8 @@ Item { objectName: "highlight" width: 80; height: 80 color: "lightsteelblue"; radius: 5 - y: grid.currentItem.y - x: grid.currentItem.x + y: grid.currentItem.y+5 + x: grid.currentItem.x+5 } } diff --git a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp index 7998e30..fd5d140 100644 --- a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp +++ b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp @@ -1215,15 +1215,22 @@ void tst_QDeclarativeGridView::manualHighlight() QTRY_COMPARE(gridview->currentIndex(), 0); QTRY_COMPARE(gridview->currentItem(), findItem(contentItem, "wrapper", 0)); - QTRY_COMPARE(gridview->highlightItem()->y(), gridview->currentItem()->y()); - QTRY_COMPARE(gridview->highlightItem()->x(), gridview->currentItem()->x()); + QTRY_COMPARE(gridview->highlightItem()->y() - 5, gridview->currentItem()->y()); + QTRY_COMPARE(gridview->highlightItem()->x() - 5, gridview->currentItem()->x()); gridview->setCurrentIndex(2); QTRY_COMPARE(gridview->currentIndex(), 2); QTRY_COMPARE(gridview->currentItem(), findItem(contentItem, "wrapper", 2)); - QTRY_COMPARE(gridview->highlightItem()->y(), gridview->currentItem()->y()); - QTRY_COMPARE(gridview->highlightItem()->x(), gridview->currentItem()->x()); + QTRY_COMPARE(gridview->highlightItem()->y() - 5, gridview->currentItem()->y()); + QTRY_COMPARE(gridview->highlightItem()->x() - 5, gridview->currentItem()->x()); + + gridview->positionViewAtIndex(8, QDeclarativeGridView::Contain); + + QTRY_COMPARE(gridview->currentIndex(), 2); + QTRY_COMPARE(gridview->currentItem(), findItem(contentItem, "wrapper", 2)); + QTRY_COMPARE(gridview->highlightItem()->y() - 5, gridview->currentItem()->y()); + QTRY_COMPARE(gridview->highlightItem()->x() - 5, gridview->currentItem()->x()); } void tst_QDeclarativeGridView::footer() diff --git a/tests/auto/declarative/qdeclarativelistview/data/manual-highlight.qml b/tests/auto/declarative/qdeclarativelistview/data/manual-highlight.qml index d8cfd9a..a32a194 100644 --- a/tests/auto/declarative/qdeclarativelistview/data/manual-highlight.qml +++ b/tests/auto/declarative/qdeclarativelistview/data/manual-highlight.qml @@ -28,7 +28,7 @@ Item { objectName: "highlight" width: 180; height: 20 color: "lightsteelblue"; radius: 5 - y: list.currentItem.y + y: list.currentItem.y+5 } } diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp index 22ebb1a..ff90d32 100644 --- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp +++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp @@ -1609,13 +1609,20 @@ void tst_QDeclarativeListView::manualHighlight() QTRY_COMPARE(listview->currentIndex(), 0); QTRY_COMPARE(listview->currentItem(), findItem(contentItem, "wrapper", 0)); - QTRY_COMPARE(listview->highlightItem()->y(), listview->currentItem()->y()); + QTRY_COMPARE(listview->highlightItem()->y() - 5, listview->currentItem()->y()); listview->setCurrentIndex(2); QTRY_COMPARE(listview->currentIndex(), 2); QTRY_COMPARE(listview->currentItem(), findItem(contentItem, "wrapper", 2)); - QTRY_COMPARE(listview->highlightItem()->y(), listview->currentItem()->y()); + QTRY_COMPARE(listview->highlightItem()->y() - 5, listview->currentItem()->y()); + + // QTBUG-15972 + listview->positionViewAtIndex(3, QDeclarativeListView::Contain); + + QTRY_COMPARE(listview->currentIndex(), 2); + QTRY_COMPARE(listview->currentItem(), findItem(contentItem, "wrapper", 2)); + QTRY_COMPARE(listview->highlightItem()->y() - 5, listview->currentItem()->y()); delete canvas; } -- cgit v0.12 From 1e33b4ea1374b499bf938bc2f370f12404b76a58 Mon Sep 17 00:00:00 2001 From: Joona Petrell Date: Thu, 9 Dec 2010 16:40:11 +1000 Subject: Update QtGui bwins def file for QTBUG-15615 --- src/s60installs/bwins/QtGuiu.def | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/s60installs/bwins/QtGuiu.def b/src/s60installs/bwins/QtGuiu.def index 355b46a..bf4d99f 100644 --- a/src/s60installs/bwins/QtGuiu.def +++ b/src/s60installs/bwins/QtGuiu.def @@ -2725,7 +2725,7 @@ EXPORTS ?clearSelection@QTextCursor@@QAEXXZ @ 2724 NONAME ; void QTextCursor::clearSelection(void) ?clearSpans@QTableView@@QAEXXZ @ 2725 NONAME ; void QTableView::clearSpans(void) ?clearString@QLineControl@@ABE?AVQString@@II@Z @ 2726 NONAME ; class QString QLineControl::clearString(unsigned int, unsigned int) const - ?clearSubFocus@QGraphicsItemPrivate@@QAEXPAVQGraphicsItem@@@Z @ 2727 NONAME ; void QGraphicsItemPrivate::clearSubFocus(class QGraphicsItem *) + ?clearSubFocus@QGraphicsItemPrivate@@QAEXPAVQGraphicsItem@@@Z @ 2727 NONAME ABSENT ; void QGraphicsItemPrivate::clearSubFocus(class QGraphicsItem *) ?clearUndo@QLineControl@@QAEXXZ @ 2728 NONAME ; void QLineControl::clearUndo(void) ?click@QAbstractButton@@QAEXXZ @ 2729 NONAME ; void QAbstractButton::click(void) ?clicked@QAbstractButton@@IAEX_N@Z @ 2730 NONAME ; void QAbstractButton::clicked(bool) @@ -9914,7 +9914,7 @@ EXPORTS ?setStyleSheet@QWidget@@QAEXABVQString@@@Z @ 9913 NONAME ; void QWidget::setStyleSheet(class QString const &) ?setStyleStrategy@QFont@@QAEXW4StyleStrategy@1@@Z @ 9914 NONAME ; void QFont::setStyleStrategy(enum QFont::StyleStrategy) ?setStyle_helper@QWidgetPrivate@@QAEXPAVQStyle@@_N1@Z @ 9915 NONAME ; void QWidgetPrivate::setStyle_helper(class QStyle *, bool, bool) - ?setSubFocus@QGraphicsItemPrivate@@QAEXPAVQGraphicsItem@@@Z @ 9916 NONAME ; void QGraphicsItemPrivate::setSubFocus(class QGraphicsItem *) + ?setSubFocus@QGraphicsItemPrivate@@QAEXPAVQGraphicsItem@@@Z @ 9916 NONAME ABSENT ; void QGraphicsItemPrivate::setSubFocus(class QGraphicsItem *) ?setSubTitle@QWizardPage@@QAEXABVQString@@@Z @ 9917 NONAME ; void QWizardPage::setSubTitle(class QString const &) ?setSubTitleFormat@QWizard@@QAEXW4TextFormat@Qt@@@Z @ 9918 NONAME ; void QWizard::setSubTitleFormat(enum Qt::TextFormat) ?setSubmitPolicy@QDataWidgetMapper@@QAEXW4SubmitPolicy@1@@Z @ 9919 NONAME ; void QDataWidgetMapper::setSubmitPolicy(enum QDataWidgetMapper::SubmitPolicy) @@ -12906,4 +12906,6 @@ EXPORTS ?userData@QStaticTextItem@@QBEPAVQStaticTextUserData@@XZ @ 12905 NONAME ; class QStaticTextUserData * QStaticTextItem::userData(void) const ?populate@QTextureGlyphCache@@QAE_NPAVQFontEngine@@HPBIPBUQFixedPoint@@@Z @ 12906 NONAME ; bool QTextureGlyphCache::populate(class QFontEngine *, int, unsigned int const *, struct QFixedPoint const *) ?resetCursorBlinkTimer@QLineControl@@QAEXXZ @ 12907 NONAME ; void QLineControl::resetCursorBlinkTimer(void) + ?setSubFocus@QGraphicsItemPrivate@@QAEXPAVQGraphicsItem@@0@Z @ 12908 NONAME ; void QGraphicsItemPrivate::setSubFocus(class QGraphicsItem *, class QGraphicsItem *) + ?clearSubFocus@QGraphicsItemPrivate@@QAEXPAVQGraphicsItem@@0@Z @ 12909 NONAME ; void QGraphicsItemPrivate::clearSubFocus(class QGraphicsItem *, class QGraphicsItem *) -- cgit v0.12 From bb07641213dfc4c949707500c3d665fae5f4b9f0 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 7 Dec 2010 14:19:43 +1000 Subject: QDeclarativeProperty doc improvements --- src/declarative/qml/qdeclarativeproperty.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/declarative/qml/qdeclarativeproperty.cpp b/src/declarative/qml/qdeclarativeproperty.cpp index df0917f..60edd64 100644 --- a/src/declarative/qml/qdeclarativeproperty.cpp +++ b/src/declarative/qml/qdeclarativeproperty.cpp @@ -77,15 +77,28 @@ a property on a specific object instance. To read a property's value, programme QDeclarativeProperty instance and call the read() method. Likewise to write a property value the write() method is used. +For example, for the following QML code: + +\qml +// MyItem.qml +import QtQuick 1.0 + +Text { text: "A bit of text" } +\endqml + +The \l Text object's properties could be accessed using QDeclarativeProperty, like this: + \code +#include +#include -QObject *object = declarativeComponent.create(); +... -QDeclarativeProperty property(object, "font.pixelSize"); +QDeclarativeView view(QUrl::fromLocalFile("MyItem.qml")); +QDeclarativeProperty property(view.rootObject(), "font.pixelSize"); qWarning() << "Current pixel size:" << property.read().toInt(); property.write(24); qWarning() << "Pixel size should now be 24:" << property.read().toInt(); - \endcode */ -- cgit v0.12 From b8da3a08945091d077d3096efae23d613b24210b Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 9 Dec 2010 14:23:42 +1000 Subject: Improvements to anchoring docs Make it clear that anchor margins only apply to anchors. Also document that anchor and absolute positioning cannot be mixed. --- doc/src/declarative/anchor-layout.qdoc | 66 ++++++++++++++++------ src/declarative/graphicsitems/qdeclarativeitem.cpp | 2 + 2 files changed, 51 insertions(+), 17 deletions(-) diff --git a/doc/src/declarative/anchor-layout.qdoc b/doc/src/declarative/anchor-layout.qdoc index b77ce36..f5d5697 100644 --- a/doc/src/declarative/anchor-layout.qdoc +++ b/doc/src/declarative/anchor-layout.qdoc @@ -30,6 +30,8 @@ \target anchor-layout \title Anchor-based Layout in QML +\section1 Overview + In addition to the more traditional \l Grid, \l Row, and \l Column, QML also provides a way to layout items using the concept of \e anchors. Each item can be thought of as having a set of 7 invisible "anchor lines": @@ -54,20 +56,6 @@ In this case, the left edge of \e rect2 is bound to the right edge of \e rect1, \image edge1.png -The anchoring system also allows you to specify margins and offsets. Margins specify the amount of empty space to leave to the outside of an item, while offsets allow you to manipulate positioning using the center anchor lines. Note that margins specified using the anchor layout system only have meaning for anchors; they won't have any effect when using other layouts or absolute positioning. - -\image margins_qml.png - -The following example specifies a left margin: - -\code -Rectangle { id: rect1; ... } -Rectangle { id: rect2; anchors.left: rect1.right; anchors.leftMargin: 5; ... } -\endcode - -In this case, a margin of 5 pixels is reserved to the left of \e rect2, producing the following: - -\image edge2.png You can specify multiple anchors. For example: @@ -78,7 +66,9 @@ Rectangle { id: rect2; anchors.left: rect1.right; anchors.top: rect1.bottom; ... \image edge3.png -By specifying multiple horizontal or vertical anchors you can control the size of an item. For example: +By specifying multiple horizontal or vertical anchors you can control the size of an item. Below, +\e rect2 is anchored to the right of \e rect1 and the left of \e rect3. If either of the blue +rectangles are moved, \e rect2 will stretch and shrink as necessary: \code Rectangle { id: rect1; x: 0; ... } @@ -88,9 +78,42 @@ Rectangle { id: rect3; x: 150; ... } \image edge4.png -\section1 Limitations -For performance reasons, you can only anchor an item to its siblings and direct parent. For example, the following anchor would be considered invalid and would produce a warning: +\section1 Anchor Margins and Offsets + +The anchoring system also allows \e margins and \e offsets to be specified for an item's anchors. +Margins specify the amount of empty space to leave to the outside of an item's anchor, while +offsets allow positioning to be manipulated using the center anchor lines. An item can +specify its anchor margins individually through \l {Item::anchors.leftMargin}{leftMargin}, +\l {Item::anchors.rightMargin}{rightMargin}, \l {Item::anchors.topMargin}{topMargin} and +\l {Item::anchors.bottomMargin}{bottomMargin}, or use \l {Item::}{anchors.margins} to +specify the same margin value for all four edges. Anchor offsets are specified using +\l {Item::anchors.horizontalCenterOffset}{horizontalCenterOffset}, +\l {Item::anchors.verticalCenterOffset}{verticalCenterOffset} and +\l {Item::anchors.baselineOffset}{baselineOffset}. + +\image margins_qml.png + +The following example specifies a left margin: + +\code +Rectangle { id: rect1; ... } +Rectangle { id: rect2; anchors.left: rect1.right; anchors.leftMargin: 5; ... } +\endcode + +In this case, a margin of 5 pixels is reserved to the left of \e rect2, producing the following: + +\image edge2.png + +\note Anchor margins only apply to anchors; they are \e not a generic means of applying margins to an \l Item. +If an anchor margin is specified for an edge but the item is not anchored to any item on that +edge, the margin is not applied. + + +\section1 Restrictions + +For performance reasons, you can only anchor an item to its siblings and direct parent. For example, +the following anchor is invalid and would produce a warning: \badcode Item { @@ -103,4 +126,13 @@ Item { } \endcode +Also, anchor-based layouts cannot be mixed with absolute positioning. If an item specifies its +\l {Item::}{x} position and also sets \l {Item::}{anchors.left}, +or anchors its left and right edges but additionally sets a \l {Item::}{width}, the +result is undefined, as it would not be clear whether the item should use anchoring or absolute +positioning. The same can be said for setting an item's \l {Item::}{y} and \l {Item::}{height} +with \l {Item::}{anchors.top} and \l {Item::}{anchors.bottom}, or setting \l {Item::}{anchors.fill} +as well as \l {Item::}{width} or \l {Item::}{height}. If you wish to change from using +anchor-based to absolute positioning, you can clear an anchor value by setting it to \c undefined. + */ diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 932e68f..75e4a0b 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -2112,6 +2112,8 @@ QDeclarativeAnchorLine QDeclarativeItemPrivate::baseline() const Margins apply to top, bottom, left, right, and fill anchors. The \c anchors.margins property can be used to set all of the various margins at once, to the same value. + Note that margins are anchor-specific and are not applied if an item does not + use anchors. Offsets apply for horizontal center, vertical center, and baseline anchors. -- cgit v0.12 From a0fabfac2ddd0b4e52a1d06623a0864f836cba71 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Fri, 10 Dec 2010 14:22:45 +1000 Subject: Fix broken database creation caused by previous fix 16447b1193fedf5fdcf1f3d270fa73c5036a1ba0 removed unused directory but the fix meant that the base Databases directory was no longer automatically created. Task-number: QTBUG-15909 --- src/declarative/qml/qdeclarativesqldatabase.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/declarative/qml/qdeclarativesqldatabase.cpp b/src/declarative/qml/qdeclarativesqldatabase.cpp index 3f53111..bda02a5 100644 --- a/src/declarative/qml/qdeclarativesqldatabase.cpp +++ b/src/declarative/qml/qdeclarativesqldatabase.cpp @@ -172,16 +172,23 @@ static const char* sqlerror[] = { return errorValue; \ } - -static QString databaseFile(const QString& connectionName, QScriptEngine *engine) +static QString qmlsqldatabase_databasesPath(QScriptEngine *engine) { QDeclarativeScriptEngine *qmlengine = static_cast(engine); - QString basename = qmlengine->offlineStoragePath - + QDir::separator() + QLatin1String("Databases") + QDir::separator(); - basename += connectionName; - return basename; + return qmlengine->offlineStoragePath + + QDir::separator() + QLatin1String("Databases"); } +static void qmlsqldatabase_initDatabasesPath(QScriptEngine *engine) +{ + QDir().mkpath(qmlsqldatabase_databasesPath(engine)); +} + +static QString qmlsqldatabase_databaseFile(const QString& connectionName, QScriptEngine *engine) +{ + return qmlsqldatabase_databasesPath(engine) + QDir::separator() + + connectionName; +} static QScriptValue qmlsqldatabase_item(QScriptContext *context, QScriptEngine *engine) @@ -302,7 +309,7 @@ static QScriptValue qmlsqldatabase_change_version(QScriptContext *context, QScri if (ok) { context->thisObject().setProperty(QLatin1String("version"), to_version, QScriptValue::ReadOnly); - QSettings ini(databaseFile(db.connectionName(),engine)+QLatin1String(".ini"),QSettings::IniFormat); + QSettings ini(qmlsqldatabase_databaseFile(db.connectionName(),engine) + QLatin1String(".ini"), QSettings::IniFormat); ini.setValue(QLatin1String("Version"), to_version); } @@ -348,6 +355,8 @@ static QScriptValue qmlsqldatabase_read_transaction(QScriptContext *context, QSc */ static QScriptValue qmlsqldatabase_open_sync(QScriptContext *context, QScriptEngine *engine) { + qmlsqldatabase_initDatabasesPath(engine); + QSqlDatabase database; QString dbname = context->argument(0).toString(); @@ -360,7 +369,7 @@ static QScriptValue qmlsqldatabase_open_sync(QScriptContext *context, QScriptEng md5.addData(dbname.toUtf8()); QString dbid(QLatin1String(md5.result().toHex())); - QString basename = databaseFile(dbid,engine); + QString basename = qmlsqldatabase_databaseFile(dbid, engine); bool created = false; QString version = dbversion; -- cgit v0.12 From 1de4983c86a73913bd2d719ad765726530009979 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 10 Dec 2010 15:34:52 +1000 Subject: PathView: removing the currentIndex could make it invalid. Removing the currentIndex could result in currentIndex being > than the number of items in the model. Task-number: QTBUG-15926 Reviewed-by: Michael Brasser --- src/declarative/graphicsitems/qdeclarativepathview.cpp | 2 +- .../declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp index 7c79afe..87ea214 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview.cpp +++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp @@ -1478,7 +1478,7 @@ void QDeclarativePathView::itemsRemoved(int modelIndex, int count) currentChanged = true; } else if (d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count) { // current item has been removed. - d->currentIndex = qMin(modelIndex, d->modelCount-1); + d->currentIndex = qMin(modelIndex, d->modelCount-count-1); if (d->currentItem) { if (QDeclarativePathViewAttached *att = d->attached(d->currentItem)) att->setIsCurrentItem(true); diff --git a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp index a2a5363..9193707 100644 --- a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp +++ b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp @@ -429,6 +429,10 @@ void tst_QDeclarativePathView::dataModel() pathview->setOffset(0); QCOMPARE(findItems(pathview, "wrapper").count(), 5); + pathview->setCurrentIndex(model.count()-1); + model.removeItem(model.count()-1); + QCOMPARE(pathview->currentIndex(), model.count()-1); + delete canvas; } -- cgit v0.12 From 38856b7ca5ec18b0292dd3dd11d8ea42fea361e6 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Fri, 10 Dec 2010 10:43:57 +0100 Subject: QmlViewer: Fix crash on exit We can't use atexit() handler to show a warning, since whether the QApplication object then still exists or not is undefined. Instead, call the method directly where it makes sense (warnings about command line arguments etc). Task-number: QTBUG-15740 Reviewed-by: Thomas Hartmann --- tools/qml/main.cpp | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index 209c72f..104f7b7 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -86,14 +86,16 @@ void myMessageOutput(QtMsgType type, const char *msg) QWeakPointer logger; QString warnings; -void showWarnings() +void exitApp(int i) { +#ifdef Q_OS_WIN + // Debugging output is not visible by default on Windows - + // therefore show modal dialog with errors instead. if (!warnings.isEmpty()) { - int argc = 0; char **argv = 0; - QApplication application(argc, argv); // QApplication() in main has been destroyed already. - Q_UNUSED(application) QMessageBox::warning(0, QApplication::tr("Qt QML Viewer"), warnings); } +#endif + exit(i); } static QAtomicInt recursiveLock(0); @@ -102,14 +104,16 @@ void myMessageOutput(QtMsgType type, const char *msg) { QString strMsg = QString::fromLatin1(msg); - if (!logger.isNull() && !QCoreApplication::closingDown()) { - if (recursiveLock.testAndSetOrdered(0, 1)) { - QMetaObject::invokeMethod(logger.data(), "append", Q_ARG(QString, strMsg)); - recursiveLock = 0; + if (!QCoreApplication::closingDown()) { + if (!logger.isNull()) { + if (recursiveLock.testAndSetOrdered(0, 1)) { + QMetaObject::invokeMethod(logger.data(), "append", Q_ARG(QString, strMsg)); + recursiveLock = 0; + } + } else { + warnings += strMsg; + warnings += QLatin1Char('\n'); } - } else { - warnings += strMsg; - warnings += QLatin1Char('\n'); } if (systemMsgOutput) { // Windows systemMsgOutput(type, msg); @@ -165,7 +169,8 @@ void usage() qWarning(" "); qWarning(" Press F1 for interactive help"); - exit(1); + + exitApp(1); } void scriptOptsUsage() @@ -184,7 +189,8 @@ void scriptOptsUsage() qWarning(" saveonexit ............................... save recording on viewer exit"); qWarning(" "); qWarning(" One of record, play or both must be specified."); - exit(1); + + exitApp(1); } enum WarningsConfig { ShowWarnings, HideWarnings, DefaultWarnings }; @@ -370,7 +376,7 @@ static void parseCommandLineOptions(const QStringList &arguments) qApp->setStartDragDistance(arguments.at(++i).toInt()); } else if (arg == QLatin1String("-v") || arg == QLatin1String("-version")) { qWarning("Qt QML Viewer version %s", QT_VERSION_STR); - exit(0); + exitApp(0); } else if (arg == "-translation") { if (lastArg) usage(); opts.translationFile = arguments.at(++i); @@ -400,7 +406,7 @@ static void parseCommandLineOptions(const QStringList &arguments) QDeclarativeEngine tmpEngine; QString paths = tmpEngine.importPathList().join(QLatin1String(":")); qWarning("Current search path: %s", paths.toLocal8Bit().constData()); - exit(0); + exitApp(0); } opts.imports << arguments.at(++i); } else if (arg == "-P") { @@ -529,12 +535,6 @@ int main(int argc, char ** argv) systemMsgOutput = qInstallMsgHandler(myMessageOutput); #endif -#if defined (Q_OS_WIN) - // Debugging output is not visible by default on Windows - - // therefore show modal dialog with errors instead. - atexit(showWarnings); -#endif - #if defined (Q_WS_X11) || defined (Q_WS_MAC) //### default to using raster graphics backend for now bool gsSpecified = false; -- cgit v0.12 From 240c33480ea300a78416205602af293d5c223ee2 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Fri, 10 Dec 2010 11:17:33 +0100 Subject: QmlViewer: Remove trailing whitespace --- tools/qml/browser/Browser.qml | 2 +- tools/qml/deviceorientation.h | 4 ++-- tools/qml/qdeclarativetester.cpp | 16 ++++++++-------- tools/qml/qdeclarativetester.h | 4 ++-- tools/qml/qmlruntime.cpp | 4 ++-- tools/qml/startup/startup.qml | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tools/qml/browser/Browser.qml b/tools/qml/browser/Browser.qml index b9573da..968d077 100644 --- a/tools/qml/browser/Browser.qml +++ b/tools/qml/browser/Browser.qml @@ -173,7 +173,7 @@ Rectangle { width: parent.width model: folders1 delegate: folderDelegate - highlight: Rectangle { + highlight: Rectangle { color: palette.highlight visible: root.showFocusHighlight && view1.count != 0 gradient: Gradient { diff --git a/tools/qml/deviceorientation.h b/tools/qml/deviceorientation.h index 487ebd4..88ceb1b 100644 --- a/tools/qml/deviceorientation.h +++ b/tools/qml/deviceorientation.h @@ -52,8 +52,8 @@ class DeviceOrientation : public QObject Q_OBJECT Q_ENUMS(Orientation) public: - enum Orientation { - UnknownOrientation, + enum Orientation { + UnknownOrientation, Portrait, Landscape, PortraitInverted, diff --git a/tools/qml/qdeclarativetester.cpp b/tools/qml/qdeclarativetester.cpp index e3a1f59..1bcdb04 100644 --- a/tools/qml/qdeclarativetester.cpp +++ b/tools/qml/qdeclarativetester.cpp @@ -54,9 +54,9 @@ QT_BEGIN_NAMESPACE extern Q_GUI_EXPORT bool qt_applefontsmoothing_enabled; -QDeclarativeTester::QDeclarativeTester(const QString &script, QDeclarativeViewer::ScriptOptions opts, +QDeclarativeTester::QDeclarativeTester(const QString &script, QDeclarativeViewer::ScriptOptions opts, QDeclarativeView *parent) -: QAbstractAnimation(parent), m_script(script), m_view(parent), filterEvents(true), options(opts), +: QAbstractAnimation(parent), m_script(script), m_view(parent), filterEvents(true), options(opts), testscript(0), hasCompleted(false), hasFailed(false) { parent->viewport()->installEventFilter(this); @@ -75,8 +75,8 @@ QDeclarativeTester::QDeclarativeTester(const QString &script, QDeclarativeViewer QDeclarativeTester::~QDeclarativeTester() { - if (!hasFailed && - options & QDeclarativeViewer::Record && + if (!hasFailed && + options & QDeclarativeViewer::Record && options & QDeclarativeViewer::SaveOnExit) save(); } @@ -228,7 +228,7 @@ void QDeclarativeTester::save() } ts << " }\n"; - while (!mouseevents.isEmpty() && + while (!mouseevents.isEmpty() && mouseevents.first().msec == fe.msec) { MouseEvent me = mouseevents.takeFirst(); @@ -345,7 +345,7 @@ void QDeclarativeTester::updateCurrentTime(int msec) if (QDeclarativeVisualTestFrame *frame = qobject_cast(event)) { if (frame->msec() < msec) { if (options & QDeclarativeViewer::TestImages && !(options & QDeclarativeViewer::Record)) { - qWarning() << "QDeclarativeTester(" << m_script << "): Extra frame. Seen:" + qWarning() << "QDeclarativeTester(" << m_script << "): Extra frame. Seen:" << msec << "Expected:" << frame->msec(); imagefailure(); } @@ -371,7 +371,7 @@ void QDeclarativeTester::updateCurrentTime(int msec) } if (goodImage != img) { QString reject(frame->image().toLocalFile() + ".reject.png"); - qWarning() << "QDeclarativeTester(" << m_script << "): Image mismatch. Reject saved to:" + qWarning() << "QDeclarativeTester(" << m_script << "): Image mismatch. Reject saved to:" << reject; img.save(reject); bool doDiff = (goodImage.size() == img.size()); @@ -424,7 +424,7 @@ void QDeclarativeTester::updateCurrentTime(int msec) ke.destination = ViewPort; } m_savedKeyEvents.append(ke); - } + } testscriptidx++; } diff --git a/tools/qml/qdeclarativetester.h b/tools/qml/qdeclarativetester.h index 0cf508a..5a2a8c6 100644 --- a/tools/qml/qdeclarativetester.h +++ b/tools/qml/qdeclarativetester.h @@ -122,7 +122,7 @@ public: int type() const { return m_type; } void setType(int t) { m_type = t; } - + int button() const { return m_button; } void setButton(int b) { m_button = b; } @@ -237,7 +237,7 @@ private: struct MouseEvent { MouseEvent(QMouseEvent *e) - : type(e->type()), button(e->button()), buttons(e->buttons()), + : type(e->type()), button(e->button()), buttons(e->buttons()), pos(e->pos()), modifiers(e->modifiers()), destination(View) {} QEvent::Type type; diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index a368bc1..3803691 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -820,7 +820,7 @@ void QDeclarativeViewer::createMenu() fileMenu->addAction(reloadAction); fileMenu->addSeparator(); fileMenu->addAction(closeAction); -#if !defined(Q_OS_SYMBIAN) +#if !defined(Q_OS_SYMBIAN) fileMenu->addAction(quitAction); QMenu *recordMenu = menu->addMenu(tr("&Recording")); @@ -836,7 +836,7 @@ void QDeclarativeViewer::createMenu() settingsMenu->addAction(proxyAction); #if defined(Q_OS_SYMBIAN) settingsMenu->addAction(fullscreenAction); -#else +#else settingsMenu->addAction(recordOptions); settingsMenu->addMenu(loggerWindow->preferencesMenu()); #endif // !Q_OS_SYMBIAN diff --git a/tools/qml/startup/startup.qml b/tools/qml/startup/startup.qml index 9ca50a3..d3bc932 100644 --- a/tools/qml/startup/startup.qml +++ b/tools/qml/startup/startup.qml @@ -92,8 +92,8 @@ Rectangle { to: 360 loops: NumberAnimation.Infinite running: true - duration: 2000 - } + duration: 2000 + } } } } @@ -168,6 +168,6 @@ Rectangle { } } } - ] + ] } // treatsApp -- cgit v0.12 From 376e636eccedb8d8bbb280c3e2655722a5902461 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Fri, 10 Dec 2010 11:21:04 +0100 Subject: QmlViewer: Remove trailing whitespace --- tools/qml/qdeclarativetester.h | 2 +- tools/qml/qml.pro | 4 ++-- tools/qml/qmlruntime.cpp | 2 +- tools/qml/startup/startup.qml | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/qml/qdeclarativetester.h b/tools/qml/qdeclarativetester.h index 5a2a8c6..6fdf495 100644 --- a/tools/qml/qdeclarativetester.h +++ b/tools/qml/qdeclarativetester.h @@ -122,7 +122,7 @@ public: int type() const { return m_type; } void setType(int t) { m_type = t; } - + int button() const { return m_button; } void setButton(int b) { m_button = b; } diff --git a/tools/qml/qml.pro b/tools/qml/qml.pro index 3927dd6..bdac6e3 100644 --- a/tools/qml/qml.pro +++ b/tools/qml/qml.pro @@ -4,7 +4,7 @@ DESTDIR = ../../bin include(qml.pri) -SOURCES += main.cpp +SOURCES += main.cpp INCLUDEPATH += ../../include/QtDeclarative INCLUDEPATH += ../../src/declarative/util @@ -26,7 +26,7 @@ wince* { QT += xmlpatterns } contains(QT_CONFIG, webkit) { - QT += webkit + QT += webkit } } maemo5 { diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index 3803691..142e4c5 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -820,7 +820,7 @@ void QDeclarativeViewer::createMenu() fileMenu->addAction(reloadAction); fileMenu->addSeparator(); fileMenu->addAction(closeAction); -#if !defined(Q_OS_SYMBIAN) +#if !defined(Q_OS_SYMBIAN) fileMenu->addAction(quitAction); QMenu *recordMenu = menu->addMenu(tr("&Recording")); diff --git a/tools/qml/startup/startup.qml b/tools/qml/startup/startup.qml index d3bc932..35c44c2 100644 --- a/tools/qml/startup/startup.qml +++ b/tools/qml/startup/startup.qml @@ -92,8 +92,8 @@ Rectangle { to: 360 loops: NumberAnimation.Infinite running: true - duration: 2000 - } + duration: 2000 + } } } } @@ -168,6 +168,6 @@ Rectangle { } } } - ] + ] } // treatsApp -- cgit v0.12 From 2249a44e57764e88ed2967aee7f845fdf4cf2358 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 13 Dec 2010 09:31:37 +1000 Subject: Build on Symbian Reviewed-by: Michael Brasser --- tools/qml/main.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index 104f7b7..b9513b9 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -59,6 +59,19 @@ QtMsgHandler systemMsgOutput = 0; static QDeclarativeViewer *openFile(const QString &fileName); static void showViewer(QDeclarativeViewer *viewer); +QString warnings; +void exitApp(int i) +{ +#ifdef Q_OS_WIN + // Debugging output is not visible by default on Windows - + // therefore show modal dialog with errors instead. + if (!warnings.isEmpty()) { + QMessageBox::warning(0, QApplication::tr("Qt QML Viewer"), warnings); + } +#endif + exit(i); +} + #if defined (Q_OS_SYMBIAN) #include #include @@ -85,19 +98,6 @@ void myMessageOutput(QtMsgType type, const char *msg) QWeakPointer logger; -QString warnings; -void exitApp(int i) -{ -#ifdef Q_OS_WIN - // Debugging output is not visible by default on Windows - - // therefore show modal dialog with errors instead. - if (!warnings.isEmpty()) { - QMessageBox::warning(0, QApplication::tr("Qt QML Viewer"), warnings); - } -#endif - exit(i); -} - static QAtomicInt recursiveLock(0); void myMessageOutput(QtMsgType type, const char *msg) -- cgit v0.12 From 35f964ac3d88831c857a850bbdc58fcbfdbaf13c Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 13 Dec 2010 13:49:52 +1000 Subject: A QAIM model resulted in items moving to incorrect locations QAbstractItemModel moves items to the gaps between items. QML views assume items are moved to the destination index. This means we need to adjust the destination when moving forward to a gap. Task-number: QTBUG-15841 Reviewed-by: Michael Brasser --- src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index 4fe6c4c..4f5213a 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -1367,7 +1367,7 @@ void QDeclarativeVisualDataModel::_q_rowsMoved(const QModelIndex &sourceParent, Q_D(QDeclarativeVisualDataModel); const int count = sourceEnd - sourceStart + 1; if (destinationParent == d->m_root && sourceParent == d->m_root) { - _q_itemsMoved(sourceStart, destinationRow, count); + _q_itemsMoved(sourceStart, sourceStart > destinationRow ? destinationRow : destinationRow-1, count); } else if (sourceParent == d->m_root) { _q_itemsRemoved(sourceStart, count); } else if (destinationParent == d->m_root) { -- cgit v0.12 From 18b940539d0633f30ae055feedb48aeb15969814 Mon Sep 17 00:00:00 2001 From: Joona Petrell Date: Wed, 8 Dec 2010 13:38:48 +1000 Subject: Add mirroring-positioners.qml example --- .../positioners/mirroring-positioners.qml | 70 ++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 examples/declarative/positioners/mirroring-positioners.qml diff --git a/examples/declarative/positioners/mirroring-positioners.qml b/examples/declarative/positioners/mirroring-positioners.qml new file mode 100644 index 0000000..0db95dd --- /dev/null +++ b/examples/declarative/positioners/mirroring-positioners.qml @@ -0,0 +1,70 @@ +import QtQuick 1.0 + +Rectangle { + width: column.width+10 + height: column.height+10 + property bool arabic: false + Column { + id: column + spacing: 10 + anchors.centerIn: parent + Text { + text: "Row" + anchors.horizontalCenter: parent.horizontalCenter + } + Row { + flow: arabic ? Row.RightToLeft : Row.LeftToRight + spacing: 10 + Repeater { + model: 4 + Loader { + property int value: index + sourceComponent: delegate + } + } + } + Text { + text: "Grid" + anchors.horizontalCenter: parent.horizontalCenter + } + Grid { + flow: arabic ? Grid.RightToLeft : Grid.LeftToRight + spacing: 10; columns: 4 + Repeater { + model: 11 + Loader { + property int value: index + sourceComponent: delegate + } + } + } + Rectangle { + height: 50; width: parent.width + color: mouseArea.pressed ? "black" : "gray" + Text { + text: arabic ? "RTL" : "LTR" + color: "white" + font.pixelSize: 20 + anchors.centerIn: parent + } + MouseArea { + id: mouseArea + onClicked: arabic = !arabic + anchors.fill: parent + } + } + } + Component { + id: delegate + Rectangle { + width: 50; height: 50 + color: Qt.rgba(0.8/(parent.value+1),0.8/(parent.value+1),0.8/(parent.value+1),1.0) + Text { + text: parent.parent.value+1 + color: "white" + font.pixelSize: 20 + anchors.centerIn: parent + } + } + } +} -- cgit v0.12 From ad653d169aaecf6273787a01797c7647a13eec04 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 13 Dec 2010 16:09:52 +1000 Subject: Fix dragging Flickable back over start point. Change 810e21d9e404aa2fcb602cb68bfd892387b234e7 caused regression. Once stealMouse is set to true is must stay that way until release. Task-number: QTBUG-15998 Reviewed-by: Michael Brasser --- src/declarative/graphicsitems/qdeclarativeflickable.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index 377f3b5..f1d92c5 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -700,8 +700,8 @@ void QDeclarativeFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent bool rejectY = false; bool rejectX = false; - bool stealY = false; - bool stealX = false; + bool stealY = stealMouse; + bool stealX = stealMouse; if (q->yflick()) { int dy = int(event->pos().y() - pressPos.y()); -- cgit v0.12 From 2e2f26072647b08292955ebad631c34d58c828f9 Mon Sep 17 00:00:00 2001 From: Joona Petrell Date: Mon, 13 Dec 2010 17:08:09 +1000 Subject: Revert "Add mirroring-positioners.qml example" that was accidentally pushed This reverts commit 18b940539d0633f30ae055feedb48aeb15969814. --- .../positioners/mirroring-positioners.qml | 70 ---------------------- 1 file changed, 70 deletions(-) delete mode 100644 examples/declarative/positioners/mirroring-positioners.qml diff --git a/examples/declarative/positioners/mirroring-positioners.qml b/examples/declarative/positioners/mirroring-positioners.qml deleted file mode 100644 index 0db95dd..0000000 --- a/examples/declarative/positioners/mirroring-positioners.qml +++ /dev/null @@ -1,70 +0,0 @@ -import QtQuick 1.0 - -Rectangle { - width: column.width+10 - height: column.height+10 - property bool arabic: false - Column { - id: column - spacing: 10 - anchors.centerIn: parent - Text { - text: "Row" - anchors.horizontalCenter: parent.horizontalCenter - } - Row { - flow: arabic ? Row.RightToLeft : Row.LeftToRight - spacing: 10 - Repeater { - model: 4 - Loader { - property int value: index - sourceComponent: delegate - } - } - } - Text { - text: "Grid" - anchors.horizontalCenter: parent.horizontalCenter - } - Grid { - flow: arabic ? Grid.RightToLeft : Grid.LeftToRight - spacing: 10; columns: 4 - Repeater { - model: 11 - Loader { - property int value: index - sourceComponent: delegate - } - } - } - Rectangle { - height: 50; width: parent.width - color: mouseArea.pressed ? "black" : "gray" - Text { - text: arabic ? "RTL" : "LTR" - color: "white" - font.pixelSize: 20 - anchors.centerIn: parent - } - MouseArea { - id: mouseArea - onClicked: arabic = !arabic - anchors.fill: parent - } - } - } - Component { - id: delegate - Rectangle { - width: 50; height: 50 - color: Qt.rgba(0.8/(parent.value+1),0.8/(parent.value+1),0.8/(parent.value+1),1.0) - Text { - text: parent.parent.value+1 - color: "white" - font.pixelSize: 20 - anchors.centerIn: parent - } - } - } -} -- cgit v0.12 From 95ddfa13737164c93c58ce3694ce59ec68a016d9 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 13 Dec 2010 17:33:13 +1000 Subject: Ensure ListView contentHeight is set to a valid size. If the view height is 0 no items will be created so the contentHeight can not be estimated. The currentItem is usually created, so it is possible to use that to estimate. Task-number: QTBUG-16037 Reviewed-by: Bea Lam --- .../graphicsitems/qdeclarativelistview.cpp | 6 ++++ .../qdeclarativelistview/data/qtbug16037.qml | 37 ++++++++++++++++++++++ .../tst_qdeclarativelistview.cpp | 20 ++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativelistview/data/qtbug16037.qml diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index d008f91..2a7f508 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -265,6 +265,8 @@ public: } } pos = (*(--visibleItems.constEnd()))->endPosition() + invisibleCount * (averageSize + spacing); + } else if (model && model->count()) { + pos = model->count() * averageSize + (model->count()-1) * spacing; } return pos; } @@ -1050,6 +1052,8 @@ void QDeclarativeListViewPrivate::updateCurrent(int modelIndex) // This is slightly sub-optimal, but section heading caching minimizes the impact. if (currentItem->section) currentItem->section->setVisible(false); + if (visibleItems.isEmpty()) + averageSize = currentItem->size(); } updateHighlight(); emit q->currentIndexChanged(); @@ -1576,6 +1580,7 @@ void QDeclarativeListView::setModel(const QVariant &model) d->updateTrackedItem(); } } + d->updateViewport(); } connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); @@ -1647,6 +1652,7 @@ void QDeclarativeListView::setDelegate(QDeclarativeComponent *delegate) d->highlight->setPosition(d->currentItem->position()); d->updateTrackedItem(); } + d->updateViewport(); } } emit delegateChanged(); diff --git a/tests/auto/declarative/qdeclarativelistview/data/qtbug16037.qml b/tests/auto/declarative/qdeclarativelistview/data/qtbug16037.qml new file mode 100644 index 0000000..0756618 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelistview/data/qtbug16037.qml @@ -0,0 +1,37 @@ +import QtQuick 1.0 + +Item { + width: 640 + height: 480 + + function setModel() { + listView.model = listModel1 + } + + ListModel { + id: listModel1 + ListElement { text: "Apple" } + ListElement { text: "Banana" } + ListElement { text: "Orange" } + ListElement { text: "Coconut" } + } + + Rectangle { + width: 200 + height: listView.contentHeight + color: "yellow" + anchors.centerIn: parent + + ListView { + id: listView + objectName: "listview" + anchors.fill: parent + + delegate: Item { + width: 200 + height: 20 + Text { text: model.text; anchors.centerIn: parent } + } + } + } +} diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp index ff90d32..b834d46 100644 --- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp +++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp @@ -104,6 +104,7 @@ private slots: void sizeLessThan1(); void QTBUG_14821(); void resizeDelegate(); + void QTBUG_16037(); private: template void items(); @@ -1944,6 +1945,25 @@ void tst_QDeclarativeListView::resizeDelegate() delete canvas; } +void tst_QDeclarativeListView::QTBUG_16037() +{ + QDeclarativeView *canvas = createView(); + + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/qtbug16037.qml")); + qApp->processEvents(); + + QDeclarativeListView *listview = findItem(canvas->rootObject(), "listview"); + QTRY_VERIFY(listview != 0); + + QVERIFY(listview->contentHeight() <= 0.0); + + QMetaObject::invokeMethod(canvas->rootObject(), "setModel"); + + QTRY_COMPARE(listview->contentHeight(), 80.0); + + delete canvas; +} + void tst_QDeclarativeListView::qListModelInterface_items() { items(); -- cgit v0.12 From de1632cc7be17df234cd86d49df9787e6aa68107 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Fri, 10 Dec 2010 13:05:40 +0100 Subject: Add expected failures for JS test suite on Symbian These are bugs in the back-end (JavaScriptCore), not in the QtScript layer. Flag them as such. Task-number: QTBUG-15435 Reviewed-by: Jedrzej Nowacki --- tests/auto/qscriptjstestsuite/tst_qscriptjstestsuite.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/auto/qscriptjstestsuite/tst_qscriptjstestsuite.cpp b/tests/auto/qscriptjstestsuite/tst_qscriptjstestsuite.cpp index a280256..4b14cc9 100644 --- a/tests/auto/qscriptjstestsuite/tst_qscriptjstestsuite.cpp +++ b/tests/auto/qscriptjstestsuite/tst_qscriptjstestsuite.cpp @@ -745,6 +745,16 @@ tst_Suite::tst_Suite() addExpectedFailure("ecma/TypeConversion/9.3.1-3.js", "1/-1e-2000", willFixInNextReleaseMessage); #endif +#ifdef Q_OS_SYMBIAN + addExpectedFailure("ecma/Math/15.8.2.13.js", "Math.pow(-1, 0.5)", willFixInNextReleaseMessage); + addExpectedFailure("ecma/Math/15.8.2.13.js", "Math.pow(-1, -0.5)", willFixInNextReleaseMessage); + addExpectedFailure("ecma_3/Operators/order-01.js", "operator evaluation order: 11.5.1 *", willFixInNextReleaseMessage); + addExpectedFailure("ecma_3/Operators/order-01.js", "operator evaluation order: 11.5.2 /", willFixInNextReleaseMessage); + addExpectedFailure("ecma_3/Operators/order-01.js", "operator evaluation order: 11.6.2 -", willFixInNextReleaseMessage); + addExpectedFailure("ecma_3/Operators/order-01.js", "operator evaluation order: 11.13.2 *=", willFixInNextReleaseMessage); + addExpectedFailure("ecma_3/Operators/order-01.js", "operator evaluation order: 11.13.2 /=", willFixInNextReleaseMessage); +#endif + static const char klass[] = "tst_QScriptJsTestSuite"; QVector *data = qt_meta_data_tst_Suite(); -- cgit v0.12 From b8f639f27a05043f9f9ac371352508d6527f0123 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 10 Dec 2010 10:00:54 +0100 Subject: Comment a bit more the timer ID allocation code. Also add the notes for where to place .loadAcquire when that function exists. Reviewed-By: Bradley T. Hughes --- src/corelib/kernel/qabstracteventdispatcher.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/corelib/kernel/qabstracteventdispatcher.cpp b/src/corelib/kernel/qabstracteventdispatcher.cpp index bcf4477..1c1c6e3 100644 --- a/src/corelib/kernel/qabstracteventdispatcher.cpp +++ b/src/corelib/kernel/qabstracteventdispatcher.cpp @@ -120,11 +120,20 @@ void QAbstractEventDispatcherPrivate::init() } } +// Timer IDs are implemented using a free-list; +// there's a vector initialized with: +// X[i] = i + 1 +// and nextFreeTimerId starts with 1. +// +// Allocating a timer ID involves taking the ID from +// X[nextFreeTimerId] +// updating nextFreeTimerId to this value and returning the old value +// (continues below). int QAbstractEventDispatcherPrivate::allocateTimerId() { int timerId, newTimerId; do { - timerId = nextFreeTimerId; + timerId = nextFreeTimerId; //.loadAcquire(); // ### FIXME Proper memory ordering semantics // which bucket are we looking in? int which = timerId & 0x00ffffff; @@ -148,6 +157,17 @@ int QAbstractEventDispatcherPrivate::allocateTimerId() return timerId; } +// Releasing a timer ID requires putting the current ID back in the vector; +// we do it by setting: +// X[timerId] = nextFreeTimerId; +// then we update nextFreeTimerId to the timer we've just released +// +// The extra code in allocateTimerId and releaseTimerId are ABA prevention +// and bucket memory. The buckets are simply to make sure we allocate only +// the necessary number of timers. See above. +// +// ABA prevention simply adds a value to 7 of the top 8 bits when resetting +// nextFreeTimerId. void QAbstractEventDispatcherPrivate::releaseTimerId(int timerId) { int which = timerId & 0x00ffffff; @@ -157,7 +177,7 @@ void QAbstractEventDispatcherPrivate::releaseTimerId(int timerId) int freeId, newTimerId; do { - freeId = nextFreeTimerId; + freeId = nextFreeTimerId;//.loadAcquire(); // ### FIXME Proper memory ordering semantics b[at] = freeId & 0x00ffffff; newTimerId = prepareNewValueWithSerialNumber(freeId, timerId); -- cgit v0.12 From f0a892a46fdc438277c8b401c267db4bd92aec1b Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 13 Dec 2010 14:50:07 +0100 Subject: Fix ABA problem with: the serial must be updated on all accesses The nextFreeTimerId's serial counter was only being updated on timer ID releasing. It needs to be updated on allocation too. Reviewed-by: Bradley T. Hughes --- src/corelib/kernel/qabstracteventdispatcher.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/kernel/qabstracteventdispatcher.cpp b/src/corelib/kernel/qabstracteventdispatcher.cpp index 1c1c6e3..5619921 100644 --- a/src/corelib/kernel/qabstracteventdispatcher.cpp +++ b/src/corelib/kernel/qabstracteventdispatcher.cpp @@ -151,7 +151,7 @@ int QAbstractEventDispatcherPrivate::allocateTimerId() } } - newTimerId = b[at]; + newTimerId = prepareNewValueWithSerialNumber(timerId, b[at]); } while (!nextFreeTimerId.testAndSetRelaxed(timerId, newTimerId)); return timerId; -- cgit v0.12 From a02a747a9d5294127dfe3e676a2759e228257e70 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 13 Dec 2010 14:58:16 +0100 Subject: Use constants the timer ID masks instead of values everywhere Reviewed-By: Bradley T. Hughes --- src/corelib/kernel/qabstracteventdispatcher.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/corelib/kernel/qabstracteventdispatcher.cpp b/src/corelib/kernel/qabstracteventdispatcher.cpp index 5619921..002d360 100644 --- a/src/corelib/kernel/qabstracteventdispatcher.cpp +++ b/src/corelib/kernel/qabstracteventdispatcher.cpp @@ -77,10 +77,14 @@ Q_DESTRUCTOR_FUNCTION(timerIdsDestructorFunction) static QBasicAtomicInt nextFreeTimerId = Q_BASIC_ATOMIC_INITIALIZER(1); +static const int TimerIdMask = 0x00ffffff; +static const int TimerSerialMask = ~TimerIdMask & ~0x80000000; +static const int TimerSerialCounter = TimerIdMask + 1; + // avoid the ABA-problem by using 7 of the top 8 bits of the timerId as a serial number static inline int prepareNewValueWithSerialNumber(int oldId, int newId) { - return (newId & 0x00FFFFFF) | ((oldId + 0x01000000) & 0x7f000000); + return (newId & TimerIdMask) | ((oldId + TimerSerialCounter) & TimerSerialMask); } static inline int bucketOffset(int timerId) @@ -136,7 +140,7 @@ int QAbstractEventDispatcherPrivate::allocateTimerId() timerId = nextFreeTimerId; //.loadAcquire(); // ### FIXME Proper memory ordering semantics // which bucket are we looking in? - int which = timerId & 0x00ffffff; + int which = timerId & TimerIdMask; int bucket = bucketOffset(which); int at = bucketIndex(bucket, which); int *b = timerIds[bucket]; @@ -170,7 +174,7 @@ int QAbstractEventDispatcherPrivate::allocateTimerId() // nextFreeTimerId. void QAbstractEventDispatcherPrivate::releaseTimerId(int timerId) { - int which = timerId & 0x00ffffff; + int which = timerId & TimerIdMask; int bucket = bucketOffset(which); int at = bucketIndex(bucket, which); int *b = timerIds[bucket]; @@ -178,7 +182,7 @@ void QAbstractEventDispatcherPrivate::releaseTimerId(int timerId) int freeId, newTimerId; do { freeId = nextFreeTimerId;//.loadAcquire(); // ### FIXME Proper memory ordering semantics - b[at] = freeId & 0x00ffffff; + b[at] = freeId & TimerIdMask; newTimerId = prepareNewValueWithSerialNumber(freeId, timerId); } while (!nextFreeTimerId.testAndSetRelease(freeId, newTimerId)); -- cgit v0.12 From bd9d5c80235ce6d1b005df96c3058b75e82bd6f0 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 13 Dec 2010 15:02:27 +0100 Subject: Add a small protection against releasing a timer twice. The cell corresponding to an allocated timer ID in the free list is unused (because the ID isn't free). So use it to store an invalid value that we can check against the user's value. This provides some protection against a given timer being released twice. Since we store the serial counter of the nextFreeTimerId, getting the same ID twice is a 1-in-128 chance. Reviewed-By: Bradley T. Hughes --- src/corelib/kernel/qabstracteventdispatcher.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/corelib/kernel/qabstracteventdispatcher.cpp b/src/corelib/kernel/qabstracteventdispatcher.cpp index 002d360..bf675a7 100644 --- a/src/corelib/kernel/qabstracteventdispatcher.cpp +++ b/src/corelib/kernel/qabstracteventdispatcher.cpp @@ -132,18 +132,24 @@ void QAbstractEventDispatcherPrivate::init() // Allocating a timer ID involves taking the ID from // X[nextFreeTimerId] // updating nextFreeTimerId to this value and returning the old value +// +// When the timer ID is allocated, its cell in the vector is unused (it's a +// free list). As an added protection, we use the cell to store an invalid +// (negative) value that we can later check for integrity. +// // (continues below). int QAbstractEventDispatcherPrivate::allocateTimerId() { int timerId, newTimerId; + int at, *b; do { timerId = nextFreeTimerId; //.loadAcquire(); // ### FIXME Proper memory ordering semantics // which bucket are we looking in? int which = timerId & TimerIdMask; int bucket = bucketOffset(which); - int at = bucketIndex(bucket, which); - int *b = timerIds[bucket]; + at = bucketIndex(bucket, which); + b = timerIds[bucket]; if (!b) { // allocate a new bucket @@ -158,6 +164,8 @@ int QAbstractEventDispatcherPrivate::allocateTimerId() newTimerId = prepareNewValueWithSerialNumber(timerId, b[at]); } while (!nextFreeTimerId.testAndSetRelaxed(timerId, newTimerId)); + b[at] = -timerId; + return timerId; } @@ -179,6 +187,8 @@ void QAbstractEventDispatcherPrivate::releaseTimerId(int timerId) int at = bucketIndex(bucket, which); int *b = timerIds[bucket]; + Q_ASSERT(b[at] == -timerId); + int freeId, newTimerId; do { freeId = nextFreeTimerId;//.loadAcquire(); // ### FIXME Proper memory ordering semantics -- cgit v0.12