@@ -445,6 +445,31 void ChartDataSet::zoomOutDomain(const QRectF &rect) | |||
|
445 | 445 | domain->blockRangeSignals(false); |
|
446 | 446 | } |
|
447 | 447 | |
|
448 | void ChartDataSet::zoomResetDomain() | |
|
449 | { | |
|
450 | QList<AbstractDomain*> domains; | |
|
451 | foreach (QAbstractSeries *s, m_seriesList) { | |
|
452 | AbstractDomain *domain = s->d_ptr->domain(); | |
|
453 | s->d_ptr->m_domain->blockRangeSignals(true); | |
|
454 | domains << domain; | |
|
455 | } | |
|
456 | ||
|
457 | foreach (AbstractDomain *domain, domains) | |
|
458 | domain->zoomReset(); | |
|
459 | ||
|
460 | foreach (AbstractDomain *domain, domains) | |
|
461 | domain->blockRangeSignals(false); | |
|
462 | } | |
|
463 | ||
|
464 | bool ChartDataSet::isZoomedDomain() | |
|
465 | { | |
|
466 | foreach (QAbstractSeries *s, m_seriesList) { | |
|
467 | if (s->d_ptr->domain()->isZoomed()) | |
|
468 | return true; | |
|
469 | } | |
|
470 | return false; | |
|
471 | } | |
|
472 | ||
|
448 | 473 | void ChartDataSet::scrollDomain(qreal dx, qreal dy) |
|
449 | 474 | { |
|
450 | 475 | QList<AbstractDomain*> domains; |
@@ -62,6 +62,8 public: | |||
|
62 | 62 | |
|
63 | 63 | void zoomInDomain(const QRectF &rect); |
|
64 | 64 | void zoomOutDomain(const QRectF &rect); |
|
65 | void zoomResetDomain(); | |
|
66 | bool isZoomedDomain(); | |
|
65 | 67 | void scrollDomain(qreal dx, qreal dy); |
|
66 | 68 | |
|
67 | 69 | QPointF mapToValue(const QPointF &position, QAbstractSeries *series = 0); |
@@ -30,7 +30,13 AbstractDomain::AbstractDomain(QObject *parent) | |||
|
30 | 30 | m_maxX(0), |
|
31 | 31 | m_minY(0), |
|
32 | 32 | m_maxY(0), |
|
33 | m_signalsBlocked(false) | |
|
33 | m_signalsBlocked(false), | |
|
34 | m_zoomed(false), | |
|
35 | m_zoomResetMinX(0), | |
|
36 | m_zoomResetMaxX(0), | |
|
37 | m_zoomResetMinY(0), | |
|
38 | m_zoomResetMaxY(0) | |
|
39 | ||
|
34 | 40 | { |
|
35 | 41 | } |
|
36 | 42 | |
@@ -131,6 +137,28 void AbstractDomain::blockRangeSignals(bool block) | |||
|
131 | 137 | } |
|
132 | 138 | } |
|
133 | 139 | |
|
140 | void AbstractDomain::zoomReset() | |
|
141 | { | |
|
142 | if (m_zoomed) { | |
|
143 | setRange(m_zoomResetMinX, | |
|
144 | m_zoomResetMaxX, | |
|
145 | m_zoomResetMinY, | |
|
146 | m_zoomResetMaxY); | |
|
147 | m_zoomed = false; | |
|
148 | } | |
|
149 | } | |
|
150 | ||
|
151 | void AbstractDomain::storeZoomReset() | |
|
152 | { | |
|
153 | if (!m_zoomed) { | |
|
154 | m_zoomed = true; | |
|
155 | m_zoomResetMinX = m_minX; | |
|
156 | m_zoomResetMaxX = m_maxX; | |
|
157 | m_zoomResetMinY = m_minY; | |
|
158 | m_zoomResetMaxY = m_maxY; | |
|
159 | } | |
|
160 | } | |
|
161 | ||
|
134 | 162 | //algorithm defined by Paul S.Heckbert GraphicalGems I |
|
135 | 163 | |
|
136 | 164 | void AbstractDomain::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) |
@@ -80,6 +80,10 public: | |||
|
80 | 80 | void blockRangeSignals(bool block); |
|
81 | 81 | bool rangeSignalsBlocked() const { return m_signalsBlocked; } |
|
82 | 82 | |
|
83 | void zoomReset(); | |
|
84 | void storeZoomReset(); | |
|
85 | bool isZoomed() { return m_zoomed; } | |
|
86 | ||
|
83 | 87 | friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const AbstractDomain &domain1, const AbstractDomain &domain2); |
|
84 | 88 | friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const AbstractDomain &domain1, const AbstractDomain &domain2); |
|
85 | 89 | friend QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const AbstractDomain &domain); |
@@ -116,6 +120,11 protected: | |||
|
116 | 120 | qreal m_maxY; |
|
117 | 121 | QSizeF m_size; |
|
118 | 122 | bool m_signalsBlocked; |
|
123 | bool m_zoomed; | |
|
124 | qreal m_zoomResetMinX; | |
|
125 | qreal m_zoomResetMaxX; | |
|
126 | qreal m_zoomResetMinY; | |
|
127 | qreal m_zoomResetMaxY; | |
|
119 | 128 | }; |
|
120 | 129 | |
|
121 | 130 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -78,6 +78,7 void LogXLogYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) | |||
|
78 | 78 | |
|
79 | 79 | void LogXLogYDomain::zoomIn(const QRectF &rect) |
|
80 | 80 | { |
|
81 | storeZoomReset(); | |
|
81 | 82 | qreal logLeftX = rect.left() * (m_logRightX - m_logLeftX) / m_size.width() + m_logLeftX; |
|
82 | 83 | qreal logRightX = rect.right() * (m_logRightX - m_logLeftX) / m_size.width() + m_logLeftX; |
|
83 | 84 | qreal leftX = qPow(m_logBaseX, logLeftX); |
@@ -97,6 +98,7 void LogXLogYDomain::zoomIn(const QRectF &rect) | |||
|
97 | 98 | |
|
98 | 99 | void LogXLogYDomain::zoomOut(const QRectF &rect) |
|
99 | 100 | { |
|
101 | storeZoomReset(); | |
|
100 | 102 | const qreal factorX = m_size.width() / rect.width(); |
|
101 | 103 | const qreal factorY = m_size.height() / rect.height(); |
|
102 | 104 |
@@ -78,6 +78,7 void LogXLogYPolarDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal max | |||
|
78 | 78 | |
|
79 | 79 | void LogXLogYPolarDomain::zoomIn(const QRectF &rect) |
|
80 | 80 | { |
|
81 | storeZoomReset(); | |
|
81 | 82 | qreal logLeftX = rect.left() * (m_logRightX - m_logLeftX) / m_size.width() + m_logLeftX; |
|
82 | 83 | qreal logRightX = rect.right() * (m_logRightX - m_logLeftX) / m_size.width() + m_logLeftX; |
|
83 | 84 | qreal leftX = qPow(m_logBaseX, logLeftX); |
@@ -97,6 +98,7 void LogXLogYPolarDomain::zoomIn(const QRectF &rect) | |||
|
97 | 98 | |
|
98 | 99 | void LogXLogYPolarDomain::zoomOut(const QRectF &rect) |
|
99 | 100 | { |
|
101 | storeZoomReset(); | |
|
100 | 102 | const qreal factorX = m_size.width() / rect.width(); |
|
101 | 103 | |
|
102 | 104 | qreal logLeftX = m_logLeftX + (m_logRightX - m_logLeftX) / 2.0 * (1.0 - factorX); |
@@ -70,6 +70,7 void LogXYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) | |||
|
70 | 70 | |
|
71 | 71 | void LogXYDomain::zoomIn(const QRectF &rect) |
|
72 | 72 | { |
|
73 | storeZoomReset(); | |
|
73 | 74 | qreal logLeftX = rect.left() * (m_logRightX - m_logLeftX) / m_size.width() + m_logLeftX; |
|
74 | 75 | qreal logRightX = rect.right() * (m_logRightX - m_logLeftX) / m_size.width() + m_logLeftX; |
|
75 | 76 | qreal leftX = qPow(m_logBaseX, logLeftX); |
@@ -89,6 +90,7 void LogXYDomain::zoomIn(const QRectF &rect) | |||
|
89 | 90 | |
|
90 | 91 | void LogXYDomain::zoomOut(const QRectF &rect) |
|
91 | 92 | { |
|
93 | storeZoomReset(); | |
|
92 | 94 | const qreal factorX = m_size.width() / rect.width(); |
|
93 | 95 | |
|
94 | 96 | qreal logLeftX = m_logLeftX + (m_logRightX - m_logLeftX) / 2 * (1 - factorX); |
@@ -70,6 +70,7 void LogXYPolarDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) | |||
|
70 | 70 | |
|
71 | 71 | void LogXYPolarDomain::zoomIn(const QRectF &rect) |
|
72 | 72 | { |
|
73 | storeZoomReset(); | |
|
73 | 74 | qreal logLeftX = rect.left() * (m_logRightX - m_logLeftX) / m_size.width() + m_logLeftX; |
|
74 | 75 | qreal logRightX = rect.right() * (m_logRightX - m_logLeftX) / m_size.width() + m_logLeftX; |
|
75 | 76 | qreal leftX = qPow(m_logBaseX, logLeftX); |
@@ -89,6 +90,7 void LogXYPolarDomain::zoomIn(const QRectF &rect) | |||
|
89 | 90 | |
|
90 | 91 | void LogXYPolarDomain::zoomOut(const QRectF &rect) |
|
91 | 92 | { |
|
93 | storeZoomReset(); | |
|
92 | 94 | const qreal factorX = m_size.width() / rect.width(); |
|
93 | 95 | |
|
94 | 96 | qreal logLeftX = m_logLeftX + (m_logRightX - m_logLeftX) / 2.0 * (1.0 - factorX); |
@@ -70,6 +70,7 void XLogYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) | |||
|
70 | 70 | |
|
71 | 71 | void XLogYDomain::zoomIn(const QRectF &rect) |
|
72 | 72 | { |
|
73 | storeZoomReset(); | |
|
73 | 74 | qreal dx = spanX() / m_size.width(); |
|
74 | 75 | qreal maxX = m_maxX; |
|
75 | 76 | qreal minX = m_minX; |
@@ -89,6 +90,7 void XLogYDomain::zoomIn(const QRectF &rect) | |||
|
89 | 90 | |
|
90 | 91 | void XLogYDomain::zoomOut(const QRectF &rect) |
|
91 | 92 | { |
|
93 | storeZoomReset(); | |
|
92 | 94 | qreal dx = spanX() / rect.width(); |
|
93 | 95 | qreal maxX = m_maxX; |
|
94 | 96 | qreal minX = m_minX; |
@@ -70,6 +70,7 void XLogYPolarDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) | |||
|
70 | 70 | |
|
71 | 71 | void XLogYPolarDomain::zoomIn(const QRectF &rect) |
|
72 | 72 | { |
|
73 | storeZoomReset(); | |
|
73 | 74 | qreal dx = spanX() / m_size.width(); |
|
74 | 75 | qreal maxX = m_maxX; |
|
75 | 76 | qreal minX = m_minX; |
@@ -89,6 +90,7 void XLogYPolarDomain::zoomIn(const QRectF &rect) | |||
|
89 | 90 | |
|
90 | 91 | void XLogYPolarDomain::zoomOut(const QRectF &rect) |
|
91 | 92 | { |
|
93 | storeZoomReset(); | |
|
92 | 94 | qreal dx = spanX() / rect.width(); |
|
93 | 95 | qreal maxX = m_maxX; |
|
94 | 96 | qreal minX = m_minX; |
@@ -61,6 +61,7 void XYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) | |||
|
61 | 61 | |
|
62 | 62 | void XYDomain::zoomIn(const QRectF &rect) |
|
63 | 63 | { |
|
64 | storeZoomReset(); | |
|
64 | 65 | qreal dx = spanX() / m_size.width(); |
|
65 | 66 | qreal dy = spanY() / m_size.height(); |
|
66 | 67 | |
@@ -79,6 +80,7 void XYDomain::zoomIn(const QRectF &rect) | |||
|
79 | 80 | |
|
80 | 81 | void XYDomain::zoomOut(const QRectF &rect) |
|
81 | 82 | { |
|
83 | storeZoomReset(); | |
|
82 | 84 | qreal dx = spanX() / rect.width(); |
|
83 | 85 | qreal dy = spanY() / rect.height(); |
|
84 | 86 |
@@ -61,6 +61,7 void XYPolarDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) | |||
|
61 | 61 | |
|
62 | 62 | void XYPolarDomain::zoomIn(const QRectF &rect) |
|
63 | 63 | { |
|
64 | storeZoomReset(); | |
|
64 | 65 | qreal dx = spanX() / m_size.width(); |
|
65 | 66 | qreal dy = spanY() / m_size.height(); |
|
66 | 67 | |
@@ -79,6 +80,7 void XYPolarDomain::zoomIn(const QRectF &rect) | |||
|
79 | 80 | |
|
80 | 81 | void XYPolarDomain::zoomOut(const QRectF &rect) |
|
81 | 82 | { |
|
83 | storeZoomReset(); | |
|
82 | 84 | qreal dx = spanX() / rect.width(); |
|
83 | 85 | qreal dy = spanY() / rect.height(); |
|
84 | 86 |
@@ -347,6 +347,26 void QChart::zoom(qreal factor) | |||
|
347 | 347 | d_ptr->zoomOut(1.0 / factor); |
|
348 | 348 | } |
|
349 | 349 | |
|
350 | ||
|
351 | /*! | |
|
352 | Resets the series domains to what they were before any zoom method was called. | |
|
353 | Note that this will also reset any scrolls and explicit axis range settings done between | |
|
354 | the first zoom operation and calling this method. If no zoom operation has been | |
|
355 | done, this method does nothing. | |
|
356 | */ | |
|
357 | void QChart::zoomReset() | |
|
358 | { | |
|
359 | d_ptr->zoomReset(); | |
|
360 | } | |
|
361 | ||
|
362 | /*! | |
|
363 | Returns true if any series has a zoomed domain. | |
|
364 | */ | |
|
365 | bool QChart::isZoomed() | |
|
366 | { | |
|
367 | return d_ptr->isZoomed(); | |
|
368 | } | |
|
369 | ||
|
350 | 370 | /*! |
|
351 | 371 | Returns a pointer to the horizontal axis attached to the specified \a series. |
|
352 | 372 | If no \a series is specified, the first horizontal axis added to the chart is returned. |
@@ -749,6 +769,16 void QChartPrivate::zoomIn(const QRectF &rect) | |||
|
749 | 769 | |
|
750 | 770 | } |
|
751 | 771 | |
|
772 | void QChartPrivate::zoomReset() | |
|
773 | { | |
|
774 | m_dataset->zoomResetDomain(); | |
|
775 | } | |
|
776 | ||
|
777 | bool QChartPrivate::isZoomed() | |
|
778 | { | |
|
779 | return m_dataset->isZoomedDomain(); | |
|
780 | } | |
|
781 | ||
|
752 | 782 | void QChartPrivate::zoomOut(qreal factor) |
|
753 | 783 | { |
|
754 | 784 | const QRectF geometry = m_presenter->geometry(); |
@@ -126,6 +126,8 public: | |||
|
126 | 126 | |
|
127 | 127 | void zoomIn(const QRectF &rect); |
|
128 | 128 | void zoom(qreal factor); |
|
129 | void zoomReset(); | |
|
130 | bool isZoomed(); | |
|
129 | 131 | |
|
130 | 132 | void scroll(qreal dx, qreal dy); |
|
131 | 133 |
@@ -61,6 +61,8 public: | |||
|
61 | 61 | void zoomIn(qreal factor); |
|
62 | 62 | void zoomOut(qreal factor); |
|
63 | 63 | void zoomIn(const QRectF &rect); |
|
64 | void zoomReset(); | |
|
65 | bool isZoomed(); | |
|
64 | 66 | void scroll(qreal dx, qreal dy); |
|
65 | 67 | }; |
|
66 | 68 |
@@ -177,7 +177,7 void QChartView::mouseMoveEvent(QMouseEvent *event) | |||
|
177 | 177 | /*! |
|
178 | 178 | If left mouse button is released and the rubber band is enabled then \a event is accepted and |
|
179 | 179 | the view is zoomed into the rect specified by the rubber band. |
|
180 |
If it is a right mouse button \a event then the |
|
|
180 | If it is a right mouse button \a event then the view is zoomed out. | |
|
181 | 181 | */ |
|
182 | 182 | void QChartView::mouseReleaseEvent(QMouseEvent *event) |
|
183 | 183 | { |
@@ -105,6 +105,7 private slots: | |||
|
105 | 105 | void zoomIn(); |
|
106 | 106 | void zoomOut_data(); |
|
107 | 107 | void zoomOut(); |
|
108 | void zoomReset(); | |
|
108 | 109 | void createDefaultAxesForLineSeries_data(); |
|
109 | 110 | void createDefaultAxesForLineSeries(); |
|
110 | 111 | void axisPolarOrientation(); |
@@ -852,6 +853,77 void tst_QChart::zoomOut() | |||
|
852 | 853 | |
|
853 | 854 | } |
|
854 | 855 | |
|
856 | void tst_QChart::zoomReset() | |
|
857 | { | |
|
858 | createTestData(); | |
|
859 | m_chart->createDefaultAxes(); | |
|
860 | QValueAxis *axisX = qobject_cast<QValueAxis *>(m_chart->axisX()); | |
|
861 | QVERIFY(axisX != 0); | |
|
862 | QValueAxis *axisY = qobject_cast<QValueAxis *>(m_chart->axisY()); | |
|
863 | QVERIFY(axisY != 0); | |
|
864 | ||
|
865 | qreal minX = axisX->min(); | |
|
866 | qreal minY = axisY->min(); | |
|
867 | qreal maxX = axisX->max(); | |
|
868 | qreal maxY = axisY->max(); | |
|
869 | ||
|
870 | QVERIFY(!m_chart->isZoomed()); | |
|
871 | ||
|
872 | m_chart->zoomIn(); | |
|
873 | ||
|
874 | QVERIFY(m_chart->isZoomed()); | |
|
875 | QVERIFY(minX < axisX->min()); | |
|
876 | QVERIFY(maxX > axisX->max()); | |
|
877 | QVERIFY(minY < axisY->min()); | |
|
878 | QVERIFY(maxY > axisY->max()); | |
|
879 | ||
|
880 | m_chart->zoomReset(); | |
|
881 | ||
|
882 | // Reset after zoomIn should restore originals | |
|
883 | QVERIFY(!m_chart->isZoomed()); | |
|
884 | QVERIFY(minX == axisX->min()); | |
|
885 | QVERIFY(maxX == axisX->max()); | |
|
886 | QVERIFY(minY == axisY->min()); | |
|
887 | QVERIFY(maxY == axisY->max()); | |
|
888 | ||
|
889 | m_chart->zoomOut(); | |
|
890 | ||
|
891 | QVERIFY(m_chart->isZoomed()); | |
|
892 | QVERIFY(minX > axisX->min()); | |
|
893 | QVERIFY(maxX < axisX->max()); | |
|
894 | QVERIFY(minY > axisY->min()); | |
|
895 | QVERIFY(maxY < axisY->max()); | |
|
896 | ||
|
897 | m_chart->zoomReset(); | |
|
898 | ||
|
899 | // Reset after zoomOut should restore originals | |
|
900 | QVERIFY(!m_chart->isZoomed()); | |
|
901 | QVERIFY(minX == axisX->min()); | |
|
902 | QVERIFY(maxX == axisX->max()); | |
|
903 | QVERIFY(minY == axisY->min()); | |
|
904 | QVERIFY(maxY == axisY->max()); | |
|
905 | ||
|
906 | axisX->setRange(234, 345); | |
|
907 | axisY->setRange(345, 456); | |
|
908 | ||
|
909 | minX = axisX->min(); | |
|
910 | minY = axisY->min(); | |
|
911 | maxX = axisX->max(); | |
|
912 | maxY = axisY->max(); | |
|
913 | ||
|
914 | QVERIFY(!m_chart->isZoomed()); | |
|
915 | ||
|
916 | m_chart->zoomReset(); | |
|
917 | ||
|
918 | // Reset without zoom should not change anything | |
|
919 | QVERIFY(!m_chart->isZoomed()); | |
|
920 | QVERIFY(minX == axisX->min()); | |
|
921 | QVERIFY(maxX == axisX->max()); | |
|
922 | QVERIFY(minY == axisY->min()); | |
|
923 | QVERIFY(maxY == axisY->max()); | |
|
924 | ||
|
925 | } | |
|
926 | ||
|
855 | 927 | void tst_QChart::createDefaultAxesForLineSeries_data() |
|
856 | 928 | { |
|
857 | 929 | QTest::addColumn<qreal>("series1minX"); |
General Comments 0
You need to be logged in to leave comments.
Login now