Fix saving handle width in QSplitter::saveState()

QSplitter::handleWidth() returns either a style dependent value if
d->handleWidth is negative or the value of d->handleWidth itself.
So to preserve this choice after calling saveState()/restoreState()
we should save and restore the value of d->handleWidth rather than a
result of handleWidth() which is non-negative.

Change-Id: Idc11f8063d34b6c4a5f9b0a0032868679766dfb9
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
Alexander Volkov 2014-09-12 17:49:59 +04:00
parent eb6507039f
commit 80ca159b47
2 changed files with 38 additions and 1 deletions

View File

@ -1609,7 +1609,7 @@ QByteArray QSplitter::saveState() const
}
stream << list;
stream << childrenCollapsible();
stream << qint32(handleWidth());
stream << qint32(d->handleWidth);
stream << opaqueResize();
stream << qint32(orientation());
stream << d->opaqueResizeSet;

View File

@ -56,6 +56,7 @@
#include <qlabel.h>
#include <qdialog.h>
#include <qscreen.h>
#include <qproxystyle.h>
#include <qdebug.h> // for file error messages
QT_FORWARD_DECLARE_CLASS(QSplitter)
@ -88,6 +89,7 @@ private slots:
void testRemoval();
void rubberBandNotInSplitter();
void saveAndRestoreStateOfNotYetShownSplitter();
void saveAndRestoreHandleWidth();
// task-specific tests below me:
void task187373_addAbstractScrollAreas();
@ -301,6 +303,41 @@ void tst_QSplitter::saveAndRestoreStateOfNotYetShownSplitter()
delete spl;
}
class TestSplitterStyle : public QProxyStyle
{
public:
TestSplitterStyle() : handleWidth(5) {}
int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const Q_DECL_OVERRIDE
{
if (metric == QStyle::PM_SplitterWidth)
return handleWidth;
else
return QProxyStyle::pixelMetric(metric, option, widget);
}
int handleWidth;
};
void tst_QSplitter::saveAndRestoreHandleWidth()
{
TestSplitterStyle style;
style.handleWidth = 5;
QSplitter spl;
spl.setStyle(&style);
QCOMPARE(spl.handleWidth(), style.handleWidth);
style.handleWidth = 10;
QCOMPARE(spl.handleWidth(), style.handleWidth);
QByteArray ba = spl.saveState();
spl.setHandleWidth(20);
QCOMPARE(spl.handleWidth(), 20);
spl.setHandleWidth(-1);
QCOMPARE(spl.handleWidth(), style.handleWidth);
spl.setHandleWidth(15);
QCOMPARE(spl.handleWidth(), 15);
spl.restoreState(ba);
QCOMPARE(spl.handleWidth(), style.handleWidth);
}
void tst_QSplitter::saveState_data()
{
QTest::addColumn<IntList>("initialSizes");