Move QGestureEventPrivate's content to the main class

QEvent now checks that the d pointer is unused.

Change-Id: Ib0aa97d1692ea55324c4c6f133ffdd5a221f1680
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
Thiago Macieira 2012-04-19 21:16:47 +02:00 committed by Qt by Nokia
parent d631c31235
commit f02e1d6d8e
5 changed files with 20 additions and 49 deletions

View File

@ -3523,7 +3523,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
ge.t = gestureEvent->t;
ge.spont = gestureEvent->spont;
ge.m_accept = wasAccepted;
ge.d_func()->accepted = gestureEvent->d_func()->accepted;
ge.m_accepted = gestureEvent->m_accepted;
res = d->notify_helper(w, &ge);
gestureEvent->spont = false;
eventAccepted = ge.isAccepted();
@ -3533,7 +3533,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
// packed into a single QEvent depends on not consuming the event
if (eventAccepted || ge.isAccepted(g)) {
// if the gesture was accepted, mark the target widget for it
gestureEvent->d_func()->targetWidgets[g->gestureType()] = w;
gestureEvent->m_targetWidgets[g->gestureType()] = w;
gestureEvent->setAccepted(g, true);
} else {
// if the gesture was explicitly ignored by the application,

View File

@ -846,9 +846,9 @@ int QTapAndHoldGesturePrivate::Timeout = 700; // in ms
Creates new QGestureEvent containing a list of \a gestures.
*/
QGestureEvent::QGestureEvent(const QList<QGesture *> &gestures)
: QEvent(QEvent::Gesture)
: QEvent(QEvent::Gesture), m_gestures(gestures), m_widget(0)
{
d = reinterpret_cast<QEventPrivate *>(new QGestureEventPrivate(gestures));
}
/*!
@ -856,7 +856,6 @@ QGestureEvent::QGestureEvent(const QList<QGesture *> &gestures)
*/
QGestureEvent::~QGestureEvent()
{
delete reinterpret_cast<QGestureEventPrivate *>(d);
}
/*!
@ -864,7 +863,7 @@ QGestureEvent::~QGestureEvent()
*/
QList<QGesture *> QGestureEvent::gestures() const
{
return d_func()->gestures;
return m_gestures;
}
/*!
@ -872,10 +871,9 @@ QList<QGesture *> QGestureEvent::gestures() const
*/
QGesture *QGestureEvent::gesture(Qt::GestureType type) const
{
const QGestureEventPrivate *d = d_func();
for(int i = 0; i < d->gestures.size(); ++i)
if (d->gestures.at(i)->gestureType() == type)
return d->gestures.at(i);
for (int i = 0; i < m_gestures.size(); ++i)
if (m_gestures.at(i)->gestureType() == type)
return m_gestures.at(i);
return 0;
}
@ -885,7 +883,7 @@ QGesture *QGestureEvent::gesture(Qt::GestureType type) const
QList<QGesture *> QGestureEvent::activeGestures() const
{
QList<QGesture *> gestures;
foreach (QGesture *gesture, d_func()->gestures) {
foreach (QGesture *gesture, m_gestures) {
if (gesture->state() != Qt::GestureCanceled)
gestures.append(gesture);
}
@ -898,7 +896,7 @@ QList<QGesture *> QGestureEvent::activeGestures() const
QList<QGesture *> QGestureEvent::canceledGestures() const
{
QList<QGesture *> gestures;
foreach (QGesture *gesture, d_func()->gestures) {
foreach (QGesture *gesture, m_gestures) {
if (gesture->state() == Qt::GestureCanceled)
gestures.append(gesture);
}
@ -980,7 +978,7 @@ bool QGestureEvent::isAccepted(QGesture *gesture) const
void QGestureEvent::setAccepted(Qt::GestureType gestureType, bool value)
{
setAccepted(false);
d_func()->accepted[gestureType] = value;
m_accepted[gestureType] = value;
}
/*!
@ -1017,7 +1015,7 @@ void QGestureEvent::ignore(Qt::GestureType gestureType)
*/
bool QGestureEvent::isAccepted(Qt::GestureType gestureType) const
{
return d_func()->accepted.value(gestureType, true);
return m_accepted.value(gestureType, true);
}
/*!
@ -1027,7 +1025,7 @@ bool QGestureEvent::isAccepted(Qt::GestureType gestureType) const
*/
void QGestureEvent::setWidget(QWidget *widget)
{
d_func()->widget = widget;
m_widget = widget;
}
/*!
@ -1035,7 +1033,7 @@ void QGestureEvent::setWidget(QWidget *widget)
*/
QWidget *QGestureEvent::widget() const
{
return d_func()->widget;
return m_widget;
}
#ifndef QT_NO_GRAPHICSVIEW
@ -1062,22 +1060,6 @@ QPointF QGestureEvent::mapToGraphicsScene(const QPointF &gesturePoint) const
}
#endif //QT_NO_GRAPHICSVIEW
/*!
\internal
*/
QGestureEventPrivate *QGestureEvent::d_func()
{
return reinterpret_cast<QGestureEventPrivate *>(d);
}
/*!
\internal
*/
const QGestureEventPrivate *QGestureEvent::d_func() const
{
return reinterpret_cast<const QGestureEventPrivate *>(d);
}
#ifdef Q_NO_USING_KEYWORD
/*!
\fn void QGestureEvent::setAccepted(bool accepted)

View File

@ -310,8 +310,10 @@ public:
#endif
private:
QGestureEventPrivate *d_func();
const QGestureEventPrivate *d_func() const;
QList<QGesture *> m_gestures;
QWidget *m_widget;
QMap<Qt::GestureType, bool> m_accepted;
QMap<Qt::GestureType, QWidget *> m_targetWidgets;
friend class QApplication;
friend class QGestureManager;

View File

@ -222,19 +222,6 @@ public:
#endif
};
class QGestureEventPrivate
{
public:
inline QGestureEventPrivate(const QList<QGesture *> &list)
: gestures(list), widget(0)
{
}
QList<QGesture *> gestures;
QWidget *widget;
QMap<Qt::GestureType, bool> accepted;
QMap<Qt::GestureType, QWidget *> targetWidgets;
};
#endif // QT_NO_GESTURES

View File

@ -660,7 +660,7 @@ void QGestureManager::deliverEvents(const QSet<QGesture *> &gestures,
bool eventAccepted = event.isAccepted();
foreach(QGesture *gesture, event.gestures()) {
if (eventAccepted || event.isAccepted(gesture)) {
QWidget *w = event.d_func()->targetWidgets.value(gesture->gestureType(), 0);
QWidget *w = event.m_targetWidgets.value(gesture->gestureType(), 0);
Q_ASSERT(w);
DEBUG() << "override event: gesture was accepted:" << gesture << w;
QList<QGesture *> &gestures = normalStartedGestures[w];
@ -687,7 +687,7 @@ void QGestureManager::deliverEvents(const QSet<QGesture *> &gestures,
foreach (QGesture *gesture, event.gestures()) {
if (gesture->state() == Qt::GestureStarted &&
(eventAccepted || event.isAccepted(gesture))) {
QWidget *w = event.d_func()->targetWidgets.value(gesture->gestureType(), 0);
QWidget *w = event.m_targetWidgets.value(gesture->gestureType(), 0);
Q_ASSERT(w);
DEBUG() << "started gesture was delivered and accepted by" << w;
m_gestureTargets[gesture] = w;