diff options
author | Keith Kyzivat <keith.kyzivat@qt.io> | 2020-10-13 16:04:14 -0400 |
---|---|---|
committer | Keith Kyzivat <keith.kyzivat@qt.io> | 2020-10-23 15:00:06 +0000 |
commit | 07f28ce1eab983a49e661855ee11ffbd624f0083 (patch) | |
tree | 40cfda27477df48604387402659ff97e20c3e3eb /src | |
parent | c082168fba5deb930a01502c54bf2080af53b544 (diff) |
Prevent zoom-out beyond infinite linear max double values
When zooming out domains that include log axes, prevent zoom-out
when the new zoom level would result in a max value that is above
the upper range of double (represented as inf).
Additionally, prevent zoom-out when the log value exceeds the
number of pixels in the log axis dimension. Major gridlines are
created at each integral log value, and it does not make sense to
zoom out beyond such point.
Task-number: QTBUG-75500
Change-Id: Icab72f600a84297d43da675c5757f6e63ae25119
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
(cherry picked from commit e71430cd2b82cda52a2886c941b227eb6cdbcb7a)
Diffstat (limited to 'src')
-rw-r--r-- | src/charts/domain/logxlogydomain.cpp | 10 | ||||
-rw-r--r-- | src/charts/domain/logxydomain.cpp | 10 | ||||
-rw-r--r-- | src/charts/domain/xlogydomain.cpp | 6 | ||||
-rw-r--r-- | src/charts/qchart.cpp | 1 | ||||
-rw-r--r-- | src/chartsqml2/declarativechart.cpp | 1 |
5 files changed, 24 insertions, 4 deletions
diff --git a/src/charts/domain/logxlogydomain.cpp b/src/charts/domain/logxlogydomain.cpp index 04ba559f..2c8cd1b8 100644 --- a/src/charts/domain/logxlogydomain.cpp +++ b/src/charts/domain/logxlogydomain.cpp @@ -115,9 +115,9 @@ void LogXLogYDomain::zoomOut(const QRectF &rect) const qreal factorY = m_size.height() / fixedRect.height(); qreal logLeftX = m_logLeftX + (m_logRightX - m_logLeftX) / 2 * (1 - factorX); - qreal logRIghtX = m_logLeftX + (m_logRightX - m_logLeftX) / 2 * (1 + factorX); + qreal logRightX = m_logLeftX + (m_logRightX - m_logLeftX) / 2 * (1 + factorX); qreal leftX = qPow(m_logBaseX, logLeftX); - qreal rightX = qPow(m_logBaseX, logRIghtX); + qreal rightX = qPow(m_logBaseX, logRightX); qreal minX = leftX < rightX ? leftX : rightX; qreal maxX = leftX > rightX ? leftX : rightX; @@ -128,6 +128,12 @@ void LogXLogYDomain::zoomOut(const QRectF &rect) qreal minY = leftY < rightY ? leftY : rightY; qreal maxY = leftY > rightY ? leftY : rightY; + if (logRightX > m_size.width() || newLogMaxY > m_size.height()) + return; + + if (qIsInf(maxX) || qIsInf(maxY)) + return; + setRange(minX, maxX, minY, maxY); } diff --git a/src/charts/domain/logxydomain.cpp b/src/charts/domain/logxydomain.cpp index fb77656c..aedfb7f3 100644 --- a/src/charts/domain/logxydomain.cpp +++ b/src/charts/domain/logxydomain.cpp @@ -106,9 +106,9 @@ void LogXYDomain::zoomOut(const QRectF &rect) const qreal factorX = m_size.width() / fixedRect.width(); qreal logLeftX = m_logLeftX + (m_logRightX - m_logLeftX) / 2 * (1 - factorX); - qreal logRIghtX = m_logLeftX + (m_logRightX - m_logLeftX) / 2 * (1 + factorX); + qreal logRightX = m_logLeftX + (m_logRightX - m_logLeftX) / 2 * (1 + factorX); qreal leftX = qPow(m_logBaseX, logLeftX); - qreal rightX = qPow(m_logBaseX, logRIghtX); + qreal rightX = qPow(m_logBaseX, logRightX); qreal minX = leftX < rightX ? leftX : rightX; qreal maxX = leftX > rightX ? leftX : rightX; @@ -119,6 +119,12 @@ void LogXYDomain::zoomOut(const QRectF &rect) maxY = minY + dy * fixedRect.bottom(); minY = maxY - dy * m_size.height(); + if (logRightX > m_size.width()) + return; + + if (qIsInf(maxX)) + return; + setRange(minX, maxX, minY, maxY); } diff --git a/src/charts/domain/xlogydomain.cpp b/src/charts/domain/xlogydomain.cpp index 0cd995f3..19dd5ca5 100644 --- a/src/charts/domain/xlogydomain.cpp +++ b/src/charts/domain/xlogydomain.cpp @@ -118,6 +118,12 @@ void XLogYDomain::zoomOut(const QRectF &rect) qreal minY = leftY < rightY ? leftY : rightY; qreal maxY = leftY > rightY ? leftY : rightY; + if (newLogMaxY > m_size.height()) + return; + + if (qIsInf(maxY)) + return; + setRange(minX, maxX, minY, maxY); } diff --git a/src/charts/qchart.cpp b/src/charts/qchart.cpp index 703e6625..743fea6d 100644 --- a/src/charts/qchart.cpp +++ b/src/charts/qchart.cpp @@ -414,6 +414,7 @@ void QChart::zoomIn(const QRectF &rect) /*! Zooms out of the view by a factor of two. + \note This will do nothing if the result would contain an invalid logarithmic axis range. */ void QChart::zoomOut() { diff --git a/src/chartsqml2/declarativechart.cpp b/src/chartsqml2/declarativechart.cpp index 6cb811aa..a58e67c7 100644 --- a/src/chartsqml2/declarativechart.cpp +++ b/src/chartsqml2/declarativechart.cpp @@ -366,6 +366,7 @@ QT_CHARTS_BEGIN_NAMESPACE /*! \qmlmethod ChartView::zoomOut() Zooms out of the view by a factor of two. + \note This will do nothing if the result would contain an invalid logarithmic axis range. */ /*! |