aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicklayouts/qquicklayout.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quicklayouts/qquicklayout.cpp')
-rw-r--r--src/quicklayouts/qquicklayout.cpp57
1 files changed, 36 insertions, 21 deletions
diff --git a/src/quicklayouts/qquicklayout.cpp b/src/quicklayouts/qquicklayout.cpp
index 3699b3fbcf..f38bdfd396 100644
--- a/src/quicklayouts/qquicklayout.cpp
+++ b/src/quicklayouts/qquicklayout.cpp
@@ -85,10 +85,12 @@ QQuickLayoutAttached::QQuickLayoutAttached(QObject *parent)
m_isMaximumWidthSet(false),
m_isMaximumHeightSet(false),
m_changesNotificationEnabled(true),
+ m_isMarginsSet(false),
m_isLeftMarginSet(false),
m_isTopMarginSet(false),
m_isRightMarginSet(false),
m_isBottomMarginSet(false),
+ m_isAlignmentSet(false),
m_horizontalStretch(-1),
m_verticalStretch(-1)
{
@@ -301,15 +303,16 @@ void QQuickLayoutAttached::setMaximumImplicitSize(const QSizeF &sz)
If this property is \c true, the item will be as wide as possible while respecting
the given constraints. If the property is \c false, the item will have a fixed width
set to the preferred width.
- The default is \c false, except for layouts themselves, which default to \c true.
+ The default depends on implicit (built-in) size policy of item.
\sa fillHeight
*/
void QQuickLayoutAttached::setFillWidth(bool fill)
{
+ bool oldFillWidth = fillWidth();
m_isFillWidthSet = true;
- if (m_fillWidth != fill) {
- m_fillWidth = fill;
+ m_fillWidth = fill;
+ if (oldFillWidth != fill) {
invalidateItem();
emit fillWidthChanged();
}
@@ -321,15 +324,16 @@ void QQuickLayoutAttached::setFillWidth(bool fill)
If this property is \c true, the item will be as tall as possible while respecting
the given constraints. If the property is \c false, the item will have a fixed height
set to the preferred height.
- The default is \c false, except for layouts themselves, which default to \c true.
+ The default depends on implicit (built-in) size policy of the item.
\sa fillWidth
*/
void QQuickLayoutAttached::setFillHeight(bool fill)
{
+ bool oldFillHeight = fillHeight();
m_isFillHeightSet = true;
- if (m_fillHeight != fill) {
- m_fillHeight = fill;
+ m_fillHeight = fill;
+ if (oldFillHeight != fill) {
invalidateItem();
emit fillHeightChanged();
}
@@ -403,6 +407,7 @@ void QQuickLayoutAttached::setColumn(int column)
*/
void QQuickLayoutAttached::setAlignment(Qt::Alignment align)
{
+ m_isAlignmentSet = true;
if (align != m_alignment) {
m_alignment = align;
if (QQuickLayout *layout = parentLayout()) {
@@ -434,6 +439,8 @@ void QQuickLayoutAttached::setAlignment(Qt::Alignment align)
\note This requires that Layout::fillWidth is set to true
+ \since Qt 6.5
+
\sa verticalStretchFactor
*/
void QQuickLayoutAttached::setHorizontalStretchFactor(int factor)
@@ -469,6 +476,8 @@ void QQuickLayoutAttached::setHorizontalStretchFactor(int factor)
\note This requires that Layout::fillHeight is set to true
+ \since Qt 6.5
+
\sa horizontalStretchFactor
*/
void QQuickLayoutAttached::setVerticalStretchFactor(int factor)
@@ -514,6 +523,7 @@ void QQuickLayoutAttached::setVerticalStretchFactor(int factor)
*/
void QQuickLayoutAttached::setMargins(qreal m)
{
+ m_isMarginsSet = true;
if (m == m_defaultMargins)
return;
@@ -825,19 +835,16 @@ void QQuickLayout::invalidate(QQuickItem * /*childItem*/)
d->m_dirtyArrangement = true;
if (!qobject_cast<QQuickLayout *>(parentItem())) {
-
- if (m_inUpdatePolish)
- ++m_polishInsideUpdatePolish;
- else
- m_polishInsideUpdatePolish = 0;
-
- if (m_polishInsideUpdatePolish <= 2) {
- // allow at most two consecutive loops in order to respond to height-for-width
- // (e.g QQuickText changes implicitHeight when its width gets changed)
- qCDebug(lcQuickLayouts) << "QQuickLayout::invalidate(), polish()";
- polish();
+ polish();
+
+ if (m_inUpdatePolish) {
+ if (++m_polishInsideUpdatePolish > 2)
+ // allow at most two consecutive loops in order to respond to height-for-width
+ // (e.g QQuickText changes implicitHeight when its width gets changed)
+ qCDebug(lcQuickLayouts) << "Layout polish loop detected for " << this
+ << ". The polish request will still be scheduled.";
} else {
- qmlWarning(this) << "Qt Quick Layouts: Polish loop detected. Aborting after two iterations.";
+ m_polishInsideUpdatePolish = 0;
}
}
}
@@ -916,7 +923,7 @@ void QQuickLayout::geometryChange(const QRectF &newGeometry, const QRectF &oldGe
{
Q_D(QQuickLayout);
QQuickItem::geometryChange(newGeometry, oldGeometry);
- if (d->m_disableRearrange || !isReady() || !newGeometry.isValid())
+ if (invalidated() || d->m_disableRearrange || !isReady())
return;
qCDebug(lcQuickLayouts) << "QQuickLayout::geometryChange" << newGeometry << oldGeometry;
@@ -1246,7 +1253,15 @@ void QQuickLayout::effectiveSizeHints_helper(QQuickItem *item, QSizeF *cachedSiz
*/
QLayoutPolicy::Policy QQuickLayout::effectiveSizePolicy_helper(QQuickItem *item, Qt::Orientation orientation, QQuickLayoutAttached *info)
{
- bool fillExtent = false;
+ bool fillExtent([&]{
+ QLayoutPolicy::Policy policy{QLayoutPolicy::Fixed};
+ if (item && QGuiApplication::testAttribute(Qt::AA_QtQuickUseDefaultSizePolicy)) {
+ QLayoutPolicy sizePolicy = QQuickItemPrivate::get(item)->sizePolicy();
+ policy = (orientation == Qt::Horizontal) ? sizePolicy.horizontalPolicy() : sizePolicy.verticalPolicy();
+ }
+ return (policy == QLayoutPolicy::Preferred);
+ }());
+
bool isSet = false;
if (info) {
if (orientation == Qt::Horizontal) {
@@ -1259,8 +1274,8 @@ QLayoutPolicy::Policy QQuickLayout::effectiveSizePolicy_helper(QQuickItem *item,
}
if (!isSet && qobject_cast<QQuickLayout*>(item))
fillExtent = true;
- return fillExtent ? QLayoutPolicy::Preferred : QLayoutPolicy::Fixed;
+ return fillExtent ? QLayoutPolicy::Preferred : QLayoutPolicy::Fixed;
}
void QQuickLayout::_q_dumpLayoutTree() const