aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/quicktemplates2/qquicksplitview.cpp49
-rw-r--r--src/quicktemplates2/qquicksplitview_p_p.h2
2 files changed, 46 insertions, 5 deletions
diff --git a/src/quicktemplates2/qquicksplitview.cpp b/src/quicktemplates2/qquicksplitview.cpp
index 64ccb6c7..502d2b3a 100644
--- a/src/quicktemplates2/qquicksplitview.cpp
+++ b/src/quicktemplates2/qquicksplitview.cpp
@@ -383,6 +383,20 @@ void QQuickSplitViewPrivate::layoutResizeSplitItems(qreal &usedWidth, qreal &use
attached = qobject_cast<QQuickSplitViewAttached*>(
qmlAttachedPropertiesObject<QQuickSplitView>(item, true));
}
+
+ /*
+ Users could conceivably respond to size changes in items by setting attached
+ SplitView properties:
+
+ onWidthChanged: if (width < 10) secondItem.SplitView.preferredWidth = 100
+
+ We handle this by doing another layout after the current layout if the
+ attached/implicit size properties are set during this layout. However, we also
+ need to set preferredWidth/Height here (for reasons mentioned in the comment above),
+ but we don't want this to count as a request for a delayed layout, so we guard against it.
+ */
+ m_ignoreNextLayoutRequest = true;
+
if (horizontal)
attached->setPreferredWidth(newItemSize);
else
@@ -430,14 +444,17 @@ void QQuickSplitViewPrivate::layoutResizeSplitItems(qreal &usedWidth, qreal &use
attached = qobject_cast<QQuickSplitViewAttached*>(
qmlAttachedPropertiesObject<QQuickSplitView>(item, true));
}
+
+ m_ignoreNextLayoutRequest = true;
+
if (horizontal)
attached->setPreferredWidth(newItemSize);
else
attached->setPreferredHeight(newItemSize);
- // We still need to use requestedWidth in the setWidth() call below,
+ // We still need to use requestedSize in the setWidth()/setHeight() call below,
// because sizeData has already been calculated and now contains an old
- // effectivePreferredWidth value.
+ // effectivePreferredWidth/Height value.
requestedSize = newItemSize;
qCDebug(qlcQQuickSplitView).nospace() << " - " << index << ": resized (dragged) " << item
@@ -1618,11 +1635,23 @@ void QQuickSplitViewAttached::setPreferredWidth(qreal width)
{
Q_D(QQuickSplitViewAttached);
d->m_isPreferredWidthSet = true;
+ // Make sure that we clear this flag now, before we emit the change signals
+ // which could cause another setter to be called.
+ auto splitViewPrivate = QQuickSplitViewPrivate::get(d->m_splitView);
+ const bool ignoreNextLayoutRequest = splitViewPrivate->m_ignoreNextLayoutRequest;
+ splitViewPrivate->m_ignoreNextLayoutRequest = false;
+
if (qFuzzyCompare(width, d->m_preferredWidth))
return;
d->m_preferredWidth = width;
- d->requestLayoutView();
+
+ if (!ignoreNextLayoutRequest) {
+ // We are currently in the middle of performing a layout, and the user (not our internal code)
+ // changed the preferred width of one of the split items, so request another layout.
+ d->requestLayoutView();
+ }
+
emit preferredWidthChanged();
}
@@ -1674,11 +1703,23 @@ void QQuickSplitViewAttached::setPreferredHeight(qreal height)
{
Q_D(QQuickSplitViewAttached);
d->m_isPreferredHeightSet = true;
+ // Make sure that we clear this flag now, before we emit the change signals
+ // which could cause another setter to be called.
+ auto splitViewPrivate = QQuickSplitViewPrivate::get(d->m_splitView);
+ const bool ignoreNextLayoutRequest = splitViewPrivate->m_ignoreNextLayoutRequest;
+ splitViewPrivate->m_ignoreNextLayoutRequest = false;
+
if (qFuzzyCompare(height, d->m_preferredHeight))
return;
d->m_preferredHeight = height;
- d->requestLayoutView();
+
+ if (!ignoreNextLayoutRequest) {
+ // We are currently in the middle of performing a layout, and the user (not our internal code)
+ // changed the preferred height of one of the split items, so request another layout.
+ d->requestLayoutView();
+ }
+
emit preferredHeightChanged();
}
diff --git a/src/quicktemplates2/qquicksplitview_p_p.h b/src/quicktemplates2/qquicksplitview_p_p.h
index 560276f0..5d71d461 100644
--- a/src/quicktemplates2/qquicksplitview_p_p.h
+++ b/src/quicktemplates2/qquicksplitview_p_p.h
@@ -106,7 +106,6 @@ public:
static QQuickSplitViewPrivate *get(QQuickSplitView *splitView);
-private:
Qt::Orientation m_orientation = Qt::Horizontal;
QQmlComponent *m_handle = nullptr;
QVector<QQuickItem*> m_handleItems;
@@ -119,6 +118,7 @@ private:
qreal m_rightOrBottomItemSizeBeforePress = 0.0;
int m_fillIndex = -1;
bool m_layingOut = false;
+ bool m_ignoreNextLayoutRequest = false;
bool m_resizing = false;
};