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