diff options
author | Denis Dzyubenko <[email protected]> | 2010-10-08 11:15:34 +0200 |
---|---|---|
committer | Denis Dzyubenko <[email protected]> | 2010-10-08 14:16:42 +0200 |
commit | 73bb48285fb2ca8382b1f974ef2425ac730db359 (patch) | |
tree | 7c0ade326aceb283d2974c096f6837b92b845822 | |
parent | 5cf60ff381cd75678705882244a6733139de8723 (diff) |
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
-rw-r--r-- | qdeclarativegesturearea.cpp | 41 |
1 files 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<Qt::GestureType, QObject *> Handlers; - Handlers handlers; + QList<QObject *> handlers; QObject *defaultHandler; static void handlers_append(QDeclarativeListProperty<QObject> *prop, QObject *handler) { QDeclarativeGestureAreaPrivate *d = static_cast<QDeclarativeGestureAreaPrivate *>(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<QObject> *prop, int index) { QDeclarativeGestureAreaPrivate *d = static_cast<QDeclarativeGestureAreaPrivate *>(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<Qt::GestureType> handlersTypes; + foreach(QObject *handler, handlers) { + Qt::GestureType type(Qt::GestureType(handler->property("gestureType").toInt())); + handlersTypes.append(type); + event->ignore(type); + } + QSet<Qt::GestureType> 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 |