diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-05-19 10:36:50 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-05-19 10:36:50 (GMT) |
commit | c9057924dfa5da4d18030720431a92d2593f85df (patch) | |
tree | 1cef0e0137e1d4bb796f0507b72e95ab30c96e20 /src | |
parent | de0858687898f6e0e54cce3f986779c7aa1a350e (diff) | |
parent | d395903e4d061a30117f7b925bdad41771a29067 (diff) | |
download | Qt-c9057924dfa5da4d18030720431a92d2593f85df.zip Qt-c9057924dfa5da4d18030720431a92d2593f85df.tar.gz Qt-c9057924dfa5da4d18030720431a92d2593f85df.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/qt-qml: (36 commits)
Doc improvements
Disable mouse-based selection in TextInput/TextEdit
Rename qml executable to qmlviewer
Don't crash if the target parent is destroyed.
Introduce a threaded interpreter for QML binding bytecode
Bug moved.
doc
doc
Remove image example (covered in class docs)
When changing Loader source, remove old item from scene immediately.
Add missing .qmlproject files
Fix folderlistmodel with qt namespace
Renaming "Qml Launcher" back to "QML Viewer"
Rename some examples: proxyviewer -> networkaccessmanagerfactory,
Regression fix for Loader anchors not working
Make Qt.include() work for js files that have '.pragma library'
doc fix
Improve docs for Qt.quit()
Prevent assignment of values (string, number, bool) to signal handlers.
Make sure strings are escaped when returned via asScript.
...
Diffstat (limited to 'src')
38 files changed, 1411 insertions, 436 deletions
diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index ec8f508..c121a2d 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -18,9 +18,14 @@ C++ API QDeclarativeExpression::value() has been renamed to QDeclarativeExpression::evaluate() -QML Launcher +The QDeclarativeExpression constructor has changed from + QDeclarativeExpression(context, expression, scope) +to + QDeclarativeExpression(context, scope, expression, parent = 0) + +QML Viewer ------------ -The standalone executable has been renamed to qml launcher. Runtime warnings +The standalone qml executable has been renamed back to Qml Viewer. Runtime warnings can be now accessed via the menu (Debugging->Show Warnings). ============================================================================= diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp index fe642e0..4593cf8 100644 --- a/src/declarative/graphicsitems/qdeclarativeimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp @@ -58,10 +58,8 @@ QT_BEGIN_NAMESPACE \table \row - \o - \image declarative-qtlogo.png - \o - \qml + \o \image declarative-qtlogo.png + \o \qml import Qt 4.7 Image { source: "qtlogo.png" } @@ -281,14 +279,27 @@ qreal QDeclarativeImage::paintedHeight() const (although it reflects what has happened with the image internally). If you wish to react to the change in status you need to do it yourself, for example in one of the following ways: - \list - \o Create a state, so that a state change occurs, e.g. - \qml State { name: 'loaded'; when: image.status = Image.Ready } \endqml - \o Do something inside the onStatusChanged signal handler, e.g. - \qml Image { id: image; onStatusChanged: if (image.status == Image.Ready) console.log('Loaded') } \endqml - \o Bind to the status variable somewhere, e.g. - \qml Text { text: if (image.status != Image.Ready) { 'Not Loaded' } else { 'Loaded' } } \endqml - \endlist + + Use this status to provide an update or respond to the status change in some way. + For example, you could: + + \e {Trigger a state change:} + \qml + State { name: 'loaded'; when: image.status = Image.Ready } + \endqml + + \e {Implement an \c onStatusChanged signal handler:} + \qml + Image { + id: image + onStatusChanged: if (image.status == Image.Ready) console.log('Loaded') + } + \endqml + + \e {Bind to the status value:} + \qml + Text { text: image.status != Image.Ready ? 'Not Loaded' : 'Loaded' } + \endqml \sa progress */ diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 936f9b0..23a6f63 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -1308,23 +1308,43 @@ void QDeclarativeListViewPrivate::flick(AxisData &data, qreal minExtent, qreal m \inherits Flickable \brief The ListView item provides a list view of items provided by a model. - The model is typically provided by a QAbstractListModel "C++ model object", - but can also be created directly in QML. The items are laid out vertically - or horizontally and may be flicked to scroll. - - The below example creates a very simple vertical list, using a QML model. - \image trivialListView.png - - The user interface defines a delegate to display an item, a highlight, - and the ListView which uses the above. - - \snippet doc/src/snippets/declarative/listview/listview.qml 3 - - The model is defined as a ListModel using QML: - \quotefile doc/src/snippets/declarative/listview/dummydata/ContactModel.qml - - In this case ListModel is a handy way for us to test our UI. In practice - the model would be implemented in C++, or perhaps via a SQL data source. + A ListView displays data from models created from built-in QML elements like ListModel + and XmlListModel, or custom model classes defined in C++ that inherit from + QAbstractListModel. + + A ListView has a \l model, which defines the data to be displayed, and + a \l delegate, which defines how the data should be displayed. Items in a + ListView are laid out horizontally or vertically. List views are inherently flickable + as ListView inherits from \l Flickable. + + For example, if there is a simple list model defined in a file \c ContactModel.qml like this: + + \snippet doc/src/snippets/declarative/listview/ContactModel.qml 0 + + A ListView can display the data in the model, like this: + + \table + \row + \o \snippet doc/src/snippets/declarative/listview/listview.qml import + \codeline + \snippet doc/src/snippets/declarative/listview/listview.qml classdocs simple + \o \image listview-simple.png + \endtable + + Here, the ListView creates a \c ContactModel component for its model, and a \l Text element + for its delegate. The view creates a new \l Text component for each item in the model. Note + the delegate is able to access the model's \c name and \c number data directly. + + An improved list view is shown below. The delegate is visually improved and is moved + into a separate \c contactDelegate component. Also, the currently selected item is highlighted + with a blue \l Rectangle using the \l highlight property, and \c focus is set to \c true + to enable keyboard navigation for the list. + + \table + \row + \o \snippet doc/src/snippets/declarative/listview/listview.qml classdocs advanced + \o \image listview-highlight.png + \endtable Delegates are instantiated as needed and may be destroyed at any time. State should \e never be stored in a delegate. @@ -1360,7 +1380,7 @@ QDeclarativeListView::~QDeclarativeListView() This property may be used to adjust the appearance of the current item, for example: - \snippet doc/src/snippets/declarative/listview/highlight.qml 0 + \snippet doc/src/snippets/declarative/listview/listview.qml isCurrentItem */ /*! @@ -1397,22 +1417,10 @@ QDeclarativeListView::~QDeclarativeListView() It is sometimes necessary to delay the destruction of an item until an animation completes. - The example below ensures that the animation completes before + The example delegate below ensures that the animation completes before the item is removed from the list. - \code - Component { - id: myDelegate - Item { - id: wrapper - ListView.onRemove: SequentialAnimation { - PropertyAction { target: wrapper; property: "ListView.delayRemove"; value: true } - NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing.type: Easing.InOutQuad } - PropertyAction { target: wrapper; property: "ListView.delayRemove"; value: false } - } - } - } - \endcode + \snippet doc/src/snippets/declarative/listview/listview.qml delayRemove */ /*! @@ -1429,13 +1437,10 @@ QDeclarativeListView::~QDeclarativeListView() \qmlproperty model ListView::model This property holds the model providing data for the list. - The model provides a set of data that is used to create the items - for the view. For large or dynamic datasets the model is usually - provided by a C++ model object. The C++ model object must be a \l - {QAbstractItemModel} subclass or a simple list. - - Models can also be created directly in QML, using a \l{ListModel}, - \l{XmlListModel} or \l{VisualItemModel}. + The model provides the set of data that is used to create the items + in the view. Models can be created directly in QML using \l ListModel, \l XmlListModel + or \l VisualItemModel, or provided by C++ model classes. If a C++ model class is + used, it must be a subclass of \l QAbstractItemModel or a simple list. \sa {qmlmodels}{Data Models} */ @@ -1511,11 +1516,11 @@ void QDeclarativeListView::setModel(const QVariant &model) that is not needed for the normal display of the delegate in a \l Loader which can load additional elements when needed. - Note that the ListView will layout the items based on the size of the root item + Tthe ListView will lay out the items based on the size of the root item in the delegate. - Here is an example delegate: - \snippet doc/src/snippets/declarative/listview/listview.qml 0 + \note Delegates are instantiated as needed and may be destroyed at any time. + State should \e never be stored in a delegate. */ QDeclarativeComponent *QDeclarativeListView::delegate() const { @@ -1591,10 +1596,9 @@ QDeclarativeItem *QDeclarativeListView::currentItem() /*! \qmlproperty Item ListView::highlightItem - \c highlightItem holds the highlight item, which was created - from the \l highlight component. + This holds the highlight item created from the \l highlight component. - The highlightItem is managed by the view unless + The \c highlightItem is managed by the view unless \l highlightFollowsCurrentItem is set to false. \sa highlight, highlightFollowsCurrentItem @@ -1623,17 +1627,11 @@ int QDeclarativeListView::count() const \qmlproperty Component ListView::highlight This property holds the component to use as the highlight. - An instance of the highlight component will be created for each list. - The geometry of the resultant component instance will be managed by the list + An instance of the highlight component is created for each list. + The geometry of the resultant component instance is managed by the list so as to stay with the current item, unless the highlightFollowsCurrentItem property is false. - The below example demonstrates how to make a simple highlight - for a vertical list. - - \snippet doc/src/snippets/declarative/listview/listview.qml 1 - \image trivialListView.png - \sa highlightItem, highlightFollowsCurrentItem */ QDeclarativeComponent *QDeclarativeListView::highlight() const @@ -1658,13 +1656,14 @@ void QDeclarativeListView::setHighlight(QDeclarativeComponent *highlight) \qmlproperty bool ListView::highlightFollowsCurrentItem This property holds whether the highlight is managed by the view. - If highlightFollowsCurrentItem is true, the highlight will be moved smoothly - to follow the current item. If highlightFollowsCurrentItem is false, the - highlight will not be moved by the view, and must be implemented - by the highlight. The following example creates a highlight with - its motion defined by the spring \l {SpringFollow}: + If this property is true, the highlight is moved smoothly + to follow the current item. Otherwise, the + highlight is not moved by the view, and any movement must be implemented + by the highlight. + + Here is a highlight with its motion defined by the a \l {SpringFollow} item: - \snippet doc/src/snippets/declarative/listview/highlight.qml 1 + \snippet doc/src/snippets/declarative/listview/listview.qml highlightFollowsCurrentItem Note that the highlight animation also affects the way that the view is scrolled. This is because the view moves to maintain the @@ -1695,31 +1694,29 @@ void QDeclarativeListView::setHighlightFollowsCurrentItem(bool autoHighlight) \qmlproperty enumeration ListView::highlightRangeMode These properties set the preferred range of the highlight (current item) - within the view. - - Note that this is the correct way to influence where the - current item ends up when the list scrolls. For example, if you want the - currently selected item to be in the middle of the list, then set the - highlight range to be where the middle item would go. Then, when the list scrolls, - the currently selected item will be the item at that spot. This also applies to - when the currently selected item changes - it will scroll to within the preferred - highlight range. Furthermore, the behaviour of the current item index will occur - whether or not a highlight exists. - - If highlightRangeMode is set to \e ListView.ApplyRange the view will - attempt to maintain the highlight within the range, however - the highlight can move outside of the range at the ends of the list - or due to a mouse interaction. - - If highlightRangeMode is set to \e ListView.StrictlyEnforceRange the highlight will never - move outside of the range. This means that the current item will change - if a keyboard or mouse action would cause the highlight to move - outside of the range. - - The default value is \e ListView.NoHighlightRange. - - Note that a valid range requires preferredHighlightEnd to be greater - than or equal to preferredHighlightBegin. + within the view. The \c preferredHighlightEnd must be greater than or equal to + \c preferredHighlightBegin. + + These properties affect the position of the current item when the list is scrolled. + For example, if the currently selected item should stay in the middle of the + list when the view is scrolled, set the \c preferredHighlightBegin and + \c preferredHighlightEnd values to the top and bottom coordinates of where the middle + item would be. If the \c currentItem is changed programmatically, the list will + automatically scroll so that the current item is in the middle of the view. + Furthermore, the behavior of the current item index will occur whether or not a + highlight exists. + + Valid values for \c highlightRangeMode are: + + \list + \o ListView.ApplyRange - the view attempts to maintain the highlight within the range. + However, the highlight can move outside of the range at the ends of the list or due + to mouse interaction. + \o ListView.StrictlyEnforceRange - the highlight never moves outside of the range. + The current item changes if a keyboard or mouse action would cause the highlight to move + outside of the range. + \o ListView.NoHighlightRange - this is the default value. + \endlist */ qreal QDeclarativeListView::preferredHighlightBegin() const { @@ -1772,7 +1769,7 @@ void QDeclarativeListView::setHighlightRangeMode(HighlightRangeMode mode) /*! \qmlproperty real ListView::spacing - This property holds the spacing to leave between items. + This property holds the spacing between items. */ qreal QDeclarativeListView::spacing() const { @@ -1794,12 +1791,22 @@ void QDeclarativeListView::setSpacing(qreal spacing) \qmlproperty enumeration ListView::orientation This property holds the orientation of the list. - Possible values are \c Vertical (default) and \c Horizontal. + Possible values: - ListView.Vertical Example: - \image trivialListView.png - ListView.Horizontal Example: + \list + \o ListView.Horizontal - Items are laid out horizontally. + \o ListView.Vertical - Items are laid out vertically. This is the default value. + \endlist + + \table + \row + \o Horizontal orientation: \image ListViewHorizontal.png + + \row + \o Vertical orientation: + \image listview-highlight.png + \endtable */ QDeclarativeListView::Orientation QDeclarativeListView::orientation() const { @@ -1829,10 +1836,11 @@ void QDeclarativeListView::setOrientation(QDeclarativeListView::Orientation orie /*! \qmlproperty bool ListView::keyNavigationWraps - This property holds whether the list wraps key navigation + This property holds whether the list wraps key navigation. - If this property is true then key presses to move off of one end of the list will cause the - current item to jump to the other end. + If this is true, key navigation that would move the current item selection + past the end of the list instead wraps around and moves the selection to + the start of the list, and vice-versa. */ bool QDeclarativeListView::isWrapEnabled() const { @@ -1854,8 +1862,8 @@ void QDeclarativeListView::setWrapEnabled(bool wrap) This property determines whether delegates are retained outside the visible area of the view. - If non-zero the view will keep as many delegates - instantiated as will fit within the buffer specified. For example, + If this value is non-zero, the view keeps as many delegates + instantiated as it can fit within the buffer specified. For example, if in a vertical view the delegate is 20 pixels high and \c cacheBuffer is set to 40, then up to 2 delegates above and 2 delegates below the visible area may be retained. @@ -1863,9 +1871,9 @@ void QDeclarativeListView::setWrapEnabled(bool wrap) Note that cacheBuffer is not a pixel buffer - it only maintains additional instantiated delegates. - Setting this value can make scrolling the list smoother at the expense + Setting this value can improve the smoothness of scrolling behavior at the expense of additional memory usage. It is not a substitute for creating efficient - delegates; the fewer elements in a delegate, the faster a view may be + delegates; the fewer elements in a delegate, the faster a view can be scrolled. */ int QDeclarativeListView::cacheBuffer() const @@ -1890,13 +1898,14 @@ void QDeclarativeListView::setCacheBuffer(int b) /*! \qmlproperty string ListView::section.property \qmlproperty enumeration ListView::section.criteria - These properties hold the expression to be evaluated for the section attached property. + These properties hold the expression to be evaluated for the \l section attached property. - section.property hold the name of the property to use to determine - the section the item is in. + \c section.property hold the name of the property to use to determine + the section that holds the item. - section.criteria holds the criteria to use to get the section. It + \c section.criteria holds the criteria to use to access the section. It can be either: + \list \o ViewSection.FullString (default) - section is the value of the property. \o ViewSection.FirstCharacter - section is the first character of the property value. @@ -1935,9 +1944,10 @@ QString QDeclarativeListView::currentSection() const \qmlproperty int ListView::highlightMoveDuration \qmlproperty real ListView::highlightResizeSpeed \qmlproperty int ListView::highlightResizeDuration + These properties hold the move and resize animation speed of the highlight delegate. - highlightFollowsCurrentItem must be true for these properties + \c highlightFollowsCurrentItem must be true for these properties to have effect. The default value for the speed properties is 400 pixels/second. @@ -2019,21 +2029,21 @@ void QDeclarativeListView::setHighlightResizeDuration(int duration) /*! \qmlproperty enumeration ListView::snapMode - This property determines where the view will settle following a drag or flick. + This property determines where the view's scrolling behavior stops following a drag or flick. The allowed values are: \list - \o ListView.NoSnap (default) - the view will stop anywhere within the visible area. - \o ListView.SnapToItem - the view will settle with an item aligned with the start of + \o ListView.NoSnap (default) - the view stops anywhere within the visible area. + \o ListView.SnapToItem - the view settles with an item aligned with the start of the view. - \o ListView.SnapOneItem - the view will settle no more than one item away from the first + \o ListView.SnapOneItem - the view settles no more than one item away from the first visible item at the time the mouse button is released. This mode is particularly useful for moving one page at a time. \endlist - snapMode does not affect the currentIndex. To update the - currentIndex as the list is moved set \e highlightRangeMode - to \e ListView.StrictlyEnforceRange. + \c snapMode does not affect the \l currentIndex. To update the + \l currentIndex as the list is moved, set \l highlightRangeMode + to \c ListView.StrictlyEnforceRange. \sa highlightRangeMode */ @@ -2335,23 +2345,23 @@ void QDeclarativeListView::decrementCurrentIndex() \a mode: \list - \o Beginning - position item at the top (or left for horizontal orientation) of the view. - \o Center- position item in the center of the view. - \o End - position item at bottom (or right for horizontal orientation) of the view. - \o Visible - if any part of the item is visible then take no action, otherwise + \o ListView.Beginning - position item at the top (or left for horizontal orientation) of the view. + \o ListView.Center - position item in the center of the view. + \o ListView.End - position item at bottom (or right for horizontal orientation) of the view. + \o ListView.Visible - if any part of the item is visible then take no action, otherwise bring the item into view. - \o Contain - ensure the entire item is visible. If the item is larger than + \o ListView.Contain - ensure the entire item is visible. If the item is larger than the view the item is positioned at the top (or left for horizontal orientation) of the view. \endlist - If positioning the view at the index would cause empty space to be displayed at + If positioning the view at \a index would cause empty space to be displayed at the beginning or end of the view, the view will be positioned at the boundary. - It is not recommended to use contentX or contentY to position the view + It is not recommended to use \l {Flickable::}{contentX} or \l {Flickable::}{contentY} to position the view at a particular index. This is unreliable since removing items from the start of the list does not cause all other items to be repositioned, and because the actual start of the view can vary based on the size of the delegates. - The correct way to bring an item into view is with positionViewAtIndex. + The correct way to bring an item into view is with \c positionViewAtIndex. */ void QDeclarativeListView::positionViewAtIndex(int index, int mode) { diff --git a/src/declarative/graphicsitems/qdeclarativeloader.cpp b/src/declarative/graphicsitems/qdeclarativeloader.cpp index cbdfd87..4995baf 100644 --- a/src/declarative/graphicsitems/qdeclarativeloader.cpp +++ b/src/declarative/graphicsitems/qdeclarativeloader.cpp @@ -81,8 +81,12 @@ void QDeclarativeLoaderPrivate::clear() // We can't delete immediately because our item may have triggered // the Loader to load a different item. - item->setVisible(false); - item->setParentItem(0); + if (item->scene()) { + item->scene()->removeItem(item); + } else { + item->setParentItem(0); + item->setVisible(false); + } item->deleteLater(); item = 0; } @@ -366,6 +370,7 @@ QDeclarativeLoader::Status QDeclarativeLoader::status() const void QDeclarativeLoader::componentComplete() { + QDeclarativeItem::componentComplete(); if (status() == Ready) emit loaded(); } diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp index 45b79a7..40d37a2 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp @@ -773,6 +773,33 @@ void QDeclarativeTextEdit::componentComplete() } /*! + \qmlproperty string TextEdit::selectByMouse + + Defaults to false. + + If true, the user can use the mouse to select text in some + platform-specific way. Note that for some platforms this may + not be an appropriate interaction (eg. may conflict with how + the text needs to behave inside a Flickable. +*/ +bool QDeclarativeTextEdit::selectByMouse() const +{ + Q_D(const QDeclarativeTextEdit); + return d->selectByMouse; +} + +void QDeclarativeTextEdit::setSelectByMouse(bool on) +{ + Q_D(QDeclarativeTextEdit); + if (d->selectByMouse != on) { + d->selectByMouse = on; + emit selectByMouseChanged(on); + } +} + + + +/*! \qmlproperty bool TextEdit::readOnly Whether the user an interact with the TextEdit item. If this @@ -914,7 +941,8 @@ void QDeclarativeTextEdit::mousePressEvent(QGraphicsSceneMouseEvent *event) } if (!hadFocus && hasFocus()) d->clickCausedFocus = true; - d->control->processEvent(event, QPointF(0, 0)); + if (event->type() != QEvent::GraphicsSceneMouseDoubleClick || d->selectByMouse) + d->control->processEvent(event, QPointF(0, 0)); if (!event->isAccepted()) QDeclarativePaintedItem::mousePressEvent(event); } @@ -943,9 +971,13 @@ Handles the given mouse \a event. void QDeclarativeTextEdit::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { Q_D(QDeclarativeTextEdit); - d->control->processEvent(event, QPointF(0, 0)); - if (!event->isAccepted()) + if (d->selectByMouse) { + d->control->processEvent(event, QPointF(0, 0)); + if (!event->isAccepted()) + QDeclarativePaintedItem::mouseDoubleClickEvent(event); + } else { QDeclarativePaintedItem::mouseDoubleClickEvent(event); + } } /*! @@ -955,10 +987,14 @@ Handles the given mouse \a event. void QDeclarativeTextEdit::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { Q_D(QDeclarativeTextEdit); - d->control->processEvent(event, QPointF(0, 0)); - if (!event->isAccepted()) + if (d->selectByMouse) { + d->control->processEvent(event, QPointF(0, 0)); + if (!event->isAccepted()) + QDeclarativePaintedItem::mouseMoveEvent(event); + event->setAccepted(true); + } else { QDeclarativePaintedItem::mouseMoveEvent(event); - event->setAccepted(true); + } } /*! diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p.h index 474de09..8848d47 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextedit_p.h @@ -86,6 +86,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeTextEdit : public QDeclarativePaintedItem Q_PROPERTY(bool persistentSelection READ persistentSelection WRITE setPersistentSelection NOTIFY persistentSelectionChanged) Q_PROPERTY(qreal textMargin READ textMargin WRITE setTextMargin NOTIFY textMarginChanged) Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints) + Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged) public: QDeclarativeTextEdit(QDeclarativeItem *parent=0); @@ -167,6 +168,9 @@ public: qreal textMargin() const; void setTextMargin(qreal margin); + bool selectByMouse() const; + void setSelectByMouse(bool); + virtual void componentComplete(); /* FROM EDIT */ @@ -200,6 +204,7 @@ Q_SIGNALS: void focusOnPressChanged(bool focusIsPressed); void persistentSelectionChanged(bool isPersistentSelection); void textMarginChanged(qreal textMargin); + void selectByMouseChanged(bool selectByMouse); public Q_SLOTS: void selectAll(); diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h index 5e19c3d..885620d 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h @@ -72,7 +72,8 @@ public: imgDirty(true), dirty(false), richText(false), cursorVisible(false), focusOnPress(true), persistentSelection(true), clickCausedFocus(false), textMargin(0.0), lastSelectionStart(0), lastSelectionEnd(0), cursorComponent(0), cursor(0), format(QDeclarativeTextEdit::AutoText), document(0), - wrapMode(QDeclarativeTextEdit::NoWrap) + wrapMode(QDeclarativeTextEdit::NoWrap), + selectByMouse(false) { } @@ -110,6 +111,7 @@ public: QTextDocument *document; QTextControl *control; QDeclarativeTextEdit::WrapMode wrapMode; + bool selectByMouse; }; QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index 8aa7e99..2e7715f 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -907,8 +907,12 @@ void QDeclarativeTextInput::mousePressEvent(QGraphicsSceneMouseEvent *event) void QDeclarativeTextInput::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { Q_D(QDeclarativeTextInput); - d->control->moveCursor(d->xToPos(event->pos().x()), true); - event->setAccepted(true); + if (d->selectByMouse) { + d->control->moveCursor(d->xToPos(event->pos().x()), true); + event->setAccepted(true); + } else { + QDeclarativePaintedItem::mouseMoveEvent(event); + } } /*! @@ -939,6 +943,8 @@ bool QDeclarativeTextInput::event(QEvent* ev) case QEvent::GraphicsSceneMouseRelease: break; default: + if (ev->type() == QEvent::GraphicsSceneMouseDoubleClick && !d->selectByMouse) + break; handled = d->control->processEvent(ev); if (ev->type() == QEvent::InputMethod) updateSize(); @@ -1114,6 +1120,32 @@ QString QDeclarativeTextInput::displayText() const } /*! + \qmlproperty string TextInput::selectByMouse + + Defaults to false. + + If true, the user can use the mouse to select text in some + platform-specific way. Note that for some platforms this may + not be an appropriate interaction (eg. may conflict with how + the text needs to behave inside a Flickable. +*/ +bool QDeclarativeTextInput::selectByMouse() const +{ + Q_D(const QDeclarativeTextInput); + return d->selectByMouse; +} + +void QDeclarativeTextInput::setSelectByMouse(bool on) +{ + Q_D(QDeclarativeTextInput); + if (d->selectByMouse != on) { + d->selectByMouse = on; + emit selectByMouseChanged(on); + } +} + + +/*! \qmlmethod void TextInput::moveCursorSelection(int position) Moves the cursor to \a position and updates the selection accordingly. diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p.h index c0c1e50..b2fd057 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextinput_p.h @@ -89,6 +89,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeTextInput : public QDeclarativePaintedIte Q_PROPERTY(QString passwordCharacter READ passwordCharacter WRITE setPasswordCharacter NOTIFY passwordCharacterChanged) Q_PROPERTY(QString displayText READ displayText NOTIFY displayTextChanged) Q_PROPERTY(bool autoScroll READ autoScroll WRITE setAutoScroll NOTIFY autoScrollChanged) + Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged) public: QDeclarativeTextInput(QDeclarativeItem* parent=0); @@ -174,6 +175,9 @@ public: bool autoScroll() const; void setAutoScroll(bool); + bool selectByMouse() const; + void setSelectByMouse(bool); + bool hasAcceptableInput() const; void drawContents(QPainter *p,const QRect &r); @@ -203,6 +207,7 @@ Q_SIGNALS: void displayTextChanged(const QString &text); void focusOnPressChanged(bool focusOnPress); void autoScrollChanged(bool autoScroll); + void selectByMouseChanged(bool selectByMouse); protected: virtual void geometryChanged(const QRectF &newGeometry, diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h index 99866b8..1d8e0f7 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h @@ -72,7 +72,8 @@ public: color((QRgb)0), style(QDeclarativeText::Normal), styleColor((QRgb)0), hAlign(QDeclarativeTextInput::AlignLeft), hscroll(0), oldScroll(0), focused(false), focusOnPress(true), - cursorVisible(false), autoScroll(true), clickCausedFocus(false) + cursorVisible(false), autoScroll(true), clickCausedFocus(false), + selectByMouse(false) { } @@ -117,6 +118,7 @@ public: bool cursorVisible; bool autoScroll; bool clickCausedFocus; + bool selectByMouse; }; QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index 0e4217e..291378f 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -204,7 +204,7 @@ QVariant QDeclarativeVisualItemModel::evaluate(int index, const QString &express QDeclarativeContext *ccontext = qmlContext(this); QDeclarativeContext *ctxt = new QDeclarativeContext(ccontext); ctxt->setContextObject(d->children.at(index)); - QDeclarativeExpression e(ctxt, expression, objectContext); + QDeclarativeExpression e(ctxt, objectContext, expression); QVariant value = e.evaluate(); delete ctxt; return value; @@ -775,9 +775,6 @@ void QDeclarativeVisualDataModel::setModel(const QVariant &model) The delegate provides a template defining each item instantiated by a view. The index is exposed as an accessible \c index property. Properties of the model are also available depending upon the type of \l {qmlmodels}{Data Model}. - - Here is an example delegate: - \snippet doc/src/snippets/declarative/listview/listview.qml 0 */ QDeclarativeComponent *QDeclarativeVisualDataModel::delegate() const { @@ -1176,7 +1173,7 @@ QVariant QDeclarativeVisualDataModel::evaluate(int index, const QString &express if (nobj) { QDeclarativeItem *item = qobject_cast<QDeclarativeItem *>(nobj); if (item) { - QDeclarativeExpression e(qmlContext(item), expression, objectContext); + QDeclarativeExpression e(qmlContext(item), objectContext, expression); value = e.evaluate(); } } else { @@ -1185,7 +1182,7 @@ QVariant QDeclarativeVisualDataModel::evaluate(int index, const QString &express QDeclarativeContext *ctxt = new QDeclarativeContext(ccontext); QDeclarativeVisualDataModelData *data = new QDeclarativeVisualDataModelData(index, this); ctxt->setContextObject(data); - QDeclarativeExpression e(ctxt, expression, objectContext); + QDeclarativeExpression e(ctxt, objectContext, expression); value = e.evaluate(); delete data; delete ctxt; diff --git a/src/declarative/qml/qdeclarativebinding.cpp b/src/declarative/qml/qdeclarativebinding.cpp index 2e905b9..8230941 100644 --- a/src/declarative/qml/qdeclarativebinding.cpp +++ b/src/declarative/qml/qdeclarativebinding.cpp @@ -88,7 +88,7 @@ QDeclarativeBinding::QDeclarativeBinding(void *data, QDeclarativeRefCount *rc, Q QDeclarativeBinding::QDeclarativeBinding(const QString &str, QObject *obj, QDeclarativeContext *ctxt, QObject *parent) -: QDeclarativeExpression(QDeclarativeContextData::get(ctxt), str, obj, *new QDeclarativeBindingPrivate) +: QDeclarativeExpression(QDeclarativeContextData::get(ctxt), obj, str, *new QDeclarativeBindingPrivate) { setParent(parent); setNotifyOnValueChanged(true); @@ -96,7 +96,7 @@ QDeclarativeBinding::QDeclarativeBinding(const QString &str, QObject *obj, QDecl QDeclarativeBinding::QDeclarativeBinding(const QString &str, QObject *obj, QDeclarativeContextData *ctxt, QObject *parent) -: QDeclarativeExpression(ctxt, str, obj, *new QDeclarativeBindingPrivate) +: QDeclarativeExpression(ctxt, obj, str, *new QDeclarativeBindingPrivate) { setParent(parent); setNotifyOnValueChanged(true); diff --git a/src/declarative/qml/qdeclarativeboundsignal.cpp b/src/declarative/qml/qdeclarativeboundsignal.cpp index 89f1256..8769122 100644 --- a/src/declarative/qml/qdeclarativeboundsignal.cpp +++ b/src/declarative/qml/qdeclarativeboundsignal.cpp @@ -119,7 +119,7 @@ QDeclarativeBoundSignal::QDeclarativeBoundSignal(QDeclarativeContext *ctxt, cons QDeclarative_setParent_noEvent(this, parent); QMetaObject::connect(scope, m_signal.methodIndex(), this, evaluateIdx); - m_expression = new QDeclarativeExpression(ctxt, val, scope); + m_expression = new QDeclarativeExpression(ctxt, scope, val); } QDeclarativeBoundSignal::~QDeclarativeBoundSignal() diff --git a/src/declarative/qml/qdeclarativecompiledbindings.cpp b/src/declarative/qml/qdeclarativecompiledbindings.cpp index f55d330..ad05e80 100644 --- a/src/declarative/qml/qdeclarativecompiledbindings.cpp +++ b/src/declarative/qml/qdeclarativecompiledbindings.cpp @@ -64,6 +64,73 @@ DEFINE_BOOL_CONFIG_OPTION(bindingsDump, QML_BINDINGS_DUMP); Q_GLOBAL_STATIC(QDeclarativeFastProperties, fastProperties); +#ifdef __GNUC__ +# define QML_THREADED_INTERPRETER +#endif + +#define FOR_EACH_QML_INSTR(F) \ + F(Noop) /* Nop */ \ + F(BindingId) /* id */ \ + F(Subscribe) /* subscribe */ \ + F(SubscribeId) /* subscribe */ \ + F(FetchAndSubscribe) /* fetchAndSubscribe */ \ + F(LoadId) /* load */ \ + F(LoadScope) /* load */ \ + F(LoadRoot) /* load */ \ + F(LoadAttached) /* attached */ \ + F(ConvertIntToReal) /* unaryop */ \ + F(ConvertRealToInt) /* unaryop */ \ + F(Real) /* real_value */ \ + F(Int) /* int_value */ \ + F(Bool) /* bool_value */ \ + F(String) /* string_value */ \ + F(AddReal) /* binaryop */ \ + F(AddInt) /* binaryop */ \ + F(AddString) /* binaryop */ \ + F(MinusReal) /* binaryop */ \ + F(MinusInt) /* binaryop */ \ + F(CompareReal) /* binaryop */ \ + F(CompareString) /* binaryop */ \ + F(NotCompareReal) /* binaryop */ \ + F(NotCompareString) /* binaryop */ \ + F(GreaterThanReal) /* binaryop */ \ + F(MaxReal) /* binaryop */ \ + F(MinReal) /* binaryop */ \ + F(NewString) /* construct */ \ + F(NewUrl) /* construct */ \ + F(CleanupUrl) /* cleanup */ \ + F(CleanupString) /* cleanup */ \ + F(Copy) /* copy */ \ + F(Fetch) /* fetch */ \ + F(Store) /* store */ \ + F(Skip) /* skip */ \ + F(Done) /* done */ \ + /* Speculative property resolution */ \ + F(InitString) /* initstring */ \ + F(FindGeneric) /* find */ \ + F(FindGenericTerminal) /* find */ \ + F(FindProperty) /* find */ \ + F(FindPropertyTerminal) /* find */ \ + F(CleanupGeneric) /* cleanup */ \ + F(ConvertGenericToReal) /* unaryop */ \ + F(ConvertGenericToBool) /* unaryop */ \ + F(ConvertGenericToString) /* unaryop */ \ + F(ConvertGenericToUrl) /* unaryop */ + +#define QML_INSTR_ENUM(I) I, +#define QML_INSTR_ADDR(I) &&op_##I, + +#ifdef QML_THREADED_INTERPRETER +# define QML_BEGIN_INSTR(I) op_##I: +# define QML_END_INSTR(I) ++instr; goto *instr->common.code; +# define QML_INSTR_HEADER void *code; +#else +# define QML_BEGIN_INSTR(I) case Instr::I: +# define QML_END_INSTR(I) break; +# define QML_INSTR_HEADER +#endif + + using namespace QDeclarativeJS; namespace { @@ -328,101 +395,45 @@ namespace { // This structure is exactly 8-bytes in size struct Instr { enum { - Noop, - BindingId, // id - - Subscribe, // subscribe - SubscribeId, // subscribe - - FetchAndSubscribe, // fetchAndSubscribe - - LoadId, // load - LoadScope, // load - LoadRoot, // load - LoadAttached, // attached - - ConvertIntToReal, // unaryop - ConvertRealToInt, // unaryop - - Real, // real_value - Int, // int_value - Bool, // bool_value - String, // string_value - - AddReal, // binaryop - AddInt, // binaryop - AddString, // binaryop - - MinusReal, // binaryop - MinusInt, // binaryop - - CompareReal, // binaryop - CompareString, // binaryop - - NotCompareReal, // binaryop - NotCompareString, // binaryop - - GreaterThanReal, // binaryop - MaxReal, // binaryop - MinReal, // binaryop - - NewString, // construct - NewUrl, // construct - - CleanupUrl, // cleanup - CleanupString, // cleanup - - Copy, // copy - Fetch, // fetch - Store, // store - - Skip, // skip - - Done, - - // Speculative property resolution - InitString, // initstring - FindGeneric, // find - FindGenericTerminal, // find - FindProperty, // find - FindPropertyTerminal, // find - CleanupGeneric, // cleanup - ConvertGenericToReal, // unaryop - ConvertGenericToBool, // unaryop - ConvertGenericToString, // unaryop - ConvertGenericToUrl, // unaryop + FOR_EACH_QML_INSTR(QML_INSTR_ENUM) }; union { struct { + QML_INSTR_HEADER quint8 type; quint8 packing[7]; } common; struct { + QML_INSTR_HEADER quint8 type; quint8 packing; quint16 column; quint32 line; } id; struct { + QML_INSTR_HEADER quint8 type; quint8 packing[3]; quint16 subscriptions; quint16 identifiers; } init; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; quint16 offset; quint32 index; } subscribe; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; quint8 packing[2]; quint32 index; } load; struct { + QML_INSTR_HEADER quint8 type; qint8 output; qint8 reg; @@ -430,6 +441,7 @@ struct Instr { quint32 index; } attached; struct { + QML_INSTR_HEADER quint8 type; qint8 output; qint8 reg; @@ -437,6 +449,7 @@ struct Instr { quint32 index; } store; struct { + QML_INSTR_HEADER quint8 type; qint8 output; qint8 objectReg; @@ -445,6 +458,7 @@ struct Instr { quint16 function; } fetchAndSubscribe; struct { + QML_INSTR_HEADER quint8 type; qint8 output; qint8 objectReg; @@ -452,41 +466,48 @@ struct Instr { quint32 index; } fetch; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; qint8 src; quint8 packing[5]; } copy; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; quint8 packing[6]; } construct; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; quint8 packing[2]; float value; } real_value; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; quint8 packing[2]; int value; } int_value; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; bool value; quint8 packing[5]; } bool_value; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; quint16 length; quint32 offset; } string_value; struct { + QML_INSTR_HEADER quint8 type; qint8 output; qint8 src1; @@ -494,18 +515,21 @@ struct Instr { quint8 packing[4]; } binaryop; struct { + QML_INSTR_HEADER quint8 type; qint8 output; qint8 src; quint8 packing[5]; } unaryop; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; quint8 packing[2]; quint32 count; } skip; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; qint8 src; @@ -514,11 +538,13 @@ struct Instr { quint16 subscribeIndex; } find; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; quint8 packing[6]; } cleanup; struct { + QML_INSTR_HEADER quint8 type; quint8 packing[1]; quint16 offset; @@ -535,7 +561,7 @@ struct Program { quint16 subscriptions; quint16 identifiers; quint16 instructionCount; - quint16 dummy; + quint16 compiled; const char *data() const { return ((const char *)this) + sizeof(Program); } const Instr *instructions() const { return (const Instr *)(data() + dataLength); } @@ -1097,35 +1123,57 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, instr += instrIndex; const char *data = program->data(); +#ifdef QML_THREADED_INTERPRETER + static void *decode_instr[] = { + FOR_EACH_QML_INSTR(QML_INSTR_ADDR) + }; + + if (!program->compiled) { + program->compiled = true; + const Instr *inop = program->instructions(); + for (int i = 0; i < program->instructionCount; ++i) { + Instr *op = (Instr *) inop++; + op->common.code = decode_instr[op->common.type]; + } + } + + goto *instr->common.code; +#else // return; + #ifdef COMPILEDBINDINGS_DEBUG qWarning().nospace() << "Begin binding run"; #endif while (instr) { + switch (instr->common.type) { + #ifdef COMPILEDBINDINGS_DEBUG dumpInstruction(instr); #endif - switch (instr->common.type) { - case Instr::Noop: - case Instr::BindingId: - break; +#endif - case Instr::SubscribeId: + QML_BEGIN_INSTR(Noop) + QML_END_INSTR(Noop) + + QML_BEGIN_INSTR(BindingId) + QML_END_INSTR(BindingId) + + QML_BEGIN_INSTR(SubscribeId) subscribeId(context, instr->subscribe.index, instr->subscribe.offset); - break; + QML_END_INSTR(SubscribeId) - case Instr::Subscribe: + QML_BEGIN_INSTR(Subscribe) { QObject *o = 0; const Register &object = registers[instr->subscribe.reg]; if (!object.isUndefined()) o = object.getQObject(); subscribe(o, instr->subscribe.index, instr->subscribe.offset); } - break; + QML_END_INSTR(Subscribe) - case Instr::FetchAndSubscribe: + QML_BEGIN_INSTR(FetchAndSubscribe) { const Register &input = registers[instr->fetchAndSubscribe.objectReg]; Register &output = registers[instr->fetchAndSubscribe.output]; @@ -1149,21 +1197,21 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, fastProperties()->accessor(instr->fetchAndSubscribe.function)(object, output.typeDataPtr(), sub); } } - break; + QML_END_INSTR(FetchAndSubscribe) - case Instr::LoadId: + QML_BEGIN_INSTR(LoadId) registers[instr->load.reg].setQObject(context->idValues[instr->load.index].data()); - break; + QML_END_INSTR(LoadId) - case Instr::LoadScope: + QML_BEGIN_INSTR(LoadScope) registers[instr->load.reg].setQObject(scope); - break; + QML_END_INSTR(LoadScope) - case Instr::LoadRoot: + QML_BEGIN_INSTR(LoadRoot) registers[instr->load.reg].setQObject(context->contextObject); - break; + QML_END_INSTR(LoadRoot) - case Instr::LoadAttached: + QML_BEGIN_INSTR(LoadAttached) { const Register &input = registers[instr->attached.reg]; Register &output = registers[instr->attached.output]; @@ -1184,48 +1232,48 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, output.setQObject(attached); } } - break; + QML_END_INSTR(LoadAttached) - case Instr::ConvertIntToReal: + QML_BEGIN_INSTR(ConvertIntToReal) { const Register &input = registers[instr->unaryop.src]; Register &output = registers[instr->unaryop.output]; if (input.isUndefined()) output.setUndefined(); else output.setqreal(qreal(input.getint())); } - break; + QML_END_INSTR(ConvertIntToReal) - case Instr::ConvertRealToInt: + QML_BEGIN_INSTR(ConvertRealToInt) { const Register &input = registers[instr->unaryop.src]; Register &output = registers[instr->unaryop.output]; if (input.isUndefined()) output.setUndefined(); - else output.setint(int(input.getqreal())); + else output.setint(qRound(input.getqreal())); } - break; + QML_END_INSTR(ConvertRealToInt) - case Instr::Real: + QML_BEGIN_INSTR(Real) registers[instr->real_value.reg].setqreal(instr->real_value.value); - break; + QML_END_INSTR(Real) - case Instr::Int: + QML_BEGIN_INSTR(Int) registers[instr->int_value.reg].setint(instr->int_value.value); - break; + QML_END_INSTR(Int) - case Instr::Bool: + QML_BEGIN_INSTR(Bool) registers[instr->bool_value.reg].setbool(instr->bool_value.value); - break; + QML_END_INSTR(Bool) - case Instr::String: + QML_BEGIN_INSTR(String) { Register &output = registers[instr->string_value.reg]; new (output.getstringptr()) QString((QChar *)(data + instr->string_value.offset), instr->string_value.length); output.settype(QMetaType::QString); } - break; + QML_END_INSTR(String) - case Instr::AddReal: + QML_BEGIN_INSTR(AddReal) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1233,9 +1281,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setNaN(); else output.setqreal(lhs.getqreal() + rhs.getqreal()); } - break; + QML_END_INSTR(AddReal) - case Instr::AddInt: + QML_BEGIN_INSTR(AddInt) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1243,9 +1291,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setNaN(); else output.setint(lhs.getint() + rhs.getint()); } - break; + QML_END_INSTR(AddInt) - case Instr::AddString: + QML_BEGIN_INSTR(AddString) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1265,9 +1313,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, output.settype(QMetaType::QString); } } - break; + QML_END_INSTR(AddString) - case Instr::MinusReal: + QML_BEGIN_INSTR(MinusReal) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1275,9 +1323,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setNaN(); else output.setqreal(lhs.getqreal() - rhs.getqreal()); } - break; + QML_END_INSTR(MinusReal) - case Instr::MinusInt: + QML_BEGIN_INSTR(MinusInt) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1285,9 +1333,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setNaN(); else output.setint(lhs.getint() - rhs.getint()); } - break; + QML_END_INSTR(MinusInt) - case Instr::CompareReal: + QML_BEGIN_INSTR(CompareReal) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1295,9 +1343,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setbool(lhs.isUndefined() == rhs.isUndefined()); else output.setbool(lhs.getqreal() == rhs.getqreal()); } - break; + QML_END_INSTR(CompareReal) - case Instr::CompareString: + QML_BEGIN_INSTR(CompareString) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1305,9 +1353,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setbool(lhs.isUndefined() == rhs.isUndefined()); else output.setbool(*lhs.getstringptr() == *rhs.getstringptr()); } - break; + QML_END_INSTR(CompareString) - case Instr::NotCompareReal: + QML_BEGIN_INSTR(NotCompareReal) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1315,9 +1363,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setbool(lhs.isUndefined() != rhs.isUndefined()); else output.setbool(lhs.getqreal() != rhs.getqreal()); } - break; + QML_END_INSTR(NotCompareReal) - case Instr::NotCompareString: + QML_BEGIN_INSTR(NotCompareString) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1325,9 +1373,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setbool(lhs.isUndefined() != rhs.isUndefined()); else output.setbool(*lhs.getstringptr() != *rhs.getstringptr()); } - break; + QML_END_INSTR(NotCompareString) - case Instr::GreaterThanReal: + QML_BEGIN_INSTR(GreaterThanReal) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1335,9 +1383,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setbool(false); else output.setbool(lhs.getqreal() > rhs.getqreal()); } - break; + QML_END_INSTR(GreaterThanReal) - case Instr::MaxReal: + QML_BEGIN_INSTR(MaxReal) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1345,9 +1393,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setNaN(); else output.setqreal(qMax(lhs.getqreal(), rhs.getqreal())); } - break; + QML_END_INSTR(MaxReal) - case Instr::MinReal: + QML_BEGIN_INSTR(MinReal) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1355,33 +1403,33 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setNaN(); else output.setqreal(qMin(lhs.getqreal(), rhs.getqreal())); } - break; + QML_END_INSTR(MinReal) - case Instr::NewString: + QML_BEGIN_INSTR(NewString) { Register &output = registers[instr->construct.reg]; new (output.getstringptr()) QString; output.settype(QMetaType::QString); } - break; + QML_END_INSTR(NewString) - case Instr::NewUrl: + QML_BEGIN_INSTR(NewUrl) { Register &output = registers[instr->construct.reg]; new (output.geturlptr()) QUrl; output.settype(QMetaType::QUrl); } - break; + QML_END_INSTR(NewUrl) - case Instr::CleanupString: + QML_BEGIN_INSTR(CleanupString) registers[instr->cleanup.reg].getstringptr()->~QString(); - break; + QML_END_INSTR(CleanupString) - case Instr::CleanupUrl: + QML_BEGIN_INSTR(CleanupUrl) registers[instr->cleanup.reg].geturlptr()->~QUrl(); - break; + QML_END_INSTR(CleanupUrl) - case Instr::Fetch: + QML_BEGIN_INSTR(Fetch) { const Register &input = registers[instr->fetch.objectReg]; Register &output = registers[instr->fetch.output]; @@ -1399,9 +1447,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, QMetaObject::metacall(object, QMetaObject::ReadProperty, instr->fetch.index, argv); } } - break; + QML_END_INSTR(Fetch) - case Instr::Store: + QML_BEGIN_INSTR(Store) { Register &data = registers[instr->store.reg]; if (data.isUndefined()) { @@ -1415,21 +1463,22 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, QMetaObject::metacall(output, QMetaObject::WriteProperty, instr->store.index, argv); } - break; + QML_END_INSTR(Store) - case Instr::Copy: + QML_BEGIN_INSTR(Copy) registers[instr->copy.reg] = registers[instr->copy.src]; - break; + QML_END_INSTR(Copy) - case Instr::Skip: + QML_BEGIN_INSTR(Skip) if (instr->skip.reg == -1 || !registers[instr->skip.reg].getbool()) instr += instr->skip.count; - break; + QML_END_INSTR(Skip) - case Instr::Done: + QML_BEGIN_INSTR(Done) return; + QML_END_INSTR(Done) - case Instr::InitString: + QML_BEGIN_INSTR(InitString) if (!identifiers[instr->initstring.offset].identifier) { quint32 len = *(quint32 *)(data + instr->initstring.dataIdx); QChar *strdata = (QChar *)(data + instr->initstring.dataIdx + sizeof(quint32)); @@ -1438,10 +1487,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, identifiers[instr->initstring.offset] = engine->objectClass->createPersistentIdentifier(str); } - break; + QML_END_INSTR(InitString) - case Instr::FindGenericTerminal: - case Instr::FindGeneric: + QML_BEGIN_INSTR(FindGenericTerminal) // We start the search in the parent context, as we know that the // name is not present in the current context or it would have been // found during the static compile @@ -1449,10 +1497,19 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, context->parent, identifiers[instr->find.name].identifier, instr->common.type == Instr::FindGenericTerminal); - break; + QML_END_INSTR(FindGenericTerminal) - case Instr::FindPropertyTerminal: - case Instr::FindProperty: + QML_BEGIN_INSTR(FindGeneric) + // We start the search in the parent context, as we know that the + // name is not present in the current context or it would have been + // found during the static compile + findgeneric(registers + instr->find.reg, instr->find.subscribeIndex, + context->parent, + identifiers[instr->find.name].identifier, + instr->common.type == Instr::FindGenericTerminal); + QML_END_INSTR(FindGeneric) + + QML_BEGIN_INSTR(FindPropertyTerminal) { const Register &object = registers[instr->find.src]; if (object.isUndefined()) { @@ -1465,9 +1522,24 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, instr->find.subscribeIndex, identifiers[instr->find.name].identifier, instr->common.type == Instr::FindPropertyTerminal); } - break; + QML_END_INSTR(FindPropertyTerminal) - case Instr::CleanupGeneric: + QML_BEGIN_INSTR(FindProperty) + { + const Register &object = registers[instr->find.src]; + if (object.isUndefined()) { + throwException(instr->find.exceptionId, error, program, context); + return; + } + + findproperty(object.getQObject(), registers + instr->find.reg, + QDeclarativeEnginePrivate::get(context->engine), + instr->find.subscribeIndex, identifiers[instr->find.name].identifier, + instr->common.type == Instr::FindPropertyTerminal); + } + QML_END_INSTR(FindProperty) + + QML_BEGIN_INSTR(CleanupGeneric) { int type = registers[instr->cleanup.reg].gettype(); if (type == qMetaTypeId<QVariant>()) { @@ -1478,9 +1550,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, registers[instr->cleanup.reg].geturlptr()->~QUrl(); } } - break; + QML_END_INSTR(CleanupGeneric) - case Instr::ConvertGenericToReal: + QML_BEGIN_INSTR(ConvertGenericToReal) { Register &output = registers[instr->unaryop.output]; Register &input = registers[instr->unaryop.src]; @@ -1488,9 +1560,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, output.setqreal(toReal(&input, input.gettype(), &ok)); if (!ok) output.setUndefined(); } - break; + QML_END_INSTR(ConvertGenericToReal) - case Instr::ConvertGenericToBool: + QML_BEGIN_INSTR(ConvertGenericToBool) { Register &output = registers[instr->unaryop.output]; Register &input = registers[instr->unaryop.src]; @@ -1498,9 +1570,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, output.setbool(toBool(&input, input.gettype(), &ok)); if (!ok) output.setUndefined(); } - break; + QML_END_INSTR(ConvertGenericToBool) - case Instr::ConvertGenericToString: + QML_BEGIN_INSTR(ConvertGenericToString) { Register &output = registers[instr->unaryop.output]; Register &input = registers[instr->unaryop.src]; @@ -1509,9 +1581,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (ok) { new (output.getstringptr()) QString(str); output.settype(QMetaType::QString); } else { output.setUndefined(); } } - break; + QML_END_INSTR(ConvertGenericToString) - case Instr::ConvertGenericToUrl: + QML_BEGIN_INSTR(ConvertGenericToUrl) { Register &output = registers[instr->unaryop.output]; Register &input = registers[instr->unaryop.src]; @@ -1520,15 +1592,19 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (ok) { new (output.geturlptr()) QUrl(url); output.settype(QMetaType::QUrl); } else { output.setUndefined(); } } - break; + QML_END_INSTR(ConvertGenericToUrl) +#ifdef QML_THREADED_INTERPRETER + // nothing to do +#else default: qFatal("EEK"); break; - } + } // switch - instr++; - } + ++instr; + } // while +#endif } void QDeclarativeBindingCompiler::dump(const QByteArray &programData) @@ -2781,6 +2857,7 @@ QByteArray QDeclarativeBindingCompiler::program() const prog.subscriptions = d->committed.subscriptionIds.count(); prog.identifiers = d->committed.registeredStrings.count(); prog.instructionCount = bytecode.count(); + prog.compiled = false; int size = sizeof(Program) + bytecode.count() * sizeof(Instr); size += prog.dataLength; diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index a43b9ac..b5bf972 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -180,7 +180,7 @@ bool QDeclarativeCompiler::isSignalPropertyName(const QByteArray &name) bool QDeclarativeCompiler::testLiteralAssignment(const QMetaProperty &prop, QDeclarativeParser::Value *v) { - QString string = v->value.asScript(); + QString string = v->value.asString(); if (!prop.isWritable()) COMPILE_EXCEPTION(v, tr("Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop.name()))); @@ -207,31 +207,31 @@ bool QDeclarativeCompiler::testLiteralAssignment(const QMetaProperty &prop, break; case QVariant::UInt: { - bool ok; - string.toUInt(&ok); - if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: unsigned int expected")); + bool ok = v->value.isNumber(); + if (ok) { + double n = v->value.asNumber(); + if (double(uint(n)) != n) + ok = false; + } + if (!ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: unsigned int expected")); } break; case QVariant::Int: { - bool ok; - string.toInt(&ok); - if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: int expected")); + bool ok = v->value.isNumber(); + if (ok) { + double n = v->value.asNumber(); + if (double(int(n)) != n) + ok = false; + } + if (!ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: int expected")); } break; case QMetaType::Float: - { - bool ok; - string.toFloat(&ok); - if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: float expected")); - } + if (!v->value.isNumber()) COMPILE_EXCEPTION(v, tr("Invalid property assignment: float expected")); break; case QVariant::Double: - { - bool ok; - string.toDouble(&ok); - if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: double expected")); - } + if (!v->value.isNumber()) COMPILE_EXCEPTION(v, tr("Invalid property assignment: double expected")); break; case QVariant::Color: { @@ -319,7 +319,7 @@ bool QDeclarativeCompiler::testLiteralAssignment(const QMetaProperty &prop, void QDeclarativeCompiler::genLiteralAssignment(const QMetaProperty &prop, QDeclarativeParser::Value *v) { - QString string = v->value.asScript(); + QString string = v->value.asString(); QDeclarativeInstruction instr; instr.line = v->location.start.line; @@ -382,28 +382,28 @@ void QDeclarativeCompiler::genLiteralAssignment(const QMetaProperty &prop, { instr.type = QDeclarativeInstruction::StoreInteger; instr.storeInteger.propertyIndex = prop.propertyIndex(); - instr.storeInteger.value = string.toUInt(); + instr.storeInteger.value = uint(v->value.asNumber()); } break; case QVariant::Int: { instr.type = QDeclarativeInstruction::StoreInteger; instr.storeInteger.propertyIndex = prop.propertyIndex(); - instr.storeInteger.value = string.toInt(); + instr.storeInteger.value = int(v->value.asNumber()); } break; case QMetaType::Float: { instr.type = QDeclarativeInstruction::StoreFloat; instr.storeFloat.propertyIndex = prop.propertyIndex(); - instr.storeFloat.value = string.toFloat(); + instr.storeFloat.value = float(v->value.asNumber()); } break; case QVariant::Double: { instr.type = QDeclarativeInstruction::StoreDouble; instr.storeDouble.propertyIndex = prop.propertyIndex(); - instr.storeDouble.value = string.toDouble(); + instr.storeDouble.value = v->value.asNumber(); } break; case QVariant::Color: @@ -1187,7 +1187,7 @@ bool QDeclarativeCompiler::buildComponent(QDeclarativeParser::Object *obj, if (idProp) { if (idProp->value || idProp->values.count() > 1 || idProp->values.at(0)->object) COMPILE_EXCEPTION(idProp, tr("Invalid component id specification")); - COMPILE_CHECK(checkValidId(idProp->values.first(), idProp->values.first()->primitive())); + COMPILE_CHECK(checkValidId(idProp->values.first(), idProp->values.first()->primitive())) QString idVal = idProp->values.first()->primitive(); @@ -1316,6 +1316,9 @@ bool QDeclarativeCompiler::buildSignal(QDeclarativeParser::Property *prop, QDecl } else { prop->values.at(0)->type = Value::SignalExpression; + if (!prop->values.at(0)->value.isScript()) + COMPILE_EXCEPTION(prop, tr("Cannot assign a value to a signal (expecting a script to be run)")); + QString script = prop->values.at(0)->value.asScript().trimmed(); if (script.isEmpty()) COMPILE_EXCEPTION(prop, tr("Empty signal assignment")); @@ -1893,7 +1896,7 @@ bool QDeclarativeCompiler::buildScriptStringProperty(QDeclarativeParser::Propert if (prop->values.count() > 1) COMPILE_EXCEPTION(prop->values.at(1), tr( "Cannot assign multiple values to a script property")); - if (prop->values.at(0)->object || !prop->values.at(0)->value.isScript()) + if (prop->values.at(0)->object) COMPILE_EXCEPTION(prop->values.at(0), tr( "Invalid property assignment: script expected")); obj->addScriptStringProperty(prop, ctxt.stack); diff --git a/src/declarative/qml/qdeclarativeenginedebug.cpp b/src/declarative/qml/qdeclarativeenginedebug.cpp index 69e42f8..7ae0050 100644 --- a/src/declarative/qml/qdeclarativeenginedebug.cpp +++ b/src/declarative/qml/qdeclarativeenginedebug.cpp @@ -414,7 +414,7 @@ void QDeclarativeEngineDebugServer::messageReceived(const QByteArray &message) QDeclarativeContext *context = qmlContext(object); QVariant result; if (object && context) { - QDeclarativeExpression exprObj(context, expr, object); + QDeclarativeExpression exprObj(context, object, expr); bool undefined = false; QVariant value = exprObj.evaluate(&undefined); if (undefined) diff --git a/src/declarative/qml/qdeclarativeexpression.cpp b/src/declarative/qml/qdeclarativeexpression.cpp index 5ceb918..b1aecfa 100644 --- a/src/declarative/qml/qdeclarativeexpression.cpp +++ b/src/declarative/qml/qdeclarativeexpression.cpp @@ -241,15 +241,17 @@ QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContextData *ctxt, vo } /*! - Create a QDeclarativeExpression object. + Create a QDeclarativeExpression object that is a child of \a parent. The \a expression JavaScript will be executed in the \a ctxt QDeclarativeContext. If specified, the \a scope object's properties will also be in scope during the expression's execution. */ -QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContext *ctxt, const QString &expression, - QObject *scope) -: QObject(*new QDeclarativeExpressionPrivate, 0) +QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContext *ctxt, + QObject *scope, + const QString &expression, + QObject *parent) +: QObject(*new QDeclarativeExpressionPrivate, parent) { Q_D(QDeclarativeExpression); d->init(QDeclarativeContextData::get(ctxt), expression, scope); @@ -258,8 +260,8 @@ QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContext *ctxt, const /*! \internal */ -QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContextData *ctxt, const QString &expression, - QObject *scope) +QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContextData *ctxt, QObject *scope, + const QString &expression) : QObject(*new QDeclarativeExpressionPrivate, 0) { Q_D(QDeclarativeExpression); @@ -267,8 +269,8 @@ QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContextData *ctxt, co } /*! \internal */ -QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContextData *ctxt, const QString &expression, - QObject *scope, QDeclarativeExpressionPrivate &dd) +QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContextData *ctxt, QObject *scope, + const QString &expression, QDeclarativeExpressionPrivate &dd) : QObject(dd, 0) { Q_D(QDeclarativeExpression); diff --git a/src/declarative/qml/qdeclarativeexpression.h b/src/declarative/qml/qdeclarativeexpression.h index 6c72e4d..a8c86da 100644 --- a/src/declarative/qml/qdeclarativeexpression.h +++ b/src/declarative/qml/qdeclarativeexpression.h @@ -64,7 +64,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeExpression : public QObject Q_OBJECT public: QDeclarativeExpression(); - QDeclarativeExpression(QDeclarativeContext *, const QString &, QObject *); + QDeclarativeExpression(QDeclarativeContext *, QObject *, const QString &, QObject * = 0); virtual ~QDeclarativeExpression(); QDeclarativeEngine *engine() const; @@ -92,13 +92,13 @@ Q_SIGNALS: void valueChanged(); protected: - QDeclarativeExpression(QDeclarativeContextData *, const QString &, QObject *, + QDeclarativeExpression(QDeclarativeContextData *, QObject *, const QString &, QDeclarativeExpressionPrivate &dd); QDeclarativeExpression(QDeclarativeContextData *, void *, QDeclarativeRefCount *rc, QObject *me, const QString &, int, QDeclarativeExpressionPrivate &dd); private: - QDeclarativeExpression(QDeclarativeContextData *, const QString &, QObject *); + QDeclarativeExpression(QDeclarativeContextData *, QObject *, const QString &); Q_DISABLE_COPY(QDeclarativeExpression) Q_DECLARE_PRIVATE(QDeclarativeExpression) diff --git a/src/declarative/qml/qdeclarativeinclude.cpp b/src/declarative/qml/qdeclarativeinclude.cpp index 619264a..e37b68b 100644 --- a/src/declarative/qml/qdeclarativeinclude.cpp +++ b/src/declarative/qml/qdeclarativeinclude.cpp @@ -140,6 +140,7 @@ void QDeclarativeInclude::finished() scriptContext->pushScope(m_scope[1]); scriptContext->setActivationObject(m_scope[1]); + QDeclarativeScriptParser::extractPragmas(code); m_scriptEngine->evaluate(code, urlString, 1); @@ -230,6 +231,7 @@ QScriptValue QDeclarativeInclude::include(QScriptContext *ctxt, QScriptEngine *e QScriptValue scope = QScriptDeclarativeClass::scopeChainValue(ctxt, -5); scriptContext->pushScope(scope); scriptContext->setActivationObject(scope); + QDeclarativeScriptParser::extractPragmas(code); engine->evaluate(code, urlString, 1); @@ -291,6 +293,7 @@ QScriptValue QDeclarativeInclude::worker_include(QScriptContext *ctxt, QScriptEn QScriptValue scope = QScriptDeclarativeClass::scopeChainValue(ctxt, -4); scriptContext->pushScope(scope); scriptContext->setActivationObject(scope); + QDeclarativeScriptParser::extractPragmas(code); engine->evaluate(code, urlString, 1); diff --git a/src/declarative/qml/qdeclarativeparser.cpp b/src/declarative/qml/qdeclarativeparser.cpp index b38bd76..8d00ef8 100644 --- a/src/declarative/qml/qdeclarativeparser.cpp +++ b/src/declarative/qml/qdeclarativeparser.cpp @@ -57,6 +57,7 @@ #include <QPointF> #include <QSizeF> #include <QRectF> +#include <QStringBuilder> #include <QtDebug> QT_BEGIN_NAMESPACE @@ -310,6 +311,49 @@ double QDeclarativeParser::Variant::asNumber() const return d; } +//reverse of Lexer::singleEscape() +QString escapedString(const QString &string) +{ + QString tmp = QLatin1String("\""); + for (int i = 0; i < string.length(); ++i) { + const QChar &c = string.at(i); + switch(c.unicode()) { + case 0x08: + tmp += QLatin1String("\\b"); + break; + case 0x09: + tmp += QLatin1String("\\t"); + break; + case 0x0A: + tmp += QLatin1String("\\n"); + break; + case 0x0B: + tmp += QLatin1String("\\v"); + break; + case 0x0C: + tmp += QLatin1String("\\f"); + break; + case 0x0D: + tmp += QLatin1String("\\r"); + break; + case 0x22: + tmp += QLatin1String("\\\""); + break; + case 0x27: + tmp += QLatin1String("\\\'"); + break; + case 0x5C: + tmp += QLatin1String("\\\\"); + break; + default: + tmp += c; + break; + } + } + tmp += QLatin1Char('\"'); + return tmp; +} + QString QDeclarativeParser::Variant::asScript() const { switch(type()) { @@ -324,6 +368,7 @@ QString QDeclarativeParser::Variant::asScript() const else return s; case String: + return escapedString(s); case Script: return s; } diff --git a/src/declarative/qml/qdeclarativeparser_p.h b/src/declarative/qml/qdeclarativeparser_p.h index 25777f5..d192f3a 100644 --- a/src/declarative/qml/qdeclarativeparser_p.h +++ b/src/declarative/qml/qdeclarativeparser_p.h @@ -307,8 +307,8 @@ namespace QDeclarativeParser }; Type type; - // ### Temporary - QString primitive() const { return value.asScript(); } + // ### Temporary (for id only) + QString primitive() const { return value.isString() ? value.asString() : value.asScript(); } // Primitive value Variant value; diff --git a/src/declarative/qml/qdeclarativevme.cpp b/src/declarative/qml/qdeclarativevme.cpp index 8ba79a6..3247f85 100644 --- a/src/declarative/qml/qdeclarativevme.cpp +++ b/src/declarative/qml/qdeclarativevme.cpp @@ -627,7 +627,7 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack, QDeclarativeBoundSignal *bs = new QDeclarativeBoundSignal(target, signal, target); QDeclarativeExpression *expr = - new QDeclarativeExpression(ctxt, primitives.at(instr.storeSignal.value), context); + new QDeclarativeExpression(ctxt, context, primitives.at(instr.storeSignal.value)); expr->setSourceLocation(comp->name, instr.line); bs->setExpression(expr); } diff --git a/src/declarative/qml/qdeclarativewatcher.cpp b/src/declarative/qml/qdeclarativewatcher.cpp index 842b3c4..da1419f 100644 --- a/src/declarative/qml/qdeclarativewatcher.cpp +++ b/src/declarative/qml/qdeclarativewatcher.cpp @@ -153,7 +153,7 @@ bool QDeclarativeWatcher::addWatch(int id, quint32 objectId, const QString &expr QObject *object = QDeclarativeDebugService::objectForId(objectId); QDeclarativeContext *context = qmlContext(object); if (context) { - QDeclarativeExpression *exprObj = new QDeclarativeExpression(context, expr, object); + QDeclarativeExpression *exprObj = new QDeclarativeExpression(context, object, expr); exprObj->setNotifyOnValueChanged(true); QDeclarativeWatchProxy *proxy = new QDeclarativeWatchProxy(id, exprObj, objectId, this); exprObj->setParent(proxy); diff --git a/src/declarative/qml/qdeclarativeworkerscript.cpp b/src/declarative/qml/qdeclarativeworkerscript.cpp index 4b687a9..8182998 100644 --- a/src/declarative/qml/qdeclarativeworkerscript.cpp +++ b/src/declarative/qml/qdeclarativeworkerscript.cpp @@ -527,7 +527,7 @@ void QDeclarativeWorkerScriptEngine::run() \snippet doc/src/snippets/declarative/workerscript.qml 0 The above worker script specifies a javascript file, "script.js", that handles - the operations to be performed in the new thread: + the operations to be performed in the new thread. Here is \c script.js: \qml WorkerScript.onMessage = function(message) { @@ -538,7 +538,7 @@ void QDeclarativeWorkerScriptEngine::run() When the user clicks anywhere within the rectangle, \c sendMessage() is called, triggering the \tt WorkerScript.onMessage() handler in - \tt source.js. This in turn sends a reply message that is then received + \tt script.js. This in turn sends a reply message that is then received by the \tt onMessage() handler of \tt myWorker. */ QDeclarativeWorkerScript::QDeclarativeWorkerScript(QObject *parent) diff --git a/src/declarative/qml/qdeclarativexmlhttprequest.cpp b/src/declarative/qml/qdeclarativexmlhttprequest.cpp index 80510f8..acd1f51 100644 --- a/src/declarative/qml/qdeclarativexmlhttprequest.cpp +++ b/src/declarative/qml/qdeclarativexmlhttprequest.cpp @@ -995,7 +995,7 @@ private: int m_status; QString m_statusText; QNetworkRequest m_request; - QNetworkReply *m_network; + QDeclarativeGuard<QNetworkReply> m_network; void destroyNetwork(); QNetworkAccessManager *m_nam; diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index 67440b6..1365cd7 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -786,7 +786,7 @@ void QDeclarativeScriptActionPrivate::execute() const QString &str = scriptStr.script(); if (!str.isEmpty()) { - QDeclarativeExpression expr(scriptStr.context(), str, scriptStr.scopeObject()); + QDeclarativeExpression expr(scriptStr.context(), scriptStr.scopeObject(), str); QDeclarativeData *ddata = QDeclarativeData::get(q); if (ddata && ddata->outerContext && !ddata->outerContext->url.isEmpty()) expr.setSourceLocation(ddata->outerContext->url.toString(), ddata->lineNumber); @@ -1947,6 +1947,9 @@ void QDeclarativePropertyAnimation::setTo(const QVariant &t) easing.period is only applicable if type is: Easing.InElastic, Easing.OutElastic, Easing.InOutElastic or Easing.OutInElastic. + + See the \l {declarative/animation/easing}{easing} example for a demonstration of + the different easing settings. */ QEasingCurve QDeclarativePropertyAnimation::easing() const { diff --git a/src/declarative/util/qdeclarativeconnections.cpp b/src/declarative/util/qdeclarativeconnections.cpp index ffa160f..808d196 100644 --- a/src/declarative/util/qdeclarativeconnections.cpp +++ b/src/declarative/util/qdeclarativeconnections.cpp @@ -262,7 +262,7 @@ void QDeclarativeConnections::connectSignals() if (prop.isValid() && (prop.type() & QDeclarativeProperty::SignalProperty)) { QDeclarativeBoundSignal *signal = new QDeclarativeBoundSignal(target(), prop.method(), this); - signal->setExpression(new QDeclarativeExpression(qmlContext(this), script, 0)); + signal->setExpression(new QDeclarativeExpression(qmlContext(this), 0, script)); d->boundsignals += signal; } else { if (!d->ignoreUnknownSignals) diff --git a/src/declarative/util/qdeclarativepropertychanges.cpp b/src/declarative/util/qdeclarativepropertychanges.cpp index 12fef36..d99de7a 100644 --- a/src/declarative/util/qdeclarativepropertychanges.cpp +++ b/src/declarative/util/qdeclarativepropertychanges.cpp @@ -321,7 +321,7 @@ void QDeclarativePropertyChangesPrivate::decode() QDeclarativeProperty prop = property(name); //### better way to check for signal property? if (prop.type() & QDeclarativeProperty::SignalProperty) { - QDeclarativeExpression *expression = new QDeclarativeExpression(qmlContext(q), data.toString(), object); + QDeclarativeExpression *expression = new QDeclarativeExpression(qmlContext(q), object, data.toString()); QDeclarativeData *ddata = QDeclarativeData::get(q); if (ddata && ddata->outerContext && !ddata->outerContext->url.isEmpty()) expression->setSourceLocation(ddata->outerContext->url.toString(), ddata->lineNumber); @@ -330,7 +330,7 @@ void QDeclarativePropertyChangesPrivate::decode() handler->expression = expression; signalReplacements << handler; } else if (isScript) { - QDeclarativeExpression *expression = new QDeclarativeExpression(qmlContext(q), data.toString(), object); + QDeclarativeExpression *expression = new QDeclarativeExpression(qmlContext(q), object, data.toString()); QDeclarativeData *ddata = QDeclarativeData::get(q); if (ddata && ddata->outerContext && !ddata->outerContext->url.isEmpty()) expression->setSourceLocation(ddata->outerContext->url.toString(), ddata->lineNumber); diff --git a/src/declarative/util/qdeclarativestateoperations.cpp b/src/declarative/util/qdeclarativestateoperations.cpp index 0326f6d..80ae5f5 100644 --- a/src/declarative/util/qdeclarativestateoperations.cpp +++ b/src/declarative/util/qdeclarativestateoperations.cpp @@ -69,18 +69,18 @@ public: rewindParent(0), rewindStackBefore(0) {} QDeclarativeItem *target; - QDeclarativeItem *parent; + QDeclarativeGuard<QDeclarativeItem> parent; QDeclarativeGuard<QDeclarativeItem> origParent; QDeclarativeGuard<QDeclarativeItem> origStackBefore; QDeclarativeItem *rewindParent; QDeclarativeItem *rewindStackBefore; - QDeclarativeNullableValue<qreal> x; - QDeclarativeNullableValue<qreal> y; - QDeclarativeNullableValue<qreal> width; - QDeclarativeNullableValue<qreal> height; - QDeclarativeNullableValue<qreal> scale; - QDeclarativeNullableValue<qreal> rotation; + QDeclarativeNullableValue<QDeclarativeScriptString> xString; + QDeclarativeNullableValue<QDeclarativeScriptString> yString; + QDeclarativeNullableValue<QDeclarativeScriptString> widthString; + QDeclarativeNullableValue<QDeclarativeScriptString> heightString; + QDeclarativeNullableValue<QDeclarativeScriptString> scaleString; + QDeclarativeNullableValue<QDeclarativeScriptString> rotationString; void doChange(QDeclarativeItem *targetParent, QDeclarativeItem *stackBefore = 0); }; @@ -196,112 +196,112 @@ QDeclarativeParentChange::~QDeclarativeParentChange() These properties hold the new position, size, scale, and rotation for the item in this state. */ -qreal QDeclarativeParentChange::x() const +QDeclarativeScriptString QDeclarativeParentChange::x() const { Q_D(const QDeclarativeParentChange); - return d->x.isNull ? qreal(0.) : d->x.value; + return d->xString.value; } -void QDeclarativeParentChange::setX(qreal x) +void QDeclarativeParentChange::setX(QDeclarativeScriptString x) { Q_D(QDeclarativeParentChange); - d->x = x; + d->xString = x; } bool QDeclarativeParentChange::xIsSet() const { Q_D(const QDeclarativeParentChange); - return d->x.isValid(); + return d->xString.isValid(); } -qreal QDeclarativeParentChange::y() const +QDeclarativeScriptString QDeclarativeParentChange::y() const { Q_D(const QDeclarativeParentChange); - return d->y.isNull ? qreal(0.) : d->y.value; + return d->yString.value; } -void QDeclarativeParentChange::setY(qreal y) +void QDeclarativeParentChange::setY(QDeclarativeScriptString y) { Q_D(QDeclarativeParentChange); - d->y = y; + d->yString = y; } bool QDeclarativeParentChange::yIsSet() const { Q_D(const QDeclarativeParentChange); - return d->y.isValid(); + return d->yString.isValid(); } -qreal QDeclarativeParentChange::width() const +QDeclarativeScriptString QDeclarativeParentChange::width() const { Q_D(const QDeclarativeParentChange); - return d->width.isNull ? qreal(0.) : d->width.value; + return d->widthString.value; } -void QDeclarativeParentChange::setWidth(qreal width) +void QDeclarativeParentChange::setWidth(QDeclarativeScriptString width) { Q_D(QDeclarativeParentChange); - d->width = width; + d->widthString = width; } bool QDeclarativeParentChange::widthIsSet() const { Q_D(const QDeclarativeParentChange); - return d->width.isValid(); + return d->widthString.isValid(); } -qreal QDeclarativeParentChange::height() const +QDeclarativeScriptString QDeclarativeParentChange::height() const { Q_D(const QDeclarativeParentChange); - return d->height.isNull ? qreal(0.) : d->height.value; + return d->heightString.value; } -void QDeclarativeParentChange::setHeight(qreal height) +void QDeclarativeParentChange::setHeight(QDeclarativeScriptString height) { Q_D(QDeclarativeParentChange); - d->height = height; + d->heightString = height; } bool QDeclarativeParentChange::heightIsSet() const { Q_D(const QDeclarativeParentChange); - return d->height.isValid(); + return d->heightString.isValid(); } -qreal QDeclarativeParentChange::scale() const +QDeclarativeScriptString QDeclarativeParentChange::scale() const { Q_D(const QDeclarativeParentChange); - return d->scale.isNull ? qreal(1.) : d->scale.value; + return d->scaleString.value; } -void QDeclarativeParentChange::setScale(qreal scale) +void QDeclarativeParentChange::setScale(QDeclarativeScriptString scale) { Q_D(QDeclarativeParentChange); - d->scale = scale; + d->scaleString = scale; } bool QDeclarativeParentChange::scaleIsSet() const { Q_D(const QDeclarativeParentChange); - return d->scale.isValid(); + return d->scaleString.isValid(); } -qreal QDeclarativeParentChange::rotation() const +QDeclarativeScriptString QDeclarativeParentChange::rotation() const { Q_D(const QDeclarativeParentChange); - return d->rotation.isNull ? qreal(0.) : d->rotation.value; + return d->rotationString.value; } -void QDeclarativeParentChange::setRotation(qreal rotation) +void QDeclarativeParentChange::setRotation(QDeclarativeScriptString rotation) { Q_D(QDeclarativeParentChange); - d->rotation = rotation; + d->rotationString = rotation; } bool QDeclarativeParentChange::rotationIsSet() const { Q_D(const QDeclarativeParentChange); - return d->rotation.isValid(); + return d->rotationString.isValid(); } QDeclarativeItem *QDeclarativeParentChange::originalParent() const @@ -356,34 +356,118 @@ QDeclarativeStateOperation::ActionList QDeclarativeParentChange::actions() a.event = this; actions << a; - if (d->x.isValid()) { - QDeclarativeAction xa(d->target, QLatin1String("x"), x()); - actions << xa; + if (d->xString.isValid()) { + bool ok = false; + QString script = d->xString.value.script(); + qreal x = script.toFloat(&ok); + if (ok) { + QDeclarativeAction xa(d->target, QLatin1String("x"), x); + actions << xa; + } else { + QDeclarativeBinding *newBinding = new QDeclarativeBinding(script, d->target, qmlContext(this)); + newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("x"))); + QDeclarativeAction xa; + xa.property = newBinding->property(); + xa.toBinding = newBinding; + xa.fromValue = xa.property.read(); + xa.deletableToBinding = true; + actions << xa; + } } - if (d->y.isValid()) { - QDeclarativeAction ya(d->target, QLatin1String("y"), y()); - actions << ya; + if (d->yString.isValid()) { + bool ok = false; + QString script = d->yString.value.script(); + qreal y = script.toFloat(&ok); + if (ok) { + QDeclarativeAction ya(d->target, QLatin1String("y"), y); + actions << ya; + } else { + QDeclarativeBinding *newBinding = new QDeclarativeBinding(script, d->target, qmlContext(this)); + newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("y"))); + QDeclarativeAction ya; + ya.property = newBinding->property(); + ya.toBinding = newBinding; + ya.fromValue = ya.property.read(); + ya.deletableToBinding = true; + actions << ya; + } } - if (d->scale.isValid()) { - QDeclarativeAction sa(d->target, QLatin1String("scale"), scale()); - actions << sa; + if (d->scaleString.isValid()) { + bool ok = false; + QString script = d->scaleString.value.script(); + qreal scale = script.toFloat(&ok); + if (ok) { + QDeclarativeAction sa(d->target, QLatin1String("scale"), scale); + actions << sa; + } else { + QDeclarativeBinding *newBinding = new QDeclarativeBinding(script, d->target, qmlContext(this)); + newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("scale"))); + QDeclarativeAction sa; + sa.property = newBinding->property(); + sa.toBinding = newBinding; + sa.fromValue = sa.property.read(); + sa.deletableToBinding = true; + actions << sa; + } } - if (d->rotation.isValid()) { - QDeclarativeAction ra(d->target, QLatin1String("rotation"), rotation()); - actions << ra; + if (d->rotationString.isValid()) { + bool ok = false; + QString script = d->rotationString.value.script(); + qreal rotation = script.toFloat(&ok); + if (ok) { + QDeclarativeAction ra(d->target, QLatin1String("rotation"), rotation); + actions << ra; + } else { + QDeclarativeBinding *newBinding = new QDeclarativeBinding(script, d->target, qmlContext(this)); + newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("rotation"))); + QDeclarativeAction ra; + ra.property = newBinding->property(); + ra.toBinding = newBinding; + ra.fromValue = ra.property.read(); + ra.deletableToBinding = true; + actions << ra; + } } - if (d->width.isValid()) { - QDeclarativeAction wa(d->target, QLatin1String("width"), width()); - actions << wa; + if (d->widthString.isValid()) { + bool ok = false; + QString script = d->widthString.value.script(); + qreal width = script.toFloat(&ok); + if (ok) { + QDeclarativeAction wa(d->target, QLatin1String("width"), width); + actions << wa; + } else { + QDeclarativeBinding *newBinding = new QDeclarativeBinding(script, d->target, qmlContext(this)); + newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("width"))); + QDeclarativeAction wa; + wa.property = newBinding->property(); + wa.toBinding = newBinding; + wa.fromValue = wa.property.read(); + wa.deletableToBinding = true; + actions << wa; + } } - if (d->height.isValid()) { - QDeclarativeAction ha(d->target, QLatin1String("height"), height()); - actions << ha; + if (d->heightString.isValid()) { + bool ok = false; + QString script = d->heightString.value.script(); + qreal height = script.toFloat(&ok); + if (ok) { + QDeclarativeAction ha(d->target, QLatin1String("height"), height); + actions << ha; + } else { + QDeclarativeBinding *newBinding = new QDeclarativeBinding(script, d->target, qmlContext(this)); + newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("height"))); + QDeclarativeAction ha; + ha.property = newBinding->property(); + ha.toBinding = newBinding; + ha.fromValue = ha.property.read(); + ha.deletableToBinding = true; + actions << ha; + } } return actions; @@ -575,7 +659,7 @@ void QDeclarativeStateChangeScript::execute(Reason) Q_D(QDeclarativeStateChangeScript); const QString &script = d->script.script(); if (!script.isEmpty()) { - QDeclarativeExpression expr(d->script.context(), script, d->script.scopeObject()); + QDeclarativeExpression expr(d->script.context(), d->script.scopeObject(), script); QDeclarativeData *ddata = QDeclarativeData::get(this); if (ddata && ddata->outerContext && !ddata->outerContext->url.isEmpty()) expr.setSourceLocation(ddata->outerContext->url.toString(), ddata->lineNumber); diff --git a/src/declarative/util/qdeclarativestateoperations_p.h b/src/declarative/util/qdeclarativestateoperations_p.h index 21a86f5..05ad052 100644 --- a/src/declarative/util/qdeclarativestateoperations_p.h +++ b/src/declarative/util/qdeclarativestateoperations_p.h @@ -62,12 +62,12 @@ class Q_DECLARATIVE_EXPORT QDeclarativeParentChange : public QDeclarativeStateOp Q_PROPERTY(QDeclarativeItem *target READ object WRITE setObject) Q_PROPERTY(QDeclarativeItem *parent READ parent WRITE setParent) - Q_PROPERTY(qreal x READ x WRITE setX) - Q_PROPERTY(qreal y READ y WRITE setY) - Q_PROPERTY(qreal width READ width WRITE setWidth) - Q_PROPERTY(qreal height READ height WRITE setHeight) - Q_PROPERTY(qreal scale READ scale WRITE setScale) - Q_PROPERTY(qreal rotation READ rotation WRITE setRotation) + Q_PROPERTY(QDeclarativeScriptString x READ x WRITE setX) + Q_PROPERTY(QDeclarativeScriptString y READ y WRITE setY) + Q_PROPERTY(QDeclarativeScriptString width READ width WRITE setWidth) + Q_PROPERTY(QDeclarativeScriptString height READ height WRITE setHeight) + Q_PROPERTY(QDeclarativeScriptString scale READ scale WRITE setScale) + Q_PROPERTY(QDeclarativeScriptString rotation READ rotation WRITE setRotation) public: QDeclarativeParentChange(QObject *parent=0); ~QDeclarativeParentChange(); @@ -80,28 +80,28 @@ public: QDeclarativeItem *originalParent() const; - qreal x() const; - void setX(qreal x); + QDeclarativeScriptString x() const; + void setX(QDeclarativeScriptString x); bool xIsSet() const; - qreal y() const; - void setY(qreal y); + QDeclarativeScriptString y() const; + void setY(QDeclarativeScriptString y); bool yIsSet() const; - qreal width() const; - void setWidth(qreal width); + QDeclarativeScriptString width() const; + void setWidth(QDeclarativeScriptString width); bool widthIsSet() const; - qreal height() const; - void setHeight(qreal height); + QDeclarativeScriptString height() const; + void setHeight(QDeclarativeScriptString height); bool heightIsSet() const; - qreal scale() const; - void setScale(qreal scale); + QDeclarativeScriptString scale() const; + void setScale(QDeclarativeScriptString scale); bool scaleIsSet() const; - qreal rotation() const; - void setRotation(qreal rotation); + QDeclarativeScriptString rotation() const; + void setRotation(QDeclarativeScriptString rotation); bool rotationIsSet() const; virtual ActionList actions(); diff --git a/src/gui/painting/qdrawutil.cpp b/src/gui/painting/qdrawutil.cpp index ef9b18c..3ce95ef 100644 --- a/src/gui/painting/qdrawutil.cpp +++ b/src/gui/painting/qdrawutil.cpp @@ -1138,12 +1138,10 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin yTarget.resize(rows + 1); bool oldAA = painter->testRenderHint(QPainter::Antialiasing); - bool oldSmooth = painter->testRenderHint(QPainter::SmoothPixmapTransform); if (painter->paintEngine()->type() != QPaintEngine::OpenGL && painter->paintEngine()->type() != QPaintEngine::OpenGL2 - && (oldSmooth || oldAA) && painter->combinedTransform().type() != QTransform::TxNone) { + && oldAA && painter->combinedTransform().type() != QTransform::TxNone) { painter->setRenderHint(QPainter::Antialiasing, false); - painter->setRenderHint(QPainter::SmoothPixmapTransform, false); } xTarget[0] = targetRect.left(); @@ -1354,8 +1352,6 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin if (oldAA) painter->setRenderHint(QPainter::Antialiasing, true); - if (oldSmooth) - painter->setRenderHint(QPainter::SmoothPixmapTransform, true); } QT_END_NAMESPACE diff --git a/src/imports/folderlistmodel/folderlistmodel.pro b/src/imports/folderlistmodel/folderlistmodel.pro new file mode 100644 index 0000000..781dfc2 --- /dev/null +++ b/src/imports/folderlistmodel/folderlistmodel.pro @@ -0,0 +1,26 @@ +TARGET = qmlfolderlistmodelplugin +TARGETPATH = Qt/labs/folderlistmodel +include(../qimportbase.pri) + +QT += declarative script + +SOURCES += qdeclarativefolderlistmodel.cpp plugin.cpp +HEADERS += qdeclarativefolderlistmodel.h + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/imports/$$TARGETPATH +target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH + +qmldir.files += $$PWD/qmldir +qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH + +symbian:{ + load(data_caging_paths) + include($$QT_SOURCE_TREE/demos/symbianpkgrules.pri) + + importFiles.sources = qmlfolderlistmodelplugin.dll qmldir + importFiles.path = $$QT_IMPORTS_BASE_DIR/$$TARGETPATH + + DEPLOYMENT = importFiles +} + +INSTALLS += target qmldir diff --git a/src/imports/folderlistmodel/plugin.cpp b/src/imports/folderlistmodel/plugin.cpp new file mode 100644 index 0000000..d4569f7 --- /dev/null +++ b/src/imports/folderlistmodel/plugin.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** 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 plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtDeclarative/qdeclarativeextensionplugin.h> +#include <QtDeclarative/qdeclarative.h> + +#include "qdeclarativefolderlistmodel.h" + +QT_BEGIN_NAMESPACE + +//![class decl] +class QmlFolderListModelPlugin : public QDeclarativeExtensionPlugin +{ + Q_OBJECT +public: + virtual void registerTypes(const char *uri) + { + Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.labs.folderlistmodel")); + qmlRegisterType<QDeclarativeFolderListModel>(uri,1,0,"FolderListModel"); + } +}; +//![class decl] + +QT_END_NAMESPACE + +#include "plugin.moc" + +//![plugin export decl] +Q_EXPORT_PLUGIN2(qmlfolderlistmodelplugin, QT_PREPEND_NAMESPACE(QmlFolderListModelPlugin)); +//![plugin export decl] + diff --git a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp new file mode 100644 index 0000000..6a7383a --- /dev/null +++ b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp @@ -0,0 +1,401 @@ +/**************************************************************************** +** +** 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 examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//![code] +#include "qdeclarativefolderlistmodel.h" +#include <QDirModel> +#include <QDebug> +#include <qdeclarativecontext.h> + +QT_BEGIN_NAMESPACE + +class QDeclarativeFolderListModelPrivate +{ +public: + QDeclarativeFolderListModelPrivate() + : sortField(QDeclarativeFolderListModel::Name), sortReversed(false), count(0) { + nameFilters << QLatin1String("*"); + } + + void updateSorting() { + QDir::SortFlags flags = 0; + switch(sortField) { + case QDeclarativeFolderListModel::Unsorted: + flags |= QDir::Unsorted; + break; + case QDeclarativeFolderListModel::Name: + flags |= QDir::Name; + break; + case QDeclarativeFolderListModel::Time: + flags |= QDir::Time; + break; + case QDeclarativeFolderListModel::Size: + flags |= QDir::Size; + break; + case QDeclarativeFolderListModel::Type: + flags |= QDir::Type; + break; + } + + if (sortReversed) + flags |= QDir::Reversed; + + model.setSorting(flags); + } + + QDirModel model; + QUrl folder; + QStringList nameFilters; + QModelIndex folderIndex; + QDeclarativeFolderListModel::SortField sortField; + bool sortReversed; + int count; +}; + +/*! + \qmlclass FolderListModel + \brief The FolderListModel provides a model of the contents of a folder in a filesystem. + + FolderListModel provides access to the local filesystem. The \e folder property + specifies the folder to list. + + Qt uses "/" as a universal directory separator in the same way that "/" is + used as a path separator in URLs. If you always use "/" as a directory + separator, Qt will translate your paths to conform to the underlying + operating system. + + This type is made available by importing the \c Qt.labs.folderlistmodel module. + \e {Elements in the Qt.labs module are not guaranteed to remain compatible + in future versions.} + + \bold{import Qt.labs.folderlistmodel 1.0} + + The roles available are: + \list + \o fileName + \o filePath + \endlist + + Additionally a file entry can be differentiated from a folder entry + via the \l isFolder() method. +*/ + +QDeclarativeFolderListModel::QDeclarativeFolderListModel(QObject *parent) + : QAbstractListModel(parent) +{ + QHash<int, QByteArray> roles; + roles[FileNameRole] = "fileName"; + roles[FilePathRole] = "filePath"; + setRoleNames(roles); + + d = new QDeclarativeFolderListModelPrivate; + d->model.setFilter(QDir::AllDirs | QDir::Files | QDir::Drives | QDir::NoDotAndDotDot); + connect(&d->model, SIGNAL(rowsInserted(const QModelIndex&,int,int)) + , this, SLOT(inserted(const QModelIndex&,int,int))); + connect(&d->model, SIGNAL(rowsRemoved(const QModelIndex&,int,int)) + , this, SLOT(removed(const QModelIndex&,int,int))); + connect(&d->model, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)) + , this, SLOT(dataChanged(const QModelIndex&,const QModelIndex&))); + connect(&d->model, SIGNAL(modelReset()), this, SLOT(refresh())); + connect(&d->model, SIGNAL(layoutChanged()), this, SLOT(refresh())); +} + +QDeclarativeFolderListModel::~QDeclarativeFolderListModel() +{ + delete d; +} + +QVariant QDeclarativeFolderListModel::data(const QModelIndex &index, int role) const +{ + QVariant rv; + QModelIndex modelIndex = d->model.index(index.row(), 0, d->folderIndex); + if (modelIndex.isValid()) { + if (role == FileNameRole) + rv = d->model.data(modelIndex, QDirModel::FileNameRole).toString(); + else if (role == FilePathRole) + rv = QUrl::fromLocalFile(d->model.data(modelIndex, QDirModel::FilePathRole).toString()); + } + return rv; +} + +int QDeclarativeFolderListModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return d->count; +} + +/*! + \qmlproperty string FolderListModel::folder + + The \a folder property holds the folder the model is currently providing. + + It is a URL, but must be a file: or qrc: URL (or relative to such a URL). +*/ +QUrl QDeclarativeFolderListModel::folder() const +{ + return d->folder; +} + +void QDeclarativeFolderListModel::setFolder(const QUrl &folder) +{ + if (folder == d->folder) + return; + QModelIndex index = d->model.index(folder.toLocalFile()); + if (index.isValid() && d->model.isDir(index)) { + d->folder = folder; + QMetaObject::invokeMethod(this, "refresh", Qt::QueuedConnection); + emit folderChanged(); + } +} + +QUrl QDeclarativeFolderListModel::parentFolder() const +{ + QUrl r; + QString localFile = d->folder.toLocalFile(); + if (!localFile.isEmpty()) { + QDir dir(localFile); +#if defined(Q_OS_SYMBIAN) + if (dir.isRoot()) + dir.setPath(""); + else +#endif + dir.cdUp(); + r = d->folder; + r.setPath(dir.path()); + } else { + int pos = d->folder.path().lastIndexOf(QLatin1Char('/')); + if (pos == -1) + return QUrl(); + r = d->folder; + r.setPath(d->folder.path().left(pos)); + } + return r; +} + +/*! + \qmlproperty list<string> FolderListModel::nameFilters + + The \a nameFilters property contains a list of filename filters. + The filters may include the ? and * wildcards. + + The example below filters on PNG and JPEG files: + + \code + FolderListModel { + nameFilters: [ "*.png", "*.jpg" ] + } + \endcode +*/ +QStringList QDeclarativeFolderListModel::nameFilters() const +{ + return d->nameFilters; +} + +void QDeclarativeFolderListModel::setNameFilters(const QStringList &filters) +{ + d->nameFilters = filters; + d->model.setNameFilters(d->nameFilters); +} + +void QDeclarativeFolderListModel::classBegin() +{ +} + +void QDeclarativeFolderListModel::componentComplete() +{ + if (!d->folder.isValid() || !QDir().exists(d->folder.toLocalFile())) + setFolder(QUrl(QLatin1String("file://")+QDir::currentPath())); + + if (!d->folderIndex.isValid()) + QMetaObject::invokeMethod(this, "refresh", Qt::QueuedConnection); +} + +QDeclarativeFolderListModel::SortField QDeclarativeFolderListModel::sortField() const +{ + return d->sortField; +} + +void QDeclarativeFolderListModel::setSortField(SortField field) +{ + if (field != d->sortField) { + d->sortField = field; + d->updateSorting(); + } +} + +bool QDeclarativeFolderListModel::sortReversed() const +{ + return d->sortReversed; +} + +void QDeclarativeFolderListModel::setSortReversed(bool rev) +{ + if (rev != d->sortReversed) { + d->sortReversed = rev; + d->updateSorting(); + } +} + +/*! + \qmlmethod bool FolderListModel::isFolder(int index) + + Returns true if the entry \a index is a folder; otherwise + returns false. +*/ +bool QDeclarativeFolderListModel::isFolder(int index) const +{ + if (index != -1) { + QModelIndex idx = d->model.index(index, 0, d->folderIndex); + if (idx.isValid()) + return d->model.isDir(idx); + } + return false; +} + +void QDeclarativeFolderListModel::refresh() +{ + d->folderIndex = QModelIndex(); + if (d->count) { + emit beginRemoveRows(QModelIndex(), 0, d->count); + d->count = 0; + emit endRemoveRows(); + } + d->folderIndex = d->model.index(d->folder.toLocalFile()); + int newcount = d->model.rowCount(d->folderIndex); + if (newcount) { + emit beginInsertRows(QModelIndex(), 0, newcount-1); + d->count = newcount; + emit endInsertRows(); + } +} + +void QDeclarativeFolderListModel::inserted(const QModelIndex &index, int start, int end) +{ + if (index == d->folderIndex) { + emit beginInsertRows(QModelIndex(), start, end); + d->count = d->model.rowCount(d->folderIndex); + emit endInsertRows(); + } +} + +void QDeclarativeFolderListModel::removed(const QModelIndex &index, int start, int end) +{ + if (index == d->folderIndex) { + emit beginRemoveRows(QModelIndex(), start, end); + d->count = d->model.rowCount(d->folderIndex); + emit endRemoveRows(); + } +} + +void QDeclarativeFolderListModel::dataChanged(const QModelIndex &start, const QModelIndex &end) +{ + if (start.parent() == d->folderIndex) + emit dataChanged(index(start.row(),0), index(end.row(),0)); +} + +/*! + \qmlproperty bool FolderListModel::showDirs + + If true (the default), directories are included in the model. + + Note that the nameFilters are ignored for directories. +*/ +bool QDeclarativeFolderListModel::showDirs() const +{ + return d->model.filter() & QDir::AllDirs; +} + +void QDeclarativeFolderListModel::setShowDirs(bool on) +{ + if (!(d->model.filter() & QDir::AllDirs) == !on) + return; + if (on) + d->model.setFilter(d->model.filter() | QDir::AllDirs | QDir::Drives); + else + d->model.setFilter(d->model.filter() & ~(QDir::AllDirs | QDir::Drives)); +} + +/*! + \qmlproperty bool FolderListModel::showDotAndDotDot + + If true, the "." and ".." directories are included in the model. + + The default is false. +*/ +bool QDeclarativeFolderListModel::showDotAndDotDot() const +{ + return !(d->model.filter() & QDir::NoDotAndDotDot); +} + +void QDeclarativeFolderListModel::setShowDotAndDotDot(bool on) +{ + if (!(d->model.filter() & QDir::NoDotAndDotDot) == on) + return; + if (on) + d->model.setFilter(d->model.filter() & ~QDir::NoDotAndDotDot); + else + d->model.setFilter(d->model.filter() | QDir::NoDotAndDotDot); +} + +/*! + \qmlproperty bool FolderListModel::showOnlyReadable + + If true, only readable files and directories are shown. + + The default is false. +*/ +bool QDeclarativeFolderListModel::showOnlyReadable() const +{ + return d->model.filter() & QDir::Readable; +} + +void QDeclarativeFolderListModel::setShowOnlyReadable(bool on) +{ + if (!(d->model.filter() & QDir::Readable) == !on) + return; + if (on) + d->model.setFilter(d->model.filter() | QDir::Readable); + else + d->model.setFilter(d->model.filter() & ~QDir::Readable); +} + +//![code] +QT_END_NAMESPACE diff --git a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.h b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.h new file mode 100644 index 0000000..ea7d701 --- /dev/null +++ b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.h @@ -0,0 +1,155 @@ +/**************************************************************************** +** +** 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 examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEFOLDERLISTMODEL_H +#define QDECLARATIVEFOLDERLISTMODEL_H + +#include <qdeclarative.h> +#include <QStringList> +#include <QUrl> +#include <QAbstractListModel> + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QDeclarativeContext; +class QModelIndex; + +class QDeclarativeFolderListModelPrivate; + +//![class begin] +class QDeclarativeFolderListModel : public QAbstractListModel, public QDeclarativeParserStatus +{ + Q_OBJECT + Q_INTERFACES(QDeclarativeParserStatus) +//![class begin] + +//![class props] + Q_PROPERTY(QUrl folder READ folder WRITE setFolder NOTIFY folderChanged) + Q_PROPERTY(QUrl parentFolder READ parentFolder NOTIFY folderChanged) + Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters) + Q_PROPERTY(SortField sortField READ sortField WRITE setSortField) + Q_PROPERTY(bool sortReversed READ sortReversed WRITE setSortReversed) + Q_PROPERTY(bool showDirs READ showDirs WRITE setShowDirs) + Q_PROPERTY(bool showDotAndDotDot READ showDotAndDotDot WRITE setShowDotAndDotDot) + Q_PROPERTY(bool showOnlyReadable READ showOnlyReadable WRITE setShowOnlyReadable) + Q_PROPERTY(int count READ count) +//![class props] + +//![abslistmodel] +public: + QDeclarativeFolderListModel(QObject *parent = 0); + ~QDeclarativeFolderListModel(); + + enum Roles { FileNameRole = Qt::UserRole+1, FilePathRole = Qt::UserRole+2 }; + + int rowCount(const QModelIndex &parent) const; + QVariant data(const QModelIndex &index, int role) const; +//![abslistmodel] + +//![count] + int count() const { return rowCount(QModelIndex()); } +//![count] + +//![prop funcs] + QUrl folder() const; + void setFolder(const QUrl &folder); + + QUrl parentFolder() const; + + QStringList nameFilters() const; + void setNameFilters(const QStringList &filters); + + enum SortField { Unsorted, Name, Time, Size, Type }; + SortField sortField() const; + void setSortField(SortField field); + Q_ENUMS(SortField) + + bool sortReversed() const; + void setSortReversed(bool rev); + + bool showDirs() const; + void setShowDirs(bool); + bool showDotAndDotDot() const; + void setShowDotAndDotDot(bool); + bool showOnlyReadable() const; + void setShowOnlyReadable(bool); +//![prop funcs] + +//![isfolder] + Q_INVOKABLE bool isFolder(int index) const; +//![isfolder] + +//![parserstatus] + virtual void classBegin(); + virtual void componentComplete(); +//![parserstatus] + +//![notifier] +Q_SIGNALS: + void folderChanged(); +//![notifier] + +//![class end] +private Q_SLOTS: + void refresh(); + void inserted(const QModelIndex &index, int start, int end); + void removed(const QModelIndex &index, int start, int end); + void dataChanged(const QModelIndex &start, const QModelIndex &end); + +private: + Q_DISABLE_COPY(QDeclarativeFolderListModel) + QDeclarativeFolderListModelPrivate *d; +}; +//![class end] + +QT_END_NAMESPACE + +//![qml decl] +QML_DECLARE_TYPE(QDeclarativeFolderListModel) +//![qml decl] + +QT_END_HEADER + +#endif // QDECLARATIVEFOLDERLISTMODEL_H diff --git a/src/imports/folderlistmodel/qmldir b/src/imports/folderlistmodel/qmldir new file mode 100644 index 0000000..6e115bb --- /dev/null +++ b/src/imports/folderlistmodel/qmldir @@ -0,0 +1 @@ +plugin qmlfolderlistmodelplugin diff --git a/src/imports/gestures/qdeclarativegesturearea.cpp b/src/imports/gestures/qdeclarativegesturearea.cpp index 19afe0c..1b0aeeb 100644 --- a/src/imports/gestures/qdeclarativegesturearea.cpp +++ b/src/imports/gestures/qdeclarativegesturearea.cpp @@ -226,7 +226,7 @@ void QDeclarativeGestureArea::connectSignals() ds >> gesturetype; QString script; ds >> script; - QDeclarativeExpression *exp = new QDeclarativeExpression(qmlContext(this), script, 0); + QDeclarativeExpression *exp = new QDeclarativeExpression(qmlContext(this), 0, script); d->bindings.insert(Qt::GestureType(gesturetype),exp); grabGesture(Qt::GestureType(gesturetype)); } diff --git a/src/imports/imports.pro b/src/imports/imports.pro index a45af95..7f9331a 100644 --- a/src/imports/imports.pro +++ b/src/imports/imports.pro @@ -1,6 +1,6 @@ TEMPLATE = subdirs -SUBDIRS += particles gestures +SUBDIRS += folderlistmodel particles gestures contains(QT_CONFIG, webkit): SUBDIRS += webkit |