@@ -1,91 +1,94 | |||||
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 <QStackedBarSeries> |
|
24 | #include <QStackedBarSeries> | |
25 | #include <QBarSet> |
|
25 | #include <QBarSet> | |
26 | #include <QLegend> |
|
26 | #include <QLegend> | |
27 | #include <QCategoriesAxis> |
|
27 | #include <QCategoriesAxis> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
29 | QTCOMMERCIALCHART_USE_NAMESPACE | |
30 |
|
30 | |||
31 | int main(int argc, char *argv[]) |
|
31 | int main(int argc, char *argv[]) | |
32 | { |
|
32 | { | |
33 | QApplication a(argc, argv); |
|
33 | QApplication a(argc, argv); | |
34 |
|
34 | |||
35 | //![1] |
|
35 | //![1] | |
36 | QBarSet *set0 = new QBarSet("Jane"); |
|
36 | QBarSet *set0 = new QBarSet("Jane"); | |
37 | QBarSet *set1 = new QBarSet("John"); |
|
37 | QBarSet *set1 = new QBarSet("John"); | |
38 | QBarSet *set2 = new QBarSet("Axel"); |
|
38 | QBarSet *set2 = new QBarSet("Axel"); | |
39 | QBarSet *set3 = new QBarSet("Mary"); |
|
39 | QBarSet *set3 = new QBarSet("Mary"); | |
40 | QBarSet *set4 = new QBarSet("Samantha"); |
|
40 | QBarSet *set4 = new QBarSet("Samantha"); | |
41 |
|
41 | |||
42 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
42 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
43 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
43 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
44 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
44 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
45 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
45 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
46 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
46 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
47 | //![1] |
|
47 | //![1] | |
48 |
|
48 | |||
49 | //![2] |
|
49 | //![2] | |
50 | QStackedBarSeries* series = new QStackedBarSeries(); |
|
50 | QStackedBarSeries* series = new QStackedBarSeries(); | |
51 | series->append(set0); |
|
51 | series->append(set0); | |
52 | series->append(set1); |
|
52 | series->append(set1); | |
53 | series->append(set2); |
|
53 | series->append(set2); | |
54 | series->append(set3); |
|
54 | series->append(set3); | |
55 | series->append(set4); |
|
55 | series->append(set4); | |
56 | //![2] |
|
56 | //![2] | |
57 |
|
57 | |||
58 | //![3] |
|
58 | //![3] | |
59 | QChart* chart = new QChart(); |
|
59 | QChart* chart = new QChart(); | |
60 | chart->addSeries(series); |
|
60 | chart->addSeries(series); | |
61 | chart->setTitle("Simple stackedbarchart example"); |
|
61 | chart->setTitle("Simple stackedbarchart example"); | |
62 | //![3] |
|
62 | //![3] | |
63 |
|
63 | |||
64 | //![4] |
|
64 | //![4] | |
65 | QStringList categories; |
|
65 | QStringList categories; | |
66 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
66 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
67 | QCategoriesAxis* axis = new QCategoriesAxis(); |
|
67 | QCategoriesAxis* axis = new QCategoriesAxis(); | |
68 | axis->append(categories); |
|
68 | axis->append(categories); | |
69 | chart->setAxisX(series,axis); |
|
69 | chart->setAxisX(series,axis); | |
|
70 | // axis->setMinCategory(QString("Feb")); | |||
|
71 | // axis->setMaxCategory(QString("May")); | |||
|
72 | // axis->setRange(QString("Feb"), QString("Apr")); | |||
70 | //![4] |
|
73 | //![4] | |
71 |
|
74 | |||
72 | //![5] |
|
75 | //![5] | |
73 | chart->legend()->setVisible(true); |
|
76 | chart->legend()->setVisible(true); | |
74 | chart->legend()->setAlignment(Qt::AlignBottom); |
|
77 | chart->legend()->setAlignment(Qt::AlignBottom); | |
75 | //![5] |
|
78 | //![5] | |
76 |
|
79 | |||
77 | //![6] |
|
80 | //![6] | |
78 | QChartView* chartView = new QChartView(chart); |
|
81 | QChartView* chartView = new QChartView(chart); | |
79 | chartView->setRenderHint(QPainter::Antialiasing); |
|
82 | chartView->setRenderHint(QPainter::Antialiasing); | |
80 | //![6] |
|
83 | //![6] | |
81 |
|
84 | |||
82 | //![7] |
|
85 | //![7] | |
83 | QMainWindow window; |
|
86 | QMainWindow window; | |
84 | window.setCentralWidget(chartView); |
|
87 | window.setCentralWidget(chartView); | |
85 | window.resize(400, 300); |
|
88 | window.resize(400, 300); | |
86 | window.show(); |
|
89 | window.show(); | |
87 | //![7] |
|
90 | //![7] | |
88 |
|
91 | |||
89 | return a.exec(); |
|
92 | return a.exec(); | |
90 | } |
|
93 | } | |
91 |
|
94 |
@@ -1,280 +1,293 | |||||
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 "qcategoriesaxis.h" |
|
21 | #include "qcategoriesaxis.h" | |
22 | #include "qcategoriesaxis_p.h" |
|
22 | #include "qcategoriesaxis_p.h" | |
23 | #include "chartcategoriesaxisx_p.h" |
|
23 | #include "chartcategoriesaxisx_p.h" | |
24 | #include "chartcategoriesaxisy_p.h" |
|
24 | #include "chartcategoriesaxisy_p.h" | |
|
25 | #include <qmath.h> | |||
25 |
|
26 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
28 | |||
28 | QCategoriesAxis::QCategoriesAxis(QObject *parent): |
|
29 | QCategoriesAxis::QCategoriesAxis(QObject *parent): | |
29 | QAbstractAxis(*new QCategoriesAxisPrivate(this),parent) |
|
30 | QAbstractAxis(*new QCategoriesAxisPrivate(this),parent) | |
30 | { |
|
31 | { | |
31 | } |
|
32 | } | |
32 |
|
33 | |||
33 | QCategoriesAxis::~QCategoriesAxis() |
|
34 | QCategoriesAxis::~QCategoriesAxis() | |
34 | { |
|
35 | { | |
35 | } |
|
36 | } | |
36 |
|
37 | |||
37 | QCategoriesAxis::QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent) |
|
38 | QCategoriesAxis::QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent) | |
38 | { |
|
39 | { | |
39 |
|
40 | |||
40 | } |
|
41 | } | |
41 |
|
42 | |||
42 | /*! |
|
43 | /*! | |
43 | Appends \a categories to axis |
|
44 | Appends \a categories to axis | |
44 | */ |
|
45 | */ | |
45 | void QCategoriesAxis::append(const QStringList &categories) |
|
46 | void QCategoriesAxis::append(const QStringList &categories) | |
46 | { |
|
47 | { | |
47 | Q_D(QCategoriesAxis); |
|
48 | Q_D(QCategoriesAxis); | |
48 | d->m_categories.append(categories); |
|
49 | d->m_categories.append(categories); | |
49 | emit categoriesChanged(); |
|
50 | emit categoriesChanged(); | |
50 | } |
|
51 | } | |
51 |
|
52 | |||
52 | /*! |
|
53 | /*! | |
53 | Appends \a category to axis |
|
54 | Appends \a category to axis | |
54 | */ |
|
55 | */ | |
55 | void QCategoriesAxis::append(const QString &category) |
|
56 | void QCategoriesAxis::append(const QString &category) | |
56 | { |
|
57 | { | |
57 | Q_D(QCategoriesAxis); |
|
58 | Q_D(QCategoriesAxis); | |
58 | d->m_categories.append(category); |
|
59 | d->m_categories.append(category); | |
59 | emit categoriesChanged(); |
|
60 | emit categoriesChanged(); | |
60 | } |
|
61 | } | |
61 |
|
62 | |||
62 | /*! |
|
63 | /*! | |
63 | Removes \a category from axis |
|
64 | Removes \a category from axis | |
64 | */ |
|
65 | */ | |
65 | void QCategoriesAxis::remove(const QString &category) |
|
66 | void QCategoriesAxis::remove(const QString &category) | |
66 | { |
|
67 | { | |
67 | Q_D(QCategoriesAxis); |
|
68 | Q_D(QCategoriesAxis); | |
68 | if (d->m_categories.contains(category)) { |
|
69 | if (d->m_categories.contains(category)) { | |
69 | d->m_categories.removeAt(d->m_categories.indexOf(category)); |
|
70 | d->m_categories.removeAt(d->m_categories.indexOf(category)); | |
70 | emit categoriesChanged(); |
|
71 | emit categoriesChanged(); | |
71 | } |
|
72 | } | |
72 | } |
|
73 | } | |
73 |
|
74 | |||
74 | /*! |
|
75 | /*! | |
75 | Inserts \a category to axis at \a index |
|
76 | Inserts \a category to axis at \a index | |
76 | */ |
|
77 | */ | |
77 | void QCategoriesAxis::insert(int index, const QString &category) |
|
78 | void QCategoriesAxis::insert(int index, const QString &category) | |
78 | { |
|
79 | { | |
79 | Q_D(QCategoriesAxis); |
|
80 | Q_D(QCategoriesAxis); | |
80 | d->m_categories.insert(index,category); |
|
81 | d->m_categories.insert(index,category); | |
81 | emit categoriesChanged(); |
|
82 | emit categoriesChanged(); | |
82 | } |
|
83 | } | |
83 |
|
84 | |||
84 | /*! |
|
85 | /*! | |
85 | Removes all categories. |
|
86 | Removes all categories. | |
86 | */ |
|
87 | */ | |
87 | void QCategoriesAxis::clear() |
|
88 | void QCategoriesAxis::clear() | |
88 | { |
|
89 | { | |
89 | Q_D(QCategoriesAxis); |
|
90 | Q_D(QCategoriesAxis); | |
90 | d->m_categories.clear(); |
|
91 | d->m_categories.clear(); | |
91 | emit categoriesChanged(); |
|
92 | emit categoriesChanged(); | |
92 | } |
|
93 | } | |
93 |
|
94 | |||
94 | void QCategoriesAxis::setCategories(const QStringList &categories) |
|
95 | void QCategoriesAxis::setCategories(const QStringList &categories) | |
95 | { |
|
96 | { | |
96 | Q_D(QCategoriesAxis); |
|
97 | Q_D(QCategoriesAxis); | |
97 | d->m_categories = categories; |
|
98 | d->m_categories = categories; | |
98 | emit categoriesChanged(); |
|
99 | emit categoriesChanged(); | |
99 | } |
|
100 | } | |
100 |
|
101 | |||
101 | QStringList QCategoriesAxis::categories() |
|
102 | QStringList QCategoriesAxis::categories() | |
102 | { |
|
103 | { | |
103 | Q_D(QCategoriesAxis); |
|
104 | Q_D(QCategoriesAxis); | |
104 | return d->m_categories; |
|
105 | return d->m_categories; | |
105 | } |
|
106 | } | |
106 |
|
107 | |||
107 | /*! |
|
108 | /*! | |
108 | Returns number of categories. |
|
109 | Returns number of categories. | |
109 | */ |
|
110 | */ | |
110 | int QCategoriesAxis::count() const |
|
111 | int QCategoriesAxis::count() const | |
111 | { |
|
112 | { | |
112 | Q_D(const QCategoriesAxis); |
|
113 | Q_D(const QCategoriesAxis); | |
113 | return d->m_categories.count(); |
|
114 | return d->m_categories.count(); | |
114 | } |
|
115 | } | |
115 |
|
116 | |||
116 | /*! |
|
117 | /*! | |
117 | Returns category at \a index. Index must be valid. |
|
118 | Returns category at \a index. Index must be valid. | |
118 | */ |
|
119 | */ | |
119 | QString QCategoriesAxis::at(int index) const |
|
120 | QString QCategoriesAxis::at(int index) const | |
120 | { |
|
121 | { | |
121 | Q_D(const QCategoriesAxis); |
|
122 | Q_D(const QCategoriesAxis); | |
122 | return d->m_categories.at(index); |
|
123 | return d->m_categories.at(index); | |
123 | } |
|
124 | } | |
124 |
|
125 | |||
125 | /*! |
|
126 | /*! | |
126 | Sets minimum category to \a minCategory. |
|
127 | Sets minimum category to \a minCategory. | |
127 | */ |
|
128 | */ | |
128 | void QCategoriesAxis::setMinCategory(const QString& minCategory) |
|
129 | void QCategoriesAxis::setMinCategory(const QString& minCategory) | |
129 | { |
|
130 | { | |
130 | Q_D(QCategoriesAxis); |
|
131 | Q_D(QCategoriesAxis); | |
131 | d->setMinCategory(minCategory); |
|
132 | d->setMinCategory(minCategory); | |
132 | } |
|
133 | } | |
133 |
|
134 | |||
134 | /*! |
|
135 | /*! | |
135 | Returns minimum category. |
|
136 | Returns minimum category. | |
136 | */ |
|
137 | */ | |
137 | QString QCategoriesAxis::minCategory() const |
|
138 | QString QCategoriesAxis::minCategory() const | |
138 | { |
|
139 | { | |
139 | Q_D(const QCategoriesAxis); |
|
140 | Q_D(const QCategoriesAxis); | |
140 | return d->m_minCategory; |
|
141 | return d->m_minCategory; | |
141 | } |
|
142 | } | |
142 |
|
143 | |||
143 | /*! |
|
144 | /*! | |
144 | Sets maximum category to \a maxCategory. |
|
145 | Sets maximum category to \a maxCategory. | |
145 | */ |
|
146 | */ | |
146 | void QCategoriesAxis::setMaxCategory(const QString& maxCategory) |
|
147 | void QCategoriesAxis::setMaxCategory(const QString& maxCategory) | |
147 | { |
|
148 | { | |
148 | Q_D(QCategoriesAxis); |
|
149 | Q_D(QCategoriesAxis); | |
149 | d->setMaxCategory(maxCategory); |
|
150 | d->setMaxCategory(maxCategory); | |
150 | } |
|
151 | } | |
151 |
|
152 | |||
152 | /*! |
|
153 | /*! | |
153 | Returns maximum category |
|
154 | Returns maximum category | |
154 | */ |
|
155 | */ | |
155 | QString QCategoriesAxis::maxCategory() const |
|
156 | QString QCategoriesAxis::maxCategory() const | |
156 | { |
|
157 | { | |
157 | Q_D(const QCategoriesAxis); |
|
158 | Q_D(const QCategoriesAxis); | |
158 | return d->m_maxCategory; |
|
159 | return d->m_maxCategory; | |
159 | } |
|
160 | } | |
160 |
|
161 | |||
161 | /*! |
|
162 | /*! | |
162 | Sets range from \a minCategory to \a maxCategory |
|
163 | Sets range from \a minCategory to \a maxCategory | |
163 | */ |
|
164 | */ | |
164 | void QCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory) |
|
165 | void QCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory) | |
165 | { |
|
166 | { | |
166 | Q_D(QCategoriesAxis); |
|
167 | Q_D(QCategoriesAxis); | |
167 | d->setRangeCategory(minCategory,maxCategory); |
|
168 | d->setRangeCategory(minCategory,maxCategory); | |
168 | } |
|
169 | } | |
169 |
|
170 | |||
170 | /*! |
|
171 | /*! | |
171 | Returns the type of axis. |
|
172 | Returns the type of axis. | |
172 | */ |
|
173 | */ | |
173 | QAbstractAxis::AxisType QCategoriesAxis::type() const |
|
174 | QAbstractAxis::AxisType QCategoriesAxis::type() const | |
174 | { |
|
175 | { | |
175 | return AxisTypeCategories; |
|
176 | return AxisTypeCategories; | |
176 | } |
|
177 | } | |
177 |
|
178 | |||
178 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
179 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
179 |
|
180 | |||
180 | QCategoriesAxisPrivate::QCategoriesAxisPrivate(QCategoriesAxis* q): |
|
181 | QCategoriesAxisPrivate::QCategoriesAxisPrivate(QCategoriesAxis* q): | |
181 | QAbstractAxisPrivate(q) |
|
182 | QAbstractAxisPrivate(q) | |
182 | { |
|
183 | { | |
183 |
|
184 | |||
184 | } |
|
185 | } | |
185 |
|
186 | |||
186 | QCategoriesAxisPrivate::~QCategoriesAxisPrivate() |
|
187 | QCategoriesAxisPrivate::~QCategoriesAxisPrivate() | |
187 | { |
|
188 | { | |
188 |
|
189 | |||
189 | } |
|
190 | } | |
190 |
|
191 | |||
191 | void QCategoriesAxisPrivate::setMinCategory(const QString& minCategory) |
|
192 | void QCategoriesAxisPrivate::setMinCategory(const QString& minCategory) | |
192 | { |
|
193 | { | |
193 | // Convert the category to value |
|
194 | // Convert the category to value | |
194 | int minIndex = m_categories.indexOf(minCategory); |
|
195 | int minIndex = m_categories.indexOf(minCategory); | |
195 | if (minIndex == -1) { |
|
196 | if (minIndex == -1) { | |
196 | return; |
|
197 | return; | |
197 | } |
|
198 | } | |
198 | setRange(minIndex,m_max); |
|
199 | ||
|
200 | int maxIndex = m_max; | |||
|
201 | if (minIndex > maxIndex) { | |||
|
202 | maxIndex = m_categories.count()-1; | |||
|
203 | } | |||
|
204 | setRange(minIndex - 0.5, maxIndex + 0.5); | |||
199 | } |
|
205 | } | |
200 |
|
206 | |||
201 | void QCategoriesAxisPrivate::setMaxCategory(const QString& maxCategory) |
|
207 | void QCategoriesAxisPrivate::setMaxCategory(const QString& maxCategory) | |
202 | { |
|
208 | { | |
203 | // Convert the category to value |
|
209 | // Convert the category to value | |
204 | int maxIndex = m_categories.indexOf(maxCategory); |
|
210 | int maxIndex = m_categories.indexOf(maxCategory); | |
205 | if (maxIndex == -1) { |
|
211 | if (maxIndex == -1) { | |
206 | return; |
|
212 | return; | |
207 | } |
|
213 | } | |
208 | setRange(m_min,maxIndex); |
|
214 | if (maxIndex < m_min) { | |
|
215 | m_min = 0; | |||
|
216 | } | |||
|
217 | setRange(m_min - 0.5, maxIndex + 0.5); | |||
209 | } |
|
218 | } | |
210 |
|
219 | |||
211 | void QCategoriesAxisPrivate::setRangeCategory(const QString& minCategory, const QString& maxCategory) |
|
220 | void QCategoriesAxisPrivate::setRangeCategory(const QString& minCategory, const QString& maxCategory) | |
212 | { |
|
221 | { | |
213 | // TODO: |
|
222 | // TODO: | |
214 | int minIndex = m_categories.indexOf(minCategory); |
|
223 | int minIndex = m_categories.indexOf(minCategory); | |
215 | if (minIndex == -1) { |
|
224 | if (minIndex == -1) { | |
216 | return; |
|
225 | return; | |
217 | } |
|
226 | } | |
218 | int maxIndex = m_categories.indexOf(maxCategory); |
|
227 | int maxIndex = m_categories.indexOf(maxCategory); | |
219 | if (maxIndex == -1) { |
|
228 | if (maxIndex == -1) { | |
220 | return; |
|
229 | return; | |
221 | } |
|
230 | } | |
222 | setRange(minIndex,maxIndex); |
|
231 | setRange(minIndex -0.5, maxIndex + 0.5); | |
223 | } |
|
232 | } | |
224 |
|
233 | |||
225 | void QCategoriesAxisPrivate::setMin(const qreal min) |
|
234 | void QCategoriesAxisPrivate::setMin(const qreal min) | |
226 | { |
|
235 | { | |
227 | setRange(min,m_max); |
|
236 | setRange(min,m_max); | |
228 | } |
|
237 | } | |
229 |
|
238 | |||
230 | void QCategoriesAxisPrivate::setMax(const qreal max) |
|
239 | void QCategoriesAxisPrivate::setMax(const qreal max) | |
231 | { |
|
240 | { | |
232 | setRange(m_min,max); |
|
241 | setRange(m_min,max); | |
233 | } |
|
242 | } | |
234 |
|
243 | |||
235 | void QCategoriesAxisPrivate::setRange(const qreal min, const qreal max) |
|
244 | void QCategoriesAxisPrivate::setRange(const qreal min, const qreal max) | |
236 | { |
|
245 | { | |
|
246 | if (max <= min) { | |||
|
247 | // max must be greater than min | |||
|
248 | return; | |||
|
249 | } | |||
237 | Q_Q(QCategoriesAxis); |
|
250 | Q_Q(QCategoriesAxis); | |
238 | bool changed = false; |
|
251 | bool changed = false; | |
239 | if (!qFuzzyIsNull(m_min - min)) { |
|
252 | if (!qFuzzyIsNull(m_min - min)) { | |
240 | m_min = min; |
|
253 | m_min = min; | |
241 | changed = true; |
|
254 | changed = true; | |
242 | } |
|
255 | } | |
243 |
|
256 | |||
244 | if (!qFuzzyIsNull(m_max - max)) { |
|
257 | if (!qFuzzyIsNull(m_max - max)) { | |
245 | m_max = max; |
|
258 | m_max = max; | |
246 | changed = true; |
|
259 | changed = true; | |
247 | } |
|
260 | } | |
248 |
|
261 | |||
249 | if (changed) { |
|
262 | if (changed) { | |
250 |
emit this->changed(m_min, m_max, |
|
263 | emit this->changed(m_min, m_max, qCeil(m_max) -qCeil(m_min) +1, false); | |
251 | emit q->categoriesChanged(); |
|
264 | emit q->categoriesChanged(); | |
252 | } |
|
265 | } | |
253 | } |
|
266 | } | |
254 |
|
267 | |||
255 | int QCategoriesAxisPrivate::ticksCount() const |
|
268 | int QCategoriesAxisPrivate::ticksCount() const | |
256 | { |
|
269 | { | |
257 | return m_categories.count()+1; |
|
270 | return m_categories.count()+1; | |
258 | } |
|
271 | } | |
259 |
|
272 | |||
260 | void QCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) |
|
273 | void QCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) | |
261 | { |
|
274 | { | |
262 | m_min = min; |
|
275 | m_min = min; | |
263 | m_max = max; |
|
276 | m_max = max; | |
264 | m_ticksCount = count; |
|
277 | m_ticksCount = count; | |
265 | } |
|
278 | } | |
266 |
|
279 | |||
267 | ChartAxis* QCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
280 | ChartAxis* QCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter) | |
268 | { |
|
281 | { | |
269 | Q_Q( QCategoriesAxis); |
|
282 | Q_Q( QCategoriesAxis); | |
270 | if(m_orientation == Qt::Vertical){ |
|
283 | if(m_orientation == Qt::Vertical){ | |
271 | return new ChartCategoriesAxisY(q,presenter); |
|
284 | return new ChartCategoriesAxisY(q,presenter); | |
272 | }else{ |
|
285 | }else{ | |
273 | return new ChartCategoriesAxisX(q,presenter); |
|
286 | return new ChartCategoriesAxisX(q,presenter); | |
274 | } |
|
287 | } | |
275 | } |
|
288 | } | |
276 |
|
289 | |||
277 | #include "moc_qcategoriesaxis.cpp" |
|
290 | #include "moc_qcategoriesaxis.cpp" | |
278 | #include "moc_qcategoriesaxis_p.cpp" |
|
291 | #include "moc_qcategoriesaxis_p.cpp" | |
279 |
|
292 | |||
280 | QTCOMMERCIALCHART_END_NAMESPACE |
|
293 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,315 +1,316 | |||||
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 "chartdataset_p.h" |
|
21 | #include "chartdataset_p.h" | |
22 | #include "qchart.h" |
|
22 | #include "qchart.h" | |
23 | #include "qvaluesaxis.h" |
|
23 | #include "qvaluesaxis.h" | |
24 | #include "qvaluesaxis_p.h" |
|
24 | #include "qvaluesaxis_p.h" | |
25 | #include "qabstractseries_p.h" |
|
25 | #include "qabstractseries_p.h" | |
26 | #include "qbarseries.h" |
|
26 | #include "qbarseries.h" | |
27 | #include "qstackedbarseries.h" |
|
27 | #include "qstackedbarseries.h" | |
28 | #include "qpercentbarseries.h" |
|
28 | #include "qpercentbarseries.h" | |
29 | #include "qpieseries.h" |
|
29 | #include "qpieseries.h" | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | ChartDataSet::ChartDataSet(QChart *parent):QObject(parent), |
|
33 | ChartDataSet::ChartDataSet(QChart *parent):QObject(parent), | |
34 | m_domainIndex(0) |
|
34 | m_domainIndex(0) | |
35 | { |
|
35 | { | |
36 |
|
36 | |||
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | ChartDataSet::~ChartDataSet() |
|
39 | ChartDataSet::~ChartDataSet() | |
40 | { |
|
40 | { | |
41 | removeAllSeries(); |
|
41 | removeAllSeries(); | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | void ChartDataSet::addSeries(QAbstractSeries* series) |
|
44 | void ChartDataSet::addSeries(QAbstractSeries* series) | |
45 | { |
|
45 | { | |
46 | QAbstractAxis* axis = m_seriesAxisXMap.value(series); |
|
46 | QAbstractAxis* axis = m_seriesAxisXMap.value(series); | |
47 |
|
47 | |||
48 | if(axis) { |
|
48 | if(axis) { | |
49 | qWarning() << "Can not add series. Series already on the chart"; |
|
49 | qWarning() << "Can not add series. Series already on the chart"; | |
50 | return; |
|
50 | return; | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | QAbstractAxis* axisX = series->d_ptr->createAxisX(this); |
|
53 | QAbstractAxis* axisX = series->d_ptr->createAxisX(this); | |
54 | QAbstractAxis* axisY = series->d_ptr->createAxisY(this); |
|
54 | QAbstractAxis* axisY = series->d_ptr->createAxisY(this); | |
55 |
|
55 | |||
56 | series->setParent(this); // take ownership |
|
56 | series->setParent(this); // take ownership | |
57 |
|
57 | |||
58 | Domain* domain = new Domain(series); |
|
58 | Domain* domain = new Domain(series); | |
59 |
|
59 | |||
60 | if(axisX){ |
|
60 | if(axisX){ | |
61 | QObject::connect(axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); |
|
61 | QObject::connect(axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); | |
62 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
62 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
63 | axisX->d_ptr->m_orientation=Qt::Horizontal; |
|
63 | axisX->d_ptr->m_orientation=Qt::Horizontal; | |
64 | emit axisAdded(axisX,domain); |
|
64 | emit axisAdded(axisX,domain); | |
65 | m_seriesAxisXMap.insert(series,axisX); |
|
65 | m_seriesAxisXMap.insert(series,axisX); | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | if(axisY){ |
|
68 | if(axisY){ | |
69 | QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); |
|
69 | QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); | |
70 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
70 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
71 | axisY->d_ptr->m_orientation=Qt::Vertical; |
|
71 | axisY->d_ptr->m_orientation=Qt::Vertical; | |
72 | emit axisAdded(axisY,domain); |
|
72 | emit axisAdded(axisY,domain); | |
73 | m_seriesAxisYMap.insert(series,axisY); |
|
73 | m_seriesAxisYMap.insert(series,axisY); | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | m_seriesDomainMap.insert(series,domain); |
|
76 | m_seriesDomainMap.insert(series,domain); | |
77 |
|
77 | |||
78 | series->d_ptr->scaleDomain(*domain); |
|
78 | series->d_ptr->scaleDomain(*domain); | |
79 |
|
79 | |||
80 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
80 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
81 |
|
81 | |||
82 | int key=0; |
|
82 | int key=0; | |
83 | while (i.hasNext()) { |
|
83 | while (i.hasNext()) { | |
84 | i.next(); |
|
84 | i.next(); | |
85 | if(i.key()!=key) { |
|
85 | if(i.key()!=key) { | |
86 | break; |
|
86 | break; | |
87 | } |
|
87 | } | |
88 | key++; |
|
88 | key++; | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | m_indexSeriesMap.insert(key,series); |
|
91 | m_indexSeriesMap.insert(key,series); | |
92 |
|
92 | |||
93 | series->d_ptr->m_chart = qobject_cast<QChart*>(parent()); |
|
93 | series->d_ptr->m_chart = qobject_cast<QChart*>(parent()); | |
94 | series->d_ptr->m_dataset = this; |
|
94 | series->d_ptr->m_dataset = this; | |
95 |
|
95 | |||
96 | emit seriesAdded(series,domain); |
|
96 | emit seriesAdded(series,domain); | |
97 |
|
97 | |||
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | void ChartDataSet::removeSeries(QAbstractSeries* series) |
|
100 | void ChartDataSet::removeSeries(QAbstractSeries* series) | |
101 | { |
|
101 | { | |
102 | Domain* domain = m_seriesDomainMap.take(series); |
|
102 | Domain* domain = m_seriesDomainMap.take(series); | |
103 |
|
103 | |||
104 | if(!domain) { |
|
104 | if(!domain) { | |
105 | qWarning()<<"Can not remove series. Series not found on the chart."; |
|
105 | qWarning()<<"Can not remove series. Series not found on the chart."; | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | emit seriesRemoved(series); |
|
108 | emit seriesRemoved(series); | |
109 |
|
109 | |||
110 | delete domain; |
|
110 | delete domain; | |
111 | domain = 0; |
|
111 | domain = 0; | |
112 |
|
112 | |||
113 | int key = seriesIndex(series); |
|
113 | int key = seriesIndex(series); | |
114 | Q_ASSERT(key!=-1); |
|
114 | Q_ASSERT(key!=-1); | |
115 |
|
115 | |||
116 | m_indexSeriesMap.remove(key); |
|
116 | m_indexSeriesMap.remove(key); | |
117 |
|
117 | |||
118 | series->setParent(0); |
|
118 | series->setParent(0); | |
119 | series->d_ptr->m_chart = 0; |
|
119 | series->d_ptr->m_chart = 0; | |
120 | series->d_ptr->m_dataset = 0; |
|
120 | series->d_ptr->m_dataset = 0; | |
121 |
|
121 | |||
122 | QAbstractAxis* axisX = m_seriesAxisXMap.take(series); |
|
122 | QAbstractAxis* axisX = m_seriesAxisXMap.take(series); | |
123 |
|
123 | |||
124 | if(axisX) { |
|
124 | if(axisX) { | |
125 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); |
|
125 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); | |
126 | int x = axesX.indexOf(axisX); |
|
126 | int x = axesX.indexOf(axisX); | |
127 |
|
127 | |||
128 | if(x==-1) { |
|
128 | if(x==-1) { | |
129 | emit axisRemoved(axisX); |
|
129 | emit axisRemoved(axisX); | |
130 | axisX->deleteLater(); |
|
130 | axisX->deleteLater(); | |
131 | } |
|
131 | } | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | QAbstractAxis* axisY = m_seriesAxisYMap.take(series); |
|
134 | QAbstractAxis* axisY = m_seriesAxisYMap.take(series); | |
135 |
|
135 | |||
136 | if(axisY) { |
|
136 | if(axisY) { | |
137 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); |
|
137 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); | |
138 |
|
138 | |||
139 | int y = axesY.indexOf(axisY); |
|
139 | int y = axesY.indexOf(axisY); | |
140 |
|
140 | |||
141 | if(y==-1) { |
|
141 | if(y==-1) { | |
142 | emit axisRemoved(axisY); |
|
142 | emit axisRemoved(axisY); | |
143 | axisY->deleteLater(); |
|
143 | axisY->deleteLater(); | |
144 | } |
|
144 | } | |
145 | } |
|
145 | } | |
146 | } |
|
146 | } | |
147 |
|
147 | |||
148 | void ChartDataSet::removeAllSeries() |
|
148 | void ChartDataSet::removeAllSeries() | |
149 | { |
|
149 | { | |
150 | QList<QAbstractSeries*> series = m_seriesDomainMap.keys(); |
|
150 | QList<QAbstractSeries*> series = m_seriesDomainMap.keys(); | |
151 | foreach(QAbstractSeries *s , series) { |
|
151 | foreach(QAbstractSeries *s , series) { | |
152 | removeSeries(s); |
|
152 | removeSeries(s); | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | Q_ASSERT(m_seriesAxisXMap.count()==0); |
|
155 | Q_ASSERT(m_seriesAxisXMap.count()==0); | |
156 | Q_ASSERT(m_seriesAxisXMap.count()==0); |
|
156 | Q_ASSERT(m_seriesAxisXMap.count()==0); | |
157 | Q_ASSERT(m_seriesDomainMap.count()==0); |
|
157 | Q_ASSERT(m_seriesDomainMap.count()==0); | |
158 |
|
158 | |||
159 | qDeleteAll(series); |
|
159 | qDeleteAll(series); | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) |
|
162 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) | |
163 | { |
|
163 | { | |
164 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
164 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
165 | while (i.hasNext()) { |
|
165 | while (i.hasNext()) { | |
166 | i.next(); |
|
166 | i.next(); | |
167 | i.value()->zoomIn(rect,size); |
|
167 | i.value()->zoomIn(rect,size); | |
168 | } |
|
168 | } | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) |
|
171 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) | |
172 | { |
|
172 | { | |
173 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
173 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
174 | while (i.hasNext()) { |
|
174 | while (i.hasNext()) { | |
175 | i.next(); |
|
175 | i.next(); | |
176 | i.value()->zoomOut(rect,size); |
|
176 | i.value()->zoomOut(rect,size); | |
177 | } |
|
177 | } | |
178 | } |
|
178 | } | |
179 |
|
179 | |||
180 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) |
|
180 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) | |
181 | { |
|
181 | { | |
182 | int count=0; |
|
182 | int count=0; | |
183 | QMapIterator<QAbstractSeries*, QAbstractAxis*> i(m_seriesAxisXMap); |
|
183 | QMapIterator<QAbstractSeries*, QAbstractAxis*> i(m_seriesAxisXMap); | |
184 | while (i.hasNext()) { |
|
184 | while (i.hasNext()) { | |
185 | i.next(); |
|
185 | i.next(); | |
186 | if(i.key()->type()==type) count++; |
|
186 | if(i.key()->type()==type) count++; | |
187 | } |
|
187 | } | |
188 | return count; |
|
188 | return count; | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 | int ChartDataSet::seriesIndex(QAbstractSeries *series) |
|
191 | int ChartDataSet::seriesIndex(QAbstractSeries *series) | |
192 | { |
|
192 | { | |
193 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
193 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
194 | while (i.hasNext()) { |
|
194 | while (i.hasNext()) { | |
195 | i.next(); |
|
195 | i.next(); | |
196 | if (i.value() == series) |
|
196 | if (i.value() == series) | |
197 | return i.key(); |
|
197 | return i.key(); | |
198 | } |
|
198 | } | |
199 | return -1; |
|
199 | return -1; | |
200 | } |
|
200 | } | |
201 |
|
201 | |||
202 | QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const |
|
202 | QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const | |
203 | { |
|
203 | { | |
204 | if(series == 0) return m_seriesAxisXMap.begin().value(); |
|
204 | if(series == 0) return m_seriesAxisXMap.begin().value(); | |
205 | return m_seriesAxisXMap.value(series); |
|
205 | return m_seriesAxisXMap.value(series); | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const |
|
208 | QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const | |
209 | { |
|
209 | { | |
210 | if(series == 0) return m_seriesAxisYMap.begin().value(); |
|
210 | if(series == 0) return m_seriesAxisYMap.begin().value(); | |
211 | return m_seriesAxisYMap.value(series); |
|
211 | return m_seriesAxisYMap.value(series); | |
212 | } |
|
212 | } | |
213 |
|
213 | |||
214 | void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis) |
|
214 | void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis) | |
215 | { |
|
215 | { | |
216 |
|
216 | |||
217 | Q_ASSERT(axis); |
|
217 | Q_ASSERT(axis); | |
218 | QAbstractAxis *oldAxis = m_seriesAxisXMap.take(series); |
|
218 | QAbstractAxis *oldAxis = m_seriesAxisXMap.take(series); | |
219 |
|
219 | |||
220 | if(!oldAxis) { |
|
220 | if(!oldAxis) { | |
221 | qWarning()<<"Series not found on the chart."; |
|
221 | qWarning()<<"Series not found on the chart."; | |
222 | return; |
|
222 | return; | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
225 | if(axis->d_ptr->m_orientation==Qt::Vertical) { |
|
225 | if(axis->d_ptr->m_orientation==Qt::Vertical) { | |
226 | qWarning()<<"Axis already defined as axis Y"; |
|
226 | qWarning()<<"Axis already defined as axis Y"; | |
227 | return; |
|
227 | return; | |
228 | } |
|
228 | } | |
229 |
|
229 | |||
230 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); |
|
230 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); | |
231 | int x = axesX.indexOf(oldAxis); |
|
231 | int x = axesX.indexOf(oldAxis); | |
232 | if(x==-1) { |
|
232 | if(x==-1) { | |
233 | emit axisRemoved(oldAxis); |
|
233 | emit axisRemoved(oldAxis); | |
234 | oldAxis->deleteLater(); |
|
234 | oldAxis->deleteLater(); | |
235 | } |
|
235 | } | |
236 |
|
236 | |||
|
237 | // TODO: should we take domain from axis (if it has min and max already defined) | |||
237 | Domain* domain = m_seriesDomainMap.value(series); |
|
238 | Domain* domain = m_seriesDomainMap.value(series); | |
238 | Q_ASSERT(domain); |
|
239 | Q_ASSERT(domain); | |
239 |
|
240 | |||
240 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); |
|
241 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); | |
241 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
242 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
242 |
|
243 | |||
243 | x = axesX.indexOf(axis); |
|
244 | x = axesX.indexOf(axis); | |
244 | if(x==-1) { |
|
245 | if(x==-1) { | |
245 | axis->d_ptr->m_orientation=Qt::Horizontal; |
|
246 | axis->d_ptr->m_orientation=Qt::Horizontal; | |
246 | emit axisAdded(axis,domain); |
|
247 | emit axisAdded(axis,domain); | |
247 | } |
|
248 | } | |
248 |
|
249 | |||
249 | m_seriesAxisXMap.insert(series,axis); |
|
250 | m_seriesAxisXMap.insert(series,axis); | |
250 | } |
|
251 | } | |
251 |
|
252 | |||
252 | void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis) |
|
253 | void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis) | |
253 | { |
|
254 | { | |
254 | Q_ASSERT(axis); |
|
255 | Q_ASSERT(axis); | |
255 | QAbstractAxis *oldAxis = m_seriesAxisYMap.take(series); |
|
256 | QAbstractAxis *oldAxis = m_seriesAxisYMap.take(series); | |
256 |
|
257 | |||
257 | if(!oldAxis) { |
|
258 | if(!oldAxis) { | |
258 | qWarning()<<"Series not found on the chart or axis is unsupported for given series type"; |
|
259 | qWarning()<<"Series not found on the chart or axis is unsupported for given series type"; | |
259 | return; |
|
260 | return; | |
260 | } |
|
261 | } | |
261 |
|
262 | |||
262 | if(axis->d_ptr->m_orientation==Qt::Horizontal) { |
|
263 | if(axis->d_ptr->m_orientation==Qt::Horizontal) { | |
263 | qWarning()<<"Axis already defined as axis X"; |
|
264 | qWarning()<<"Axis already defined as axis X"; | |
264 | return; |
|
265 | return; | |
265 | } |
|
266 | } | |
266 |
|
267 | |||
267 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); |
|
268 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); | |
268 | int y = axesY.indexOf(oldAxis); |
|
269 | int y = axesY.indexOf(oldAxis); | |
269 | if(y==-1) { |
|
270 | if(y==-1) { | |
270 | emit axisRemoved(oldAxis); |
|
271 | emit axisRemoved(oldAxis); | |
271 | oldAxis->deleteLater(); |
|
272 | oldAxis->deleteLater(); | |
272 | } |
|
273 | } | |
273 |
|
274 | |||
274 | Domain* domain = m_seriesDomainMap.value(series); |
|
275 | Domain* domain = m_seriesDomainMap.value(series); | |
275 | Q_ASSERT(domain); |
|
276 | Q_ASSERT(domain); | |
276 |
|
277 | |||
277 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); |
|
278 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); | |
278 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
279 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
279 |
|
280 | |||
280 | y = axesY.indexOf(axis); |
|
281 | y = axesY.indexOf(axis); | |
281 | if(y==-1) { |
|
282 | if(y==-1) { | |
282 | axis->d_ptr->m_orientation=Qt::Vertical; |
|
283 | axis->d_ptr->m_orientation=Qt::Vertical; | |
283 | emit axisAdded(axis,domain); |
|
284 | emit axisAdded(axis,domain); | |
284 | } |
|
285 | } | |
285 |
|
286 | |||
286 | m_seriesAxisYMap.insert(series,axis); |
|
287 | m_seriesAxisYMap.insert(series,axis); | |
287 | } |
|
288 | } | |
288 |
|
289 | |||
289 | Domain* ChartDataSet::domain(QAbstractSeries *series) const |
|
290 | Domain* ChartDataSet::domain(QAbstractSeries *series) const | |
290 | { |
|
291 | { | |
291 | return m_seriesDomainMap.value(series); |
|
292 | return m_seriesDomainMap.value(series); | |
292 | } |
|
293 | } | |
293 |
|
294 | |||
294 | void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) |
|
295 | void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) | |
295 | { |
|
296 | { | |
296 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
297 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
297 | while (i.hasNext()) { |
|
298 | while (i.hasNext()) { | |
298 | i.next(); |
|
299 | i.next(); | |
299 | i.value()->move(dx,dy,size); |
|
300 | i.value()->move(dx,dy,size); | |
300 | } |
|
301 | } | |
301 | } |
|
302 | } | |
302 |
|
303 | |||
303 | QList<QAbstractSeries*> ChartDataSet::series() const |
|
304 | QList<QAbstractSeries*> ChartDataSet::series() const | |
304 | { |
|
305 | { | |
305 | return m_seriesAxisXMap.keys(); |
|
306 | return m_seriesAxisXMap.keys(); | |
306 | } |
|
307 | } | |
307 |
|
308 | |||
308 | void ChartDataSet::updateSeries(QAbstractSeries *series) |
|
309 | void ChartDataSet::updateSeries(QAbstractSeries *series) | |
309 | { |
|
310 | { | |
310 | emit seriesUpdated(series); |
|
311 | emit seriesUpdated(series); | |
311 | } |
|
312 | } | |
312 |
|
313 | |||
313 | #include "moc_chartdataset_p.cpp" |
|
314 | #include "moc_chartdataset_p.cpp" | |
314 |
|
315 | |||
315 | QTCOMMERCIALCHART_END_NAMESPACE |
|
316 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now