@@ -1,399 +1,401 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 | #include "chartpresenter_p.h" |
|
3 | #include "chartpresenter_p.h" | |
4 | #include "chartdataset_p.h" |
|
4 | #include "chartdataset_p.h" | |
5 | #include "charttheme_p.h" |
|
5 | #include "charttheme_p.h" | |
6 | #include "chartanimator_p.h" |
|
6 | #include "chartanimator_p.h" | |
7 | //series |
|
7 | //series | |
8 | #include "qbarseries.h" |
|
8 | #include "qbarseries.h" | |
9 | #include "qstackedbarseries.h" |
|
9 | #include "qstackedbarseries.h" | |
10 | #include "qpercentbarseries.h" |
|
10 | #include "qpercentbarseries.h" | |
11 | #include "qlineseries.h" |
|
11 | #include "qlineseries.h" | |
12 | #include "qareaseries.h" |
|
12 | #include "qareaseries.h" | |
13 | #include "qpieseries.h" |
|
13 | #include "qpieseries.h" | |
14 | #include "qscatterseries.h" |
|
14 | #include "qscatterseries.h" | |
15 | #include "qsplineseries.h" |
|
15 | #include "qsplineseries.h" | |
16 | //items |
|
16 | //items | |
17 | #include "axisitem_p.h" |
|
17 | #include "axisitem_p.h" | |
18 | #include "areachartitem_p.h" |
|
18 | #include "areachartitem_p.h" | |
19 | #include "barpresenter_p.h" |
|
19 | #include "barpresenter_p.h" | |
20 | #include "stackedbarpresenter_p.h" |
|
20 | #include "stackedbarpresenter_p.h" | |
21 | #include "percentbarpresenter_p.h" |
|
21 | #include "percentbarpresenter_p.h" | |
22 | #include "linechartitem_p.h" |
|
22 | #include "linechartitem_p.h" | |
23 | #include "piepresenter_p.h" |
|
23 | #include "piepresenter_p.h" | |
24 | #include "scatterchartitem_p.h" |
|
24 | #include "scatterchartitem_p.h" | |
25 | #include "splinechartitem_p.h" |
|
25 | #include "splinechartitem_p.h" | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
29 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), | |
30 | m_chart(chart), |
|
30 | m_chart(chart), | |
31 | m_animator(0), |
|
31 | m_animator(0), | |
32 | m_dataset(dataset), |
|
32 | m_dataset(dataset), | |
33 | m_chartTheme(0), |
|
33 | m_chartTheme(0), | |
34 | m_zoomIndex(0), |
|
34 | m_zoomIndex(0), | |
35 | m_marginSize(0), |
|
35 | m_marginSize(0), | |
36 | m_rect(QRectF(QPoint(0,0),m_chart->size())), |
|
36 | m_rect(QRectF(QPoint(0,0),m_chart->size())), | |
37 | m_options(QChart::NoAnimation) |
|
37 | m_options(QChart::NoAnimation) | |
38 | { |
|
38 | { | |
39 | createConnections(); |
|
39 | createConnections(); | |
40 | setChartTheme(QChart::ChartThemeDefault); |
|
40 | setChartTheme(QChart::ChartThemeDefault); | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | ChartPresenter::~ChartPresenter() |
|
43 | ChartPresenter::~ChartPresenter() | |
44 | { |
|
44 | { | |
45 | delete m_chartTheme; |
|
45 | delete m_chartTheme; | |
46 | } |
|
46 | } | |
47 |
|
47 | |||
48 | void ChartPresenter::createConnections() |
|
48 | void ChartPresenter::createConnections() | |
49 | { |
|
49 | { | |
50 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
50 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); | |
51 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),this,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
51 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),this,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
52 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*))); |
|
52 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*))); | |
53 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),this,SLOT(handleAxisAdded(QChartAxis*,Domain*))); |
|
53 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),this,SLOT(handleAxisAdded(QChartAxis*,Domain*))); | |
54 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); |
|
54 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 |
|
57 | |||
58 | QRectF ChartPresenter::geometry() const |
|
58 | QRectF ChartPresenter::geometry() const | |
59 | { |
|
59 | { | |
60 | return m_rect; |
|
60 | return m_rect; | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | void ChartPresenter::handleGeometryChanged() |
|
63 | void ChartPresenter::handleGeometryChanged() | |
64 | { |
|
64 | { | |
65 | QRectF rect(QPoint(0,0),m_chart->size()); |
|
65 | QRectF rect(QPoint(0,0),m_chart->size()); | |
66 | rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); |
|
66 | rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); | |
67 |
|
67 | |||
68 | //rewrite zoom stack |
|
68 | //rewrite zoom stack | |
69 | for(int i=0;i<m_zoomStack.count();i++){ |
|
69 | for(int i=0;i<m_zoomStack.count();i++){ | |
70 | QRectF r = m_zoomStack[i]; |
|
70 | QRectF r = m_zoomStack[i]; | |
71 | qreal w = rect.width()/m_rect.width(); |
|
71 | qreal w = rect.width()/m_rect.width(); | |
72 | qreal h = rect.height()/m_rect.height(); |
|
72 | qreal h = rect.height()/m_rect.height(); | |
73 | QPointF tl = r.topLeft(); |
|
73 | QPointF tl = r.topLeft(); | |
74 | tl.setX(tl.x()*w); |
|
74 | tl.setX(tl.x()*w); | |
75 | tl.setY(tl.y()*h); |
|
75 | tl.setY(tl.y()*h); | |
76 | QPointF br = r.bottomRight(); |
|
76 | QPointF br = r.bottomRight(); | |
77 | br.setX(br.x()*w); |
|
77 | br.setX(br.x()*w); | |
78 | br.setY(br.y()*h); |
|
78 | br.setY(br.y()*h); | |
79 | r.setTopLeft(tl); |
|
79 | r.setTopLeft(tl); | |
80 | r.setBottomRight(br); |
|
80 | r.setBottomRight(br); | |
81 | m_zoomStack[i]=r; |
|
81 | m_zoomStack[i]=r; | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | m_rect = rect; |
|
84 | m_rect = rect; | |
85 | Q_ASSERT(m_rect.isValid()); |
|
85 | Q_ASSERT(m_rect.isValid()); | |
86 | emit geometryChanged(m_rect); |
|
86 | emit geometryChanged(m_rect); | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | int ChartPresenter::margin() const |
|
89 | int ChartPresenter::margin() const | |
90 | { |
|
90 | { | |
91 | return m_marginSize; |
|
91 | return m_marginSize; | |
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | void ChartPresenter::setMargin(int margin) |
|
94 | void ChartPresenter::setMargin(int margin) | |
95 | { |
|
95 | { | |
96 | m_marginSize = margin; |
|
96 | m_marginSize = margin; | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain) |
|
99 | void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain) | |
100 | { |
|
100 | { | |
101 | AxisItem* item = new AxisItem(axis,this,axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); |
|
101 | AxisItem* item = new AxisItem(axis,this,axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); | |
102 |
|
102 | |||
103 | if(m_options.testFlag(QChart::GridAxisAnimations)){ |
|
103 | if(m_options.testFlag(QChart::GridAxisAnimations)){ | |
104 | m_animator->addAnimation(item); |
|
104 | m_animator->addAnimation(item); | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | if(axis==m_dataset->axisX()){ |
|
107 | if(axis==m_dataset->axisX()){ | |
|
108 | m_chartTheme->decorate(axis,true); | |||
108 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); |
|
109 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); | |
109 | //initialize |
|
110 | //initialize | |
110 | item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount()); |
|
111 | item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount()); | |
|
112 | ||||
111 | } |
|
113 | } | |
112 | else{ |
|
114 | else{ | |
|
115 | m_chartTheme->decorate(axis,false); | |||
113 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); |
|
116 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); | |
114 | //initialize |
|
117 | //initialize | |
115 | item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount()); |
|
118 | item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount()); | |
116 | } |
|
119 | } | |
117 |
|
120 | |||
118 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
121 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
119 | //initialize |
|
122 | //initialize | |
120 | item->handleGeometryChanged(m_rect); |
|
123 | item->handleGeometryChanged(m_rect); | |
121 | m_chartTheme->decorate(axis, m_chart); |
|
|||
122 | m_axisItems.insert(axis, item); |
|
124 | m_axisItems.insert(axis, item); | |
123 | } |
|
125 | } | |
124 |
|
126 | |||
125 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) |
|
127 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) | |
126 | { |
|
128 | { | |
127 | AxisItem* item = m_axisItems.take(axis); |
|
129 | AxisItem* item = m_axisItems.take(axis); | |
128 | Q_ASSERT(item); |
|
130 | Q_ASSERT(item); | |
129 | if(m_animator) m_animator->removeAnimation(item); |
|
131 | if(m_animator) m_animator->removeAnimation(item); | |
130 | delete item; |
|
132 | delete item; | |
131 | } |
|
133 | } | |
132 |
|
134 | |||
133 |
|
135 | |||
134 | void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) |
|
136 | void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |
135 | { |
|
137 | { | |
136 | ChartItem *item = 0 ; |
|
138 | ChartItem *item = 0 ; | |
137 |
|
139 | |||
138 | switch(series->type()) |
|
140 | switch(series->type()) | |
139 | { |
|
141 | { | |
140 | case QSeries::SeriesTypeLine: { |
|
142 | case QSeries::SeriesTypeLine: { | |
141 |
|
143 | |||
142 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); |
|
144 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); | |
143 | LineChartItem* line = new LineChartItem(lineSeries,m_chart); |
|
145 | LineChartItem* line = new LineChartItem(lineSeries,m_chart); | |
144 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
146 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
145 | m_animator->addAnimation(line); |
|
147 | m_animator->addAnimation(line); | |
146 | } |
|
148 | } | |
147 |
m_chartTheme->decorate( |
|
149 | m_chartTheme->decorate(lineSeries, m_dataset->seriesIndex(series)); | |
148 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),line,SLOT(handleGeometryChanged(const QRectF&))); |
|
150 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),line,SLOT(handleGeometryChanged(const QRectF&))); | |
149 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),line,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
151 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),line,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
150 | item = line; |
|
152 | item = line; | |
151 | break; |
|
153 | break; | |
152 | } |
|
154 | } | |
153 |
|
155 | |||
154 | case QSeries::SeriesTypeArea: { |
|
156 | case QSeries::SeriesTypeArea: { | |
155 |
|
157 | |||
156 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); |
|
158 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); | |
157 | AreaChartItem* area = new AreaChartItem(areaSeries,m_chart); |
|
159 | AreaChartItem* area = new AreaChartItem(areaSeries,m_chart); | |
158 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
160 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
159 | m_animator->addAnimation(area->upperLineItem()); |
|
161 | m_animator->addAnimation(area->upperLineItem()); | |
160 | if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem()); |
|
162 | if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem()); | |
161 | } |
|
163 | } | |
162 |
m_chartTheme->decorate( |
|
164 | m_chartTheme->decorate(areaSeries, m_dataset->seriesIndex(series)); | |
163 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&))); |
|
165 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&))); | |
164 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),area,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
166 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),area,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
165 | item=area; |
|
167 | item=area; | |
166 | break; |
|
168 | break; | |
167 | } |
|
169 | } | |
168 |
|
170 | |||
169 | case QSeries::SeriesTypeBar: { |
|
171 | case QSeries::SeriesTypeBar: { | |
170 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
172 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); | |
171 | BarPresenter* bar = new BarPresenter(barSeries,m_chart); |
|
173 | BarPresenter* bar = new BarPresenter(barSeries,m_chart); | |
172 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
174 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
173 | // m_animator->addAnimation(bar); |
|
175 | // m_animator->addAnimation(bar); | |
174 | } |
|
176 | } | |
175 | m_chartTheme->decorate(bar, barSeries, m_dataset->seriesIndex(barSeries)); |
|
177 | m_chartTheme->decorate(bar, barSeries, m_dataset->seriesIndex(barSeries)); | |
176 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
|
178 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); | |
177 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
179 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
178 | item=bar; |
|
180 | item=bar; | |
179 | break; |
|
181 | break; | |
180 | } |
|
182 | } | |
181 |
|
183 | |||
182 | case QSeries::SeriesTypeStackedBar: { |
|
184 | case QSeries::SeriesTypeStackedBar: { | |
183 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
185 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); | |
184 | StackedBarPresenter* bar = new StackedBarPresenter(stackedBarSeries,m_chart); |
|
186 | StackedBarPresenter* bar = new StackedBarPresenter(stackedBarSeries,m_chart); | |
185 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
187 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
186 | // m_animator->addAnimation(bar); |
|
188 | // m_animator->addAnimation(bar); | |
187 | } |
|
189 | } | |
188 | m_chartTheme->decorate(bar, stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries)); |
|
190 | m_chartTheme->decorate(bar, stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries)); | |
189 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
|
191 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); | |
190 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
192 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
191 | item=bar; |
|
193 | item=bar; | |
192 | break; |
|
194 | break; | |
193 | } |
|
195 | } | |
194 |
|
196 | |||
195 | case QSeries::SeriesTypePercentBar: { |
|
197 | case QSeries::SeriesTypePercentBar: { | |
196 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
198 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); | |
197 | PercentBarPresenter* bar = new PercentBarPresenter(percentBarSeries,m_chart); |
|
199 | PercentBarPresenter* bar = new PercentBarPresenter(percentBarSeries,m_chart); | |
198 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
200 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
199 | // m_animator->addAnimation(bar); |
|
201 | // m_animator->addAnimation(bar); | |
200 | } |
|
202 | } | |
201 | m_chartTheme->decorate(bar, percentBarSeries, m_dataset->seriesIndex(percentBarSeries)); |
|
203 | m_chartTheme->decorate(bar, percentBarSeries, m_dataset->seriesIndex(percentBarSeries)); | |
202 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
|
204 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); | |
203 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
205 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
204 | item=bar; |
|
206 | item=bar; | |
205 | break; |
|
207 | break; | |
206 | } |
|
208 | } | |
207 |
|
209 | |||
208 | case QSeries::SeriesTypeScatter: { |
|
210 | case QSeries::SeriesTypeScatter: { | |
209 | QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series); |
|
211 | QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series); | |
210 | ScatterChartItem *scatter = new ScatterChartItem(scatterSeries, m_chart); |
|
212 | ScatterChartItem *scatter = new ScatterChartItem(scatterSeries, m_chart); | |
211 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
213 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
212 | m_animator->addAnimation(scatter); |
|
214 | m_animator->addAnimation(scatter); | |
213 | } |
|
215 | } | |
214 |
m_chartTheme->decorate( |
|
216 | m_chartTheme->decorate(scatterSeries, m_dataset->seriesIndex(series)); | |
215 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),scatter,SLOT(handleGeometryChanged(const QRectF&))); |
|
217 | 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))); |
|
218 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),scatter,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
217 | item = scatter; |
|
219 | item = scatter; | |
218 | break; |
|
220 | break; | |
219 | } |
|
221 | } | |
220 |
|
222 | |||
221 | case QSeries::SeriesTypePie: { |
|
223 | case QSeries::SeriesTypePie: { | |
222 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
224 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
223 | PiePresenter* pie = new PiePresenter(m_chart, pieSeries); |
|
225 | PiePresenter* pie = new PiePresenter(m_chart, pieSeries); | |
224 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
226 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
225 | // m_animator->addAnimation(pie); |
|
227 | // m_animator->addAnimation(pie); | |
226 | } |
|
228 | } | |
227 | m_chartTheme->decorate(pie, pieSeries, m_dataset->seriesIndex(series)); |
|
229 | m_chartTheme->decorate(pie, pieSeries, m_dataset->seriesIndex(series)); | |
228 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),pie,SLOT(handleGeometryChanged(const QRectF&))); |
|
230 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),pie,SLOT(handleGeometryChanged(const QRectF&))); | |
229 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),pie,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
231 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),pie,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
230 | // Hide all from background when there is only piechart |
|
232 | // Hide all from background when there is only piechart | |
231 | // TODO: refactor this ugly code... should be one setting for this |
|
233 | // TODO: refactor this ugly code... should be one setting for this | |
232 | if (m_chartItems.count() == 0) { |
|
234 | if (m_chartItems.count() == 0) { | |
233 | m_chart->axisX()->hide(); |
|
235 | m_chart->axisX()->hide(); | |
234 | m_chart->axisY()->hide(); |
|
236 | m_chart->axisY()->hide(); | |
235 | m_chart->setChartBackgroundBrush(Qt::transparent); |
|
237 | m_chart->setChartBackgroundBrush(Qt::transparent); | |
236 | } |
|
238 | } | |
237 | item=pie; |
|
239 | item=pie; | |
238 | break; |
|
240 | break; | |
239 | } |
|
241 | } | |
240 |
|
242 | |||
241 | case QSeries::SeriesTypeSpline: { |
|
243 | case QSeries::SeriesTypeSpline: { | |
242 | QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series); |
|
244 | QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series); | |
243 | SplineChartItem* spline = new SplineChartItem(splineSeries, m_chart); |
|
245 | SplineChartItem* spline = new SplineChartItem(splineSeries, m_chart); | |
244 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
246 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
245 | m_animator->addAnimation(spline); |
|
247 | m_animator->addAnimation(spline); | |
246 | } |
|
248 | } | |
247 |
m_chartTheme->decorate( |
|
249 | m_chartTheme->decorate(splineSeries, m_dataset->seriesIndex(series)); | |
248 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),spline,SLOT(handleGeometryChanged(const QRectF&))); |
|
250 | 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))); |
|
251 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),spline,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
250 | item=spline; |
|
252 | item=spline; | |
251 | break; |
|
253 | break; | |
252 | } |
|
254 | } | |
253 | default: { |
|
255 | default: { | |
254 | qDebug()<< "Series type" << series->type() << "not implemented."; |
|
256 | qDebug()<< "Series type" << series->type() << "not implemented."; | |
255 | break; |
|
257 | break; | |
256 | } |
|
258 | } | |
257 | } |
|
259 | } | |
258 |
|
260 | |||
259 | //initialize |
|
261 | //initialize | |
260 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); |
|
262 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); | |
261 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
263 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
262 | m_chartItems.insert(series,item); |
|
264 | m_chartItems.insert(series,item); | |
263 | zoomReset(); |
|
265 | zoomReset(); | |
264 | } |
|
266 | } | |
265 |
|
267 | |||
266 | void ChartPresenter::handleSeriesRemoved(QSeries* series) |
|
268 | void ChartPresenter::handleSeriesRemoved(QSeries* series) | |
267 | { |
|
269 | { | |
268 | ChartItem* item = m_chartItems.take(series); |
|
270 | ChartItem* item = m_chartItems.take(series); | |
269 | Q_ASSERT(item); |
|
271 | Q_ASSERT(item); | |
270 | if(m_animator) { |
|
272 | if(m_animator) { | |
271 | //small hack to handle area animations |
|
273 | //small hack to handle area animations | |
272 | if(series->type()==QSeries::SeriesTypeArea){ |
|
274 | if(series->type()==QSeries::SeriesTypeArea){ | |
273 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); |
|
275 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); | |
274 | AreaChartItem* area = static_cast<AreaChartItem*>(item); |
|
276 | AreaChartItem* area = static_cast<AreaChartItem*>(item); | |
275 | m_animator->removeAnimation(area->upperLineItem()); |
|
277 | m_animator->removeAnimation(area->upperLineItem()); | |
276 | if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem()); |
|
278 | if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem()); | |
277 | }else |
|
279 | }else | |
278 | m_animator->removeAnimation(item); |
|
280 | m_animator->removeAnimation(item); | |
279 | } |
|
281 | } | |
280 | delete item; |
|
282 | delete item; | |
281 | } |
|
283 | } | |
282 |
|
284 | |||
283 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) |
|
285 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) | |
284 | { |
|
286 | { | |
285 | if(m_chartTheme && m_chartTheme->id() == theme) return; |
|
287 | if(m_chartTheme && m_chartTheme->id() == theme) return; | |
286 | delete m_chartTheme; |
|
288 | delete m_chartTheme; | |
287 | m_chartTheme = ChartTheme::createTheme(theme); |
|
289 | m_chartTheme = ChartTheme::createTheme(theme); | |
288 | m_chartTheme->decorate(m_chart); |
|
290 | m_chartTheme->decorate(m_chart); | |
289 | m_chartTheme->decorate(m_chart->legend()); |
|
291 | m_chartTheme->decorate(m_chart->legend()); | |
290 | resetAllElements(); |
|
292 | resetAllElements(); | |
291 | } |
|
293 | } | |
292 |
|
294 | |||
293 | QChart::ChartTheme ChartPresenter::chartTheme() |
|
295 | QChart::ChartTheme ChartPresenter::chartTheme() | |
294 | { |
|
296 | { | |
295 | return m_chartTheme->id(); |
|
297 | return m_chartTheme->id(); | |
296 | } |
|
298 | } | |
297 |
|
299 | |||
298 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
300 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |
299 | { |
|
301 | { | |
300 | if(m_options!=options) { |
|
302 | if(m_options!=options) { | |
301 |
|
303 | |||
302 | m_options=options; |
|
304 | m_options=options; | |
303 |
|
305 | |||
304 | if(m_options!=QChart::NoAnimation && !m_animator) { |
|
306 | if(m_options!=QChart::NoAnimation && !m_animator) { | |
305 | m_animator= new ChartAnimator(this); |
|
307 | m_animator= new ChartAnimator(this); | |
306 |
|
308 | |||
307 | } |
|
309 | } | |
308 | resetAllElements(); |
|
310 | resetAllElements(); | |
309 | } |
|
311 | } | |
310 |
|
312 | |||
311 | } |
|
313 | } | |
312 |
|
314 | |||
313 | void ChartPresenter::resetAllElements() |
|
315 | void ChartPresenter::resetAllElements() | |
314 | { |
|
316 | { | |
315 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); |
|
317 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); | |
316 | QList<QSeries*> seriesList = m_chartItems.uniqueKeys(); |
|
318 | QList<QSeries*> seriesList = m_chartItems.uniqueKeys(); | |
317 |
|
319 | |||
318 | foreach(QChartAxis* axis, axisList) { |
|
320 | foreach(QChartAxis* axis, axisList) { | |
319 | handleAxisRemoved(axis); |
|
321 | handleAxisRemoved(axis); | |
320 | handleAxisAdded(axis,m_dataset->domain(axis)); |
|
322 | handleAxisAdded(axis,m_dataset->domain(axis)); | |
321 | } |
|
323 | } | |
322 | foreach(QSeries* series, seriesList) { |
|
324 | foreach(QSeries* series, seriesList) { | |
323 | handleSeriesRemoved(series); |
|
325 | handleSeriesRemoved(series); | |
324 | handleSeriesAdded(series,m_dataset->domain(series)); |
|
326 | handleSeriesAdded(series,m_dataset->domain(series)); | |
325 | } |
|
327 | } | |
326 | } |
|
328 | } | |
327 |
|
329 | |||
328 | void ChartPresenter::zoomIn() |
|
330 | void ChartPresenter::zoomIn() | |
329 | { |
|
331 | { | |
330 | QRectF rect = geometry(); |
|
332 | QRectF rect = geometry(); | |
331 | rect.setWidth(rect.width()/2); |
|
333 | rect.setWidth(rect.width()/2); | |
332 | rect.setHeight(rect.height()/2); |
|
334 | rect.setHeight(rect.height()/2); | |
333 | rect.moveCenter(geometry().center()); |
|
335 | rect.moveCenter(geometry().center()); | |
334 | zoomIn(rect); |
|
336 | zoomIn(rect); | |
335 | } |
|
337 | } | |
336 |
|
338 | |||
337 | void ChartPresenter::zoomIn(const QRectF& rect) |
|
339 | void ChartPresenter::zoomIn(const QRectF& rect) | |
338 | { |
|
340 | { | |
339 | QRectF r = rect.normalized(); |
|
341 | QRectF r = rect.normalized(); | |
340 | r.translate(-m_marginSize, -m_marginSize); |
|
342 | r.translate(-m_marginSize, -m_marginSize); | |
341 | if(m_animator) { |
|
343 | if(m_animator) { | |
342 |
|
344 | |||
343 | QPointF point(r.center().x()/geometry().width(),r.center().y()/geometry().height()); |
|
345 | QPointF point(r.center().x()/geometry().width(),r.center().y()/geometry().height()); | |
344 | m_animator->setState(ChartAnimator::ZoomInState,point); |
|
346 | m_animator->setState(ChartAnimator::ZoomInState,point); | |
345 | } |
|
347 | } | |
346 | m_dataset->zoomInDomain(r,geometry().size()); |
|
348 | m_dataset->zoomInDomain(r,geometry().size()); | |
347 | m_zoomStack<<r; |
|
349 | m_zoomStack<<r; | |
348 | m_zoomIndex++; |
|
350 | m_zoomIndex++; | |
349 | if(m_animator) { |
|
351 | if(m_animator) { | |
350 | m_animator->setState(ChartAnimator::ShowState); |
|
352 | m_animator->setState(ChartAnimator::ShowState); | |
351 | } |
|
353 | } | |
352 | } |
|
354 | } | |
353 |
|
355 | |||
354 | void ChartPresenter::zoomOut() |
|
356 | void ChartPresenter::zoomOut() | |
355 | { |
|
357 | { | |
356 | if(m_zoomIndex==0) return; |
|
358 | if(m_zoomIndex==0) return; | |
357 | if(m_animator) |
|
359 | if(m_animator) | |
358 | { |
|
360 | { | |
359 | m_animator->setState(ChartAnimator::ZoomOutState); |
|
361 | m_animator->setState(ChartAnimator::ZoomOutState); | |
360 | } |
|
362 | } | |
361 | m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size()); |
|
363 | m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size()); | |
362 | m_zoomIndex--; |
|
364 | m_zoomIndex--; | |
363 | m_zoomStack.resize(m_zoomIndex); |
|
365 | m_zoomStack.resize(m_zoomIndex); | |
364 | if(m_animator){ |
|
366 | if(m_animator){ | |
365 | m_animator->setState(ChartAnimator::ShowState); |
|
367 | m_animator->setState(ChartAnimator::ShowState); | |
366 | } |
|
368 | } | |
367 | } |
|
369 | } | |
368 |
|
370 | |||
369 | void ChartPresenter::zoomReset() |
|
371 | void ChartPresenter::zoomReset() | |
370 | { |
|
372 | { | |
371 | m_zoomIndex=0; |
|
373 | m_zoomIndex=0; | |
372 | m_zoomStack.resize(m_zoomIndex); |
|
374 | m_zoomStack.resize(m_zoomIndex); | |
373 | } |
|
375 | } | |
374 |
|
376 | |||
375 | void ChartPresenter::scroll(int dx,int dy) |
|
377 | void ChartPresenter::scroll(int dx,int dy) | |
376 | { |
|
378 | { | |
377 | if(m_animator){ |
|
379 | if(m_animator){ | |
378 | if(dx<0) m_animator->setState(ChartAnimator::ScrollLeftState,QPointF()); |
|
380 | if(dx<0) m_animator->setState(ChartAnimator::ScrollLeftState,QPointF()); | |
379 | if(dx>0) m_animator->setState(ChartAnimator::ScrollRightState,QPointF()); |
|
381 | if(dx>0) m_animator->setState(ChartAnimator::ScrollRightState,QPointF()); | |
380 | if(dy<0) m_animator->setState(ChartAnimator::ScrollUpState,QPointF()); |
|
382 | if(dy<0) m_animator->setState(ChartAnimator::ScrollUpState,QPointF()); | |
381 | if(dy>0) m_animator->setState(ChartAnimator::ScrollDownState,QPointF()); |
|
383 | if(dy>0) m_animator->setState(ChartAnimator::ScrollDownState,QPointF()); | |
382 | } |
|
384 | } | |
383 |
|
385 | |||
384 | m_dataset->scrollDomain(dx,dy,geometry().size()); |
|
386 | m_dataset->scrollDomain(dx,dy,geometry().size()); | |
385 |
|
387 | |||
386 | if(m_animator){ |
|
388 | if(m_animator){ | |
387 | m_animator->setState(ChartAnimator::ShowState); |
|
389 | m_animator->setState(ChartAnimator::ShowState); | |
388 | } |
|
390 | } | |
389 | } |
|
391 | } | |
390 |
|
392 | |||
391 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
|
393 | QChart::AnimationOptions ChartPresenter::animationOptions() const | |
392 | { |
|
394 | { | |
393 | return m_options; |
|
395 | return m_options; | |
394 | } |
|
396 | } | |
395 |
|
397 | |||
396 |
|
398 | |||
397 | #include "moc_chartpresenter_p.cpp" |
|
399 | #include "moc_chartpresenter_p.cpp" | |
398 |
|
400 | |||
399 | QTCOMMERCIALCHART_END_NAMESPACE |
|
401 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,326 +1,305 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 | #include "qchart.h" |
|
2 | #include "qchart.h" | |
3 | #include "qlegend.h" |
|
3 | #include "qlegend.h" | |
4 | #include "qchartaxis.h" |
|
4 | #include "qchartaxis.h" | |
5 | #include <QTime> |
|
5 | #include <QTime> | |
6 |
|
6 | |||
7 | //series |
|
7 | //series | |
8 | #include "qbarset.h" |
|
8 | #include "qbarset.h" | |
9 | #include "qbarseries.h" |
|
9 | #include "qbarseries.h" | |
10 | #include "qstackedbarseries.h" |
|
10 | #include "qstackedbarseries.h" | |
11 | #include "qpercentbarseries.h" |
|
11 | #include "qpercentbarseries.h" | |
12 | #include "qlineseries.h" |
|
12 | #include "qlineseries.h" | |
13 | #include "qareaseries.h" |
|
13 | #include "qareaseries.h" | |
14 | #include "qscatterseries.h" |
|
14 | #include "qscatterseries.h" | |
15 | #include "qpieseries.h" |
|
15 | #include "qpieseries.h" | |
16 | #include "qpieslice.h" |
|
16 | #include "qpieslice.h" | |
17 | #include "qsplineseries.h" |
|
17 | #include "qsplineseries.h" | |
18 |
|
18 | |||
19 | //items |
|
19 | //items | |
20 | #include "axisitem_p.h" |
|
20 | #include "axisitem_p.h" | |
21 | #include "barpresenter_p.h" |
|
21 | #include "barpresenter_p.h" | |
22 | #include "stackedbarpresenter_p.h" |
|
22 | #include "stackedbarpresenter_p.h" | |
23 | #include "percentbarpresenter_p.h" |
|
23 | #include "percentbarpresenter_p.h" | |
24 | #include "linechartitem_p.h" |
|
24 | #include "linechartitem_p.h" | |
25 | #include "areachartitem_p.h" |
|
25 | #include "areachartitem_p.h" | |
26 | #include "scatterchartitem_p.h" |
|
26 | #include "scatterchartitem_p.h" | |
27 | #include "piepresenter_p.h" |
|
27 | #include "piepresenter_p.h" | |
28 | #include "splinechartitem_p.h" |
|
28 | #include "splinechartitem_p.h" | |
29 |
|
29 | |||
30 | //themes |
|
30 | //themes | |
31 | #include "chartthemedefault_p.h" |
|
31 | #include "chartthemedefault_p.h" | |
32 | #include "chartthemevanilla_p.h" |
|
32 | #include "chartthemevanilla_p.h" | |
33 | #include "chartthemeicy_p.h" |
|
33 | #include "chartthemeicy_p.h" | |
34 | #include "chartthemegrayscale_p.h" |
|
34 | #include "chartthemegrayscale_p.h" | |
35 | #include "chartthemescientific_p.h" |
|
35 | #include "chartthemescientific_p.h" | |
36 |
|
36 | |||
37 |
|
37 | |||
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 |
|
39 | |||
40 | ChartTheme::ChartTheme(QChart::ChartTheme id) |
|
40 | ChartTheme::ChartTheme(QChart::ChartTheme id) | |
41 | { |
|
41 | { | |
42 | m_id = id; |
|
42 | m_id = id; | |
43 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
43 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 |
|
46 | |||
47 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) |
|
47 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) | |
48 | { |
|
48 | { | |
49 | switch(theme) { |
|
49 | switch(theme) { | |
50 | case QChart::ChartThemeVanilla: |
|
50 | case QChart::ChartThemeVanilla: | |
51 | return new ChartThemeVanilla(); |
|
51 | return new ChartThemeVanilla(); | |
52 | case QChart::ChartThemeIcy: |
|
52 | case QChart::ChartThemeIcy: | |
53 | return new ChartThemeIcy(); |
|
53 | return new ChartThemeIcy(); | |
54 | case QChart::ChartThemeGrayscale: |
|
54 | case QChart::ChartThemeGrayscale: | |
55 | return new ChartThemeGrayscale(); |
|
55 | return new ChartThemeGrayscale(); | |
56 | case QChart::ChartThemeScientific: |
|
56 | case QChart::ChartThemeScientific: | |
57 | return new ChartThemeScientific(); |
|
57 | return new ChartThemeScientific(); | |
58 | default: |
|
58 | default: | |
59 | return new ChartThemeDefault(); |
|
59 | return new ChartThemeDefault(); | |
60 | } |
|
60 | } | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | void ChartTheme::decorate(QChart* chart) |
|
63 | void ChartTheme::decorate(QChart* chart) | |
64 | { |
|
64 | { | |
65 | chart->setChartBackgroundBrush(m_backgroundGradient); |
|
65 | chart->setChartBackgroundBrush(m_backgroundGradient); | |
66 | chart->setChartTitleFont(m_masterFont); |
|
66 | chart->setChartTitleFont(m_masterFont); | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | void ChartTheme::decorate(QLegend* legend) |
|
69 | void ChartTheme::decorate(QLegend* legend) | |
70 | { |
|
70 | { | |
71 | legend->setBackgroundBrush(m_backgroundGradient); |
|
71 | legend->setBackgroundBrush(m_backgroundGradient); | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 |
void ChartTheme::decorate( |
|
74 | void ChartTheme::decorate(QAreaSeries* series, int index) | |
75 | { |
|
75 | { | |
76 | QPen pen; |
|
76 | QPen pen; | |
77 | QBrush brush; |
|
77 | QBrush brush; | |
78 |
|
78 | |||
79 | if (pen == series->pen()){ |
|
79 | if (pen == series->pen()){ | |
80 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0)); |
|
80 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0)); | |
81 | pen.setWidthF(2); |
|
81 | pen.setWidthF(2); | |
82 | series->setPen(pen); |
|
82 | series->setPen(pen); | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | if (brush == series->brush()) { |
|
85 | if (brush == series->brush()) { | |
86 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
86 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
87 | series->setBrush(brush); |
|
87 | series->setBrush(brush); | |
88 | } |
|
88 | } | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 |
|
91 | |||
92 |
void ChartTheme::decorate( |
|
92 | void ChartTheme::decorate(QLineSeries* series,int index) | |
93 | { |
|
93 | { | |
94 | QPen pen; |
|
94 | QPen pen; | |
95 | if(pen == series->pen()){ |
|
95 | if(pen == series->pen()){ | |
96 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
96 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
97 | pen.setWidthF(2); |
|
97 | pen.setWidthF(2); | |
98 | series->setPen(pen); |
|
98 | series->setPen(pen); | |
99 | } |
|
99 | } | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int index) |
|
102 | void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int index) | |
103 | { |
|
103 | { | |
104 | QList<QBarSet*> sets = series->barSets(); |
|
104 | QList<QBarSet*> sets = series->barSets(); | |
105 | for (int i=0; i<sets.count(); i++) { |
|
105 | for (int i=0; i<sets.count(); i++) { | |
106 | qreal pos = 0.5; |
|
106 | qreal pos = 0.5; | |
107 | if (sets.count() > 1) |
|
107 | if (sets.count() > 1) | |
108 | pos = (qreal) i / (qreal) (sets.count() - 1); |
|
108 | pos = (qreal) i / (qreal) (sets.count() - 1); | |
109 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
109 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
110 | sets.at(i)->setBrush(QBrush(c)); |
|
110 | sets.at(i)->setBrush(QBrush(c)); | |
111 |
|
111 | |||
112 | // Pick label color as far as possible from bar color (within gradient). |
|
112 | // Pick label color as far as possible from bar color (within gradient). | |
113 | // 0.3 is magic number that was picked as value that gave enough contrast with icy theme gradient :) |
|
113 | // 0.3 is magic number that was picked as value that gave enough contrast with icy theme gradient :) | |
114 | // TODO: better picking of label color? |
|
114 | // TODO: better picking of label color? | |
115 | if (pos < 0.3) { |
|
115 | if (pos < 0.3) { | |
116 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); |
|
116 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); | |
117 | } else { |
|
117 | } else { | |
118 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); |
|
118 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); | |
119 | } |
|
119 | } | |
120 | sets.at(i)->setFloatingValuePen(QPen(c)); |
|
120 | sets.at(i)->setFloatingValuePen(QPen(c)); | |
121 | } |
|
121 | } | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 | void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int index) |
|
124 | void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int index) | |
125 | { |
|
125 | { | |
126 | QList<QBarSet*> sets = series->barSets(); |
|
126 | QList<QBarSet*> sets = series->barSets(); | |
127 | for (int i=0; i<sets.count(); i++) { |
|
127 | for (int i=0; i<sets.count(); i++) { | |
128 | qreal pos = 0.5; |
|
128 | qreal pos = 0.5; | |
129 | if (sets.count() > 1) |
|
129 | if (sets.count() > 1) | |
130 | pos = (qreal) i / (qreal) (sets.count() - 1); |
|
130 | pos = (qreal) i / (qreal) (sets.count() - 1); | |
131 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
131 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
132 | sets.at(i)->setBrush(QBrush(c)); |
|
132 | sets.at(i)->setBrush(QBrush(c)); | |
133 |
|
133 | |||
134 | if (pos < 0.3) { |
|
134 | if (pos < 0.3) { | |
135 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); |
|
135 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); | |
136 | } else { |
|
136 | } else { | |
137 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); |
|
137 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); | |
138 | } |
|
138 | } | |
139 | sets.at(i)->setFloatingValuePen(QPen(c)); |
|
139 | sets.at(i)->setFloatingValuePen(QPen(c)); | |
140 | } |
|
140 | } | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int index) |
|
143 | void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int index) | |
144 | { |
|
144 | { | |
145 | QList<QBarSet*> sets = series->barSets(); |
|
145 | QList<QBarSet*> sets = series->barSets(); | |
146 | for (int i=0; i<sets.count(); i++) { |
|
146 | for (int i=0; i<sets.count(); i++) { | |
147 | qreal pos = 0.5; |
|
147 | qreal pos = 0.5; | |
148 | if (sets.count() > 1) |
|
148 | if (sets.count() > 1) | |
149 | pos = (qreal) i / (qreal) (sets.count() - 1); |
|
149 | pos = (qreal) i / (qreal) (sets.count() - 1); | |
150 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
150 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
151 | sets.at(i)->setBrush(QBrush(c)); |
|
151 | sets.at(i)->setBrush(QBrush(c)); | |
152 |
|
152 | |||
153 | if (pos < 0.3) { |
|
153 | if (pos < 0.3) { | |
154 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); |
|
154 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); | |
155 | } else { |
|
155 | } else { | |
156 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); |
|
156 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); | |
157 | } |
|
157 | } | |
158 | sets.at(i)->setFloatingValuePen(QPen(c)); |
|
158 | sets.at(i)->setFloatingValuePen(QPen(c)); | |
159 | } |
|
159 | } | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 |
void ChartTheme::decorate( |
|
162 | void ChartTheme::decorate(QScatterSeries* series, int index) | |
163 | { |
|
163 | { | |
164 | Q_ASSERT(item); |
|
|||
165 | Q_ASSERT(series); |
|
|||
166 |
|
164 | |||
167 | QPen pen; |
|
165 | QPen pen; | |
168 | QBrush brush; |
|
166 | QBrush brush; | |
169 |
|
167 | |||
170 | if (pen == series->pen()) { |
|
168 | if (pen == series->pen()) { | |
171 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0)); |
|
169 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0)); | |
172 | pen.setWidthF(2); |
|
170 | pen.setWidthF(2); | |
173 | series->setPen(pen); |
|
171 | series->setPen(pen); | |
174 | } |
|
172 | } | |
175 |
|
173 | |||
176 | if (brush == series->brush()) { |
|
174 | if (brush == series->brush()) { | |
177 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
175 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
178 | series->setBrush(brush); |
|
176 | series->setBrush(brush); | |
179 | } |
|
177 | } | |
180 | } |
|
178 | } | |
181 |
|
179 | |||
182 | void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int index) |
|
180 | void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int index) | |
183 | { |
|
181 | { | |
184 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
182 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient | |
185 | for (int i(0); i < series->slices().count(); i++) { |
|
183 | for (int i(0); i < series->slices().count(); i++) { | |
186 | qreal pos = (qreal) i / (qreal) series->count(); |
|
184 | qreal pos = (qreal) i / (qreal) series->count(); | |
187 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.1); |
|
185 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.1); | |
188 | series->slices().at(i)->setSlicePen(penColor); |
|
186 | series->slices().at(i)->setSlicePen(penColor); | |
189 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
187 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
190 | series->slices().at(i)->setSliceBrush(brushColor); |
|
188 | series->slices().at(i)->setSliceBrush(brushColor); | |
191 | } |
|
189 | } | |
192 | } |
|
190 | } | |
193 |
|
191 | |||
194 |
void ChartTheme::decorate( |
|
192 | void ChartTheme::decorate(QSplineSeries* series, int index) | |
195 | { |
|
193 | { | |
196 | Q_ASSERT(item); |
|
|||
197 | Q_ASSERT(series); |
|
|||
198 |
|
||||
199 | QPen pen; |
|
194 | QPen pen; | |
200 |
|
195 | |||
201 |
if(pen |
|
196 | if(pen == series->pen()){ | |
202 | item->setLinePen(series->pen()); |
|
|||
203 | }else{ |
|
|||
204 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
197 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
205 |
pen.setWidthF( |
|
198 | pen.setWidthF(2); | |
206 |
|
|
199 | series->setPen(pen); | |
207 | } |
|
200 | } | |
208 |
|
||||
209 | // QColor color = m_seriesColors.at(index % m_seriesColors.size()); |
|
|||
210 | // TODO: define alpha in the theme? or in the series? |
|
|||
211 | //color.setAlpha(120); |
|
|||
212 |
|
||||
213 | // QBrush brush(color, Qt::SolidPattern); |
|
|||
214 | // presenter->m_markerBrush = brush; |
|
|||
215 |
|
||||
216 | // QPen pen(brush, 3); |
|
|||
217 | // pen.setColor(color); |
|
|||
218 | // presenter->m_markerPen = pen; |
|
|||
219 | } |
|
201 | } | |
220 |
|
202 | |||
221 |
void ChartTheme::decorate(QChartAxis* axis, |
|
203 | void ChartTheme::decorate(QChartAxis* axis,bool axisX) | |
222 | { |
|
204 | { | |
223 | Q_ASSERT(axis); |
|
|||
224 | Q_ASSERT(parent); |
|
|||
225 |
|
||||
226 | if (axis->isAxisVisible()) { |
|
205 | if (axis->isAxisVisible()) { | |
227 | axis->setLabelsBrush(m_axisLabelBrush); |
|
206 | axis->setLabelsBrush(m_axisLabelBrush); | |
228 | axis->setLabelsPen(m_axisLabelPen); |
|
207 | axis->setLabelsPen(m_axisLabelPen); | |
229 | // TODO: check the axis type (x or y) should define whether to show the shades or not |
|
208 | // TODO: check the axis type (x or y) should define whether to show the shades or not | |
230 | if (m_backgroundShades == BackgroundShadesBoth |
|
209 | if (m_backgroundShades == BackgroundShadesBoth | |
231 |
|| (m_backgroundShades == BackgroundShadesVertical && |
|
210 | || (m_backgroundShades == BackgroundShadesVertical && axisX) | |
232 |
|| (m_backgroundShades == BackgroundShadesHorizontal && |
|
211 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX)) { | |
233 | axis->setShadesPen(m_backgroundShadesPen); |
|
212 | axis->setShadesPen(m_backgroundShadesPen); | |
234 | axis->setShadesBrush(m_backgroundShadesBrush); |
|
213 | axis->setShadesBrush(m_backgroundShadesBrush); | |
235 | } else { |
|
214 | } else { | |
236 | // The shades not supposed to be shown for this axis, clear possible brush and pen |
|
215 | // The shades not supposed to be shown for this axis, clear possible brush and pen | |
237 | axis->setShadesPen(Qt::NoPen); |
|
216 | axis->setShadesPen(Qt::NoPen); | |
238 | axis->setShadesBrush(Qt::NoBrush); |
|
217 | axis->setShadesBrush(Qt::NoBrush); | |
239 | } |
|
218 | } | |
240 | axis->setAxisPen(m_axisLinePen); |
|
219 | axis->setAxisPen(m_axisLinePen); | |
241 | axis->setGridLinePen(m_gridLinePen); |
|
220 | axis->setGridLinePen(m_gridLinePen); | |
242 | axis->setLabelsFont(m_masterFont); |
|
221 | axis->setLabelsFont(m_masterFont); | |
243 | } |
|
222 | } | |
244 | } |
|
223 | } | |
245 |
|
224 | |||
246 | void ChartTheme::generateSeriesGradients() |
|
225 | void ChartTheme::generateSeriesGradients() | |
247 | { |
|
226 | { | |
248 | // Generate gradients in HSV color space |
|
227 | // Generate gradients in HSV color space | |
249 | foreach (QColor color, m_seriesColors) { |
|
228 | foreach (QColor color, m_seriesColors) { | |
250 | QLinearGradient g; |
|
229 | QLinearGradient g; | |
251 | qreal h = color.hsvHueF(); |
|
230 | qreal h = color.hsvHueF(); | |
252 | qreal s = color.hsvSaturationF(); |
|
231 | qreal s = color.hsvSaturationF(); | |
253 |
|
232 | |||
254 | // TODO: tune the algorithm to give nice results with most base colors defined in |
|
233 | // TODO: tune the algorithm to give nice results with most base colors defined in | |
255 | // most themes. The rest of the gradients we can define manually in theme specific |
|
234 | // most themes. The rest of the gradients we can define manually in theme specific | |
256 | // implementation. |
|
235 | // implementation. | |
257 | QColor start = color; |
|
236 | QColor start = color; | |
258 | start.setHsvF(h, 0.05, 0.95); |
|
237 | start.setHsvF(h, 0.05, 0.95); | |
259 | g.setColorAt(0.0, start); |
|
238 | g.setColorAt(0.0, start); | |
260 |
|
239 | |||
261 | g.setColorAt(0.5, color); |
|
240 | g.setColorAt(0.5, color); | |
262 |
|
241 | |||
263 | QColor end = color; |
|
242 | QColor end = color; | |
264 | end.setHsvF(h, s, 0.25); |
|
243 | end.setHsvF(h, s, 0.25); | |
265 | g.setColorAt(1.0, end); |
|
244 | g.setColorAt(1.0, end); | |
266 |
|
245 | |||
267 | m_seriesGradients << g; |
|
246 | m_seriesGradients << g; | |
268 | } |
|
247 | } | |
269 | } |
|
248 | } | |
270 |
|
249 | |||
271 |
|
250 | |||
272 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) |
|
251 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) | |
273 | { |
|
252 | { | |
274 | Q_ASSERT(pos >=0.0 && pos <= 1.0); |
|
253 | Q_ASSERT(pos >=0.0 && pos <= 1.0); | |
275 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); |
|
254 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); | |
276 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); |
|
255 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); | |
277 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); |
|
256 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); | |
278 | QColor c; |
|
257 | QColor c; | |
279 | c.setRgbF(r, g, b); |
|
258 | c.setRgbF(r, g, b); | |
280 | return c; |
|
259 | return c; | |
281 | } |
|
260 | } | |
282 |
|
261 | |||
283 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) |
|
262 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) | |
284 | { |
|
263 | { | |
285 | Q_ASSERT(pos >=0 && pos <= 1.0); |
|
264 | Q_ASSERT(pos >=0 && pos <= 1.0); | |
286 |
|
265 | |||
287 | // another possibility: |
|
266 | // another possibility: | |
288 | // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient |
|
267 | // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient | |
289 |
|
268 | |||
290 | QGradientStops stops = gradient.stops(); |
|
269 | QGradientStops stops = gradient.stops(); | |
291 | int count = stops.count(); |
|
270 | int count = stops.count(); | |
292 |
|
271 | |||
293 | // find previous stop relative to position |
|
272 | // find previous stop relative to position | |
294 | QGradientStop prev = stops.first(); |
|
273 | QGradientStop prev = stops.first(); | |
295 | for (int i=0; i<count; i++) { |
|
274 | for (int i=0; i<count; i++) { | |
296 | QGradientStop stop = stops.at(i); |
|
275 | QGradientStop stop = stops.at(i); | |
297 | if (pos > stop.first) |
|
276 | if (pos > stop.first) | |
298 | prev = stop; |
|
277 | prev = stop; | |
299 |
|
278 | |||
300 | // given position is actually a stop position? |
|
279 | // given position is actually a stop position? | |
301 | if (pos == stop.first) { |
|
280 | if (pos == stop.first) { | |
302 | //qDebug() << "stop color" << pos; |
|
281 | //qDebug() << "stop color" << pos; | |
303 | return stop.second; |
|
282 | return stop.second; | |
304 | } |
|
283 | } | |
305 | } |
|
284 | } | |
306 |
|
285 | |||
307 | // find next stop relative to position |
|
286 | // find next stop relative to position | |
308 | QGradientStop next = stops.last(); |
|
287 | QGradientStop next = stops.last(); | |
309 | for (int i=count-1; i>=0; i--) { |
|
288 | for (int i=count-1; i>=0; i--) { | |
310 | QGradientStop stop = stops.at(i); |
|
289 | QGradientStop stop = stops.at(i); | |
311 | if (pos < stop.first) |
|
290 | if (pos < stop.first) | |
312 | next = stop; |
|
291 | next = stop; | |
313 | } |
|
292 | } | |
314 |
|
293 | |||
315 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; |
|
294 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; | |
316 |
|
295 | |||
317 | qreal range = next.first - prev.first; |
|
296 | qreal range = next.first - prev.first; | |
318 | qreal posDelta = pos - prev.first; |
|
297 | qreal posDelta = pos - prev.first; | |
319 | qreal relativePos = posDelta / range; |
|
298 | qreal relativePos = posDelta / range; | |
320 |
|
299 | |||
321 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; |
|
300 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; | |
322 |
|
301 | |||
323 | return colorAt(prev.second, next.second, relativePos); |
|
302 | return colorAt(prev.second, next.second, relativePos); | |
324 | } |
|
303 | } | |
325 |
|
304 | |||
326 | QTCOMMERCIALCHART_END_NAMESPACE |
|
305 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,81 +1,81 | |||||
1 | #ifndef CHARTTHEME_H |
|
1 | #ifndef CHARTTHEME_H | |
2 | #define CHARTTHEME_H |
|
2 | #define CHARTTHEME_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "qchart.h" |
|
5 | #include "qchart.h" | |
6 | #include <QColor> |
|
6 | #include <QColor> | |
7 | #include <QGradientStops> |
|
7 | #include <QGradientStops> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | class ChartItem; |
|
11 | class ChartItem; | |
12 | class QSeries; |
|
12 | class QSeries; | |
13 | class LineChartItem; |
|
13 | class LineChartItem; | |
14 | class QLineSeries; |
|
14 | class QLineSeries; | |
15 | class BarPresenter; |
|
15 | class BarPresenter; | |
16 | class QBarSeries; |
|
16 | class QBarSeries; | |
17 | class StackedBarPresenter; |
|
17 | class StackedBarPresenter; | |
18 | class QStackedBarSeries; |
|
18 | class QStackedBarSeries; | |
19 | class QPercentBarSeries; |
|
19 | class QPercentBarSeries; | |
20 | class PercentBarPresenter; |
|
20 | class PercentBarPresenter; | |
21 | class QScatterSeries; |
|
21 | class QScatterSeries; | |
22 | class ScatterChartItem; |
|
22 | class ScatterChartItem; | |
23 | class PiePresenter; |
|
23 | class PiePresenter; | |
24 | class QPieSeries; |
|
24 | class QPieSeries; | |
25 | class SplineChartItem; |
|
25 | class SplineChartItem; | |
26 | class QSplineSeries; |
|
26 | class QSplineSeries; | |
27 | class AreaChartItem; |
|
27 | class AreaChartItem; | |
28 | class QAreaSeries; |
|
28 | class QAreaSeries; | |
29 |
|
29 | |||
30 | class ChartTheme |
|
30 | class ChartTheme | |
31 | { |
|
31 | { | |
32 | public: |
|
32 | public: | |
33 | enum BackgroundShadesMode { |
|
33 | enum BackgroundShadesMode { | |
34 | BackgroundShadesNone = 0, |
|
34 | BackgroundShadesNone = 0, | |
35 | BackgroundShadesVertical, |
|
35 | BackgroundShadesVertical, | |
36 | BackgroundShadesHorizontal, |
|
36 | BackgroundShadesHorizontal, | |
37 | BackgroundShadesBoth |
|
37 | BackgroundShadesBoth | |
38 | }; |
|
38 | }; | |
39 |
|
39 | |||
40 | protected: |
|
40 | protected: | |
41 | explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeDefault); |
|
41 | explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeDefault); | |
42 | public: |
|
42 | public: | |
43 | static ChartTheme* createTheme(QChart::ChartTheme theme); |
|
43 | static ChartTheme* createTheme(QChart::ChartTheme theme); | |
44 | QChart::ChartTheme id() const {return m_id;} |
|
44 | QChart::ChartTheme id() const {return m_id;} | |
45 | void decorate(QChart* chart); |
|
45 | void decorate(QChart* chart); | |
46 | void decorate(QLegend* legend); |
|
46 | void decorate(QLegend* legend); | |
47 | //void decorate(ChartItem* item, QSeries* series,int index); |
|
47 | //void decorate(ChartItem* item, QSeries* series,int index); | |
48 | void decorate(BarPresenter* item, QBarSeries* series, int index); |
|
48 | void decorate(BarPresenter* item, QBarSeries* series, int index); | |
49 | void decorate(StackedBarPresenter* item, QStackedBarSeries* series, int index); |
|
49 | void decorate(StackedBarPresenter* item, QStackedBarSeries* series, int index); | |
50 | void decorate(PercentBarPresenter* item, QPercentBarSeries* series, int index); |
|
50 | void decorate(PercentBarPresenter* item, QPercentBarSeries* series, int index); | |
51 |
void decorate( |
|
51 | void decorate(QLineSeries* series, int index); | |
52 |
void decorate( |
|
52 | void decorate(QAreaSeries* series, int index); | |
53 |
void decorate( |
|
53 | void decorate(QScatterSeries* series, int index); | |
54 | void decorate(PiePresenter* item, QPieSeries* series, int index); |
|
54 | void decorate(PiePresenter* item, QPieSeries* series, int index); | |
55 |
void decorate( |
|
55 | void decorate(QSplineSeries* series, int index); | |
56 |
void decorate(QChartAxis* axis, |
|
56 | void decorate(QChartAxis* axis, bool axisX); | |
57 |
|
57 | |||
58 | public: // utils |
|
58 | public: // utils | |
59 | void generateSeriesGradients(); |
|
59 | void generateSeriesGradients(); | |
60 | static QColor colorAt(const QColor &start, const QColor &end, qreal pos); |
|
60 | static QColor colorAt(const QColor &start, const QColor &end, qreal pos); | |
61 | static QColor colorAt(const QGradient &gradient, qreal pos); |
|
61 | static QColor colorAt(const QGradient &gradient, qreal pos); | |
62 |
|
62 | |||
63 | protected: |
|
63 | protected: | |
64 | QChart::ChartTheme m_id; |
|
64 | QChart::ChartTheme m_id; | |
65 | QList<QColor> m_seriesColors; |
|
65 | QList<QColor> m_seriesColors; | |
66 | QList<QGradient> m_seriesGradients; |
|
66 | QList<QGradient> m_seriesGradients; | |
67 | QLinearGradient m_backgroundGradient; |
|
67 | QLinearGradient m_backgroundGradient; | |
68 |
|
68 | |||
69 | QFont m_masterFont; |
|
69 | QFont m_masterFont; | |
70 | QPen m_axisLinePen; |
|
70 | QPen m_axisLinePen; | |
71 | QBrush m_axisLabelBrush; |
|
71 | QBrush m_axisLabelBrush; | |
72 | QPen m_axisLabelPen; |
|
72 | QPen m_axisLabelPen; | |
73 | QPen m_backgroundShadesPen; |
|
73 | QPen m_backgroundShadesPen; | |
74 | QBrush m_backgroundShadesBrush; |
|
74 | QBrush m_backgroundShadesBrush; | |
75 | BackgroundShadesMode m_backgroundShades; |
|
75 | BackgroundShadesMode m_backgroundShades; | |
76 | QPen m_gridLinePen; |
|
76 | QPen m_gridLinePen; | |
77 | }; |
|
77 | }; | |
78 |
|
78 | |||
79 | QTCOMMERCIALCHART_END_NAMESPACE |
|
79 | QTCOMMERCIALCHART_END_NAMESPACE | |
80 |
|
80 | |||
81 | #endif // CHARTTHEME_H |
|
81 | #endif // CHARTTHEME_H |
@@ -1,106 +1,101 | |||||
1 | #include "splinechartitem_p.h" |
|
1 | #include "splinechartitem_p.h" | |
2 | #include "chartpresenter_p.h" |
|
2 | #include "chartpresenter_p.h" | |
3 | #include <QPainter> |
|
3 | #include <QPainter> | |
4 |
|
4 | |||
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
6 |
|
6 | |||
7 | SplineChartItem::SplineChartItem(QSplineSeries* series, QGraphicsItem *parent) : |
|
7 | SplineChartItem::SplineChartItem(QSplineSeries* series, QGraphicsItem *parent) : | |
8 | XYChartItem(series, parent), |
|
8 | XYChartItem(series, parent), | |
9 | m_series(series) |
|
9 | m_series(series) | |
10 | { |
|
10 | { | |
11 | setZValue(ChartPresenter::LineChartZValue); |
|
11 | setZValue(ChartPresenter::LineChartZValue); | |
12 | QObject::connect(series,SIGNAL(updated()),this,SLOT(handleUpdated())); |
|
12 | QObject::connect(series,SIGNAL(updated()),this,SLOT(handleUpdated())); | |
13 | handleUpdated(); |
|
13 | handleUpdated(); | |
14 | } |
|
14 | } | |
15 |
|
15 | |||
16 | QRectF SplineChartItem::boundingRect() const |
|
16 | QRectF SplineChartItem::boundingRect() const | |
17 | { |
|
17 | { | |
18 | return m_rect; |
|
18 | return m_rect; | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
21 | QPainterPath SplineChartItem::shape() const |
|
21 | QPainterPath SplineChartItem::shape() const | |
22 | { |
|
22 | { | |
23 | return m_path; |
|
23 | return m_path; | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | QPointF SplineChartItem::calculateGeometryControlPoint(int index) const |
|
26 | QPointF SplineChartItem::calculateGeometryControlPoint(int index) const | |
27 | { |
|
27 | { | |
28 | return XYChartItem::calculateGeometryPoint(m_series->controlPoint(index)); |
|
28 | return XYChartItem::calculateGeometryPoint(m_series->controlPoint(index)); | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 | void SplineChartItem::setLayout(QVector<QPointF>& points) |
|
31 | void SplineChartItem::setLayout(QVector<QPointF>& points) | |
32 | { |
|
32 | { | |
33 |
|
33 | |||
34 | if(points.size()==0) |
|
34 | if(points.size()==0) | |
35 | { |
|
35 | { | |
36 | XYChartItem::setLayout(points); |
|
36 | XYChartItem::setLayout(points); | |
37 | return; |
|
37 | return; | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | QPainterPath splinePath; |
|
40 | QPainterPath splinePath; | |
41 | const QPointF& point = points.at(0); |
|
41 | const QPointF& point = points.at(0); | |
42 | splinePath.moveTo(point); |
|
42 | splinePath.moveTo(point); | |
43 |
|
43 | |||
44 | for (int i = 0; i < points.size() - 1; i++) |
|
44 | for (int i = 0; i < points.size() - 1; i++) | |
45 | { |
|
45 | { | |
46 | const QPointF& point = points.at(i + 1); |
|
46 | const QPointF& point = points.at(i + 1); | |
47 | splinePath.cubicTo(calculateGeometryControlPoint(2 * i), calculateGeometryControlPoint(2 * i + 1), point); |
|
47 | splinePath.cubicTo(calculateGeometryControlPoint(2 * i), calculateGeometryControlPoint(2 * i + 1), point); | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | prepareGeometryChange(); |
|
50 | prepareGeometryChange(); | |
51 | m_path = splinePath; |
|
51 | m_path = splinePath; | |
52 | m_rect = splinePath.boundingRect(); |
|
52 | m_rect = splinePath.boundingRect(); | |
53 | XYChartItem::setLayout(points); |
|
53 | XYChartItem::setLayout(points); | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | void SplineChartItem::setLinePen(const QPen& pen) |
|
|||
57 | { |
|
|||
58 | m_pen = pen; |
|
|||
59 | } |
|
|||
60 |
|
||||
61 | //handlers |
|
56 | //handlers | |
62 |
|
57 | |||
63 | void SplineChartItem::handleUpdated() |
|
58 | void SplineChartItem::handleUpdated() | |
64 | { |
|
59 | { | |
65 | //m_items.setVisible(m_series->pointsVisible()); |
|
60 | //m_items.setVisible(m_series->pointsVisible()); | |
66 |
|
|
61 | m_pen = m_series->pen(); | |
67 | update(); |
|
62 | update(); | |
68 | } |
|
63 | } | |
69 |
|
64 | |||
70 | //painter |
|
65 | //painter | |
71 |
|
66 | |||
72 | void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
67 | void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
73 | { |
|
68 | { | |
74 | Q_UNUSED(widget); |
|
69 | Q_UNUSED(widget); | |
75 | Q_UNUSED(option); |
|
70 | Q_UNUSED(option); | |
76 | painter->save(); |
|
71 | painter->save(); | |
77 | painter->setClipRect(clipRect()); |
|
72 | painter->setClipRect(clipRect()); | |
78 | painter->setPen(m_pen); |
|
73 | painter->setPen(m_pen); | |
79 | painter->drawPath(m_path); |
|
74 | painter->drawPath(m_path); | |
80 |
|
75 | |||
81 | const QVector<QPointF> points = XYChartItem::points(); |
|
76 | const QVector<QPointF> points = XYChartItem::points(); | |
82 |
|
77 | |||
83 | for (int i = 0; i < points.size() - 1; i++) |
|
78 | for (int i = 0; i < points.size() - 1; i++) | |
84 | { |
|
79 | { | |
85 | painter->setPen(Qt::red); |
|
80 | painter->setPen(Qt::red); | |
86 | painter->drawEllipse(points[i], 2, 2); |
|
81 | painter->drawEllipse(points[i], 2, 2); | |
87 |
|
82 | |||
88 | painter->setPen(Qt::blue); |
|
83 | painter->setPen(Qt::blue); | |
89 | // painter->drawLine(m_series->at(i), m_series->controlPoint(2 * i)); |
|
84 | // painter->drawLine(m_series->at(i), m_series->controlPoint(2 * i)); | |
90 | // painter->drawLine(m_series->at(i + 1), m_series->controlPoint(2 * i + 1)); |
|
85 | // painter->drawLine(m_series->at(i + 1), m_series->controlPoint(2 * i + 1)); | |
91 | // painter->drawEllipse(calculateGeometryControlPoint(2 * i), 4, 4); |
|
86 | // painter->drawEllipse(calculateGeometryControlPoint(2 * i), 4, 4); | |
92 | // painter->drawEllipse(calculateGeometryControlPoint(2 * i + 1), 4, 4); |
|
87 | // painter->drawEllipse(calculateGeometryControlPoint(2 * i + 1), 4, 4); | |
93 | } |
|
88 | } | |
94 | if (points.count() > 0) |
|
89 | if (points.count() > 0) | |
95 | { |
|
90 | { | |
96 | painter->setPen(Qt::red); |
|
91 | painter->setPen(Qt::red); | |
97 | painter->drawEllipse(points[points.count() - 1], 2, 2); |
|
92 | painter->drawEllipse(points[points.count() - 1], 2, 2); | |
98 | } |
|
93 | } | |
99 | painter->restore(); |
|
94 | painter->restore(); | |
100 | } |
|
95 | } | |
101 |
|
96 | |||
102 |
|
97 | |||
103 |
|
98 | |||
104 | #include "moc_splinechartitem_p.cpp" |
|
99 | #include "moc_splinechartitem_p.cpp" | |
105 |
|
100 | |||
106 | QTCOMMERCIALCHART_END_NAMESPACE |
|
101 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,43 +1,42 | |||||
1 | #ifndef SPLINECHARTITEM_P_H |
|
1 | #ifndef SPLINECHARTITEM_P_H | |
2 | #define SPLINECHARTITEM_P_H |
|
2 | #define SPLINECHARTITEM_P_H | |
3 |
|
3 | |||
4 | #include "qsplineseries.h" |
|
4 | #include "qsplineseries.h" | |
5 | #include "xychartitem_p.h" |
|
5 | #include "xychartitem_p.h" | |
6 | #include <QGraphicsItem> |
|
6 | #include <QGraphicsItem> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class SplineChartItem : public XYChartItem |
|
10 | class SplineChartItem : public XYChartItem | |
11 | { |
|
11 | { | |
12 | Q_OBJECT |
|
12 | Q_OBJECT | |
13 | public: |
|
13 | public: | |
14 | SplineChartItem(QSplineSeries* series, QGraphicsItem *parent = 0); |
|
14 | SplineChartItem(QSplineSeries* series, QGraphicsItem *parent = 0); | |
15 |
|
15 | |||
16 | //from QGraphicsItem |
|
16 | //from QGraphicsItem | |
17 | QRectF boundingRect() const; |
|
17 | QRectF boundingRect() const; | |
18 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
18 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
19 | QPainterPath shape() const; |
|
19 | QPainterPath shape() const; | |
20 |
|
20 | |||
21 | void setLinePen(const QPen& pen); |
|
|||
22 | void setPointsVisible(bool visible); |
|
21 | void setPointsVisible(bool visible); | |
23 |
|
22 | |||
24 | public slots: |
|
23 | public slots: | |
25 | void handleUpdated(); |
|
24 | void handleUpdated(); | |
26 |
|
25 | |||
27 | protected: |
|
26 | protected: | |
28 | void setLayout(QVector<QPointF>& points); |
|
27 | void setLayout(QVector<QPointF>& points); | |
29 |
|
28 | |||
30 | private: |
|
29 | private: | |
31 | QPointF calculateGeometryControlPoint(int index) const; |
|
30 | QPointF calculateGeometryControlPoint(int index) const; | |
32 |
|
31 | |||
33 | private: |
|
32 | private: | |
34 | QSplineSeries* m_series; |
|
33 | QSplineSeries* m_series; | |
35 | QPainterPath m_path; |
|
34 | QPainterPath m_path; | |
36 | QRectF m_rect; |
|
35 | QRectF m_rect; | |
37 | QPen m_pen; |
|
36 | QPen m_pen; | |
38 |
|
37 | |||
39 | }; |
|
38 | }; | |
40 |
|
39 | |||
41 | QTCOMMERCIALCHART_END_NAMESPACE |
|
40 | QTCOMMERCIALCHART_END_NAMESPACE | |
42 |
|
41 | |||
43 | #endif // SPLINECHARTITEM_P_H |
|
42 | #endif // SPLINECHARTITEM_P_H |
General Comments 0
You need to be logged in to leave comments.
Login now