From 22d472c17167c4ca8df5678842768ab63b7baadd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Tue, 24 Mar 2009 10:39:52 +0100 Subject: Do not cache the sizeHint() while we're in QGraphicsWidget's constructor. Do not send a QFontChange event before the item has been polished. This is because we cannot call a virtual function while we're in the ctor. This is basically the same as how we do it in QWidget. Task-number: 246215 Reviewed-by: alexis --- src/gui/graphicsview/qgraphicswidget.cpp | 2 + src/gui/graphicsview/qgraphicswidget_p.cpp | 2 + src/gui/graphicsview/qgraphicswidget_p.h | 2 + tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp | 64 ++++++++++++---------- 4 files changed, 41 insertions(+), 29 deletions(-) diff --git a/src/gui/graphicsview/qgraphicswidget.cpp b/src/gui/graphicsview/qgraphicswidget.cpp index 5cc18f9..64ec0e7 100644 --- a/src/gui/graphicsview/qgraphicswidget.cpp +++ b/src/gui/graphicsview/qgraphicswidget.cpp @@ -1269,6 +1269,8 @@ bool QGraphicsWidget::event(QEvent *event) break; case QEvent::Polish: polishEvent(); + d->polished = true; + d->updateFont(d->font); break; case QEvent::WindowActivate: case QEvent::WindowDeactivate: diff --git a/src/gui/graphicsview/qgraphicswidget_p.cpp b/src/gui/graphicsview/qgraphicswidget_p.cpp index 641409d..789f8da 100644 --- a/src/gui/graphicsview/qgraphicswidget_p.cpp +++ b/src/gui/graphicsview/qgraphicswidget_p.cpp @@ -274,6 +274,8 @@ void QGraphicsWidgetPrivate::updateFont(const QFont &font) } } + if (!polished) + return; // Notify change. QEvent event(QEvent::FontChange); QApplication::sendEvent(q, &event); diff --git a/src/gui/graphicsview/qgraphicswidget_p.h b/src/gui/graphicsview/qgraphicswidget_p.h index afa6812..455a129 100644 --- a/src/gui/graphicsview/qgraphicswidget_p.h +++ b/src/gui/graphicsview/qgraphicswidget_p.h @@ -85,6 +85,7 @@ public: inheritedPaletteResolveMask(0), inheritedFontResolveMask(0), inSetGeometry(0), + polished(0), focusPolicy(Qt::NoFocus), focusNext(0), focusPrev(0), @@ -193,6 +194,7 @@ public: } quint32 attributes : 10; quint32 inSetGeometry : 1; + quint32 polished: 1; // Focus Qt::FocusPolicy focusPolicy; diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp index 86d1acb..f25a079 100644 --- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp @@ -259,6 +259,35 @@ void tst_QGraphicsWidget::cleanup() { } +class SizeHinter : public QGraphicsWidget +{ +public: + SizeHinter(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0, + const QSizeF &min = QSizeF(5,5), + const QSizeF &pref = QSizeF(50, 50), + const QSizeF &max = QSizeF(500, 500)) + : QGraphicsWidget(parent, wFlags) + { + m_sizes[Qt::MinimumSize] = min; + m_sizes[Qt::PreferredSize] = pref; + m_sizes[Qt::MaximumSize] = max; + + } + void setSizeHint(Qt::SizeHint which, const QSizeF &newSizeHint) + { + m_sizes[which] = newSizeHint; + } + +protected: + QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const + { + Q_UNUSED(constraint); + return m_sizes[which]; + } +private: + QSizeF m_sizes[4]; +}; + void tst_QGraphicsWidget::qgraphicswidget() { SubQGraphicsWidget widget; @@ -282,6 +311,12 @@ void tst_QGraphicsWidget::qgraphicswidget() QCOMPARE(widget.type(), (int)QGraphicsWidget::Type); QCOMPARE(widget.call_propertyChange(QString(), QVariant()), QVariant()); widget.call_sizeHint(Qt::PreferredSize, QSizeF()); + + QGraphicsScene scene; + QGraphicsWidget *parent = new QGraphicsWidget; + SizeHinter *child = new SizeHinter(parent); + + QCOMPARE(child->minimumSize(), QSizeF(5, 5)); } void tst_QGraphicsWidget::activation() @@ -1516,35 +1551,6 @@ enum WhichSize { None, }; -class SizeHinter : public QGraphicsWidget -{ -public: - SizeHinter(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0, - const QSizeF &min = QSizeF(5,5), - const QSizeF &pref = QSizeF(50, 50), - const QSizeF &max = QSizeF(500, 500)) - : QGraphicsWidget(parent, wFlags) - { - m_sizes[Qt::MinimumSize] = min; - m_sizes[Qt::PreferredSize] = pref; - m_sizes[Qt::MaximumSize] = max; - - } - void setSizeHint(Qt::SizeHint which, const QSizeF &newSizeHint) - { - m_sizes[which] = newSizeHint; - } - -protected: - QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const - { - Q_UNUSED(constraint); - return m_sizes[which]; - } -private: - QSizeF m_sizes[4]; -}; - typedef QPair Inst; Q_DECLARE_METATYPE(Inst) -- cgit v0.12