From 73bb48285fb2ca8382b1f974ef2425ac730db359 Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Fri, 8 Oct 2010 11:15:34 +0200 Subject: Fixed handlers list property in QDeclarativeGestureArea It is supposed to be a list, but internally we were storing it in a map, which breaks if declarative engine tries to append an item and then expects to read it by taking the last item from the list. Also removed the setParent call, apparently declarative does that for us. Reviewed-by: Zeno Albisser --- qdeclarativegesturearea.cpp | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/qdeclarativegesturearea.cpp b/qdeclarativegesturearea.cpp index 298b0e7..29c7b1f 100644 --- a/qdeclarativegesturearea.cpp +++ b/qdeclarativegesturearea.cpp @@ -69,14 +69,12 @@ public: QDeclarativeGestureArea *q_ptr; - typedef QMap Handlers; - Handlers handlers; + QList handlers; QObject *defaultHandler; static void handlers_append(QDeclarativeListProperty *prop, QObject *handler) { QDeclarativeGestureAreaPrivate *d = static_cast(prop->data); QDeclarativeGestureArea *q = d->q_ptr; - handler->setParent(q); int type = handler->property("gestureType").toInt(); // check that all needed properties exist if (!handler->property("gestureType").isValid() || !handler->property("gesture").isValid() @@ -88,11 +86,15 @@ public: return; } Qt::GestureType gestureType = Qt::GestureType(type); - if (d->handlers.contains(gestureType)) { - qmlInfo(handler) << "Duplicate gesture found, ignoring."; - return; + // see if there is already a handler for that gesture type + foreach(QObject *handler, d->handlers) { + Qt::GestureType type(Qt::GestureType(handler->property("gestureType").toInt())); + if (type == gestureType) { + qmlInfo(handler) << "Duplicate gesture found, ignoring."; + return; + } } - d->handlers.insert(gestureType, handler); + d->handlers.append(handler); if (GestureAreaQmlPlugin::self) GestureAreaQmlPlugin::self->allGestures << gestureType; if (type == 0 && GestureAreaQmlPlugin::self) { @@ -118,7 +120,7 @@ public: } static QObject *handlers_at(QDeclarativeListProperty *prop, int index) { QDeclarativeGestureAreaPrivate *d = static_cast(prop->data); - return d->handlers.value(d->handlers.keys().at(index)); + return d->handlers.at(index); } void evaluate(QGestureEvent *event, QGesture *gesture, QObject *handler); @@ -259,26 +261,29 @@ void QDeclarativeGestureAreaPrivate::evaluate(QGestureEvent *event, QGesture *ge bool QDeclarativeGestureAreaPrivate::gestureEvent(QGestureEvent *event) { - event->accept(); - foreach(Qt::GestureType type, handlers.keys()) - event->ignore(type); - if (handlers.isEmpty()) return false; + event->accept(); + + QList handlersTypes; + foreach(QObject *handler, handlers) { + Qt::GestureType type(Qt::GestureType(handler->property("gestureType").toInt())); + handlersTypes.append(type); + event->ignore(type); + } + QSet handledGestures; - Handlers::Iterator it = handlers.end(); - do { - --it; - Qt::GestureType gestureType = it.key(); + for (int i = handlers.size()-1; i >= 0; --i) { + Qt::GestureType gestureType = handlersTypes.at(i); if (!gestureType) continue; if (QGesture *gesture = event->gesture(gestureType)) { handledGestures << gestureType; - QObject *handler = it.value(); + QObject *handler = handlers.at(i); evaluate(event, gesture, handler); } - } while (it != handlers.begin()); + } if (defaultHandler) { // filter all gestures through the default handler -- cgit v1.2.3