@@ -1,125 +1,121 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt 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 Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QApplication> |
|
21 | #include <QApplication> | |
22 | #include <QMainWindow> |
|
22 | #include <QMainWindow> | |
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QLineSeries> |
|
24 | #include <QLineSeries> | |
25 | #include <QIntervalsAxis> |
|
25 | #include <QIntervalsAxis> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
27 | QTCOMMERCIALCHART_USE_NAMESPACE | |
28 |
|
28 | |||
29 | int main(int argc, char *argv[]) |
|
29 | int main(int argc, char *argv[]) | |
30 | { |
|
30 | { | |
31 | QApplication a(argc, argv); |
|
31 | QApplication a(argc, argv); | |
32 |
|
32 | |||
33 | //![1] |
|
33 | //![1] | |
34 | QLineSeries* series = new QLineSeries(); |
|
34 | QLineSeries* series = new QLineSeries(); | |
35 |
*series << QPointF(0, 6) << QPointF(9, 4) << QPointF(15, 20) << QPointF(25, 12) << QPointF( |
|
35 | *series << QPointF(0, 6) << QPointF(9, 4) << QPointF(15, 20) << QPointF(25, 12) << QPointF(39, 36); | |
36 | QChart* chart = new QChart(); |
|
36 | QChart* chart = new QChart(); | |
37 | chart->legend()->hide(); |
|
37 | chart->legend()->hide(); | |
38 | chart->addSeries(series); |
|
38 | chart->addSeries(series); | |
39 | //![1] |
|
39 | //![1] | |
40 |
|
40 | |||
41 | //![2] |
|
41 | //![2] | |
42 | // Customize series |
|
42 | // Customize series | |
43 | QPen pen(QRgb(0xfdb157)); |
|
43 | QPen pen(QRgb(0xfdb157)); | |
44 | pen.setWidth(5); |
|
44 | pen.setWidth(5); | |
45 | series->setPen(pen); |
|
45 | series->setPen(pen); | |
46 |
|
46 | |||
47 | // Customize chart title |
|
47 | // Customize chart title | |
48 | QFont font; |
|
48 | QFont font; | |
49 | font.setPixelSize(18); |
|
49 | font.setPixelSize(18); | |
50 | chart->setTitleFont(font); |
|
50 | chart->setTitleFont(font); | |
51 | chart->setTitleBrush(QBrush(Qt::white)); |
|
51 | chart->setTitleBrush(QBrush(Qt::white)); | |
52 | chart->setTitle("Customchart example"); |
|
52 | chart->setTitle("Customchart example"); | |
53 |
|
53 | |||
54 | // Customize chart background |
|
54 | // Customize chart background | |
55 | QLinearGradient backgroundGradient; |
|
55 | QLinearGradient backgroundGradient; | |
56 | backgroundGradient.setStart(QPointF(0,0)); |
|
56 | backgroundGradient.setStart(QPointF(0,0)); | |
57 | backgroundGradient.setFinalStop(QPointF(0,1)); |
|
57 | backgroundGradient.setFinalStop(QPointF(0,1)); | |
58 | backgroundGradient.setColorAt(0.0, QRgb(0xd2d0d1)); |
|
58 | backgroundGradient.setColorAt(0.0, QRgb(0xd2d0d1)); | |
59 | backgroundGradient.setColorAt(1.0, QRgb(0x4c4547)); |
|
59 | backgroundGradient.setColorAt(1.0, QRgb(0x4c4547)); | |
60 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
60 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
61 | chart->setBackgroundBrush(backgroundGradient); |
|
61 | chart->setBackgroundBrush(backgroundGradient); | |
62 | //![2] |
|
62 | //![2] | |
63 |
|
63 | |||
64 | //![3] |
|
64 | //![3] | |
65 | QIntervalsAxis* axisX = new QIntervalsAxis(); |
|
65 | QIntervalsAxis* axisX = new QIntervalsAxis(); | |
66 | QIntervalsAxis* axisY = new QIntervalsAxis(); |
|
66 | QIntervalsAxis* axisY = new QIntervalsAxis(); | |
67 |
|
67 | |||
68 | // Customize axis label font |
|
68 | // Customize axis label font | |
69 | QFont labelsFont; |
|
69 | QFont labelsFont; | |
70 | labelsFont.setPixelSize(12); |
|
70 | labelsFont.setPixelSize(12); | |
71 | axisX->setLabelsFont(labelsFont); |
|
71 | axisX->setLabelsFont(labelsFont); | |
72 | axisY->setLabelsFont(labelsFont); |
|
72 | axisY->setLabelsFont(labelsFont); | |
73 |
|
73 | |||
74 | // Customize axis colors |
|
74 | // Customize axis colors | |
75 | QPen axisPen(QRgb(0xd18952)); |
|
75 | QPen axisPen(QRgb(0xd18952)); | |
76 | axisPen.setWidth(2); |
|
76 | axisPen.setWidth(2); | |
77 | axisX->setAxisPen(axisPen); |
|
77 | axisX->setAxisPen(axisPen); | |
78 | axisY->setAxisPen(axisPen); |
|
78 | axisY->setAxisPen(axisPen); | |
79 |
|
79 | |||
80 | // Customize axis label colors |
|
80 | // Customize axis label colors | |
81 | QBrush axisBrush(Qt::white); |
|
81 | QBrush axisBrush(Qt::white); | |
82 | axisX->setLabelsBrush(axisBrush); |
|
82 | axisX->setLabelsBrush(axisBrush); | |
83 | axisY->setLabelsBrush(axisBrush); |
|
83 | axisY->setLabelsBrush(axisBrush); | |
84 |
|
84 | |||
85 | // Customize grid lines and shades |
|
85 | // Customize grid lines and shades | |
86 | axisX->setGridLineVisible(false); |
|
86 | axisX->setGridLineVisible(false); | |
87 | axisY->setGridLineVisible(false); |
|
87 | axisY->setGridLineVisible(false); | |
88 | axisY->setShadesPen(Qt::NoPen); |
|
88 | axisY->setShadesPen(Qt::NoPen); | |
89 | axisY->setShadesBrush(QBrush(QRgb(0xa5a2a3))); |
|
89 | axisY->setShadesBrush(QBrush(QRgb(0xa5a2a3))); | |
90 | axisY->setShadesVisible(true); |
|
90 | axisY->setShadesVisible(true); | |
91 | //![3] |
|
91 | //![3] | |
92 |
|
92 | |||
93 | //![4] |
|
93 | //![4] | |
94 | axisX->append("low", 10); |
|
94 | axisX->append("low", 10); | |
95 | axisX->append("optimal", 20); |
|
95 | axisX->append("optimal", 20); | |
96 | axisX->append("high", 30); |
|
96 | axisX->append("high", 30); | |
97 | axisX->setRange(0, 30); |
|
97 | axisX->setRange(0, 30); | |
98 | // axisX->setRange("low","high"); |
|
|||
99 |
|
98 | |||
100 | axisY->append("slow", 10); |
|
99 | axisY->append("slow", 10); | |
101 | axisY->append("med", 20); |
|
100 | axisY->append("med", 20); | |
102 | axisY->append("fast", 30); |
|
101 | axisY->append("fast", 30); | |
103 | axisY->setRange(0, 30); |
|
102 | axisY->setRange(0, 30); | |
104 | // axisY->setRange("slow","fast"); |
|
|||
105 |
|
103 | |||
106 | chart->setAxisX(axisX, series); |
|
104 | chart->setAxisX(axisX, series); | |
107 | chart->setAxisY(axisY, series); |
|
105 | chart->setAxisY(axisY, series); | |
108 | axisX->setRange(0, 30); |
|
|||
109 | axisY->setRange(0, 30); |
|
|||
110 | //![4] |
|
106 | //![4] | |
111 |
|
107 | |||
112 | //![5] |
|
108 | //![5] | |
113 | QChartView* chartView = new QChartView(chart); |
|
109 | QChartView* chartView = new QChartView(chart); | |
114 | chartView->setRenderHint(QPainter::Antialiasing); |
|
110 | chartView->setRenderHint(QPainter::Antialiasing); | |
115 | //![5] |
|
111 | //![5] | |
116 |
|
112 | |||
117 | //![6] |
|
113 | //![6] | |
118 | QMainWindow window; |
|
114 | QMainWindow window; | |
119 | window.setCentralWidget(chartView); |
|
115 | window.setCentralWidget(chartView); | |
120 | window.resize(400, 300); |
|
116 | window.resize(400, 300); | |
121 | window.show(); |
|
117 | window.show(); | |
122 | //![6] |
|
118 | //![6] | |
123 |
|
119 | |||
124 | return a.exec(); |
|
120 | return a.exec(); | |
125 | } |
|
121 | } |
@@ -1,190 +1,190 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt 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 Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qintervalsaxis.h" |
|
21 | #include "qintervalsaxis.h" | |
22 | #include "qintervalsaxis_p.h" |
|
22 | #include "qintervalsaxis_p.h" | |
23 | #include "chartintervalsaxisx_p.h" |
|
23 | #include "chartintervalsaxisx_p.h" | |
24 | #include "chartintervalsaxisy_p.h" |
|
24 | #include "chartintervalsaxisy_p.h" | |
25 | #include <qmath.h> |
|
25 | #include <qmath.h> | |
26 | #include <QDebug> |
|
26 | #include <QDebug> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 | /*! |
|
29 | /*! | |
30 | \internal |
|
30 | \internal | |
31 | \class QIntervalsAxis |
|
31 | \class QIntervalsAxis | |
32 | \brief The QIntervalsAxis class is used for manipulating chart's axis. |
|
32 | \brief The QIntervalsAxis class is used for manipulating chart's axis. | |
33 | \mainclass |
|
33 | \mainclass | |
34 |
|
34 | |||
35 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
35 | Axis can be setup to show axis line with tick marks, grid lines and shades. | |
36 | */ |
|
36 | */ | |
37 |
|
37 | |||
38 | /*! |
|
38 | /*! | |
39 | \qmlclass Axis QIntervalsAxis |
|
39 | \qmlclass Axis QIntervalsAxis | |
40 | \brief The Axis element is used for manipulating chart's axes. |
|
40 | \brief The Axis element is used for manipulating chart's axes. | |
41 |
|
41 | |||
42 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
42 | Axis can be setup to show axis line with tick marks, grid lines and shades. | |
43 |
|
43 | |||
44 | To access Axes you can use ChartView API. For example: |
|
44 | To access Axes you can use ChartView API. For example: | |
45 | \code |
|
45 | \code | |
46 | // TODO :) |
|
46 | // TODO :) | |
47 | \endcode |
|
47 | \endcode | |
48 | */ |
|
48 | */ | |
49 |
|
49 | |||
50 | /*! |
|
50 | /*! | |
51 | Constructs an axis object which is a child of \a parent. |
|
51 | Constructs an axis object which is a child of \a parent. | |
52 | */ |
|
52 | */ | |
53 | QIntervalsAxis::QIntervalsAxis(QObject *parent): |
|
53 | QIntervalsAxis::QIntervalsAxis(QObject *parent): | |
54 | QValuesAxis(*new QIntervalsAxisPrivate(this),parent) |
|
54 | QValuesAxis(*new QIntervalsAxisPrivate(this),parent) | |
55 | { |
|
55 | { | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | Destroys the object |
|
59 | Destroys the object | |
60 | */ |
|
60 | */ | |
61 | QIntervalsAxis::~QIntervalsAxis() |
|
61 | QIntervalsAxis::~QIntervalsAxis() | |
62 | { |
|
62 | { | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | /*! |
|
65 | /*! | |
66 | \internal |
|
66 | \internal | |
67 | */ |
|
67 | */ | |
68 | QIntervalsAxis::QIntervalsAxis(QIntervalsAxisPrivate &d,QObject *parent):QValuesAxis(d,parent) |
|
68 | QIntervalsAxis::QIntervalsAxis(QIntervalsAxisPrivate &d,QObject *parent):QValuesAxis(d,parent) | |
69 | { |
|
69 | { | |
70 |
|
70 | |||
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | /*! |
|
73 | /*! | |
74 | Appends \a category to axis |
|
74 | Appends \a category to axis | |
75 | */ |
|
75 | */ | |
76 | void QIntervalsAxis::append(const QString& intervalLabel, qreal interval) |
|
76 | void QIntervalsAxis::append(const QString& intervalLabel, qreal interval) | |
77 | { |
|
77 | { | |
78 | Q_D(QIntervalsAxis); |
|
78 | Q_D(QIntervalsAxis); | |
79 | if (!d->m_intervals.contains(intervalLabel)) |
|
79 | if (!d->m_intervals.contains(intervalLabel)) | |
80 | { |
|
80 | { | |
81 | if(d->m_intervals.isEmpty()){ |
|
81 | if(d->m_intervals.isEmpty()){ | |
82 | Range range(d->m_categoryMinimum,interval); |
|
82 | Range range(d->m_categoryMinimum,interval); | |
83 | d->m_intervalsMap.insert(intervalLabel, range); |
|
83 | d->m_intervalsMap.insert(intervalLabel, range); | |
84 | d->m_intervals.append(intervalLabel); |
|
84 | d->m_intervals.append(intervalLabel); | |
85 | }else{ |
|
85 | }else{ | |
86 | Range range = d->m_intervalsMap.value(d->m_intervals.last()); |
|
86 | Range range = d->m_intervalsMap.value(d->m_intervals.last()); | |
87 | d->m_intervalsMap.insert(intervalLabel, Range(range.second,interval)); |
|
87 | d->m_intervalsMap.insert(intervalLabel, Range(range.second,interval)); | |
88 | d->m_intervals.append(intervalLabel); |
|
88 | d->m_intervals.append(intervalLabel); | |
89 | } |
|
89 | } | |
90 | setRange(d->m_min,interval); |
|
90 | // setRange(d->m_min,interval); | |
91 | } |
|
91 | } | |
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | void QIntervalsAxis::setFisrtIntervalMinimum(qreal min) |
|
94 | void QIntervalsAxis::setFisrtIntervalMinimum(qreal min) | |
95 | { |
|
95 | { | |
96 | Q_D(QIntervalsAxis); |
|
96 | Q_D(QIntervalsAxis); | |
97 | if(d->m_intervals.isEmpty()){ |
|
97 | if(d->m_intervals.isEmpty()){ | |
98 | d->m_categoryMinimum = min; |
|
98 | d->m_categoryMinimum = min; | |
99 | }else{ |
|
99 | }else{ | |
100 | Range range = d->m_intervalsMap.value(d->m_intervals.first()); |
|
100 | Range range = d->m_intervalsMap.value(d->m_intervals.first()); | |
101 | d->m_intervalsMap.insert(d->m_intervals.first(), Range(min, range.second)); |
|
101 | d->m_intervalsMap.insert(d->m_intervals.first(), Range(min, range.second)); | |
102 | setRange(min, d->m_min); |
|
102 | setRange(min, d->m_min); | |
103 | } |
|
103 | } | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | qreal QIntervalsAxis::intervalMin(const QString& intervalLabel) const |
|
106 | qreal QIntervalsAxis::intervalMin(const QString& intervalLabel) const | |
107 | { |
|
107 | { | |
108 | Q_D(const QIntervalsAxis); |
|
108 | Q_D(const QIntervalsAxis); | |
109 | return d->m_intervalsMap.value(intervalLabel).first; |
|
109 | return d->m_intervalsMap.value(intervalLabel).first; | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | qreal QIntervalsAxis::intervalMax(const QString& intervalLabel) const |
|
112 | qreal QIntervalsAxis::intervalMax(const QString& intervalLabel) const | |
113 | { |
|
113 | { | |
114 | Q_D(const QIntervalsAxis); |
|
114 | Q_D(const QIntervalsAxis); | |
115 | return d->m_intervalsMap.value(intervalLabel).second; |
|
115 | return d->m_intervalsMap.value(intervalLabel).second; | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | /*! |
|
118 | /*! | |
119 | Removes \a category from axis |
|
119 | Removes \a category from axis | |
120 | */ |
|
120 | */ | |
121 | void QIntervalsAxis::remove(const QString &intervalLabel) |
|
121 | void QIntervalsAxis::remove(const QString &intervalLabel) | |
122 | { |
|
122 | { | |
123 | Q_UNUSED(intervalLabel); |
|
123 | Q_UNUSED(intervalLabel); | |
124 | //TODO |
|
124 | //TODO | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | QStringList QIntervalsAxis::intervalsLabels() |
|
127 | QStringList QIntervalsAxis::intervalsLabels() | |
128 | { |
|
128 | { | |
129 | Q_D(QIntervalsAxis); |
|
129 | Q_D(QIntervalsAxis); | |
130 | return d->m_intervals; |
|
130 | return d->m_intervals; | |
131 | } |
|
131 | } | |
132 |
|
132 | |||
133 | /*! |
|
133 | /*! | |
134 | Returns number of categories. |
|
134 | Returns number of categories. | |
135 | */ |
|
135 | */ | |
136 | int QIntervalsAxis::count() const |
|
136 | int QIntervalsAxis::count() const | |
137 | { |
|
137 | { | |
138 | Q_D(const QIntervalsAxis); |
|
138 | Q_D(const QIntervalsAxis); | |
139 | return d->m_intervals.count(); |
|
139 | return d->m_intervals.count(); | |
140 | } |
|
140 | } | |
141 |
|
141 | |||
142 | /*! |
|
142 | /*! | |
143 | Returns the type of the axis |
|
143 | Returns the type of the axis | |
144 | */ |
|
144 | */ | |
145 | QAbstractAxis::AxisType QIntervalsAxis::type() const |
|
145 | QAbstractAxis::AxisType QIntervalsAxis::type() const | |
146 | { |
|
146 | { | |
147 | return AxisTypeCategories; |
|
147 | return AxisTypeCategories; | |
148 | } |
|
148 | } | |
149 |
|
149 | |||
150 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
150 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
151 |
|
151 | |||
152 | QIntervalsAxisPrivate::QIntervalsAxisPrivate(QIntervalsAxis* q): |
|
152 | QIntervalsAxisPrivate::QIntervalsAxisPrivate(QIntervalsAxis* q): | |
153 | QValuesAxisPrivate(q), |
|
153 | QValuesAxisPrivate(q), | |
154 | m_categoryMinimum(0) |
|
154 | m_categoryMinimum(0) | |
155 | { |
|
155 | { | |
156 |
|
156 | |||
157 | } |
|
157 | } | |
158 |
|
158 | |||
159 | QIntervalsAxisPrivate::~QIntervalsAxisPrivate() |
|
159 | QIntervalsAxisPrivate::~QIntervalsAxisPrivate() | |
160 | { |
|
160 | { | |
161 |
|
161 | |||
162 | } |
|
162 | } | |
163 |
|
163 | |||
164 | int QIntervalsAxisPrivate::ticksCount() const |
|
164 | int QIntervalsAxisPrivate::ticksCount() const | |
165 | { |
|
165 | { | |
166 | return m_intervals.count() + 1; |
|
166 | return m_intervals.count() + 1; | |
167 | } |
|
167 | } | |
168 |
|
168 | |||
169 | void QIntervalsAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) |
|
169 | void QIntervalsAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) | |
170 | { |
|
170 | { | |
171 | Q_UNUSED(count); |
|
171 | Q_UNUSED(count); | |
172 | m_min = min; |
|
172 | m_min = min; | |
173 | m_max = max; |
|
173 | m_max = max; | |
174 | // m_ticksCount = count; |
|
174 | // m_ticksCount = count; | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | ChartAxis* QIntervalsAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
177 | ChartAxis* QIntervalsAxisPrivate::createGraphics(ChartPresenter* presenter) | |
178 | { |
|
178 | { | |
179 | Q_Q(QIntervalsAxis); |
|
179 | Q_Q(QIntervalsAxis); | |
180 | if(m_orientation == Qt::Vertical){ |
|
180 | if(m_orientation == Qt::Vertical){ | |
181 | return new ChartIntervalAxisY(q,presenter); |
|
181 | return new ChartIntervalAxisY(q,presenter); | |
182 | }else{ |
|
182 | }else{ | |
183 | return new ChartIntervalAxisX(q,presenter); |
|
183 | return new ChartIntervalAxisX(q,presenter); | |
184 | } |
|
184 | } | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | #include "moc_qintervalsaxis.cpp" |
|
187 | #include "moc_qintervalsaxis.cpp" | |
188 | #include "moc_qintervalsaxis_p.cpp" |
|
188 | #include "moc_qintervalsaxis_p.cpp" | |
189 |
|
189 | |||
190 | QTCOMMERCIALCHART_END_NAMESPACE |
|
190 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,362 +1,368 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt 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 Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qvaluesaxis.h" |
|
21 | #include "qvaluesaxis.h" | |
22 | #include "qvaluesaxis_p.h" |
|
22 | #include "qvaluesaxis_p.h" | |
23 | #include "chartvaluesaxisx_p.h" |
|
23 | #include "chartvaluesaxisx_p.h" | |
24 | #include "chartvaluesaxisy_p.h" |
|
24 | #include "chartvaluesaxisy_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include <cmath> |
|
26 | #include <cmath> | |
27 | #include <QDebug> |
|
27 | #include <QDebug> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 | /*! |
|
30 | /*! | |
31 | \class QValuesAxis |
|
31 | \class QValuesAxis | |
32 | \brief The QValuesAxis class is used for manipulating chart's axis. |
|
32 | \brief The QValuesAxis class is used for manipulating chart's axis. | |
33 | \mainclass |
|
33 | \mainclass | |
34 |
|
34 | |||
35 | ValuesAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
35 | ValuesAxis can be setup to show axis line with tick marks, grid lines and shades. | |
36 | Values of axis are drawn to position of ticks |
|
36 | Values of axis are drawn to position of ticks | |
37 | */ |
|
37 | */ | |
38 |
|
38 | |||
39 | /*! |
|
39 | /*! | |
40 | \qmlclass ValuesAxis QValuesAxis |
|
40 | \qmlclass ValuesAxis QValuesAxis | |
41 | \brief The ValuesAxis element is used for manipulating chart's axes |
|
41 | \brief The ValuesAxis element is used for manipulating chart's axes | |
42 |
|
42 | |||
43 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
43 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. | |
44 | Values of axis are drawn to position of ticks |
|
44 | Values of axis are drawn to position of ticks | |
45 |
|
45 | |||
46 | To access Axes you can use ChartView API. For example: |
|
46 | To access Axes you can use ChartView API. For example: | |
47 | \code |
|
47 | \code | |
48 | ChartView { |
|
48 | ChartView { | |
49 | ValuesAxis { |
|
49 | ValuesAxis { | |
50 | id: xAxis |
|
50 | id: xAxis | |
51 | min: 0 |
|
51 | min: 0 | |
52 | max: 10 |
|
52 | max: 10 | |
53 | } |
|
53 | } | |
54 | // Add a few series... |
|
54 | // Add a few series... | |
55 | } |
|
55 | } | |
56 | \endcode |
|
56 | \endcode | |
57 | */ |
|
57 | */ | |
58 |
|
58 | |||
59 | /*! |
|
59 | /*! | |
60 | \property QValuesAxis::min |
|
60 | \property QValuesAxis::min | |
61 | Defines the minimum value on the axis. |
|
61 | Defines the minimum value on the axis. | |
62 | */ |
|
62 | */ | |
63 | /*! |
|
63 | /*! | |
64 | \qmlproperty real ValuesAxis::min |
|
64 | \qmlproperty real ValuesAxis::min | |
65 | Defines the minimum value on the axis. |
|
65 | Defines the minimum value on the axis. | |
66 | */ |
|
66 | */ | |
67 |
|
67 | |||
68 | /*! |
|
68 | /*! | |
69 | \property QValuesAxis::max |
|
69 | \property QValuesAxis::max | |
70 | Defines the maximum value on the axis. |
|
70 | Defines the maximum value on the axis. | |
71 | */ |
|
71 | */ | |
72 | /*! |
|
72 | /*! | |
73 | \qmlproperty real ValuesAxis::max |
|
73 | \qmlproperty real ValuesAxis::max | |
74 | Defines the maximum value on the axis. |
|
74 | Defines the maximum value on the axis. | |
75 | */ |
|
75 | */ | |
76 |
|
76 | |||
77 | /*! |
|
77 | /*! | |
78 | \fn void QValuesAxis::minChanged(qreal min) |
|
78 | \fn void QValuesAxis::minChanged(qreal min) | |
79 | Axis emits signal when \a min of axis has changed. |
|
79 | Axis emits signal when \a min of axis has changed. | |
80 | */ |
|
80 | */ | |
81 | /*! |
|
81 | /*! | |
82 | \qmlsignal ValuesAxis::onMinChanged(real min) |
|
82 | \qmlsignal ValuesAxis::onMinChanged(real min) | |
83 | Axis emits signal when \a min of axis has changed. |
|
83 | Axis emits signal when \a min of axis has changed. | |
84 | */ |
|
84 | */ | |
85 |
|
85 | |||
86 | /*! |
|
86 | /*! | |
87 | \fn void QValuesAxis::maxChanged(qreal max) |
|
87 | \fn void QValuesAxis::maxChanged(qreal max) | |
88 | Axis emits signal when \a max of axis has changed. |
|
88 | Axis emits signal when \a max of axis has changed. | |
89 | */ |
|
89 | */ | |
90 | /*! |
|
90 | /*! | |
91 | \qmlsignal ValuesAxis::onMaxChanged(real max) |
|
91 | \qmlsignal ValuesAxis::onMaxChanged(real max) | |
92 | Axis emits signal when \a max of axis has changed. |
|
92 | Axis emits signal when \a max of axis has changed. | |
93 | */ |
|
93 | */ | |
94 |
|
94 | |||
95 | /*! |
|
95 | /*! | |
96 | \fn void QValuesAxis::rangeChanged(qreal min, qreal max) |
|
96 | \fn void QValuesAxis::rangeChanged(qreal min, qreal max) | |
97 | Axis emits signal when \a min or \a max of axis has changed. |
|
97 | Axis emits signal when \a min or \a max of axis has changed. | |
98 | */ |
|
98 | */ | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 | \property QValuesAxis::ticksCount |
|
101 | \property QValuesAxis::ticksCount | |
102 | The number of tick marks for the axis. |
|
102 | The number of tick marks for the axis. | |
103 | */ |
|
103 | */ | |
104 |
|
104 | |||
105 | /*! |
|
105 | /*! | |
106 | \qmlproperty int ValuesAxis::ticksCount |
|
106 | \qmlproperty int ValuesAxis::ticksCount | |
107 | The number of tick marks for the axis. |
|
107 | The number of tick marks for the axis. | |
108 | */ |
|
108 | */ | |
109 |
|
109 | |||
110 | /*! |
|
110 | /*! | |
111 | \property QValuesAxis::niceNumbersEnabled |
|
111 | \property QValuesAxis::niceNumbersEnabled | |
112 | Whether the nice numbers algorithm is enabled or not for the axis. |
|
112 | Whether the nice numbers algorithm is enabled or not for the axis. | |
113 | */ |
|
113 | */ | |
114 |
|
114 | |||
115 | /*! |
|
115 | /*! | |
116 | \qmlproperty bool ValuesAxis::niceNumbersEnabled |
|
116 | \qmlproperty bool ValuesAxis::niceNumbersEnabled | |
117 | Whether the nice numbers algorithm is enabled or not for the axis. |
|
117 | Whether the nice numbers algorithm is enabled or not for the axis. | |
118 | */ |
|
118 | */ | |
119 |
|
119 | |||
120 | /*! |
|
120 | /*! | |
121 | Constructs an axis object which is a child of \a parent. |
|
121 | Constructs an axis object which is a child of \a parent. | |
122 | */ |
|
122 | */ | |
123 | QValuesAxis::QValuesAxis(QObject *parent) : |
|
123 | QValuesAxis::QValuesAxis(QObject *parent) : | |
124 | QAbstractAxis(*new QValuesAxisPrivate(this),parent) |
|
124 | QAbstractAxis(*new QValuesAxisPrivate(this),parent) | |
125 | { |
|
125 | { | |
126 |
|
126 | |||
127 | } |
|
127 | } | |
128 |
|
128 | |||
129 | /*! |
|
129 | /*! | |
130 | \internal |
|
130 | \internal | |
131 | */ |
|
131 | */ | |
132 | QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent) |
|
132 | QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent) | |
133 | { |
|
133 | { | |
134 |
|
134 | |||
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | /*! |
|
137 | /*! | |
138 | Destroys the object |
|
138 | Destroys the object | |
139 | */ |
|
139 | */ | |
140 | QValuesAxis::~QValuesAxis() |
|
140 | QValuesAxis::~QValuesAxis() | |
141 | { |
|
141 | { | |
142 |
|
142 | |||
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | void QValuesAxis::setMin(qreal min) |
|
145 | void QValuesAxis::setMin(qreal min) | |
146 | { |
|
146 | { | |
147 | Q_D(QValuesAxis); |
|
147 | Q_D(QValuesAxis); | |
148 | setRange(min,d->m_max); |
|
148 | setRange(min,d->m_max); | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | qreal QValuesAxis::min() const |
|
151 | qreal QValuesAxis::min() const | |
152 | { |
|
152 | { | |
153 | Q_D(const QValuesAxis); |
|
153 | Q_D(const QValuesAxis); | |
154 | return d->m_min; |
|
154 | return d->m_min; | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | void QValuesAxis::setMax(qreal max) |
|
157 | void QValuesAxis::setMax(qreal max) | |
158 | { |
|
158 | { | |
159 | Q_D(QValuesAxis); |
|
159 | Q_D(QValuesAxis); | |
160 | setRange(d->m_min,max); |
|
160 | setRange(d->m_min,max); | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | qreal QValuesAxis::max() const |
|
163 | qreal QValuesAxis::max() const | |
164 | { |
|
164 | { | |
165 | Q_D(const QValuesAxis); |
|
165 | Q_D(const QValuesAxis); | |
166 | return d->m_max; |
|
166 | return d->m_max; | |
167 | } |
|
167 | } | |
168 |
|
168 | |||
169 | /*! |
|
169 | /*! | |
170 | Sets range from \a min to \a max on the axis. |
|
170 | Sets range from \a min to \a max on the axis. | |
171 | */ |
|
171 | */ | |
172 | void QValuesAxis::setRange(qreal min, qreal max) |
|
172 | void QValuesAxis::setRange(qreal min, qreal max) | |
173 | { |
|
173 | { | |
174 | Q_D(QValuesAxis); |
|
174 | Q_D(QValuesAxis); | |
175 | bool changed = false; |
|
175 | bool changed = false; | |
176 |
|
176 | |||
177 | if (!qFuzzyIsNull(d->m_min - min)) { |
|
177 | if (!qFuzzyIsNull(d->m_min - min)) { | |
178 | d->m_min = min; |
|
178 | d->m_min = min; | |
179 | changed = true; |
|
179 | changed = true; | |
180 | emit minChanged(min); |
|
180 | emit minChanged(min); | |
181 | } |
|
181 | } | |
182 |
|
182 | |||
183 | if (!qFuzzyIsNull(d->m_max - max)) { |
|
183 | if (!qFuzzyIsNull(d->m_max - max)) { | |
184 | d->m_max = max; |
|
184 | d->m_max = max; | |
185 | changed = true; |
|
185 | changed = true; | |
186 | emit maxChanged(max); |
|
186 | emit maxChanged(max); | |
187 | } |
|
187 | } | |
188 |
|
188 | |||
189 | if(d->m_niceNumbers) d->looseNiceNumbers(d->m_min, d->m_max, d->m_tickCount); |
|
189 | if(d->m_niceNumbers) d->looseNiceNumbers(d->m_min, d->m_max, d->m_tickCount); | |
190 |
|
190 | |||
191 | if (changed) { |
|
191 | if (changed) { | |
192 | emit rangeChanged(d->m_min,d->m_max); |
|
192 | emit rangeChanged(d->m_min,d->m_max); | |
193 | d->emitUpdated(); |
|
193 | d->emitUpdated(); | |
194 | } |
|
194 | } | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | /*! |
|
197 | /*! | |
198 | Sets \a count for ticks on the axis. |
|
198 | Sets \a count for ticks on the axis. | |
199 | */ |
|
199 | */ | |
200 | void QValuesAxis::setTicksCount(int count) |
|
200 | void QValuesAxis::setTicksCount(int count) | |
201 | { |
|
201 | { | |
202 | Q_D(QValuesAxis); |
|
202 | Q_D(QValuesAxis); | |
203 | if (d->m_tickCount != count && count >=2) { |
|
203 | if (d->m_tickCount != count && count >=2) { | |
204 | d->m_tickCount = count; |
|
204 | d->m_tickCount = count; | |
205 | d->emitUpdated(); |
|
205 | d->emitUpdated(); | |
206 | } |
|
206 | } | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 | /*! |
|
209 | /*! | |
210 | \fn int QValuesAxis::ticksCount() const |
|
210 | \fn int QValuesAxis::ticksCount() const | |
211 | Return number of ticks on the axis |
|
211 | Return number of ticks on the axis | |
212 | */ |
|
212 | */ | |
213 | int QValuesAxis::ticksCount() const |
|
213 | int QValuesAxis::ticksCount() const | |
214 | { |
|
214 | { | |
215 | Q_D(const QValuesAxis); |
|
215 | Q_D(const QValuesAxis); | |
216 | return d->m_tickCount; |
|
216 | return d->m_tickCount; | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 | void QValuesAxis::setNiceNumbersEnabled(bool enable) |
|
219 | void QValuesAxis::setNiceNumbersEnabled(bool enable) | |
220 | { |
|
220 | { | |
221 | Q_D(QValuesAxis); |
|
221 | Q_D(QValuesAxis); | |
222 | if (d->m_niceNumbers != enable){ |
|
222 | if (d->m_niceNumbers != enable){ | |
223 | d->m_niceNumbers = enable; |
|
223 | d->m_niceNumbers = enable; | |
224 | if(enable && !qFuzzyIsNull(d->m_max - d->m_min)) setRange(d->min(),d->max()); |
|
224 | if(enable && !qFuzzyIsNull(d->m_max - d->m_min)) setRange(d->min(),d->max()); | |
225 | } |
|
225 | } | |
226 | } |
|
226 | } | |
227 |
|
227 | |||
228 | bool QValuesAxis::niceNumbersEnabled() const |
|
228 | bool QValuesAxis::niceNumbersEnabled() const | |
229 | { |
|
229 | { | |
230 | Q_D(const QValuesAxis); |
|
230 | Q_D(const QValuesAxis); | |
231 | return d->m_niceNumbers; |
|
231 | return d->m_niceNumbers; | |
232 | } |
|
232 | } | |
233 |
|
233 | |||
234 | /*! |
|
234 | /*! | |
235 | Returns the type of the axis |
|
235 | Returns the type of the axis | |
236 | */ |
|
236 | */ | |
237 | QAbstractAxis::AxisType QValuesAxis::type() const |
|
237 | QAbstractAxis::AxisType QValuesAxis::type() const | |
238 | { |
|
238 | { | |
239 | return AxisTypeValues; |
|
239 | return AxisTypeValues; | |
240 | } |
|
240 | } | |
241 |
|
241 | |||
242 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
242 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
243 |
|
243 | |||
244 | QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q): |
|
244 | QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q): | |
245 | QAbstractAxisPrivate(q), |
|
245 | QAbstractAxisPrivate(q), | |
246 | m_min(0), |
|
246 | m_min(0), | |
247 | m_max(0), |
|
247 | m_max(0), | |
248 | m_tickCount(5), |
|
248 | m_tickCount(5), | |
249 | m_niceNumbers(false) |
|
249 | m_niceNumbers(false) | |
250 | { |
|
250 | { | |
251 |
|
251 | |||
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | QValuesAxisPrivate::~QValuesAxisPrivate() |
|
254 | QValuesAxisPrivate::~QValuesAxisPrivate() | |
255 | { |
|
255 | { | |
256 |
|
256 | |||
257 | } |
|
257 | } | |
258 |
|
258 | |||
259 | void QValuesAxisPrivate::handleDomainUpdated() |
|
259 | void QValuesAxisPrivate::handleDomainUpdated() | |
260 | { |
|
260 | { | |
261 | Q_Q(QValuesAxis); |
|
261 | Q_Q(QValuesAxis); | |
262 | Domain* domain = qobject_cast<Domain*>(sender()); |
|
262 | Domain* domain = qobject_cast<Domain*>(sender()); | |
263 | Q_ASSERT(domain); |
|
263 | Q_ASSERT(domain); | |
264 |
|
264 | |||
265 | if(orientation()==Qt::Horizontal){ |
|
265 | if(orientation()==Qt::Horizontal){ | |
266 | q->setRange(domain->minX(),domain->maxX()); |
|
266 | q->setRange(domain->minX(),domain->maxX()); | |
267 | }else if(orientation()==Qt::Vertical){ |
|
267 | }else if(orientation()==Qt::Vertical){ | |
268 | q->setRange(domain->minY(),domain->maxY()); |
|
268 | q->setRange(domain->minY(),domain->maxY()); | |
269 | } |
|
269 | } | |
270 | } |
|
270 | } | |
271 |
|
271 | |||
272 |
|
272 | |||
273 | void QValuesAxisPrivate::setMin(const QVariant &min) |
|
273 | void QValuesAxisPrivate::setMin(const QVariant &min) | |
274 | { |
|
274 | { | |
275 | Q_Q(QValuesAxis); |
|
275 | Q_Q(QValuesAxis); | |
276 | bool ok; |
|
276 | bool ok; | |
277 | qreal value = min.toReal(&ok); |
|
277 | qreal value = min.toReal(&ok); | |
278 | if(ok) q->setMin(value); |
|
278 | if(ok) q->setMin(value); | |
279 | } |
|
279 | } | |
280 |
|
280 | |||
281 | void QValuesAxisPrivate::setMax(const QVariant &max) |
|
281 | void QValuesAxisPrivate::setMax(const QVariant &max) | |
282 | { |
|
282 | { | |
283 |
|
283 | |||
284 | Q_Q(QValuesAxis); |
|
284 | Q_Q(QValuesAxis); | |
285 | bool ok; |
|
285 | bool ok; | |
286 | qreal value = max.toReal(&ok); |
|
286 | qreal value = max.toReal(&ok); | |
287 | if(ok) q->setMax(value); |
|
287 | if(ok) q->setMax(value); | |
288 | } |
|
288 | } | |
289 |
|
289 | |||
290 | void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
290 | void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
291 | { |
|
291 | { | |
292 | Q_Q(QValuesAxis); |
|
292 | Q_Q(QValuesAxis); | |
293 | bool ok1; |
|
293 | bool ok1; | |
294 | bool ok2; |
|
294 | bool ok2; | |
295 | qreal value1 = min.toReal(&ok1); |
|
295 | qreal value1 = min.toReal(&ok1); | |
296 | qreal value2 = max.toReal(&ok2); |
|
296 | qreal value2 = max.toReal(&ok2); | |
297 | if(ok1&&ok2) q->setRange(value1,value2); |
|
297 | if(ok1&&ok2) q->setRange(value1,value2); | |
298 | } |
|
298 | } | |
299 |
|
299 | |||
300 | ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
300 | ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter) | |
301 | { |
|
301 | { | |
302 | Q_Q(QValuesAxis); |
|
302 | Q_Q(QValuesAxis); | |
303 | if(m_orientation == Qt::Vertical){ |
|
303 | if(m_orientation == Qt::Vertical){ | |
304 | return new ChartValuesAxisY(q,presenter); |
|
304 | return new ChartValuesAxisY(q,presenter); | |
305 | }else{ |
|
305 | }else{ | |
306 | return new ChartValuesAxisX(q,presenter); |
|
306 | return new ChartValuesAxisX(q,presenter); | |
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | } |
|
309 | } | |
310 |
|
310 | |||
311 | void QValuesAxisPrivate::intializeDomain(Domain* domain) |
|
311 | void QValuesAxisPrivate::intializeDomain(Domain* domain) | |
312 | { |
|
312 | { | |
313 | if(qFuzzyCompare(m_max,m_min)) { |
|
313 | if(qFuzzyCompare(m_max,m_min)) { | |
314 | if(m_orientation==Qt::Vertical){ |
|
314 | if(m_orientation==Qt::Vertical){ | |
315 | m_min = domain->minY(); |
|
315 | m_min = domain->minY(); | |
316 | m_max = domain->maxY(); |
|
316 | m_max = domain->maxY(); | |
317 | }else{ |
|
317 | }else{ | |
318 | m_min = domain->minX(); |
|
318 | m_min = domain->minX(); | |
319 | m_max = domain->maxX(); |
|
319 | m_max = domain->maxX(); | |
320 | } |
|
320 | } | |
|
321 | } else { | |||
|
322 | if(m_orientation==Qt::Vertical){ | |||
|
323 | domain->setRangeY(m_min, m_max); | |||
|
324 | }else{ | |||
|
325 | domain->setRangeX(m_min, m_max); | |||
|
326 | } | |||
321 | } |
|
327 | } | |
322 | } |
|
328 | } | |
323 |
|
329 | |||
324 | //algorithm defined by Paul S.Heckbert GraphicalGems I |
|
330 | //algorithm defined by Paul S.Heckbert GraphicalGems I | |
325 |
|
331 | |||
326 | void QValuesAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const |
|
332 | void QValuesAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const | |
327 | { |
|
333 | { | |
328 | qreal range = niceNumber(max-min,true); //range with ceiling |
|
334 | qreal range = niceNumber(max-min,true); //range with ceiling | |
329 | qreal step = niceNumber(range/(ticksCount-1),false); |
|
335 | qreal step = niceNumber(range/(ticksCount-1),false); | |
330 | min = floor(min/step); |
|
336 | min = floor(min/step); | |
331 | max = ceil(max/step); |
|
337 | max = ceil(max/step); | |
332 | ticksCount = int(max-min) +1; |
|
338 | ticksCount = int(max-min) +1; | |
333 | min*=step; |
|
339 | min*=step; | |
334 | max*=step; |
|
340 | max*=step; | |
335 | } |
|
341 | } | |
336 |
|
342 | |||
337 | //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n |
|
343 | //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n | |
338 |
|
344 | |||
339 | qreal QValuesAxisPrivate::niceNumber(qreal x,bool ceiling) const |
|
345 | qreal QValuesAxisPrivate::niceNumber(qreal x,bool ceiling) const | |
340 | { |
|
346 | { | |
341 | qreal z = pow(10,floor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x |
|
347 | qreal z = pow(10,floor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x | |
342 | qreal q = x/z;//q<10 && q>=1; |
|
348 | qreal q = x/z;//q<10 && q>=1; | |
343 |
|
349 | |||
344 | if(ceiling) { |
|
350 | if(ceiling) { | |
345 | if(q <= 1.0) q=1; |
|
351 | if(q <= 1.0) q=1; | |
346 | else if(q <= 2.0) q=2; |
|
352 | else if(q <= 2.0) q=2; | |
347 | else if(q <= 5.0) q=5; |
|
353 | else if(q <= 5.0) q=5; | |
348 | else q=10; |
|
354 | else q=10; | |
349 | } |
|
355 | } | |
350 | else { |
|
356 | else { | |
351 | if(q < 1.5) q=1; |
|
357 | if(q < 1.5) q=1; | |
352 | else if(q < 3.0) q=2; |
|
358 | else if(q < 3.0) q=2; | |
353 | else if(q < 7.0) q=5; |
|
359 | else if(q < 7.0) q=5; | |
354 | else q=10; |
|
360 | else q=10; | |
355 | } |
|
361 | } | |
356 | return q*z; |
|
362 | return q*z; | |
357 | } |
|
363 | } | |
358 |
|
364 | |||
359 | #include "moc_qvaluesaxis.cpp" |
|
365 | #include "moc_qvaluesaxis.cpp" | |
360 | #include "moc_qvaluesaxis_p.cpp" |
|
366 | #include "moc_qvaluesaxis_p.cpp" | |
361 |
|
367 | |||
362 | QTCOMMERCIALCHART_END_NAMESPACE |
|
368 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now