Revert "Fix global coordinate mapping for child widgets in QGraphicsView."

This reverts commit 56aad2ad60.

QWidget::mapFromGlobal() does not work correctly when the widget is
a child widget of another widget embedded into a QGraphicsView with a
transformation (scaling/rotation). It starts applying offsets going
up the widget tree (just as mapToGlobal) until it hits the embedded widget
not taking into account the transformation.

It would need to go in from to top to bottom or better be reimplemented
such that a QTransform for mapping coordinates from/to global is determined
which is then applied in reverse.

Task-number: QTBUG-50030
Task-number: QTBUG-50136
Change-Id: Iadeb891d793be1938c64942bfbf38d541a281c33
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
bb10
Friedemann Kleint 2015-12-22 17:15:57 +01:00
parent 4829edfa4e
commit 38c8af7231
2 changed files with 29 additions and 25 deletions

View File

@ -12305,21 +12305,20 @@ QPaintEngine *QWidget::paintEngine() const
*/
QPoint QWidget::mapToGlobal(const QPoint &pos) const
{
#ifndef QT_NO_GRAPHICSVIEW
Q_D(const QWidget);
if (d->extra && d->extra->proxyWidget && d->extra->proxyWidget->scene()) {
const QList <QGraphicsView *> views = d->extra->proxyWidget->scene()->views();
if (!views.isEmpty()) {
const QPointF scenePos = d->extra->proxyWidget->mapToScene(pos);
const QPoint viewPortPos = views.first()->mapFromScene(scenePos);
return views.first()->viewport()->mapToGlobal(viewPortPos);
}
}
#endif // !QT_NO_GRAPHICSVIEW
int x = pos.x(), y = pos.y();
const QWidget *w = this;
while (w) {
#ifndef QT_NO_GRAPHICSVIEW
const QWidgetPrivate *d = w->d_func();
if (d->extra && d->extra->proxyWidget && d->extra->proxyWidget->scene()) {
const QList <QGraphicsView *> views = d->extra->proxyWidget->scene()->views();
if (!views.isEmpty()) {
const QPointF scenePos = d->extra->proxyWidget->mapToScene(QPoint(x, y));
const QPoint viewPortPos = views.first()->mapFromScene(scenePos);
return views.first()->viewport()->mapToGlobal(viewPortPos);
}
}
#endif // !QT_NO_GRAPHICSVIEW
QWindow *window = w->windowHandle();
if (window && window->handle())
return window->mapToGlobal(QPoint(x, y));
@ -12341,21 +12340,20 @@ QPoint QWidget::mapToGlobal(const QPoint &pos) const
*/
QPoint QWidget::mapFromGlobal(const QPoint &pos) const
{
#ifndef QT_NO_GRAPHICSVIEW
Q_D(const QWidget);
if (d->extra && d->extra->proxyWidget && d->extra->proxyWidget->scene()) {
const QList <QGraphicsView *> views = d->extra->proxyWidget->scene()->views();
if (!views.isEmpty()) {
const QPoint viewPortPos = views.first()->viewport()->mapFromGlobal(pos);
const QPointF scenePos = views.first()->mapToScene(viewPortPos);
return d->extra->proxyWidget->mapFromScene(scenePos).toPoint();
}
}
#endif // !QT_NO_GRAPHICSVIEW
int x = pos.x(), y = pos.y();
const QWidget *w = this;
while (w) {
#ifndef QT_NO_GRAPHICSVIEW
const QWidgetPrivate *d = w->d_func();
if (d->extra && d->extra->proxyWidget && d->extra->proxyWidget->scene()) {
const QList <QGraphicsView *> views = d->extra->proxyWidget->scene()->views();
if (!views.isEmpty()) {
const QPoint viewPortPos = views.first()->viewport()->mapFromGlobal(QPoint(x, y));
const QPointF scenePos = views.first()->mapToScene(viewPortPos);
return d->extra->proxyWidget->mapFromScene(scenePos).toPoint();
}
}
#endif // !QT_NO_GRAPHICSVIEW
QWindow *window = w->windowHandle();
if (window && window->handle())
return window->mapFromGlobal(QPoint(x, y));

View File

@ -3684,6 +3684,7 @@ void tst_QGraphicsProxyWidget::mapToGlobal() // QTBUG-41135
const QSize size = availableGeometry.size() / 5;
QGraphicsScene scene;
QGraphicsView view(&scene);
view.setTransform(QTransform::fromScale(2, 2)); // QTBUG-50136, use transform.
view.setWindowTitle(QTest::currentTestFunction());
view.resize(size);
view.move(availableGeometry.bottomRight() - QPoint(size.width(), size.height()) - QPoint(100, 100));
@ -3706,10 +3707,15 @@ void tst_QGraphicsProxyWidget::mapToGlobal() // QTBUG-41135
QVERIFY2((viewCenter - embeddedCenterGlobal).manhattanLength() <= 2,
msgPointMismatch(embeddedCenterGlobal, viewCenter).constData());
// Same test with child centered on embeddedWidget
// Same test with child centered on embeddedWidget. The correct
// mapping is not implemented yet, but at least make sure
// the roundtrip maptoGlobal()/mapFromGlobal() returns the same
// point since that is important for mouse event handling (QTBUG-50030,
// QTBUG-50136).
const QPoint childCenter = childWidget->rect().center();
const QPoint childCenterGlobal = childWidget->mapToGlobal(childCenter);
QCOMPARE(childWidget->mapFromGlobal(childCenterGlobal), childCenter);
QEXPECT_FAIL("", "Not implemented for child widgets of embedded widgets", Continue);
QVERIFY2((viewCenter - childCenterGlobal).manhattanLength() <= 4,
msgPointMismatch(childCenterGlobal, viewCenter).constData());
}