aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquicksplitview.cpp
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2018-12-04 15:44:00 +0100
committerMitch Curtis <mitch.curtis@qt.io>2019-01-08 13:15:09 +0000
commit9c7429219d36e8eb40e1fe6e679715c89209fc40 (patch)
treed5a4999c774adf49f724886995ad05e3387caa7d /src/quicktemplates2/qquicksplitview.cpp
parentce9940ca550d70931248a98fc4d47f10959a9a9e (diff)
SplitView: schedule another layout if requested sizes changed during layout
As mentioned in the review of ed87e837, there could be a scenario where the user sets the preferred size of an item inside the onWidthChanged handler of another item: onWidthChanged: if (width < 10) secondItem.SplitView.preferredWidth = 100 Before this patch, this would result in the preferredWidth assignment being ignored since it happened during a layout. This patch adds some auto tests to ensure that this works, as the previous patch (that converted layouts to be done in polish/updatePolish cycles) already fixed the issue. It also adds a check to avoid doing too many layouts in the case of one of the split handles being dragged. Change-Id: Ide519b33a2fa3bf746ae3793e0671fd1750c70d8 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquicksplitview.cpp')
-rw-r--r--src/quicktemplates2/qquicksplitview.cpp49
1 files changed, 45 insertions, 4 deletions
diff --git a/src/quicktemplates2/qquicksplitview.cpp b/src/quicktemplates2/qquicksplitview.cpp
index 64ccb6c795..502d2b3a91 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();
}