QStyle: Fix cases when logicalValue is outside range
Change-Id: I410c40425d6677612dbe3a40cbaa1debba998064 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
parent
bd6d6d92b5
commit
0031c5cb79
@ -2257,10 +2257,12 @@ Qt::Alignment QStyle::visualAlignment(Qt::LayoutDirection direction, Qt::Alignme
|
||||
|
||||
int QStyle::sliderPositionFromValue(int min, int max, int logicalValue, int span, bool upsideDown)
|
||||
{
|
||||
if (span <= 0 || logicalValue < min || max <= min)
|
||||
if (span <= 0 || max <= min)
|
||||
return 0;
|
||||
if (logicalValue < min)
|
||||
return upsideDown ? span : 0;
|
||||
if (logicalValue > max)
|
||||
return upsideDown ? span : min;
|
||||
return upsideDown ? 0 : span;
|
||||
|
||||
const uint range = qint64(max) - min;
|
||||
const uint p = upsideDown ? qint64(max) - logicalValue : qint64(logicalValue) - min;
|
||||
|
@ -680,14 +680,17 @@ void tst_QStyle::sliderPositionFromValue_data()
|
||||
QTest::addRow("no span inverse") << 12 << 56 << 34 << 0 << true << 0;
|
||||
|
||||
QTest::addRow("value too small") << 34 << 56 << 12 << 2000 << false << 0;
|
||||
QTest::addRow("value too small inverse") << 34 << 56 << 12 << 2000 << true << 2000;
|
||||
|
||||
QTest::addRow("no-range") << 12 << 12 << 12 << 2000 << false << 0;
|
||||
QTest::addRow("no-range-inverse") << 12 << 12 << 12 << 2000 << true << 0;
|
||||
|
||||
QTest::addRow("close-to-max") << 12 << 34 << 33 << 2000 << false << 1909;
|
||||
QTest::addRow("at-max") << 12 << 34 << 34 << 2000 << false << 2000;
|
||||
QTest::addRow("value too large") << 12 << 34 << 35 << 2000 << false << 2000;
|
||||
QTest::addRow("close-to-max-inverse") << 12 << 34 << 33 << 2000 << true << 91;
|
||||
QTest::addRow("at-max-inverse") << 12 << 34 << 34 << 2000 << true << 0;
|
||||
QTest::addRow("value too large-inverse") << 12 << 34 << 35 << 2000 << true << 0;
|
||||
|
||||
QTest::addRow("big-range") << 100000 << 700000 << 250000 << 2000 << false << 500;
|
||||
QTest::addRow("big-range-inverse") << 100000 << 700000 << 250000 << 2000 << true << 1500;
|
||||
|
Loading…
Reference in New Issue
Block a user