SplitView: fix preferredHeight not being restored in restoreState()

Change-Id: Icc236494f5df382d6bc49092d23a460822c835a1
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
Mitch Curtis 2019-06-10 14:03:12 +02:00
parent 324ec97aa2
commit 7ded94bf0e
2 changed files with 17 additions and 9 deletions

View File

@ -1224,13 +1224,13 @@ QVariant QQuickSplitView::saveState()
cborMap[QLatin1String("preferredWidth")] = static_cast<double>(attachedPrivate->m_preferredWidth);
qCDebug(qlcQQuickSplitViewState).nospace() << "- wrote preferredWidth of "
<< attachedPrivate->m_preferredWidth << " for split item at index " << i;
<< attachedPrivate->m_preferredWidth << " for split item " << item << " at index " << i;
}
if (attachedPrivate->m_isPreferredHeightSet) {
cborMap[QLatin1String("preferredHeight")] = static_cast<double>(attachedPrivate->m_preferredHeight);
qCDebug(qlcQQuickSplitViewState).nospace() << "- wrote preferredHeight of "
<< attachedPrivate->m_preferredHeight << " for split item at index " << i;
<< attachedPrivate->m_preferredHeight << " for split item " << item << " at index " << i;
}
cborArray.append(cborMap);
@ -1280,7 +1280,7 @@ bool QQuickSplitView::restoreState(const QVariant &state)
QCborMap cborMap(it->toMap());
const int splitItemIndex = cborMap.value(QLatin1String("index")).toInteger();
const bool isPreferredWidthSet = cborMap.contains(QLatin1String("preferredWidth"));
const bool isPreferredHeightSet = cborMap.contains(QLatin1String("preferredWidth"));
const bool isPreferredHeightSet = cborMap.contains(QLatin1String("preferredHeight"));
QQuickItem *item = qobject_cast<QQuickItem*>(d->contentModel->object(splitItemIndex));
// If the split item does not have a preferred size specified in QML, it could still have
@ -1299,7 +1299,7 @@ bool QQuickSplitView::restoreState(const QVariant &state)
const QQuickSplitViewAttachedPrivate *attachedPrivate = QQuickSplitViewAttachedPrivate::get(attached);
qCDebug(qlcQQuickSplitViewState).nospace()
<< "- restored the following state for split item at index " << splitItemIndex
<< "- restored the following state for split item " << item << " at index " << splitItemIndex
<< ": preferredWidthSet=" << attachedPrivate->m_isPreferredWidthSet
<< " preferredWidth=" << attachedPrivate->m_preferredWidth
<< " preferredHeightSet=" << attachedPrivate->m_isPreferredHeightSet

View File

@ -1851,13 +1851,21 @@ TestCase {
}
}
function test_saveAndRestoreState() {
var control = createTemporaryObject(threeSizedItemsComponent, testCase)
function test_saveAndRestoreState_data() {
return [
{ tag: "Horizontal", orientation: Qt.Horizontal, propertyName: "preferredWidth", propertyValue: 123 },
{ tag: "Vertical", orientation: Qt.Vertical, propertyName: "preferredHeight", propertyValue: 234 }
]
}
function test_saveAndRestoreState(data) {
var control = createTemporaryObject(threeSizedItemsComponent, testCase, { orientation: data.orientation })
verify(control)
compare(control.orientation, data.orientation)
var lastItem = control.itemAt(2)
verify(lastItem)
lastItem.SplitView.preferredWidth = 123
lastItem.SplitView[data.propertyName] = data.propertyValue
// Save the state.
var settings = createTemporaryObject(settingsComponent, testCase)
@ -1868,14 +1876,14 @@ TestCase {
control = createTemporaryObject(threeSizedItemsComponent, testCase)
lastItem = control.itemAt(2)
verify(lastItem)
compare(lastItem.SplitView.preferredWidth, -1)
compare(lastItem.SplitView[data.propertyName], -1)
settings = createTemporaryObject(settingsComponent, testCase)
verify(settings)
// Restore the state.
control.restoreState(settings.value("splitView"))
compare(lastItem.SplitView.preferredWidth, 123)
compare(lastItem.SplitView[data.propertyName], data.propertyValue)
}
function test_changePreferredSizeDuringLayout() {