summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Arve Saether <jan-arve.saether@digia.com>2014-01-15 15:28:08 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-17 10:46:32 +0100
commit43691a7e6d1a57d19639ddf4af9a1a6567c9c805 (patch)
tree704d0919a342296b897035271960d179493a7b23
parent24634002e33d9cda641305b21886b81292664e5c (diff)
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 <jpnurmi@digia.com>
-rw-r--r--src/gui/util/qgridlayoutengine.cpp39
1 files changed, 9 insertions, 30 deletions
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<qreal> sizehint_xx;
QVector<qreal> 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