@@ -1,144 +1,144 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | // W A R N I N G |
|
31 | 31 | // ------------- |
|
32 | 32 | // |
|
33 | 33 | // This file is not part of the Qt Chart API. It exists purely as an |
|
34 | 34 | // implementation detail. This header file may change from version to |
|
35 | 35 | // version without notice, or even be removed. |
|
36 | 36 | // |
|
37 | 37 | // We mean it. |
|
38 | 38 | |
|
39 | 39 | #ifndef QABSTRACTAXIS_P_H |
|
40 | 40 | #define QABSTRACTAXIS_P_H |
|
41 | 41 | |
|
42 | 42 | #include <QtCharts/QAbstractAxis> |
|
43 | 43 | #include <private/chartaxiselement_p.h> |
|
44 | 44 | #include <QtCharts/QChart> |
|
45 | 45 | #include <QtCore/QDebug> |
|
46 | 46 | |
|
47 | 47 | QT_BEGIN_NAMESPACE |
|
48 | 48 | class QGraphicsItem; |
|
49 | 49 | QT_END_NAMESPACE |
|
50 | 50 | |
|
51 | 51 | QT_CHARTS_BEGIN_NAMESPACE |
|
52 | 52 | |
|
53 | 53 | class ChartPresenter; |
|
54 | 54 | class AbstractDomain; |
|
55 | 55 | class QChart; |
|
56 | 56 | class QAbstractSeries; |
|
57 | 57 | class ChartTheme; |
|
58 | 58 | class ChartElement; |
|
59 | 59 | |
|
60 |
class Q |
|
|
60 | class Q_AUTOTEST_EXPORT QAbstractAxisPrivate : public QObject | |
|
61 | 61 | { |
|
62 | 62 | Q_OBJECT |
|
63 | 63 | public: |
|
64 | 64 | QAbstractAxisPrivate(QAbstractAxis *q); |
|
65 | 65 | ~QAbstractAxisPrivate(); |
|
66 | 66 | |
|
67 | 67 | public: |
|
68 | 68 | Qt::Alignment alignment() const { return m_alignment; } |
|
69 | 69 | Qt::Orientation orientation() const { return m_orientation; } |
|
70 | 70 | void setAlignment( Qt::Alignment alignment); |
|
71 | 71 | |
|
72 | 72 | virtual void initializeDomain(AbstractDomain *domain) = 0; |
|
73 | 73 | virtual void initializeGraphics(QGraphicsItem *parent) = 0; |
|
74 | 74 | virtual void initializeTheme(ChartTheme* theme, bool forced = false); |
|
75 | 75 | virtual void initializeAnimations(QChart::AnimationOptions options, int duration, |
|
76 | 76 | QEasingCurve &curve); |
|
77 | 77 | |
|
78 | 78 | //interface for manipulating range form base class |
|
79 | 79 | virtual void setMin(const QVariant &min) = 0; |
|
80 | 80 | virtual void setMax(const QVariant &max) = 0; |
|
81 | 81 | virtual void setRange(const QVariant &min, const QVariant &max) = 0; |
|
82 | 82 | |
|
83 | 83 | //interface manipulating range form domain |
|
84 | 84 | virtual void setRange(qreal min, qreal max) = 0; |
|
85 | 85 | virtual qreal min() = 0; |
|
86 | 86 | virtual qreal max() = 0; |
|
87 | 87 | |
|
88 | 88 | ChartAxisElement *axisItem() { return m_item.data(); } |
|
89 | 89 | |
|
90 | 90 | public Q_SLOTS: |
|
91 | 91 | void handleRangeChanged(qreal min, qreal max); |
|
92 | 92 | |
|
93 | 93 | Q_SIGNALS: |
|
94 | 94 | void rangeChanged(qreal min, qreal max); |
|
95 | 95 | |
|
96 | 96 | protected: |
|
97 | 97 | QAbstractAxis *q_ptr; |
|
98 | 98 | QChart *m_chart; |
|
99 | 99 | QScopedPointer<ChartAxisElement> m_item; |
|
100 | 100 | |
|
101 | 101 | private: |
|
102 | 102 | QList<QAbstractSeries*> m_series; |
|
103 | 103 | |
|
104 | 104 | Qt::Alignment m_alignment; |
|
105 | 105 | Qt::Orientation m_orientation; |
|
106 | 106 | |
|
107 | 107 | bool m_visible; |
|
108 | 108 | |
|
109 | 109 | bool m_arrowVisible; |
|
110 | 110 | QPen m_axisPen; |
|
111 | 111 | QBrush m_axisBrush; |
|
112 | 112 | |
|
113 | 113 | bool m_gridLineVisible; |
|
114 | 114 | QPen m_gridLinePen; |
|
115 | 115 | bool m_minorGridLineVisible; |
|
116 | 116 | QPen m_minorGridLinePen; |
|
117 | 117 | |
|
118 | 118 | bool m_labelsVisible; |
|
119 | 119 | QBrush m_labelsBrush; |
|
120 | 120 | QFont m_labelsFont; |
|
121 | 121 | int m_labelsAngle; |
|
122 | 122 | |
|
123 | 123 | bool m_titleVisible; |
|
124 | 124 | QBrush m_titleBrush; |
|
125 | 125 | QFont m_titleFont; |
|
126 | 126 | QString m_title; |
|
127 | 127 | |
|
128 | 128 | bool m_shadesVisible; |
|
129 | 129 | QPen m_shadesPen; |
|
130 | 130 | QBrush m_shadesBrush; |
|
131 | 131 | qreal m_shadesOpacity; |
|
132 | 132 | |
|
133 | 133 | bool m_dirty; |
|
134 | 134 | |
|
135 | 135 | bool m_reverse; |
|
136 | 136 | |
|
137 | 137 | friend class QAbstractAxis; |
|
138 | 138 | friend class ChartDataSet; |
|
139 | 139 | friend class ChartPresenter; |
|
140 | 140 | }; |
|
141 | 141 | |
|
142 | 142 | QT_CHARTS_END_NAMESPACE |
|
143 | 143 | |
|
144 | 144 | #endif |
@@ -1,107 +1,107 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | // W A R N I N G |
|
31 | 31 | // ------------- |
|
32 | 32 | // |
|
33 | 33 | // This file is not part of the Qt Chart API. It exists purely as an |
|
34 | 34 | // implementation detail. This header file may change from version to |
|
35 | 35 | // version without notice, or even be removed. |
|
36 | 36 | // |
|
37 | 37 | // We mean it. |
|
38 | 38 | |
|
39 | 39 | #ifndef CHARTDATASET_P_H |
|
40 | 40 | #define CHARTDATASET_P_H |
|
41 | 41 | |
|
42 | 42 | #include <QtCharts/QAbstractSeries> |
|
43 | 43 | #include <private/abstractdomain_p.h> |
|
44 | 44 | #include <private/qabstractaxis_p.h> |
|
45 | 45 | #include <QtCore/QVector> |
|
46 | 46 | |
|
47 | 47 | QT_CHARTS_BEGIN_NAMESPACE |
|
48 | 48 | |
|
49 | 49 | class QAbstractAxis; |
|
50 | 50 | class ChartPresenter; |
|
51 | 51 | class GLXYSeriesDataManager; |
|
52 | 52 | |
|
53 |
class Q |
|
|
53 | class Q_AUTOTEST_EXPORT ChartDataSet : public QObject | |
|
54 | 54 | { |
|
55 | 55 | Q_OBJECT |
|
56 | 56 | public: |
|
57 | 57 | ChartDataSet(QChart *chart); |
|
58 | 58 | virtual ~ChartDataSet(); |
|
59 | 59 | |
|
60 | 60 | void addSeries(QAbstractSeries *series); |
|
61 | 61 | void removeSeries(QAbstractSeries *series); |
|
62 | 62 | QList<QAbstractSeries *> series() const; |
|
63 | 63 | |
|
64 | 64 | void addAxis(QAbstractAxis *axis,Qt::Alignment aligment); |
|
65 | 65 | void removeAxis(QAbstractAxis *axis); |
|
66 | 66 | QList<QAbstractAxis*> axes() const; |
|
67 | 67 | |
|
68 | 68 | bool attachAxis(QAbstractSeries* series,QAbstractAxis *axis); |
|
69 | 69 | bool detachAxis(QAbstractSeries* series,QAbstractAxis *axis); |
|
70 | 70 | |
|
71 | 71 | void createDefaultAxes(); |
|
72 | 72 | |
|
73 | 73 | void zoomInDomain(const QRectF &rect); |
|
74 | 74 | void zoomOutDomain(const QRectF &rect); |
|
75 | 75 | void zoomResetDomain(); |
|
76 | 76 | bool isZoomedDomain(); |
|
77 | 77 | void scrollDomain(qreal dx, qreal dy); |
|
78 | 78 | |
|
79 | 79 | QPointF mapToValue(const QPointF &position, QAbstractSeries *series = 0); |
|
80 | 80 | QPointF mapToPosition(const QPointF &value, QAbstractSeries *series = 0); |
|
81 | 81 | |
|
82 | 82 | GLXYSeriesDataManager *glXYSeriesDataManager() { return m_glXYSeriesDataManager; } |
|
83 | 83 | |
|
84 | 84 | Q_SIGNALS: |
|
85 | 85 | void axisAdded(QAbstractAxis* axis); |
|
86 | 86 | void axisRemoved(QAbstractAxis* axis); |
|
87 | 87 | void seriesAdded(QAbstractSeries* series); |
|
88 | 88 | void seriesRemoved(QAbstractSeries* series); |
|
89 | 89 | |
|
90 | 90 | private: |
|
91 | 91 | void createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation); |
|
92 | 92 | QAbstractAxis *createAxis(QAbstractAxis::AxisType type, Qt::Orientation orientation); |
|
93 | 93 | AbstractDomain::DomainType selectDomain(QList<QAbstractAxis* > axes); |
|
94 | 94 | AbstractDomain* createDomain(AbstractDomain::DomainType type); |
|
95 | 95 | void deleteAllAxes(); |
|
96 | 96 | void deleteAllSeries(); |
|
97 | 97 | void findMinMaxForSeries(QList<QAbstractSeries *> series,Qt::Orientations orientation, qreal &min, qreal &max); |
|
98 | 98 | private: |
|
99 | 99 | QList<QAbstractSeries *> m_seriesList; |
|
100 | 100 | QList<QAbstractAxis *> m_axisList; |
|
101 | 101 | QChart* m_chart; |
|
102 | 102 | GLXYSeriesDataManager *m_glXYSeriesDataManager; |
|
103 | 103 | }; |
|
104 | 104 | |
|
105 | 105 | QT_CHARTS_END_NAMESPACE |
|
106 | 106 | |
|
107 | 107 | #endif /* CHARTENGINE_P_H */ |
@@ -1,101 +1,96 | |||
|
1 | 1 | ############################# BUILD CONFIG ###################################### |
|
2 | 2 | |
|
3 | 3 | TARGET = QtCharts |
|
4 | 4 | |
|
5 | 5 | message($$QT_CONFIG) |
|
6 | 6 | QT = core gui widgets |
|
7 | 7 | DEFINES += QT_CHARTS_LIBRARY |
|
8 | 8 | # Fix exports in static builds for applications linking charts module |
|
9 | 9 | static: MODULE_DEFINES += QT_CHARTS_STATICLIB |
|
10 | 10 | |
|
11 | 11 | MODULE_INCNAME = QtCharts |
|
12 | 12 | |
|
13 | 13 | QMAKE_DOCS = $$PWD/doc/qtcharts.qdocconf |
|
14 | 14 | |
|
15 | 15 | load(qt_module) |
|
16 | 16 | |
|
17 | 17 | QMAKE_TARGET_PRODUCT = "Qt Charts (Qt $$QT_VERSION)" |
|
18 | 18 | QMAKE_TARGET_DESCRIPTION = "Charts component for Qt." |
|
19 | 19 | |
|
20 | 20 | ############################# SOURCES ########################################## |
|
21 | 21 | |
|
22 | 22 | SOURCES += \ |
|
23 | 23 | $$PWD/chartdataset.cpp \ |
|
24 | 24 | $$PWD/chartpresenter.cpp \ |
|
25 | 25 | $$PWD/chartthememanager.cpp \ |
|
26 | 26 | $$PWD/qchart.cpp \ |
|
27 | 27 | $$PWD/qchartview.cpp \ |
|
28 | 28 | $$PWD/qabstractseries.cpp \ |
|
29 | 29 | $$PWD/chartbackground.cpp \ |
|
30 | 30 | $$PWD/chartelement.cpp \ |
|
31 | 31 | $$PWD/chartitem.cpp \ |
|
32 | 32 | $$PWD/scroller.cpp \ |
|
33 | 33 | $$PWD/charttitle.cpp \ |
|
34 | 34 | $$PWD/qpolarchart.cpp |
|
35 | 35 | |
|
36 | 36 | contains(QT_CONFIG, opengl): SOURCES += $$PWD/glwidget.cpp |
|
37 | 37 | |
|
38 | 38 | PRIVATE_HEADERS += \ |
|
39 | 39 | $$PWD/chartdataset_p.h \ |
|
40 | 40 | $$PWD/chartitem_p.h \ |
|
41 | 41 | $$PWD/chartpresenter_p.h \ |
|
42 | 42 | $$PWD/chartthememanager_p.h \ |
|
43 | 43 | $$PWD/chartbackground_p.h \ |
|
44 | 44 | $$PWD/chartelement_p.h \ |
|
45 | 45 | $$PWD/chartconfig_p.h \ |
|
46 | 46 | $$PWD/qchart_p.h \ |
|
47 | 47 | $$PWD/qchartview_p.h \ |
|
48 | 48 | $$PWD/scroller_p.h \ |
|
49 | 49 | $$PWD/qabstractseries_p.h \ |
|
50 | 50 | $$PWD/charttitle_p.h \ |
|
51 | 51 | $$PWD/charthelpers_p.h |
|
52 | 52 | |
|
53 | 53 | contains(QT_CONFIG, opengl): PRIVATE_HEADERS += $$PWD/glwidget_p.h |
|
54 | 54 | |
|
55 | 55 | PUBLIC_HEADERS += \ |
|
56 | 56 | $$PWD/qchart.h \ |
|
57 | 57 | $$PWD/qchartglobal.h \ |
|
58 | 58 | $$PWD/qabstractseries.h \ |
|
59 | 59 | $$PWD/qchartview.h \ |
|
60 | 60 | $$PWD/chartsnamespace.h \ |
|
61 | 61 | $$PWD/qpolarchart.h |
|
62 | 62 | |
|
63 | 63 | include($$PWD/common.pri) |
|
64 | 64 | include($$PWD/animations/animations.pri) |
|
65 | 65 | include($$PWD/areachart/areachart.pri) |
|
66 | 66 | include($$PWD/axis/axis.pri) |
|
67 | 67 | include($$PWD/domain/domain.pri) |
|
68 | 68 | include($$PWD/barchart/barchart.pri) |
|
69 | 69 | include($$PWD/legend/legend.pri) |
|
70 | 70 | include($$PWD/linechart/linechart.pri) |
|
71 | 71 | include($$PWD/piechart/piechart.pri) |
|
72 | 72 | include($$PWD/scatterchart/scatter.pri) |
|
73 | 73 | include($$PWD/splinechart/splinechart.pri) |
|
74 | 74 | include($$PWD/themes/themes.pri) |
|
75 | 75 | include($$PWD/xychart/xychart.pri) |
|
76 | 76 | include($$PWD/layout/layout.pri) |
|
77 | 77 | include($$PWD/boxplotchart/boxplotchart.pri) |
|
78 | 78 | |
|
79 | 79 | HEADERS += $$PUBLIC_HEADERS |
|
80 | 80 | HEADERS += $$PRIVATE_HEADERS |
|
81 | 81 | HEADERS += $$THEMES |
|
82 | 82 | |
|
83 | 83 | OTHER_FILES += doc/qtcharts.qdocconf \ |
|
84 | 84 | doc/src/* \ |
|
85 | 85 | doc/images/* |
|
86 | 86 | |
|
87 | #Define for unit tests | |
|
88 | CONFIG(debug, debug|release) { | |
|
89 | DEFINES += BUILD_PRIVATE_UNIT_TESTS | |
|
90 | } | |
|
91 | ||
|
92 | 87 | msvc { |
|
93 | 88 | # Suppress "conversion from 'size_t' to 'int', possible loss of data" warnings in 64bit |
|
94 | 89 | # builds resulting from usage of str::sort |
|
95 | 90 | QMAKE_CXXFLAGS_WARN_ON += -wd4267 |
|
96 | 91 | } |
|
97 | 92 | |
|
98 | 93 | win32:!winrt:!wince { |
|
99 | 94 | # ChartThemeSystem uses Windows native API |
|
100 | 95 | LIBS += -luser32 |
|
101 | 96 | } |
@@ -1,275 +1,275 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #include <private/abstractdomain_p.h> |
|
31 | 31 | #include <private/qabstractaxis_p.h> |
|
32 | 32 | #include <QtCore/QtMath> |
|
33 | 33 | #include <cmath> |
|
34 | 34 | |
|
35 | 35 | QT_CHARTS_BEGIN_NAMESPACE |
|
36 | 36 | |
|
37 | 37 | AbstractDomain::AbstractDomain(QObject *parent) |
|
38 | 38 | : QObject(parent), |
|
39 | 39 | m_minX(0), |
|
40 | 40 | m_maxX(0), |
|
41 | 41 | m_minY(0), |
|
42 | 42 | m_maxY(0), |
|
43 | 43 | m_signalsBlocked(false), |
|
44 | 44 | m_zoomed(false), |
|
45 | 45 | m_zoomResetMinX(0), |
|
46 | 46 | m_zoomResetMaxX(0), |
|
47 | 47 | m_zoomResetMinY(0), |
|
48 | 48 | m_zoomResetMaxY(0) |
|
49 | 49 | |
|
50 | 50 | { |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | 53 | AbstractDomain::~AbstractDomain() |
|
54 | 54 | { |
|
55 | 55 | } |
|
56 | 56 | |
|
57 | 57 | void AbstractDomain::setSize(const QSizeF &size) |
|
58 | 58 | { |
|
59 | 59 | if (m_size != size) { |
|
60 | 60 | m_size=size; |
|
61 | 61 | emit updated(); |
|
62 | 62 | } |
|
63 | 63 | } |
|
64 | 64 | |
|
65 | 65 | QSizeF AbstractDomain::size() const |
|
66 | 66 | { |
|
67 | 67 | return m_size; |
|
68 | 68 | } |
|
69 | 69 | |
|
70 | 70 | void AbstractDomain::setRangeX(qreal min, qreal max) |
|
71 | 71 | { |
|
72 | 72 | setRange(min, max, m_minY, m_maxY); |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | void AbstractDomain::setRangeY(qreal min, qreal max) |
|
76 | 76 | { |
|
77 | 77 | setRange(m_minX, m_maxX, min, max); |
|
78 | 78 | } |
|
79 | 79 | |
|
80 | 80 | void AbstractDomain::setMinX(qreal min) |
|
81 | 81 | { |
|
82 | 82 | setRange(min, m_maxX, m_minY, m_maxY); |
|
83 | 83 | } |
|
84 | 84 | |
|
85 | 85 | void AbstractDomain::setMaxX(qreal max) |
|
86 | 86 | { |
|
87 | 87 | setRange(m_minX, max, m_minY, m_maxY); |
|
88 | 88 | } |
|
89 | 89 | |
|
90 | 90 | void AbstractDomain::setMinY(qreal min) |
|
91 | 91 | { |
|
92 | 92 | setRange(m_minX, m_maxX, min, m_maxY); |
|
93 | 93 | } |
|
94 | 94 | |
|
95 | 95 | void AbstractDomain::setMaxY(qreal max) |
|
96 | 96 | { |
|
97 | 97 | setRange(m_minX, m_maxX, m_minY, max); |
|
98 | 98 | } |
|
99 | 99 | |
|
100 | 100 | qreal AbstractDomain::spanX() const |
|
101 | 101 | { |
|
102 | 102 | Q_ASSERT(m_maxX >= m_minX); |
|
103 | 103 | return m_maxX - m_minX; |
|
104 | 104 | } |
|
105 | 105 | |
|
106 | 106 | qreal AbstractDomain::spanY() const |
|
107 | 107 | { |
|
108 | 108 | Q_ASSERT(m_maxY >= m_minY); |
|
109 | 109 | return m_maxY - m_minY; |
|
110 | 110 | } |
|
111 | 111 | |
|
112 | 112 | bool AbstractDomain::isEmpty() const |
|
113 | 113 | { |
|
114 | 114 | return qFuzzyCompare(spanX(), 0) || qFuzzyCompare(spanY(), 0) || m_size.isEmpty(); |
|
115 | 115 | } |
|
116 | 116 | |
|
117 | 117 | QPointF AbstractDomain::calculateDomainPoint(const QPointF &point) const |
|
118 | 118 | { |
|
119 | 119 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); |
|
120 | 120 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); |
|
121 | 121 | qreal x = point.x() / deltaX + m_minX; |
|
122 | 122 | qreal y = (point.y() - m_size.height()) / (-deltaY) + m_minY; |
|
123 | 123 | return QPointF(x, y); |
|
124 | 124 | } |
|
125 | 125 | |
|
126 | 126 | // handlers |
|
127 | 127 | |
|
128 | 128 | void AbstractDomain::handleVerticalAxisRangeChanged(qreal min, qreal max) |
|
129 | 129 | { |
|
130 | 130 | setRangeY(min, max); |
|
131 | 131 | } |
|
132 | 132 | |
|
133 | 133 | void AbstractDomain::handleHorizontalAxisRangeChanged(qreal min, qreal max) |
|
134 | 134 | { |
|
135 | 135 | setRangeX(min, max); |
|
136 | 136 | } |
|
137 | 137 | |
|
138 | 138 | void AbstractDomain::blockRangeSignals(bool block) |
|
139 | 139 | { |
|
140 | 140 | if (m_signalsBlocked!=block) { |
|
141 | 141 | m_signalsBlocked=block; |
|
142 | 142 | if (!block) { |
|
143 | 143 | emit rangeHorizontalChanged(m_minX,m_maxX); |
|
144 | 144 | emit rangeVerticalChanged(m_minY,m_maxY); |
|
145 | 145 | } |
|
146 | 146 | } |
|
147 | 147 | } |
|
148 | 148 | |
|
149 | 149 | void AbstractDomain::zoomReset() |
|
150 | 150 | { |
|
151 | 151 | if (m_zoomed) { |
|
152 | 152 | setRange(m_zoomResetMinX, |
|
153 | 153 | m_zoomResetMaxX, |
|
154 | 154 | m_zoomResetMinY, |
|
155 | 155 | m_zoomResetMaxY); |
|
156 | 156 | m_zoomed = false; |
|
157 | 157 | } |
|
158 | 158 | } |
|
159 | 159 | |
|
160 | 160 | void AbstractDomain::storeZoomReset() |
|
161 | 161 | { |
|
162 | 162 | if (!m_zoomed) { |
|
163 | 163 | m_zoomed = true; |
|
164 | 164 | m_zoomResetMinX = m_minX; |
|
165 | 165 | m_zoomResetMaxX = m_maxX; |
|
166 | 166 | m_zoomResetMinY = m_minY; |
|
167 | 167 | m_zoomResetMaxY = m_maxY; |
|
168 | 168 | } |
|
169 | 169 | } |
|
170 | 170 | |
|
171 | 171 | //algorithm defined by Paul S.Heckbert GraphicalGems I |
|
172 | 172 | |
|
173 | 173 | void AbstractDomain::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) |
|
174 | 174 | { |
|
175 | 175 | qreal range = niceNumber(max - min, true); //range with ceiling |
|
176 | 176 | qreal step = niceNumber(range / (ticksCount - 1), false); |
|
177 | 177 | min = qFloor(min / step); |
|
178 | 178 | max = qCeil(max / step); |
|
179 | 179 | ticksCount = int(max - min) + 1; |
|
180 | 180 | min *= step; |
|
181 | 181 | max *= step; |
|
182 | 182 | } |
|
183 | 183 | |
|
184 | 184 | //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n |
|
185 | 185 | |
|
186 | 186 | qreal AbstractDomain::niceNumber(qreal x, bool ceiling) |
|
187 | 187 | { |
|
188 | 188 | qreal z = qPow(10, qFloor(std::log10(x))); //find corresponding number of the form of 10^n than is smaller than x |
|
189 | 189 | qreal q = x / z; //q<10 && q>=1; |
|
190 | 190 | |
|
191 | 191 | if (ceiling) { |
|
192 | 192 | if (q <= 1.0) q = 1; |
|
193 | 193 | else if (q <= 2.0) q = 2; |
|
194 | 194 | else if (q <= 5.0) q = 5; |
|
195 | 195 | else q = 10; |
|
196 | 196 | } else { |
|
197 | 197 | if (q < 1.5) q = 1; |
|
198 | 198 | else if (q < 3.0) q = 2; |
|
199 | 199 | else if (q < 7.0) q = 5; |
|
200 | 200 | else q = 10; |
|
201 | 201 | } |
|
202 | 202 | return q * z; |
|
203 | 203 | } |
|
204 | 204 | |
|
205 | 205 | bool AbstractDomain::attachAxis(QAbstractAxis *axis) |
|
206 | 206 | { |
|
207 | 207 | if (axis->orientation() == Qt::Vertical) { |
|
208 | 208 | QObject::connect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleVerticalAxisRangeChanged(qreal,qreal))); |
|
209 | 209 | QObject::connect(this, SIGNAL(rangeVerticalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal))); |
|
210 | 210 | } |
|
211 | 211 | |
|
212 | 212 | if (axis->orientation() == Qt::Horizontal) { |
|
213 | 213 | QObject::connect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleHorizontalAxisRangeChanged(qreal,qreal))); |
|
214 | 214 | QObject::connect(this, SIGNAL(rangeHorizontalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal))); |
|
215 | 215 | } |
|
216 | 216 | |
|
217 | 217 | return true; |
|
218 | 218 | } |
|
219 | 219 | |
|
220 | 220 | bool AbstractDomain::detachAxis(QAbstractAxis *axis) |
|
221 | 221 | { |
|
222 | 222 | if (axis->orientation() == Qt::Vertical) { |
|
223 | 223 | QObject::disconnect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleVerticalAxisRangeChanged(qreal,qreal))); |
|
224 | 224 | QObject::disconnect(this, SIGNAL(rangeVerticalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal))); |
|
225 | 225 | } |
|
226 | 226 | |
|
227 | 227 | if (axis->orientation() == Qt::Horizontal) { |
|
228 | 228 | QObject::disconnect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleHorizontalAxisRangeChanged(qreal,qreal))); |
|
229 | 229 | QObject::disconnect(this, SIGNAL(rangeHorizontalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal))); |
|
230 | 230 | } |
|
231 | 231 | |
|
232 | 232 | return true; |
|
233 | 233 | } |
|
234 | 234 | |
|
235 | 235 | // operators |
|
236 | 236 | |
|
237 |
bool Q |
|
|
237 | bool Q_AUTOTEST_EXPORT operator== (const AbstractDomain &domain1, const AbstractDomain &domain2) | |
|
238 | 238 | { |
|
239 | 239 | return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) |
|
240 | 240 | && qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) |
|
241 | 241 | && qFuzzyIsNull(domain1.m_minX - domain2.m_minX) |
|
242 | 242 | && qFuzzyIsNull(domain1.m_minY - domain2.m_minY)); |
|
243 | 243 | } |
|
244 | 244 | |
|
245 | 245 | |
|
246 |
bool Q |
|
|
246 | bool Q_AUTOTEST_EXPORT operator!= (const AbstractDomain &domain1, const AbstractDomain &domain2) | |
|
247 | 247 | { |
|
248 | 248 | return !(domain1 == domain2); |
|
249 | 249 | } |
|
250 | 250 | |
|
251 | 251 | |
|
252 |
QDebug Q |
|
|
252 | QDebug Q_AUTOTEST_EXPORT operator<<(QDebug dbg, const AbstractDomain &domain) | |
|
253 | 253 | { |
|
254 | 254 | #ifdef QT_NO_TEXTSTREAM |
|
255 | 255 | Q_UNUSED(domain) |
|
256 | 256 | #else |
|
257 | 257 | dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size; |
|
258 | 258 | #endif |
|
259 | 259 | return dbg.maybeSpace(); |
|
260 | 260 | } |
|
261 | 261 | |
|
262 | 262 | // This function adjusts min/max ranges to failsafe values if negative/zero values are attempted. |
|
263 | 263 | void AbstractDomain::adjustLogDomainRanges(qreal &min, qreal &max) |
|
264 | 264 | { |
|
265 | 265 | if (min <= 0) { |
|
266 | 266 | min = 1.0; |
|
267 | 267 | if (max <= min) |
|
268 | 268 | max = min + 1.0; |
|
269 | 269 | } |
|
270 | 270 | } |
|
271 | 271 | |
|
272 | 272 | |
|
273 | 273 | #include "moc_abstractdomain_p.cpp" |
|
274 | 274 | |
|
275 | 275 | QT_CHARTS_END_NAMESPACE |
@@ -1,141 +1,141 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | // W A R N I N G |
|
31 | 31 | // ------------- |
|
32 | 32 | // |
|
33 | 33 | // This file is not part of the Qt Chart API. It exists purely as an |
|
34 | 34 | // implementation detail. This header file may change from version to |
|
35 | 35 | // version without notice, or even be removed. |
|
36 | 36 | // |
|
37 | 37 | // We mean it. |
|
38 | 38 | |
|
39 | 39 | #ifndef ABSTRACTDOMAIN_H |
|
40 | 40 | #define ABSTRACTDOMAIN_H |
|
41 | 41 | #include <QtCharts/QChartGlobal> |
|
42 | 42 | #include <QtCore/QRectF> |
|
43 | 43 | #include <QtCore/QSizeF> |
|
44 | 44 | #include <QtCore/QDebug> |
|
45 | 45 | |
|
46 | 46 | QT_CHARTS_BEGIN_NAMESPACE |
|
47 | 47 | |
|
48 | 48 | class QAbstractAxis; |
|
49 | 49 | |
|
50 |
class Q |
|
|
50 | class Q_AUTOTEST_EXPORT AbstractDomain: public QObject | |
|
51 | 51 | { |
|
52 | 52 | Q_OBJECT |
|
53 | 53 | public: |
|
54 | 54 | enum DomainType { UndefinedDomain, |
|
55 | 55 | XYDomain, |
|
56 | 56 | XLogYDomain, |
|
57 | 57 | LogXYDomain, |
|
58 | 58 | LogXLogYDomain, |
|
59 | 59 | XYPolarDomain, |
|
60 | 60 | XLogYPolarDomain, |
|
61 | 61 | LogXYPolarDomain, |
|
62 | 62 | LogXLogYPolarDomain }; |
|
63 | 63 | public: |
|
64 | 64 | explicit AbstractDomain(QObject *object = 0); |
|
65 | 65 | virtual ~AbstractDomain(); |
|
66 | 66 | |
|
67 | 67 | virtual void setSize(const QSizeF &size); |
|
68 | 68 | QSizeF size() const; |
|
69 | 69 | |
|
70 | 70 | virtual DomainType type() = 0; |
|
71 | 71 | |
|
72 | 72 | virtual void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) = 0; |
|
73 | 73 | void setRangeX(qreal min, qreal max); |
|
74 | 74 | void setRangeY(qreal min, qreal max); |
|
75 | 75 | void setMinX(qreal min); |
|
76 | 76 | void setMaxX(qreal max); |
|
77 | 77 | void setMinY(qreal min); |
|
78 | 78 | void setMaxY(qreal max); |
|
79 | 79 | |
|
80 | 80 | qreal minX() const { return m_minX; } |
|
81 | 81 | qreal maxX() const { return m_maxX; } |
|
82 | 82 | qreal minY() const { return m_minY; } |
|
83 | 83 | qreal maxY() const { return m_maxY; } |
|
84 | 84 | |
|
85 | 85 | qreal spanX() const; |
|
86 | 86 | qreal spanY() const; |
|
87 | 87 | bool isEmpty() const; |
|
88 | 88 | |
|
89 | 89 | void blockRangeSignals(bool block); |
|
90 | 90 | bool rangeSignalsBlocked() const { return m_signalsBlocked; } |
|
91 | 91 | |
|
92 | 92 | void zoomReset(); |
|
93 | 93 | void storeZoomReset(); |
|
94 | 94 | bool isZoomed() { return m_zoomed; } |
|
95 | 95 | |
|
96 |
friend bool Q |
|
|
97 |
friend bool Q |
|
|
98 |
friend QDebug Q |
|
|
96 | friend bool Q_AUTOTEST_EXPORT operator== (const AbstractDomain &domain1, const AbstractDomain &domain2); | |
|
97 | friend bool Q_AUTOTEST_EXPORT operator!= (const AbstractDomain &domain1, const AbstractDomain &domain2); | |
|
98 | friend QDebug Q_AUTOTEST_EXPORT operator<<(QDebug dbg, const AbstractDomain &domain); | |
|
99 | 99 | |
|
100 | 100 | virtual void zoomIn(const QRectF &rect) = 0; |
|
101 | 101 | virtual void zoomOut(const QRectF &rect) = 0; |
|
102 | 102 | virtual void move(qreal dx, qreal dy) = 0; |
|
103 | 103 | |
|
104 | 104 | virtual QPointF calculateGeometryPoint(const QPointF &point, bool &ok) const = 0; |
|
105 | 105 | virtual QPointF calculateDomainPoint(const QPointF &point) const = 0; |
|
106 | 106 | virtual QVector<QPointF> calculateGeometryPoints(const QVector<QPointF> &vector) const = 0; |
|
107 | 107 | |
|
108 | 108 | virtual bool attachAxis(QAbstractAxis *axis); |
|
109 | 109 | virtual bool detachAxis(QAbstractAxis *axis); |
|
110 | 110 | |
|
111 | 111 | static void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount); |
|
112 | 112 | static qreal niceNumber(qreal x, bool ceiling); |
|
113 | 113 | |
|
114 | 114 | Q_SIGNALS: |
|
115 | 115 | void updated(); |
|
116 | 116 | void rangeHorizontalChanged(qreal min, qreal max); |
|
117 | 117 | void rangeVerticalChanged(qreal min, qreal max); |
|
118 | 118 | |
|
119 | 119 | public Q_SLOTS: |
|
120 | 120 | void handleVerticalAxisRangeChanged(qreal min,qreal max); |
|
121 | 121 | void handleHorizontalAxisRangeChanged(qreal min,qreal max); |
|
122 | 122 | |
|
123 | 123 | protected: |
|
124 | 124 | void adjustLogDomainRanges(qreal &min, qreal &max); |
|
125 | 125 | |
|
126 | 126 | qreal m_minX; |
|
127 | 127 | qreal m_maxX; |
|
128 | 128 | qreal m_minY; |
|
129 | 129 | qreal m_maxY; |
|
130 | 130 | QSizeF m_size; |
|
131 | 131 | bool m_signalsBlocked; |
|
132 | 132 | bool m_zoomed; |
|
133 | 133 | qreal m_zoomResetMinX; |
|
134 | 134 | qreal m_zoomResetMaxX; |
|
135 | 135 | qreal m_zoomResetMinY; |
|
136 | 136 | qreal m_zoomResetMaxY; |
|
137 | 137 | }; |
|
138 | 138 | |
|
139 | 139 | QT_CHARTS_END_NAMESPACE |
|
140 | 140 | |
|
141 | 141 | #endif // ABSTRACTDOMAIN_H |
@@ -1,288 +1,288 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #include <private/logxlogydomain_p.h> |
|
31 | 31 | #include <private/qabstractaxis_p.h> |
|
32 | 32 | #include <QtCharts/QLogValueAxis> |
|
33 | 33 | #include <QtCore/QtMath> |
|
34 | 34 | #include <cmath> |
|
35 | 35 | |
|
36 | 36 | QT_CHARTS_BEGIN_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | LogXLogYDomain::LogXLogYDomain(QObject *parent) |
|
39 | 39 | : AbstractDomain(parent), |
|
40 | 40 | m_logLeftX(0), |
|
41 | 41 | m_logRightX(1), |
|
42 | 42 | m_logBaseX(10), |
|
43 | 43 | m_logLeftY(0), |
|
44 | 44 | m_logRightY(1), |
|
45 | 45 | m_logBaseY(10) |
|
46 | 46 | { |
|
47 | 47 | } |
|
48 | 48 | |
|
49 | 49 | LogXLogYDomain::~LogXLogYDomain() |
|
50 | 50 | { |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | 53 | void LogXLogYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
54 | 54 | { |
|
55 | 55 | bool axisXChanged = false; |
|
56 | 56 | bool axisYChanged = false; |
|
57 | 57 | |
|
58 | 58 | adjustLogDomainRanges(minX, maxX); |
|
59 | 59 | adjustLogDomainRanges(minY, maxY); |
|
60 | 60 | |
|
61 | 61 | if (!qFuzzyIsNull(m_minX - minX) || !qFuzzyIsNull(m_maxX - maxX)) { |
|
62 | 62 | m_minX = minX; |
|
63 | 63 | m_maxX = maxX; |
|
64 | 64 | axisXChanged = true; |
|
65 | 65 | qreal logMinX = std::log10(m_minX) / std::log10(m_logBaseX); |
|
66 | 66 | qreal logMaxX = std::log10(m_maxX) / std::log10(m_logBaseX); |
|
67 | 67 | m_logLeftX = logMinX < logMaxX ? logMinX : logMaxX; |
|
68 | 68 | m_logRightX = logMinX > logMaxX ? logMinX : logMaxX; |
|
69 | 69 | if(!m_signalsBlocked) |
|
70 | 70 | emit rangeHorizontalChanged(m_minX, m_maxX); |
|
71 | 71 | } |
|
72 | 72 | |
|
73 | 73 | if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) { |
|
74 | 74 | m_minY = minY; |
|
75 | 75 | m_maxY = maxY; |
|
76 | 76 | axisYChanged = true; |
|
77 | 77 | qreal logMinY = std::log10(m_minY) / std::log10(m_logBaseY); |
|
78 | 78 | qreal logMaxY = std::log10(m_maxY) / std::log10(m_logBaseY); |
|
79 | 79 | m_logLeftY = logMinY < logMaxY ? logMinY : logMaxY; |
|
80 | 80 | m_logRightY = logMinY > logMaxY ? logMinY : logMaxY; |
|
81 | 81 | if (!m_signalsBlocked) |
|
82 | 82 | emit rangeVerticalChanged(m_minY, m_maxY); |
|
83 | 83 | } |
|
84 | 84 | |
|
85 | 85 | if (axisXChanged || axisYChanged) |
|
86 | 86 | emit updated(); |
|
87 | 87 | } |
|
88 | 88 | |
|
89 | 89 | void LogXLogYDomain::zoomIn(const QRectF &rect) |
|
90 | 90 | { |
|
91 | 91 | storeZoomReset(); |
|
92 | 92 | qreal logLeftX = rect.left() * (m_logRightX - m_logLeftX) / m_size.width() + m_logLeftX; |
|
93 | 93 | qreal logRightX = rect.right() * (m_logRightX - m_logLeftX) / m_size.width() + m_logLeftX; |
|
94 | 94 | qreal leftX = qPow(m_logBaseX, logLeftX); |
|
95 | 95 | qreal rightX = qPow(m_logBaseX, logRightX); |
|
96 | 96 | qreal minX = leftX < rightX ? leftX : rightX; |
|
97 | 97 | qreal maxX = leftX > rightX ? leftX : rightX; |
|
98 | 98 | |
|
99 | 99 | qreal logLeftY = m_logRightY - rect.bottom() * (m_logRightY - m_logLeftY) / m_size.height(); |
|
100 | 100 | qreal logRightY = m_logRightY - rect.top() * (m_logRightY - m_logLeftY) / m_size.height(); |
|
101 | 101 | qreal leftY = qPow(m_logBaseY, logLeftY); |
|
102 | 102 | qreal rightY = qPow(m_logBaseY, logRightY); |
|
103 | 103 | qreal minY = leftY < rightY ? leftY : rightY; |
|
104 | 104 | qreal maxY = leftY > rightY ? leftY : rightY; |
|
105 | 105 | |
|
106 | 106 | setRange(minX, maxX, minY, maxY); |
|
107 | 107 | } |
|
108 | 108 | |
|
109 | 109 | void LogXLogYDomain::zoomOut(const QRectF &rect) |
|
110 | 110 | { |
|
111 | 111 | storeZoomReset(); |
|
112 | 112 | const qreal factorX = m_size.width() / rect.width(); |
|
113 | 113 | const qreal factorY = m_size.height() / rect.height(); |
|
114 | 114 | |
|
115 | 115 | qreal logLeftX = m_logLeftX + (m_logRightX - m_logLeftX) / 2 * (1 - factorX); |
|
116 | 116 | qreal logRIghtX = m_logLeftX + (m_logRightX - m_logLeftX) / 2 * (1 + factorX); |
|
117 | 117 | qreal leftX = qPow(m_logBaseX, logLeftX); |
|
118 | 118 | qreal rightX = qPow(m_logBaseX, logRIghtX); |
|
119 | 119 | qreal minX = leftX < rightX ? leftX : rightX; |
|
120 | 120 | qreal maxX = leftX > rightX ? leftX : rightX; |
|
121 | 121 | |
|
122 | 122 | qreal newLogMinY = m_logLeftY + (m_logRightY - m_logLeftY) / 2 * (1 - factorY); |
|
123 | 123 | qreal newLogMaxY = m_logLeftY + (m_logRightY - m_logLeftY) / 2 * (1 + factorY); |
|
124 | 124 | qreal leftY = qPow(m_logBaseY, newLogMinY); |
|
125 | 125 | qreal rightY = qPow(m_logBaseY, newLogMaxY); |
|
126 | 126 | qreal minY = leftY < rightY ? leftY : rightY; |
|
127 | 127 | qreal maxY = leftY > rightY ? leftY : rightY; |
|
128 | 128 | |
|
129 | 129 | setRange(minX, maxX, minY, maxY); |
|
130 | 130 | } |
|
131 | 131 | |
|
132 | 132 | void LogXLogYDomain::move(qreal dx, qreal dy) |
|
133 | 133 | { |
|
134 | 134 | qreal stepX = dx * qAbs(m_logRightX - m_logLeftX) / m_size.width(); |
|
135 | 135 | qreal leftX = qPow(m_logBaseX, m_logLeftX + stepX); |
|
136 | 136 | qreal rightX = qPow(m_logBaseX, m_logRightX + stepX); |
|
137 | 137 | qreal minX = leftX < rightX ? leftX : rightX; |
|
138 | 138 | qreal maxX = leftX > rightX ? leftX : rightX; |
|
139 | 139 | |
|
140 | 140 | qreal stepY = dy * (m_logRightY - m_logLeftY) / m_size.height(); |
|
141 | 141 | qreal leftY = qPow(m_logBaseY, m_logLeftY + stepY); |
|
142 | 142 | qreal rightY = qPow(m_logBaseY, m_logRightY + stepY); |
|
143 | 143 | qreal minY = leftY < rightY ? leftY : rightY; |
|
144 | 144 | qreal maxY = leftY > rightY ? leftY : rightY; |
|
145 | 145 | |
|
146 | 146 | setRange(minX, maxX, minY, maxY); |
|
147 | 147 | } |
|
148 | 148 | |
|
149 | 149 | QPointF LogXLogYDomain::calculateGeometryPoint(const QPointF &point, bool &ok) const |
|
150 | 150 | { |
|
151 | 151 | const qreal deltaX = m_size.width() / qAbs(m_logRightX - m_logLeftX); |
|
152 | 152 | const qreal deltaY = m_size.height() / qAbs(m_logRightY - m_logLeftY); |
|
153 | 153 | qreal x(0); |
|
154 | 154 | qreal y(0); |
|
155 | 155 | if (point.x() > 0 && point.y() > 0) { |
|
156 | 156 | x = (std::log10(point.x()) / std::log10(m_logBaseX)) * deltaX - m_logLeftX * deltaX; |
|
157 | 157 | y = (std::log10(point.y()) / std::log10(m_logBaseY)) * -deltaY - m_logLeftY * -deltaY + m_size.height(); |
|
158 | 158 | ok = true; |
|
159 | 159 | } else { |
|
160 | 160 | qWarning() << "Logarithms of zero and negative values are undefined."; |
|
161 | 161 | ok = false; |
|
162 | 162 | if (point.x() > 0) |
|
163 | 163 | x = (std::log10(point.x()) / std::log10(m_logBaseX)) * deltaX - m_logLeftX * deltaX; |
|
164 | 164 | else |
|
165 | 165 | x = 0; |
|
166 | 166 | if (point.y() > 0) { |
|
167 | 167 | y = (std::log10(point.y()) / std::log10(m_logBaseY)) * -deltaY - m_logLeftY * -deltaY |
|
168 | 168 | + m_size.height(); |
|
169 | 169 | } else { |
|
170 | 170 | y = m_size.height(); |
|
171 | 171 | } |
|
172 | 172 | } |
|
173 | 173 | return QPointF(x, y); |
|
174 | 174 | } |
|
175 | 175 | |
|
176 | 176 | QVector<QPointF> LogXLogYDomain::calculateGeometryPoints(const QVector<QPointF> &vector) const |
|
177 | 177 | { |
|
178 | 178 | const qreal deltaX = m_size.width() / qAbs(m_logRightX - m_logLeftX); |
|
179 | 179 | const qreal deltaY = m_size.height() / qAbs(m_logRightY - m_logLeftY); |
|
180 | 180 | |
|
181 | 181 | QVector<QPointF> result; |
|
182 | 182 | result.resize(vector.count()); |
|
183 | 183 | |
|
184 | 184 | for (int i = 0; i < vector.count(); ++i) { |
|
185 | 185 | if (vector[i].x() > 0 && vector[i].y() > 0) { |
|
186 | 186 | qreal x = (std::log10(vector[i].x()) / std::log10(m_logBaseX)) * deltaX - m_logLeftX * deltaX; |
|
187 | 187 | qreal y = (std::log10(vector[i].y()) / std::log10(m_logBaseY)) * -deltaY - m_logLeftY * -deltaY + m_size.height(); |
|
188 | 188 | result[i].setX(x); |
|
189 | 189 | result[i].setY(y); |
|
190 | 190 | } else { |
|
191 | 191 | qWarning() << "Logarithms of zero and negative values are undefined."; |
|
192 | 192 | return QVector<QPointF>(); |
|
193 | 193 | } |
|
194 | 194 | } |
|
195 | 195 | return result; |
|
196 | 196 | } |
|
197 | 197 | |
|
198 | 198 | QPointF LogXLogYDomain::calculateDomainPoint(const QPointF &point) const |
|
199 | 199 | { |
|
200 | 200 | const qreal deltaX = m_size.width() / qAbs(m_logRightX - m_logLeftX); |
|
201 | 201 | const qreal deltaY = m_size.height() / qAbs(m_logRightY - m_logLeftY); |
|
202 | 202 | qreal x = qPow(m_logBaseX, m_logLeftX + point.x() / deltaX); |
|
203 | 203 | qreal y = qPow(m_logBaseY, m_logLeftY + (m_size.height() - point.y()) / deltaY); |
|
204 | 204 | return QPointF(x, y); |
|
205 | 205 | } |
|
206 | 206 | |
|
207 | 207 | bool LogXLogYDomain::attachAxis(QAbstractAxis *axis) |
|
208 | 208 | { |
|
209 | 209 | AbstractDomain::attachAxis(axis); |
|
210 | 210 | QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis); |
|
211 | 211 | |
|
212 | 212 | if (logAxis && logAxis->orientation() == Qt::Vertical) { |
|
213 | 213 | QObject::connect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleVerticalAxisBaseChanged(qreal))); |
|
214 | 214 | handleVerticalAxisBaseChanged(logAxis->base()); |
|
215 | 215 | } |
|
216 | 216 | |
|
217 | 217 | if (logAxis && logAxis->orientation() == Qt::Horizontal) { |
|
218 | 218 | QObject::connect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleHorizontalAxisBaseChanged(qreal))); |
|
219 | 219 | handleHorizontalAxisBaseChanged(logAxis->base()); |
|
220 | 220 | } |
|
221 | 221 | |
|
222 | 222 | return true; |
|
223 | 223 | } |
|
224 | 224 | |
|
225 | 225 | bool LogXLogYDomain::detachAxis(QAbstractAxis *axis) |
|
226 | 226 | { |
|
227 | 227 | AbstractDomain::detachAxis(axis); |
|
228 | 228 | QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis); |
|
229 | 229 | |
|
230 | 230 | if (logAxis && logAxis->orientation() == Qt::Vertical) |
|
231 | 231 | QObject::disconnect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleVerticalAxisBaseChanged(qreal))); |
|
232 | 232 | |
|
233 | 233 | if (logAxis && logAxis->orientation() == Qt::Horizontal) |
|
234 | 234 | QObject::disconnect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleHorizontalAxisBaseChanged(qreal))); |
|
235 | 235 | |
|
236 | 236 | return true; |
|
237 | 237 | } |
|
238 | 238 | |
|
239 | 239 | void LogXLogYDomain::handleVerticalAxisBaseChanged(qreal baseY) |
|
240 | 240 | { |
|
241 | 241 | m_logBaseY = baseY; |
|
242 | 242 | qreal logMinY = std::log10(m_minY) / std::log10(m_logBaseY); |
|
243 | 243 | qreal logMaxY = std::log10(m_maxY) / std::log10(m_logBaseY); |
|
244 | 244 | m_logLeftY = logMinY < logMaxY ? logMinY : logMaxY; |
|
245 | 245 | m_logRightY = logMinY > logMaxY ? logMinY : logMaxY; |
|
246 | 246 | emit updated(); |
|
247 | 247 | } |
|
248 | 248 | |
|
249 | 249 | void LogXLogYDomain::handleHorizontalAxisBaseChanged(qreal baseX) |
|
250 | 250 | { |
|
251 | 251 | m_logBaseX = baseX; |
|
252 | 252 | qreal logMinX = std::log10(m_minX) / std::log10(m_logBaseX); |
|
253 | 253 | qreal logMaxX = std::log10(m_maxX) / std::log10(m_logBaseX); |
|
254 | 254 | m_logLeftX = logMinX < logMaxX ? logMinX : logMaxX; |
|
255 | 255 | m_logRightX = logMinX > logMaxX ? logMinX : logMaxX; |
|
256 | 256 | emit updated(); |
|
257 | 257 | } |
|
258 | 258 | |
|
259 | 259 | // operators |
|
260 | 260 | |
|
261 |
bool Q |
|
|
261 | bool Q_AUTOTEST_EXPORT operator== (const LogXLogYDomain &domain1, const LogXLogYDomain &domain2) | |
|
262 | 262 | { |
|
263 | 263 | return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) |
|
264 | 264 | && qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) |
|
265 | 265 | && qFuzzyIsNull(domain1.m_minX - domain2.m_minX) |
|
266 | 266 | && qFuzzyIsNull(domain1.m_minY - domain2.m_minY)); |
|
267 | 267 | } |
|
268 | 268 | |
|
269 | 269 | |
|
270 |
bool Q |
|
|
270 | bool Q_AUTOTEST_EXPORT operator!= (const LogXLogYDomain &domain1, const LogXLogYDomain &domain2) | |
|
271 | 271 | { |
|
272 | 272 | return !(domain1 == domain2); |
|
273 | 273 | } |
|
274 | 274 | |
|
275 | 275 | |
|
276 |
QDebug Q |
|
|
276 | QDebug Q_AUTOTEST_EXPORT operator<<(QDebug dbg, const LogXLogYDomain &domain) | |
|
277 | 277 | { |
|
278 | 278 | #ifdef QT_NO_TEXTSTREAM |
|
279 | 279 | Q_UNUSED(domain) |
|
280 | 280 | #else |
|
281 | 281 | dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size; |
|
282 | 282 | #endif |
|
283 | 283 | return dbg.maybeSpace(); |
|
284 | 284 | } |
|
285 | 285 | |
|
286 | 286 | #include "moc_logxlogydomain_p.cpp" |
|
287 | 287 | |
|
288 | 288 | QT_CHARTS_END_NAMESPACE |
@@ -1,88 +1,88 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | // W A R N I N G |
|
31 | 31 | // ------------- |
|
32 | 32 | // |
|
33 | 33 | // This file is not part of the Qt Chart API. It exists purely as an |
|
34 | 34 | // implementation detail. This header file may change from version to |
|
35 | 35 | // version without notice, or even be removed. |
|
36 | 36 | // |
|
37 | 37 | // We mean it. |
|
38 | 38 | |
|
39 | 39 | #ifndef LOGXLOGYDOMAIN_H |
|
40 | 40 | #define LOGXLOGYDOMAIN_H |
|
41 | 41 | #include <private/abstractdomain_p.h> |
|
42 | 42 | #include <QtCore/QRectF> |
|
43 | 43 | #include <QtCore/QSizeF> |
|
44 | 44 | |
|
45 | 45 | QT_CHARTS_BEGIN_NAMESPACE |
|
46 | 46 | |
|
47 |
class Q |
|
|
47 | class Q_AUTOTEST_EXPORT LogXLogYDomain: public AbstractDomain | |
|
48 | 48 | { |
|
49 | 49 | Q_OBJECT |
|
50 | 50 | public: |
|
51 | 51 | explicit LogXLogYDomain(QObject *object = 0); |
|
52 | 52 | virtual ~LogXLogYDomain(); |
|
53 | 53 | |
|
54 | 54 | DomainType type(){ return AbstractDomain::LogXLogYDomain;} |
|
55 | 55 | |
|
56 | 56 | void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
57 | 57 | |
|
58 |
friend bool Q |
|
|
59 |
friend bool Q |
|
|
60 |
friend QDebug Q |
|
|
58 | friend bool Q_AUTOTEST_EXPORT operator== (const LogXLogYDomain &domain1, const LogXLogYDomain &domain2); | |
|
59 | friend bool Q_AUTOTEST_EXPORT operator!= (const LogXLogYDomain &domain1, const LogXLogYDomain &domain2); | |
|
60 | friend QDebug Q_AUTOTEST_EXPORT operator<<(QDebug dbg, const LogXLogYDomain &domain); | |
|
61 | 61 | |
|
62 | 62 | void zoomIn(const QRectF &rect); |
|
63 | 63 | void zoomOut(const QRectF &rect); |
|
64 | 64 | void move(qreal dx, qreal dy); |
|
65 | 65 | |
|
66 | 66 | QPointF calculateGeometryPoint(const QPointF &point, bool &ok) const; |
|
67 | 67 | QPointF calculateDomainPoint(const QPointF &point) const; |
|
68 | 68 | QVector<QPointF> calculateGeometryPoints(const QVector<QPointF> &vector) const; |
|
69 | 69 | |
|
70 | 70 | bool attachAxis(QAbstractAxis *axis); |
|
71 | 71 | bool detachAxis(QAbstractAxis *axis); |
|
72 | 72 | |
|
73 | 73 | public Q_SLOTS: |
|
74 | 74 | void handleVerticalAxisBaseChanged(qreal baseY); |
|
75 | 75 | void handleHorizontalAxisBaseChanged(qreal baseX); |
|
76 | 76 | |
|
77 | 77 | private: |
|
78 | 78 | qreal m_logLeftX; |
|
79 | 79 | qreal m_logRightX; |
|
80 | 80 | qreal m_logBaseX; |
|
81 | 81 | qreal m_logLeftY; |
|
82 | 82 | qreal m_logRightY; |
|
83 | 83 | qreal m_logBaseY; |
|
84 | 84 | }; |
|
85 | 85 | |
|
86 | 86 | QT_CHARTS_END_NAMESPACE |
|
87 | 87 | |
|
88 | 88 | #endif // LOGXLOGYDOMAIN_H |
@@ -1,283 +1,283 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #include <private/logxlogypolardomain_p.h> |
|
31 | 31 | #include <private/qabstractaxis_p.h> |
|
32 | 32 | #include <QtCharts/QLogValueAxis> |
|
33 | 33 | #include <QtCore/QtMath> |
|
34 | 34 | #include <cmath> |
|
35 | 35 | |
|
36 | 36 | QT_CHARTS_BEGIN_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | LogXLogYPolarDomain::LogXLogYPolarDomain(QObject *parent) |
|
39 | 39 | : PolarDomain(parent), |
|
40 | 40 | m_logLeftX(0), |
|
41 | 41 | m_logRightX(1), |
|
42 | 42 | m_logBaseX(10), |
|
43 | 43 | m_logInnerY(0), |
|
44 | 44 | m_logOuterY(1), |
|
45 | 45 | m_logBaseY(10) |
|
46 | 46 | { |
|
47 | 47 | } |
|
48 | 48 | |
|
49 | 49 | LogXLogYPolarDomain::~LogXLogYPolarDomain() |
|
50 | 50 | { |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | 53 | void LogXLogYPolarDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
54 | 54 | { |
|
55 | 55 | bool axisXChanged = false; |
|
56 | 56 | bool axisYChanged = false; |
|
57 | 57 | |
|
58 | 58 | adjustLogDomainRanges(minX, maxX); |
|
59 | 59 | adjustLogDomainRanges(minY, maxY); |
|
60 | 60 | |
|
61 | 61 | if (!qFuzzyCompare(m_minX, minX) || !qFuzzyCompare(m_maxX, maxX)) { |
|
62 | 62 | m_minX = minX; |
|
63 | 63 | m_maxX = maxX; |
|
64 | 64 | axisXChanged = true; |
|
65 | 65 | qreal logMinX = std::log10(m_minX) / std::log10(m_logBaseX); |
|
66 | 66 | qreal logMaxX = std::log10(m_maxX) / std::log10(m_logBaseX); |
|
67 | 67 | m_logLeftX = logMinX < logMaxX ? logMinX : logMaxX; |
|
68 | 68 | m_logRightX = logMinX > logMaxX ? logMinX : logMaxX; |
|
69 | 69 | if (!m_signalsBlocked) |
|
70 | 70 | emit rangeHorizontalChanged(m_minX, m_maxX); |
|
71 | 71 | } |
|
72 | 72 | |
|
73 | 73 | if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) { |
|
74 | 74 | m_minY = minY; |
|
75 | 75 | m_maxY = maxY; |
|
76 | 76 | axisYChanged = true; |
|
77 | 77 | qreal logMinY = std::log10(m_minY) / std::log10(m_logBaseY); |
|
78 | 78 | qreal logMaxY = std::log10(m_maxY) / std::log10(m_logBaseY); |
|
79 | 79 | m_logInnerY = logMinY < logMaxY ? logMinY : logMaxY; |
|
80 | 80 | m_logOuterY = logMinY > logMaxY ? logMinY : logMaxY; |
|
81 | 81 | if (!m_signalsBlocked) |
|
82 | 82 | emit rangeVerticalChanged(m_minY, m_maxY); |
|
83 | 83 | } |
|
84 | 84 | |
|
85 | 85 | if (axisXChanged || axisYChanged) |
|
86 | 86 | emit updated(); |
|
87 | 87 | } |
|
88 | 88 | |
|
89 | 89 | void LogXLogYPolarDomain::zoomIn(const QRectF &rect) |
|
90 | 90 | { |
|
91 | 91 | storeZoomReset(); |
|
92 | 92 | qreal logLeftX = rect.left() * (m_logRightX - m_logLeftX) / m_size.width() + m_logLeftX; |
|
93 | 93 | qreal logRightX = rect.right() * (m_logRightX - m_logLeftX) / m_size.width() + m_logLeftX; |
|
94 | 94 | qreal leftX = qPow(m_logBaseX, logLeftX); |
|
95 | 95 | qreal rightX = qPow(m_logBaseX, logRightX); |
|
96 | 96 | qreal minX = leftX < rightX ? leftX : rightX; |
|
97 | 97 | qreal maxX = leftX > rightX ? leftX : rightX; |
|
98 | 98 | |
|
99 | 99 | qreal logLeftY = m_logOuterY - rect.bottom() * (m_logOuterY - m_logInnerY) / m_size.height(); |
|
100 | 100 | qreal logRightY = m_logOuterY - rect.top() * (m_logOuterY - m_logInnerY) / m_size.height(); |
|
101 | 101 | qreal leftY = qPow(m_logBaseY, logLeftY); |
|
102 | 102 | qreal rightY = qPow(m_logBaseY, logRightY); |
|
103 | 103 | qreal minY = leftY < rightY ? leftY : rightY; |
|
104 | 104 | qreal maxY = leftY > rightY ? leftY : rightY; |
|
105 | 105 | |
|
106 | 106 | setRange(minX, maxX, minY, maxY); |
|
107 | 107 | } |
|
108 | 108 | |
|
109 | 109 | void LogXLogYPolarDomain::zoomOut(const QRectF &rect) |
|
110 | 110 | { |
|
111 | 111 | storeZoomReset(); |
|
112 | 112 | const qreal factorX = m_size.width() / rect.width(); |
|
113 | 113 | |
|
114 | 114 | qreal logLeftX = m_logLeftX + (m_logRightX - m_logLeftX) / 2.0 * (1.0 - factorX); |
|
115 | 115 | qreal logRIghtX = m_logLeftX + (m_logRightX - m_logLeftX) / 2.0 * (1.0 + factorX); |
|
116 | 116 | qreal leftX = qPow(m_logBaseX, logLeftX); |
|
117 | 117 | qreal rightX = qPow(m_logBaseX, logRIghtX); |
|
118 | 118 | qreal minX = leftX < rightX ? leftX : rightX; |
|
119 | 119 | qreal maxX = leftX > rightX ? leftX : rightX; |
|
120 | 120 | |
|
121 | 121 | const qreal factorY = m_size.height() / rect.height(); |
|
122 | 122 | qreal newLogMinY = m_logInnerY + (m_logOuterY - m_logInnerY) / 2.0 * (1.0 - factorY); |
|
123 | 123 | qreal newLogMaxY = m_logInnerY + (m_logOuterY - m_logInnerY) / 2.0 * (1.0 + factorY); |
|
124 | 124 | qreal leftY = qPow(m_logBaseY, newLogMinY); |
|
125 | 125 | qreal rightY = qPow(m_logBaseY, newLogMaxY); |
|
126 | 126 | qreal minY = leftY < rightY ? leftY : rightY; |
|
127 | 127 | qreal maxY = leftY > rightY ? leftY : rightY; |
|
128 | 128 | |
|
129 | 129 | setRange(minX, maxX, minY, maxY); |
|
130 | 130 | } |
|
131 | 131 | |
|
132 | 132 | void LogXLogYPolarDomain::move(qreal dx, qreal dy) |
|
133 | 133 | { |
|
134 | 134 | qreal stepX = dx * (m_logRightX - m_logLeftX) / m_size.width(); |
|
135 | 135 | qreal leftX = qPow(m_logBaseX, m_logLeftX + stepX); |
|
136 | 136 | qreal rightX = qPow(m_logBaseX, m_logRightX + stepX); |
|
137 | 137 | qreal minX = leftX < rightX ? leftX : rightX; |
|
138 | 138 | qreal maxX = leftX > rightX ? leftX : rightX; |
|
139 | 139 | |
|
140 | 140 | qreal stepY = dy * (m_logOuterY - m_logInnerY) / m_radius; |
|
141 | 141 | qreal leftY = qPow(m_logBaseY, m_logInnerY + stepY); |
|
142 | 142 | qreal rightY = qPow(m_logBaseY, m_logOuterY + stepY); |
|
143 | 143 | qreal minY = leftY < rightY ? leftY : rightY; |
|
144 | 144 | qreal maxY = leftY > rightY ? leftY : rightY; |
|
145 | 145 | |
|
146 | 146 | setRange(minX, maxX, minY, maxY); |
|
147 | 147 | } |
|
148 | 148 | |
|
149 | 149 | qreal LogXLogYPolarDomain::toAngularCoordinate(qreal value, bool &ok) const |
|
150 | 150 | { |
|
151 | 151 | qreal retVal; |
|
152 | 152 | if (value <= 0) { |
|
153 | 153 | ok = false; |
|
154 | 154 | retVal = 0.0; |
|
155 | 155 | } else { |
|
156 | 156 | ok = true; |
|
157 | 157 | const qreal tickSpan = 360.0 / qAbs(m_logRightX - m_logLeftX); |
|
158 | 158 | const qreal logValue = std::log10(value) / std::log10(m_logBaseX); |
|
159 | 159 | const qreal valueDelta = logValue - m_logLeftX; |
|
160 | 160 | |
|
161 | 161 | retVal = valueDelta * tickSpan; |
|
162 | 162 | } |
|
163 | 163 | return retVal; |
|
164 | 164 | } |
|
165 | 165 | |
|
166 | 166 | qreal LogXLogYPolarDomain::toRadialCoordinate(qreal value, bool &ok) const |
|
167 | 167 | { |
|
168 | 168 | qreal retVal; |
|
169 | 169 | if (value <= 0) { |
|
170 | 170 | ok = false; |
|
171 | 171 | retVal = 0.0; |
|
172 | 172 | } else { |
|
173 | 173 | ok = true; |
|
174 | 174 | const qreal tickSpan = m_radius / qAbs(m_logOuterY - m_logInnerY); |
|
175 | 175 | const qreal logValue = std::log10(value) / std::log10(m_logBaseY); |
|
176 | 176 | const qreal valueDelta = logValue - m_logInnerY; |
|
177 | 177 | |
|
178 | 178 | retVal = valueDelta * tickSpan; |
|
179 | 179 | |
|
180 | 180 | if (retVal < 0.0) |
|
181 | 181 | retVal = 0.0; |
|
182 | 182 | } |
|
183 | 183 | return retVal; |
|
184 | 184 | } |
|
185 | 185 | |
|
186 | 186 | QPointF LogXLogYPolarDomain::calculateDomainPoint(const QPointF &point) const |
|
187 | 187 | { |
|
188 | 188 | if (point == m_center) |
|
189 | 189 | return QPointF(0.0, m_minY); |
|
190 | 190 | |
|
191 | 191 | QLineF line(m_center, point); |
|
192 | 192 | qreal a = 90.0 - line.angle(); |
|
193 | 193 | if (a < 0.0) |
|
194 | 194 | a += 360.0; |
|
195 | 195 | |
|
196 | 196 | const qreal deltaX = 360.0 / qAbs(m_logRightX - m_logLeftX); |
|
197 | 197 | a = qPow(m_logBaseX, m_logLeftX + (a / deltaX)); |
|
198 | 198 | |
|
199 | 199 | const qreal deltaY = m_radius / qAbs(m_logOuterY - m_logInnerY); |
|
200 | 200 | qreal r = qPow(m_logBaseY, m_logInnerY + (line.length() / deltaY)); |
|
201 | 201 | |
|
202 | 202 | return QPointF(a, r); |
|
203 | 203 | } |
|
204 | 204 | |
|
205 | 205 | bool LogXLogYPolarDomain::attachAxis(QAbstractAxis *axis) |
|
206 | 206 | { |
|
207 | 207 | AbstractDomain::attachAxis(axis); |
|
208 | 208 | QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis); |
|
209 | 209 | |
|
210 | 210 | if (logAxis && logAxis->orientation() == Qt::Horizontal) { |
|
211 | 211 | QObject::connect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleHorizontalAxisBaseChanged(qreal))); |
|
212 | 212 | handleHorizontalAxisBaseChanged(logAxis->base()); |
|
213 | 213 | } else if (logAxis && logAxis->orientation() == Qt::Vertical){ |
|
214 | 214 | QObject::connect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleVerticalAxisBaseChanged(qreal))); |
|
215 | 215 | handleVerticalAxisBaseChanged(logAxis->base()); |
|
216 | 216 | } |
|
217 | 217 | |
|
218 | 218 | return true; |
|
219 | 219 | } |
|
220 | 220 | |
|
221 | 221 | bool LogXLogYPolarDomain::detachAxis(QAbstractAxis *axis) |
|
222 | 222 | { |
|
223 | 223 | AbstractDomain::detachAxis(axis); |
|
224 | 224 | QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis); |
|
225 | 225 | |
|
226 | 226 | if (logAxis && logAxis->orientation() == Qt::Horizontal) |
|
227 | 227 | QObject::disconnect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleHorizontalAxisBaseChanged(qreal))); |
|
228 | 228 | else if (logAxis && logAxis->orientation() == Qt::Vertical) |
|
229 | 229 | QObject::disconnect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleVerticalAxisBaseChanged(qreal))); |
|
230 | 230 | |
|
231 | 231 | return true; |
|
232 | 232 | } |
|
233 | 233 | |
|
234 | 234 | void LogXLogYPolarDomain::handleHorizontalAxisBaseChanged(qreal baseX) |
|
235 | 235 | { |
|
236 | 236 | m_logBaseX = baseX; |
|
237 | 237 | qreal logMinX = std::log10(m_minX) / std::log10(m_logBaseX); |
|
238 | 238 | qreal logMaxX = std::log10(m_maxX) / std::log10(m_logBaseX); |
|
239 | 239 | m_logLeftX = logMinX < logMaxX ? logMinX : logMaxX; |
|
240 | 240 | m_logRightX = logMinX > logMaxX ? logMinX : logMaxX; |
|
241 | 241 | emit updated(); |
|
242 | 242 | } |
|
243 | 243 | |
|
244 | 244 | void LogXLogYPolarDomain::handleVerticalAxisBaseChanged(qreal baseY) |
|
245 | 245 | { |
|
246 | 246 | m_logBaseY = baseY; |
|
247 | 247 | qreal logMinY = std::log10(m_minY) / std::log10(m_logBaseY); |
|
248 | 248 | qreal logMaxY = std::log10(m_maxY) / std::log10(m_logBaseY); |
|
249 | 249 | m_logInnerY = logMinY < logMaxY ? logMinY : logMaxY; |
|
250 | 250 | m_logOuterY = logMinY > logMaxY ? logMinY : logMaxY; |
|
251 | 251 | emit updated(); |
|
252 | 252 | } |
|
253 | 253 | |
|
254 | 254 | // operators |
|
255 | 255 | |
|
256 |
bool Q |
|
|
256 | bool Q_AUTOTEST_EXPORT operator== (const LogXLogYPolarDomain &domain1, const LogXLogYPolarDomain &domain2) | |
|
257 | 257 | { |
|
258 | 258 | return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) |
|
259 | 259 | && qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) |
|
260 | 260 | && qFuzzyIsNull(domain1.m_minX - domain2.m_minX) |
|
261 | 261 | && qFuzzyIsNull(domain1.m_minY - domain2.m_minY)); |
|
262 | 262 | } |
|
263 | 263 | |
|
264 | 264 | |
|
265 |
bool Q |
|
|
265 | bool Q_AUTOTEST_EXPORT operator!= (const LogXLogYPolarDomain &domain1, const LogXLogYPolarDomain &domain2) | |
|
266 | 266 | { |
|
267 | 267 | return !(domain1 == domain2); |
|
268 | 268 | } |
|
269 | 269 | |
|
270 | 270 | |
|
271 |
QDebug Q |
|
|
271 | QDebug Q_AUTOTEST_EXPORT operator<<(QDebug dbg, const LogXLogYPolarDomain &domain) | |
|
272 | 272 | { |
|
273 | 273 | #ifdef QT_NO_TEXTSTREAM |
|
274 | 274 | Q_UNUSED(domain) |
|
275 | 275 | #else |
|
276 | 276 | dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size; |
|
277 | 277 | #endif |
|
278 | 278 | return dbg.maybeSpace(); |
|
279 | 279 | } |
|
280 | 280 | |
|
281 | 281 | #include "moc_logxlogypolardomain_p.cpp" |
|
282 | 282 | |
|
283 | 283 | QT_CHARTS_END_NAMESPACE |
@@ -1,90 +1,90 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | // W A R N I N G |
|
31 | 31 | // ------------- |
|
32 | 32 | // |
|
33 | 33 | // This file is not part of the Qt Chart API. It exists purely as an |
|
34 | 34 | // implementation detail. This header file may change from version to |
|
35 | 35 | // version without notice, or even be removed. |
|
36 | 36 | // |
|
37 | 37 | // We mean it. |
|
38 | 38 | |
|
39 | 39 | #ifndef LOGXLOGYPOLARDOMAIN_H |
|
40 | 40 | #define LOGXLOGYPOLARDOMAIN_H |
|
41 | 41 | #include <private/polardomain_p.h> |
|
42 | 42 | #include <QtCore/QRectF> |
|
43 | 43 | #include <QtCore/QSizeF> |
|
44 | 44 | |
|
45 | 45 | QT_CHARTS_BEGIN_NAMESPACE |
|
46 | 46 | |
|
47 |
class Q |
|
|
47 | class Q_AUTOTEST_EXPORT LogXLogYPolarDomain: public PolarDomain | |
|
48 | 48 | { |
|
49 | 49 | Q_OBJECT |
|
50 | 50 | public: |
|
51 | 51 | explicit LogXLogYPolarDomain(QObject *object = 0); |
|
52 | 52 | virtual ~LogXLogYPolarDomain(); |
|
53 | 53 | |
|
54 | 54 | DomainType type() { return AbstractDomain::LogXLogYPolarDomain; } |
|
55 | 55 | |
|
56 | 56 | void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
57 | 57 | |
|
58 |
friend bool Q |
|
|
59 |
friend bool Q |
|
|
60 |
friend QDebug Q |
|
|
58 | friend bool Q_AUTOTEST_EXPORT operator== (const LogXLogYPolarDomain &domain1, const LogXLogYPolarDomain &domain2); | |
|
59 | friend bool Q_AUTOTEST_EXPORT operator!= (const LogXLogYPolarDomain &domain1, const LogXLogYPolarDomain &domain2); | |
|
60 | friend QDebug Q_AUTOTEST_EXPORT operator<<(QDebug dbg, const LogXLogYPolarDomain &domain); | |
|
61 | 61 | |
|
62 | 62 | void zoomIn(const QRectF &rect); |
|
63 | 63 | void zoomOut(const QRectF &rect); |
|
64 | 64 | void move(qreal dx, qreal dy); |
|
65 | 65 | |
|
66 | 66 | QPointF calculateDomainPoint(const QPointF &point) const; |
|
67 | 67 | |
|
68 | 68 | bool attachAxis(QAbstractAxis *axis); |
|
69 | 69 | bool detachAxis(QAbstractAxis *axis); |
|
70 | 70 | |
|
71 | 71 | public Q_SLOTS: |
|
72 | 72 | void handleVerticalAxisBaseChanged(qreal baseY); |
|
73 | 73 | void handleHorizontalAxisBaseChanged(qreal baseX); |
|
74 | 74 | |
|
75 | 75 | protected: |
|
76 | 76 | qreal toAngularCoordinate(qreal value, bool &ok) const; |
|
77 | 77 | qreal toRadialCoordinate(qreal value, bool &ok) const; |
|
78 | 78 | |
|
79 | 79 | private: |
|
80 | 80 | qreal m_logLeftX; |
|
81 | 81 | qreal m_logRightX; |
|
82 | 82 | qreal m_logBaseX; |
|
83 | 83 | qreal m_logInnerY; |
|
84 | 84 | qreal m_logOuterY; |
|
85 | 85 | qreal m_logBaseY; |
|
86 | 86 | }; |
|
87 | 87 | |
|
88 | 88 | QT_CHARTS_END_NAMESPACE |
|
89 | 89 | |
|
90 | 90 | #endif // LOGXLOGYPOLARDOMAIN_H |
@@ -1,255 +1,255 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #include <private/logxydomain_p.h> |
|
31 | 31 | #include <private/qabstractaxis_p.h> |
|
32 | 32 | #include <QtCharts/QLogValueAxis> |
|
33 | 33 | #include <QtCore/QtMath> |
|
34 | 34 | #include <cmath> |
|
35 | 35 | |
|
36 | 36 | QT_CHARTS_BEGIN_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | LogXYDomain::LogXYDomain(QObject *parent) |
|
39 | 39 | : AbstractDomain(parent), |
|
40 | 40 | m_logLeftX(0), |
|
41 | 41 | m_logRightX(1), |
|
42 | 42 | m_logBaseX(10) |
|
43 | 43 | { |
|
44 | 44 | } |
|
45 | 45 | |
|
46 | 46 | LogXYDomain::~LogXYDomain() |
|
47 | 47 | { |
|
48 | 48 | } |
|
49 | 49 | |
|
50 | 50 | void LogXYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
51 | 51 | { |
|
52 | 52 | bool axisXChanged = false; |
|
53 | 53 | bool axisYChanged = false; |
|
54 | 54 | |
|
55 | 55 | adjustLogDomainRanges(minX, maxX); |
|
56 | 56 | |
|
57 | 57 | if (!qFuzzyCompare(m_minX, minX) || !qFuzzyCompare(m_maxX, maxX)) { |
|
58 | 58 | m_minX = minX; |
|
59 | 59 | m_maxX = maxX; |
|
60 | 60 | axisXChanged = true; |
|
61 | 61 | qreal logMinX = std::log10(m_minX) / std::log10(m_logBaseX); |
|
62 | 62 | qreal logMaxX = std::log10(m_maxX) / std::log10(m_logBaseX); |
|
63 | 63 | m_logLeftX = logMinX < logMaxX ? logMinX : logMaxX; |
|
64 | 64 | m_logRightX = logMinX > logMaxX ? logMinX : logMaxX; |
|
65 | 65 | if(!m_signalsBlocked) |
|
66 | 66 | emit rangeHorizontalChanged(m_minX, m_maxX); |
|
67 | 67 | } |
|
68 | 68 | |
|
69 | 69 | if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) { |
|
70 | 70 | m_minY = minY; |
|
71 | 71 | m_maxY = maxY; |
|
72 | 72 | axisYChanged = true; |
|
73 | 73 | if (!m_signalsBlocked) |
|
74 | 74 | emit rangeVerticalChanged(m_minY, m_maxY); |
|
75 | 75 | } |
|
76 | 76 | |
|
77 | 77 | if (axisXChanged || axisYChanged) |
|
78 | 78 | emit updated(); |
|
79 | 79 | } |
|
80 | 80 | |
|
81 | 81 | void LogXYDomain::zoomIn(const QRectF &rect) |
|
82 | 82 | { |
|
83 | 83 | storeZoomReset(); |
|
84 | 84 | qreal logLeftX = rect.left() * (m_logRightX - m_logLeftX) / m_size.width() + m_logLeftX; |
|
85 | 85 | qreal logRightX = rect.right() * (m_logRightX - m_logLeftX) / m_size.width() + m_logLeftX; |
|
86 | 86 | qreal leftX = qPow(m_logBaseX, logLeftX); |
|
87 | 87 | qreal rightX = qPow(m_logBaseX, logRightX); |
|
88 | 88 | qreal minX = leftX < rightX ? leftX : rightX; |
|
89 | 89 | qreal maxX = leftX > rightX ? leftX : rightX; |
|
90 | 90 | |
|
91 | 91 | qreal dy = spanY() / m_size.height(); |
|
92 | 92 | qreal minY = m_minY; |
|
93 | 93 | qreal maxY = m_maxY; |
|
94 | 94 | |
|
95 | 95 | minY = maxY - dy * rect.bottom(); |
|
96 | 96 | maxY = maxY - dy * rect.top(); |
|
97 | 97 | |
|
98 | 98 | setRange(minX, maxX, minY, maxY); |
|
99 | 99 | } |
|
100 | 100 | |
|
101 | 101 | void LogXYDomain::zoomOut(const QRectF &rect) |
|
102 | 102 | { |
|
103 | 103 | storeZoomReset(); |
|
104 | 104 | const qreal factorX = m_size.width() / rect.width(); |
|
105 | 105 | |
|
106 | 106 | qreal logLeftX = m_logLeftX + (m_logRightX - m_logLeftX) / 2 * (1 - factorX); |
|
107 | 107 | qreal logRIghtX = m_logLeftX + (m_logRightX - m_logLeftX) / 2 * (1 + factorX); |
|
108 | 108 | qreal leftX = qPow(m_logBaseX, logLeftX); |
|
109 | 109 | qreal rightX = qPow(m_logBaseX, logRIghtX); |
|
110 | 110 | qreal minX = leftX < rightX ? leftX : rightX; |
|
111 | 111 | qreal maxX = leftX > rightX ? leftX : rightX; |
|
112 | 112 | |
|
113 | 113 | qreal dy = spanY() / rect.height(); |
|
114 | 114 | qreal minY = m_minY; |
|
115 | 115 | qreal maxY = m_maxY; |
|
116 | 116 | |
|
117 | 117 | maxY = minY + dy * rect.bottom(); |
|
118 | 118 | minY = maxY - dy * m_size.height(); |
|
119 | 119 | |
|
120 | 120 | setRange(minX, maxX, minY, maxY); |
|
121 | 121 | } |
|
122 | 122 | |
|
123 | 123 | void LogXYDomain::move(qreal dx, qreal dy) |
|
124 | 124 | { |
|
125 | 125 | qreal stepX = dx * (m_logRightX - m_logLeftX) / m_size.width(); |
|
126 | 126 | qreal leftX = qPow(m_logBaseX, m_logLeftX + stepX); |
|
127 | 127 | qreal rightX = qPow(m_logBaseX, m_logRightX + stepX); |
|
128 | 128 | qreal minX = leftX < rightX ? leftX : rightX; |
|
129 | 129 | qreal maxX = leftX > rightX ? leftX : rightX; |
|
130 | 130 | |
|
131 | 131 | qreal y = spanY() / m_size.height(); |
|
132 | 132 | qreal minY = m_minY; |
|
133 | 133 | qreal maxY = m_maxY; |
|
134 | 134 | |
|
135 | 135 | if (dy != 0) { |
|
136 | 136 | minY = minY + y * dy; |
|
137 | 137 | maxY = maxY + y * dy; |
|
138 | 138 | } |
|
139 | 139 | setRange(minX, maxX, minY, maxY); |
|
140 | 140 | } |
|
141 | 141 | |
|
142 | 142 | QPointF LogXYDomain::calculateGeometryPoint(const QPointF &point, bool &ok) const |
|
143 | 143 | { |
|
144 | 144 | const qreal deltaX = m_size.width() / (m_logRightX - m_logLeftX); |
|
145 | 145 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); |
|
146 | 146 | |
|
147 | 147 | qreal x(0); |
|
148 | 148 | qreal y = (point.y() - m_minY) * -deltaY + m_size.height(); |
|
149 | 149 | if (point.x() > 0) { |
|
150 | 150 | x = (std::log10(point.x()) / std::log10(m_logBaseX)) * deltaX - m_logLeftX * deltaX; |
|
151 | 151 | ok = true; |
|
152 | 152 | } else { |
|
153 | 153 | x = 0; |
|
154 | 154 | qWarning() << "Logarithms of zero and negative values are undefined."; |
|
155 | 155 | ok = false; |
|
156 | 156 | } |
|
157 | 157 | return QPointF(x, y); |
|
158 | 158 | } |
|
159 | 159 | |
|
160 | 160 | QVector<QPointF> LogXYDomain::calculateGeometryPoints(const QVector<QPointF> &vector) const |
|
161 | 161 | { |
|
162 | 162 | const qreal deltaX = m_size.width() / (m_logRightX - m_logLeftX); |
|
163 | 163 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); |
|
164 | 164 | |
|
165 | 165 | QVector<QPointF> result; |
|
166 | 166 | result.resize(vector.count()); |
|
167 | 167 | |
|
168 | 168 | for (int i = 0; i < vector.count(); ++i) { |
|
169 | 169 | if (vector[i].x() > 0) { |
|
170 | 170 | qreal x = (std::log10(vector[i].x()) / std::log10(m_logBaseX)) * deltaX - m_logLeftX * deltaX; |
|
171 | 171 | qreal y = (vector[i].y() - m_minY) * -deltaY + m_size.height(); |
|
172 | 172 | result[i].setX(x); |
|
173 | 173 | result[i].setY(y); |
|
174 | 174 | } else { |
|
175 | 175 | qWarning() << "Logarithms of zero and negative values are undefined."; |
|
176 | 176 | return QVector<QPointF>(); |
|
177 | 177 | } |
|
178 | 178 | |
|
179 | 179 | } |
|
180 | 180 | return result; |
|
181 | 181 | } |
|
182 | 182 | |
|
183 | 183 | QPointF LogXYDomain::calculateDomainPoint(const QPointF &point) const |
|
184 | 184 | { |
|
185 | 185 | const qreal deltaX = m_size.width() / (m_logRightX - m_logLeftX); |
|
186 | 186 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); |
|
187 | 187 | qreal x = qPow(m_logBaseX, m_logLeftX + point.x() / deltaX); |
|
188 | 188 | qreal y = (point.y() - m_size.height()) / (-deltaY) + m_minY; |
|
189 | 189 | return QPointF(x, y); |
|
190 | 190 | } |
|
191 | 191 | |
|
192 | 192 | bool LogXYDomain::attachAxis(QAbstractAxis *axis) |
|
193 | 193 | { |
|
194 | 194 | AbstractDomain::attachAxis(axis); |
|
195 | 195 | QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis); |
|
196 | 196 | |
|
197 | 197 | if (logAxis && logAxis->orientation() == Qt::Horizontal) { |
|
198 | 198 | QObject::connect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleHorizontalAxisBaseChanged(qreal))); |
|
199 | 199 | handleHorizontalAxisBaseChanged(logAxis->base()); |
|
200 | 200 | } |
|
201 | 201 | |
|
202 | 202 | return true; |
|
203 | 203 | } |
|
204 | 204 | |
|
205 | 205 | bool LogXYDomain::detachAxis(QAbstractAxis *axis) |
|
206 | 206 | { |
|
207 | 207 | AbstractDomain::detachAxis(axis); |
|
208 | 208 | QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis); |
|
209 | 209 | |
|
210 | 210 | if (logAxis && logAxis->orientation() == Qt::Horizontal) |
|
211 | 211 | QObject::disconnect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleHorizontalAxisBaseChanged(qreal))); |
|
212 | 212 | |
|
213 | 213 | return true; |
|
214 | 214 | } |
|
215 | 215 | |
|
216 | 216 | void LogXYDomain::handleHorizontalAxisBaseChanged(qreal baseX) |
|
217 | 217 | { |
|
218 | 218 | m_logBaseX = baseX; |
|
219 | 219 | qreal logMinX = std::log10(m_minX) / std::log10(m_logBaseX); |
|
220 | 220 | qreal logMaxX = std::log10(m_maxX) / std::log10(m_logBaseX); |
|
221 | 221 | m_logLeftX = logMinX < logMaxX ? logMinX : logMaxX; |
|
222 | 222 | m_logRightX = logMinX > logMaxX ? logMinX : logMaxX; |
|
223 | 223 | emit updated(); |
|
224 | 224 | } |
|
225 | 225 | |
|
226 | 226 | // operators |
|
227 | 227 | |
|
228 |
bool Q |
|
|
228 | bool Q_AUTOTEST_EXPORT operator== (const LogXYDomain &domain1, const LogXYDomain &domain2) | |
|
229 | 229 | { |
|
230 | 230 | return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) |
|
231 | 231 | && qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) |
|
232 | 232 | && qFuzzyIsNull(domain1.m_minX - domain2.m_minX) |
|
233 | 233 | && qFuzzyIsNull(domain1.m_minY - domain2.m_minY)); |
|
234 | 234 | } |
|
235 | 235 | |
|
236 | 236 | |
|
237 |
bool Q |
|
|
237 | bool Q_AUTOTEST_EXPORT operator!= (const LogXYDomain &domain1, const LogXYDomain &domain2) | |
|
238 | 238 | { |
|
239 | 239 | return !(domain1 == domain2); |
|
240 | 240 | } |
|
241 | 241 | |
|
242 | 242 | |
|
243 |
QDebug Q |
|
|
243 | QDebug Q_AUTOTEST_EXPORT operator<<(QDebug dbg, const LogXYDomain &domain) | |
|
244 | 244 | { |
|
245 | 245 | #ifdef QT_NO_TEXTSTREAM |
|
246 | 246 | Q_UNUSED(domain) |
|
247 | 247 | #else |
|
248 | 248 | dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size; |
|
249 | 249 | #endif |
|
250 | 250 | return dbg.maybeSpace(); |
|
251 | 251 | } |
|
252 | 252 | |
|
253 | 253 | #include "moc_logxydomain_p.cpp" |
|
254 | 254 | |
|
255 | 255 | QT_CHARTS_END_NAMESPACE |
@@ -1,84 +1,84 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | // W A R N I N G |
|
31 | 31 | // ------------- |
|
32 | 32 | // |
|
33 | 33 | // This file is not part of the Qt Chart API. It exists purely as an |
|
34 | 34 | // implementation detail. This header file may change from version to |
|
35 | 35 | // version without notice, or even be removed. |
|
36 | 36 | // |
|
37 | 37 | // We mean it. |
|
38 | 38 | |
|
39 | 39 | #ifndef LOGXYDOMAIN_H |
|
40 | 40 | #define LOGXYDOMAIN_H |
|
41 | 41 | #include <private/abstractdomain_p.h> |
|
42 | 42 | #include <QtCore/QRectF> |
|
43 | 43 | #include <QtCore/QSizeF> |
|
44 | 44 | |
|
45 | 45 | QT_CHARTS_BEGIN_NAMESPACE |
|
46 | 46 | |
|
47 |
class Q |
|
|
47 | class Q_AUTOTEST_EXPORT LogXYDomain: public AbstractDomain | |
|
48 | 48 | { |
|
49 | 49 | Q_OBJECT |
|
50 | 50 | public: |
|
51 | 51 | explicit LogXYDomain(QObject *object = 0); |
|
52 | 52 | virtual ~LogXYDomain(); |
|
53 | 53 | |
|
54 | 54 | DomainType type(){ return AbstractDomain::LogXYDomain;} |
|
55 | 55 | |
|
56 | 56 | void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
57 | 57 | |
|
58 |
friend bool Q |
|
|
59 |
friend bool Q |
|
|
60 |
friend QDebug Q |
|
|
58 | friend bool Q_AUTOTEST_EXPORT operator== (const LogXYDomain &domain1, const LogXYDomain &domain2); | |
|
59 | friend bool Q_AUTOTEST_EXPORT operator!= (const LogXYDomain &domain1, const LogXYDomain &domain2); | |
|
60 | friend QDebug Q_AUTOTEST_EXPORT operator<<(QDebug dbg, const LogXYDomain &domain); | |
|
61 | 61 | |
|
62 | 62 | void zoomIn(const QRectF &rect); |
|
63 | 63 | void zoomOut(const QRectF &rect); |
|
64 | 64 | void move(qreal dx, qreal dy); |
|
65 | 65 | |
|
66 | 66 | QPointF calculateGeometryPoint(const QPointF &point, bool &ok) const; |
|
67 | 67 | QPointF calculateDomainPoint(const QPointF &point) const; |
|
68 | 68 | QVector<QPointF> calculateGeometryPoints(const QVector<QPointF> &vector) const; |
|
69 | 69 | |
|
70 | 70 | bool attachAxis(QAbstractAxis *axis); |
|
71 | 71 | bool detachAxis(QAbstractAxis *axis); |
|
72 | 72 | |
|
73 | 73 | public Q_SLOTS: |
|
74 | 74 | void handleHorizontalAxisBaseChanged(qreal baseX); |
|
75 | 75 | |
|
76 | 76 | private: |
|
77 | 77 | qreal m_logLeftX; |
|
78 | 78 | qreal m_logRightX; |
|
79 | 79 | qreal m_logBaseX; |
|
80 | 80 | }; |
|
81 | 81 | |
|
82 | 82 | QT_CHARTS_END_NAMESPACE |
|
83 | 83 | |
|
84 | 84 | #endif // LOGXYDOMAIN_H |
@@ -1,252 +1,252 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #include <private/logxypolardomain_p.h> |
|
31 | 31 | #include <private/qabstractaxis_p.h> |
|
32 | 32 | #include <QtCharts/QLogValueAxis> |
|
33 | 33 | #include <QtCore/QtMath> |
|
34 | 34 | #include <cmath> |
|
35 | 35 | |
|
36 | 36 | QT_CHARTS_BEGIN_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | LogXYPolarDomain::LogXYPolarDomain(QObject *parent) |
|
39 | 39 | : PolarDomain(parent), |
|
40 | 40 | m_logLeftX(0), |
|
41 | 41 | m_logRightX(1), |
|
42 | 42 | m_logBaseX(10) |
|
43 | 43 | { |
|
44 | 44 | } |
|
45 | 45 | |
|
46 | 46 | LogXYPolarDomain::~LogXYPolarDomain() |
|
47 | 47 | { |
|
48 | 48 | } |
|
49 | 49 | |
|
50 | 50 | void LogXYPolarDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
51 | 51 | { |
|
52 | 52 | bool axisXChanged = false; |
|
53 | 53 | bool axisYChanged = false; |
|
54 | 54 | |
|
55 | 55 | adjustLogDomainRanges(minX, maxX); |
|
56 | 56 | |
|
57 | 57 | if (!qFuzzyCompare(m_minX, minX) || !qFuzzyCompare(m_maxX, maxX)) { |
|
58 | 58 | m_minX = minX; |
|
59 | 59 | m_maxX = maxX; |
|
60 | 60 | axisXChanged = true; |
|
61 | 61 | qreal logMinX = std::log10(m_minX) / std::log10(m_logBaseX); |
|
62 | 62 | qreal logMaxX = std::log10(m_maxX) / std::log10(m_logBaseX); |
|
63 | 63 | m_logLeftX = logMinX < logMaxX ? logMinX : logMaxX; |
|
64 | 64 | m_logRightX = logMinX > logMaxX ? logMinX : logMaxX; |
|
65 | 65 | if (!m_signalsBlocked) |
|
66 | 66 | emit rangeHorizontalChanged(m_minX, m_maxX); |
|
67 | 67 | } |
|
68 | 68 | |
|
69 | 69 | if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) { |
|
70 | 70 | m_minY = minY; |
|
71 | 71 | m_maxY = maxY; |
|
72 | 72 | axisYChanged = true; |
|
73 | 73 | if (!m_signalsBlocked) |
|
74 | 74 | emit rangeVerticalChanged(m_minY, m_maxY); |
|
75 | 75 | } |
|
76 | 76 | |
|
77 | 77 | if (axisXChanged || axisYChanged) |
|
78 | 78 | emit updated(); |
|
79 | 79 | } |
|
80 | 80 | |
|
81 | 81 | void LogXYPolarDomain::zoomIn(const QRectF &rect) |
|
82 | 82 | { |
|
83 | 83 | storeZoomReset(); |
|
84 | 84 | qreal logLeftX = rect.left() * (m_logRightX - m_logLeftX) / m_size.width() + m_logLeftX; |
|
85 | 85 | qreal logRightX = rect.right() * (m_logRightX - m_logLeftX) / m_size.width() + m_logLeftX; |
|
86 | 86 | qreal leftX = qPow(m_logBaseX, logLeftX); |
|
87 | 87 | qreal rightX = qPow(m_logBaseX, logRightX); |
|
88 | 88 | qreal minX = leftX < rightX ? leftX : rightX; |
|
89 | 89 | qreal maxX = leftX > rightX ? leftX : rightX; |
|
90 | 90 | |
|
91 | 91 | qreal dy = spanY() / m_size.height(); |
|
92 | 92 | qreal minY = m_minY; |
|
93 | 93 | qreal maxY = m_maxY; |
|
94 | 94 | |
|
95 | 95 | minY = maxY - dy * rect.bottom(); |
|
96 | 96 | maxY = maxY - dy * rect.top(); |
|
97 | 97 | |
|
98 | 98 | setRange(minX, maxX, minY, maxY); |
|
99 | 99 | } |
|
100 | 100 | |
|
101 | 101 | void LogXYPolarDomain::zoomOut(const QRectF &rect) |
|
102 | 102 | { |
|
103 | 103 | storeZoomReset(); |
|
104 | 104 | const qreal factorX = m_size.width() / rect.width(); |
|
105 | 105 | |
|
106 | 106 | qreal logLeftX = m_logLeftX + (m_logRightX - m_logLeftX) / 2.0 * (1.0 - factorX); |
|
107 | 107 | qreal logRIghtX = m_logLeftX + (m_logRightX - m_logLeftX) / 2.0 * (1.0 + factorX); |
|
108 | 108 | qreal leftX = qPow(m_logBaseX, logLeftX); |
|
109 | 109 | qreal rightX = qPow(m_logBaseX, logRIghtX); |
|
110 | 110 | qreal minX = leftX < rightX ? leftX : rightX; |
|
111 | 111 | qreal maxX = leftX > rightX ? leftX : rightX; |
|
112 | 112 | |
|
113 | 113 | qreal dy = spanY() / rect.height(); |
|
114 | 114 | qreal minY = m_minY; |
|
115 | 115 | qreal maxY = m_maxY; |
|
116 | 116 | |
|
117 | 117 | maxY = minY + dy * rect.bottom(); |
|
118 | 118 | minY = maxY - dy * m_size.height(); |
|
119 | 119 | |
|
120 | 120 | setRange(minX, maxX, minY, maxY); |
|
121 | 121 | } |
|
122 | 122 | |
|
123 | 123 | void LogXYPolarDomain::move(qreal dx, qreal dy) |
|
124 | 124 | { |
|
125 | 125 | qreal stepX = dx * (m_logRightX - m_logLeftX) / m_size.width(); |
|
126 | 126 | qreal leftX = qPow(m_logBaseX, m_logLeftX + stepX); |
|
127 | 127 | qreal rightX = qPow(m_logBaseX, m_logRightX + stepX); |
|
128 | 128 | qreal minX = leftX < rightX ? leftX : rightX; |
|
129 | 129 | qreal maxX = leftX > rightX ? leftX : rightX; |
|
130 | 130 | |
|
131 | 131 | qreal y = spanY() / m_radius; |
|
132 | 132 | qreal minY = m_minY; |
|
133 | 133 | qreal maxY = m_maxY; |
|
134 | 134 | |
|
135 | 135 | if (dy != 0) { |
|
136 | 136 | minY = minY + y * dy; |
|
137 | 137 | maxY = maxY + y * dy; |
|
138 | 138 | } |
|
139 | 139 | setRange(minX, maxX, minY, maxY); |
|
140 | 140 | } |
|
141 | 141 | |
|
142 | 142 | qreal LogXYPolarDomain::toAngularCoordinate(qreal value, bool &ok) const |
|
143 | 143 | { |
|
144 | 144 | qreal retVal; |
|
145 | 145 | if (value <= 0) { |
|
146 | 146 | ok = false; |
|
147 | 147 | retVal = 0.0; |
|
148 | 148 | } else { |
|
149 | 149 | ok = true; |
|
150 | 150 | const qreal tickSpan = 360.0 / qAbs(m_logRightX - m_logLeftX); |
|
151 | 151 | const qreal logValue = std::log10(value) / std::log10(m_logBaseX); |
|
152 | 152 | const qreal valueDelta = logValue - m_logLeftX; |
|
153 | 153 | |
|
154 | 154 | retVal = valueDelta * tickSpan; |
|
155 | 155 | } |
|
156 | 156 | return retVal; |
|
157 | 157 | } |
|
158 | 158 | |
|
159 | 159 | qreal LogXYPolarDomain::toRadialCoordinate(qreal value, bool &ok) const |
|
160 | 160 | { |
|
161 | 161 | ok = true; |
|
162 | 162 | if (value < m_minY) |
|
163 | 163 | value = m_minY; |
|
164 | 164 | |
|
165 | 165 | // Dont limit the max. The drawing should clip the stuff that goes out of the grid |
|
166 | 166 | qreal f = (value - m_minY) / (m_maxY - m_minY); |
|
167 | 167 | |
|
168 | 168 | return f * m_radius; |
|
169 | 169 | } |
|
170 | 170 | |
|
171 | 171 | QPointF LogXYPolarDomain::calculateDomainPoint(const QPointF &point) const |
|
172 | 172 | { |
|
173 | 173 | if (point == m_center) |
|
174 | 174 | return QPointF(0.0, m_minY); |
|
175 | 175 | |
|
176 | 176 | QLineF line(m_center, point); |
|
177 | 177 | qreal a = 90.0 - line.angle(); |
|
178 | 178 | if (a < 0.0) |
|
179 | 179 | a += 360.0; |
|
180 | 180 | |
|
181 | 181 | const qreal deltaX = 360.0 / qAbs(m_logRightX - m_logLeftX); |
|
182 | 182 | a = qPow(m_logBaseX, m_logLeftX + (a / deltaX)); |
|
183 | 183 | |
|
184 | 184 | qreal r = m_minY + ((m_maxY - m_minY) * (line.length() / m_radius)); |
|
185 | 185 | |
|
186 | 186 | return QPointF(a, r); |
|
187 | 187 | } |
|
188 | 188 | |
|
189 | 189 | bool LogXYPolarDomain::attachAxis(QAbstractAxis *axis) |
|
190 | 190 | { |
|
191 | 191 | AbstractDomain::attachAxis(axis); |
|
192 | 192 | QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis); |
|
193 | 193 | |
|
194 | 194 | if (logAxis && logAxis->orientation() == Qt::Horizontal) { |
|
195 | 195 | QObject::connect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleHorizontalAxisBaseChanged(qreal))); |
|
196 | 196 | handleHorizontalAxisBaseChanged(logAxis->base()); |
|
197 | 197 | } |
|
198 | 198 | |
|
199 | 199 | return true; |
|
200 | 200 | } |
|
201 | 201 | |
|
202 | 202 | bool LogXYPolarDomain::detachAxis(QAbstractAxis *axis) |
|
203 | 203 | { |
|
204 | 204 | AbstractDomain::detachAxis(axis); |
|
205 | 205 | QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis); |
|
206 | 206 | |
|
207 | 207 | if (logAxis && logAxis->orientation() == Qt::Horizontal) |
|
208 | 208 | QObject::disconnect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleHorizontalAxisBaseChanged(qreal))); |
|
209 | 209 | |
|
210 | 210 | return true; |
|
211 | 211 | } |
|
212 | 212 | |
|
213 | 213 | void LogXYPolarDomain::handleHorizontalAxisBaseChanged(qreal baseX) |
|
214 | 214 | { |
|
215 | 215 | m_logBaseX = baseX; |
|
216 | 216 | qreal logMinX = std::log10(m_minX) / std::log10(m_logBaseX); |
|
217 | 217 | qreal logMaxX = std::log10(m_maxX) / std::log10(m_logBaseX); |
|
218 | 218 | m_logLeftX = logMinX < logMaxX ? logMinX : logMaxX; |
|
219 | 219 | m_logRightX = logMinX > logMaxX ? logMinX : logMaxX; |
|
220 | 220 | emit updated(); |
|
221 | 221 | } |
|
222 | 222 | |
|
223 | 223 | // operators |
|
224 | 224 | |
|
225 |
bool Q |
|
|
225 | bool Q_AUTOTEST_EXPORT operator== (const LogXYPolarDomain &domain1, const LogXYPolarDomain &domain2) | |
|
226 | 226 | { |
|
227 | 227 | return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) |
|
228 | 228 | && qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) |
|
229 | 229 | && qFuzzyIsNull(domain1.m_minX - domain2.m_minX) |
|
230 | 230 | && qFuzzyIsNull(domain1.m_minY - domain2.m_minY)); |
|
231 | 231 | } |
|
232 | 232 | |
|
233 | 233 | |
|
234 |
bool Q |
|
|
234 | bool Q_AUTOTEST_EXPORT operator!= (const LogXYPolarDomain &domain1, const LogXYPolarDomain &domain2) | |
|
235 | 235 | { |
|
236 | 236 | return !(domain1 == domain2); |
|
237 | 237 | } |
|
238 | 238 | |
|
239 | 239 | |
|
240 |
QDebug Q |
|
|
240 | QDebug Q_AUTOTEST_EXPORT operator<<(QDebug dbg, const LogXYPolarDomain &domain) | |
|
241 | 241 | { |
|
242 | 242 | #ifdef QT_NO_TEXTSTREAM |
|
243 | 243 | Q_UNUSED(domain) |
|
244 | 244 | #else |
|
245 | 245 | dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size; |
|
246 | 246 | #endif |
|
247 | 247 | return dbg.maybeSpace(); |
|
248 | 248 | } |
|
249 | 249 | |
|
250 | 250 | #include "moc_logxypolardomain_p.cpp" |
|
251 | 251 | |
|
252 | 252 | QT_CHARTS_END_NAMESPACE |
@@ -1,86 +1,86 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | // W A R N I N G |
|
31 | 31 | // ------------- |
|
32 | 32 | // |
|
33 | 33 | // This file is not part of the Qt Chart API. It exists purely as an |
|
34 | 34 | // implementation detail. This header file may change from version to |
|
35 | 35 | // version without notice, or even be removed. |
|
36 | 36 | // |
|
37 | 37 | // We mean it. |
|
38 | 38 | |
|
39 | 39 | #ifndef LOGXYPOLARDOMAIN_H |
|
40 | 40 | #define LOGXYPOLARDOMAIN_H |
|
41 | 41 | #include <private/polardomain_p.h> |
|
42 | 42 | #include <QtCore/QRectF> |
|
43 | 43 | #include <QtCore/QSizeF> |
|
44 | 44 | |
|
45 | 45 | QT_CHARTS_BEGIN_NAMESPACE |
|
46 | 46 | |
|
47 |
class Q |
|
|
47 | class Q_AUTOTEST_EXPORT LogXYPolarDomain: public PolarDomain | |
|
48 | 48 | { |
|
49 | 49 | Q_OBJECT |
|
50 | 50 | public: |
|
51 | 51 | explicit LogXYPolarDomain(QObject *object = 0); |
|
52 | 52 | virtual ~LogXYPolarDomain(); |
|
53 | 53 | |
|
54 | 54 | DomainType type() { return AbstractDomain::LogXYPolarDomain; } |
|
55 | 55 | |
|
56 | 56 | void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
57 | 57 | |
|
58 |
friend bool Q |
|
|
59 |
friend bool Q |
|
|
60 |
friend QDebug Q |
|
|
58 | friend bool Q_AUTOTEST_EXPORT operator== (const LogXYPolarDomain &domain1, const LogXYPolarDomain &domain2); | |
|
59 | friend bool Q_AUTOTEST_EXPORT operator!= (const LogXYPolarDomain &domain1, const LogXYPolarDomain &domain2); | |
|
60 | friend QDebug Q_AUTOTEST_EXPORT operator<<(QDebug dbg, const LogXYPolarDomain &domain); | |
|
61 | 61 | |
|
62 | 62 | void zoomIn(const QRectF &rect); |
|
63 | 63 | void zoomOut(const QRectF &rect); |
|
64 | 64 | void move(qreal dx, qreal dy); |
|
65 | 65 | |
|
66 | 66 | QPointF calculateDomainPoint(const QPointF &point) const; |
|
67 | 67 | |
|
68 | 68 | bool attachAxis(QAbstractAxis *axis); |
|
69 | 69 | bool detachAxis(QAbstractAxis *axis); |
|
70 | 70 | |
|
71 | 71 | public Q_SLOTS: |
|
72 | 72 | void handleHorizontalAxisBaseChanged(qreal baseX); |
|
73 | 73 | |
|
74 | 74 | protected: |
|
75 | 75 | qreal toAngularCoordinate(qreal value, bool &ok) const; |
|
76 | 76 | qreal toRadialCoordinate(qreal value, bool &ok) const; |
|
77 | 77 | |
|
78 | 78 | private: |
|
79 | 79 | qreal m_logLeftX; |
|
80 | 80 | qreal m_logRightX; |
|
81 | 81 | qreal m_logBaseX; |
|
82 | 82 | }; |
|
83 | 83 | |
|
84 | 84 | QT_CHARTS_END_NAMESPACE |
|
85 | 85 | |
|
86 | 86 | #endif // LOGXYPOLARDOMAIN_H |
@@ -1,71 +1,71 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | // W A R N I N G |
|
31 | 31 | // ------------- |
|
32 | 32 | // |
|
33 | 33 | // This file is not part of the Qt Chart API. It exists purely as an |
|
34 | 34 | // implementation detail. This header file may change from version to |
|
35 | 35 | // version without notice, or even be removed. |
|
36 | 36 | // |
|
37 | 37 | // We mean it. |
|
38 | 38 | |
|
39 | 39 | #ifndef POLARDOMAIN_H |
|
40 | 40 | #define POLARDOMAIN_H |
|
41 | 41 | #include <private/abstractdomain_p.h> |
|
42 | 42 | #include <QtCore/QRectF> |
|
43 | 43 | #include <QtCore/QSizeF> |
|
44 | 44 | |
|
45 | 45 | QT_CHARTS_BEGIN_NAMESPACE |
|
46 | 46 | |
|
47 |
class Q |
|
|
47 | class Q_AUTOTEST_EXPORT PolarDomain: public AbstractDomain | |
|
48 | 48 | { |
|
49 | 49 | Q_OBJECT |
|
50 | 50 | public: |
|
51 | 51 | explicit PolarDomain(QObject *object = 0); |
|
52 | 52 | virtual ~PolarDomain(); |
|
53 | 53 | |
|
54 | 54 | void setSize(const QSizeF &size); |
|
55 | 55 | |
|
56 | 56 | QPointF calculateGeometryPoint(const QPointF &point, bool &ok) const; |
|
57 | 57 | QVector<QPointF> calculateGeometryPoints(const QVector<QPointF> &vector) const; |
|
58 | 58 | |
|
59 | 59 | virtual qreal toAngularCoordinate(qreal value, bool &ok) const = 0; |
|
60 | 60 | virtual qreal toRadialCoordinate(qreal value, bool &ok) const = 0; |
|
61 | 61 | |
|
62 | 62 | protected: |
|
63 | 63 | QPointF polarCoordinateToPoint(qreal angularCoordinate, qreal radialCoordinate) const; |
|
64 | 64 | |
|
65 | 65 | QPointF m_center; |
|
66 | 66 | qreal m_radius; |
|
67 | 67 | }; |
|
68 | 68 | |
|
69 | 69 | QT_CHARTS_END_NAMESPACE |
|
70 | 70 | |
|
71 | 71 | #endif // POLARDOMAIN_H |
@@ -1,251 +1,251 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #include <private/xlogydomain_p.h> |
|
31 | 31 | #include <private/qabstractaxis_p.h> |
|
32 | 32 | #include <QtCharts/QLogValueAxis> |
|
33 | 33 | #include <QtCore/QtMath> |
|
34 | 34 | #include <cmath> |
|
35 | 35 | |
|
36 | 36 | QT_CHARTS_BEGIN_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | XLogYDomain::XLogYDomain(QObject *parent) |
|
39 | 39 | : AbstractDomain(parent), |
|
40 | 40 | m_logLeftY(0), |
|
41 | 41 | m_logRightY(1), |
|
42 | 42 | m_logBaseY(10) |
|
43 | 43 | { |
|
44 | 44 | } |
|
45 | 45 | |
|
46 | 46 | XLogYDomain::~XLogYDomain() |
|
47 | 47 | { |
|
48 | 48 | } |
|
49 | 49 | |
|
50 | 50 | void XLogYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
51 | 51 | { |
|
52 | 52 | bool axisXChanged = false; |
|
53 | 53 | bool axisYChanged = false; |
|
54 | 54 | |
|
55 | 55 | adjustLogDomainRanges(minY, maxY); |
|
56 | 56 | |
|
57 | 57 | if (!qFuzzyIsNull(m_minX - minX) || !qFuzzyIsNull(m_maxX - maxX)) { |
|
58 | 58 | m_minX = minX; |
|
59 | 59 | m_maxX = maxX; |
|
60 | 60 | axisXChanged = true; |
|
61 | 61 | if(!m_signalsBlocked) |
|
62 | 62 | emit rangeHorizontalChanged(m_minX, m_maxX); |
|
63 | 63 | } |
|
64 | 64 | |
|
65 | 65 | if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) { |
|
66 | 66 | m_minY = minY; |
|
67 | 67 | m_maxY = maxY; |
|
68 | 68 | axisYChanged = true; |
|
69 | 69 | qreal logMinY = std::log10(m_minY) / std::log10(m_logBaseY); |
|
70 | 70 | qreal logMaxY = std::log10(m_maxY) / std::log10(m_logBaseY); |
|
71 | 71 | m_logLeftY = logMinY < logMaxY ? logMinY : logMaxY; |
|
72 | 72 | m_logRightY = logMinY > logMaxY ? logMinY : logMaxY; |
|
73 | 73 | if (!m_signalsBlocked) |
|
74 | 74 | emit rangeVerticalChanged(m_minY, m_maxY); |
|
75 | 75 | } |
|
76 | 76 | |
|
77 | 77 | if (axisXChanged || axisYChanged) |
|
78 | 78 | emit updated(); |
|
79 | 79 | } |
|
80 | 80 | |
|
81 | 81 | void XLogYDomain::zoomIn(const QRectF &rect) |
|
82 | 82 | { |
|
83 | 83 | storeZoomReset(); |
|
84 | 84 | qreal dx = spanX() / m_size.width(); |
|
85 | 85 | qreal maxX = m_maxX; |
|
86 | 86 | qreal minX = m_minX; |
|
87 | 87 | |
|
88 | 88 | maxX = minX + dx * rect.right(); |
|
89 | 89 | minX = minX + dx * rect.left(); |
|
90 | 90 | |
|
91 | 91 | qreal logLeftY = m_logRightY - rect.bottom() * (m_logRightY - m_logLeftY) / m_size.height(); |
|
92 | 92 | qreal logRightY = m_logRightY - rect.top() * (m_logRightY - m_logLeftY) / m_size.height(); |
|
93 | 93 | qreal leftY = qPow(m_logBaseY, logLeftY); |
|
94 | 94 | qreal rightY = qPow(m_logBaseY, logRightY); |
|
95 | 95 | qreal minY = leftY < rightY ? leftY : rightY; |
|
96 | 96 | qreal maxY = leftY > rightY ? leftY : rightY; |
|
97 | 97 | |
|
98 | 98 | setRange(minX, maxX, minY, maxY); |
|
99 | 99 | } |
|
100 | 100 | |
|
101 | 101 | void XLogYDomain::zoomOut(const QRectF &rect) |
|
102 | 102 | { |
|
103 | 103 | storeZoomReset(); |
|
104 | 104 | qreal dx = spanX() / rect.width(); |
|
105 | 105 | qreal maxX = m_maxX; |
|
106 | 106 | qreal minX = m_minX; |
|
107 | 107 | |
|
108 | 108 | minX = maxX - dx * rect.right(); |
|
109 | 109 | maxX = minX + dx * m_size.width(); |
|
110 | 110 | |
|
111 | 111 | const qreal factorY = m_size.height() / rect.height(); |
|
112 | 112 | qreal newLogMinY = m_logLeftY + (m_logRightY - m_logLeftY) / 2 * (1 - factorY); |
|
113 | 113 | qreal newLogMaxY = m_logLeftY + (m_logRightY - m_logLeftY) / 2 * (1 + factorY); |
|
114 | 114 | qreal leftY = qPow(m_logBaseY, newLogMinY); |
|
115 | 115 | qreal rightY = qPow(m_logBaseY, newLogMaxY); |
|
116 | 116 | qreal minY = leftY < rightY ? leftY : rightY; |
|
117 | 117 | qreal maxY = leftY > rightY ? leftY : rightY; |
|
118 | 118 | |
|
119 | 119 | setRange(minX, maxX, minY, maxY); |
|
120 | 120 | } |
|
121 | 121 | |
|
122 | 122 | void XLogYDomain::move(qreal dx, qreal dy) |
|
123 | 123 | { |
|
124 | 124 | qreal x = spanX() / m_size.width(); |
|
125 | 125 | qreal maxX = m_maxX; |
|
126 | 126 | qreal minX = m_minX; |
|
127 | 127 | |
|
128 | 128 | if (dx != 0) { |
|
129 | 129 | minX = minX + x * dx; |
|
130 | 130 | maxX = maxX + x * dx; |
|
131 | 131 | } |
|
132 | 132 | |
|
133 | 133 | qreal stepY = dy * (m_logRightY - m_logLeftY) / m_size.height(); |
|
134 | 134 | qreal leftY = qPow(m_logBaseY, m_logLeftY + stepY); |
|
135 | 135 | qreal rightY = qPow(m_logBaseY, m_logRightY + stepY); |
|
136 | 136 | qreal minY = leftY < rightY ? leftY : rightY; |
|
137 | 137 | qreal maxY = leftY > rightY ? leftY : rightY; |
|
138 | 138 | |
|
139 | 139 | setRange(minX, maxX, minY, maxY); |
|
140 | 140 | } |
|
141 | 141 | |
|
142 | 142 | QPointF XLogYDomain::calculateGeometryPoint(const QPointF &point, bool &ok) const |
|
143 | 143 | { |
|
144 | 144 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); |
|
145 | 145 | const qreal deltaY = m_size.height() / qAbs(m_logRightY - m_logLeftY); |
|
146 | 146 | |
|
147 | 147 | qreal x = (point.x() - m_minX) * deltaX; |
|
148 | 148 | qreal y(0); |
|
149 | 149 | if (point.y() > 0) { |
|
150 | 150 | y = (std::log10(point.y()) / std::log10(m_logBaseY)) * -deltaY - m_logLeftY * -deltaY + m_size.height(); |
|
151 | 151 | ok = true; |
|
152 | 152 | } else { |
|
153 | 153 | y = m_size.height(); |
|
154 | 154 | qWarning() << "Logarithms of zero and negative values are undefined."; |
|
155 | 155 | ok = false; |
|
156 | 156 | } |
|
157 | 157 | return QPointF(x, y); |
|
158 | 158 | } |
|
159 | 159 | |
|
160 | 160 | QVector<QPointF> XLogYDomain::calculateGeometryPoints(const QVector<QPointF> &vector) const |
|
161 | 161 | { |
|
162 | 162 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); |
|
163 | 163 | const qreal deltaY = m_size.height() / qAbs(m_logRightY - m_logLeftY); |
|
164 | 164 | |
|
165 | 165 | QVector<QPointF> result; |
|
166 | 166 | result.resize(vector.count()); |
|
167 | 167 | |
|
168 | 168 | for (int i = 0; i < vector.count(); ++i) { |
|
169 | 169 | if (vector[i].y() > 0) { |
|
170 | 170 | qreal x = (vector[i].x() - m_minX) * deltaX; |
|
171 | 171 | qreal y = (std::log10(vector[i].y()) / std::log10(m_logBaseY)) * -deltaY - m_logLeftY * -deltaY + m_size.height(); |
|
172 | 172 | result[i].setX(x); |
|
173 | 173 | result[i].setY(y); |
|
174 | 174 | } else { |
|
175 | 175 | qWarning() << "Logarithms of zero and negative values are undefined."; |
|
176 | 176 | return QVector<QPointF>(); |
|
177 | 177 | } |
|
178 | 178 | } |
|
179 | 179 | return result; |
|
180 | 180 | } |
|
181 | 181 | |
|
182 | 182 | QPointF XLogYDomain::calculateDomainPoint(const QPointF &point) const |
|
183 | 183 | { |
|
184 | 184 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); |
|
185 | 185 | const qreal deltaY = m_size.height() / qAbs(m_logRightY - m_logLeftY); |
|
186 | 186 | qreal x = point.x() / deltaX + m_minX; |
|
187 | 187 | qreal y = qPow(m_logBaseY, m_logLeftY + (m_size.height() - point.y()) / deltaY); |
|
188 | 188 | return QPointF(x, y); |
|
189 | 189 | } |
|
190 | 190 | |
|
191 | 191 | bool XLogYDomain::attachAxis(QAbstractAxis *axis) |
|
192 | 192 | { |
|
193 | 193 | QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis); |
|
194 | 194 | |
|
195 | 195 | if (logAxis && logAxis->orientation() == Qt::Vertical) { |
|
196 | 196 | QObject::connect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleVerticalAxisBaseChanged(qreal))); |
|
197 | 197 | handleVerticalAxisBaseChanged(logAxis->base()); |
|
198 | 198 | } |
|
199 | 199 | return AbstractDomain::attachAxis(axis); |
|
200 | 200 | } |
|
201 | 201 | |
|
202 | 202 | bool XLogYDomain::detachAxis(QAbstractAxis *axis) |
|
203 | 203 | { |
|
204 | 204 | QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis); |
|
205 | 205 | |
|
206 | 206 | if (logAxis && logAxis->orientation() == Qt::Vertical) |
|
207 | 207 | QObject::disconnect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleVerticalAxisBaseChanged(qreal))); |
|
208 | 208 | |
|
209 | 209 | return AbstractDomain::detachAxis(axis); |
|
210 | 210 | } |
|
211 | 211 | |
|
212 | 212 | void XLogYDomain::handleVerticalAxisBaseChanged(qreal baseY) |
|
213 | 213 | { |
|
214 | 214 | m_logBaseY = baseY; |
|
215 | 215 | qreal logMinY = std::log10(m_minY) / std::log10(m_logBaseY); |
|
216 | 216 | qreal logMaxY = std::log10(m_maxY) / std::log10(m_logBaseY); |
|
217 | 217 | m_logLeftY = logMinY < logMaxY ? logMinY : logMaxY; |
|
218 | 218 | m_logRightY = logMinY > logMaxY ? logMinY : logMaxY; |
|
219 | 219 | emit updated(); |
|
220 | 220 | } |
|
221 | 221 | |
|
222 | 222 | // operators |
|
223 | 223 | |
|
224 |
bool Q |
|
|
224 | bool Q_AUTOTEST_EXPORT operator== (const XLogYDomain &domain1, const XLogYDomain &domain2) | |
|
225 | 225 | { |
|
226 | 226 | return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) |
|
227 | 227 | && qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) |
|
228 | 228 | && qFuzzyIsNull(domain1.m_minX - domain2.m_minX) |
|
229 | 229 | && qFuzzyIsNull(domain1.m_minY - domain2.m_minY)); |
|
230 | 230 | } |
|
231 | 231 | |
|
232 | 232 | |
|
233 |
bool Q |
|
|
233 | bool Q_AUTOTEST_EXPORT operator!= (const XLogYDomain &domain1, const XLogYDomain &domain2) | |
|
234 | 234 | { |
|
235 | 235 | return !(domain1 == domain2); |
|
236 | 236 | } |
|
237 | 237 | |
|
238 | 238 | |
|
239 |
QDebug Q |
|
|
239 | QDebug Q_AUTOTEST_EXPORT operator<<(QDebug dbg, const XLogYDomain &domain) | |
|
240 | 240 | { |
|
241 | 241 | #ifdef QT_NO_TEXTSTREAM |
|
242 | 242 | Q_UNUSED(domain) |
|
243 | 243 | #else |
|
244 | 244 | dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size; |
|
245 | 245 | #endif |
|
246 | 246 | return dbg.maybeSpace(); |
|
247 | 247 | } |
|
248 | 248 | |
|
249 | 249 | #include "moc_xlogydomain_p.cpp" |
|
250 | 250 | |
|
251 | 251 | QT_CHARTS_END_NAMESPACE |
@@ -1,84 +1,84 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | // W A R N I N G |
|
31 | 31 | // ------------- |
|
32 | 32 | // |
|
33 | 33 | // This file is not part of the Qt Chart API. It exists purely as an |
|
34 | 34 | // implementation detail. This header file may change from version to |
|
35 | 35 | // version without notice, or even be removed. |
|
36 | 36 | // |
|
37 | 37 | // We mean it. |
|
38 | 38 | |
|
39 | 39 | #ifndef XLOGYDOMAIN_H |
|
40 | 40 | #define XLOGYDOMAIN_H |
|
41 | 41 | #include <private/abstractdomain_p.h> |
|
42 | 42 | #include <QtCore/QRectF> |
|
43 | 43 | #include <QtCore/QSizeF> |
|
44 | 44 | |
|
45 | 45 | QT_CHARTS_BEGIN_NAMESPACE |
|
46 | 46 | |
|
47 |
class Q |
|
|
47 | class Q_AUTOTEST_EXPORT XLogYDomain: public AbstractDomain | |
|
48 | 48 | { |
|
49 | 49 | Q_OBJECT |
|
50 | 50 | public: |
|
51 | 51 | explicit XLogYDomain(QObject *object = 0); |
|
52 | 52 | virtual ~XLogYDomain(); |
|
53 | 53 | |
|
54 | 54 | DomainType type(){ return AbstractDomain::XLogYDomain;}; |
|
55 | 55 | |
|
56 | 56 | void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
57 | 57 | |
|
58 |
friend bool Q |
|
|
59 |
friend bool Q |
|
|
60 |
friend QDebug Q |
|
|
58 | friend bool Q_AUTOTEST_EXPORT operator== (const XLogYDomain &domain1, const XLogYDomain &domain2); | |
|
59 | friend bool Q_AUTOTEST_EXPORT operator!= (const XLogYDomain &domain1, const XLogYDomain &domain2); | |
|
60 | friend QDebug Q_AUTOTEST_EXPORT operator<<(QDebug dbg, const XLogYDomain &domain); | |
|
61 | 61 | |
|
62 | 62 | void zoomIn(const QRectF &rect); |
|
63 | 63 | void zoomOut(const QRectF &rect); |
|
64 | 64 | void move(qreal dx, qreal dy); |
|
65 | 65 | |
|
66 | 66 | QPointF calculateGeometryPoint(const QPointF &point, bool &ok) const; |
|
67 | 67 | QPointF calculateDomainPoint(const QPointF &point) const; |
|
68 | 68 | QVector<QPointF> calculateGeometryPoints(const QVector<QPointF> &vector) const; |
|
69 | 69 | |
|
70 | 70 | bool attachAxis(QAbstractAxis *axis); |
|
71 | 71 | bool detachAxis(QAbstractAxis *axis); |
|
72 | 72 | |
|
73 | 73 | public Q_SLOTS: |
|
74 | 74 | void handleVerticalAxisBaseChanged(qreal baseY); |
|
75 | 75 | |
|
76 | 76 | private: |
|
77 | 77 | qreal m_logLeftY; |
|
78 | 78 | qreal m_logRightY; |
|
79 | 79 | qreal m_logBaseY; |
|
80 | 80 | }; |
|
81 | 81 | |
|
82 | 82 | QT_CHARTS_END_NAMESPACE |
|
83 | 83 | |
|
84 | 84 | #endif // XLOGYDOMAIN_H |
@@ -1,247 +1,247 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #include <private/xlogypolardomain_p.h> |
|
31 | 31 | #include <private/qabstractaxis_p.h> |
|
32 | 32 | #include <QtCharts/QLogValueAxis> |
|
33 | 33 | #include <QtCore/QtMath> |
|
34 | 34 | #include <cmath> |
|
35 | 35 | |
|
36 | 36 | QT_CHARTS_BEGIN_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | XLogYPolarDomain::XLogYPolarDomain(QObject *parent) |
|
39 | 39 | : PolarDomain(parent), |
|
40 | 40 | m_logInnerY(0), |
|
41 | 41 | m_logOuterY(1), |
|
42 | 42 | m_logBaseY(10) |
|
43 | 43 | { |
|
44 | 44 | } |
|
45 | 45 | |
|
46 | 46 | XLogYPolarDomain::~XLogYPolarDomain() |
|
47 | 47 | { |
|
48 | 48 | } |
|
49 | 49 | |
|
50 | 50 | void XLogYPolarDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
51 | 51 | { |
|
52 | 52 | bool axisXChanged = false; |
|
53 | 53 | bool axisYChanged = false; |
|
54 | 54 | |
|
55 | 55 | adjustLogDomainRanges(minY, maxY); |
|
56 | 56 | |
|
57 | 57 | if (!qFuzzyIsNull(m_minX - minX) || !qFuzzyIsNull(m_maxX - maxX)) { |
|
58 | 58 | m_minX = minX; |
|
59 | 59 | m_maxX = maxX; |
|
60 | 60 | axisXChanged = true; |
|
61 | 61 | if (!m_signalsBlocked) |
|
62 | 62 | emit rangeHorizontalChanged(m_minX, m_maxX); |
|
63 | 63 | } |
|
64 | 64 | |
|
65 | 65 | if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) { |
|
66 | 66 | m_minY = minY; |
|
67 | 67 | m_maxY = maxY; |
|
68 | 68 | axisYChanged = true; |
|
69 | 69 | qreal logMinY = std::log10(m_minY) / std::log10(m_logBaseY); |
|
70 | 70 | qreal logMaxY = std::log10(m_maxY) / std::log10(m_logBaseY); |
|
71 | 71 | m_logInnerY = logMinY < logMaxY ? logMinY : logMaxY; |
|
72 | 72 | m_logOuterY = logMinY > logMaxY ? logMinY : logMaxY; |
|
73 | 73 | if (!m_signalsBlocked) |
|
74 | 74 | emit rangeVerticalChanged(m_minY, m_maxY); |
|
75 | 75 | } |
|
76 | 76 | |
|
77 | 77 | if (axisXChanged || axisYChanged) |
|
78 | 78 | emit updated(); |
|
79 | 79 | } |
|
80 | 80 | |
|
81 | 81 | void XLogYPolarDomain::zoomIn(const QRectF &rect) |
|
82 | 82 | { |
|
83 | 83 | storeZoomReset(); |
|
84 | 84 | qreal dx = spanX() / m_size.width(); |
|
85 | 85 | qreal maxX = m_maxX; |
|
86 | 86 | qreal minX = m_minX; |
|
87 | 87 | |
|
88 | 88 | maxX = minX + dx * rect.right(); |
|
89 | 89 | minX = minX + dx * rect.left(); |
|
90 | 90 | |
|
91 | 91 | qreal logLeftY = m_logOuterY - rect.bottom() * (m_logOuterY - m_logInnerY) / m_size.height(); |
|
92 | 92 | qreal logRightY = m_logOuterY - rect.top() * (m_logOuterY - m_logInnerY) / m_size.height(); |
|
93 | 93 | qreal leftY = qPow(m_logBaseY, logLeftY); |
|
94 | 94 | qreal rightY = qPow(m_logBaseY, logRightY); |
|
95 | 95 | qreal minY = leftY < rightY ? leftY : rightY; |
|
96 | 96 | qreal maxY = leftY > rightY ? leftY : rightY; |
|
97 | 97 | |
|
98 | 98 | setRange(minX, maxX, minY, maxY); |
|
99 | 99 | } |
|
100 | 100 | |
|
101 | 101 | void XLogYPolarDomain::zoomOut(const QRectF &rect) |
|
102 | 102 | { |
|
103 | 103 | storeZoomReset(); |
|
104 | 104 | qreal dx = spanX() / rect.width(); |
|
105 | 105 | qreal maxX = m_maxX; |
|
106 | 106 | qreal minX = m_minX; |
|
107 | 107 | |
|
108 | 108 | minX = maxX - dx * rect.right(); |
|
109 | 109 | maxX = minX + dx * m_size.width(); |
|
110 | 110 | |
|
111 | 111 | const qreal factorY = m_size.height() / rect.height(); |
|
112 | 112 | qreal newLogMinY = m_logInnerY + (m_logOuterY - m_logInnerY) / 2.0 * (1.0 - factorY); |
|
113 | 113 | qreal newLogMaxY = m_logInnerY + (m_logOuterY - m_logInnerY) / 2.0 * (1.0 + factorY); |
|
114 | 114 | qreal leftY = qPow(m_logBaseY, newLogMinY); |
|
115 | 115 | qreal rightY = qPow(m_logBaseY, newLogMaxY); |
|
116 | 116 | qreal minY = leftY < rightY ? leftY : rightY; |
|
117 | 117 | qreal maxY = leftY > rightY ? leftY : rightY; |
|
118 | 118 | |
|
119 | 119 | setRange(minX, maxX, minY, maxY); |
|
120 | 120 | } |
|
121 | 121 | |
|
122 | 122 | void XLogYPolarDomain::move(qreal dx, qreal dy) |
|
123 | 123 | { |
|
124 | 124 | qreal x = spanX() / 360.0; |
|
125 | 125 | |
|
126 | 126 | qreal maxX = m_maxX; |
|
127 | 127 | qreal minX = m_minX; |
|
128 | 128 | |
|
129 | 129 | if (dx != 0) { |
|
130 | 130 | minX = minX + x * dx; |
|
131 | 131 | maxX = maxX + x * dx; |
|
132 | 132 | } |
|
133 | 133 | |
|
134 | 134 | qreal stepY = dy * (m_logOuterY - m_logInnerY) / m_radius; |
|
135 | 135 | qreal leftY = qPow(m_logBaseY, m_logInnerY + stepY); |
|
136 | 136 | qreal rightY = qPow(m_logBaseY, m_logOuterY + stepY); |
|
137 | 137 | qreal minY = leftY < rightY ? leftY : rightY; |
|
138 | 138 | qreal maxY = leftY > rightY ? leftY : rightY; |
|
139 | 139 | |
|
140 | 140 | setRange(minX, maxX, minY, maxY); |
|
141 | 141 | } |
|
142 | 142 | |
|
143 | 143 | qreal XLogYPolarDomain::toAngularCoordinate(qreal value, bool &ok) const |
|
144 | 144 | { |
|
145 | 145 | ok = true; |
|
146 | 146 | qreal f = (value - m_minX) / (m_maxX - m_minX); |
|
147 | 147 | return f * 360.0; |
|
148 | 148 | } |
|
149 | 149 | |
|
150 | 150 | qreal XLogYPolarDomain::toRadialCoordinate(qreal value, bool &ok) const |
|
151 | 151 | { |
|
152 | 152 | qreal retVal; |
|
153 | 153 | if (value <= 0) { |
|
154 | 154 | ok = false; |
|
155 | 155 | retVal = 0.0; |
|
156 | 156 | } else { |
|
157 | 157 | ok = true; |
|
158 | 158 | const qreal tickSpan = m_radius / qAbs(m_logOuterY - m_logInnerY); |
|
159 | 159 | const qreal logValue = std::log10(value) / std::log10(m_logBaseY); |
|
160 | 160 | const qreal valueDelta = logValue - m_logInnerY; |
|
161 | 161 | |
|
162 | 162 | retVal = valueDelta * tickSpan; |
|
163 | 163 | |
|
164 | 164 | if (retVal < 0.0) |
|
165 | 165 | retVal = 0.0; |
|
166 | 166 | } |
|
167 | 167 | return retVal; |
|
168 | 168 | } |
|
169 | 169 | |
|
170 | 170 | QPointF XLogYPolarDomain::calculateDomainPoint(const QPointF &point) const |
|
171 | 171 | { |
|
172 | 172 | if (point == m_center) |
|
173 | 173 | return QPointF(0.0, m_minY); |
|
174 | 174 | |
|
175 | 175 | QLineF line(m_center, point); |
|
176 | 176 | qreal a = 90.0 - line.angle(); |
|
177 | 177 | if (a < 0.0) |
|
178 | 178 | a += 360.0; |
|
179 | 179 | a = ((a / 360.0) * (m_maxX - m_minX)) + m_minX; |
|
180 | 180 | |
|
181 | 181 | const qreal deltaY = m_radius / qAbs(m_logOuterY - m_logInnerY); |
|
182 | 182 | qreal r = qPow(m_logBaseY, m_logInnerY + (line.length() / deltaY)); |
|
183 | 183 | |
|
184 | 184 | return QPointF(a, r); |
|
185 | 185 | } |
|
186 | 186 | |
|
187 | 187 | bool XLogYPolarDomain::attachAxis(QAbstractAxis *axis) |
|
188 | 188 | { |
|
189 | 189 | QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis); |
|
190 | 190 | |
|
191 | 191 | if (logAxis && logAxis->orientation() == Qt::Vertical) { |
|
192 | 192 | QObject::connect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleVerticalAxisBaseChanged(qreal))); |
|
193 | 193 | handleVerticalAxisBaseChanged(logAxis->base()); |
|
194 | 194 | } |
|
195 | 195 | return AbstractDomain::attachAxis(axis); |
|
196 | 196 | } |
|
197 | 197 | |
|
198 | 198 | bool XLogYPolarDomain::detachAxis(QAbstractAxis *axis) |
|
199 | 199 | { |
|
200 | 200 | QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis); |
|
201 | 201 | |
|
202 | 202 | if (logAxis && logAxis->orientation() == Qt::Vertical) |
|
203 | 203 | QObject::disconnect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleVerticalAxisBaseChanged(qreal))); |
|
204 | 204 | |
|
205 | 205 | return AbstractDomain::detachAxis(axis); |
|
206 | 206 | } |
|
207 | 207 | |
|
208 | 208 | void XLogYPolarDomain::handleVerticalAxisBaseChanged(qreal baseY) |
|
209 | 209 | { |
|
210 | 210 | m_logBaseY = baseY; |
|
211 | 211 | qreal logMinY = std::log10(m_minY) / std::log10(m_logBaseY); |
|
212 | 212 | qreal logMaxY = std::log10(m_maxY) / std::log10(m_logBaseY); |
|
213 | 213 | m_logInnerY = logMinY < logMaxY ? logMinY : logMaxY; |
|
214 | 214 | m_logOuterY = logMinY > logMaxY ? logMinY : logMaxY; |
|
215 | 215 | emit updated(); |
|
216 | 216 | } |
|
217 | 217 | |
|
218 | 218 | // operators |
|
219 | 219 | |
|
220 |
bool Q |
|
|
220 | bool Q_AUTOTEST_EXPORT operator== (const XLogYPolarDomain &domain1, const XLogYPolarDomain &domain2) | |
|
221 | 221 | { |
|
222 | 222 | return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) |
|
223 | 223 | && qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) |
|
224 | 224 | && qFuzzyIsNull(domain1.m_minX - domain2.m_minX) |
|
225 | 225 | && qFuzzyIsNull(domain1.m_minY - domain2.m_minY)); |
|
226 | 226 | } |
|
227 | 227 | |
|
228 | 228 | |
|
229 |
bool Q |
|
|
229 | bool Q_AUTOTEST_EXPORT operator!= (const XLogYPolarDomain &domain1, const XLogYPolarDomain &domain2) | |
|
230 | 230 | { |
|
231 | 231 | return !(domain1 == domain2); |
|
232 | 232 | } |
|
233 | 233 | |
|
234 | 234 | |
|
235 |
QDebug Q |
|
|
235 | QDebug Q_AUTOTEST_EXPORT operator<<(QDebug dbg, const XLogYPolarDomain &domain) | |
|
236 | 236 | { |
|
237 | 237 | #ifdef QT_NO_TEXTSTREAM |
|
238 | 238 | Q_UNUSED(domain) |
|
239 | 239 | #else |
|
240 | 240 | dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size; |
|
241 | 241 | #endif |
|
242 | 242 | return dbg.maybeSpace(); |
|
243 | 243 | } |
|
244 | 244 | |
|
245 | 245 | #include "moc_xlogypolardomain_p.cpp" |
|
246 | 246 | |
|
247 | 247 | QT_CHARTS_END_NAMESPACE |
@@ -1,86 +1,86 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | // W A R N I N G |
|
31 | 31 | // ------------- |
|
32 | 32 | // |
|
33 | 33 | // This file is not part of the Qt Chart API. It exists purely as an |
|
34 | 34 | // implementation detail. This header file may change from version to |
|
35 | 35 | // version without notice, or even be removed. |
|
36 | 36 | // |
|
37 | 37 | // We mean it. |
|
38 | 38 | |
|
39 | 39 | #ifndef XLOGYPOLARDOMAIN_H |
|
40 | 40 | #define XLOGYPOLARDOMAIN_H |
|
41 | 41 | #include <private/polardomain_p.h> |
|
42 | 42 | #include <QtCore/QRectF> |
|
43 | 43 | #include <QtCore/QSizeF> |
|
44 | 44 | |
|
45 | 45 | QT_CHARTS_BEGIN_NAMESPACE |
|
46 | 46 | |
|
47 |
class Q |
|
|
47 | class Q_AUTOTEST_EXPORT XLogYPolarDomain: public PolarDomain | |
|
48 | 48 | { |
|
49 | 49 | Q_OBJECT |
|
50 | 50 | public: |
|
51 | 51 | explicit XLogYPolarDomain(QObject *object = 0); |
|
52 | 52 | virtual ~XLogYPolarDomain(); |
|
53 | 53 | |
|
54 | 54 | DomainType type() { return AbstractDomain::XLogYPolarDomain; } |
|
55 | 55 | |
|
56 | 56 | void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
57 | 57 | |
|
58 |
friend bool Q |
|
|
59 |
friend bool Q |
|
|
60 |
friend QDebug Q |
|
|
58 | friend bool Q_AUTOTEST_EXPORT operator== (const XLogYPolarDomain &domain1, const XLogYPolarDomain &domain2); | |
|
59 | friend bool Q_AUTOTEST_EXPORT operator!= (const XLogYPolarDomain &domain1, const XLogYPolarDomain &domain2); | |
|
60 | friend QDebug Q_AUTOTEST_EXPORT operator<<(QDebug dbg, const XLogYPolarDomain &domain); | |
|
61 | 61 | |
|
62 | 62 | void zoomIn(const QRectF &rect); |
|
63 | 63 | void zoomOut(const QRectF &rect); |
|
64 | 64 | void move(qreal dx, qreal dy); |
|
65 | 65 | |
|
66 | 66 | QPointF calculateDomainPoint(const QPointF &point) const; |
|
67 | 67 | |
|
68 | 68 | bool attachAxis(QAbstractAxis *axis); |
|
69 | 69 | bool detachAxis(QAbstractAxis *axis); |
|
70 | 70 | |
|
71 | 71 | public Q_SLOTS: |
|
72 | 72 | void handleVerticalAxisBaseChanged(qreal baseY); |
|
73 | 73 | |
|
74 | 74 | protected: |
|
75 | 75 | qreal toAngularCoordinate(qreal value, bool &ok) const; |
|
76 | 76 | qreal toRadialCoordinate(qreal value, bool &ok) const; |
|
77 | 77 | |
|
78 | 78 | private: |
|
79 | 79 | qreal m_logInnerY; |
|
80 | 80 | qreal m_logOuterY; |
|
81 | 81 | qreal m_logBaseY; |
|
82 | 82 | }; |
|
83 | 83 | |
|
84 | 84 | QT_CHARTS_END_NAMESPACE |
|
85 | 85 | |
|
86 | 86 | #endif // XLOGYPOLARDOMAIN_H |
@@ -1,213 +1,213 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #include <private/xydomain_p.h> |
|
31 | 31 | #include <private/qabstractaxis_p.h> |
|
32 | 32 | #include <QtCore/QtMath> |
|
33 | 33 | |
|
34 | 34 | QT_CHARTS_BEGIN_NAMESPACE |
|
35 | 35 | |
|
36 | 36 | XYDomain::XYDomain(QObject *parent) |
|
37 | 37 | : AbstractDomain(parent) |
|
38 | 38 | { |
|
39 | 39 | } |
|
40 | 40 | |
|
41 | 41 | XYDomain::~XYDomain() |
|
42 | 42 | { |
|
43 | 43 | } |
|
44 | 44 | |
|
45 | 45 | void XYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
46 | 46 | { |
|
47 | 47 | bool axisXChanged = false; |
|
48 | 48 | bool axisYChanged = false; |
|
49 | 49 | |
|
50 | 50 | if (!qFuzzyCompare(m_minX, minX) || !qFuzzyCompare(m_maxX, maxX)) { |
|
51 | 51 | m_minX = minX; |
|
52 | 52 | m_maxX = maxX; |
|
53 | 53 | axisXChanged = true; |
|
54 | 54 | if(!m_signalsBlocked) |
|
55 | 55 | emit rangeHorizontalChanged(m_minX, m_maxX); |
|
56 | 56 | } |
|
57 | 57 | |
|
58 | 58 | if (!qFuzzyCompare(m_minY, minY) || !qFuzzyCompare(m_maxY, maxY)) { |
|
59 | 59 | m_minY = minY; |
|
60 | 60 | m_maxY = maxY; |
|
61 | 61 | axisYChanged = true; |
|
62 | 62 | if(!m_signalsBlocked) |
|
63 | 63 | emit rangeVerticalChanged(m_minY, m_maxY); |
|
64 | 64 | } |
|
65 | 65 | |
|
66 | 66 | if (axisXChanged || axisYChanged) |
|
67 | 67 | emit updated(); |
|
68 | 68 | } |
|
69 | 69 | |
|
70 | 70 | |
|
71 | 71 | void XYDomain::zoomIn(const QRectF &rect) |
|
72 | 72 | { |
|
73 | 73 | storeZoomReset(); |
|
74 | 74 | qreal dx = spanX() / m_size.width(); |
|
75 | 75 | qreal dy = spanY() / m_size.height(); |
|
76 | 76 | |
|
77 | 77 | qreal maxX = m_maxX; |
|
78 | 78 | qreal minX = m_minX; |
|
79 | 79 | qreal minY = m_minY; |
|
80 | 80 | qreal maxY = m_maxY; |
|
81 | 81 | |
|
82 | 82 | maxX = minX + dx * rect.right(); |
|
83 | 83 | minX = minX + dx * rect.left(); |
|
84 | 84 | minY = maxY - dy * rect.bottom(); |
|
85 | 85 | maxY = maxY - dy * rect.top(); |
|
86 | 86 | |
|
87 | 87 | if ((maxX - minX) == spanX()) { |
|
88 | 88 | minX = m_minX; |
|
89 | 89 | maxX = m_maxX; |
|
90 | 90 | } |
|
91 | 91 | if ((maxY - minY) == spanY()) { |
|
92 | 92 | minY = m_minY; |
|
93 | 93 | maxY = m_maxY; |
|
94 | 94 | } |
|
95 | 95 | |
|
96 | 96 | setRange(minX, maxX, minY, maxY); |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | 99 | void XYDomain::zoomOut(const QRectF &rect) |
|
100 | 100 | { |
|
101 | 101 | storeZoomReset(); |
|
102 | 102 | qreal dx = spanX() / rect.width(); |
|
103 | 103 | qreal dy = spanY() / rect.height(); |
|
104 | 104 | |
|
105 | 105 | qreal maxX = m_maxX; |
|
106 | 106 | qreal minX = m_minX; |
|
107 | 107 | qreal minY = m_minY; |
|
108 | 108 | qreal maxY = m_maxY; |
|
109 | 109 | |
|
110 | 110 | minX = maxX - dx * rect.right(); |
|
111 | 111 | maxX = minX + dx * m_size.width(); |
|
112 | 112 | maxY = minY + dy * rect.bottom(); |
|
113 | 113 | minY = maxY - dy * m_size.height(); |
|
114 | 114 | |
|
115 | 115 | if ((maxX - minX) == spanX()) { |
|
116 | 116 | minX = m_minX; |
|
117 | 117 | maxX = m_maxX; |
|
118 | 118 | } |
|
119 | 119 | if ((maxY - minY) == spanY()) { |
|
120 | 120 | minY = m_minY; |
|
121 | 121 | maxY = m_maxY; |
|
122 | 122 | } |
|
123 | 123 | |
|
124 | 124 | setRange(minX, maxX, minY, maxY); |
|
125 | 125 | } |
|
126 | 126 | |
|
127 | 127 | void XYDomain::move(qreal dx, qreal dy) |
|
128 | 128 | { |
|
129 | 129 | qreal x = spanX() / m_size.width(); |
|
130 | 130 | qreal y = spanY() / m_size.height(); |
|
131 | 131 | |
|
132 | 132 | qreal maxX = m_maxX; |
|
133 | 133 | qreal minX = m_minX; |
|
134 | 134 | qreal minY = m_minY; |
|
135 | 135 | qreal maxY = m_maxY; |
|
136 | 136 | |
|
137 | 137 | if (dx != 0) { |
|
138 | 138 | minX = minX + x * dx; |
|
139 | 139 | maxX = maxX + x * dx; |
|
140 | 140 | } |
|
141 | 141 | if (dy != 0) { |
|
142 | 142 | minY = minY + y * dy; |
|
143 | 143 | maxY = maxY + y * dy; |
|
144 | 144 | } |
|
145 | 145 | setRange(minX, maxX, minY, maxY); |
|
146 | 146 | } |
|
147 | 147 | |
|
148 | 148 | QPointF XYDomain::calculateGeometryPoint(const QPointF &point, bool &ok) const |
|
149 | 149 | { |
|
150 | 150 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); |
|
151 | 151 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); |
|
152 | 152 | qreal x = (point.x() - m_minX) * deltaX; |
|
153 | 153 | qreal y = (point.y() - m_minY) * -deltaY + m_size.height(); |
|
154 | 154 | ok = true; |
|
155 | 155 | return QPointF(x, y); |
|
156 | 156 | } |
|
157 | 157 | |
|
158 | 158 | QVector<QPointF> XYDomain::calculateGeometryPoints(const QVector<QPointF> &vector) const |
|
159 | 159 | { |
|
160 | 160 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); |
|
161 | 161 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); |
|
162 | 162 | |
|
163 | 163 | QVector<QPointF> result; |
|
164 | 164 | result.resize(vector.count()); |
|
165 | 165 | |
|
166 | 166 | for (int i = 0; i < vector.count(); ++i) { |
|
167 | 167 | qreal x = (vector[i].x() - m_minX) * deltaX; |
|
168 | 168 | qreal y = (vector[i].y() - m_minY) * -deltaY + m_size.height(); |
|
169 | 169 | result[i].setX(x); |
|
170 | 170 | result[i].setY(y); |
|
171 | 171 | } |
|
172 | 172 | return result; |
|
173 | 173 | } |
|
174 | 174 | |
|
175 | 175 | QPointF XYDomain::calculateDomainPoint(const QPointF &point) const |
|
176 | 176 | { |
|
177 | 177 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); |
|
178 | 178 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); |
|
179 | 179 | qreal x = point.x() / deltaX + m_minX; |
|
180 | 180 | qreal y = (point.y() - m_size.height()) / (-deltaY) + m_minY; |
|
181 | 181 | return QPointF(x, y); |
|
182 | 182 | } |
|
183 | 183 | |
|
184 | 184 | // operators |
|
185 | 185 | |
|
186 |
bool Q |
|
|
186 | bool Q_AUTOTEST_EXPORT operator== (const XYDomain &domain1, const XYDomain &domain2) | |
|
187 | 187 | { |
|
188 | 188 | return (qFuzzyCompare(domain1.m_maxX, domain2.m_maxX) |
|
189 | 189 | && qFuzzyCompare(domain1.m_maxY, domain2.m_maxY) |
|
190 | 190 | && qFuzzyCompare(domain1.m_minX, domain2.m_minX) |
|
191 | 191 | && qFuzzyCompare(domain1.m_minY, domain2.m_minY)); |
|
192 | 192 | } |
|
193 | 193 | |
|
194 | 194 | |
|
195 |
bool Q |
|
|
195 | bool Q_AUTOTEST_EXPORT operator!= (const XYDomain &domain1, const XYDomain &domain2) | |
|
196 | 196 | { |
|
197 | 197 | return !(domain1 == domain2); |
|
198 | 198 | } |
|
199 | 199 | |
|
200 | 200 | |
|
201 |
QDebug Q |
|
|
201 | QDebug Q_AUTOTEST_EXPORT operator<<(QDebug dbg, const XYDomain &domain) | |
|
202 | 202 | { |
|
203 | 203 | #ifdef QT_NO_TEXTSTREAM |
|
204 | 204 | Q_UNUSED(domain) |
|
205 | 205 | #else |
|
206 | 206 | dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size; |
|
207 | 207 | #endif |
|
208 | 208 | return dbg.maybeSpace(); |
|
209 | 209 | } |
|
210 | 210 | |
|
211 | 211 | #include "moc_xydomain_p.cpp" |
|
212 | 212 | |
|
213 | 213 | QT_CHARTS_END_NAMESPACE |
@@ -1,73 +1,73 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | // W A R N I N G |
|
31 | 31 | // ------------- |
|
32 | 32 | // |
|
33 | 33 | // This file is not part of the Qt Chart API. It exists purely as an |
|
34 | 34 | // implementation detail. This header file may change from version to |
|
35 | 35 | // version without notice, or even be removed. |
|
36 | 36 | // |
|
37 | 37 | // We mean it. |
|
38 | 38 | |
|
39 | 39 | #ifndef XYDOMAIN_H |
|
40 | 40 | #define XYDOMAIN_H |
|
41 | 41 | #include <private/abstractdomain_p.h> |
|
42 | 42 | #include <QtCore/QRectF> |
|
43 | 43 | #include <QtCore/QSizeF> |
|
44 | 44 | |
|
45 | 45 | QT_CHARTS_BEGIN_NAMESPACE |
|
46 | 46 | |
|
47 |
class Q |
|
|
47 | class Q_AUTOTEST_EXPORT XYDomain: public AbstractDomain | |
|
48 | 48 | { |
|
49 | 49 | Q_OBJECT |
|
50 | 50 | public: |
|
51 | 51 | explicit XYDomain(QObject *object = 0); |
|
52 | 52 | virtual ~XYDomain(); |
|
53 | 53 | |
|
54 | 54 | DomainType type(){ return AbstractDomain::XYDomain;} |
|
55 | 55 | |
|
56 | 56 | void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
57 | 57 | |
|
58 |
friend bool Q |
|
|
59 |
friend bool Q |
|
|
60 |
friend QDebug Q |
|
|
58 | friend bool Q_AUTOTEST_EXPORT operator== (const XYDomain &Domain1, const XYDomain &Domain2); | |
|
59 | friend bool Q_AUTOTEST_EXPORT operator!= (const XYDomain &Domain1, const XYDomain &Domain2); | |
|
60 | friend QDebug Q_AUTOTEST_EXPORT operator<<(QDebug dbg, const XYDomain &AbstractDomain); | |
|
61 | 61 | |
|
62 | 62 | void zoomIn(const QRectF &rect); |
|
63 | 63 | void zoomOut(const QRectF &rect); |
|
64 | 64 | void move(qreal dx, qreal dy); |
|
65 | 65 | |
|
66 | 66 | QPointF calculateGeometryPoint(const QPointF &point, bool &ok) const; |
|
67 | 67 | QPointF calculateDomainPoint(const QPointF &point) const; |
|
68 | 68 | QVector<QPointF> calculateGeometryPoints(const QVector<QPointF> &vector) const; |
|
69 | 69 | }; |
|
70 | 70 | |
|
71 | 71 | QT_CHARTS_END_NAMESPACE |
|
72 | 72 | |
|
73 | 73 | #endif // XYDOMAIN_H |
@@ -1,193 +1,193 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #include <private/xypolardomain_p.h> |
|
31 | 31 | #include <private/qabstractaxis_p.h> |
|
32 | 32 | #include <QtCore/QtMath> |
|
33 | 33 | |
|
34 | 34 | QT_CHARTS_BEGIN_NAMESPACE |
|
35 | 35 | |
|
36 | 36 | XYPolarDomain::XYPolarDomain(QObject *parent) |
|
37 | 37 | : PolarDomain(parent) |
|
38 | 38 | { |
|
39 | 39 | } |
|
40 | 40 | |
|
41 | 41 | XYPolarDomain::~XYPolarDomain() |
|
42 | 42 | { |
|
43 | 43 | } |
|
44 | 44 | |
|
45 | 45 | void XYPolarDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
46 | 46 | { |
|
47 | 47 | bool axisXChanged = false; |
|
48 | 48 | bool axisYChanged = false; |
|
49 | 49 | |
|
50 | 50 | if (!qFuzzyCompare(m_minX, minX) || !qFuzzyCompare(m_maxX, maxX)) { |
|
51 | 51 | m_minX = minX; |
|
52 | 52 | m_maxX = maxX; |
|
53 | 53 | axisXChanged = true; |
|
54 | 54 | if (!m_signalsBlocked) |
|
55 | 55 | emit rangeHorizontalChanged(m_minX, m_maxX); |
|
56 | 56 | } |
|
57 | 57 | |
|
58 | 58 | if (!qFuzzyCompare(m_minY, minY) || !qFuzzyCompare(m_maxY, maxY)) { |
|
59 | 59 | m_minY = minY; |
|
60 | 60 | m_maxY = maxY; |
|
61 | 61 | axisYChanged = true; |
|
62 | 62 | if (!m_signalsBlocked) |
|
63 | 63 | emit rangeVerticalChanged(m_minY, m_maxY); |
|
64 | 64 | } |
|
65 | 65 | |
|
66 | 66 | if (axisXChanged || axisYChanged) |
|
67 | 67 | emit updated(); |
|
68 | 68 | } |
|
69 | 69 | |
|
70 | 70 | |
|
71 | 71 | void XYPolarDomain::zoomIn(const QRectF &rect) |
|
72 | 72 | { |
|
73 | 73 | storeZoomReset(); |
|
74 | 74 | qreal dx = spanX() / m_size.width(); |
|
75 | 75 | qreal dy = spanY() / m_size.height(); |
|
76 | 76 | |
|
77 | 77 | qreal maxX = m_maxX; |
|
78 | 78 | qreal minX = m_minX; |
|
79 | 79 | qreal minY = m_minY; |
|
80 | 80 | qreal maxY = m_maxY; |
|
81 | 81 | |
|
82 | 82 | maxX = minX + dx * rect.right(); |
|
83 | 83 | minX = minX + dx * rect.left(); |
|
84 | 84 | minY = maxY - dy * rect.bottom(); |
|
85 | 85 | maxY = maxY - dy * rect.top(); |
|
86 | 86 | |
|
87 | 87 | setRange(minX, maxX, minY, maxY); |
|
88 | 88 | } |
|
89 | 89 | |
|
90 | 90 | void XYPolarDomain::zoomOut(const QRectF &rect) |
|
91 | 91 | { |
|
92 | 92 | storeZoomReset(); |
|
93 | 93 | qreal dx = spanX() / rect.width(); |
|
94 | 94 | qreal dy = spanY() / rect.height(); |
|
95 | 95 | |
|
96 | 96 | qreal maxX = m_maxX; |
|
97 | 97 | qreal minX = m_minX; |
|
98 | 98 | qreal minY = m_minY; |
|
99 | 99 | qreal maxY = m_maxY; |
|
100 | 100 | |
|
101 | 101 | minX = maxX - dx * rect.right(); |
|
102 | 102 | maxX = minX + dx * m_size.width(); |
|
103 | 103 | maxY = minY + dy * rect.bottom(); |
|
104 | 104 | minY = maxY - dy * m_size.height(); |
|
105 | 105 | |
|
106 | 106 | setRange(minX, maxX, minY, maxY); |
|
107 | 107 | } |
|
108 | 108 | |
|
109 | 109 | void XYPolarDomain::move(qreal dx, qreal dy) |
|
110 | 110 | { |
|
111 | 111 | // One unit scrolls one degree angular and one pixel radial |
|
112 | 112 | qreal x = spanX() / 360.0; |
|
113 | 113 | qreal y = spanY() / m_radius; |
|
114 | 114 | |
|
115 | 115 | qreal maxX = m_maxX; |
|
116 | 116 | qreal minX = m_minX; |
|
117 | 117 | qreal minY = m_minY; |
|
118 | 118 | qreal maxY = m_maxY; |
|
119 | 119 | |
|
120 | 120 | if (dx != 0) { |
|
121 | 121 | minX = minX + x * dx; |
|
122 | 122 | maxX = maxX + x * dx; |
|
123 | 123 | } |
|
124 | 124 | if (dy != 0) { |
|
125 | 125 | minY = minY + y * dy; |
|
126 | 126 | maxY = maxY + y * dy; |
|
127 | 127 | } |
|
128 | 128 | setRange(minX, maxX, minY, maxY); |
|
129 | 129 | } |
|
130 | 130 | |
|
131 | 131 | QPointF XYPolarDomain::calculateDomainPoint(const QPointF &point) const |
|
132 | 132 | { |
|
133 | 133 | if (point == m_center) |
|
134 | 134 | return QPointF(0.0, m_minX); |
|
135 | 135 | |
|
136 | 136 | QLineF line(m_center, point); |
|
137 | 137 | qreal a = 90.0 - line.angle(); |
|
138 | 138 | if (a < 0.0) |
|
139 | 139 | a += 360.0; |
|
140 | 140 | a = ((a / 360.0) * (m_maxX - m_minX)) + m_minX; |
|
141 | 141 | qreal r = m_minY + ((m_maxY - m_minY) * (line.length() / m_radius)); |
|
142 | 142 | return QPointF(a, r); |
|
143 | 143 | } |
|
144 | 144 | |
|
145 | 145 | qreal XYPolarDomain::toAngularCoordinate(qreal value, bool &ok) const |
|
146 | 146 | { |
|
147 | 147 | ok = true; |
|
148 | 148 | qreal f = (value - m_minX) / (m_maxX - m_minX); |
|
149 | 149 | return f * 360.0; |
|
150 | 150 | } |
|
151 | 151 | |
|
152 | 152 | qreal XYPolarDomain::toRadialCoordinate(qreal value, bool &ok) const |
|
153 | 153 | { |
|
154 | 154 | ok = true; |
|
155 | 155 | if (value < m_minY) |
|
156 | 156 | value = m_minY; |
|
157 | 157 | |
|
158 | 158 | // Dont limit the max. The drawing should clip the stuff that goes out of the grid |
|
159 | 159 | qreal f = (value - m_minY) / (m_maxY - m_minY); |
|
160 | 160 | |
|
161 | 161 | return f * m_radius; |
|
162 | 162 | } |
|
163 | 163 | |
|
164 | 164 | // operators |
|
165 | 165 | |
|
166 |
bool Q |
|
|
166 | bool Q_AUTOTEST_EXPORT operator== (const XYPolarDomain &domain1, const XYPolarDomain &domain2) | |
|
167 | 167 | { |
|
168 | 168 | return (qFuzzyCompare(domain1.m_maxX, domain2.m_maxX) |
|
169 | 169 | && qFuzzyCompare(domain1.m_maxY, domain2.m_maxY) |
|
170 | 170 | && qFuzzyCompare(domain1.m_minX, domain2.m_minX) |
|
171 | 171 | && qFuzzyCompare(domain1.m_minY, domain2.m_minY)); |
|
172 | 172 | } |
|
173 | 173 | |
|
174 | 174 | |
|
175 |
bool Q |
|
|
175 | bool Q_AUTOTEST_EXPORT operator!= (const XYPolarDomain &domain1, const XYPolarDomain &domain2) | |
|
176 | 176 | { |
|
177 | 177 | return !(domain1 == domain2); |
|
178 | 178 | } |
|
179 | 179 | |
|
180 | 180 | |
|
181 |
QDebug Q |
|
|
181 | QDebug Q_AUTOTEST_EXPORT operator<<(QDebug dbg, const XYPolarDomain &domain) | |
|
182 | 182 | { |
|
183 | 183 | #ifdef QT_NO_TEXTSTREAM |
|
184 | 184 | Q_UNUSED(domain) |
|
185 | 185 | #else |
|
186 | 186 | dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size; |
|
187 | 187 | #endif |
|
188 | 188 | return dbg.maybeSpace(); |
|
189 | 189 | } |
|
190 | 190 | |
|
191 | 191 | #include "moc_xypolardomain_p.cpp" |
|
192 | 192 | |
|
193 | 193 | QT_CHARTS_END_NAMESPACE |
@@ -1,74 +1,74 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | // W A R N I N G |
|
31 | 31 | // ------------- |
|
32 | 32 | // |
|
33 | 33 | // This file is not part of the Qt Chart API. It exists purely as an |
|
34 | 34 | // implementation detail. This header file may change from version to |
|
35 | 35 | // version without notice, or even be removed. |
|
36 | 36 | // |
|
37 | 37 | // We mean it. |
|
38 | 38 | |
|
39 | 39 | #ifndef XYPOLARDOMAIN_H |
|
40 | 40 | #define XYPOLARDOMAIN_H |
|
41 | 41 | #include <private/polardomain_p.h> |
|
42 | 42 | #include <QtCore/QRectF> |
|
43 | 43 | |
|
44 | 44 | QT_CHARTS_BEGIN_NAMESPACE |
|
45 | 45 | |
|
46 |
class Q |
|
|
46 | class Q_AUTOTEST_EXPORT XYPolarDomain: public PolarDomain | |
|
47 | 47 | { |
|
48 | 48 | Q_OBJECT |
|
49 | 49 | public: |
|
50 | 50 | explicit XYPolarDomain(QObject *object = 0); |
|
51 | 51 | virtual ~XYPolarDomain(); |
|
52 | 52 | |
|
53 | 53 | DomainType type(){ return AbstractDomain::XYPolarDomain;} |
|
54 | 54 | |
|
55 | 55 | void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
56 | 56 | |
|
57 |
friend bool Q |
|
|
58 |
friend bool Q |
|
|
59 |
friend QDebug Q |
|
|
57 | friend bool Q_AUTOTEST_EXPORT operator== (const XYPolarDomain &Domain1, const XYPolarDomain &Domain2); | |
|
58 | friend bool Q_AUTOTEST_EXPORT operator!= (const XYPolarDomain &Domain1, const XYPolarDomain &Domain2); | |
|
59 | friend QDebug Q_AUTOTEST_EXPORT operator<<(QDebug dbg, const XYPolarDomain &AbstractDomain); | |
|
60 | 60 | |
|
61 | 61 | void zoomIn(const QRectF &rect); |
|
62 | 62 | void zoomOut(const QRectF &rect); |
|
63 | 63 | void move(qreal dx, qreal dy); |
|
64 | 64 | |
|
65 | 65 | QPointF calculateDomainPoint(const QPointF &point) const; |
|
66 | 66 | |
|
67 | 67 | protected: |
|
68 | 68 | qreal toAngularCoordinate(qreal value, bool &ok) const; |
|
69 | 69 | qreal toRadialCoordinate(qreal value, bool &ok) const; |
|
70 | 70 | }; |
|
71 | 71 | |
|
72 | 72 | QT_CHARTS_END_NAMESPACE |
|
73 | 73 | |
|
74 | 74 | #endif // XYPOLARDOMAIN_H |
@@ -1,87 +1,79 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QCHARTGLOBAL_H |
|
31 | 31 | #define QCHARTGLOBAL_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCore/QtGlobal> |
|
34 | 34 | |
|
35 | 35 | #define QT_CHARTS_VERSION_STR "2.1.0" |
|
36 | 36 | /* |
|
37 | 37 | QT_CHARTS_VERSION is (major << 16) + (minor << 8) + patch. |
|
38 | 38 | */ |
|
39 | 39 | #define QT_CHARTS_VERSION 0x020100 |
|
40 | 40 | /* |
|
41 | 41 | can be used like #if (QT_CHARTS_VERSION >= QT_CHARTS_VERSION_CHECK(1, 1, 0)) |
|
42 | 42 | */ |
|
43 | 43 | #define QT_CHARTS_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch)) |
|
44 | 44 | |
|
45 | 45 | #if defined(QT_CHARTS_LIBRARY) |
|
46 | 46 | # define QT_CHARTS_EXPORT Q_DECL_EXPORT |
|
47 | 47 | #else |
|
48 | 48 | # define QT_CHARTS_EXPORT Q_DECL_IMPORT |
|
49 | 49 | #endif |
|
50 | 50 | |
|
51 | #if defined(BUILD_PRIVATE_UNIT_TESTS) && defined(QT_CHARTS_LIBRARY) | |
|
52 | # define QT_CHARTS_AUTOTEST_EXPORT Q_DECL_EXPORT | |
|
53 | #elif defined(BUILD_PRIVATE_UNIT_TESTS) && !defined(QT_CHARTS_LIBRARY) | |
|
54 | # define QT_CHARTS_AUTOTEST_EXPORT Q_DECL_IMPORT | |
|
55 | #else | |
|
56 | # define QT_CHARTS_AUTOTEST_EXPORT | |
|
57 | #endif | |
|
58 | ||
|
59 | 51 | #ifdef QT_CHARTS_STATICLIB |
|
60 | 52 | # undef QT_CHARTS_EXPORT |
|
61 |
# undef Q |
|
|
53 | # undef Q_AUTOTEST_EXPORT | |
|
62 | 54 | # define QT_CHARTS_EXPORT |
|
63 |
# define Q |
|
|
55 | # define Q_AUTOTEST_EXPORT | |
|
64 | 56 | #endif |
|
65 | 57 | |
|
66 | 58 | #define QT_CHARTS_NAMESPACE QtCharts |
|
67 | 59 | |
|
68 | 60 | #ifdef QT_CHARTS_NAMESPACE |
|
69 | 61 | # define QT_CHARTS_BEGIN_NAMESPACE namespace QT_CHARTS_NAMESPACE { |
|
70 | 62 | # define QT_CHARTS_END_NAMESPACE } |
|
71 | 63 | # define QT_CHARTS_USE_NAMESPACE using namespace QT_CHARTS_NAMESPACE; |
|
72 | 64 | #else |
|
73 | 65 | # define QT_CHARTS_BEGIN_NAMESPACE |
|
74 | 66 | # define QT_CHARTS_END_NAMESPACE |
|
75 | 67 | # define QT_CHARTS_USE_NAMESPACE |
|
76 | 68 | #endif |
|
77 | 69 | |
|
78 | 70 | /* |
|
79 | 71 | On Windows min and max conflict with standard macros |
|
80 | 72 | */ |
|
81 | 73 | #ifdef Q_OS_WIN |
|
82 | 74 | #ifndef NOMINMAX |
|
83 | 75 | #define NOMINMAX |
|
84 | 76 | #endif |
|
85 | 77 | #endif |
|
86 | 78 | |
|
87 | 79 | #endif // QCHARTGLOBAL_H |
@@ -1,15 +1,10 | |||
|
1 | 1 | !include( ../tests.pri ) { |
|
2 | 2 | error( "Couldn't find the tests.pri file!" ) |
|
3 | 3 | } |
|
4 | 4 | |
|
5 | 5 | QT += testlib widgets |
|
6 | 6 | |
|
7 | 7 | !contains(TARGET, ^tst_.*):TARGET = $$join(TARGET,,"tst_") |
|
8 | 8 | |
|
9 | 9 | INCLUDEPATH += ../inc |
|
10 | 10 | HEADERS += ../inc/tst_definitions.h |
|
11 | ||
|
12 | #Define for unit tests | |
|
13 | CONFIG(debug, debug|release) { | |
|
14 | DEFINES += BUILD_PRIVATE_UNIT_TESTS | |
|
15 | } |
@@ -1,36 +1,41 | |||
|
1 | 1 | TEMPLATE = subdirs |
|
2 | 2 | SUBDIRS += \ |
|
3 | 3 | qchartview \ |
|
4 | 4 | qchart \ |
|
5 | 5 | qlineseries \ |
|
6 | 6 | qbarset \ |
|
7 | 7 | qbarseries \ |
|
8 | 8 | qstackedbarseries \ |
|
9 | 9 | qpercentbarseries \ |
|
10 | 10 | qpieslice qpieseries \ |
|
11 | 11 | qpiemodelmapper \ |
|
12 | 12 | qsplineseries \ |
|
13 | 13 | qscatterseries \ |
|
14 | 14 | qxymodelmapper \ |
|
15 | 15 | qbarmodelmapper \ |
|
16 | 16 | qhorizontalbarseries \ |
|
17 | 17 | qhorizontalstackedbarseries \ |
|
18 | 18 | qhorizontalpercentbarseries \ |
|
19 | 19 | qvalueaxis \ |
|
20 | 20 | qlogvalueaxis \ |
|
21 | 21 | qcategoryaxis \ |
|
22 | 22 | qbarcategoryaxis \ |
|
23 | 23 | domain \ |
|
24 | 24 | chartdataset \ |
|
25 | 25 | qlegend \ |
|
26 | 26 | cmake |
|
27 | 27 | |
|
28 | 28 | !linux-arm*: { |
|
29 | 29 | SUBDIRS += \ |
|
30 | 30 | qdatetimeaxis |
|
31 | 31 | } |
|
32 | 32 | |
|
33 | 33 | qtHaveModule(quick) { |
|
34 | 34 | SUBDIRS += qml \ |
|
35 | 35 | qml-qtquicktest |
|
36 | 36 | } |
|
37 | ||
|
38 | !contains(QT_CONFIG, private_tests): SUBDIRS -= \ | |
|
39 | domain \ | |
|
40 | chartdataset | |
|
41 |
@@ -1,407 +1,385 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | #ifndef BUILD_PRIVATE_UNIT_TESTS | |
|
30 | #include <QtTest/QtTest> | |
|
31 | ||
|
32 | class tst_ChartDataSet: public QObject { | |
|
33 | ||
|
34 | Q_OBJECT | |
|
35 | ||
|
36 | private Q_SLOTS: | |
|
37 | void skip(); | |
|
38 | ||
|
39 | }; | |
|
40 | ||
|
41 | void tst_ChartDataSet::skip() | |
|
42 | { | |
|
43 | QSKIP("This test requires the debug version of library"); | |
|
44 | } | |
|
45 | ||
|
46 | QTEST_MAIN(tst_ChartDataSet) | |
|
47 | #include "tst_chartdataset.moc" | |
|
48 | ||
|
49 | #else | |
|
50 | 29 | |
|
51 | 30 | #include <QtTest/QtTest> |
|
52 | 31 | #include <QtCharts/QAbstractAxis> |
|
53 | 32 | #include <QtCharts/QValueAxis> |
|
54 | 33 | #include <QtCharts/QBarCategoryAxis> |
|
55 | 34 | #include <QtCharts/QCategoryAxis> |
|
56 | 35 | #ifndef QT_ON_ARM |
|
57 | 36 | #include <QtCharts/QDateTimeAxis> |
|
58 | 37 | #endif |
|
59 | 38 | #include <QtCharts/QLineSeries> |
|
60 | 39 | #include <QtCharts/QAreaSeries> |
|
61 | 40 | #include <QtCharts/QScatterSeries> |
|
62 | 41 | #include <QtCharts/QSplineSeries> |
|
63 | 42 | #include <QtCharts/QPieSeries> |
|
64 | 43 | #include <QtCharts/QBarSeries> |
|
65 | 44 | #include <QtCharts/QPercentBarSeries> |
|
66 | 45 | #include <QtCharts/QStackedBarSeries> |
|
67 | 46 | #include <private/chartdataset_p.h> |
|
68 | 47 | #include <private/abstractdomain_p.h> |
|
69 | 48 | #include <tst_definitions.h> |
|
70 | 49 | |
|
71 | 50 | QT_CHARTS_USE_NAMESPACE |
|
72 | 51 | |
|
73 | 52 | Q_DECLARE_METATYPE(AbstractDomain *) |
|
74 | 53 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
75 | 54 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
76 | 55 | Q_DECLARE_METATYPE(QList<QAbstractSeries *>) |
|
77 | 56 | Q_DECLARE_METATYPE(QList<QAbstractAxis *>) |
|
78 | 57 | Q_DECLARE_METATYPE(Qt::Alignment) |
|
79 | 58 | Q_DECLARE_METATYPE(QList<Qt::Alignment>) |
|
80 | 59 | Q_DECLARE_METATYPE(QLineSeries *) |
|
81 | 60 | |
|
82 | 61 | class tst_ChartDataSet: public QObject { |
|
83 | 62 | |
|
84 | 63 | Q_OBJECT |
|
85 | 64 | public: |
|
86 | 65 | tst_ChartDataSet():m_dataset(0){}; |
|
87 | 66 | |
|
88 | 67 | public Q_SLOTS: |
|
89 | 68 | void initTestCase(); |
|
90 | 69 | void cleanupTestCase(); |
|
91 | 70 | void init(); |
|
92 | 71 | void cleanup(); |
|
93 | 72 | |
|
94 | 73 | private Q_SLOTS: |
|
95 | 74 | void chartdataset_data(); |
|
96 | 75 | void chartdataset(); |
|
97 | 76 | void addSeries_data(); |
|
98 | 77 | void addSeries(); |
|
99 | 78 | void removeSeries_data(); |
|
100 | 79 | void removeSeries(); |
|
101 | 80 | void addAxis_data(); |
|
102 | 81 | void addAxis(); |
|
103 | 82 | void removeAxis_data(); |
|
104 | 83 | void removeAxis(); |
|
105 | 84 | void attachAxis_data(); |
|
106 | 85 | void attachAxis(); |
|
107 | 86 | void detachAxis_data(); |
|
108 | 87 | void detachAxis(); |
|
109 | 88 | |
|
110 | 89 | private: |
|
111 | 90 | ChartDataSet* m_dataset; |
|
112 | 91 | }; |
|
113 | 92 | |
|
114 | 93 | void tst_ChartDataSet::initTestCase() |
|
115 | 94 | { |
|
116 | 95 | qRegisterMetaType<AbstractDomain*>(); |
|
117 | 96 | qRegisterMetaType<QAbstractAxis*>(); |
|
118 | 97 | qRegisterMetaType<QAbstractSeries*>(); |
|
119 | 98 | } |
|
120 | 99 | |
|
121 | 100 | void tst_ChartDataSet::cleanupTestCase() |
|
122 | 101 | { |
|
123 | 102 | QTest::qWait(1); // Allow final deleteLaters to run |
|
124 | 103 | } |
|
125 | 104 | |
|
126 | 105 | void tst_ChartDataSet::init() |
|
127 | 106 | { |
|
128 | 107 | Q_ASSERT(!m_dataset); |
|
129 | 108 | m_dataset = new ChartDataSet(0); |
|
130 | 109 | } |
|
131 | 110 | |
|
132 | 111 | |
|
133 | 112 | void tst_ChartDataSet::cleanup() |
|
134 | 113 | { |
|
135 | 114 | delete m_dataset; |
|
136 | 115 | m_dataset = 0; |
|
137 | 116 | } |
|
138 | 117 | |
|
139 | 118 | void tst_ChartDataSet::chartdataset_data() |
|
140 | 119 | { |
|
141 | 120 | } |
|
142 | 121 | |
|
143 | 122 | void tst_ChartDataSet::chartdataset() |
|
144 | 123 | { |
|
145 | 124 | QVERIFY(m_dataset->axes().isEmpty()); |
|
146 | 125 | QVERIFY(m_dataset->series().isEmpty()); |
|
147 | 126 | m_dataset->createDefaultAxes(); |
|
148 | 127 | } |
|
149 | 128 | |
|
150 | 129 | |
|
151 | 130 | void tst_ChartDataSet::addSeries_data() |
|
152 | 131 | { |
|
153 | 132 | QTest::addColumn<QAbstractSeries*>("series"); |
|
154 | 133 | |
|
155 | 134 | QAbstractSeries* line = new QLineSeries(this); |
|
156 | 135 | QTest::newRow("line") << line; |
|
157 | 136 | |
|
158 | 137 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(new QLineSeries(this))); |
|
159 | 138 | QTest::newRow("area") << area; |
|
160 | 139 | |
|
161 | 140 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
162 | 141 | QTest::newRow("scatter") << scatter; |
|
163 | 142 | |
|
164 | 143 | QAbstractSeries* spline = new QSplineSeries(this); |
|
165 | 144 | QTest::newRow("spline") << spline; |
|
166 | 145 | |
|
167 | 146 | QAbstractSeries* pie = new QPieSeries(this); |
|
168 | 147 | QTest::newRow("pie") << pie; |
|
169 | 148 | |
|
170 | 149 | QAbstractSeries* bar = new QBarSeries(this); |
|
171 | 150 | QTest::newRow("bar") << bar; |
|
172 | 151 | |
|
173 | 152 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
174 | 153 | QTest::newRow("percent") << percent; |
|
175 | 154 | |
|
176 | 155 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
177 | 156 | QTest::newRow("stacked") << stacked; |
|
178 | 157 | } |
|
179 | 158 | |
|
180 | 159 | void tst_ChartDataSet::addSeries() |
|
181 | 160 | { |
|
182 | 161 | QFETCH(QAbstractSeries*, series); |
|
183 | 162 | QVERIFY(m_dataset->series().isEmpty()); |
|
184 | 163 | |
|
185 | 164 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
186 | 165 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
187 | 166 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
188 | 167 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
189 | 168 | |
|
190 | 169 | m_dataset->addSeries(series); |
|
191 | 170 | |
|
192 | 171 | QCOMPARE(m_dataset->series().count(),1); |
|
193 | 172 | TRY_COMPARE(spy0.count(), 0); |
|
194 | 173 | TRY_COMPARE(spy1.count(), 0); |
|
195 | 174 | TRY_COMPARE(spy2.count(), 1); |
|
196 | 175 | TRY_COMPARE(spy3.count(), 0); |
|
197 | 176 | } |
|
198 | 177 | |
|
199 | 178 | void tst_ChartDataSet::removeSeries_data() |
|
200 | 179 | { |
|
201 | 180 | addSeries_data(); |
|
202 | 181 | } |
|
203 | 182 | |
|
204 | 183 | void tst_ChartDataSet::removeSeries() |
|
205 | 184 | { |
|
206 | 185 | QFETCH(QAbstractSeries*, series); |
|
207 | 186 | QVERIFY(m_dataset->series().isEmpty()); |
|
208 | 187 | m_dataset->addSeries(series); |
|
209 | 188 | |
|
210 | 189 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
211 | 190 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
212 | 191 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
213 | 192 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
214 | 193 | |
|
215 | 194 | m_dataset->removeSeries(series); |
|
216 | 195 | |
|
217 | 196 | QCOMPARE(m_dataset->series().count(),0); |
|
218 | 197 | TRY_COMPARE(spy0.count(), 0); |
|
219 | 198 | TRY_COMPARE(spy1.count(), 0); |
|
220 | 199 | TRY_COMPARE(spy2.count(), 0); |
|
221 | 200 | TRY_COMPARE(spy3.count(), 1); |
|
222 | 201 | |
|
223 | 202 | delete series; |
|
224 | 203 | } |
|
225 | 204 | |
|
226 | 205 | void tst_ChartDataSet::addAxis_data() |
|
227 | 206 | { |
|
228 | 207 | QTest::addColumn<QAbstractAxis*>("axis"); |
|
229 | 208 | QAbstractAxis* value = new QValueAxis(this); |
|
230 | 209 | QAbstractAxis* category = new QCategoryAxis(this); |
|
231 | 210 | QAbstractAxis* barcategory = new QBarCategoryAxis(this); |
|
232 | 211 | #ifndef Q_WS_QWS |
|
233 | 212 | QAbstractAxis* datetime = new QDateTimeAxis(this); |
|
234 | 213 | #endif |
|
235 | 214 | |
|
236 | 215 | QTest::newRow("value") << value; |
|
237 | 216 | QTest::newRow("category") << category; |
|
238 | 217 | QTest::newRow("barcategory") << barcategory; |
|
239 | 218 | #ifndef Q_WS_QWS |
|
240 | 219 | QTest::newRow("datetime") << datetime; |
|
241 | 220 | #endif |
|
242 | 221 | } |
|
243 | 222 | |
|
244 | 223 | void tst_ChartDataSet::addAxis() |
|
245 | 224 | { |
|
246 | 225 | QFETCH(QAbstractAxis*, axis); |
|
247 | 226 | QVERIFY(m_dataset->axes().isEmpty()); |
|
248 | 227 | |
|
249 | 228 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
250 | 229 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
251 | 230 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
252 | 231 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
253 | 232 | |
|
254 | 233 | m_dataset->addAxis(axis,Qt::AlignBottom); |
|
255 | 234 | |
|
256 | 235 | QCOMPARE(m_dataset->axes().count(),1); |
|
257 | 236 | TRY_COMPARE(spy0.count(), 1); |
|
258 | 237 | TRY_COMPARE(spy1.count(), 0); |
|
259 | 238 | TRY_COMPARE(spy2.count(), 0); |
|
260 | 239 | TRY_COMPARE(spy3.count(), 0); |
|
261 | 240 | } |
|
262 | 241 | |
|
263 | 242 | void tst_ChartDataSet::removeAxis_data() |
|
264 | 243 | { |
|
265 | 244 | addAxis_data(); |
|
266 | 245 | } |
|
267 | 246 | |
|
268 | 247 | void tst_ChartDataSet::removeAxis() |
|
269 | 248 | { |
|
270 | 249 | QFETCH(QAbstractAxis*, axis); |
|
271 | 250 | QVERIFY(m_dataset->series().isEmpty()); |
|
272 | 251 | m_dataset->addAxis(axis,Qt::AlignBottom); |
|
273 | 252 | |
|
274 | 253 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
275 | 254 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
276 | 255 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
277 | 256 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
278 | 257 | |
|
279 | 258 | m_dataset->removeAxis(axis); |
|
280 | 259 | |
|
281 | 260 | QCOMPARE(m_dataset->axes().count(),0); |
|
282 | 261 | QCOMPARE(m_dataset->series().count(),0); |
|
283 | 262 | TRY_COMPARE(spy0.count(), 0); |
|
284 | 263 | TRY_COMPARE(spy1.count(), 1); |
|
285 | 264 | TRY_COMPARE(spy2.count(), 0); |
|
286 | 265 | TRY_COMPARE(spy3.count(), 0); |
|
287 | 266 | |
|
288 | 267 | delete axis; |
|
289 | 268 | } |
|
290 | 269 | |
|
291 | 270 | void tst_ChartDataSet::attachAxis_data() |
|
292 | 271 | { |
|
293 | 272 | |
|
294 | 273 | QTest::addColumn<QList<QAbstractSeries*> >("series"); |
|
295 | 274 | QTest::addColumn<QList<QAbstractAxis*> >("axis"); |
|
296 | 275 | QTest::addColumn<QList<Qt::Alignment> >("alignment"); |
|
297 | 276 | QTest::addColumn<QAbstractSeries*>("attachSeries"); |
|
298 | 277 | QTest::addColumn<QAbstractAxis*>("attachAxis"); |
|
299 | 278 | QTest::addColumn<bool>("success"); |
|
300 | 279 | |
|
301 | 280 | { |
|
302 | 281 | QList<QAbstractSeries*> series; |
|
303 | 282 | QList<QAbstractAxis*> axes; |
|
304 | 283 | QList<Qt::Alignment> alignment; |
|
305 | 284 | QAbstractSeries* line = new QLineSeries(this); |
|
306 | 285 | QAbstractAxis* value1 = new QValueAxis(this); |
|
307 | 286 | QAbstractAxis* value2 = new QValueAxis(this); |
|
308 | 287 | series << line << 0; |
|
309 | 288 | axes << value1 << value2; |
|
310 | 289 | alignment << Qt::AlignBottom << Qt::AlignLeft; |
|
311 | 290 | QTest::newRow("first") << series << axes << alignment << line << value2 << true ; |
|
312 | 291 | } |
|
313 | 292 | |
|
314 | 293 | { |
|
315 | 294 | QList<QAbstractSeries*> series; |
|
316 | 295 | QList<QAbstractAxis*> axes; |
|
317 | 296 | QList<Qt::Alignment> alignment; |
|
318 | 297 | QAbstractSeries* line = new QLineSeries(this); |
|
319 | 298 | QAbstractAxis* value1 = new QValueAxis(this); |
|
320 | 299 | QAbstractAxis* value2 = new QValueAxis(this); |
|
321 | 300 | series << 0 << line; |
|
322 | 301 | axes << value1 << value2; |
|
323 | 302 | alignment << Qt::AlignBottom << Qt::AlignLeft; |
|
324 | 303 | QTest::newRow("second") << series << axes << alignment << line << value1 << true; |
|
325 | 304 | } |
|
326 | 305 | |
|
327 | 306 | } |
|
328 | 307 | |
|
329 | 308 | void tst_ChartDataSet::attachAxis() |
|
330 | 309 | { |
|
331 | 310 | QFETCH(QList<QAbstractSeries*>, series); |
|
332 | 311 | QFETCH(QList<QAbstractAxis*>, axis); |
|
333 | 312 | QFETCH(QList<Qt::Alignment>, alignment); |
|
334 | 313 | QFETCH(QAbstractSeries*, attachSeries); |
|
335 | 314 | QFETCH(QAbstractAxis*, attachAxis); |
|
336 | 315 | QFETCH(bool, success); |
|
337 | 316 | |
|
338 | 317 | Q_ASSERT(series.count() == axis.count()); |
|
339 | 318 | Q_ASSERT(series.count() == alignment.count()); |
|
340 | 319 | |
|
341 | 320 | QVERIFY(m_dataset->series().isEmpty()); |
|
342 | 321 | QVERIFY(m_dataset->axes().isEmpty()); |
|
343 | 322 | |
|
344 | 323 | for(int i = 0 ; i < series.count() ; i++){ |
|
345 | 324 | if(series[i]) m_dataset->addSeries(series[i]); |
|
346 | 325 | if(axis[i]) m_dataset->addAxis(axis[i],alignment[i]); |
|
347 | 326 | if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]); |
|
348 | 327 | } |
|
349 | 328 | |
|
350 | 329 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
351 | 330 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
352 | 331 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
353 | 332 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
354 | 333 | |
|
355 | 334 | QCOMPARE(m_dataset->attachAxis(attachSeries,attachAxis),success); |
|
356 | 335 | |
|
357 | 336 | } |
|
358 | 337 | |
|
359 | 338 | void tst_ChartDataSet::detachAxis_data() |
|
360 | 339 | { |
|
361 | 340 | QTest::addColumn<QList<QAbstractSeries*> >("series"); |
|
362 | 341 | QTest::addColumn<QList<QAbstractAxis*> >("axis"); |
|
363 | 342 | QTest::addColumn<QAbstractSeries*>("detachSeries"); |
|
364 | 343 | QTest::addColumn<QAbstractAxis*>("detachAxis"); |
|
365 | 344 | QTest::addColumn<bool>("success"); |
|
366 | 345 | |
|
367 | 346 | { |
|
368 | 347 | QList<QAbstractSeries*> series; |
|
369 | 348 | QList<QAbstractAxis*> axes; |
|
370 | 349 | QAbstractSeries* line = new QLineSeries(this); |
|
371 | 350 | QAbstractAxis* value = new QValueAxis(this); |
|
372 | 351 | series << line; |
|
373 | 352 | axes << value; |
|
374 | 353 | QTest::newRow("first") << series << axes << line << value << true; |
|
375 | 354 | } |
|
376 | 355 | } |
|
377 | 356 | |
|
378 | 357 | void tst_ChartDataSet::detachAxis() |
|
379 | 358 | { |
|
380 | 359 | QFETCH(QList<QAbstractSeries*>, series); |
|
381 | 360 | QFETCH(QList<QAbstractAxis*>, axis); |
|
382 | 361 | QFETCH(QAbstractSeries*, detachSeries); |
|
383 | 362 | QFETCH(QAbstractAxis*, detachAxis); |
|
384 | 363 | QFETCH(bool, success); |
|
385 | 364 | |
|
386 | 365 | Q_ASSERT(series.count() == axis.count()); |
|
387 | 366 | |
|
388 | 367 | QVERIFY(m_dataset->series().isEmpty()); |
|
389 | 368 | QVERIFY(m_dataset->axes().isEmpty()); |
|
390 | 369 | |
|
391 | 370 | for(int i = 0; i < series.count(); i++) { |
|
392 | 371 | if(series[i]) m_dataset->addSeries(series[i]); |
|
393 | 372 | if(axis[i]) m_dataset->addAxis(axis[i],Qt::AlignBottom); |
|
394 | 373 | if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]); |
|
395 | 374 | } |
|
396 | 375 | |
|
397 | 376 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
398 | 377 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
399 | 378 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
400 | 379 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
401 | 380 | |
|
402 | 381 | QCOMPARE(m_dataset->detachAxis(detachSeries,detachAxis),success); |
|
403 | 382 | } |
|
404 | 383 | |
|
405 | 384 | QTEST_MAIN(tst_ChartDataSet) |
|
406 | 385 | #include "tst_chartdataset.moc" |
|
407 | #endif |
@@ -1,756 +1,732 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | #ifndef BUILD_PRIVATE_UNIT_TESTS | |
|
30 | ||
|
31 | #include <QtTest/QtTest> | |
|
32 | ||
|
33 | class tst_Domain: public QObject { | |
|
34 | ||
|
35 | Q_OBJECT | |
|
36 | ||
|
37 | private Q_SLOTS: | |
|
38 | void skip(); | |
|
39 | ||
|
40 | }; | |
|
41 | ||
|
42 | void tst_Domain::skip() | |
|
43 | { | |
|
44 | QSKIP("This test requires the debug version of library"); | |
|
45 | } | |
|
46 | ||
|
47 | QTEST_MAIN(tst_Domain) | |
|
48 | #include "tst_domain.moc" | |
|
49 | ||
|
50 | #else | |
|
51 | ||
|
52 | 29 | #include <QtTest/QtTest> |
|
53 | 30 | #include <private/xydomain_p.h> |
|
54 | 31 | #include <private/qabstractaxis_p.h> |
|
55 | 32 | #include <tst_definitions.h> |
|
56 | 33 | |
|
57 | 34 | QT_CHARTS_USE_NAMESPACE |
|
58 | 35 | |
|
59 | 36 | Q_DECLARE_METATYPE(XYDomain*) |
|
60 | 37 | Q_DECLARE_METATYPE(QSizeF) |
|
61 | 38 | Q_DECLARE_METATYPE(QMargins) |
|
62 | 39 | |
|
63 | 40 | |
|
64 | 41 | class AxisMock: public QAbstractAxisPrivate |
|
65 | 42 | { |
|
66 | 43 | Q_OBJECT |
|
67 | 44 | public: |
|
68 | 45 | AxisMock(Qt::Alignment alignment):QAbstractAxisPrivate(0){ setAlignment(alignment);}; |
|
69 | 46 | void initializeGraphics(QGraphicsItem* item) |
|
70 | 47 | { |
|
71 | 48 | Q_UNUSED(item); |
|
72 | 49 | }; |
|
73 | 50 | |
|
74 | 51 | void initializeDomain(AbstractDomain* domain) |
|
75 | 52 | { |
|
76 | 53 | Q_UNUSED(domain); |
|
77 | 54 | }; |
|
78 | 55 | void setMin(const QVariant &min) |
|
79 | 56 | { |
|
80 | 57 | Q_UNUSED(min); |
|
81 | 58 | } |
|
82 | 59 | qreal min() { return m_min;} |
|
83 | 60 | void setMax(const QVariant &max) |
|
84 | 61 | { |
|
85 | 62 | Q_UNUSED(max); |
|
86 | 63 | } |
|
87 | 64 | qreal max() { return m_max; } |
|
88 | 65 | void setRange(const QVariant &min, const QVariant &max) |
|
89 | 66 | { |
|
90 | 67 | Q_UNUSED(min); |
|
91 | 68 | Q_UNUSED(max); |
|
92 | 69 | }; |
|
93 | 70 | |
|
94 | 71 | void setRange(qreal min, qreal max) |
|
95 | 72 | { |
|
96 | 73 | m_min=min; |
|
97 | 74 | m_max=max; |
|
98 | 75 | emit rangeChanged(min,max); |
|
99 | 76 | }; |
|
100 | 77 | |
|
101 | 78 | int count () const { return m_count; } |
|
102 | 79 | |
|
103 | 80 | void handleDomainUpdated(){}; |
|
104 | 81 | public: |
|
105 | 82 | int m_count; |
|
106 | 83 | qreal m_min; |
|
107 | 84 | qreal m_max; |
|
108 | 85 | }; |
|
109 | 86 | |
|
110 | 87 | class tst_Domain: public QObject |
|
111 | 88 | { |
|
112 | 89 | Q_OBJECT |
|
113 | 90 | |
|
114 | 91 | public Q_SLOTS: |
|
115 | 92 | void initTestCase(); |
|
116 | 93 | void cleanupTestCase(); |
|
117 | 94 | void init(); |
|
118 | 95 | void cleanup(); |
|
119 | 96 | |
|
120 | 97 | private Q_SLOTS: |
|
121 | 98 | void domain(); |
|
122 | 99 | void handleHorizontalAxisRangeChanged_data(); |
|
123 | 100 | void handleHorizontalAxisRangeChanged(); |
|
124 | 101 | void handleVerticalAxisRangeChanged_data(); |
|
125 | 102 | void handleVerticalAxisRangeChanged(); |
|
126 | 103 | void isEmpty_data(); |
|
127 | 104 | void isEmpty(); |
|
128 | 105 | void maxX_data(); |
|
129 | 106 | void maxX(); |
|
130 | 107 | void maxY_data(); |
|
131 | 108 | void maxY(); |
|
132 | 109 | void minX_data(); |
|
133 | 110 | void minX(); |
|
134 | 111 | void minY_data(); |
|
135 | 112 | void minY(); |
|
136 | 113 | void operatorEquals_data(); |
|
137 | 114 | void operatorEquals(); |
|
138 | 115 | void setRange_data(); |
|
139 | 116 | void setRange(); |
|
140 | 117 | void setRangeX_data(); |
|
141 | 118 | void setRangeX(); |
|
142 | 119 | void setRangeY_data(); |
|
143 | 120 | void setRangeY(); |
|
144 | 121 | void spanX_data(); |
|
145 | 122 | void spanX(); |
|
146 | 123 | void spanY_data(); |
|
147 | 124 | void spanY(); |
|
148 | 125 | void zoomIn_data(); |
|
149 | 126 | void zoomIn(); |
|
150 | 127 | void zoomOut_data(); |
|
151 | 128 | void zoomOut(); |
|
152 | 129 | void move_data(); |
|
153 | 130 | void move(); |
|
154 | 131 | }; |
|
155 | 132 | |
|
156 | 133 | void tst_Domain::initTestCase() |
|
157 | 134 | { |
|
158 | 135 | } |
|
159 | 136 | |
|
160 | 137 | void tst_Domain::cleanupTestCase() |
|
161 | 138 | { |
|
162 | 139 | QTest::qWait(1); // Allow final deleteLaters to run |
|
163 | 140 | } |
|
164 | 141 | |
|
165 | 142 | void tst_Domain::init() |
|
166 | 143 | { |
|
167 | 144 | } |
|
168 | 145 | |
|
169 | 146 | void tst_Domain::cleanup() |
|
170 | 147 | { |
|
171 | 148 | } |
|
172 | 149 | |
|
173 | 150 | void tst_Domain::domain() |
|
174 | 151 | { |
|
175 | 152 | XYDomain domain; |
|
176 | 153 | |
|
177 | 154 | QCOMPARE(domain.isEmpty(), true); |
|
178 | 155 | QCOMPARE(domain.maxX(), 0.0); |
|
179 | 156 | QCOMPARE(domain.maxY(), 0.0); |
|
180 | 157 | QCOMPARE(domain.minX(), 0.0); |
|
181 | 158 | QCOMPARE(domain.minY(), 0.0); |
|
182 | 159 | } |
|
183 | 160 | |
|
184 | 161 | void tst_Domain::handleHorizontalAxisRangeChanged_data() |
|
185 | 162 | { |
|
186 | 163 | QTest::addColumn<qreal>("min"); |
|
187 | 164 | QTest::addColumn<qreal>("max"); |
|
188 | 165 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
189 | 166 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
190 | 167 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
191 | 168 | } |
|
192 | 169 | |
|
193 | 170 | void tst_Domain::handleHorizontalAxisRangeChanged() |
|
194 | 171 | { |
|
195 | 172 | QFETCH(qreal, min); |
|
196 | 173 | QFETCH(qreal, max); |
|
197 | 174 | |
|
198 | 175 | XYDomain domain; |
|
199 | 176 | |
|
200 | 177 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
201 | 178 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
202 | 179 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
203 | 180 | |
|
204 | 181 | AxisMock axis(Qt::AlignBottom); |
|
205 | 182 | QObject::connect(&axis,SIGNAL(rangeChanged(qreal,qreal)),&domain,SLOT(handleHorizontalAxisRangeChanged(qreal,qreal))); |
|
206 | 183 | axis.setRange(min,max); |
|
207 | 184 | |
|
208 | 185 | QVERIFY(qFuzzyCompare(domain.minX(), min)); |
|
209 | 186 | QVERIFY(qFuzzyCompare(domain.maxX(), max)); |
|
210 | 187 | |
|
211 | 188 | QList<QVariant> arg1 = spy1.first(); |
|
212 | 189 | QVERIFY(qFuzzyCompare(arg1.at(0).toReal(), min)); |
|
213 | 190 | QVERIFY(qFuzzyCompare(arg1.at(1).toReal(), max)); |
|
214 | 191 | |
|
215 | 192 | TRY_COMPARE(spy0.count(), 1); |
|
216 | 193 | TRY_COMPARE(spy1.count(), 1); |
|
217 | 194 | TRY_COMPARE(spy2.count(), 0); |
|
218 | 195 | |
|
219 | 196 | } |
|
220 | 197 | |
|
221 | 198 | void tst_Domain::handleVerticalAxisRangeChanged_data() |
|
222 | 199 | { |
|
223 | 200 | QTest::addColumn<qreal>("min"); |
|
224 | 201 | QTest::addColumn<qreal>("max"); |
|
225 | 202 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
226 | 203 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
227 | 204 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
228 | 205 | } |
|
229 | 206 | |
|
230 | 207 | void tst_Domain::handleVerticalAxisRangeChanged() |
|
231 | 208 | { |
|
232 | 209 | QFETCH(qreal, min); |
|
233 | 210 | QFETCH(qreal, max); |
|
234 | 211 | |
|
235 | 212 | XYDomain domain; |
|
236 | 213 | |
|
237 | 214 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
238 | 215 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
239 | 216 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
240 | 217 | |
|
241 | 218 | AxisMock axis(Qt::AlignLeft); |
|
242 | 219 | QObject::connect(&axis, SIGNAL(rangeChanged(qreal,qreal)), &domain, SLOT(handleVerticalAxisRangeChanged(qreal,qreal))); |
|
243 | 220 | axis.setRange(min,max); |
|
244 | 221 | |
|
245 | 222 | QVERIFY(qFuzzyCompare(domain.minY(), min)); |
|
246 | 223 | QVERIFY(qFuzzyCompare(domain.maxY(), max)); |
|
247 | 224 | |
|
248 | 225 | QList<QVariant> arg1 = spy2.first(); |
|
249 | 226 | QVERIFY(qFuzzyCompare(arg1.at(0).toReal(), min)); |
|
250 | 227 | QVERIFY(qFuzzyCompare(arg1.at(1).toReal(), max)); |
|
251 | 228 | |
|
252 | 229 | TRY_COMPARE(spy0.count(), 1); |
|
253 | 230 | TRY_COMPARE(spy1.count(), 0); |
|
254 | 231 | TRY_COMPARE(spy2.count(), 1); |
|
255 | 232 | } |
|
256 | 233 | |
|
257 | 234 | void tst_Domain::isEmpty_data() |
|
258 | 235 | { |
|
259 | 236 | QTest::addColumn<qreal>("minX"); |
|
260 | 237 | QTest::addColumn<qreal>("maxX"); |
|
261 | 238 | QTest::addColumn<qreal>("minY"); |
|
262 | 239 | QTest::addColumn<qreal>("maxY"); |
|
263 | 240 | QTest::addColumn<QSizeF>("size"); |
|
264 | 241 | QTest::addColumn<bool>("isEmpty"); |
|
265 | 242 | QTest::newRow("0 0 0 0") << 0.0 << 0.0 << 0.0 << 0.0 << QSizeF(1,1) << true; |
|
266 | 243 | QTest::newRow("0 1 0 0") << 0.0 << 1.0 << 0.0 << 0.0 << QSizeF(1,1) << true; |
|
267 | 244 | QTest::newRow("0 0 0 1") << 0.0 << 1.0 << 0.0 << 0.0 << QSizeF(1,1) << true; |
|
268 | 245 | QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << QSizeF(1,1) << false; |
|
269 | 246 | QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << QSizeF(-11,1) << true; |
|
270 | 247 | } |
|
271 | 248 | |
|
272 | 249 | void tst_Domain::isEmpty() |
|
273 | 250 | { |
|
274 | 251 | QFETCH(qreal, minX); |
|
275 | 252 | QFETCH(qreal, maxX); |
|
276 | 253 | QFETCH(qreal, minY); |
|
277 | 254 | QFETCH(qreal, maxY); |
|
278 | 255 | QFETCH(QSizeF, size); |
|
279 | 256 | QFETCH(bool, isEmpty); |
|
280 | 257 | |
|
281 | 258 | XYDomain domain; |
|
282 | 259 | domain.setRange(minX, maxX, minY, maxY); |
|
283 | 260 | domain.setSize(size); |
|
284 | 261 | QCOMPARE(domain.isEmpty(), isEmpty); |
|
285 | 262 | } |
|
286 | 263 | |
|
287 | 264 | void tst_Domain::maxX_data() |
|
288 | 265 | { |
|
289 | 266 | QTest::addColumn<qreal>("maxX1"); |
|
290 | 267 | QTest::addColumn<qreal>("maxX2"); |
|
291 | 268 | QTest::addColumn<int>("count"); |
|
292 | 269 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
293 | 270 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
294 | 271 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
295 | 272 | } |
|
296 | 273 | |
|
297 | 274 | void tst_Domain::maxX() |
|
298 | 275 | { |
|
299 | 276 | QFETCH(qreal, maxX1); |
|
300 | 277 | QFETCH(qreal, maxX2); |
|
301 | 278 | QFETCH(int, count); |
|
302 | 279 | |
|
303 | 280 | XYDomain domain; |
|
304 | 281 | |
|
305 | 282 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
306 | 283 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
307 | 284 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
308 | 285 | |
|
309 | 286 | domain.setMaxX(maxX1); |
|
310 | 287 | QCOMPARE(domain.maxX(), maxX1); |
|
311 | 288 | domain.setMaxX(maxX2); |
|
312 | 289 | QCOMPARE(domain.maxX(), maxX2); |
|
313 | 290 | |
|
314 | 291 | TRY_COMPARE(spy0.count(), count); |
|
315 | 292 | TRY_COMPARE(spy1.count(), count); |
|
316 | 293 | TRY_COMPARE(spy2.count(), 0); |
|
317 | 294 | |
|
318 | 295 | } |
|
319 | 296 | |
|
320 | 297 | void tst_Domain::maxY_data() |
|
321 | 298 | { |
|
322 | 299 | QTest::addColumn<qreal>("maxY1"); |
|
323 | 300 | QTest::addColumn<qreal>("maxY2"); |
|
324 | 301 | QTest::addColumn<int>("count"); |
|
325 | 302 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
326 | 303 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
327 | 304 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
328 | 305 | } |
|
329 | 306 | |
|
330 | 307 | void tst_Domain::maxY() |
|
331 | 308 | { |
|
332 | 309 | QFETCH(qreal, maxY1); |
|
333 | 310 | QFETCH(qreal, maxY2); |
|
334 | 311 | QFETCH(int, count); |
|
335 | 312 | |
|
336 | 313 | XYDomain domain; |
|
337 | 314 | |
|
338 | 315 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
339 | 316 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
340 | 317 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
341 | 318 | |
|
342 | 319 | domain.setMaxY(maxY1); |
|
343 | 320 | QCOMPARE(domain.maxY(), maxY1); |
|
344 | 321 | domain.setMaxY(maxY2); |
|
345 | 322 | QCOMPARE(domain.maxY(), maxY2); |
|
346 | 323 | |
|
347 | 324 | TRY_COMPARE(spy0.count(), count); |
|
348 | 325 | TRY_COMPARE(spy1.count(), 0); |
|
349 | 326 | TRY_COMPARE(spy2.count(), count); |
|
350 | 327 | } |
|
351 | 328 | |
|
352 | 329 | void tst_Domain::minX_data() |
|
353 | 330 | { |
|
354 | 331 | QTest::addColumn<qreal>("minX1"); |
|
355 | 332 | QTest::addColumn<qreal>("minX2"); |
|
356 | 333 | QTest::addColumn<int>("count"); |
|
357 | 334 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
358 | 335 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
359 | 336 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
360 | 337 | } |
|
361 | 338 | |
|
362 | 339 | void tst_Domain::minX() |
|
363 | 340 | { |
|
364 | 341 | QFETCH(qreal, minX1); |
|
365 | 342 | QFETCH(qreal, minX2); |
|
366 | 343 | QFETCH(int, count); |
|
367 | 344 | |
|
368 | 345 | XYDomain domain; |
|
369 | 346 | |
|
370 | 347 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
371 | 348 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
372 | 349 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
373 | 350 | |
|
374 | 351 | domain.setMinX(minX1); |
|
375 | 352 | QCOMPARE(domain.minX(), minX1); |
|
376 | 353 | domain.setMinX(minX2); |
|
377 | 354 | QCOMPARE(domain.minX(), minX2); |
|
378 | 355 | |
|
379 | 356 | TRY_COMPARE(spy0.count(), count); |
|
380 | 357 | TRY_COMPARE(spy1.count(), count); |
|
381 | 358 | TRY_COMPARE(spy2.count(), 0); |
|
382 | 359 | } |
|
383 | 360 | |
|
384 | 361 | void tst_Domain::minY_data() |
|
385 | 362 | { |
|
386 | 363 | QTest::addColumn<qreal>("minY1"); |
|
387 | 364 | QTest::addColumn<qreal>("minY2"); |
|
388 | 365 | QTest::addColumn<int>("count"); |
|
389 | 366 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
390 | 367 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
391 | 368 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
392 | 369 | } |
|
393 | 370 | |
|
394 | 371 | void tst_Domain::minY() |
|
395 | 372 | { |
|
396 | 373 | QFETCH(qreal, minY1); |
|
397 | 374 | QFETCH(qreal, minY2); |
|
398 | 375 | QFETCH(int, count); |
|
399 | 376 | |
|
400 | 377 | XYDomain domain; |
|
401 | 378 | |
|
402 | 379 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
403 | 380 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
404 | 381 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
405 | 382 | |
|
406 | 383 | domain.setMinY(minY1); |
|
407 | 384 | QCOMPARE(domain.minY(), minY1); |
|
408 | 385 | domain.setMinY(minY2); |
|
409 | 386 | QCOMPARE(domain.minY(), minY2); |
|
410 | 387 | |
|
411 | 388 | TRY_COMPARE(spy0.count(), count); |
|
412 | 389 | TRY_COMPARE(spy1.count(), 0); |
|
413 | 390 | TRY_COMPARE(spy2.count(), count); |
|
414 | 391 | } |
|
415 | 392 | |
|
416 | 393 | void tst_Domain::operatorEquals_data() |
|
417 | 394 | { |
|
418 | 395 | |
|
419 | 396 | QTest::addColumn<XYDomain*>("domain1"); |
|
420 | 397 | QTest::addColumn<XYDomain*>("domain2"); |
|
421 | 398 | QTest::addColumn<bool>("equals"); |
|
422 | 399 | QTest::addColumn<bool>("notEquals"); |
|
423 | 400 | XYDomain* a; |
|
424 | 401 | XYDomain* b; |
|
425 | 402 | a = new XYDomain(); |
|
426 | 403 | a->setRange(0, 100, 0, 100); |
|
427 | 404 | b = new XYDomain(); |
|
428 | 405 | b->setRange(0, 100, 0, 100); |
|
429 | 406 | QTest::newRow("equals") << a << b << true << false; |
|
430 | 407 | a = new XYDomain(); |
|
431 | 408 | a->setRange(0, 100, 0, 100); |
|
432 | 409 | b = new XYDomain(); |
|
433 | 410 | b->setRange(0, 100, 0, 1); |
|
434 | 411 | QTest::newRow("equals") << a << b << false << true; |
|
435 | 412 | a = new XYDomain(); |
|
436 | 413 | a->setRange(0, 100, 0, 100); |
|
437 | 414 | b = new XYDomain(); |
|
438 | 415 | b->setRange(0, 1, 0, 100); |
|
439 | 416 | QTest::newRow("equals") << a << b << false << true; |
|
440 | 417 | |
|
441 | 418 | } |
|
442 | 419 | |
|
443 | 420 | void tst_Domain::operatorEquals() |
|
444 | 421 | { |
|
445 | 422 | QFETCH(XYDomain*, domain1); |
|
446 | 423 | QFETCH(XYDomain*, domain2); |
|
447 | 424 | QFETCH(bool, equals); |
|
448 | 425 | QFETCH(bool, notEquals); |
|
449 | 426 | |
|
450 | 427 | XYDomain domain; |
|
451 | 428 | |
|
452 | 429 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
453 | 430 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
454 | 431 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
455 | 432 | |
|
456 | 433 | QCOMPARE(*domain1==*domain2, equals); |
|
457 | 434 | QCOMPARE(*domain1!=*domain2, notEquals); |
|
458 | 435 | |
|
459 | 436 | TRY_COMPARE(spy0.count(), 0); |
|
460 | 437 | TRY_COMPARE(spy1.count(), 0); |
|
461 | 438 | TRY_COMPARE(spy2.count(), 0); |
|
462 | 439 | |
|
463 | 440 | delete domain1; |
|
464 | 441 | delete domain2; |
|
465 | 442 | } |
|
466 | 443 | |
|
467 | 444 | void tst_Domain::setRange_data() |
|
468 | 445 | { |
|
469 | 446 | QTest::addColumn<qreal>("minX"); |
|
470 | 447 | QTest::addColumn<qreal>("maxX"); |
|
471 | 448 | QTest::addColumn<qreal>("minY"); |
|
472 | 449 | QTest::addColumn<qreal>("maxY"); |
|
473 | 450 | QTest::newRow("1,2,1,2") << 1.0 << 2.0 << 1.0 << 2.0; |
|
474 | 451 | QTest::newRow("1,3,1,3") << 1.0 << 3.0 << 1.0 << 3.0; |
|
475 | 452 | QTest::newRow("-1,5,-2,-1") << -1.0 << 5.0 << -2.0 << -1.0; |
|
476 | 453 | } |
|
477 | 454 | |
|
478 | 455 | void tst_Domain::setRange() |
|
479 | 456 | { |
|
480 | 457 | QFETCH(qreal, minX); |
|
481 | 458 | QFETCH(qreal, maxX); |
|
482 | 459 | QFETCH(qreal, minY); |
|
483 | 460 | QFETCH(qreal, maxY); |
|
484 | 461 | |
|
485 | 462 | XYDomain domain; |
|
486 | 463 | |
|
487 | 464 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
488 | 465 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
489 | 466 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
490 | 467 | |
|
491 | 468 | domain.setRange(minX, maxX, minY, maxY); |
|
492 | 469 | |
|
493 | 470 | QCOMPARE(domain.minX(), minX); |
|
494 | 471 | QCOMPARE(domain.maxX(), maxX); |
|
495 | 472 | QCOMPARE(domain.minY(), minY); |
|
496 | 473 | QCOMPARE(domain.maxY(), maxY); |
|
497 | 474 | |
|
498 | 475 | TRY_COMPARE(spy0.count(), 1); |
|
499 | 476 | TRY_COMPARE(spy1.count(), 1); |
|
500 | 477 | TRY_COMPARE(spy2.count(), 1); |
|
501 | 478 | |
|
502 | 479 | } |
|
503 | 480 | |
|
504 | 481 | void tst_Domain::setRangeX_data() |
|
505 | 482 | { |
|
506 | 483 | QTest::addColumn<qreal>("min"); |
|
507 | 484 | QTest::addColumn<qreal>("max"); |
|
508 | 485 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
509 | 486 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
510 | 487 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
511 | 488 | } |
|
512 | 489 | |
|
513 | 490 | void tst_Domain::setRangeX() |
|
514 | 491 | { |
|
515 | 492 | QFETCH(qreal, min); |
|
516 | 493 | QFETCH(qreal, max); |
|
517 | 494 | |
|
518 | 495 | XYDomain domain; |
|
519 | 496 | |
|
520 | 497 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
521 | 498 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
522 | 499 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
523 | 500 | |
|
524 | 501 | domain.setRangeX(min, max); |
|
525 | 502 | |
|
526 | 503 | QVERIFY(qFuzzyCompare(domain.minX(), min)); |
|
527 | 504 | QVERIFY(qFuzzyCompare(domain.maxX(), max)); |
|
528 | 505 | |
|
529 | 506 | QList<QVariant> arg1 = spy1.first(); |
|
530 | 507 | QVERIFY(qFuzzyCompare(arg1.at(0).toReal(), min)); |
|
531 | 508 | QVERIFY(qFuzzyCompare(arg1.at(1).toReal(), max)); |
|
532 | 509 | |
|
533 | 510 | TRY_COMPARE(spy0.count(), 1); |
|
534 | 511 | TRY_COMPARE(spy1.count(), 1); |
|
535 | 512 | TRY_COMPARE(spy2.count(), 0); |
|
536 | 513 | } |
|
537 | 514 | |
|
538 | 515 | void tst_Domain::setRangeY_data() |
|
539 | 516 | { |
|
540 | 517 | QTest::addColumn<qreal>("min"); |
|
541 | 518 | QTest::addColumn<qreal>("max"); |
|
542 | 519 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
543 | 520 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
544 | 521 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
545 | 522 | } |
|
546 | 523 | |
|
547 | 524 | void tst_Domain::setRangeY() |
|
548 | 525 | { |
|
549 | 526 | QFETCH(qreal, min); |
|
550 | 527 | QFETCH(qreal, max); |
|
551 | 528 | |
|
552 | 529 | XYDomain domain; |
|
553 | 530 | |
|
554 | 531 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
555 | 532 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
556 | 533 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
557 | 534 | |
|
558 | 535 | domain.setRangeY(min, max); |
|
559 | 536 | |
|
560 | 537 | QVERIFY(qFuzzyCompare(domain.minY(), min)); |
|
561 | 538 | QVERIFY(qFuzzyCompare(domain.maxY(), max)); |
|
562 | 539 | |
|
563 | 540 | QList<QVariant> arg1 = spy2.first(); |
|
564 | 541 | QVERIFY(qFuzzyCompare(arg1.at(0).toReal(), min)); |
|
565 | 542 | QVERIFY(qFuzzyCompare(arg1.at(1).toReal(), max)); |
|
566 | 543 | |
|
567 | 544 | TRY_COMPARE(spy0.count(), 1); |
|
568 | 545 | TRY_COMPARE(spy1.count(), 0); |
|
569 | 546 | TRY_COMPARE(spy2.count(), 1); |
|
570 | 547 | } |
|
571 | 548 | |
|
572 | 549 | void tst_Domain::spanX_data() |
|
573 | 550 | { |
|
574 | 551 | QTest::addColumn<qreal>("minX"); |
|
575 | 552 | QTest::addColumn<qreal>("maxX"); |
|
576 | 553 | QTest::addColumn<qreal>("spanX"); |
|
577 | 554 | QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0; |
|
578 | 555 | QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0; |
|
579 | 556 | } |
|
580 | 557 | |
|
581 | 558 | void tst_Domain::spanX() |
|
582 | 559 | { |
|
583 | 560 | QFETCH(qreal, minX); |
|
584 | 561 | QFETCH(qreal, maxX); |
|
585 | 562 | QFETCH(qreal, spanX); |
|
586 | 563 | |
|
587 | 564 | XYDomain domain; |
|
588 | 565 | |
|
589 | 566 | domain.setRangeX(minX, maxX); |
|
590 | 567 | |
|
591 | 568 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
592 | 569 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
593 | 570 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
594 | 571 | |
|
595 | 572 | QCOMPARE(domain.spanX(), spanX); |
|
596 | 573 | |
|
597 | 574 | TRY_COMPARE(spy0.count(), 0); |
|
598 | 575 | TRY_COMPARE(spy1.count(), 0); |
|
599 | 576 | TRY_COMPARE(spy2.count(), 0); |
|
600 | 577 | } |
|
601 | 578 | |
|
602 | 579 | void tst_Domain::spanY_data() |
|
603 | 580 | { |
|
604 | 581 | QTest::addColumn<qreal>("minY"); |
|
605 | 582 | QTest::addColumn<qreal>("maxY"); |
|
606 | 583 | QTest::addColumn<qreal>("spanY"); |
|
607 | 584 | QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0; |
|
608 | 585 | QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0; |
|
609 | 586 | } |
|
610 | 587 | |
|
611 | 588 | void tst_Domain::spanY() |
|
612 | 589 | { |
|
613 | 590 | QFETCH(qreal, minY); |
|
614 | 591 | QFETCH(qreal, maxY); |
|
615 | 592 | QFETCH(qreal, spanY); |
|
616 | 593 | |
|
617 | 594 | XYDomain domain; |
|
618 | 595 | |
|
619 | 596 | domain.setRangeY(minY, maxY); |
|
620 | 597 | |
|
621 | 598 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
622 | 599 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
623 | 600 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
624 | 601 | |
|
625 | 602 | QCOMPARE(domain.spanY(), spanY); |
|
626 | 603 | |
|
627 | 604 | TRY_COMPARE(spy0.count(), 0); |
|
628 | 605 | TRY_COMPARE(spy1.count(), 0); |
|
629 | 606 | TRY_COMPARE(spy2.count(), 0); |
|
630 | 607 | } |
|
631 | 608 | |
|
632 | 609 | void tst_Domain::zoomIn_data() |
|
633 | 610 | { |
|
634 | 611 | QTest::addColumn<QMargins>("range"); |
|
635 | 612 | QTest::addColumn<QSizeF>("size"); |
|
636 | 613 | QTest::addColumn<QMargins>("zoom"); |
|
637 | 614 | QTest::addColumn<QMargins>("result"); |
|
638 | 615 | |
|
639 | 616 | QTest::newRow("first") << QMargins(0,0,1000,1000) << QSizeF(1000, 1000) << |
|
640 | 617 | QMargins(100, 100, 900, 900) << QMargins(100,100,900,900); |
|
641 | 618 | QTest::newRow("second") << QMargins(0,0,2000,2000) << QSizeF(1000, 1000) << |
|
642 | 619 | QMargins(100, 100, 900, 900) << QMargins(200,200,1800,1800); |
|
643 | 620 | } |
|
644 | 621 | |
|
645 | 622 | void tst_Domain::zoomIn() |
|
646 | 623 | { |
|
647 | 624 | QFETCH(QMargins, range); |
|
648 | 625 | QFETCH(QSizeF, size); |
|
649 | 626 | QFETCH(QMargins, zoom); |
|
650 | 627 | QFETCH(QMargins, result); |
|
651 | 628 | |
|
652 | 629 | XYDomain domain; |
|
653 | 630 | domain.setRange(range.left(), range.right(), range.top(),range.bottom()); |
|
654 | 631 | domain.setSize(size); |
|
655 | 632 | |
|
656 | 633 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
657 | 634 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
658 | 635 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
659 | 636 | |
|
660 | 637 | domain.zoomIn(QRectF(zoom.left(),zoom.top(),zoom.right()-zoom.left(),zoom.bottom()-zoom.top())); |
|
661 | 638 | |
|
662 | 639 | QCOMPARE(domain.minX(),qreal(result.left())); |
|
663 | 640 | QCOMPARE(domain.maxX(),qreal(result.right())); |
|
664 | 641 | QCOMPARE(domain.minY(),qreal(result.top())); |
|
665 | 642 | QCOMPARE(domain.maxY(),qreal(result.bottom())); |
|
666 | 643 | |
|
667 | 644 | TRY_COMPARE(spy0.count(), 1); |
|
668 | 645 | TRY_COMPARE(spy1.count(), 1); |
|
669 | 646 | TRY_COMPARE(spy2.count(), 1); |
|
670 | 647 | } |
|
671 | 648 | |
|
672 | 649 | void tst_Domain::zoomOut_data() |
|
673 | 650 | { |
|
674 | 651 | QTest::addColumn<QMargins>("range"); |
|
675 | 652 | QTest::addColumn<QSizeF>("size"); |
|
676 | 653 | QTest::addColumn<QMargins>("zoom"); |
|
677 | 654 | QTest::addColumn<QMargins>("result"); |
|
678 | 655 | |
|
679 | 656 | QTest::newRow("first") << QMargins(100,100,900,900) << QSizeF(1000, 1000) << |
|
680 | 657 | QMargins(100, 100, 900, 900) << QMargins(0,0,1000,1000); |
|
681 | 658 | QTest::newRow("second") << QMargins(200,200,1800,1800) << QSizeF(1000, 1000) << |
|
682 | 659 | QMargins(100, 100, 900, 900) << QMargins(0,0,2000,2000); |
|
683 | 660 | } |
|
684 | 661 | |
|
685 | 662 | void tst_Domain::zoomOut() |
|
686 | 663 | { |
|
687 | 664 | QFETCH(QMargins, range); |
|
688 | 665 | QFETCH(QSizeF, size); |
|
689 | 666 | QFETCH(QMargins, zoom); |
|
690 | 667 | QFETCH(QMargins, result); |
|
691 | 668 | |
|
692 | 669 | XYDomain domain; |
|
693 | 670 | domain.setRange(range.left(), range.right(), range.top(),range.bottom()); |
|
694 | 671 | domain.setSize(size); |
|
695 | 672 | |
|
696 | 673 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
697 | 674 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
698 | 675 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
699 | 676 | |
|
700 | 677 | domain.zoomOut(QRectF(zoom.left(),zoom.top(),zoom.right()-zoom.left(),zoom.bottom()-zoom.top())); |
|
701 | 678 | |
|
702 | 679 | QCOMPARE(domain.minX(),qreal(result.left())); |
|
703 | 680 | QCOMPARE(domain.maxX(),qreal(result.right())); |
|
704 | 681 | QCOMPARE(domain.minY(),qreal(result.top())); |
|
705 | 682 | QCOMPARE(domain.maxY(),qreal(result.bottom())); |
|
706 | 683 | |
|
707 | 684 | TRY_COMPARE(spy0.count(), 1); |
|
708 | 685 | TRY_COMPARE(spy1.count(), 1); |
|
709 | 686 | TRY_COMPARE(spy2.count(), 1); |
|
710 | 687 | } |
|
711 | 688 | |
|
712 | 689 | void tst_Domain::move_data() |
|
713 | 690 | { |
|
714 | 691 | QTest::addColumn<QMargins>("range"); |
|
715 | 692 | QTest::addColumn<QSizeF>("size"); |
|
716 | 693 | QTest::addColumn<int>("dx"); |
|
717 | 694 | QTest::addColumn<int>("dy"); |
|
718 | 695 | QTest::addColumn<QMargins>("result"); |
|
719 | 696 | |
|
720 | 697 | QTest::newRow("first") << QMargins(0,0,1000,1000) << QSizeF(1000, 1000) << |
|
721 | 698 | 10 << 10 << QMargins(10,10,1010,1010); |
|
722 | 699 | QTest::newRow("second") << QMargins(0,0,1000,1000) << QSizeF(1000, 1000) << |
|
723 | 700 | -10 << -10 << QMargins(-10,-10,990,990); |
|
724 | 701 | } |
|
725 | 702 | |
|
726 | 703 | void tst_Domain::move() |
|
727 | 704 | { |
|
728 | 705 | QFETCH(QMargins, range); |
|
729 | 706 | QFETCH(QSizeF, size); |
|
730 | 707 | QFETCH(int, dx); |
|
731 | 708 | QFETCH(int, dy); |
|
732 | 709 | QFETCH(QMargins, result); |
|
733 | 710 | |
|
734 | 711 | XYDomain domain; |
|
735 | 712 | domain.setRange(range.left(), range.right(), range.top(),range.bottom()); |
|
736 | 713 | domain.setSize(size); |
|
737 | 714 | |
|
738 | 715 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
739 | 716 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
740 | 717 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
741 | 718 | |
|
742 | 719 | domain.move(dx, dy); |
|
743 | 720 | |
|
744 | 721 | QCOMPARE(domain.minX(),qreal(result.left())); |
|
745 | 722 | QCOMPARE(domain.maxX(),qreal(result.right())); |
|
746 | 723 | QCOMPARE(domain.minY(),qreal(result.top())); |
|
747 | 724 | QCOMPARE(domain.maxY(),qreal(result.bottom())); |
|
748 | 725 | |
|
749 | 726 | TRY_COMPARE(spy0.count(), 1); |
|
750 | 727 | TRY_COMPARE(spy1.count(), (dx != 0 ? 1 : 0)); |
|
751 | 728 | TRY_COMPARE(spy2.count(), (dy != 0 ? 1 : 0)); |
|
752 | 729 | } |
|
753 | 730 | |
|
754 | 731 | QTEST_MAIN(tst_Domain) |
|
755 | 732 | #include "tst_domain.moc" |
|
756 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now