##// 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 ** 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 "chartintervalsaxisx_p.h"
21 #include "chartintervalsaxisx_p.h"
22 #include "qabstractaxis.h"
22 #include "qabstractaxis.h"
23 #include "chartpresenter_p.h"
23 #include "chartpresenter_p.h"
24 #include "chartanimator_p.h"
24 #include "chartanimator_p.h"
25 #include <QGraphicsLayout>
25 #include <QGraphicsLayout>
26 #include <QDebug>
26 #include <QDebug>
27 #include <QFontMetrics>
27 #include <QFontMetrics>
28 #include <cmath>
28 #include <cmath>
29 #include <QIntervalsAxis>
29 #include <QIntervalsAxis>
30
30
31 static int label_padding = 5;
31 static int label_padding = 5;
32
32
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
34
35 ChartIntervalAxisX::ChartIntervalAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter)
35 ChartIntervalAxisX::ChartIntervalAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter)
36 {
36 {
37 }
37 }
38
38
39 ChartIntervalAxisX::~ChartIntervalAxisX()
39 ChartIntervalAxisX::~ChartIntervalAxisX()
40 {
40 {
41 }
41 }
42
42
43 QVector<qreal> ChartIntervalAxisX::calculateLayout() const
43 QVector<qreal> ChartIntervalAxisX::calculateLayout() const
44 {
44 {
45 QIntervalsAxis *axis = qobject_cast<QIntervalsAxis *>(m_chartAxis);
45 QIntervalsAxis *axis = qobject_cast<QIntervalsAxis *>(m_chartAxis);
46 int tickCount = axis->intervalsLabels().count() + 1;
46 int tickCount = axis->intervalsLabels().count() + 1;
47 QVector<qreal> points;
47 QVector<qreal> points;
48
49 if (tickCount < 2)
50 return points;
51
48 points.resize(tickCount);
52 points.resize(tickCount);
49
53
50 qreal scale = m_rect.width() / axis->max();
54 qreal scale = m_rect.width() / axis->max();
51 for (int i = 0; i < tickCount; ++i)
55 for (int i = 0; i < tickCount; ++i)
52 if (i < tickCount - 1) {
56 if (i < tickCount - 1) {
53 int x = axis->intervalMin(axis->intervalsLabels().at(i)) * scale + m_rect.left();
57 int x = axis->intervalMin(axis->intervalsLabels().at(i)) * scale + m_rect.left();
54 points[i] = x;
58 points[i] = x;
55 } else {
59 } else {
56 int x = axis->intervalMax(axis->intervalsLabels().at(i - 1)) * scale + m_rect.left();
60 int x = axis->intervalMax(axis->intervalsLabels().at(i - 1)) * scale + m_rect.left();
57 points[i] = x;
61 points[i] = x;
58 }
62 }
59
63
60 return points;
64 return points;
61 }
65 }
62
66
63 void ChartIntervalAxisX::updateGeometry()
67 void ChartIntervalAxisX::updateGeometry()
64 {
68 {
65 const QVector<qreal>& layout = ChartAxis::layout();
69 const QVector<qreal>& layout = ChartAxis::layout();
66
70
67 m_minWidth = 0;
71 m_minWidth = 0;
68 m_minHeight = 0;
72 m_minHeight = 0;
69
73
70 if(layout.isEmpty()) return;
74 if(layout.isEmpty()) return;
71
75
72 QIntervalsAxis *intervalAxis = qobject_cast<QIntervalsAxis *>(m_chartAxis);
76 QIntervalsAxis *intervalAxis = qobject_cast<QIntervalsAxis *>(m_chartAxis);
73
77
74 QStringList ticksList = intervalAxis->intervalsLabels();
78 QStringList ticksList = intervalAxis->intervalsLabels();
75
79
76 // createNumberLabels(ticksList,m_min,m_max,layout.size());
80 // createNumberLabels(ticksList,m_min,m_max,layout.size());
77
81
78 QList<QGraphicsItem *> lines = m_grid->childItems();
82 QList<QGraphicsItem *> lines = m_grid->childItems();
79 QList<QGraphicsItem *> labels = m_labels->childItems();
83 QList<QGraphicsItem *> labels = m_labels->childItems();
80 QList<QGraphicsItem *> shades = m_shades->childItems();
84 QList<QGraphicsItem *> shades = m_shades->childItems();
81 QList<QGraphicsItem *> axis = m_axis->childItems();
85 QList<QGraphicsItem *> axis = m_axis->childItems();
82
86
83 // Q_ASSERT(labels.size() == ticksList.size());
87 // Q_ASSERT(labels.size() == ticksList.size());
84 // Q_ASSERT(layout.size() == ticksList.size());
88 // Q_ASSERT(layout.size() == ticksList.size());
85
89
86 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
90 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
87 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
91 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
88
92
89 // qreal width = 0;
93 // qreal width = 0;
90 for (int i = 0; i < layout.size(); ++i) {
94 for (int i = 0; i < layout.size(); ++i) {
91 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
95 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
92 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
96 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
93 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
97 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
94 if (i < ticksList.count()) {
98 if (i < ticksList.count()) {
95 labelItem->setText(ticksList.at(i));
99 labelItem->setText(ticksList.at(i));
96 }
100 }
97 const QRectF& rect = labelItem->boundingRect();
101 const QRectF& rect = labelItem->boundingRect();
98 QPointF center = rect.center();
102 QPointF center = rect.center();
99 labelItem->setTransformOriginPoint(center.x(), center.y());
103 labelItem->setTransformOriginPoint(center.x(), center.y());
100 if (i < ticksList.count())
104 if (i < ticksList.count())
101 labelItem->setPos(layout[i] + (layout[i + 1] - layout[i]) / 2 - center.x(), m_rect.bottom() + label_padding);
105 labelItem->setPos(layout[i] + (layout[i + 1] - layout[i]) / 2 - center.x(), m_rect.bottom() + label_padding);
102 else
106 else
103 labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding);
107 labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding);
104
108
105 if(labelItem->pos().x() > m_rect.width() + m_rect.left() - rect.width() / 2){
109 if(labelItem->pos().x() > m_rect.width() + m_rect.left() - rect.width() / 2){
106 labelItem->setVisible(false);
110 labelItem->setVisible(false);
107 lineItem->setVisible(false);
111 lineItem->setVisible(false);
108 }
112 }
109
113
110 m_minWidth += rect.width();
114 m_minWidth += rect.width();
111 m_minHeight = qMax(rect.height(), m_minHeight);
115 m_minHeight = qMax(rect.height(), m_minHeight);
112
116
113 if ((i + 1) % 2 && i > 1) {
117 if ((i + 1) % 2 && i > 1) {
114 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i / 2 - 1));
118 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i / 2 - 1));
115 rectItem->setRect(layout[i - 1],m_rect.top(),layout[i]-layout[i - 1],m_rect.height());
119 rectItem->setRect(layout[i - 1],m_rect.top(),layout[i]-layout[i - 1],m_rect.height());
116 }
120 }
117 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
121 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
118 lineItem->setLine(layout[i],m_rect.bottom(),layout[i], m_rect.bottom() + 5);
122 lineItem->setLine(layout[i],m_rect.bottom(),layout[i], m_rect.bottom() + 5);
119 }
123 }
120 }
124 }
121
125
122 QTCOMMERCIALCHART_END_NAMESPACE
126 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,128 +1,132
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 "chartintervalsaxisy_p.h"
21 #include "chartintervalsaxisy_p.h"
22 #include "qabstractaxis.h"
22 #include "qabstractaxis.h"
23 #include "chartpresenter_p.h"
23 #include "chartpresenter_p.h"
24 #include "chartanimator_p.h"
24 #include "chartanimator_p.h"
25 #include <QGraphicsLayout>
25 #include <QGraphicsLayout>
26 #include <QDebug>
26 #include <QDebug>
27 #include <QFontMetrics>
27 #include <QFontMetrics>
28 #include <cmath>
28 #include <cmath>
29 #include <QIntervalsAxis>
29 #include <QIntervalsAxis>
30
30
31 static int label_padding = 5;
31 static int label_padding = 5;
32
32
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
34
35 ChartIntervalAxisY::ChartIntervalAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter)
35 ChartIntervalAxisY::ChartIntervalAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter)
36 {
36 {
37 }
37 }
38
38
39 ChartIntervalAxisY::~ChartIntervalAxisY()
39 ChartIntervalAxisY::~ChartIntervalAxisY()
40 {
40 {
41 }
41 }
42
42
43 QVector<qreal> ChartIntervalAxisY::calculateLayout() const
43 QVector<qreal> ChartIntervalAxisY::calculateLayout() const
44 {
44 {
45 QIntervalsAxis *axis = qobject_cast<QIntervalsAxis *>(m_chartAxis);
45 QIntervalsAxis *axis = qobject_cast<QIntervalsAxis *>(m_chartAxis);
46 int tickCount = axis->intervalsLabels().count() + 1;
46 int tickCount = axis->intervalsLabels().count() + 1;
47 QVector<qreal> points;
47 QVector<qreal> points;
48
49 if (tickCount < 2)
50 return points;
51
48 points.resize(tickCount);
52 points.resize(tickCount);
49
53
50 qreal scale = m_rect.height() / axis->max();
54 qreal scale = m_rect.height() / axis->max();
51 for (int i = 0; i < tickCount; ++i)
55 for (int i = 0; i < tickCount; ++i)
52 if (i < tickCount - 1) {
56 if (i < tickCount - 1) {
53 int y = -axis->intervalMin(axis->intervalsLabels().at(i)) * scale + m_rect.bottom();
57 int y = -axis->intervalMin(axis->intervalsLabels().at(i)) * scale + m_rect.bottom();
54 points[i] = y;
58 points[i] = y;
55 } else {
59 } else {
56 int y = -axis->intervalMax(axis->intervalsLabels().at(i - 1)) * scale + m_rect.bottom();
60 int y = -axis->intervalMax(axis->intervalsLabels().at(i - 1)) * scale + m_rect.bottom();
57 points[i] = y;
61 points[i] = y;
58 }
62 }
59
63
60 return points;
64 return points;
61 }
65 }
62
66
63 void ChartIntervalAxisY::updateGeometry()
67 void ChartIntervalAxisY::updateGeometry()
64 {
68 {
65 const QVector<qreal> &layout = ChartAxis::layout();
69 const QVector<qreal> &layout = ChartAxis::layout();
66 m_minWidth = 0;
70 m_minWidth = 0;
67 m_minHeight = 0;
71 m_minHeight = 0;
68
72
69 if(layout.isEmpty()) return;
73 if(layout.isEmpty()) return;
70
74
71 QIntervalsAxis *intervalAxis = qobject_cast<QIntervalsAxis *>(m_chartAxis);
75 QIntervalsAxis *intervalAxis = qobject_cast<QIntervalsAxis *>(m_chartAxis);
72
76
73 QStringList ticksList = intervalAxis->intervalsLabels();
77 QStringList ticksList = intervalAxis->intervalsLabels();
74
78
75 QList<QGraphicsItem *> lines = m_grid->childItems();
79 QList<QGraphicsItem *> lines = m_grid->childItems();
76 QList<QGraphicsItem *> labels = m_labels->childItems();
80 QList<QGraphicsItem *> labels = m_labels->childItems();
77 QList<QGraphicsItem *> shades = m_shades->childItems();
81 QList<QGraphicsItem *> shades = m_shades->childItems();
78 QList<QGraphicsItem *> axis = m_axis->childItems();
82 QList<QGraphicsItem *> axis = m_axis->childItems();
79
83
80 // Q_ASSERT(labels.size() == ticksList.size());
84 // Q_ASSERT(labels.size() == ticksList.size());
81 // Q_ASSERT(layout.size() == ticksList.size());
85 // Q_ASSERT(layout.size() == ticksList.size());
82
86
83 qreal height = 2*m_rect.bottom();
87 qreal height = 2*m_rect.bottom();
84
88
85 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
89 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
86 lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
90 lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
87
91
88 for (int i = 0; i < layout.size(); ++i) {
92 for (int i = 0; i < layout.size(); ++i) {
89 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
93 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
90 lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]);
94 lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]);
91 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
95 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
92
96
93 if (i < ticksList.count()) {
97 if (i < ticksList.count()) {
94 labelItem->setText(ticksList.at(i));
98 labelItem->setText(ticksList.at(i));
95 }
99 }
96 const QRectF& rect = labelItem->boundingRect();
100 const QRectF& rect = labelItem->boundingRect();
97
101
98 QPointF center = rect.center();
102 QPointF center = rect.center();
99 labelItem->setTransformOriginPoint(center.x(), center.y());
103 labelItem->setTransformOriginPoint(center.x(), center.y());
100
104
101 if (i < ticksList.count())
105 if (i < ticksList.count())
102 labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] + (layout[i + 1] - layout[i]) / 2 - center.y());
106 labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] + (layout[i + 1] - layout[i]) / 2 - center.y());
103 else
107 else
104 labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y());
108 labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y());
105
109
106 if(labelItem->pos().y()+rect.height()>height) {
110 if(labelItem->pos().y()+rect.height()>height) {
107 labelItem->setVisible(false);
111 labelItem->setVisible(false);
108 lineItem->setVisible(false);
112 lineItem->setVisible(false);
109 }
113 }
110 else {
114 else {
111 labelItem->setVisible(true);
115 labelItem->setVisible(true);
112 lineItem->setVisible(true);
116 lineItem->setVisible(true);
113 height=labelItem->pos().y();
117 height=labelItem->pos().y();
114 }
118 }
115
119
116 m_minWidth=qMax(rect.width()+label_padding,m_minWidth);
120 m_minWidth=qMax(rect.width()+label_padding,m_minWidth);
117 m_minHeight+=rect.height();
121 m_minHeight+=rect.height();
118
122
119 if ((i+1)%2 && i>1) {
123 if ((i+1)%2 && i>1) {
120 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
124 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
121 rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]);
125 rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]);
122 }
126 }
123 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
127 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
124 lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]);
128 lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]);
125 }
129 }
126 }
130 }
127
131
128 QTCOMMERCIALCHART_END_NAMESPACE
132 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,190 +1,210
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
79 if (!d->m_intervals.contains(intervalLabel))
80 if (!d->m_intervals.contains(intervalLabel))
80 {
81 {
81 if(d->m_intervals.isEmpty()){
82 if(d->m_intervals.isEmpty()){
82 Range range(d->m_categoryMinimum,interval);
83 Range range(d->m_categoryMinimum,interval);
83 d->m_intervalsMap.insert(intervalLabel, range);
84 d->m_intervalsMap.insert(intervalLabel, range);
84 d->m_intervals.append(intervalLabel);
85 d->m_intervals.append(intervalLabel);
85 }else{
86 }else if (interval > intervalMax(d->m_intervals.last())){
86 Range range = d->m_intervalsMap.value(d->m_intervals.last());
87 Range range = d->m_intervalsMap.value(d->m_intervals.last());
87 d->m_intervalsMap.insert(intervalLabel, Range(range.second,interval));
88 d->m_intervalsMap.insert(intervalLabel, Range(range.second,interval));
88 d->m_intervals.append(intervalLabel);
89 d->m_intervals.append(intervalLabel);
89 }
90 }
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_D(QIntervalsAxis);
124 //TODO
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 QStringList QIntervalsAxis::intervalsLabels()
148 QStringList QIntervalsAxis::intervalsLabels()
128 {
149 {
129 Q_D(QIntervalsAxis);
150 Q_D(QIntervalsAxis);
130 return d->m_intervals;
151 return d->m_intervals;
131 }
152 }
132
153
133 /*!
154 /*!
134 Returns number of categories.
155 Returns number of categories.
135 */
156 */
136 int QIntervalsAxis::count() const
157 int QIntervalsAxis::count() const
137 {
158 {
138 Q_D(const QIntervalsAxis);
159 Q_D(const QIntervalsAxis);
139 return d->m_intervals.count();
160 return d->m_intervals.count();
140 }
161 }
141
162
142 /*!
163 /*!
143 Returns the type of the axis
164 Returns the type of the axis
144 */
165 */
145 QAbstractAxis::AxisType QIntervalsAxis::type() const
166 QAbstractAxis::AxisType QIntervalsAxis::type() const
146 {
167 {
147 return AxisTypeCategories;
168 return QAbstractAxis::AxisTypeIntervals;
148 }
169 }
149
170
150 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
171 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
151
172
152 QIntervalsAxisPrivate::QIntervalsAxisPrivate(QIntervalsAxis* q):
173 QIntervalsAxisPrivate::QIntervalsAxisPrivate(QIntervalsAxis* q):
153 QValuesAxisPrivate(q),
174 QValuesAxisPrivate(q),
154 m_categoryMinimum(0)
175 m_categoryMinimum(0)
155 {
176 {
156
177
157 }
178 }
158
179
159 QIntervalsAxisPrivate::~QIntervalsAxisPrivate()
180 QIntervalsAxisPrivate::~QIntervalsAxisPrivate()
160 {
181 {
161
182
162 }
183 }
163
184
164 int QIntervalsAxisPrivate::ticksCount() const
185 int QIntervalsAxisPrivate::ticksCount() const
165 {
186 {
166 return m_intervals.count() + 1;
187 return m_intervals.count() + 1;
167 }
188 }
168
189
169 void QIntervalsAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
190 void QIntervalsAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
170 {
191 {
171 Q_UNUSED(count);
192 Q_UNUSED(count);
172 m_min = min;
193 m_min = min;
173 m_max = max;
194 m_max = max;
174 // m_ticksCount = count;
175 }
195 }
176
196
177 ChartAxis* QIntervalsAxisPrivate::createGraphics(ChartPresenter* presenter)
197 ChartAxis* QIntervalsAxisPrivate::createGraphics(ChartPresenter* presenter)
178 {
198 {
179 Q_Q(QIntervalsAxis);
199 Q_Q(QIntervalsAxis);
180 if(m_orientation == Qt::Vertical){
200 if(m_orientation == Qt::Vertical){
181 return new ChartIntervalAxisY(q,presenter);
201 return new ChartIntervalAxisY(q,presenter);
182 }else{
202 }else{
183 return new ChartIntervalAxisX(q,presenter);
203 return new ChartIntervalAxisX(q,presenter);
184 }
204 }
185 }
205 }
186
206
187 #include "moc_qintervalsaxis.cpp"
207 #include "moc_qintervalsaxis.cpp"
188 #include "moc_qintervalsaxis_p.cpp"
208 #include "moc_qintervalsaxis_p.cpp"
189
209
190 QTCOMMERCIALCHART_END_NAMESPACE
210 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,141 +1,142
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 #ifndef QABSTRACTAXIS_H
21 #ifndef QABSTRACTAXIS_H
22 #define QABSTRACTAXIS_H
22 #define QABSTRACTAXIS_H
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <QPen>
25 #include <QPen>
26 #include <QFont>
26 #include <QFont>
27 #include <QVariant>
27 #include <QVariant>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class QAbstractAxisPrivate;
31 class QAbstractAxisPrivate;
32
32
33 class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject
33 class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
36 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
37 Q_PROPERTY(bool arrowVisible READ isArrowVisible WRITE setArrowVisible NOTIFY arrowVisibleChanged)
37 Q_PROPERTY(bool arrowVisible READ isArrowVisible WRITE setArrowVisible NOTIFY arrowVisibleChanged)
38 Q_PROPERTY(QColor color READ axisPenColor WRITE setAxisPenColor NOTIFY colorChanged)
38 Q_PROPERTY(QColor color READ axisPenColor WRITE setAxisPenColor NOTIFY colorChanged)
39 Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
39 Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
40 Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle)
40 Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle)
41 Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont)
41 Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont)
42 Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged)
42 Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged)
43 Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged)
43 Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged)
44 Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged)
44 Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged)
45 Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged)
45 Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged)
46 Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged)
46 Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged)
47
47
48 public:
48 public:
49
49
50 enum AxisType {
50 enum AxisType {
51 AxisTypeNoAxis = 0x0,
51 AxisTypeNoAxis = 0x0,
52 AxisTypeValues = 0x1,
52 AxisTypeValues = 0x1,
53 AxisTypeCategories = 0x2
53 AxisTypeCategories = 0x2,
54 AxisTypeIntervals = 0x3
54 };
55 };
55
56
56 Q_DECLARE_FLAGS(AxisTypes, AxisType)
57 Q_DECLARE_FLAGS(AxisTypes, AxisType)
57
58
58 protected:
59 protected:
59 explicit QAbstractAxis(QAbstractAxisPrivate &d,QObject *parent = 0);
60 explicit QAbstractAxis(QAbstractAxisPrivate &d,QObject *parent = 0);
60
61
61 public:
62 public:
62 ~QAbstractAxis();
63 ~QAbstractAxis();
63
64
64 virtual AxisType type() const = 0;
65 virtual AxisType type() const = 0;
65
66
66 //visibilty hadnling
67 //visibilty hadnling
67 bool isVisible() const;
68 bool isVisible() const;
68 void setVisible(bool visible = true);
69 void setVisible(bool visible = true);
69
70
70
71
71 //axis handling
72 //axis handling
72 bool isArrowVisible() const;
73 bool isArrowVisible() const;
73 void setArrowVisible(bool visible = true);
74 void setArrowVisible(bool visible = true);
74 void setAxisPen(const QPen &pen);
75 void setAxisPen(const QPen &pen);
75 QPen axisPen() const;
76 QPen axisPen() const;
76 void setAxisPenColor(QColor color);
77 void setAxisPenColor(QColor color);
77 QColor axisPenColor() const;
78 QColor axisPenColor() const;
78
79
79 //grid handling
80 //grid handling
80 bool isGridLineVisible() const;
81 bool isGridLineVisible() const;
81 void setGridLineVisible(bool visible = true);
82 void setGridLineVisible(bool visible = true);
82 void setGridLinePen(const QPen &pen);
83 void setGridLinePen(const QPen &pen);
83 QPen gridLinePen() const;
84 QPen gridLinePen() const;
84
85
85 //labels handling
86 //labels handling
86 bool labelsVisible() const;
87 bool labelsVisible() const;
87 void setLabelsVisible(bool visible = true);
88 void setLabelsVisible(bool visible = true);
88 void setLabelsPen(const QPen &pen);
89 void setLabelsPen(const QPen &pen);
89 QPen labelsPen() const;
90 QPen labelsPen() const;
90 void setLabelsBrush(const QBrush &brush);
91 void setLabelsBrush(const QBrush &brush);
91 QBrush labelsBrush() const;
92 QBrush labelsBrush() const;
92 void setLabelsFont(const QFont &font);
93 void setLabelsFont(const QFont &font);
93 QFont labelsFont() const;
94 QFont labelsFont() const;
94 void setLabelsAngle(int angle);
95 void setLabelsAngle(int angle);
95 int labelsAngle() const;
96 int labelsAngle() const;
96 void setLabelsColor(QColor color);
97 void setLabelsColor(QColor color);
97 QColor labelsColor() const;
98 QColor labelsColor() const;
98
99
99 //shades handling
100 //shades handling
100 bool shadesVisible() const;
101 bool shadesVisible() const;
101 void setShadesVisible(bool visible = true);
102 void setShadesVisible(bool visible = true);
102 void setShadesPen(const QPen &pen);
103 void setShadesPen(const QPen &pen);
103 QPen shadesPen() const;
104 QPen shadesPen() const;
104 void setShadesBrush(const QBrush &brush);
105 void setShadesBrush(const QBrush &brush);
105 QBrush shadesBrush() const;
106 QBrush shadesBrush() const;
106 void setShadesColor(QColor color);
107 void setShadesColor(QColor color);
107 QColor shadesColor() const;
108 QColor shadesColor() const;
108 void setShadesBorderColor(QColor color);
109 void setShadesBorderColor(QColor color);
109 QColor shadesBorderColor() const;
110 QColor shadesBorderColor() const;
110
111
111 Qt::Orientation orientation();
112 Qt::Orientation orientation();
112
113
113 //range handling
114 //range handling
114 void setMin(const QVariant &min);
115 void setMin(const QVariant &min);
115 void setMax(const QVariant &max);
116 void setMax(const QVariant &max);
116 void setRange(const QVariant &min, const QVariant &max);
117 void setRange(const QVariant &min, const QVariant &max);
117
118
118 void show();
119 void show();
119 void hide();
120 void hide();
120
121
121 Q_SIGNALS:
122 Q_SIGNALS:
122 void visibleChanged(bool visible);
123 void visibleChanged(bool visible);
123 void arrowVisibleChanged(bool visible);
124 void arrowVisibleChanged(bool visible);
124 void labelsVisibleChanged(bool visible);
125 void labelsVisibleChanged(bool visible);
125 void gridVisibleChanged(bool visible);
126 void gridVisibleChanged(bool visible);
126 void colorChanged(QColor color);
127 void colorChanged(QColor color);
127 void labelsColorChanged(QColor color);
128 void labelsColorChanged(QColor color);
128 void shadesVisibleChanged(bool visible);
129 void shadesVisibleChanged(bool visible);
129 void shadesColorChanged(QColor color);
130 void shadesColorChanged(QColor color);
130 void shadesBorderColorChanged(QColor color);
131 void shadesBorderColorChanged(QColor color);
131
132
132 protected:
133 protected:
133 QScopedPointer<QAbstractAxisPrivate> d_ptr;
134 QScopedPointer<QAbstractAxisPrivate> d_ptr;
134 Q_DISABLE_COPY(QAbstractAxis);
135 Q_DISABLE_COPY(QAbstractAxis);
135 friend class ChartDataSet;
136 friend class ChartDataSet;
136 friend class ChartAxis;
137 friend class ChartAxis;
137 friend class ChartPresenter;
138 friend class ChartPresenter;
138 };
139 };
139
140
140 QTCOMMERCIALCHART_END_NAMESPACE
141 QTCOMMERCIALCHART_END_NAMESPACE
141 #endif
142 #endif
@@ -1,27 +1,28
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 TEMPLATE = subdirs
5 TEMPLATE = subdirs
6 SUBDIRS += \
6 SUBDIRS += \
7 qchartview \
7 qchartview \
8 qchart \
8 qchart \
9 qlineseries \
9 qlineseries \
10 qbarset \
10 qbarset \
11 qbarseries \
11 qbarseries \
12 qstackedbarseries \
12 qstackedbarseries \
13 qpercentbarseries \
13 qpercentbarseries \
14 qpieslice qpieseries \
14 qpieslice qpieseries \
15 qpiemodelmapper \
15 qpiemodelmapper \
16 qsplineseries \
16 qsplineseries \
17 qscatterseries \
17 qscatterseries \
18 qxymodelmapper \
18 qxymodelmapper \
19 qbarmodelmapper \
19 qbarmodelmapper \
20 qhorizontalbarseries \
20 qhorizontalbarseries \
21 qhorizontalstackedbarseries \
21 qhorizontalstackedbarseries \
22 qhorizontalpercentbarseries \
22 qhorizontalpercentbarseries \
23 qvaluesaxis
23 qvaluesaxis \
24 qintervalsaxis
24
25
25 test_private:{
26 test_private:{
26 SUBDIRS += domain chartdataset
27 SUBDIRS += domain chartdataset
27 }
28 }
1 NO CONTENT: modified file
NO CONTENT: modified file
General Comments 0
You need to be logged in to leave comments. Login now