diff options
Diffstat (limited to 'src/declarative/graphicsitems')
14 files changed, 465 insertions, 221 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index d4c65ae..c507795 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -128,8 +128,8 @@ QDeclarativeFlickablePrivate::QDeclarativeFlickablePrivate() , flickingHorizontally(false), flickingVertically(false) , hMoved(false), vMoved(false) , movingHorizontally(false), movingVertically(false) - , stealMouse(false), pressed(false) - , interactive(true), deceleration(500), maxVelocity(2000), reportedVelocitySmoothing(100) + , stealMouse(false), pressed(false), interactive(true), calcVelocity(false) + , deceleration(500), maxVelocity(2000), reportedVelocitySmoothing(100) , delayedPressEvent(0), delayedPressTarget(0), pressDelay(0), fixupDuration(600) , vTime(0), visibleArea(0) , flickableDirection(QDeclarativeFlickable::AutoFlickDirection) @@ -372,11 +372,12 @@ void QDeclarativeFlickablePrivate::updateBeginningEnd() \inlineimage flickable.gif \endfloat - The following example shows a large + The following example shows a small view onto a large image in which the + user can drag or flick the image in order to view different parts of it. - \clearfloat \snippet doc/src/snippets/declarative/flickable.qml document + \clearfloat \section1 Limitations \note Due to an implementation detail, items placed inside a Flickable cannot anchor to it by @@ -981,7 +982,7 @@ void QDeclarativeFlickable::viewportMoved() qreal prevY = d->lastFlickablePosition.x(); qreal prevX = d->lastFlickablePosition.y(); d->velocityTimeline.clear(); - if (d->pressed) { + if (d->pressed || d->calcVelocity) { int elapsed = QDeclarativeItemPrivate::restart(d->velocityTime); if (elapsed > 0) { qreal horizontalVelocity = (prevX - d->hData.move.value()) * 1000 / elapsed; diff --git a/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h b/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h index 261b271..beee741 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h @@ -141,6 +141,7 @@ public: bool stealMouse : 1; bool pressed : 1; bool interactive : 1; + bool calcVelocity : 1; QElapsedTimer lastPosTime; QPointF lastPos; QPointF pressPos; @@ -173,7 +174,7 @@ public: // flickableData property static void data_append(QDeclarativeListProperty<QObject> *, QObject *); static int data_count(QDeclarativeListProperty<QObject> *); - static QObject * data_at(QDeclarativeListProperty<QObject> *, int); + static QObject *data_at(QDeclarativeListProperty<QObject> *, int); static void data_clear(QDeclarativeListProperty<QObject> *); }; diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index a0faf14..8d08c99 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -1070,27 +1070,41 @@ void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal m GridView are laid out horizontally or vertically. Grid views are inherently flickable as GridView inherits from \l Flickable. - For example, if there is a simple list model defined in a file \c ContactModel.qml like this: + \section1 Example Usage + + The following example shows the definition of a simple list model defined + in a file called \c ContactModel.qml: \snippet doc/src/snippets/declarative/gridview/ContactModel.qml 0 - Another component can display this model data in a GridView, like this: + \beginfloatright + \inlineimage gridview-simple.png + \endfloat + + This model can be referenced as \c ContactModel in other QML files. See \l{QML Modules} + for more information about creating reusable components like this. + + Another component can display this model data in a GridView, as in the following + example, which creates a \c ContactModel component for its model, and a \l Column element + (containing \l Image and \l Text elements) for its delegate. + \clearfloat \snippet doc/src/snippets/declarative/gridview/gridview.qml import \codeline \snippet doc/src/snippets/declarative/gridview/gridview.qml classdocs simple - \image gridview-simple.png - Here, the GridView creates a \c ContactModel component for its model, and a \l Column element - (containing \l Image and \ Text elements) for its delegate. The view will create a new delegate - for each item in the model. Notice the delegate is able to access the model's \c name and - \c portrait data directly. + \beginfloatright + \inlineimage gridview-highlight.png + \endfloat + + The view will create a new delegate for each item in the model. Note that the delegate + is able to access the model's \c name and \c portrait data directly. An improved grid view is shown below. The delegate is visually improved and is moved into a separate \c contactDelegate component. - + + \clearfloat \snippet doc/src/snippets/declarative/gridview/gridview.qml classdocs advanced - \image gridview-highlight.png 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 grid view. @@ -1099,10 +1113,10 @@ void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal m Delegates are instantiated as needed and may be destroyed at any time. State should \e never be stored in a delegate. - \note Views do not enable \e clip automatically. If the view - is not clipped by another item or the screen, it will be necessary - to set \e {clip: true} in order to have the out of view items clipped - nicely. + \note Views do not set the \l{Item::}{clip} property automatically. + If the view is not clipped by another item or the screen, it will be necessary + to set this property to true in order to clip the items that are partially or + fully outside the view. \sa {declarative/modelviews/gridview}{GridView example} */ @@ -2241,7 +2255,9 @@ void QDeclarativeGridView::trackedPositionChanged() } if (viewPos != pos) { cancelFlick(); + d->calcVelocity = true; d->setPosition(pos); + d->calcVelocity = false; } } } diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 11f9179..e9da4f7 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -44,6 +44,7 @@ #include "private/qdeclarativeevents_p_p.h" #include <private/qdeclarativeengine_p.h> +#include <private/qgraphicsitem_p.h> #include <qdeclarativeengine.h> #include <qdeclarativeopenmetaobject_p.h> @@ -1619,6 +1620,51 @@ void QDeclarativeItemPrivate::data_append(QDeclarativeListProperty<QObject> *pro } } +static inline int children_count_helper(QDeclarativeListProperty<QObject> *prop) +{ + QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(static_cast<QGraphicsObject *>(prop->object)); + return d->children.count(); +} + +static inline QObject *children_at_helper(QDeclarativeListProperty<QObject> *prop, int index) +{ + QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(static_cast<QGraphicsObject *>(prop->object)); + if (index >= 0 && index < d->children.count()) + return d->children.at(index)->toGraphicsObject(); + else + return 0; +} + +static inline void children_clear_helper(QDeclarativeListProperty<QObject> *prop) +{ + QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(static_cast<QGraphicsObject *>(prop->object)); + int childCount = d->children.count(); + for (int index = 0 ;index < childCount; index++) + QGraphicsItemPrivate::get(d->children.at(0))->setParentItemHelper(0, /*newParentVariant=*/0, /*thisPointerVariant=*/0); +} + +int QDeclarativeItemPrivate::data_count(QDeclarativeListProperty<QObject> *prop) +{ + return resources_count(prop) + children_count_helper(prop); +} + +QObject *QDeclarativeItemPrivate::data_at(QDeclarativeListProperty<QObject> *prop, int i) +{ + int resourcesCount = resources_count(prop); + if (i < resourcesCount) + return resources_at(prop, i); + const int j = i - resourcesCount; + if (j < children_count_helper(prop)) + return children_at_helper(prop, j); + return 0; +} + +void QDeclarativeItemPrivate::data_clear(QDeclarativeListProperty<QObject> *prop) +{ + resources_clear(prop); + children_clear_helper(prop); +} + QObject *QDeclarativeItemPrivate::resources_at(QDeclarativeListProperty<QObject> *prop, int index) { const QObjectList children = prop->object->children(); @@ -1638,6 +1684,13 @@ int QDeclarativeItemPrivate::resources_count(QDeclarativeListProperty<QObject> * return prop->object->children().count(); } +void QDeclarativeItemPrivate::resources_clear(QDeclarativeListProperty<QObject> *prop) +{ + const QObjectList children = prop->object->children(); + for (int index = 0; index < children.count(); index++) + children.at(index)->setParent(0); +} + int QDeclarativeItemPrivate::transform_count(QDeclarativeListProperty<QGraphicsTransform> *list) { QGraphicsObject *object = qobject_cast<QGraphicsObject *>(list->object); @@ -1724,7 +1777,11 @@ void QDeclarativeItemPrivate::parentProperty(QObject *o, void *rv, QDeclarativeN QDeclarativeListProperty<QObject> QDeclarativeItemPrivate::data() { - return QDeclarativeListProperty<QObject>(q_func(), 0, QDeclarativeItemPrivate::data_append); + return QDeclarativeListProperty<QObject>(q_func(), 0, QDeclarativeItemPrivate::data_append, + QDeclarativeItemPrivate::data_count, + QDeclarativeItemPrivate::data_at, + QDeclarativeItemPrivate::data_clear + ); } /*! @@ -2413,7 +2470,9 @@ QDeclarativeListProperty<QObject> QDeclarativeItemPrivate::resources() { return QDeclarativeListProperty<QObject>(q_func(), 0, QDeclarativeItemPrivate::resources_append, QDeclarativeItemPrivate::resources_count, - QDeclarativeItemPrivate::resources_at); + QDeclarativeItemPrivate::resources_at, + QDeclarativeItemPrivate::resources_clear + ); } /*! @@ -2484,7 +2543,7 @@ QDeclarativeListProperty<QDeclarativeTransition> QDeclarativeItemPrivate::transi /*! \qmlproperty bool Item::clip - This property holds whether clipping is enabled. + This property holds whether clipping is enabled. The default clip value is \c false. If clipping is enabled, an item will clip its own painting, as well as the painting of its children, to its bounding rectangle. @@ -2494,9 +2553,9 @@ QDeclarativeListProperty<QDeclarativeTransition> QDeclarativeItemPrivate::transi /*! \property QDeclarativeItem::clip - This property holds whether clipping is enabled. + This property holds whether clipping is enabled. The default clip value is \c false. - if clipping is enabled, an item will clip its own painting, as well + If clipping is enabled, an item will clip its own painting, as well as the painting of its children, to its bounding rectangle. If you set clipping during an item's paint operation, remember to re-set it to prevent clipping the rest of your scene. diff --git a/src/declarative/graphicsitems/qdeclarativeitem_p.h b/src/declarative/graphicsitems/qdeclarativeitem_p.h index fffb4f7..f85fa27 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem_p.h +++ b/src/declarative/graphicsitems/qdeclarativeitem_p.h @@ -176,11 +176,15 @@ public: // data property static void data_append(QDeclarativeListProperty<QObject> *, QObject *); + static int data_count(QDeclarativeListProperty<QObject> *); + static QObject *data_at(QDeclarativeListProperty<QObject> *, int); + static void data_clear(QDeclarativeListProperty<QObject> *); // resources property static QObject *resources_at(QDeclarativeListProperty<QObject> *, int); static void resources_append(QDeclarativeListProperty<QObject> *, QObject *); static int resources_count(QDeclarativeListProperty<QObject> *); + static void resources_clear(QDeclarativeListProperty<QObject> *); // transform property static int transform_count(QDeclarativeListProperty<QGraphicsTransform> *list); diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 177c5b3..c1e6aaa 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -1394,11 +1394,14 @@ void QDeclarativeListViewPrivate::flick(AxisData &data, qreal minExtent, qreal m 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. + 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 because ListView inherits from \l Flickable. - For example, if there is a simple list model defined in a file \c ContactModel.qml like this: + \section1 Example Usage + + The following example shows the definition of a simple list model defined + in a file called \c ContactModel.qml: \snippet doc/src/snippets/declarative/listview/ContactModel.qml 0 @@ -1416,7 +1419,7 @@ void QDeclarativeListViewPrivate::flick(AxisData &data, qreal minExtent, qreal m An improved list view is shown below. The delegate is visually improved and is moved into a separate \c contactDelegate component. - + \snippet doc/src/snippets/declarative/listview/listview.qml classdocs advanced \image listview-highlight.png @@ -2732,7 +2735,9 @@ void QDeclarativeListView::trackedPositionChanged() } if (viewPos != pos) { cancelFlick(); + d->calcVelocity = true; d->setPosition(pos); + d->calcVelocity = false; } } } diff --git a/src/declarative/graphicsitems/qdeclarativeloader.cpp b/src/declarative/graphicsitems/qdeclarativeloader.cpp index 5d71625..1066c2b 100644 --- a/src/declarative/graphicsitems/qdeclarativeloader.cpp +++ b/src/declarative/graphicsitems/qdeclarativeloader.cpp @@ -212,8 +212,8 @@ QDeclarativeLoader::~QDeclarativeLoader() \qmlproperty url Loader::source This property holds the URL of the QML component to instantiate. - Note the QML component must be an \l Item-based component. Loader cannot - load non-visual components. + Note the QML component must be an \l{Item}-based component. The loader + cannot load non-visual components. To unload the currently loaded item, set this property to an empty string, or set \l sourceComponent to \c undefined. @@ -275,8 +275,8 @@ void QDeclarativeLoader::setSource(const QUrl &url) } \endqml - To unload the currently loaded item, set this property to an empty string, - or set \l sourceComponent to \c undefined. + To unload the currently loaded item, set this property to an empty string + or \c undefined. \sa source, progress */ diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp index 5516611..a0208ef 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp +++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp @@ -185,27 +185,57 @@ QDeclarativeMouseAreaPrivate::~QDeclarativeMouseAreaPrivate() \brief The MouseArea item enables simple mouse handling. \inherits Item - A MouseArea is typically used in conjunction with a visible item, - where the MouseArea effectively 'proxies' mouse handling for that - item. For example, we can put a MouseArea in a \l Rectangle that changes + A MouseArea is an invisible item that is typically used in conjunction with + a visible item in order to provide mouse handling for that item. + By effectively acting as a proxy, the logic for mouse handling can be + contained within a MouseArea item. + + For basic key handling, see the \l{Keys}{Keys attached property}. + + The \l enabled property is used to enable and disable mouse handling for + the proxied item. When disabled, the mouse area becomes transparent to + mouse events. + + The \l pressed read-only property indicates whether or not the user is + holding down a mouse button over the mouse area. This property is often + used in bindings between properties in a user interface. The containsMouse + read-only property indicates the presence of the mouse cursor over the + mouse area but, by default, only when a mouse button is held down; see below + for further details. + + Information about the mouse position and button clicks are provided via + signals for which event handler properties are defined. The most commonly + used involved handling mouse presses and clicks: onClicked, onDoubleClicked, + onPressed, onReleased and onPressAndHold. + + By default, MouseArea items only report mouse clicks and not changes to the + position of the mouse cursor. Setting the hoverEnabled property ensures that + handlers defined for onPositionChanged, onEntered and onExited are used and + that the containsMouse property is updated even when no mouse buttons are + pressed. + + \section1 Example Usage + + \beginfloatright + \inlineimage qml-mousearea-snippet.png + \endfloat + + The following example uses a MouseArea in a \l Rectangle that changes the \l Rectangle color to red when clicked: - \snippet doc/src/snippets/declarative/mousearea.qml import + \snippet doc/src/snippets/declarative/mousearea/mousearea.qml import \codeline - \snippet doc/src/snippets/declarative/mousearea.qml intro + \snippet doc/src/snippets/declarative/mousearea/mousearea.qml intro - Many MouseArea signals pass a \l {MouseEvent}{mouse} parameter that contains + \clearfloat + Many MouseArea signals pass a \l{MouseEvent}{mouse} parameter that contains additional information about the mouse event, such as the position, button, and any key modifiers. Here is an extension of the previous example that produces a different color when the area is right clicked: - \snippet doc/src/snippets/declarative/mousearea.qml intro-extended - - For basic key handling, see the \l {Keys}{Keys attached property}. - - MouseArea is an invisible item: it is never painted. + \snippet doc/src/snippets/declarative/mousearea/mousearea.qml intro-extended \sa MouseEvent, {declarative/touchinteraction/mousearea}{MouseArea example} */ @@ -303,18 +333,23 @@ QDeclarativeMouseAreaPrivate::~QDeclarativeMouseAreaPrivate() The \l {MouseEvent}{mouse} parameter provides information about the click, including the x and y position of the release of the click, and whether the click was held. - The \e accepted property of the MouseEvent parameter is ignored in this handler. + If the \e accepted property of the \l {MouseEvent}{mouse} parameter is set to false + in the handler, the onPressed/onReleased/onClicked handlers will be called for the second + click; otherwise they are supressed. The accepted property defaults to true. */ /*! \qmlsignal MouseArea::onCanceled() This handler is called when mouse events have been canceled, either because an event was not accepted, or - because another element stole the mouse event handling. This signal is for advanced use: it is useful when - there is more than one MouseArea that is handling input, or when there is a MouseArea inside a \l Flickable. In the latter - case, if you execute some logic on the pressed signal and then start dragging, the \l Flickable will steal the mouse handling - from the MouseArea. In these cases, to reset the logic when the MouseArea has lost the mouse handling to the - \l Flickable, \c onCanceled should be used in addition to onReleased. + because another element stole the mouse event handling. + + This signal is for advanced use: it is useful when there is more than one MouseArea + that is handling input, or when there is a MouseArea inside a \l Flickable. In the latter + case, if you execute some logic on the pressed signal and then start dragging, the + \l Flickable will steal the mouse handling from the MouseArea. In these cases, to reset + the logic when the MouseArea has lost the mouse handling to the \l Flickable, + \c onCanceled should be used in addition to onReleased. */ QDeclarativeMouseArea::QDeclarativeMouseArea(QDeclarativeItem *parent) @@ -331,11 +366,13 @@ QDeclarativeMouseArea::~QDeclarativeMouseArea() /*! \qmlproperty real MouseArea::mouseX \qmlproperty real MouseArea::mouseY - These properties hold the coordinates of the mouse. + These properties hold the coordinates of the mouse cursor. If the hoverEnabled property is false then these properties will only be valid while a button is pressed, and will remain valid as long as the button is held - even if the mouse is moved outside the area. + down even if the mouse is moved outside the area. + + By default, this property is false. If hoverEnabled is true then these properties will be valid when: \list @@ -360,6 +397,8 @@ qreal QDeclarativeMouseArea::mouseY() const /*! \qmlproperty bool MouseArea::enabled This property holds whether the item accepts mouse events. + + By default, this property is true. */ bool QDeclarativeMouseArea::isEnabled() const { @@ -387,7 +426,8 @@ void QDeclarativeMouseArea::setEnabled(bool a) \endlist The code below displays "right" when the right mouse buttons is pressed: - \snippet doc/src/snippets/declarative/mousearea.qml mousebuttons + + \snippet doc/src/snippets/declarative/mousearea/mousearea.qml mousebuttons \sa acceptedButtons */ @@ -525,12 +565,13 @@ void QDeclarativeMouseArea::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *even if (!d->absorb) { QDeclarativeItem::mouseDoubleClickEvent(event); } else { - QDeclarativeItem::mouseDoubleClickEvent(event); - if (event->isAccepted()) { - // Only deliver the event if we have accepted the press. - d->saveEvent(event); - QDeclarativeMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, true, false); - emit this->doubleClicked(&me); + d->saveEvent(event); + QDeclarativeMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, true, false); + me.setAccepted(d->isDoubleClickConnected()); + emit this->doubleClicked(&me); + if (!me.isAccepted()) { + // Only deliver the press event if we haven't accepted the double click. + QDeclarativeItem::mouseDoubleClickEvent(event); } } } @@ -704,7 +745,8 @@ QVariant QDeclarativeMouseArea::itemChange(GraphicsItemChange change, pressed. Hover enables handling of all mouse events even when no mouse button is pressed. - This property affects the containsMouse property and the onEntered, onExited and onPositionChanged signals. + This property affects the containsMouse property and the onEntered, onExited and + onPositionChanged signals. */ bool QDeclarativeMouseArea::hoverEnabled() const { @@ -847,7 +889,7 @@ QDeclarativeDrag *QDeclarativeMouseArea::drag() The following example displays a \l Rectangle that can be dragged along the X-axis. The opacity of the rectangle is reduced when it is dragged to the right. - \snippet doc/src/snippets/declarative/mousearea.qml drag + \snippet doc/src/snippets/declarative/mousearea/mousearea.qml drag \note Items cannot be dragged if they are anchored for the requested \c drag.axis. For example, if \c anchors.left or \c anchors.right was set @@ -858,7 +900,7 @@ QDeclarativeDrag *QDeclarativeMouseArea::drag() If \c drag.filterChildren is set to true, a drag can override descendant MouseAreas. This enables a parent MouseArea to handle drags, for example, while descendants handle clicks: - \snippet doc/src/snippets/declarative/mouseareadragfilter.qml dragfilter + \snippet doc/src/snippets/declarative/mousearea/mouseareadragfilter.qml dragfilter */ diff --git a/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h b/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h index cf9dc18..48a56d9 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h @@ -95,6 +95,12 @@ public: return QObjectPrivate::get(q)->isSignalConnected(idx); } + bool isDoubleClickConnected() { + Q_Q(QDeclarativeMouseArea); + static int idx = QObjectPrivate::get(q)->signalIndex("doubleClicked(QDeclarativeMouseEvent*)"); + return QObjectPrivate::get(q)->isSignalConnected(idx); + } + bool absorb : 1; bool hovered : 1; bool pressed : 1; diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp index de3f9fa..d134929 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview.cpp +++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp @@ -141,11 +141,13 @@ void QDeclarativePathViewPrivate::releaseItem(QDeclarativeItem *item) { if (!item || !model) return; - if (QDeclarativePathViewAttached *att = attached(item)) - att->setOnPath(false); QDeclarativeItemPrivate *itemPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(item)); itemPrivate->removeItemChangeListener(this, QDeclarativeItemPrivate::Geometry); - model->release(item); + if (model->release(item) == 0) { + // item was not destroyed, and we no longer reference it. + if (QDeclarativePathViewAttached *att = attached(item)) + att->setOnPath(false); + } } QDeclarativePathViewAttached *QDeclarativePathViewPrivate::attached(QDeclarativeItem *item) @@ -404,14 +406,14 @@ QDeclarativePathView::~QDeclarativePathView() be instantiated, but not considered to be currently on the path. Usually, these items would be set invisible, for example: - \code + \qml Component { Rectangle { visible: PathView.onPath ... } } - \endcode + \endqml It is attached to each instance of the delegate. */ @@ -1033,103 +1035,138 @@ QPointF QDeclarativePathViewPrivate::pointNear(const QPointF &point, qreal *near return nearPoint; } - void QDeclarativePathView::mousePressEvent(QGraphicsSceneMouseEvent *event) { Q_D(QDeclarativePathView); - if (!d->interactive || !d->items.count()) + if (d->interactive) { + d->handleMousePressEvent(event); + event->accept(); + } else { + QDeclarativeItem::mousePressEvent(event); + } +} + +void QDeclarativePathViewPrivate::handleMousePressEvent(QGraphicsSceneMouseEvent *event) +{ + Q_Q(QDeclarativePathView); + if (!interactive || !items.count()) return; - QPointF scenePoint = mapToScene(event->pos()); + QPointF scenePoint = q->mapToScene(event->pos()); int idx = 0; - for (; idx < d->items.count(); ++idx) { - QRectF rect = d->items.at(idx)->boundingRect(); - rect = d->items.at(idx)->mapToScene(rect).boundingRect(); + for (; idx < items.count(); ++idx) { + QRectF rect = items.at(idx)->boundingRect(); + rect = items.at(idx)->mapToScene(rect).boundingRect(); if (rect.contains(scenePoint)) break; } - if (idx == d->items.count() && d->dragMargin == 0.) // didn't click on an item + if (idx == items.count() && dragMargin == 0.) // didn't click on an item return; - d->startPoint = d->pointNear(event->pos(), &d->startPc); - if (idx == d->items.count()) { - qreal distance = qAbs(event->pos().x() - d->startPoint.x()) + qAbs(event->pos().y() - d->startPoint.y()); - if (distance > d->dragMargin) + startPoint = pointNear(event->pos(), &startPc); + if (idx == items.count()) { + qreal distance = qAbs(event->pos().x() - startPoint.x()) + qAbs(event->pos().y() - startPoint.y()); + if (distance > dragMargin) return; } - if (d->tl.isActive() && d->flicking) - d->stealMouse = true; // If we've been flicked then steal the click. + if (tl.isActive() && flicking) + stealMouse = true; // If we've been flicked then steal the click. else - d->stealMouse = false; + stealMouse = false; - d->lastElapsed = 0; - d->lastDist = 0; - QDeclarativeItemPrivate::start(d->lastPosTime); - d->tl.clear(); + lastElapsed = 0; + lastDist = 0; + QDeclarativeItemPrivate::start(lastPosTime); + tl.clear(); } void QDeclarativePathView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { Q_D(QDeclarativePathView); - if (!d->interactive || !d->lastPosTime.isValid()) + if (d->interactive) { + d->handleMouseMoveEvent(event); + if (d->stealMouse) + setKeepMouseGrab(true); + event->accept(); + } else { + QDeclarativeItem::mouseMoveEvent(event); + } +} + +void QDeclarativePathViewPrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + Q_Q(QDeclarativePathView); + if (!interactive || !lastPosTime.isValid()) return; - if (!d->stealMouse) { - QPointF delta = event->pos() - d->startPoint; + if (!stealMouse) { + QPointF delta = event->pos() - startPoint; if (qAbs(delta.x()) > QApplication::startDragDistance() || qAbs(delta.y()) > QApplication::startDragDistance()) - d->stealMouse = true; + stealMouse = true; } - if (d->stealMouse) { - d->moveReason = QDeclarativePathViewPrivate::Mouse; + if (stealMouse) { + moveReason = QDeclarativePathViewPrivate::Mouse; qreal newPc; - d->pointNear(event->pos(), &newPc); - qreal diff = (newPc - d->startPc)*d->modelCount*d->mappedRange; + pointNear(event->pos(), &newPc); + qreal diff = (newPc - startPc)*modelCount*mappedRange; if (diff) { - setOffset(d->offset + diff); + setOffset(offset + diff); - if (diff > d->modelCount/2) - diff -= d->modelCount; - else if (diff < -d->modelCount/2) - diff += d->modelCount; + if (diff > modelCount/2) + diff -= modelCount; + else if (diff < -modelCount/2) + diff += modelCount; - d->lastElapsed = QDeclarativeItemPrivate::restart(d->lastPosTime); - d->lastDist = diff; - d->startPc = newPc; + lastElapsed = QDeclarativeItemPrivate::restart(lastPosTime); + lastDist = diff; + startPc = newPc; } - if (!d->moving) { - d->moving = true; - emit movingChanged(); - emit movementStarted(); + if (!moving) { + moving = true; + emit q->movingChanged(); + emit q->movementStarted(); } } } -void QDeclarativePathView::mouseReleaseEvent(QGraphicsSceneMouseEvent *) +void QDeclarativePathView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { Q_D(QDeclarativePathView); - d->stealMouse = false; - setKeepMouseGrab(false); - if (!d->interactive || !d->lastPosTime.isValid()) + if (d->interactive) { + d->handleMouseReleaseEvent(event); + event->accept(); + ungrabMouse(); + } else { + QDeclarativeItem::mouseReleaseEvent(event); + } +} + +void QDeclarativePathViewPrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *) +{ + Q_Q(QDeclarativePathView); + stealMouse = false; + q->setKeepMouseGrab(false); + if (!interactive || !lastPosTime.isValid()) return; - qreal elapsed = qreal(d->lastElapsed + QDeclarativeItemPrivate::elapsed(d->lastPosTime)) / 1000.; - qreal velocity = elapsed > 0. ? d->lastDist / elapsed : 0; - if (d->model && d->modelCount && qAbs(velocity) > 1.) { - qreal count = d->pathItems == -1 ? d->modelCount : d->pathItems; + qreal elapsed = qreal(lastElapsed + QDeclarativeItemPrivate::elapsed(lastPosTime)) / 1000.; + qreal velocity = elapsed > 0. ? lastDist / elapsed : 0; + if (model && modelCount && qAbs(velocity) > 1.) { + qreal count = pathItems == -1 ? modelCount : pathItems; if (qAbs(velocity) > count * 2) // limit velocity velocity = (velocity > 0 ? count : -count) * 2; // Calculate the distance to be travelled qreal v2 = velocity*velocity; - qreal accel = d->deceleration/10; + qreal accel = deceleration/10; // + 0.25 to encourage moving at least one item in the flick direction - qreal dist = qMin(qreal(d->modelCount-1), qreal(v2 / (accel * 2.0) + 0.25)); - if (d->haveHighlightRange && d->highlightRangeMode == QDeclarativePathView::StrictlyEnforceRange) { + qreal dist = qMin(qreal(modelCount-1), qreal(v2 / (accel * 2.0) + 0.25)); + if (haveHighlightRange && highlightRangeMode == QDeclarativePathView::StrictlyEnforceRange) { // round to nearest item. if (velocity > 0.) - dist = qRound(dist + d->offset) - d->offset; + dist = qRound(dist + offset) - offset; else - dist = qRound(dist - d->offset) + d->offset; + dist = qRound(dist - offset) + offset; // Calculate accel required to stop on item boundary if (dist <= 0.) { dist = 0.; @@ -1138,23 +1175,22 @@ void QDeclarativePathView::mouseReleaseEvent(QGraphicsSceneMouseEvent *) accel = v2 / (2.0f * qAbs(dist)); } } - d->offsetAdj = 0.0; - d->moveOffset.setValue(d->offset); - d->tl.accel(d->moveOffset, velocity, accel, dist); - d->tl.callback(QDeclarativeTimeLineCallback(&d->moveOffset, d->fixOffsetCallback, d)); - if (!d->flicking) { - d->flicking = true; - emit flickingChanged(); - emit flickStarted(); + offsetAdj = 0.0; + moveOffset.setValue(offset); + tl.accel(moveOffset, velocity, accel, dist); + tl.callback(QDeclarativeTimeLineCallback(&moveOffset, fixOffsetCallback, this)); + if (!flicking) { + flicking = true; + emit q->flickingChanged(); + emit q->flickStarted(); } } else { - d->fixOffset(); + fixOffset(); } - d->lastPosTime.invalidate(); - ungrabMouse(); - if (!d->tl.isActive()) - movementEnding(); + lastPosTime.invalidate(); + if (!tl.isActive()) + q->movementEnding(); } bool QDeclarativePathView::sendMouseEvent(QGraphicsSceneMouseEvent *event) @@ -1164,7 +1200,8 @@ bool QDeclarativePathView::sendMouseEvent(QGraphicsSceneMouseEvent *event) QRectF myRect = mapToScene(QRectF(0, 0, width(), height())).boundingRect(); QGraphicsScene *s = scene(); QDeclarativeItem *grabber = s ? qobject_cast<QDeclarativeItem*>(s->mouseGrabberItem()) : 0; - if ((d->stealMouse || myRect.contains(event->scenePos().toPoint())) && (!grabber || !grabber->keepMouseGrab())) { + bool stealThisEvent = d->stealMouse; + if ((stealThisEvent || myRect.contains(event->scenePos().toPoint())) && (!grabber || !grabber->keepMouseGrab())) { mouseEvent.setAccepted(false); for (int i = 0x1; i <= 0x10; i <<= 1) { if (event->buttons() & i) { @@ -1179,25 +1216,28 @@ bool QDeclarativePathView::sendMouseEvent(QGraphicsSceneMouseEvent *event) switch(mouseEvent.type()) { case QEvent::GraphicsSceneMouseMove: - mouseMoveEvent(&mouseEvent); + d->handleMouseMoveEvent(&mouseEvent); break; case QEvent::GraphicsSceneMousePress: - mousePressEvent(&mouseEvent); + d->handleMousePressEvent(&mouseEvent); + stealThisEvent = d->stealMouse; // Update stealThisEvent in case changed by function call above break; case QEvent::GraphicsSceneMouseRelease: - mouseReleaseEvent(&mouseEvent); + d->handleMouseReleaseEvent(&mouseEvent); break; default: break; } grabber = qobject_cast<QDeclarativeItem*>(s->mouseGrabberItem()); - if (grabber && d->stealMouse && !grabber->keepMouseGrab() && grabber != this) + if (grabber && stealThisEvent && !grabber->keepMouseGrab() && grabber != this) grabMouse(); return d->stealMouse; } else if (d->lastPosTime.isValid()) { d->lastPosTime.invalidate(); } + if (mouseEvent.type() == QEvent::GraphicsSceneMouseRelease) + d->stealMouse = false; return false; } @@ -1211,12 +1251,7 @@ bool QDeclarativePathView::sceneEventFilter(QGraphicsItem *i, QEvent *e) case QEvent::GraphicsSceneMousePress: case QEvent::GraphicsSceneMouseMove: case QEvent::GraphicsSceneMouseRelease: - { - bool ret = sendMouseEvent(static_cast<QGraphicsSceneMouseEvent *>(e)); - if (e->type() == QEvent::GraphicsSceneMouseRelease) - return ret; - break; - } + return sendMouseEvent(static_cast<QGraphicsSceneMouseEvent *>(e)); default: break; } diff --git a/src/declarative/graphicsitems/qdeclarativepathview_p_p.h b/src/declarative/graphicsitems/qdeclarativepathview_p_p.h index dfebe35..b217216 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativepathview_p_p.h @@ -123,6 +123,10 @@ public: return model && model->count() > 0 && model->isValid() && path; } + void handleMousePressEvent(QGraphicsSceneMouseEvent *event); + void handleMouseMoveEvent(QGraphicsSceneMouseEvent *event); + void handleMouseReleaseEvent(QGraphicsSceneMouseEvent *); + int calcCurrentIndex(); void updateCurrent(); static void fixOffsetCallback(void*); diff --git a/src/declarative/graphicsitems/qdeclarativerectangle.cpp b/src/declarative/graphicsitems/qdeclarativerectangle.cpp index d027924..9831d5f 100644 --- a/src/declarative/graphicsitems/qdeclarativerectangle.cpp +++ b/src/declarative/graphicsitems/qdeclarativerectangle.cpp @@ -85,8 +85,8 @@ void QDeclarativePen::setWidth(int w) /*! \qmlclass GradientStop QDeclarativeGradientStop \ingroup qml-basic-visual-elements - \since 4.7 - \brief The GradientStop item defines the color at a position in a Gradient + \since 4.7 + \brief The GradientStop item defines the color at a position in a Gradient. \sa Gradient */ @@ -95,7 +95,12 @@ void QDeclarativePen::setWidth(int w) \qmlproperty real GradientStop::position \qmlproperty color GradientStop::color - Sets a \e color at a \e position in a gradient. + The position and color properties describe the color used at a given + position in a gradient, as represented by a gradient stop. + + The default position is 0.0; the default color is black. + + \sa Gradient */ void QDeclarativeGradientStop::updateGradient() @@ -107,20 +112,50 @@ void QDeclarativeGradientStop::updateGradient() /*! \qmlclass Gradient QDeclarativeGradient \ingroup qml-basic-visual-elements - \since 4.7 + \since 4.7 \brief The Gradient item defines a gradient fill. - A gradient is defined by two or more colors, which will be blended seemlessly. The - colors are specified at their position in the range 0.0 - 1.0 via - the GradientStop item. For example, the following code paints a - rectangle with a gradient starting with red, blending to yellow at 1/3 of the - size of the rectangle, and ending with Green: + A gradient is defined by two or more colors, which will be blended seamlessly. - \snippet doc/src/snippets/declarative/gradient.qml code + The colors are specified as a set of GradientStop child items, each of + which defines a position on the gradient from 0.0 to 1.0 and a color. + The position of each GradientStop is defined by setting its + \l{GradientStop::}{position} property; its color is defined using its + \l{GradientStop::}{color} property. + + A gradient without any gradient stops is rendered as a solid white fill. Note that this item is not a visual representation of a gradient. To display a - gradient use a visual item (like rectangle) which supports having a gradient set - on it for display. + gradient, use a visual element (like \l Rectangle) which supports the use + of gradients. + + \section1 Example Usage + + \beginfloatright + \inlineimage qml-gradient.png + \endfloat + + The following example declares a \l Rectangle item with a gradient starting + with red, blending to yellow at one third of the height of the rectangle, + and ending with green: + + \snippet doc/src/snippets/declarative/gradient.qml code + + \clearfloat + \section1 Performance and Limitations + + Calculating gradients can be computationally expensive compared to the use + of solid color fills or images. Consider using gradients for static items + in a user interface. + + In Qt 4.7, only vertical, linear gradients can be applied to items. If you + need to apply different orientations of gradients, a combination of rotation + and clipping will need to be applied to the relevant items. This can + introduce additional performance requirements for your application. + + The use of animations involving gradient stops may not give the desired + result. An alternative way to animate gradients is to use pre-generated + images or SVG drawings containing gradients. \sa GradientStop */ @@ -128,6 +163,10 @@ void QDeclarativeGradientStop::updateGradient() /*! \qmlproperty list<GradientStop> Gradient::stops This property holds the gradient stops describing the gradient. + + By default, this property contains an empty list. + + To set the gradient stops, define them as children of the Gradient element. */ const QGradient *QDeclarativeGradient::gradient() const @@ -155,27 +194,46 @@ void QDeclarativeGradient::doUpdate() /*! \qmlclass Rectangle QDeclarativeRectangle \ingroup qml-basic-visual-elements - \since 4.7 - \brief The Rectangle item allows you to add rectangles to a scene. + \since 4.7 + \brief The Rectangle item provides a filled rectangle with an optional border. \inherits Item - A Rectangle is painted using a solid fill (color) and an optional border. - You can also create rounded rectangles using the \l radius property. + Rectangle items are used to fill areas with solid color or gradients, and are + often used to hold other items. - \qml - import Qt 4.7 - - Rectangle { - width: 100 - height: 100 - color: "red" - border.color: "black" - border.width: 5 - radius: 10 - } - \endqml + \section1 Appearance + + Each Rectangle item is painted using either a solid fill color, specified using + the \l color property, or a gradient, defined using a Gradient element and set + using the \l gradient property. If both a color and a gradient are specified, + the gradient is used. + + You can add an optional border to a rectangle with its own color and thickness + by settting the \l border.color and \l border.width properties. + + You can also create rounded rectangles using the \l radius property. Since this + introduces curved edges to the corners of a rectangle, it may be appropriate to + set the \l smooth property to improve its appearance. - \image declarative-rect.png + \section1 Example Usage + + \beginfloatright + \inlineimage declarative-rect.png + \endfloat + + The following example shows the effects of some of the common properties on a + Rectangle item, which in this case is used to create a square: + + \snippet doc/src/snippets/declarative/rectangle/rectangle.qml document + + \clearfloat + \section1 Performance + + Using the \l smooth property improves the appearance of a rounded rectangle at + the cost of rendering performance. You should consider unsetting this property + for rectangles in motion, and only set it when they are stationary. + + \sa Image */ int QDeclarativeRectanglePrivate::doUpdateSlotIdx = -1; @@ -207,13 +265,14 @@ void QDeclarativeRectangle::doUpdate() rectangle's boundaries, and the spare pixel is rendered to the right and below the rectangle (as documented for QRect rendering). This can cause unintended effects if \c border.width is 1 and the rectangle is \l{Item::clip}{clipped} by a parent item: - - \table - \row - \o \snippet doc/src/snippets/declarative/rect-border-width.qml 0 - \o \image rect-border-width.png - \endtable + \beginfloatright + \inlineimage rect-border-width.png + \endfloat + + \snippet doc/src/snippets/declarative/rectangle/rect-border-width.qml 0 + + \clearfloat Here, the innermost rectangle's border is clipped on the bottom and right edges by its parent. To avoid this, the border width can be set to two instead of one. */ @@ -231,34 +290,12 @@ QDeclarativePen *QDeclarativeRectangle::border() This property allows for the construction of simple vertical gradients. Other gradients may by formed by adding rotation to the rectangle. - \table - \row - \o \image declarative-rect_gradient.png - \o - \qml - Rectangle { - y: 0; width: 80; height: 80 - color: "lightsteelblue" - } - - Rectangle { - y: 100; width: 80; height: 80 - gradient: Gradient { - GradientStop { position: 0.0; color: "lightsteelblue" } - GradientStop { position: 1.0; color: "blue" } - } - } + \beginfloatleft + \inlineimage declarative-rect_gradient.png + \endfloat - Rectangle { - y: 200; width: 80; height: 80 - rotation: 90 - gradient: Gradient { - GradientStop { position: 0.0; color: "lightsteelblue" } - GradientStop { position: 1.0; color: "blue" } - } - } - \endqml - \endtable + \snippet doc/src/snippets/declarative/rectangle/rectangle-gradient.qml rectangles + \clearfloat If both a gradient and a color are specified, the gradient will be used. @@ -319,17 +356,21 @@ void QDeclarativeRectangle::setRadius(qreal radius) \qmlproperty color Rectangle::color This property holds the color used to fill the rectangle. - \qml - // green rectangle using hexidecimal notation - Rectangle { color: "#00FF00" } + The default color is white. - // steelblue rectangle using SVG color name - Rectangle { color: "steelblue" } - \endqml + \beginfloatright + \inlineimage rect-color.png + \endfloat - The default color is white. + The following example shows rectangles with colors specified + using hexadecimal and named color notation: + \snippet doc/src/snippets/declarative/rectangle/rectangle-colors.qml rectangles + + \clearfloat If both a gradient and a color are specified, the gradient will be used. + + \sa gradient */ QColor QDeclarativeRectangle::color() const { diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index 14194a0..1f4c1c7 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -1206,6 +1206,16 @@ void QDeclarativeText::mousePressEvent(QGraphicsSceneMouseEvent *event) \qmlsignal Text::onLinkActivated(string link) This handler is called when the user clicks on a link embedded in the text. + The link must be in rich text or HTML format and the + \a link string provides access to the particular link. + + \snippet doc/src/snippets/declarative/text/onLinkActivated.qml 0 + + The example code will display the text + "The main website is at \l{http://qt.nokia.com}{Nokia Qt DF}." + + Clicking on the highlighted link will output + \tt{http://qt.nokia.com link activated} to the console. */ /*! diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index a46ee73..a70886e 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -287,16 +287,12 @@ public: m_roles = m_listModelInterface->roles(); for (int ii = 0; ii < m_roles.count(); ++ii) m_roleNames.insert(m_listModelInterface->toString(m_roles.at(ii)).toUtf8(), m_roles.at(ii)); - if (m_roles.count() == 1) - m_roleNames.insert("modelData", m_roles.at(0)); } else if (m_abstractItemModel) { for (QHash<int,QByteArray>::const_iterator it = m_abstractItemModel->roleNames().begin(); it != m_abstractItemModel->roleNames().end(); ++it) { m_roles.append(it.key()); m_roleNames.insert(*it, it.key()); } - if (m_roles.count() == 1) - m_roleNames.insert("modelData", m_roles.at(0)); if (m_roles.count()) m_roleNames.insert("hasModelChildren", -1); } else if (m_listAccessor) { @@ -314,7 +310,8 @@ public: } } - QHash<int,int> roleToPropId; + QHash<int,int> m_roleToPropId; + int m_modelDataPropId; void createMetaData() { if (!m_metaDataCreated) { ensureRoles(); @@ -322,9 +319,12 @@ public: QHash<QByteArray, int>::const_iterator it = m_roleNames.begin(); while (it != m_roleNames.end()) { int propId = m_delegateDataType->createProperty(it.key()) - m_delegateDataType->propertyOffset(); - roleToPropId.insert(*it, propId); + m_roleToPropId.insert(*it, propId); ++it; } + // Add modelData property + if (m_roles.count() == 1) + m_modelDataPropId = m_delegateDataType->createProperty("modelData") - m_delegateDataType->propertyOffset(); m_metaDataCreated = true; } } @@ -430,6 +430,11 @@ public: void setIndex(int index); int propForRole(int) const; + int modelDataPropertyId() const { + QDeclarativeVisualDataModelPrivate *model = QDeclarativeVisualDataModelPrivate::get(m_model); + return model->m_modelDataPropId; + } + void setValue(int, const QVariant &); bool hasValue(int id) const { return m_meta->hasValue(id); @@ -450,8 +455,8 @@ private: int QDeclarativeVisualDataModelData::propForRole(int id) const { QDeclarativeVisualDataModelPrivate *model = QDeclarativeVisualDataModelPrivate::get(m_model); - QHash<int,int>::const_iterator it = model->roleToPropId.find(id); - if (it != model->roleToPropId.end()) + QHash<int,int>::const_iterator it = model->m_roleToPropId.find(id); + if (it != model->m_roleToPropId.end()) return *it; return -1; @@ -518,14 +523,16 @@ QVariant QDeclarativeVisualDataModelDataMetaObject::initialValue(int propId) } } else if (model->m_abstractItemModel) { model->ensureRoles(); + QModelIndex index = model->m_abstractItemModel->index(data->m_index, 0, model->m_root); if (propName == "hasModelChildren") { - QModelIndex index = model->m_abstractItemModel->index(data->m_index, 0, model->m_root); return model->m_abstractItemModel->hasChildren(index); } else { QHash<QByteArray,int>::const_iterator it = model->m_roleNames.find(propName); if (it != model->m_roleNames.end()) { - QModelIndex index = model->m_abstractItemModel->index(data->m_index, 0, model->m_root); return model->m_abstractItemModel->data(index, *it); + } else if (model->m_roles.count() == 1 && propName == "modelData") { + //for compatibility with other lists, assign modelData if there is only a single role + return model->m_abstractItemModel->data(index, model->m_roles.first()); } } } @@ -1195,6 +1202,19 @@ void QDeclarativeVisualDataModel::_q_itemsChanged(int index, int count, qmlInfo(this) << "Changing role not present in item: " << roleName; } } + if (roles.count() == 1) { + // Handle the modelData role we add if there is just one role. + int propId = data->modelDataPropertyId(); + if (data->hasValue(propId)) { + int role = roles.at(0); + if (d->m_listModelInterface) { + data->setValue(propId, d->m_listModelInterface->data(idx, QList<int>() << role).value(role)); + } else if (d->m_abstractItemModel) { + QModelIndex index = d->m_abstractItemModel->index(idx, 0, d->m_root); + data->setValue(propId, d->m_abstractItemModel->data(index, role)); + } + } + } } } } |