@@ -258,6 +258,19 int ChartDataSet::seriesCount(QSeries::QSeriesType type) | |||
|
258 | 258 | return count; |
|
259 | 259 | } |
|
260 | 260 | |
|
261 | int ChartDataSet::seriesIndex(QSeries *series) | |
|
262 | { | |
|
263 | int count(-1); | |
|
264 | QMapIterator<QSeries*, QChartAxis*> i(m_seriesAxisMap); | |
|
265 | while (i.hasNext()) { | |
|
266 | i.next(); | |
|
267 | count++; | |
|
268 | if (i.key() == series) | |
|
269 | return count; | |
|
270 | } | |
|
271 | return count; | |
|
272 | } | |
|
273 | ||
|
261 | 274 | QChartAxis* ChartDataSet::axisY(QSeries* series) const |
|
262 | 275 | { |
|
263 | 276 | if(series == 0) return m_axisY; |
@@ -25,6 +25,7 public: | |||
|
25 | 25 | void scrollDomain(int dx,int dy,const QSizeF& size); |
|
26 | 26 | |
|
27 | 27 | int seriesCount(QSeries::QSeriesType type); |
|
28 | int seriesIndex(QSeries *series); | |
|
28 | 29 | |
|
29 | 30 | Domain* domain(QSeries* series) const; |
|
30 | 31 | Domain* domain(QChartAxis* axis) const; |
@@ -145,7 +145,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |||
|
145 | 145 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
146 | 146 | m_animator->addAnimation(line); |
|
147 | 147 | } |
|
148 |
m_chartTheme->decorate(line,lineSeries,m_dataset->series |
|
|
148 | m_chartTheme->decorate(line, lineSeries, m_dataset->seriesIndex(series)); | |
|
149 | 149 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),line,SLOT(handleGeometryChanged(const QRectF&))); |
|
150 | 150 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),line,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
151 | 151 | item = line; |
@@ -159,7 +159,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |||
|
159 | 159 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
160 | 160 | // m_animator->addAnimation(area); |
|
161 | 161 | } |
|
162 |
m_chartTheme->decorate(area,areaSeries,m_dataset->series |
|
|
162 | m_chartTheme->decorate(area, areaSeries, m_dataset->seriesIndex(series)); | |
|
163 | 163 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&))); |
|
164 | 164 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),area,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
165 | 165 | item=area; |
@@ -172,7 +172,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |||
|
172 | 172 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
173 | 173 | // m_animator->addAnimation(bar); |
|
174 | 174 | } |
|
175 |
m_chartTheme->decorate(bar,barSeries,m_dataset->series |
|
|
175 | m_chartTheme->decorate(bar, barSeries, m_dataset->seriesIndex(barSeries)); | |
|
176 | 176 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
|
177 | 177 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
178 | 178 | item=bar; |
@@ -185,7 +185,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |||
|
185 | 185 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
186 | 186 | // m_animator->addAnimation(bar); |
|
187 | 187 | } |
|
188 |
m_chartTheme->decorate(bar,stackedBarSeries,m_dataset->series |
|
|
188 | m_chartTheme->decorate(bar, stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries)); | |
|
189 | 189 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
|
190 | 190 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
191 | 191 | item=bar; |
@@ -198,7 +198,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |||
|
198 | 198 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
199 | 199 | // m_animator->addAnimation(bar); |
|
200 | 200 | } |
|
201 |
m_chartTheme->decorate(bar,percentBarSeries |
|
|
201 | m_chartTheme->decorate(bar, percentBarSeries, m_dataset->seriesIndex(percentBarSeries)); | |
|
202 | 202 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
|
203 | 203 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
204 | 204 | item=bar; |
@@ -207,15 +207,15 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |||
|
207 | 207 | |
|
208 | 208 | case QSeries::SeriesTypeScatter: { |
|
209 | 209 | QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series); |
|
210 |
|
|
|
211 |
|
|
|
212 |
|
|
|
213 | } | |
|
214 |
|
|
|
215 |
|
|
|
216 |
|
|
|
217 |
|
|
|
218 | break; | |
|
210 | ScatterChartItem *scatter = new ScatterChartItem(scatterSeries, m_chart); | |
|
211 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
|
212 | m_animator->addAnimation(scatter); | |
|
213 | } | |
|
214 | m_chartTheme->decorate(scatter, scatterSeries, m_dataset->seriesIndex(series)); | |
|
215 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),scatter,SLOT(handleGeometryChanged(const QRectF&))); | |
|
216 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),scatter,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
|
217 | item = scatter; | |
|
218 | break; | |
|
219 | 219 | } |
|
220 | 220 | |
|
221 | 221 | case QSeries::SeriesTypePie: { |
@@ -224,7 +224,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |||
|
224 | 224 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
225 | 225 | // m_animator->addAnimation(pie); |
|
226 | 226 | } |
|
227 |
m_chartTheme->decorate(pie, pieSeries, m_dataset->series |
|
|
227 | m_chartTheme->decorate(pie, pieSeries, m_dataset->seriesIndex(series)); | |
|
228 | 228 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),pie,SLOT(handleGeometryChanged(const QRectF&))); |
|
229 | 229 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),pie,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
230 | 230 | // Hide all from background when there is only piechart |
@@ -239,18 +239,17 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |||
|
239 | 239 | } |
|
240 | 240 | |
|
241 | 241 | case QSeries::SeriesTypeSpline: { |
|
242 | ||
|
243 | QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series); | |
|
244 | SplineChartItem* spline = new SplineChartItem(splineSeries, m_chart); | |
|
245 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
|
246 | m_animator->addAnimation(spline); | |
|
247 | } | |
|
248 | m_chartTheme->decorate(spline, splineSeries, m_dataset->seriesCount(series->type())); | |
|
249 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),spline,SLOT(handleGeometryChanged(const QRectF&))); | |
|
250 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),spline,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
|
251 | item=spline; | |
|
252 | break; | |
|
253 | } | |
|
242 | QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series); | |
|
243 | SplineChartItem* spline = new SplineChartItem(splineSeries, m_chart); | |
|
244 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
|
245 | m_animator->addAnimation(spline); | |
|
246 | } | |
|
247 | m_chartTheme->decorate(spline, splineSeries, m_dataset->seriesIndex(series)); | |
|
248 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),spline,SLOT(handleGeometryChanged(const QRectF&))); | |
|
249 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),spline,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
|
250 | item=spline; | |
|
251 | break; | |
|
252 | } | |
|
254 | 253 | default: { |
|
255 | 254 | qDebug()<< "Series type" << series->type() << "not implemented."; |
|
256 | 255 | break; |
@@ -64,7 +64,7 void ChartTheme::decorate(QChart* chart) | |||
|
64 | 64 | chart->setChartBackgroundBrush(m_backgroundGradient); |
|
65 | 65 | } |
|
66 | 66 | |
|
67 |
void ChartTheme::decorate(AreaChartItem* item, QAreaSeries* series,int |
|
|
67 | void ChartTheme::decorate(AreaChartItem* item, QAreaSeries* series, int index) | |
|
68 | 68 | { |
|
69 | 69 | QPen pen; |
|
70 | 70 | QBrush brush; |
@@ -72,7 +72,7 void ChartTheme::decorate(AreaChartItem* item, QAreaSeries* series,int count) | |||
|
72 | 72 | if (pen != series->pen()){ |
|
73 | 73 | item->setPen(series->pen()); |
|
74 | 74 | } else { |
|
75 |
pen.setColor(colorAt(m_seriesGradients.at( |
|
|
75 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0)); | |
|
76 | 76 | pen.setWidthF(2); |
|
77 | 77 | item->setPen(pen); |
|
78 | 78 | } |
@@ -80,106 +80,106 void ChartTheme::decorate(AreaChartItem* item, QAreaSeries* series,int count) | |||
|
80 | 80 | if (brush != series->brush()) { |
|
81 | 81 | item->setBrush(series->brush()); |
|
82 | 82 | } else { |
|
83 |
QBrush brush(m_seriesColors.at( |
|
|
83 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
|
84 | 84 | item->setBrush(brush); |
|
85 | 85 | } |
|
86 | 86 | } |
|
87 | 87 | |
|
88 | 88 | |
|
89 |
void ChartTheme::decorate(LineChartItem* item, QLineSeries* series,int |
|
|
89 | void ChartTheme::decorate(LineChartItem* item, QLineSeries* series,int index) | |
|
90 | 90 | { |
|
91 | 91 | QPen pen; |
|
92 | 92 | if(pen != series->pen()){ |
|
93 | 93 | item->setLinePen(series->pen()); |
|
94 | 94 | return; |
|
95 | 95 | } |
|
96 |
pen.setColor(m_seriesColors.at( |
|
|
96 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
|
97 | 97 | pen.setWidthF(2); |
|
98 | 98 | item->setLinePen(pen); |
|
99 | 99 | } |
|
100 | 100 | |
|
101 |
void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int |
|
|
101 | void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int index) | |
|
102 | 102 | { |
|
103 | 103 | QList<QBarSet*> sets = series->barSets(); |
|
104 | 104 | for (int i=0; i<sets.count(); i++) { |
|
105 | 105 | qreal pos = 0.5; |
|
106 | 106 | if (sets.count() > 1) |
|
107 | 107 | pos = (qreal) i / (qreal) (sets.count() - 1); |
|
108 |
QColor c = colorAt(m_seriesGradients.at( |
|
|
108 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
|
109 | 109 | sets.at(i)->setBrush(QBrush(c)); |
|
110 | 110 | |
|
111 | 111 | // Pick label color as far as possible from bar color (within gradient). |
|
112 | 112 | // 0.3 is magic number that was picked as value that gave enough contrast with icy theme gradient :) |
|
113 | 113 | // TODO: better picking of label color? |
|
114 | 114 | if (pos < 0.3) { |
|
115 |
c = colorAt(m_seriesGradients.at( |
|
|
115 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); | |
|
116 | 116 | } else { |
|
117 |
c = colorAt(m_seriesGradients.at( |
|
|
117 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); | |
|
118 | 118 | } |
|
119 | 119 | sets.at(i)->setFloatingValuePen(QPen(c)); |
|
120 | 120 | } |
|
121 | 121 | } |
|
122 | 122 | |
|
123 |
void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int |
|
|
123 | void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int index) | |
|
124 | 124 | { |
|
125 | 125 | QList<QBarSet*> sets = series->barSets(); |
|
126 | 126 | for (int i=0; i<sets.count(); i++) { |
|
127 | 127 | qreal pos = 0.5; |
|
128 | 128 | if (sets.count() > 1) |
|
129 | 129 | pos = (qreal) i / (qreal) (sets.count() - 1); |
|
130 |
QColor c = colorAt(m_seriesGradients.at( |
|
|
130 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
|
131 | 131 | sets.at(i)->setBrush(QBrush(c)); |
|
132 | 132 | |
|
133 | 133 | if (pos < 0.3) { |
|
134 |
c = colorAt(m_seriesGradients.at( |
|
|
134 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); | |
|
135 | 135 | } else { |
|
136 |
c = colorAt(m_seriesGradients.at( |
|
|
136 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); | |
|
137 | 137 | } |
|
138 | 138 | sets.at(i)->setFloatingValuePen(QPen(c)); |
|
139 | 139 | } |
|
140 | 140 | } |
|
141 | 141 | |
|
142 |
void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int |
|
|
142 | void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int index) | |
|
143 | 143 | { |
|
144 | 144 | QList<QBarSet*> sets = series->barSets(); |
|
145 | 145 | for (int i=0; i<sets.count(); i++) { |
|
146 | 146 | qreal pos = 0.5; |
|
147 | 147 | if (sets.count() > 1) |
|
148 | 148 | pos = (qreal) i / (qreal) (sets.count() - 1); |
|
149 |
QColor c = colorAt(m_seriesGradients.at( |
|
|
149 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
|
150 | 150 | sets.at(i)->setBrush(QBrush(c)); |
|
151 | 151 | |
|
152 | 152 | if (pos < 0.3) { |
|
153 |
c = colorAt(m_seriesGradients.at( |
|
|
153 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); | |
|
154 | 154 | } else { |
|
155 |
c = colorAt(m_seriesGradients.at( |
|
|
155 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); | |
|
156 | 156 | } |
|
157 | 157 | sets.at(i)->setFloatingValuePen(QPen(c)); |
|
158 | 158 | } |
|
159 | 159 | } |
|
160 | 160 | |
|
161 |
void ChartTheme::decorate(ScatterChartItem* item, QScatterSeries* series, int |
|
|
161 | void ChartTheme::decorate(ScatterChartItem* item, QScatterSeries* series, int index) | |
|
162 | 162 | { |
|
163 | 163 | Q_ASSERT(item); |
|
164 | 164 | Q_ASSERT(series); |
|
165 | 165 | |
|
166 | 166 | // Use a base color for brush |
|
167 |
item->setBrush(m_seriesColors.at( |
|
|
167 | item->setBrush(m_seriesColors.at(index % m_seriesColors.size())); | |
|
168 | 168 | |
|
169 | 169 | // Take pen near from gradient start, effectively using a lighter color for outline |
|
170 | 170 | QPen pen(QBrush(Qt::SolidPattern), 3); |
|
171 |
pen.setColor(colorAt(m_seriesGradients.at( |
|
|
171 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0)); | |
|
172 | 172 | item->setPen(pen); |
|
173 | 173 | } |
|
174 | 174 | |
|
175 |
void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int |
|
|
175 | void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int index) | |
|
176 | 176 | { |
|
177 | 177 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
178 | 178 | for (int i(0); i < series->slices().count(); i++) { |
|
179 | 179 | qreal pos = (qreal) i / (qreal) series->count(); |
|
180 |
QColor penColor = colorAt(m_seriesGradients.at( |
|
|
180 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.1); | |
|
181 | 181 | series->slices().at(i)->setSlicePen(penColor); |
|
182 |
QColor brushColor = colorAt(m_seriesGradients.at( |
|
|
182 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
|
183 | 183 | series->slices().at(i)->setSliceBrush(brushColor); |
|
184 | 184 | } |
|
185 | 185 | } |
@@ -194,7 +194,7 void ChartTheme::decorate(QChartAxis* axis, AxisItem* item) | |||
|
194 | 194 | axis->setShadesOpacity(0.5); |
|
195 | 195 | } |
|
196 | 196 | |
|
197 |
void ChartTheme::decorate(SplineChartItem* item, QSplineSeries* series, int |
|
|
197 | void ChartTheme::decorate(SplineChartItem* item, QSplineSeries* series, int index) | |
|
198 | 198 | { |
|
199 | 199 | Q_ASSERT(item); |
|
200 | 200 | Q_ASSERT(series); |
@@ -204,12 +204,12 void ChartTheme::decorate(SplineChartItem* item, QSplineSeries* series, int coun | |||
|
204 | 204 | if(pen != series->pen()){ |
|
205 | 205 | item->setLinePen(series->pen()); |
|
206 | 206 | }else{ |
|
207 |
pen.setColor(m_seriesColors.at( |
|
|
207 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
|
208 | 208 | pen.setWidthF(series->pen().widthF()); |
|
209 | 209 | item->setLinePen(series->pen()); |
|
210 | 210 | } |
|
211 | 211 | |
|
212 |
// QColor color = m_seriesColors.at( |
|
|
212 | // QColor color = m_seriesColors.at(index % m_seriesColors.size()); | |
|
213 | 213 | // TODO: define alpha in the theme? or in the series? |
|
214 | 214 | //color.setAlpha(120); |
|
215 | 215 |
@@ -35,16 +35,16 public: | |||
|
35 | 35 | static ChartTheme* createTheme(QChart::ChartTheme theme); |
|
36 | 36 | QChart::ChartTheme id() const {return m_id;} |
|
37 | 37 | void decorate(QChart* chart); |
|
38 |
//void decorate(ChartItem* item, QSeries* series,int |
|
|
39 |
void decorate(BarPresenter* item, QBarSeries* series,int |
|
|
40 |
void decorate(StackedBarPresenter* item, QStackedBarSeries* series,int |
|
|
41 |
void decorate(PercentBarPresenter* item, QPercentBarSeries* series,int |
|
|
42 |
void decorate(LineChartItem* item, QLineSeries* series,int |
|
|
43 |
void decorate(AreaChartItem* item, QAreaSeries* series,int |
|
|
44 |
void decorate(ScatterChartItem* presenter, QScatterSeries* series, int |
|
|
45 |
void decorate(PiePresenter* item, QPieSeries* series, int |
|
|
38 | //void decorate(ChartItem* item, QSeries* series,int index); | |
|
39 | void decorate(BarPresenter* item, QBarSeries* series, int index); | |
|
40 | void decorate(StackedBarPresenter* item, QStackedBarSeries* series, int index); | |
|
41 | void decorate(PercentBarPresenter* item, QPercentBarSeries* series, int index); | |
|
42 | void decorate(LineChartItem* item, QLineSeries* series, int index); | |
|
43 | void decorate(AreaChartItem* item, QAreaSeries* series, int index); | |
|
44 | void decorate(ScatterChartItem* presenter, QScatterSeries* series, int index); | |
|
45 | void decorate(PiePresenter* item, QPieSeries* series, int index); | |
|
46 | 46 | void decorate(QChartAxis* axis,AxisItem* item); |
|
47 |
void decorate(SplineChartItem* presenter, QSplineSeries* series, int |
|
|
47 | void decorate(SplineChartItem* presenter, QSplineSeries* series, int index); | |
|
48 | 48 | |
|
49 | 49 | public: // utils |
|
50 | 50 | void generateSeriesGradients(); |
General Comments 0
You need to be logged in to leave comments.
Login now