From 43691a7e6d1a57d19639ddf4af9a1a6567c9c805 Mon Sep 17 00:00:00 2001 From: Jan Arve Saether Date: Wed, 15 Jan 2014 15:28:08 +0100 Subject: Improve code in sizeHint() The plan is to do better caching in ensureColumnAndRowData(), and this patch will benefit for any such changes later Change-Id: Id1662e3fe7f70079e29ddb6e3d64e6e580ad9e0f Reviewed-by: J-P Nurmi --- src/gui/util/qgridlayoutengine.cpp | 39 +++++++++----------------------------- 1 file changed, 9 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/gui/util/qgridlayoutengine.cpp b/src/gui/util/qgridlayoutengine.cpp index 5202d30a3e..d22dcfb8e9 100644 --- a/src/gui/util/qgridlayoutengine.cpp +++ b/src/gui/util/qgridlayoutengine.cpp @@ -1051,18 +1051,15 @@ QRectF QGridLayoutEngine::cellRect(const QRectF &contentsGeometry, int row, int QSizeF QGridLayoutEngine::sizeHint(Qt::SizeHint which, const QSizeF &constraint, const QAbstractLayoutStyleInfo *styleInfo) const { - QGridLayoutBox sizehint_totalBoxes[NOrientations]; - bool sizeHintCalculated = false; if (hasDynamicConstraint() && rowCount() > 0 && columnCount() > 0) { + QGridLayoutBox sizehint_totalBoxes[NOrientations]; + bool sizeHintCalculated = false; if (constraintOrientation() == Qt::Vertical) { //We have items whose height depends on their width if (constraint.width() >= 0) { - if (styleInfo->hasChanged() || !q_totalBoxesValid) - ensureColumnAndRowData(&q_columnData, &sizehint_totalBoxes[Hor], NULL, NULL, Qt::Horizontal, styleInfo); - else - sizehint_totalBoxes[Hor] = q_totalBoxes[Hor]; + ensureColumnAndRowData(&q_columnData, &sizehint_totalBoxes[Hor], NULL, NULL, Qt::Horizontal, styleInfo); QVector sizehint_xx; QVector sizehint_widths; @@ -1094,32 +1091,14 @@ QSizeF QGridLayoutEngine::sizeHint(Qt::SizeHint which, const QSizeF &constraint, sizeHintCalculated = true; } } + if (sizeHintCalculated) + return QSizeF(sizehint_totalBoxes[Hor].q_sizes(which), sizehint_totalBoxes[Ver].q_sizes(which)); } - if (!sizeHintCalculated) { - //No items with height for width, so it doesn't matter which order we do these in - if (styleInfo->hasChanged() || !q_totalBoxesValid) { - ensureColumnAndRowData(&q_columnData, &sizehint_totalBoxes[Hor], NULL, NULL, Qt::Horizontal, styleInfo); - ensureColumnAndRowData(&q_rowData, &sizehint_totalBoxes[Ver], NULL, NULL, Qt::Vertical, styleInfo); - } else { - sizehint_totalBoxes[Hor] = q_totalBoxes[Hor]; - sizehint_totalBoxes[Ver] = q_totalBoxes[Ver]; - } - } - - switch (which) { - case Qt::MinimumSize: - return QSizeF(sizehint_totalBoxes[Hor].q_minimumSize, sizehint_totalBoxes[Ver].q_minimumSize); - case Qt::PreferredSize: - return QSizeF(sizehint_totalBoxes[Hor].q_preferredSize, sizehint_totalBoxes[Ver].q_preferredSize); - case Qt::MaximumSize: - return QSizeF(sizehint_totalBoxes[Hor].q_maximumSize, sizehint_totalBoxes[Ver].q_maximumSize); - case Qt::MinimumDescent: - return QSizeF(-1.0, sizehint_totalBoxes[Hor].q_minimumDescent); // ### doesn't work - default: - break; - } - return QSizeF(); + //No items with height for width, so it doesn't matter which order we do these in + ensureColumnAndRowData(&q_columnData, &q_totalBoxes[Hor], NULL, NULL, Qt::Horizontal, styleInfo); + ensureColumnAndRowData(&q_rowData, &q_totalBoxes[Ver], NULL, NULL, Qt::Vertical, styleInfo); + return QSizeF(q_totalBoxes[Hor].q_sizes(which), q_totalBoxes[Ver].q_sizes(which)); } QLayoutPolicy::ControlTypes QGridLayoutEngine::controlTypes(LayoutSide side) const -- cgit v1.2.3