From fb6cf75abfae111ab2a1c968ffd0c9b707109b10 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 3 Feb 2010 15:51:55 +1000 Subject: Compile. --- src/declarative/graphicsitems/qmlgraphicsflickable.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsflickable.cpp b/src/declarative/graphicsitems/qmlgraphicsflickable.cpp index df8c275..c4edb28 100644 --- a/src/declarative/graphicsitems/qmlgraphicsflickable.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsflickable.cpp @@ -826,17 +826,17 @@ void QmlGraphicsFlickable::wheelEvent(QGraphicsSceneWheelEvent *event) QmlGraphicsItem::wheelEvent(event); } else if (yflick()) { if (event->delta() > 0) - d->velocityY = qMax(event->delta() - d->verticalVelocity.value(), 250.0); + d->velocityY = qMax(event->delta() - d->verticalVelocity.value(), qreal(250.0)); else - d->velocityY = qMin(event->delta() - d->verticalVelocity.value(), -250.0); + d->velocityY = qMin(event->delta() - d->verticalVelocity.value(), qreal(-250.0)); d->flicked = false; d->flickY(d->velocityY); event->accept(); } else if (xflick()) { if (event->delta() > 0) - d->velocityX = qMax(event->delta() - d->horizontalVelocity.value(), 250.0); + d->velocityX = qMax(event->delta() - d->horizontalVelocity.value(), qreal(250.0)); else - d->velocityX = qMin(event->delta() - d->horizontalVelocity.value(), -250.0); + d->velocityX = qMin(event->delta() - d->horizontalVelocity.value(), qreal(-250.0)); d->flicked = false; d->flickX(d->velocityX); event->accept(); -- cgit v0.12 From 4c288190000ea6c9f7148d44e8e12d882256e217 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 3 Feb 2010 15:52:28 +1000 Subject: Avoid crash on shutdown if model is destroyed before view. --- src/declarative/graphicsitems/qmlgraphicsgridview.cpp | 10 +++++++--- src/declarative/graphicsitems/qmlgraphicslistview.cpp | 6 +++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp index 890d3ad..7105300 100644 --- a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp @@ -151,7 +151,7 @@ class QmlGraphicsGridViewPrivate : public QmlGraphicsFlickablePrivate public: QmlGraphicsGridViewPrivate() - : model(0), currentItem(0), flow(QmlGraphicsGridView::LeftToRight) + : currentItem(0), flow(QmlGraphicsGridView::LeftToRight) , visiblePos(0), visibleIndex(0) , currentIndex(-1) , cellWidth(100), cellHeight(100), columns(1), requestedIndex(-1) , highlightComponent(0), highlight(0), trackedItem(0) @@ -307,7 +307,7 @@ public: } } - QmlGraphicsVisualModel *model; + QGuard model; QVariant modelVariant; QList visibleItems; QHash unrequestedItems; @@ -350,6 +350,7 @@ void QmlGraphicsGridViewPrivate::init() void QmlGraphicsGridViewPrivate::clear() { + qDebug() << "clearing items" << visibleItems.count(); for (int i = 0; i < visibleItems.count(); ++i) releaseItem(visibleItems.at(i)); visibleItems.clear(); @@ -384,13 +385,16 @@ FxGridItem *QmlGraphicsGridViewPrivate::createItem(int modelIndex) void QmlGraphicsGridViewPrivate::releaseItem(FxGridItem *item) { Q_Q(QmlGraphicsGridView); - if (!item) + if (!item || !model) return; if (trackedItem == item) { QObject::disconnect(trackedItem->item, SIGNAL(yChanged()), q, SLOT(trackedPositionChanged())); QObject::disconnect(trackedItem->item, SIGNAL(xChanged()), q, SLOT(trackedPositionChanged())); trackedItem = 0; } + qDebug() << "release" << item; + qDebug() << " item" << item->item; + qDebug() << " model" << model; if (model->release(item->item) == 0) { // item was not destroyed, and we no longer reference it. unrequestedItems.insert(item->item, model->indexOf(item->item, q)); diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp index ad0aa04..8fb7c84 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp @@ -210,7 +210,7 @@ class QmlGraphicsListViewPrivate : public QmlGraphicsFlickablePrivate, private Q public: QmlGraphicsListViewPrivate() - : model(0), currentItem(0), orient(QmlGraphicsListView::Vertical) + : currentItem(0), orient(QmlGraphicsListView::Vertical) , visiblePos(0), visibleIndex(0) , averageSize(100.0), currentIndex(-1), requestedIndex(-1) , highlightRangeStart(0), highlightRangeEnd(0) @@ -495,7 +495,7 @@ public: virtual void flickX(qreal velocity); virtual void flickY(qreal velocity); - QmlGraphicsVisualModel *model; + QGuard model; QVariant modelVariant; QList visibleItems; QHash unrequestedItems; @@ -615,7 +615,7 @@ FxListItem *QmlGraphicsListViewPrivate::createItem(int modelIndex) void QmlGraphicsListViewPrivate::releaseItem(FxListItem *item) { Q_Q(QmlGraphicsListView); - if (!item) + if (!item || !model) return; if (trackedItem == item) { const char *notifier1 = orient == QmlGraphicsListView::Vertical ? SIGNAL(yChanged()) : SIGNAL(xChanged()); -- cgit v0.12 From 59865a84484c29bd21bda62e3c55c8d2eb957f28 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 3 Feb 2010 15:53:18 +1000 Subject: Add a PathView.onPath property to help deal with unrequested items. --- .../graphicsitems/qmlgraphicspathview.cpp | 63 +++++++++++++++++++++- .../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(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(obj)->setOnPath(false); + if (model->release(item) == 0) { + if (QObject *obj = QmlGraphicsPathView::qmlAttachedProperties(item)) + static_cast(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(&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 items; - QmlGraphicsVisualModel *model; + QGuard model; QVariant modelVariant; enum MovementReason { Other, Key, Mouse }; MovementReason moveReason; -- cgit v0.12