diff options
author | Martin Jones <martin.jones@nokia.com> | 2010-02-03 05:53:18 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2010-02-03 05:53:18 (GMT) |
commit | 59865a84484c29bd21bda62e3c55c8d2eb957f28 (patch) | |
tree | 68a4369b48f5a7bfee683d4d3efb6a6879bde4e0 /src | |
parent | 4c288190000ea6c9f7148d44e8e12d882256e217 (diff) | |
download | Qt-59865a84484c29bd21bda62e3c55c8d2eb957f28.zip Qt-59865a84484c29bd21bda62e3c55c8d2eb957f28.tar.gz Qt-59865a84484c29bd21bda62e3c55c8d2eb957f28.tar.bz2 |
Add a PathView.onPath property to help deal with unrequested items.
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/graphicsitems/qmlgraphicspathview.cpp | 63 | ||||
-rw-r--r-- | src/declarative/graphicsitems/qmlgraphicspathview_p_p.h | 18 |
2 files changed, 66 insertions, 15 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicspathview.cpp b/src/declarative/graphicsitems/qmlgraphicspathview.cpp index 112eda2..85e87eb 100644 --- a/src/declarative/graphicsitems/qmlgraphicspathview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicspathview.cpp @@ -71,9 +71,11 @@ inline qreal qmlMod(qreal x, qreal y) class QmlGraphicsPathViewAttached : public QObject { Q_OBJECT + + Q_PROPERTY(bool onPath READ isOnPath NOTIFY onPathChanged) public: QmlGraphicsPathViewAttached(QObject *parent) - : QObject(parent), mo(new QmlOpenMetaObject(this)) + : QObject(parent), mo(new QmlOpenMetaObject(this)), onPath(false) { } @@ -91,10 +93,49 @@ public: mo->setValue(name, val); } + bool isOnPath() const { return onPath; } + void setOnPath(bool on) { + if (on != onPath) { + onPath = on; + emit onPathChanged(); + } + } + +Q_SIGNALS: + void onPathChanged(); + private: QmlOpenMetaObject *mo; + bool onPath; }; + +QmlGraphicsItem *QmlGraphicsPathViewPrivate::getItem(int modelIndex) +{ + Q_Q(QmlGraphicsPathView); + requestedIndex = modelIndex; + QmlGraphicsItem *item = model->item(modelIndex); + if (item) { + if (QObject *obj = QmlGraphicsPathView::qmlAttachedProperties(item)) + static_cast<QmlGraphicsPathViewAttached *>(obj)->setOnPath(true); + item->setParentItem(q); + } + requestedIndex = -1; + return item; +} + +void QmlGraphicsPathViewPrivate::releaseItem(QmlGraphicsItem *item) +{ + if (!item || !model) + return; + if (QObject *obj = QmlGraphicsPathView::qmlAttachedProperties(item)) + static_cast<QmlGraphicsPathViewAttached *>(obj)->setOnPath(false); + if (model->release(item) == 0) { + if (QObject *obj = QmlGraphicsPathView::qmlAttachedProperties(item)) + static_cast<QmlGraphicsPathViewAttached *>(obj)->setOnPath(false); + } +} + /*! \qmlclass PathView QmlGraphicsPathView \brief The PathView element lays out model-provided items on a path. @@ -126,6 +167,26 @@ QmlGraphicsPathView::~QmlGraphicsPathView() } /*! + \qmlattachedproperty bool PathView::onPath + This attached property holds whether the item is currently on the path. + + If a pathItemCount has been set, it is possible that some items may + be instantiated, but not considered to be currently on the path. + Usually, these items would be set invisible, for example: + + \code + Component { + Rectangle { + visible: PathView.onPath + ... + } + } + \endcode + + It is attached to each instance of the delegate. +*/ + +/*! \qmlproperty model PathView::model This property holds the model providing data for the view. diff --git a/src/declarative/graphicsitems/qmlgraphicspathview_p_p.h b/src/declarative/graphicsitems/qmlgraphicspathview_p_p.h index 7ffe6ac..18cb205 100644 --- a/src/declarative/graphicsitems/qmlgraphicspathview_p_p.h +++ b/src/declarative/graphicsitems/qmlgraphicspathview_p_p.h @@ -79,7 +79,7 @@ public: : path(0), currentIndex(0), startPc(0), lastDist(0) , lastElapsed(0), stealMouse(false), ownModel(false), activeItem(0) , snapPos(0), dragMargin(0), moveOffset(this, &QmlGraphicsPathViewPrivate::setOffset) - , firstIndex(0), pathItems(-1), pathOffset(0), requestedIndex(-1), model(0) + , firstIndex(0), pathItems(-1), pathOffset(0), requestedIndex(-1) , moveReason(Other) { fixupOffsetEvent = QmlTimeLineEvent::timeLineEvent<QmlGraphicsPathViewPrivate, &QmlGraphicsPathViewPrivate::fixOffset>(&moveOffset, this); @@ -95,18 +95,8 @@ public: q->connect(&tl, SIGNAL(updated()), q, SLOT(ticked())); } - QmlGraphicsItem *getItem(int modelIndex) { - Q_Q(QmlGraphicsPathView); - requestedIndex = modelIndex; - QmlGraphicsItem *item = model->item(modelIndex); - if (item) - item->setParentItem(q); - requestedIndex = -1; - return item; - } - void releaseItem(QmlGraphicsItem *item) { - model->release(item); - } + QmlGraphicsItem *getItem(int modelIndex); + void releaseItem(QmlGraphicsItem *item); bool isValid() const { return model && model->count() > 0 && model->isValid() && path; @@ -143,7 +133,7 @@ public: int pathOffset; int requestedIndex; QList<QmlGraphicsItem *> items; - QmlGraphicsVisualModel *model; + QGuard<QmlGraphicsVisualModel> model; QVariant modelVariant; enum MovementReason { Other, Key, Mouse }; MovementReason moveReason; |