@@ -1,488 +1,487 | |||||
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 "qbarseries.h" |
|
21 | #include "qbarseries.h" | |
22 | #include "qbarseries_p.h" |
|
22 | #include "qbarseries_p.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include "legendmarker_p.h" |
|
26 | #include "legendmarker_p.h" | |
27 | #include "chartdataset_p.h" |
|
27 | #include "chartdataset_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 | #include "chartanimator_p.h" |
|
29 | #include "chartanimator_p.h" | |
30 |
|
30 | |||
31 | #include <QAbstractItemModel> |
|
31 | #include <QAbstractItemModel> | |
32 | #include <QModelIndex> |
|
32 | #include <QModelIndex> | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \class QBarSeries |
|
37 | \class QBarSeries | |
38 | \brief part of QtCommercial chart API. |
|
38 | \brief part of QtCommercial chart API. | |
39 | \mainclass |
|
39 | \mainclass | |
40 |
|
40 | |||
41 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multiple |
|
41 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multiple | |
42 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined |
|
42 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined | |
43 | by QStringList. |
|
43 | by QStringList. | |
44 |
|
44 | |||
45 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
45 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. | |
46 | \image examples_barchart.png |
|
46 | \image examples_barchart.png | |
47 |
|
47 | |||
48 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
48 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
49 | */ |
|
49 | */ | |
50 |
|
50 | |||
51 | /*! |
|
51 | /*! | |
52 | \fn void QBarSeries::clicked(QBarSet *barset, QString category) |
|
52 | \fn void QBarSeries::clicked(QBarSet *barset, QString category) | |
53 |
|
53 | |||
54 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset of category \a category |
|
54 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset of category \a category | |
55 | contained by the series. |
|
55 | contained by the series. | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) |
|
59 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) | |
60 |
|
60 | |||
61 | The signal is emitted if mouse is hovered on top of series. |
|
61 | The signal is emitted if mouse is hovered on top of series. | |
62 | Parameter \a barset is the pointer of barset, where hover happened. |
|
62 | Parameter \a barset is the pointer of barset, where hover happened. | |
63 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
63 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
64 | */ |
|
64 | */ | |
65 |
|
65 | |||
66 | /*! |
|
66 | /*! | |
67 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. |
|
67 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. | |
68 | QBarSeries is QObject which is a child of a \a parent. |
|
68 | QBarSeries is QObject which is a child of a \a parent. | |
69 | */ |
|
69 | */ | |
70 | QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : |
|
70 | QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : | |
71 | QAbstractSeries(*new QBarSeriesPrivate(categories, this),parent) |
|
71 | QAbstractSeries(*new QBarSeriesPrivate(categories, this),parent) | |
72 | { |
|
72 | { | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | /*! |
|
75 | /*! | |
76 | Destructs barseries and owned barsets. |
|
76 | Destructs barseries and owned barsets. | |
77 | */ |
|
77 | */ | |
78 | QBarSeries::~QBarSeries() |
|
78 | QBarSeries::~QBarSeries() | |
79 | { |
|
79 | { | |
80 | // NOTE: d_ptr destroyed by QObject |
|
80 | // NOTE: d_ptr destroyed by QObject | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | \internal |
|
84 | \internal | |
85 | */ |
|
85 | */ | |
86 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : |
|
86 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : | |
87 | QAbstractSeries(d,parent) |
|
87 | QAbstractSeries(d,parent) | |
88 | { |
|
88 | { | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | /*! |
|
91 | /*! | |
92 | Returns the type of series. Derived classes override this. |
|
92 | Returns the type of series. Derived classes override this. | |
93 | */ |
|
93 | */ | |
94 | QAbstractSeries::QSeriesType QBarSeries::type() const |
|
94 | QAbstractSeries::QSeriesType QBarSeries::type() const | |
95 | { |
|
95 | { | |
96 | return QAbstractSeries::SeriesTypeBar; |
|
96 | return QAbstractSeries::SeriesTypeBar; | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | /*! |
|
99 | /*! | |
100 | Adds a set of bars to series. Takes ownership of \a set. |
|
100 | Adds a set of bars to series. Takes ownership of \a set. | |
101 | */ |
|
101 | */ | |
102 | void QBarSeries::appendBarSet(QBarSet *set) |
|
102 | void QBarSeries::appendBarSet(QBarSet *set) | |
103 | { |
|
103 | { | |
104 | Q_D(QBarSeries); |
|
104 | Q_D(QBarSeries); | |
105 | d->m_barSets.append(set); |
|
105 | d->m_barSets.append(set); | |
106 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
106 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); | |
107 | emit d->restructuredBars(); |
|
107 | emit d->restructuredBars(); | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 | /*! |
|
110 | /*! | |
111 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
111 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. | |
112 | */ |
|
112 | */ | |
113 | void QBarSeries::removeBarSet(QBarSet *set) |
|
113 | void QBarSeries::removeBarSet(QBarSet *set) | |
114 | { |
|
114 | { | |
115 | Q_D(QBarSeries); |
|
115 | Q_D(QBarSeries); | |
116 | if (d->m_barSets.contains(set)) { |
|
116 | if (d->m_barSets.contains(set)) { | |
117 | d->m_barSets.removeOne(set); |
|
117 | d->m_barSets.removeOne(set); | |
118 | QObject::disconnect(set, SIGNAL(updatedBars()), this, SLOT(barsetChanged())); |
|
118 | QObject::disconnect(set, SIGNAL(updatedBars()), this, SLOT(barsetChanged())); | |
119 | emit d->restructuredBars(); |
|
119 | emit d->restructuredBars(); | |
120 | } |
|
120 | } | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | /*! |
|
123 | /*! | |
124 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
124 | Adds a list of barsets to series. Takes ownership of \a sets. | |
125 | */ |
|
125 | */ | |
126 | void QBarSeries::appendBarSets(QList<QBarSet* > sets) |
|
126 | void QBarSeries::appendBarSets(QList<QBarSet* > sets) | |
127 | { |
|
127 | { | |
128 | Q_D(QBarSeries); |
|
128 | Q_D(QBarSeries); | |
129 | foreach (QBarSet* set, sets) { |
|
129 | foreach (QBarSet* set, sets) { | |
130 | d->m_barSets.append(set); |
|
130 | d->m_barSets.append(set); | |
131 | QObject::connect(set, SIGNAL(updatedBars()), this, SLOT(barsetChanged())); |
|
131 | QObject::connect(set, SIGNAL(updatedBars()), this, SLOT(barsetChanged())); | |
132 | } |
|
132 | } | |
133 | emit d->restructuredBars(); |
|
133 | emit d->restructuredBars(); | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | /*! |
|
136 | /*! | |
137 | Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets. |
|
137 | Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets. | |
138 | */ |
|
138 | */ | |
139 | void QBarSeries::removeBarSets(QList<QBarSet* > sets) |
|
139 | void QBarSeries::removeBarSets(QList<QBarSet* > sets) | |
140 | { |
|
140 | { | |
141 | Q_D(QBarSeries); |
|
141 | Q_D(QBarSeries); | |
142 |
|
142 | |||
143 | foreach (QBarSet* set, sets) { |
|
143 | foreach (QBarSet* set, sets) { | |
144 | if (d->m_barSets.contains(set)) { |
|
144 | if (d->m_barSets.contains(set)) { | |
145 | d->m_barSets.removeOne(set); |
|
145 | d->m_barSets.removeOne(set); | |
146 | QObject::disconnect(set, SIGNAL(updatedBars()), this, SLOT(barsetChanged())); |
|
146 | QObject::disconnect(set, SIGNAL(updatedBars()), this, SLOT(barsetChanged())); | |
147 | } |
|
147 | } | |
148 | } |
|
148 | } | |
149 | emit d->restructuredBars(); |
|
149 | emit d->restructuredBars(); | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | /*! |
|
152 | /*! | |
153 | Returns number of sets in series. |
|
153 | Returns number of sets in series. | |
154 | */ |
|
154 | */ | |
155 | int QBarSeries::barsetCount() const |
|
155 | int QBarSeries::barsetCount() const | |
156 | { |
|
156 | { | |
157 | Q_D(const QBarSeries); |
|
157 | Q_D(const QBarSeries); | |
158 | return d->m_barSets.count(); |
|
158 | return d->m_barSets.count(); | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | Returns number of categories in series |
|
162 | Returns number of categories in series | |
163 | */ |
|
163 | */ | |
164 | int QBarSeries::categoryCount() const |
|
164 | int QBarSeries::categoryCount() const | |
165 | { |
|
165 | { | |
166 | Q_D(const QBarSeries); |
|
166 | Q_D(const QBarSeries); | |
167 | return d->m_categories.count(); |
|
167 | return d->m_categories.count(); | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | /*! |
|
170 | /*! | |
171 | Returns a list of sets in series. Keeps ownership of sets. |
|
171 | Returns a list of sets in series. Keeps ownership of sets. | |
172 | */ |
|
172 | */ | |
173 | QList<QBarSet*> QBarSeries::barSets() const |
|
173 | QList<QBarSet*> QBarSeries::barSets() const | |
174 | { |
|
174 | { | |
175 | Q_D(const QBarSeries); |
|
175 | Q_D(const QBarSeries); | |
176 | return d->m_barSets; |
|
176 | return d->m_barSets; | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | /*! |
|
179 | /*! | |
180 | \fn bool QBarSeries::setModel(QAbstractItemModel *model) |
|
180 | \fn bool QBarSeries::setModel(QAbstractItemModel *model) | |
181 | Sets the \a model to be used as a data source |
|
181 | Sets the \a model to be used as a data source | |
182 | */ |
|
182 | */ | |
183 | bool QBarSeries::setModel(QAbstractItemModel *model) |
|
183 | bool QBarSeries::setModel(QAbstractItemModel *model) | |
184 | { |
|
184 | { | |
185 | Q_D(QBarSeries); |
|
185 | Q_D(QBarSeries); | |
186 | return d->setModel(model); |
|
186 | return d->setModel(model); | |
187 | } |
|
187 | } | |
188 |
|
188 | |||
189 | /*! |
|
189 | /*! | |
190 | \fn bool QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) |
|
190 | \fn bool QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) | |
191 | Sets column/row specified by \a categories to be used as a list of bar series categories. |
|
191 | Sets column/row specified by \a categories to be used as a list of bar series categories. | |
192 | Parameter \a bottomBoundry indicates the column/row where the first bar set is located in the model. |
|
192 | Parameter \a bottomBoundry indicates the column/row where the first bar set is located in the model. | |
193 | Parameter \a topBoundry indicates the column/row where the last bar set is located in the model. |
|
193 | Parameter \a topBoundry indicates the column/row where the last bar set is located in the model. | |
194 | All the columns/rows inbetween those two values are also used as data for bar sets. |
|
194 | All the columns/rows inbetween those two values are also used as data for bar sets. | |
195 | The \a orientation parameter specifies whether the data is in columns or in rows. |
|
195 | The \a orientation parameter specifies whether the data is in columns or in rows. | |
196 | */ |
|
196 | */ | |
197 | void QBarSeries::setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation) |
|
197 | void QBarSeries::setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation) | |
198 | { |
|
198 | { | |
199 | Q_D(QBarSeries); |
|
199 | Q_D(QBarSeries); | |
200 | d->setModelMapping(categories,bottomBoundary,topBoundary,orientation); |
|
200 | d->setModelMapping(categories,bottomBoundary,topBoundary,orientation); | |
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | /*! |
|
203 | /*! | |
204 | Returns the bar categories of the series. |
|
204 | Returns the bar categories of the series. | |
205 | */ |
|
205 | */ | |
206 | QBarCategories QBarSeries::categories() const |
|
206 | QBarCategories QBarSeries::categories() const | |
207 | { |
|
207 | { | |
208 | Q_D(const QBarSeries); |
|
208 | Q_D(const QBarSeries); | |
209 | return d->m_categories; |
|
209 | return d->m_categories; | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | /*! |
|
212 | /*! | |
213 | Sets the visibility of labels in series to \a visible |
|
213 | Sets the visibility of labels in series to \a visible | |
214 | */ |
|
214 | */ | |
215 | void QBarSeries::setLabelsVisible(bool visible) |
|
215 | void QBarSeries::setLabelsVisible(bool visible) | |
216 | { |
|
216 | { | |
217 | foreach (QBarSet* s, barSets()) { |
|
217 | foreach (QBarSet* s, barSets()) { | |
218 | s->setLabelsVisible(visible); |
|
218 | s->setLabelsVisible(visible); | |
219 | } |
|
219 | } | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
222 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
223 |
|
223 | |||
224 | QBarSeriesPrivate::QBarSeriesPrivate(QBarCategories categories, QBarSeries *q) : |
|
224 | QBarSeriesPrivate::QBarSeriesPrivate(QBarCategories categories, QBarSeries *q) : | |
225 | QAbstractSeriesPrivate(q), |
|
225 | QAbstractSeriesPrivate(q), | |
226 | m_categories(categories), |
|
226 | m_categories(categories), | |
227 | m_model(0), |
|
|||
228 | m_mapCategories(-1), |
|
227 | m_mapCategories(-1), | |
229 | m_mapBarBottom(-1), |
|
228 | m_mapBarBottom(-1), | |
230 | m_mapBarTop(-1), |
|
229 | m_mapBarTop(-1), | |
231 | m_mapOrientation(Qt::Vertical) |
|
230 | m_mapOrientation(Qt::Vertical) | |
232 | { |
|
231 | { | |
233 | } |
|
232 | } | |
234 |
|
233 | |||
235 | QBarSet* QBarSeriesPrivate::barsetAt(int index) |
|
234 | QBarSet* QBarSeriesPrivate::barsetAt(int index) | |
236 | { |
|
235 | { | |
237 | return m_barSets.at(index); |
|
236 | return m_barSets.at(index); | |
238 | } |
|
237 | } | |
239 |
|
238 | |||
240 | QString QBarSeriesPrivate::categoryName(int category) |
|
239 | QString QBarSeriesPrivate::categoryName(int category) | |
241 | { |
|
240 | { | |
242 | return m_categories.at(category); |
|
241 | return m_categories.at(category); | |
243 | } |
|
242 | } | |
244 |
|
243 | |||
245 | qreal QBarSeriesPrivate::min() |
|
244 | qreal QBarSeriesPrivate::min() | |
246 | { |
|
245 | { | |
247 | if (m_barSets.count() <= 0) { |
|
246 | if (m_barSets.count() <= 0) { | |
248 | return 0; |
|
247 | return 0; | |
249 | } |
|
248 | } | |
250 | qreal min = INT_MAX; |
|
249 | qreal min = INT_MAX; | |
251 |
|
250 | |||
252 | for (int i = 0; i < m_barSets.count(); i++) { |
|
251 | for (int i = 0; i < m_barSets.count(); i++) { | |
253 | int categoryCount = m_barSets.at(i)->count(); |
|
252 | int categoryCount = m_barSets.at(i)->count(); | |
254 | for (int j = 0; j < categoryCount; j++) { |
|
253 | for (int j = 0; j < categoryCount; j++) { | |
255 | qreal temp = m_barSets.at(i)->at(j); |
|
254 | qreal temp = m_barSets.at(i)->at(j); | |
256 | if (temp < min) |
|
255 | if (temp < min) | |
257 | min = temp; |
|
256 | min = temp; | |
258 | } |
|
257 | } | |
259 | } |
|
258 | } | |
260 | return min; |
|
259 | return min; | |
261 | } |
|
260 | } | |
262 |
|
261 | |||
263 | qreal QBarSeriesPrivate::max() |
|
262 | qreal QBarSeriesPrivate::max() | |
264 | { |
|
263 | { | |
265 | if (m_barSets.count() <= 0) { |
|
264 | if (m_barSets.count() <= 0) { | |
266 | return 0; |
|
265 | return 0; | |
267 | } |
|
266 | } | |
268 | qreal max = INT_MIN; |
|
267 | qreal max = INT_MIN; | |
269 |
|
268 | |||
270 | for (int i = 0; i < m_barSets.count(); i++) { |
|
269 | for (int i = 0; i < m_barSets.count(); i++) { | |
271 | int categoryCount = m_barSets.at(i)->count(); |
|
270 | int categoryCount = m_barSets.at(i)->count(); | |
272 | for (int j = 0; j < categoryCount; j++) { |
|
271 | for (int j = 0; j < categoryCount; j++) { | |
273 | qreal temp = m_barSets.at(i)->at(j); |
|
272 | qreal temp = m_barSets.at(i)->at(j); | |
274 | if (temp > max) |
|
273 | if (temp > max) | |
275 | max = temp; |
|
274 | max = temp; | |
276 | } |
|
275 | } | |
277 | } |
|
276 | } | |
278 |
|
277 | |||
279 | return max; |
|
278 | return max; | |
280 | } |
|
279 | } | |
281 |
|
280 | |||
282 | qreal QBarSeriesPrivate::valueAt(int set, int category) |
|
281 | qreal QBarSeriesPrivate::valueAt(int set, int category) | |
283 | { |
|
282 | { | |
284 | if ((set < 0) || (set >= m_barSets.count())) { |
|
283 | if ((set < 0) || (set >= m_barSets.count())) { | |
285 | // No set, no value. |
|
284 | // No set, no value. | |
286 | return 0; |
|
285 | return 0; | |
287 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
286 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
288 | // No category, no value. |
|
287 | // No category, no value. | |
289 | return 0; |
|
288 | return 0; | |
290 | } |
|
289 | } | |
291 |
|
290 | |||
292 | return m_barSets.at(set)->at(category); |
|
291 | return m_barSets.at(set)->at(category); | |
293 | } |
|
292 | } | |
294 |
|
293 | |||
295 | qreal QBarSeriesPrivate::percentageAt(int set, int category) |
|
294 | qreal QBarSeriesPrivate::percentageAt(int set, int category) | |
296 | { |
|
295 | { | |
297 | if ((set < 0) || (set >= m_barSets.count())) { |
|
296 | if ((set < 0) || (set >= m_barSets.count())) { | |
298 | // No set, no value. |
|
297 | // No set, no value. | |
299 | return 0; |
|
298 | return 0; | |
300 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
299 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
301 | // No category, no value. |
|
300 | // No category, no value. | |
302 | return 0; |
|
301 | return 0; | |
303 | } |
|
302 | } | |
304 |
|
303 | |||
305 | qreal value = m_barSets.at(set)->at(category); |
|
304 | qreal value = m_barSets.at(set)->at(category); | |
306 | qreal sum = categorySum(category); |
|
305 | qreal sum = categorySum(category); | |
307 | if ( qFuzzyIsNull(sum) ) { |
|
306 | if ( qFuzzyIsNull(sum) ) { | |
308 | return 0; |
|
307 | return 0; | |
309 | } |
|
308 | } | |
310 |
|
309 | |||
311 | return value / sum; |
|
310 | return value / sum; | |
312 | } |
|
311 | } | |
313 |
|
312 | |||
314 | qreal QBarSeriesPrivate::categorySum(int category) |
|
313 | qreal QBarSeriesPrivate::categorySum(int category) | |
315 | { |
|
314 | { | |
316 | qreal sum(0); |
|
315 | qreal sum(0); | |
317 | int count = m_barSets.count(); // Count sets |
|
316 | int count = m_barSets.count(); // Count sets | |
318 | for (int set = 0; set < count; set++) { |
|
317 | for (int set = 0; set < count; set++) { | |
319 | if (category < m_barSets.at(set)->count()) |
|
318 | if (category < m_barSets.at(set)->count()) | |
320 | sum += m_barSets.at(set)->at(category); |
|
319 | sum += m_barSets.at(set)->at(category); | |
321 | } |
|
320 | } | |
322 | return sum; |
|
321 | return sum; | |
323 | } |
|
322 | } | |
324 |
|
323 | |||
325 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) |
|
324 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) | |
326 | { |
|
325 | { | |
327 | qreal sum(0); |
|
326 | qreal sum(0); | |
328 | int count = m_barSets.count(); // Count sets |
|
327 | int count = m_barSets.count(); // Count sets | |
329 | for (int set = 0; set < count; set++) { |
|
328 | for (int set = 0; set < count; set++) { | |
330 | if (category < m_barSets.at(set)->count()) |
|
329 | if (category < m_barSets.at(set)->count()) | |
331 | sum += qAbs(m_barSets.at(set)->at(category)); |
|
330 | sum += qAbs(m_barSets.at(set)->at(category)); | |
332 | } |
|
331 | } | |
333 | return sum; |
|
332 | return sum; | |
334 | } |
|
333 | } | |
335 |
|
334 | |||
336 | qreal QBarSeriesPrivate::maxCategorySum() |
|
335 | qreal QBarSeriesPrivate::maxCategorySum() | |
337 | { |
|
336 | { | |
338 | qreal max = INT_MIN; |
|
337 | qreal max = INT_MIN; | |
339 | int count = m_categories.count(); |
|
338 | int count = m_categories.count(); | |
340 | for (int i = 0; i < count; i++) { |
|
339 | for (int i = 0; i < count; i++) { | |
341 | qreal sum = categorySum(i); |
|
340 | qreal sum = categorySum(i); | |
342 | if (sum > max) |
|
341 | if (sum > max) | |
343 | max = sum; |
|
342 | max = sum; | |
344 | } |
|
343 | } | |
345 | return max; |
|
344 | return max; | |
346 | } |
|
345 | } | |
347 |
|
346 | |||
348 | bool QBarSeriesPrivate::setModel(QAbstractItemModel *model) |
|
347 | bool QBarSeriesPrivate::setModel(QAbstractItemModel *model) | |
349 | { |
|
348 | { | |
350 | // disconnect signals from old model |
|
349 | // disconnect signals from old model | |
351 | if(m_model) |
|
350 | if(m_model) | |
352 | { |
|
351 | { | |
353 | disconnect(m_model, 0, this, 0); |
|
352 | disconnect(m_model, 0, this, 0); | |
354 | m_mapCategories = -1; |
|
353 | m_mapCategories = -1; | |
355 | m_mapBarBottom = -1; |
|
354 | m_mapBarBottom = -1; | |
356 | m_mapBarTop = -1; |
|
355 | m_mapBarTop = -1; | |
357 | m_mapOrientation = Qt::Vertical; |
|
356 | m_mapOrientation = Qt::Vertical; | |
358 | } |
|
357 | } | |
359 |
|
358 | |||
360 | // set new model |
|
359 | // set new model | |
361 | if(model) |
|
360 | if(model) | |
362 | { |
|
361 | { | |
363 | m_model = model; |
|
362 | m_model = model; | |
364 | return true; |
|
363 | return true; | |
365 | } |
|
364 | } | |
366 | else |
|
365 | else | |
367 | { |
|
366 | { | |
368 | m_model = 0; |
|
367 | m_model = 0; | |
369 | return false; |
|
368 | return false; | |
370 | } |
|
369 | } | |
371 | } |
|
370 | } | |
372 |
|
371 | |||
373 | void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) |
|
372 | void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) | |
374 | { |
|
373 | { | |
375 | Q_Q(QBarSeries); |
|
374 | Q_Q(QBarSeries); | |
376 |
|
375 | |||
377 | if (m_model == 0) |
|
376 | if (m_model == 0) | |
378 | return; |
|
377 | return; | |
379 |
|
378 | |||
380 | m_mapCategories = categories; |
|
379 | m_mapCategories = categories; | |
381 | m_mapBarBottom = bottomBoundry; |
|
380 | m_mapBarBottom = bottomBoundry; | |
382 | m_mapBarTop = topBoundry; |
|
381 | m_mapBarTop = topBoundry; | |
383 | m_mapOrientation = orientation; |
|
382 | m_mapOrientation = orientation; | |
384 |
|
383 | |||
385 | // connect the signals |
|
384 | // connect the signals | |
386 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), |
|
385 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
387 | this, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
386 | this, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
388 |
|
387 | |||
389 | // create the initial bars |
|
388 | // create the initial bars | |
390 | m_categories.clear(); |
|
389 | m_categories.clear(); | |
391 | if (m_mapOrientation == Qt::Vertical) { |
|
390 | if (m_mapOrientation == Qt::Vertical) { | |
392 | for (int k = 0; k < m_model->rowCount(); k++) { |
|
391 | for (int k = 0; k < m_model->rowCount(); k++) { | |
393 | m_categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); |
|
392 | m_categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); | |
394 | } |
|
393 | } | |
395 |
|
394 | |||
396 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
395 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
397 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); |
|
396 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); | |
398 | for(int m = 0; m < m_model->rowCount(); m++) |
|
397 | for(int m = 0; m < m_model->rowCount(); m++) | |
399 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); |
|
398 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |
400 | q->appendBarSet(barSet); |
|
399 | q->appendBarSet(barSet); | |
401 | } |
|
400 | } | |
402 | } else { |
|
401 | } else { | |
403 | for (int k = 0; k < m_model->columnCount(); k++) { |
|
402 | for (int k = 0; k < m_model->columnCount(); k++) { | |
404 | m_categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); |
|
403 | m_categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); | |
405 | } |
|
404 | } | |
406 |
|
405 | |||
407 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
406 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
408 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); |
|
407 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Vertical, Qt::DisplayRole).toString()); | |
409 | for(int m = 0; m < m_model->columnCount(); m++) |
|
408 | for(int m = 0; m < m_model->columnCount(); m++) | |
410 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); |
|
409 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |
411 | q->appendBarSet(barSet); |
|
410 | q->appendBarSet(barSet); | |
412 | } |
|
411 | } | |
413 | } |
|
412 | } | |
414 | } |
|
413 | } | |
415 |
|
414 | |||
416 | void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
415 | void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
417 | { |
|
416 | { | |
418 | Q_UNUSED(bottomRight) |
|
417 | Q_UNUSED(bottomRight) | |
419 |
|
418 | |||
420 | if (m_mapOrientation == Qt::Vertical) |
|
419 | if (m_mapOrientation == Qt::Vertical) | |
421 | { |
|
420 | { | |
422 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
421 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
423 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop) |
|
422 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop) | |
424 | barsetAt(topLeft.column() - m_mapBarBottom)->replace(topLeft.row(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
423 | barsetAt(topLeft.column() - m_mapBarBottom)->replace(topLeft.row(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
425 | } |
|
424 | } | |
426 | else |
|
425 | else | |
427 | { |
|
426 | { | |
428 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
427 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
429 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop) |
|
428 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop) | |
430 | barsetAt(topLeft.row() - m_mapBarBottom)->replace(topLeft.column(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
429 | barsetAt(topLeft.row() - m_mapBarBottom)->replace(topLeft.column(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
431 | } |
|
430 | } | |
432 | } |
|
431 | } | |
433 |
|
432 | |||
434 | void QBarSeriesPrivate::barsetChanged() |
|
433 | void QBarSeriesPrivate::barsetChanged() | |
435 | { |
|
434 | { | |
436 | emit updatedBars(); |
|
435 | emit updatedBars(); | |
437 | } |
|
436 | } | |
438 |
|
437 | |||
439 | void QBarSeriesPrivate::scaleDomain(Domain& domain) |
|
438 | void QBarSeriesPrivate::scaleDomain(Domain& domain) | |
440 | { |
|
439 | { | |
441 | qreal minX(domain.minX()); |
|
440 | qreal minX(domain.minX()); | |
442 | qreal minY(domain.minY()); |
|
441 | qreal minY(domain.minY()); | |
443 | qreal maxX(domain.maxX()); |
|
442 | qreal maxX(domain.maxX()); | |
444 | qreal maxY(domain.maxY()); |
|
443 | qreal maxY(domain.maxY()); | |
445 | int tickXCount(domain.tickXCount()); |
|
444 | int tickXCount(domain.tickXCount()); | |
446 | int tickYCount(domain.tickYCount()); |
|
445 | int tickYCount(domain.tickYCount()); | |
447 |
|
446 | |||
448 | qreal x = m_categories.count(); |
|
447 | qreal x = m_categories.count(); | |
449 | qreal y = max(); |
|
448 | qreal y = max(); | |
450 | minX = qMin(minX, x); |
|
449 | minX = qMin(minX, x); | |
451 | minY = qMin(minY, y); |
|
450 | minY = qMin(minY, y); | |
452 | maxX = qMax(maxX, x); |
|
451 | maxX = qMax(maxX, x); | |
453 | maxY = qMax(maxY, y); |
|
452 | maxY = qMax(maxY, y); | |
454 | tickXCount = x+1; |
|
453 | tickXCount = x+1; | |
455 |
|
454 | |||
456 | domain.setRangeX(minX,maxX,tickXCount); |
|
455 | domain.setRangeX(minX,maxX,tickXCount); | |
457 | domain.setRangeY(minY,maxY,tickYCount); |
|
456 | domain.setRangeY(minY,maxY,tickYCount); | |
458 | } |
|
457 | } | |
459 |
|
458 | |||
460 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
459 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
461 | { |
|
460 | { | |
462 | Q_Q(QBarSeries); |
|
461 | Q_Q(QBarSeries); | |
463 |
|
462 | |||
464 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
463 | BarChartItem* bar = new BarChartItem(q,presenter); | |
465 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
464 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
466 | presenter->animator()->addAnimation(bar); |
|
465 | presenter->animator()->addAnimation(bar); | |
467 | } |
|
466 | } | |
468 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
467 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
469 | return bar; |
|
468 | return bar; | |
470 |
|
469 | |||
471 | } |
|
470 | } | |
472 |
|
471 | |||
473 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
472 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) | |
474 | { |
|
473 | { | |
475 | Q_Q(QBarSeries); |
|
474 | Q_Q(QBarSeries); | |
476 | QList<LegendMarker*> markers; |
|
475 | QList<LegendMarker*> markers; | |
477 | foreach(QBarSet* set, q->barSets()) { |
|
476 | foreach(QBarSet* set, q->barSets()) { | |
478 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
477 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); | |
479 | markers << marker; |
|
478 | markers << marker; | |
480 | } |
|
479 | } | |
481 |
|
480 | |||
482 | return markers; |
|
481 | return markers; | |
483 | } |
|
482 | } | |
484 |
|
483 | |||
485 | #include "moc_qbarseries.cpp" |
|
484 | #include "moc_qbarseries.cpp" | |
486 | #include "moc_qbarseries_p.cpp" |
|
485 | #include "moc_qbarseries_p.cpp" | |
487 |
|
486 | |||
488 | QTCOMMERCIALCHART_END_NAMESPACE |
|
487 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,62 +1,61 | |||||
1 | #ifndef QBARSERIES_P_H |
|
1 | #ifndef QBARSERIES_P_H | |
2 | #define QBARSERIES_P_H |
|
2 | #define QBARSERIES_P_H | |
3 |
|
3 | |||
4 | #include "qbarseries.h" |
|
4 | #include "qbarseries.h" | |
5 | #include "qabstractseries_p.h" |
|
5 | #include "qabstractseries_p.h" | |
6 | #include <QStringList> |
|
6 | #include <QStringList> | |
7 | #include <QAbstractSeries> |
|
7 | #include <QAbstractSeries> | |
8 |
|
8 | |||
9 | class QModelIndex; |
|
9 | class QModelIndex; | |
10 |
|
10 | |||
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
12 |
|
12 | |||
13 | // Container for series |
|
13 | // Container for series | |
14 | class QBarSeriesPrivate : public QAbstractSeriesPrivate |
|
14 | class QBarSeriesPrivate : public QAbstractSeriesPrivate | |
15 | { |
|
15 | { | |
16 | Q_OBJECT |
|
16 | Q_OBJECT | |
17 | public: |
|
17 | public: | |
18 | QBarSeriesPrivate(QBarCategories categories, QBarSeries *parent); |
|
18 | QBarSeriesPrivate(QBarCategories categories, QBarSeries *parent); | |
19 |
|
19 | |||
20 | void scaleDomain(Domain& domain); |
|
20 | void scaleDomain(Domain& domain); | |
21 | Chart* createGraphics(ChartPresenter* presenter); |
|
21 | Chart* createGraphics(ChartPresenter* presenter); | |
22 | QList<LegendMarker*> createLegendMarker(QLegend* legend); |
|
22 | QList<LegendMarker*> createLegendMarker(QLegend* legend); | |
23 |
|
23 | |||
24 | bool setModel(QAbstractItemModel *model); |
|
24 | bool setModel(QAbstractItemModel *model); | |
25 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); |
|
25 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); | |
26 |
|
26 | |||
27 | QBarSet* barsetAt(int index); |
|
27 | QBarSet* barsetAt(int index); | |
28 | QString categoryName(int category); |
|
28 | QString categoryName(int category); | |
29 | qreal min(); |
|
29 | qreal min(); | |
30 | qreal max(); |
|
30 | qreal max(); | |
31 | qreal valueAt(int set, int category); |
|
31 | qreal valueAt(int set, int category); | |
32 | qreal percentageAt(int set, int category); |
|
32 | qreal percentageAt(int set, int category); | |
33 | qreal categorySum(int category); |
|
33 | qreal categorySum(int category); | |
34 | qreal absoluteCategorySum(int category); |
|
34 | qreal absoluteCategorySum(int category); | |
35 | qreal maxCategorySum(); |
|
35 | qreal maxCategorySum(); | |
36 |
|
36 | |||
37 | Q_SIGNALS: |
|
37 | Q_SIGNALS: | |
38 | void clicked(QBarSet *barset, QString category); |
|
38 | void clicked(QBarSet *barset, QString category); | |
39 | void updatedBars(); |
|
39 | void updatedBars(); | |
40 | void restructuredBars(); |
|
40 | void restructuredBars(); | |
41 |
|
41 | |||
42 | private Q_SLOTS: |
|
42 | private Q_SLOTS: | |
43 | // slots for updating bars when data in model changes |
|
43 | // slots for updating bars when data in model changes | |
44 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
|
44 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
45 | void barsetChanged(); |
|
45 | void barsetChanged(); | |
46 |
|
46 | |||
47 | protected: |
|
47 | protected: | |
48 | QList<QBarSet *> m_barSets; |
|
48 | QList<QBarSet *> m_barSets; | |
49 | QBarCategories m_categories; |
|
49 | QBarCategories m_categories; | |
50 |
|
50 | |||
51 | QAbstractItemModel* m_model; |
|
|||
52 | int m_mapCategories; |
|
51 | int m_mapCategories; | |
53 | int m_mapBarBottom; |
|
52 | int m_mapBarBottom; | |
54 | int m_mapBarTop; |
|
53 | int m_mapBarTop; | |
55 | Qt::Orientation m_mapOrientation; |
|
54 | Qt::Orientation m_mapOrientation; | |
56 | private: |
|
55 | private: | |
57 | Q_DECLARE_PUBLIC(QBarSeries) |
|
56 | Q_DECLARE_PUBLIC(QBarSeries) | |
58 | }; |
|
57 | }; | |
59 |
|
58 | |||
60 | QTCOMMERCIALCHART_END_NAMESPACE |
|
59 | QTCOMMERCIALCHART_END_NAMESPACE | |
61 |
|
60 | |||
62 | #endif // QBARSERIESPRIVATE_P_H |
|
61 | #endif // QBARSERIESPRIVATE_P_H |
@@ -1,336 +1,341 | |||||
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 "tablewidget.h" |
|
21 | #include "tablewidget.h" | |
22 | #include <QGridLayout> |
|
22 | #include <QGridLayout> | |
23 | #include <QTableView> |
|
23 | #include <QTableView> | |
24 | #include <QStyledItemDelegate> |
|
24 | #include <QStyledItemDelegate> | |
25 | #include <QLineSeries> |
|
25 | #include <QLineSeries> | |
26 | #include <QSplineSeries> |
|
26 | #include <QSplineSeries> | |
27 | #include <QScatterSeries> |
|
27 | #include <QScatterSeries> | |
28 | #include "customtablemodel.h" |
|
28 | #include "customtablemodel.h" | |
29 | #include <QPieSeries> |
|
29 | #include <QPieSeries> | |
30 | #include <QPieSlice> |
|
30 | #include <QPieSlice> | |
31 | #include <QAreaSeries> |
|
31 | #include <QAreaSeries> | |
32 | #include <QBarSeries> |
|
32 | #include <QBarSeries> | |
33 | #include <QBarSet> |
|
33 | #include <QBarSet> | |
34 | #include <QPushButton> |
|
34 | #include <QPushButton> | |
35 | #include <QRadioButton> |
|
35 | #include <QRadioButton> | |
36 | #include <QLabel> |
|
36 | #include <QLabel> | |
37 | #include <QSpinBox> |
|
37 | #include <QSpinBox> | |
38 | #include <QTime> |
|
38 | #include <QTime> | |
39 |
|
39 | |||
40 | TableWidget::TableWidget(QWidget *parent) |
|
40 | TableWidget::TableWidget(QWidget *parent) | |
41 | : QWidget(parent) |
|
41 | : QWidget(parent) | |
42 | { |
|
42 | { | |
43 | setGeometry(100, 100, 1000, 600); |
|
43 | setGeometry(100, 100, 1000, 600); | |
44 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
44 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
45 | // create simple model for storing data |
|
45 | // create simple model for storing data | |
46 | // user's table data model |
|
46 | // user's table data model | |
47 | m_model = new CustomTableModel; |
|
47 | m_model = new CustomTableModel; | |
48 | m_tableView = new QTableView; |
|
48 | m_tableView = new QTableView; | |
49 | m_tableView->setModel(m_model); |
|
49 | m_tableView->setModel(m_model); | |
50 | m_tableView->setMinimumHeight(300); |
|
50 | m_tableView->setMinimumHeight(300); | |
51 | // tableView->setMinimumSize(340, 480); |
|
51 | // tableView->setMinimumSize(340, 480); | |
52 | // tableView->setItemDelegate(new QStyledItemDelegate); |
|
52 | // tableView->setItemDelegate(new QStyledItemDelegate); | |
53 | m_chart = new QChart; |
|
53 | m_chart = new QChart; | |
|
54 | m_chart->legend()->setVisible(true); | |||
54 | m_chartView = new QChartView(m_chart); |
|
55 | m_chartView = new QChartView(m_chart); | |
55 | m_chartView->setRenderHint(QPainter::Antialiasing); |
|
56 | m_chartView->setRenderHint(QPainter::Antialiasing); | |
56 | m_chartView->setMinimumSize(640, 480); |
|
57 | m_chartView->setMinimumSize(640, 480); | |
57 |
|
58 | |||
58 | // add, remove data buttons |
|
59 | // add, remove data buttons | |
59 | QPushButton* addRowAboveButton = new QPushButton("Add row above"); |
|
60 | QPushButton* addRowAboveButton = new QPushButton("Add row above"); | |
60 | connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove())); |
|
61 | connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove())); | |
61 |
|
62 | |||
62 | QPushButton* addRowBelowButton = new QPushButton("Add row below"); |
|
63 | QPushButton* addRowBelowButton = new QPushButton("Add row below"); | |
63 | connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow())); |
|
64 | connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow())); | |
64 |
|
65 | |||
65 | QPushButton* removeRowButton = new QPushButton("Remove row"); |
|
66 | QPushButton* removeRowButton = new QPushButton("Remove row"); | |
66 | connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow())); |
|
67 | connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow())); | |
67 |
|
68 | |||
68 | QLabel *spinBoxLabel = new QLabel("Rows affected:"); |
|
69 | QLabel *spinBoxLabel = new QLabel("Rows affected:"); | |
69 |
|
70 | |||
70 | // spin box for setting number of affected items (add, remove) |
|
71 | // spin box for setting number of affected items (add, remove) | |
71 | m_linesCountSpinBox = new QSpinBox; |
|
72 | m_linesCountSpinBox = new QSpinBox; | |
72 | m_linesCountSpinBox->setRange(1, 10); |
|
73 | m_linesCountSpinBox->setRange(1, 10); | |
73 | m_linesCountSpinBox->setValue(1); |
|
74 | m_linesCountSpinBox->setValue(1); | |
74 |
|
75 | |||
75 | // buttons layout |
|
76 | // buttons layout | |
76 | QVBoxLayout* buttonsLayout = new QVBoxLayout; |
|
77 | QVBoxLayout* buttonsLayout = new QVBoxLayout; | |
77 | buttonsLayout->addWidget(spinBoxLabel); |
|
78 | buttonsLayout->addWidget(spinBoxLabel); | |
78 | buttonsLayout->addWidget(m_linesCountSpinBox); |
|
79 | buttonsLayout->addWidget(m_linesCountSpinBox); | |
79 | buttonsLayout->addWidget(addRowAboveButton); |
|
80 | buttonsLayout->addWidget(addRowAboveButton); | |
80 | buttonsLayout->addWidget(addRowBelowButton); |
|
81 | buttonsLayout->addWidget(addRowBelowButton); | |
81 | buttonsLayout->addWidget(removeRowButton); |
|
82 | buttonsLayout->addWidget(removeRowButton); | |
82 | buttonsLayout->addStretch(); |
|
83 | buttonsLayout->addStretch(); | |
83 |
|
84 | |||
84 | // chart type radio buttons |
|
85 | // chart type radio buttons | |
85 | m_lineRadioButton = new QRadioButton("Line"); |
|
86 | m_lineRadioButton = new QRadioButton("Line"); | |
86 | m_splineRadioButton = new QRadioButton("Spline"); |
|
87 | m_splineRadioButton = new QRadioButton("Spline"); | |
87 | m_scatterRadioButton = new QRadioButton("Scatter"); |
|
88 | m_scatterRadioButton = new QRadioButton("Scatter"); | |
88 | m_pieRadioButton = new QRadioButton("Pie"); |
|
89 | m_pieRadioButton = new QRadioButton("Pie"); | |
89 | m_areaRadioButton = new QRadioButton("Area"); |
|
90 | m_areaRadioButton = new QRadioButton("Area"); | |
90 | m_barRadioButton = new QRadioButton("Bar"); |
|
91 | m_barRadioButton = new QRadioButton("Bar"); | |
91 |
|
92 | |||
92 | connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
93 | connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
93 | connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
94 | connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
94 | connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
95 | connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
95 | connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
96 | connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
96 | connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
97 | connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
97 | connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
98 | connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
98 | m_lineRadioButton->setChecked(true); |
|
99 | m_lineRadioButton->setChecked(true); | |
99 |
|
100 | |||
100 | // radio buttons layout |
|
101 | // radio buttons layout | |
101 | QVBoxLayout* radioLayout = new QVBoxLayout; |
|
102 | QVBoxLayout* radioLayout = new QVBoxLayout; | |
102 | radioLayout->addWidget(m_lineRadioButton); |
|
103 | radioLayout->addWidget(m_lineRadioButton); | |
103 | radioLayout->addWidget(m_splineRadioButton); |
|
104 | radioLayout->addWidget(m_splineRadioButton); | |
104 | radioLayout->addWidget(m_scatterRadioButton); |
|
105 | radioLayout->addWidget(m_scatterRadioButton); | |
105 | radioLayout->addWidget(m_pieRadioButton); |
|
106 | radioLayout->addWidget(m_pieRadioButton); | |
106 | radioLayout->addWidget(m_areaRadioButton); |
|
107 | radioLayout->addWidget(m_areaRadioButton); | |
107 | radioLayout->addWidget(m_barRadioButton); |
|
108 | radioLayout->addWidget(m_barRadioButton); | |
108 | radioLayout->addStretch(); |
|
109 | radioLayout->addStretch(); | |
109 |
|
110 | |||
110 | // create main layout |
|
111 | // create main layout | |
111 | QGridLayout* mainLayout = new QGridLayout; |
|
112 | QGridLayout* mainLayout = new QGridLayout; | |
112 | mainLayout->addLayout(buttonsLayout, 1, 1); |
|
113 | mainLayout->addLayout(buttonsLayout, 1, 1); | |
113 | mainLayout->addLayout(radioLayout, 2, 1); |
|
114 | mainLayout->addLayout(radioLayout, 2, 1); | |
114 | mainLayout->addWidget(m_tableView, 1, 0); |
|
115 | mainLayout->addWidget(m_tableView, 1, 0); | |
115 | mainLayout->addWidget(m_chartView, 2, 0); |
|
116 | mainLayout->addWidget(m_chartView, 2, 0); | |
116 | setLayout(mainLayout); |
|
117 | setLayout(mainLayout); | |
117 | m_lineRadioButton->setFocus(); |
|
118 | m_lineRadioButton->setFocus(); | |
118 | } |
|
119 | } | |
119 |
|
120 | |||
120 | void TableWidget::addRowAbove() |
|
121 | void TableWidget::addRowAbove() | |
121 | { |
|
122 | { | |
122 | m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value()); |
|
123 | m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value()); | |
123 |
|
124 | |||
124 | } |
|
125 | } | |
125 |
|
126 | |||
126 | void TableWidget::addRowBelow() |
|
127 | void TableWidget::addRowBelow() | |
127 | { |
|
128 | { | |
128 | m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value()); |
|
129 | m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value()); | |
129 |
|
130 | |||
130 | } |
|
131 | } | |
131 |
|
132 | |||
132 | void TableWidget::removeRow() |
|
133 | void TableWidget::removeRow() | |
133 | { |
|
134 | { | |
134 | m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value())); |
|
135 | m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value())); | |
135 | } |
|
136 | } | |
136 |
|
137 | |||
137 | void TableWidget::updateChartType(bool toggle) |
|
138 | void TableWidget::updateChartType(bool toggle) | |
138 | { |
|
139 | { | |
139 | // this if is needed, so that the function is only called once. |
|
140 | // this if is needed, so that the function is only called once. | |
140 | // For the radioButton that was enabled. |
|
141 | // For the radioButton that was enabled. | |
141 | if (toggle) { |
|
142 | if (toggle) { | |
142 | m_chart->removeAllSeries(); |
|
143 | m_chart->removeAllSeries(); | |
|
144 | m_chart->axisX()->setNiceNumbersEnabled(false); | |||
|
145 | m_chart->axisY()->setNiceNumbersEnabled(false); | |||
143 |
|
146 | |||
144 | // renable axes of the chart (pie hides them) |
|
147 | // renable axes of the chart (pie hides them) | |
145 | // x axis |
|
148 | // x axis | |
146 | QAxis *axis = m_chart->axisX(); |
|
149 | QAxis *axis = m_chart->axisX(); | |
147 | axis->setAxisVisible(true); |
|
150 | axis->setAxisVisible(true); | |
148 | axis->setGridLineVisible(true); |
|
151 | axis->setGridLineVisible(true); | |
149 | axis->setLabelsVisible(true); |
|
152 | axis->setLabelsVisible(true); | |
150 |
|
153 | |||
151 | // y axis |
|
154 | // y axis | |
152 | axis = m_chart->axisY(); |
|
155 | axis = m_chart->axisY(); | |
153 | axis->setAxisVisible(true); |
|
156 | axis->setAxisVisible(true); | |
154 | axis->setGridLineVisible(true); |
|
157 | axis->setGridLineVisible(true); | |
155 | axis->setLabelsVisible(true); |
|
158 | axis->setLabelsVisible(true); | |
156 |
|
159 | |||
157 | m_model->clearMapping(); |
|
160 | m_model->clearMapping(); | |
158 |
|
161 | |||
159 | QString seriesColorHex = "#000000"; |
|
162 | QString seriesColorHex = "#000000"; | |
160 | QPen pen; |
|
163 | QPen pen; | |
161 | pen.setWidth(2); |
|
164 | pen.setWidth(2); | |
162 |
|
165 | |||
163 | if (m_lineRadioButton->isChecked()) |
|
166 | if (m_lineRadioButton->isChecked()) | |
164 | { |
|
167 | { | |
165 | // series 1 |
|
168 | // series 1 | |
166 | m_series = new QLineSeries; |
|
169 | m_series = new QLineSeries; | |
167 | m_series->setModel(m_model); |
|
170 | m_series->setModel(m_model); | |
168 | m_series->setModelMapping(0,1, Qt::Vertical); |
|
171 | m_series->setModelMapping(0,1, Qt::Vertical); | |
169 | // m_series->setModelMappingRange(1, 4); |
|
172 | // m_series->setModelMappingRange(1, 4); | |
170 | m_chart->addSeries(m_series); |
|
173 | m_chart->addSeries(m_series); | |
171 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
174 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
172 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 4)); |
|
175 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 4)); | |
173 |
|
176 | |||
174 | // series 2 |
|
177 | // series 2 | |
175 | m_series = new QLineSeries; |
|
178 | m_series = new QLineSeries; | |
176 | m_series->setModel(m_model); |
|
179 | m_series->setModel(m_model); | |
177 | m_series->setModelMapping(2,3, Qt::Vertical); |
|
180 | m_series->setModelMapping(2,3, Qt::Vertical); | |
178 | m_chart->addSeries(m_series); |
|
181 | m_chart->addSeries(m_series); | |
179 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
182 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
180 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); |
|
183 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); | |
181 |
|
184 | |||
182 | // series 3 |
|
185 | // series 3 | |
183 | m_series = new QLineSeries; |
|
186 | m_series = new QLineSeries; | |
184 | m_series->setModel(m_model); |
|
187 | m_series->setModel(m_model); | |
185 | m_series->setModelMapping(4,5, Qt::Vertical); |
|
188 | m_series->setModelMapping(4,5, Qt::Vertical); | |
186 | // m_series->setModelMappingRange(2, 0); |
|
189 | // m_series->setModelMappingRange(2, 0); | |
187 | m_chart->addSeries(m_series); |
|
190 | m_chart->addSeries(m_series); | |
188 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
191 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
189 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); |
|
192 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); | |
190 | } |
|
193 | } | |
191 | else if (m_splineRadioButton->isChecked()) |
|
194 | else if (m_splineRadioButton->isChecked()) | |
192 | { |
|
195 | { | |
193 | // series 1 |
|
196 | // series 1 | |
194 | m_series = new QSplineSeries; |
|
197 | m_series = new QSplineSeries; | |
195 | m_series->setModel(m_model); |
|
198 | m_series->setModel(m_model); | |
196 | m_series->setModelMapping(0,1, Qt::Vertical); |
|
199 | m_series->setModelMapping(0,1, Qt::Vertical); | |
197 | // m_series->setModelMappingRange(1, 4); |
|
200 | // m_series->setModelMappingRange(1, 4); | |
198 | // series->setModelMapping(0,1, Qt::Horizontal); |
|
201 | // series->setModelMapping(0,1, Qt::Horizontal); | |
199 | m_chart->addSeries(m_series); |
|
202 | m_chart->addSeries(m_series); | |
200 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
203 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
201 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 4)); |
|
204 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 4)); | |
202 |
|
205 | |||
203 | // series 2 |
|
206 | // series 2 | |
204 | m_series = new QSplineSeries; |
|
207 | m_series = new QSplineSeries; | |
205 | m_series->setModel(m_model); |
|
208 | m_series->setModel(m_model); | |
206 | m_series->setModelMapping(2,3, Qt::Vertical); |
|
209 | m_series->setModelMapping(2,3, Qt::Vertical); | |
207 | // m_series->setModelMappingRange(0, 0); |
|
210 | // m_series->setModelMappingRange(0, 0); | |
208 | // series->setModelMapping(2,3, Qt::Horizontal); |
|
211 | // series->setModelMapping(2,3, Qt::Horizontal); | |
209 | m_chart->addSeries(m_series); |
|
212 | m_chart->addSeries(m_series); | |
210 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
213 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
211 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); |
|
214 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); | |
212 |
|
215 | |||
213 | // series 3 |
|
216 | // series 3 | |
214 | m_series = new QSplineSeries; |
|
217 | m_series = new QSplineSeries; | |
215 | m_series->setModel(m_model); |
|
218 | m_series->setModel(m_model); | |
216 | m_series->setModelMapping(4,5, Qt::Vertical); |
|
219 | m_series->setModelMapping(4,5, Qt::Vertical); | |
217 | // m_series->setModelMappingRange(2, 0); |
|
220 | // m_series->setModelMappingRange(2, 0); | |
218 | // series->setModelMapping(4,5, Qt::Horizontal); |
|
221 | // series->setModelMapping(4,5, Qt::Horizontal); | |
219 | m_chart->addSeries(m_series); |
|
222 | m_chart->addSeries(m_series); | |
220 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
223 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
221 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); |
|
224 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); | |
222 | } |
|
225 | } | |
223 | else if (m_scatterRadioButton->isChecked()) |
|
226 | else if (m_scatterRadioButton->isChecked()) | |
224 | { |
|
227 | { | |
225 | // series 1 |
|
228 | // series 1 | |
226 | m_series = new QScatterSeries; |
|
229 | m_series = new QScatterSeries; | |
227 | m_series->setModel(m_model); |
|
230 | m_series->setModel(m_model); | |
228 | m_series->setModelMapping(0,1, Qt::Vertical); |
|
231 | m_series->setModelMapping(0,1, Qt::Vertical); | |
229 | // m_series->setModelMappingRange(2, 0); |
|
232 | // m_series->setModelMappingRange(2, 0); | |
230 | // series->setModelMapping(0,1, Qt::Horizontal); |
|
233 | // series->setModelMapping(0,1, Qt::Horizontal); | |
231 | m_chart->addSeries(m_series); |
|
234 | m_chart->addSeries(m_series); | |
232 |
|
235 | |||
233 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
236 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
234 | m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000)); |
|
237 | m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000)); | |
235 |
|
238 | |||
236 | // series 2 |
|
239 | // series 2 | |
237 | m_series = new QScatterSeries; |
|
240 | m_series = new QScatterSeries; | |
238 | m_series->setModel(m_model); |
|
241 | m_series->setModel(m_model); | |
239 | m_series->setModelMapping(2,3, Qt::Vertical); |
|
242 | m_series->setModelMapping(2,3, Qt::Vertical); | |
240 | // m_series->setModelMappingRange(1, 6); |
|
243 | // m_series->setModelMappingRange(1, 6); | |
241 | // series->setModelMapping(2,3, Qt::Horizontal); |
|
244 | // series->setModelMapping(2,3, Qt::Horizontal); | |
242 | m_chart->addSeries(m_series); |
|
245 | m_chart->addSeries(m_series); | |
243 |
|
246 | |||
244 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
247 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
245 | m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6)); |
|
248 | m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6)); | |
246 |
|
249 | |||
247 | // series 3 |
|
250 | // series 3 | |
248 | m_series = new QScatterSeries; |
|
251 | m_series = new QScatterSeries; | |
249 | m_series->setModel(m_model); |
|
252 | m_series->setModel(m_model); | |
250 | m_series->setModelMapping(4,5, Qt::Vertical); |
|
253 | m_series->setModelMapping(4,5, Qt::Vertical); | |
251 | // series->setModelMapping(4,5, Qt::Horizontal); |
|
254 | // series->setModelMapping(4,5, Qt::Horizontal); | |
252 | m_chart->addSeries(m_series); |
|
255 | m_chart->addSeries(m_series); | |
253 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
256 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
254 | m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000)); |
|
257 | m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000)); | |
255 | } |
|
258 | } | |
256 | else if (m_pieRadioButton->isChecked()) |
|
259 | else if (m_pieRadioButton->isChecked()) | |
257 | { |
|
260 | { | |
258 | // pie 1 |
|
261 | // pie 1 | |
259 | QPieSeries* pieSeries = new QPieSeries; |
|
262 | QPieSeries* pieSeries = new QPieSeries; | |
260 | pieSeries->setModel(m_model); |
|
263 | pieSeries->setModel(m_model); | |
261 | pieSeries->setModelMapping(0,0, Qt::Vertical); |
|
264 | pieSeries->setModelMapping(0,0, Qt::Vertical); | |
262 | pieSeries->setLabelsVisible(true); |
|
265 | pieSeries->setLabelsVisible(true); | |
263 | pieSeries->setPieSize(0.4); |
|
266 | pieSeries->setPieSize(0.4); | |
264 | pieSeries->setHorizontalPosition(0.2); |
|
267 | pieSeries->setHorizontalPosition(0.2); | |
265 | pieSeries->setVerticalPosition(0.35); |
|
268 | pieSeries->setVerticalPosition(0.35); | |
266 |
|
269 | |||
267 | m_chart->addSeries(pieSeries); |
|
270 | m_chart->addSeries(pieSeries); | |
268 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
271 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
269 | m_model->addMapping(seriesColorHex, QRect(0, 0, 1, 1000)); |
|
272 | m_model->addMapping(seriesColorHex, QRect(0, 0, 1, 1000)); | |
270 |
|
273 | |||
271 | // pie 2 |
|
274 | // pie 2 | |
272 | pieSeries = new QPieSeries; |
|
275 | pieSeries = new QPieSeries; | |
273 | pieSeries->setModel(m_model); |
|
276 | pieSeries->setModel(m_model); | |
274 | pieSeries->setModelMapping(1,1, Qt::Vertical); |
|
277 | pieSeries->setModelMapping(1,1, Qt::Vertical); | |
275 | pieSeries->setLabelsVisible(true); |
|
278 | pieSeries->setLabelsVisible(true); | |
276 | pieSeries->setPieSize(0.4); |
|
279 | pieSeries->setPieSize(0.4); | |
277 | pieSeries->setHorizontalPosition(0.8); |
|
280 | pieSeries->setHorizontalPosition(0.8); | |
278 | pieSeries->setVerticalPosition(0.35); |
|
281 | pieSeries->setVerticalPosition(0.35); | |
279 | m_chart->addSeries(pieSeries); |
|
282 | m_chart->addSeries(pieSeries); | |
280 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
283 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
281 | m_model->addMapping(seriesColorHex, QRect(1, 0, 1, 1000)); |
|
284 | m_model->addMapping(seriesColorHex, QRect(1, 0, 1, 1000)); | |
282 |
|
285 | |||
283 | // pie 3 |
|
286 | // pie 3 | |
284 | pieSeries = new QPieSeries; |
|
287 | pieSeries = new QPieSeries; | |
285 | pieSeries->setModel(m_model); |
|
288 | pieSeries->setModel(m_model); | |
286 | pieSeries->setModelMapping(2,2, Qt::Vertical); |
|
289 | pieSeries->setModelMapping(2,2, Qt::Vertical); | |
287 | pieSeries->setLabelsVisible(true); |
|
290 | pieSeries->setLabelsVisible(true); | |
288 | pieSeries->setPieSize(0.4); |
|
291 | pieSeries->setPieSize(0.4); | |
289 | pieSeries->setHorizontalPosition(0.5); |
|
292 | pieSeries->setHorizontalPosition(0.5); | |
290 | pieSeries->setVerticalPosition(0.65); |
|
293 | pieSeries->setVerticalPosition(0.65); | |
291 | m_chart->addSeries(pieSeries); |
|
294 | m_chart->addSeries(pieSeries); | |
292 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
295 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
293 | m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000)); |
|
296 | m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000)); | |
294 | } |
|
297 | } | |
295 | else if (m_areaRadioButton->isChecked()) |
|
298 | else if (m_areaRadioButton->isChecked()) | |
296 | { |
|
299 | { | |
297 | QLineSeries* upperLineSeries = new QLineSeries; |
|
300 | QLineSeries* upperLineSeries = new QLineSeries; | |
298 | upperLineSeries->setModel(m_model); |
|
301 | upperLineSeries->setModel(m_model); | |
299 | upperLineSeries->setModelMapping(0, 1, Qt::Vertical); |
|
302 | upperLineSeries->setModelMapping(0, 1, Qt::Vertical); | |
300 | // upperLineSeries->setModelMappingRange(1, 5); |
|
303 | // upperLineSeries->setModelMappingRange(1, 5); | |
301 | QLineSeries* lowerLineSeries = new QLineSeries; |
|
304 | QLineSeries* lowerLineSeries = new QLineSeries; | |
302 | lowerLineSeries->setModel(m_model); |
|
305 | lowerLineSeries->setModel(m_model); | |
303 | lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); |
|
306 | lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); | |
304 | QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); |
|
307 | QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); | |
305 | m_chart->addSeries(areaSeries); |
|
308 | m_chart->addSeries(areaSeries); | |
306 | seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper(); |
|
309 | seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper(); | |
307 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5)); |
|
310 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5)); | |
308 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); |
|
311 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); | |
309 | } |
|
312 | } | |
310 | else if (m_barRadioButton->isChecked()) |
|
313 | else if (m_barRadioButton->isChecked()) | |
311 | { |
|
314 | { | |
312 | QBarSeries* barSeries = new QBarSeries(QStringList()); |
|
315 | QBarSeries* barSeries = new QBarSeries(QStringList()); | |
313 | barSeries->setModel(m_model); |
|
316 | barSeries->setModel(m_model); | |
314 | barSeries->setModelMapping(5, 2, 4, Qt::Vertical); |
|
317 | barSeries->setModelMapping(5, 2, 4, Qt::Vertical); | |
315 | m_chart->addSeries(barSeries); |
|
318 | m_chart->addSeries(barSeries); | |
316 | QList<QBarSet*> barsets = barSeries->barSets(); |
|
319 | QList<QBarSet*> barsets = barSeries->barSets(); | |
317 | for (int i = 0; i < barsets.count(); i++) { |
|
320 | for (int i = 0; i < barsets.count(); i++) { | |
318 | seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); |
|
321 | seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); | |
319 | m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000)); |
|
322 | m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000)); | |
320 | } |
|
323 | } | |
321 | } |
|
324 | } | |
322 |
|
325 | |||
323 |
|
326 | |||
324 | m_chart->axisX()->setRange(0, 500); |
|
327 | if (!m_barRadioButton->isChecked()) | |
|
328 | m_chart->axisX()->setRange(0, 500); | |||
325 | m_chart->axisY()->setRange(0, 120); |
|
329 | m_chart->axisY()->setRange(0, 120); | |
|
330 | m_chart->legend()->setVisible(true); | |||
326 |
|
331 | |||
327 | // repaint table view colors |
|
332 | // repaint table view colors | |
328 | m_tableView->repaint(); |
|
333 | m_tableView->repaint(); | |
329 | m_tableView->setFocus(); |
|
334 | m_tableView->setFocus(); | |
330 | } |
|
335 | } | |
331 | } |
|
336 | } | |
332 |
|
337 | |||
333 | TableWidget::~TableWidget() |
|
338 | TableWidget::~TableWidget() | |
334 | { |
|
339 | { | |
335 |
|
340 | |||
336 | } |
|
341 | } |
General Comments 0
You need to be logged in to leave comments.
Login now