From 03baad51d584778a99f4b393232ccc1312db3391 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 29 Dec 2009 12:44:04 +0100 Subject: Fixes crash when widget with WA_StaticContents child become toplevel. Happens for example if a DockWidget is undocked and has a child whith the WA_StaticContents attribute. The parent does not change (so newParent is false) but still, the top level widget change. So staticWidget need to be moved to the new backingstore. Reviewed-by: Benjamin Poulain Task-number: QTBUG-6883 --- src/gui/kernel/qwidget.cpp | 11 +++++------ tests/auto/qwidget/tst_qwidget.cpp | 30 +++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index e551a1d..81f38ec 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -9774,13 +9774,12 @@ void QWidget::setParent(QWidget *parent, Qt::WindowFlags f) } #endif - if (newParent) { - if (QWidgetBackingStore *oldBs = oldtlw->d_func()->maybeBackingStore()) { + if (QWidgetBackingStore *oldBs = oldtlw->d_func()->maybeBackingStore()) { + if (newParent) oldBs->removeDirtyWidget(this); - // Move the widget and all its static children from - // the old backing store to the new one. - oldBs->moveStaticWidgets(this); - } + // Move the widget and all its static children from + // the old backing store to the new one. + oldBs->moveStaticWidgets(this); } if ((QApplicationPrivate::app_compile_version < 0x040200 diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp index 3e14b56..2d04cc5 100644 --- a/tests/auto/qwidget/tst_qwidget.cpp +++ b/tests/auto/qwidget/tst_qwidget.cpp @@ -66,6 +66,8 @@ #include #include #include +#include +#include #include #include @@ -356,6 +358,7 @@ private slots: void paintOnScreenPossible(); #endif void reparentStaticWidget(); + void QTBUG6883_reparentStaticWidget2(); #ifdef Q_WS_QWS void updateOutsideSurfaceClip(); #endif @@ -8728,6 +8731,31 @@ void tst_QWidget::reparentStaticWidget() // Please don't crash. paintOnScreen.resize(paintOnScreen.size() + QSize(2, 2)); QTest::qWait(20); + +} + +void tst_QWidget::QTBUG6883_reparentStaticWidget2() +{ + QMainWindow mw; + QDockWidget *one = new QDockWidget("one", &mw); + mw.addDockWidget(Qt::LeftDockWidgetArea, one , Qt::Vertical); + + QWidget *child = new QWidget(); + child->setPalette(Qt::red); + child->setAutoFillBackground(true); + child->setAttribute(Qt::WA_StaticContents); + child->resize(100, 100); + one->setWidget(child); + + QToolBar *mainTools = mw.addToolBar("Main Tools"); + mainTools->addWidget(new QLineEdit); + + mw.show(); + QTest::qWaitForWindowShown(&mw); + + one->setFloating(true); + QTest::qWait(20); + //do not crash } #ifdef Q_WS_QWS @@ -9726,7 +9754,7 @@ public: void deleteBackingStore() { if (static_cast(d_ptr.data())->maybeBackingStore()) { - delete static_cast(d_ptr.data())->topData()->backingStore; + delete static_cast(d_ptr.data())->topData()->backingStore; static_cast(d_ptr.data())->topData()->backingStore = 0; } } -- cgit v0.12 From f5d106e78e2fd51d20c2e9c82afadc172bc84af2 Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Tue, 29 Dec 2009 15:12:21 +0100 Subject: Remove pointless const's from functions (internal API) This change is in response to the review for b063135, but was missed from that patch. Reviewed-By: Kim --- src/opengl/gl2paintengineex/qglengineshadermanager.cpp | 4 ++-- src/opengl/gl2paintengineex/qglengineshadermanager_p.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp index 1d3801c..d28d5f3 100644 --- a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp +++ b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp @@ -393,7 +393,7 @@ QGLEngineShaderManager::~QGLEngineShaderManager() removeCustomStage(); } -GLuint QGLEngineShaderManager::getUniformLocation(const Uniform id) +GLuint QGLEngineShaderManager::getUniformLocation(Uniform id) { if (!currentShaderProg) return 0; @@ -428,7 +428,7 @@ GLuint QGLEngineShaderManager::getUniformLocation(const Uniform id) } -void QGLEngineShaderManager::optimiseForBrushTransform(const QTransform::TransformationType transformType) +void QGLEngineShaderManager::optimiseForBrushTransform(QTransform::TransformationType transformType) { Q_UNUSED(transformType); // Currently ignored } diff --git a/src/opengl/gl2paintengineex/qglengineshadermanager_p.h b/src/opengl/gl2paintengineex/qglengineshadermanager_p.h index 3749b5c..1ec4cdc 100644 --- a/src/opengl/gl2paintengineex/qglengineshadermanager_p.h +++ b/src/opengl/gl2paintengineex/qglengineshadermanager_p.h @@ -454,7 +454,7 @@ public: // There are optimisations we can do, depending on the brush transform: // 1) May not have to apply perspective-correction // 2) Can use lower precision for matrix - void optimiseForBrushTransform(const QTransform::TransformationType transformType); + void optimiseForBrushTransform(QTransform::TransformationType transformType); void setSrcPixelType(Qt::BrushStyle); void setSrcPixelType(PixelSrcType); // For non-brush sources, like pixmaps & images void setOpacityMode(OpacityMode); @@ -463,7 +463,7 @@ public: void setCustomStage(QGLCustomShaderStage* stage); void removeCustomStage(); - GLuint getUniformLocation(const Uniform id); + GLuint getUniformLocation(Uniform id); void setDirty(); // someone has manually changed the current shader program bool useCorrectShaderProg(); // returns true if the shader program needed to be changed -- cgit v0.12