##// END OF EJS Templates
Fixes and tests to Interval axis
Marek Rosa -
r1708:f5ae73793525
parent child
Show More
@@ -0,0 +1,5
1 !include( ../auto.pri ) {
2 error( "Couldn't find the auto.pri file!" )
3 }
4 HEADERS += ../qabstractaxis/tst_qabstractaxis.h
5 SOURCES += tst_qintervalsaxis.cpp ../qabstractaxis/tst_qabstractaxis.cpp
@@ -0,0 +1,299
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "../qabstractaxis/tst_qabstractaxis.h"
22 #include "qintervalsaxis.h"
23 #include <qlineseries.h>
24
25 class tst_QIntervalsAxis: public tst_QAbstractAxis
26 {
27 Q_OBJECT
28
29 public slots:
30 void initTestCase();
31 void cleanupTestCase();
32 void init();
33 void cleanup();
34
35 private slots:
36 void qintervalsaxis_data();
37 void qintervalsaxis();
38
39 void max_raw_data();
40 void max_raw();
41 void max_data();
42 void max();
43 void max_animation_data();
44 void max_animation();
45 void min_raw_data();
46 void min_raw();
47 void min_data();
48 void min();
49 void min_animation_data();
50 void min_animation();
51 void range_raw_data();
52 void range_raw();
53 void range_data();
54 void range();
55 void range_animation_data();
56 void range_animation();
57
58 void interval_data();
59 void interval();
60
61 private:
62 QIntervalsAxis* m_intervalsaxis;
63 QLineSeries* m_series;
64 };
65
66 void tst_QIntervalsAxis::initTestCase()
67 {
68 }
69
70 void tst_QIntervalsAxis::cleanupTestCase()
71 {
72 }
73
74 void tst_QIntervalsAxis::init()
75 {
76 m_intervalsaxis = new QIntervalsAxis();
77 m_series = new QLineSeries();
78 *m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100);
79 tst_QAbstractAxis::init(m_intervalsaxis, m_series);
80 m_chart->addSeries(m_series);
81 m_chart->createDefaultAxes();
82 }
83
84 void tst_QIntervalsAxis::cleanup()
85 {
86 delete m_series;
87 delete m_intervalsaxis;
88 m_series = 0;
89 m_intervalsaxis = 0;
90 tst_QAbstractAxis::cleanup();
91 }
92
93 void tst_QIntervalsAxis::qintervalsaxis_data()
94 {
95 }
96
97 void tst_QIntervalsAxis::qintervalsaxis()
98 {
99 qabstractaxis();
100
101 QVERIFY(qFuzzyIsNull(m_intervalsaxis->max()));
102 QVERIFY(qFuzzyIsNull(m_intervalsaxis->min()));
103 QCOMPARE(m_intervalsaxis->type(), QAbstractAxis::AxisTypeIntervals);
104
105 m_chart->setAxisX(m_intervalsaxis, m_series);
106 m_view->show();
107 QTest::qWaitForWindowShown(m_view);
108
109 QVERIFY(!qFuzzyIsNull(m_intervalsaxis->max()));
110 QVERIFY(!qFuzzyIsNull(m_intervalsaxis->min()));
111 }
112
113 void tst_QIntervalsAxis::max_raw_data()
114 {
115 QTest::addColumn<qreal>("max");
116 QTest::newRow("1.0") << 1.0;
117 QTest::newRow("50.0") << 50.0;
118 QTest::newRow("101.0") << 101.0;
119 }
120
121 void tst_QIntervalsAxis::max_raw()
122 {
123 QFETCH(qreal, max);
124
125 QSignalSpy spy0(m_intervalsaxis, SIGNAL(maxChanged(qreal)));
126 QSignalSpy spy1(m_intervalsaxis, SIGNAL(minChanged(qreal)));
127 QSignalSpy spy2(m_intervalsaxis, SIGNAL(rangeChanged(qreal, qreal)));
128
129 m_intervalsaxis->setMax(max);
130 QVERIFY2(qFuzzyIsNull(m_intervalsaxis->max() - max), "Not equal");
131
132 QCOMPARE(spy0.count(), 1);
133 QCOMPARE(spy1.count(), 0);
134 QCOMPARE(spy2.count(), 1);
135 }
136
137 void tst_QIntervalsAxis::max_data()
138 {
139 max_raw_data();
140 }
141
142 void tst_QIntervalsAxis::max()
143 {
144 m_chart->setAxisX(m_intervalsaxis, m_series);
145 m_view->show();
146 QTest::qWaitForWindowShown(m_view);
147 max_raw();
148 }
149
150 void tst_QIntervalsAxis::max_animation_data()
151 {
152 max_data();
153 }
154
155 void tst_QIntervalsAxis::max_animation()
156 {
157 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
158 max();
159 }
160
161 void tst_QIntervalsAxis::min_raw_data()
162 {
163 QTest::addColumn<qreal>("min");
164 QTest::newRow("-1.0") << -1.0;
165 QTest::newRow("-50.0") << -50.0;
166 QTest::newRow("-101.0") << -101.0;
167 }
168
169 void tst_QIntervalsAxis::min_raw()
170 {
171 QFETCH(qreal, min);
172
173 QSignalSpy spy0(m_intervalsaxis, SIGNAL(maxChanged(qreal)));
174 QSignalSpy spy1(m_intervalsaxis, SIGNAL(minChanged(qreal)));
175 QSignalSpy spy2(m_intervalsaxis, SIGNAL(rangeChanged(qreal, qreal)));
176
177 m_intervalsaxis->setMin(min);
178 QVERIFY2(qFuzzyIsNull(m_intervalsaxis->min() - min), "Not equal");
179
180 QCOMPARE(spy0.count(), 0);
181 QCOMPARE(spy1.count(), 1);
182 QCOMPARE(spy2.count(), 1);
183 }
184
185 void tst_QIntervalsAxis::min_data()
186 {
187 min_raw_data();
188 }
189
190 void tst_QIntervalsAxis::min()
191 {
192 m_chart->setAxisX(m_intervalsaxis, m_series);
193 m_view->show();
194 QTest::qWaitForWindowShown(m_view);
195 min_raw();
196 }
197
198 void tst_QIntervalsAxis::min_animation_data()
199 {
200 min_data();
201 }
202
203 void tst_QIntervalsAxis::min_animation()
204 {
205 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
206 min();
207 }
208
209 void tst_QIntervalsAxis::range_raw_data()
210 {
211 QTest::addColumn<qreal>("min");
212 QTest::addColumn<qreal>("max");
213 QTest::newRow("1.0 - 101.0") << -1.0 << 101.0;
214 QTest::newRow("25.0 - 75.0") << 25.0 << 75.0;
215 QTest::newRow("101.0") << 40.0 << 60.0;
216 }
217
218 void tst_QIntervalsAxis::range_raw()
219 {
220 QFETCH(qreal, min);
221 QFETCH(qreal, max);
222
223 QSignalSpy spy0(m_intervalsaxis, SIGNAL(maxChanged(qreal)));
224 QSignalSpy spy1(m_intervalsaxis, SIGNAL(minChanged(qreal)));
225 QSignalSpy spy2(m_intervalsaxis, SIGNAL(rangeChanged(qreal, qreal)));
226
227 m_intervalsaxis->setRange(min, max);
228 QVERIFY2(qFuzzyIsNull(m_intervalsaxis->min() - min), "Min not equal");
229 QVERIFY2(qFuzzyIsNull(m_intervalsaxis->max() - max), "Max not equal");
230
231 QCOMPARE(spy0.count(), 1);
232 QCOMPARE(spy1.count(), 1);
233 QCOMPARE(spy2.count(), 1);
234 }
235
236 void tst_QIntervalsAxis::range_data()
237 {
238 range_raw_data();
239 }
240
241 void tst_QIntervalsAxis::range()
242 {
243 m_chart->setAxisX(m_intervalsaxis, m_series);
244 m_view->show();
245 QTest::qWaitForWindowShown(m_view);
246 range_raw();
247 }
248
249 void tst_QIntervalsAxis::range_animation_data()
250 {
251 range_data();
252 }
253
254 void tst_QIntervalsAxis::range_animation()
255 {
256 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
257 range();
258 }
259
260 void tst_QIntervalsAxis::interval_data()
261 {
262 //
263 }
264
265 void tst_QIntervalsAxis::interval()
266 {
267 // append one correct interval
268 m_intervalsaxis->append("first", (qreal)45);
269 QCOMPARE(m_intervalsaxis->intervalMin("first"), (qreal)0);
270 QCOMPARE(m_intervalsaxis->intervalMax("first"), (qreal)45);
271
272 // append one more correct interval
273 m_intervalsaxis->append("second", (qreal)75);
274 QCOMPARE(m_intervalsaxis->intervalMin("second"), (qreal)45);
275 QCOMPARE(m_intervalsaxis->intervalMax("second"), (qreal)75);
276
277 // append one incorrect interval
278 m_intervalsaxis->append("third", (qreal)15);
279 QCOMPARE(m_intervalsaxis->count(), 2);
280 QCOMPARE(m_intervalsaxis->intervalMax(m_intervalsaxis->intervalsLabels().last()), (qreal)75);
281 // QCOMPARE(intervalMax("first"), (qreal)75);
282
283 // append one more correct interval
284 m_intervalsaxis->append("third", (qreal)100);
285 QCOMPARE(m_intervalsaxis->count(), 3);
286 QCOMPARE(m_intervalsaxis->intervalMin("third"), (qreal)75);
287 QCOMPARE(m_intervalsaxis->intervalMax("third"), (qreal)100);
288
289 // remove one interval
290 m_intervalsaxis->remove("first");
291 QCOMPARE(m_intervalsaxis->count(), 2);
292 QCOMPARE(m_intervalsaxis->intervalMin("second"), (qreal)0); // second interval should extend to firstInterval minimum
293 QCOMPARE(m_intervalsaxis->intervalMax("second"), (qreal)75);
294
295 }
296
297 QTEST_MAIN(tst_QIntervalsAxis)
298 #include "tst_qintervalsaxis.moc"
299
@@ -1,122 +1,126
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "chartintervalsaxisx_p.h"
22 22 #include "qabstractaxis.h"
23 23 #include "chartpresenter_p.h"
24 24 #include "chartanimator_p.h"
25 25 #include <QGraphicsLayout>
26 26 #include <QDebug>
27 27 #include <QFontMetrics>
28 28 #include <cmath>
29 29 #include <QIntervalsAxis>
30 30
31 31 static int label_padding = 5;
32 32
33 33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34 34
35 35 ChartIntervalAxisX::ChartIntervalAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter)
36 36 {
37 37 }
38 38
39 39 ChartIntervalAxisX::~ChartIntervalAxisX()
40 40 {
41 41 }
42 42
43 43 QVector<qreal> ChartIntervalAxisX::calculateLayout() const
44 44 {
45 45 QIntervalsAxis *axis = qobject_cast<QIntervalsAxis *>(m_chartAxis);
46 46 int tickCount = axis->intervalsLabels().count() + 1;
47 47 QVector<qreal> points;
48
49 if (tickCount < 2)
50 return points;
51
48 52 points.resize(tickCount);
49 53
50 54 qreal scale = m_rect.width() / axis->max();
51 55 for (int i = 0; i < tickCount; ++i)
52 56 if (i < tickCount - 1) {
53 57 int x = axis->intervalMin(axis->intervalsLabels().at(i)) * scale + m_rect.left();
54 58 points[i] = x;
55 59 } else {
56 60 int x = axis->intervalMax(axis->intervalsLabels().at(i - 1)) * scale + m_rect.left();
57 61 points[i] = x;
58 62 }
59 63
60 64 return points;
61 65 }
62 66
63 67 void ChartIntervalAxisX::updateGeometry()
64 68 {
65 69 const QVector<qreal>& layout = ChartAxis::layout();
66 70
67 71 m_minWidth = 0;
68 72 m_minHeight = 0;
69 73
70 74 if(layout.isEmpty()) return;
71 75
72 76 QIntervalsAxis *intervalAxis = qobject_cast<QIntervalsAxis *>(m_chartAxis);
73 77
74 78 QStringList ticksList = intervalAxis->intervalsLabels();
75 79
76 80 // createNumberLabels(ticksList,m_min,m_max,layout.size());
77 81
78 82 QList<QGraphicsItem *> lines = m_grid->childItems();
79 83 QList<QGraphicsItem *> labels = m_labels->childItems();
80 84 QList<QGraphicsItem *> shades = m_shades->childItems();
81 85 QList<QGraphicsItem *> axis = m_axis->childItems();
82 86
83 87 // Q_ASSERT(labels.size() == ticksList.size());
84 88 // Q_ASSERT(layout.size() == ticksList.size());
85 89
86 90 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
87 91 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
88 92
89 93 // qreal width = 0;
90 94 for (int i = 0; i < layout.size(); ++i) {
91 95 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
92 96 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
93 97 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
94 98 if (i < ticksList.count()) {
95 99 labelItem->setText(ticksList.at(i));
96 100 }
97 101 const QRectF& rect = labelItem->boundingRect();
98 102 QPointF center = rect.center();
99 103 labelItem->setTransformOriginPoint(center.x(), center.y());
100 104 if (i < ticksList.count())
101 105 labelItem->setPos(layout[i] + (layout[i + 1] - layout[i]) / 2 - center.x(), m_rect.bottom() + label_padding);
102 106 else
103 107 labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding);
104 108
105 109 if(labelItem->pos().x() > m_rect.width() + m_rect.left() - rect.width() / 2){
106 110 labelItem->setVisible(false);
107 111 lineItem->setVisible(false);
108 112 }
109 113
110 114 m_minWidth += rect.width();
111 115 m_minHeight = qMax(rect.height(), m_minHeight);
112 116
113 117 if ((i + 1) % 2 && i > 1) {
114 118 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i / 2 - 1));
115 119 rectItem->setRect(layout[i - 1],m_rect.top(),layout[i]-layout[i - 1],m_rect.height());
116 120 }
117 121 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
118 122 lineItem->setLine(layout[i],m_rect.bottom(),layout[i], m_rect.bottom() + 5);
119 123 }
120 124 }
121 125
122 126 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,128 +1,132
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "chartintervalsaxisy_p.h"
22 22 #include "qabstractaxis.h"
23 23 #include "chartpresenter_p.h"
24 24 #include "chartanimator_p.h"
25 25 #include <QGraphicsLayout>
26 26 #include <QDebug>
27 27 #include <QFontMetrics>
28 28 #include <cmath>
29 29 #include <QIntervalsAxis>
30 30
31 31 static int label_padding = 5;
32 32
33 33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34 34
35 35 ChartIntervalAxisY::ChartIntervalAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter)
36 36 {
37 37 }
38 38
39 39 ChartIntervalAxisY::~ChartIntervalAxisY()
40 40 {
41 41 }
42 42
43 43 QVector<qreal> ChartIntervalAxisY::calculateLayout() const
44 44 {
45 45 QIntervalsAxis *axis = qobject_cast<QIntervalsAxis *>(m_chartAxis);
46 46 int tickCount = axis->intervalsLabels().count() + 1;
47 47 QVector<qreal> points;
48
49 if (tickCount < 2)
50 return points;
51
48 52 points.resize(tickCount);
49 53
50 54 qreal scale = m_rect.height() / axis->max();
51 55 for (int i = 0; i < tickCount; ++i)
52 56 if (i < tickCount - 1) {
53 57 int y = -axis->intervalMin(axis->intervalsLabels().at(i)) * scale + m_rect.bottom();
54 58 points[i] = y;
55 59 } else {
56 60 int y = -axis->intervalMax(axis->intervalsLabels().at(i - 1)) * scale + m_rect.bottom();
57 61 points[i] = y;
58 62 }
59 63
60 64 return points;
61 65 }
62 66
63 67 void ChartIntervalAxisY::updateGeometry()
64 68 {
65 69 const QVector<qreal> &layout = ChartAxis::layout();
66 70 m_minWidth = 0;
67 71 m_minHeight = 0;
68 72
69 73 if(layout.isEmpty()) return;
70 74
71 75 QIntervalsAxis *intervalAxis = qobject_cast<QIntervalsAxis *>(m_chartAxis);
72 76
73 77 QStringList ticksList = intervalAxis->intervalsLabels();
74 78
75 79 QList<QGraphicsItem *> lines = m_grid->childItems();
76 80 QList<QGraphicsItem *> labels = m_labels->childItems();
77 81 QList<QGraphicsItem *> shades = m_shades->childItems();
78 82 QList<QGraphicsItem *> axis = m_axis->childItems();
79 83
80 84 // Q_ASSERT(labels.size() == ticksList.size());
81 85 // Q_ASSERT(layout.size() == ticksList.size());
82 86
83 87 qreal height = 2*m_rect.bottom();
84 88
85 89 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
86 90 lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
87 91
88 92 for (int i = 0; i < layout.size(); ++i) {
89 93 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
90 94 lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]);
91 95 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
92 96
93 97 if (i < ticksList.count()) {
94 98 labelItem->setText(ticksList.at(i));
95 99 }
96 100 const QRectF& rect = labelItem->boundingRect();
97 101
98 102 QPointF center = rect.center();
99 103 labelItem->setTransformOriginPoint(center.x(), center.y());
100 104
101 105 if (i < ticksList.count())
102 106 labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] + (layout[i + 1] - layout[i]) / 2 - center.y());
103 107 else
104 108 labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y());
105 109
106 110 if(labelItem->pos().y()+rect.height()>height) {
107 111 labelItem->setVisible(false);
108 112 lineItem->setVisible(false);
109 113 }
110 114 else {
111 115 labelItem->setVisible(true);
112 116 lineItem->setVisible(true);
113 117 height=labelItem->pos().y();
114 118 }
115 119
116 120 m_minWidth=qMax(rect.width()+label_padding,m_minWidth);
117 121 m_minHeight+=rect.height();
118 122
119 123 if ((i+1)%2 && i>1) {
120 124 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
121 125 rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]);
122 126 }
123 127 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
124 128 lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]);
125 129 }
126 130 }
127 131
128 132 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,190 +1,210
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qintervalsaxis.h"
22 22 #include "qintervalsaxis_p.h"
23 23 #include "chartintervalsaxisx_p.h"
24 24 #include "chartintervalsaxisy_p.h"
25 25 #include <qmath.h>
26 26 #include <QDebug>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29 /*!
30 30 \internal
31 31 \class QIntervalsAxis
32 32 \brief The QIntervalsAxis class is used for manipulating chart's axis.
33 33 \mainclass
34 34
35 35 Axis can be setup to show axis line with tick marks, grid lines and shades.
36 36 */
37 37
38 38 /*!
39 39 \qmlclass Axis QIntervalsAxis
40 40 \brief The Axis element is used for manipulating chart's axes.
41 41
42 42 Axis can be setup to show axis line with tick marks, grid lines and shades.
43 43
44 44 To access Axes you can use ChartView API. For example:
45 45 \code
46 46 // TODO :)
47 47 \endcode
48 48 */
49 49
50 50 /*!
51 51 Constructs an axis object which is a child of \a parent.
52 52 */
53 53 QIntervalsAxis::QIntervalsAxis(QObject *parent):
54 54 QValuesAxis(*new QIntervalsAxisPrivate(this),parent)
55 55 {
56 56 }
57 57
58 58 /*!
59 59 Destroys the object
60 60 */
61 61 QIntervalsAxis::~QIntervalsAxis()
62 62 {
63 63 }
64 64
65 65 /*!
66 66 \internal
67 67 */
68 68 QIntervalsAxis::QIntervalsAxis(QIntervalsAxisPrivate &d,QObject *parent):QValuesAxis(d,parent)
69 69 {
70 70
71 71 }
72 72
73 73 /*!
74 74 Appends \a category to axis
75 75 */
76 76 void QIntervalsAxis::append(const QString& intervalLabel, qreal interval)
77 77 {
78 78 Q_D(QIntervalsAxis);
79
79 80 if (!d->m_intervals.contains(intervalLabel))
80 81 {
81 82 if(d->m_intervals.isEmpty()){
82 83 Range range(d->m_categoryMinimum,interval);
83 84 d->m_intervalsMap.insert(intervalLabel, range);
84 85 d->m_intervals.append(intervalLabel);
85 }else{
86 }else if (interval > intervalMax(d->m_intervals.last())){
86 87 Range range = d->m_intervalsMap.value(d->m_intervals.last());
87 88 d->m_intervalsMap.insert(intervalLabel, Range(range.second,interval));
88 89 d->m_intervals.append(intervalLabel);
89 90 }
90 // setRange(d->m_min,interval);
91 91 }
92 92 }
93 93
94 94 void QIntervalsAxis::setFisrtIntervalMinimum(qreal min)
95 95 {
96 96 Q_D(QIntervalsAxis);
97 97 if(d->m_intervals.isEmpty()){
98 98 d->m_categoryMinimum = min;
99 99 }else{
100 100 Range range = d->m_intervalsMap.value(d->m_intervals.first());
101 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 106 qreal QIntervalsAxis::intervalMin(const QString& intervalLabel) const
107 107 {
108 108 Q_D(const QIntervalsAxis);
109 109 return d->m_intervalsMap.value(intervalLabel).first;
110 110 }
111 111
112 112 qreal QIntervalsAxis::intervalMax(const QString& intervalLabel) const
113 113 {
114 114 Q_D(const QIntervalsAxis);
115 115 return d->m_intervalsMap.value(intervalLabel).second;
116 116 }
117 117
118 118 /*!
119 119 Removes \a category from axis
120 120 */
121 121 void QIntervalsAxis::remove(const QString &intervalLabel)
122 122 {
123 Q_UNUSED(intervalLabel);
124 //TODO
123 Q_D(QIntervalsAxis);
124 int labelIndex = d->m_intervals.indexOf(intervalLabel);
125
126 // check if such label exists
127 if (labelIndex != -1) {
128 d->m_intervals.removeAt(labelIndex);
129 d->m_intervalsMap.remove(intervalLabel);
130
131 // the range of the interval that follows (if exists) needs to be updated
132 if (labelIndex < d->m_intervals.count()) {
133 QString label = d->m_intervals.at(labelIndex);
134 Range range = d->m_intervalsMap.value(label);
135
136 // set the range
137 if (labelIndex == 0) {
138 range.first = d->m_categoryMinimum;
139 d->m_intervalsMap.insert(label, range);
140 } else {
141 range.first = d->m_intervalsMap.value(d->m_intervals.at(labelIndex - 1)).second;
142 d->m_intervalsMap.insert(label, range);
143 }
144 }
145 }
125 146 }
126 147
127 148 QStringList QIntervalsAxis::intervalsLabels()
128 149 {
129 150 Q_D(QIntervalsAxis);
130 151 return d->m_intervals;
131 152 }
132 153
133 154 /*!
134 155 Returns number of categories.
135 156 */
136 157 int QIntervalsAxis::count() const
137 158 {
138 159 Q_D(const QIntervalsAxis);
139 160 return d->m_intervals.count();
140 161 }
141 162
142 163 /*!
143 164 Returns the type of the axis
144 165 */
145 166 QAbstractAxis::AxisType QIntervalsAxis::type() const
146 167 {
147 return AxisTypeCategories;
168 return QAbstractAxis::AxisTypeIntervals;
148 169 }
149 170
150 171 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
151 172
152 173 QIntervalsAxisPrivate::QIntervalsAxisPrivate(QIntervalsAxis* q):
153 174 QValuesAxisPrivate(q),
154 175 m_categoryMinimum(0)
155 176 {
156 177
157 178 }
158 179
159 180 QIntervalsAxisPrivate::~QIntervalsAxisPrivate()
160 181 {
161 182
162 183 }
163 184
164 185 int QIntervalsAxisPrivate::ticksCount() const
165 186 {
166 187 return m_intervals.count() + 1;
167 188 }
168 189
169 190 void QIntervalsAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
170 191 {
171 192 Q_UNUSED(count);
172 193 m_min = min;
173 194 m_max = max;
174 // m_ticksCount = count;
175 195 }
176 196
177 197 ChartAxis* QIntervalsAxisPrivate::createGraphics(ChartPresenter* presenter)
178 198 {
179 199 Q_Q(QIntervalsAxis);
180 200 if(m_orientation == Qt::Vertical){
181 201 return new ChartIntervalAxisY(q,presenter);
182 202 }else{
183 203 return new ChartIntervalAxisX(q,presenter);
184 204 }
185 205 }
186 206
187 207 #include "moc_qintervalsaxis.cpp"
188 208 #include "moc_qintervalsaxis_p.cpp"
189 209
190 210 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,141 +1,142
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef QABSTRACTAXIS_H
22 22 #define QABSTRACTAXIS_H
23 23
24 24 #include <qchartglobal.h>
25 25 #include <QPen>
26 26 #include <QFont>
27 27 #include <QVariant>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 class QAbstractAxisPrivate;
32 32
33 33 class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject
34 34 {
35 35 Q_OBJECT
36 36 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
37 37 Q_PROPERTY(bool arrowVisible READ isArrowVisible WRITE setArrowVisible NOTIFY arrowVisibleChanged)
38 38 Q_PROPERTY(QColor color READ axisPenColor WRITE setAxisPenColor NOTIFY colorChanged)
39 39 Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
40 40 Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle)
41 41 Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont)
42 42 Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged)
43 43 Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged)
44 44 Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged)
45 45 Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged)
46 46 Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged)
47 47
48 48 public:
49 49
50 50 enum AxisType {
51 51 AxisTypeNoAxis = 0x0,
52 52 AxisTypeValues = 0x1,
53 AxisTypeCategories = 0x2
53 AxisTypeCategories = 0x2,
54 AxisTypeIntervals = 0x3
54 55 };
55 56
56 57 Q_DECLARE_FLAGS(AxisTypes, AxisType)
57 58
58 59 protected:
59 60 explicit QAbstractAxis(QAbstractAxisPrivate &d,QObject *parent = 0);
60 61
61 62 public:
62 63 ~QAbstractAxis();
63 64
64 65 virtual AxisType type() const = 0;
65 66
66 67 //visibilty hadnling
67 68 bool isVisible() const;
68 69 void setVisible(bool visible = true);
69 70
70 71
71 72 //axis handling
72 73 bool isArrowVisible() const;
73 74 void setArrowVisible(bool visible = true);
74 75 void setAxisPen(const QPen &pen);
75 76 QPen axisPen() const;
76 77 void setAxisPenColor(QColor color);
77 78 QColor axisPenColor() const;
78 79
79 80 //grid handling
80 81 bool isGridLineVisible() const;
81 82 void setGridLineVisible(bool visible = true);
82 83 void setGridLinePen(const QPen &pen);
83 84 QPen gridLinePen() const;
84 85
85 86 //labels handling
86 87 bool labelsVisible() const;
87 88 void setLabelsVisible(bool visible = true);
88 89 void setLabelsPen(const QPen &pen);
89 90 QPen labelsPen() const;
90 91 void setLabelsBrush(const QBrush &brush);
91 92 QBrush labelsBrush() const;
92 93 void setLabelsFont(const QFont &font);
93 94 QFont labelsFont() const;
94 95 void setLabelsAngle(int angle);
95 96 int labelsAngle() const;
96 97 void setLabelsColor(QColor color);
97 98 QColor labelsColor() const;
98 99
99 100 //shades handling
100 101 bool shadesVisible() const;
101 102 void setShadesVisible(bool visible = true);
102 103 void setShadesPen(const QPen &pen);
103 104 QPen shadesPen() const;
104 105 void setShadesBrush(const QBrush &brush);
105 106 QBrush shadesBrush() const;
106 107 void setShadesColor(QColor color);
107 108 QColor shadesColor() const;
108 109 void setShadesBorderColor(QColor color);
109 110 QColor shadesBorderColor() const;
110 111
111 112 Qt::Orientation orientation();
112 113
113 114 //range handling
114 115 void setMin(const QVariant &min);
115 116 void setMax(const QVariant &max);
116 117 void setRange(const QVariant &min, const QVariant &max);
117 118
118 119 void show();
119 120 void hide();
120 121
121 122 Q_SIGNALS:
122 123 void visibleChanged(bool visible);
123 124 void arrowVisibleChanged(bool visible);
124 125 void labelsVisibleChanged(bool visible);
125 126 void gridVisibleChanged(bool visible);
126 127 void colorChanged(QColor color);
127 128 void labelsColorChanged(QColor color);
128 129 void shadesVisibleChanged(bool visible);
129 130 void shadesColorChanged(QColor color);
130 131 void shadesBorderColorChanged(QColor color);
131 132
132 133 protected:
133 134 QScopedPointer<QAbstractAxisPrivate> d_ptr;
134 135 Q_DISABLE_COPY(QAbstractAxis);
135 136 friend class ChartDataSet;
136 137 friend class ChartAxis;
137 138 friend class ChartPresenter;
138 139 };
139 140
140 141 QTCOMMERCIALCHART_END_NAMESPACE
141 142 #endif
@@ -1,27 +1,28
1 1 !include( ../tests.pri ) {
2 2 error( "Couldn't find the tests.pri file!" )
3 3 }
4 4
5 5 TEMPLATE = subdirs
6 6 SUBDIRS += \
7 7 qchartview \
8 8 qchart \
9 9 qlineseries \
10 10 qbarset \
11 11 qbarseries \
12 12 qstackedbarseries \
13 13 qpercentbarseries \
14 14 qpieslice qpieseries \
15 15 qpiemodelmapper \
16 16 qsplineseries \
17 17 qscatterseries \
18 18 qxymodelmapper \
19 19 qbarmodelmapper \
20 20 qhorizontalbarseries \
21 21 qhorizontalstackedbarseries \
22 22 qhorizontalpercentbarseries \
23 qvaluesaxis
23 qvaluesaxis \
24 qintervalsaxis
24 25
25 26 test_private:{
26 27 SUBDIRS += domain chartdataset
27 28 }
1 NO CONTENT: modified file
General Comments 0
You need to be logged in to leave comments. Login now