@@ -1,400 +1,399 | |||||
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 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); |
|
108 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); | |
109 | //initialize |
|
109 | //initialize | |
110 | item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount()); |
|
110 | item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount()); | |
111 | } |
|
111 | } | |
112 | else{ |
|
112 | else{ | |
113 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); |
|
113 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); | |
114 | //initialize |
|
114 | //initialize | |
115 | item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount()); |
|
115 | item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount()); | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
118 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
119 | //initialize |
|
119 | //initialize | |
120 | item->handleGeometryChanged(m_rect); |
|
120 | item->handleGeometryChanged(m_rect); | |
121 |
m_chartTheme->decorate(axis, |
|
121 | m_chartTheme->decorate(axis, m_chart); | |
122 | m_axisItems.insert(axis,item); |
|
122 | m_axisItems.insert(axis, item); | |
123 |
|
||||
124 | } |
|
123 | } | |
125 |
|
124 | |||
126 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) |
|
125 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) | |
127 | { |
|
126 | { | |
128 | AxisItem* item = m_axisItems.take(axis); |
|
127 | AxisItem* item = m_axisItems.take(axis); | |
129 | Q_ASSERT(item); |
|
128 | Q_ASSERT(item); | |
130 | if(m_animator) m_animator->removeAnimation(item); |
|
129 | if(m_animator) m_animator->removeAnimation(item); | |
131 | delete item; |
|
130 | delete item; | |
132 | } |
|
131 | } | |
133 |
|
132 | |||
134 |
|
133 | |||
135 | void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) |
|
134 | void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |
136 | { |
|
135 | { | |
137 | ChartItem *item = 0 ; |
|
136 | ChartItem *item = 0 ; | |
138 |
|
137 | |||
139 | switch(series->type()) |
|
138 | switch(series->type()) | |
140 | { |
|
139 | { | |
141 | case QSeries::SeriesTypeLine: { |
|
140 | case QSeries::SeriesTypeLine: { | |
142 |
|
141 | |||
143 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); |
|
142 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); | |
144 | LineChartItem* line = new LineChartItem(lineSeries,m_chart); |
|
143 | LineChartItem* line = new LineChartItem(lineSeries,m_chart); | |
145 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
144 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
146 | m_animator->addAnimation(line); |
|
145 | m_animator->addAnimation(line); | |
147 | } |
|
146 | } | |
148 | m_chartTheme->decorate(line, lineSeries, m_dataset->seriesIndex(series)); |
|
147 | m_chartTheme->decorate(line, lineSeries, m_dataset->seriesIndex(series)); | |
149 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),line,SLOT(handleGeometryChanged(const QRectF&))); |
|
148 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),line,SLOT(handleGeometryChanged(const QRectF&))); | |
150 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),line,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
149 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),line,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
151 | item = line; |
|
150 | item = line; | |
152 | break; |
|
151 | break; | |
153 | } |
|
152 | } | |
154 |
|
153 | |||
155 | case QSeries::SeriesTypeArea: { |
|
154 | case QSeries::SeriesTypeArea: { | |
156 |
|
155 | |||
157 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); |
|
156 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); | |
158 | AreaChartItem* area = new AreaChartItem(areaSeries,m_chart); |
|
157 | AreaChartItem* area = new AreaChartItem(areaSeries,m_chart); | |
159 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
158 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
160 | m_animator->addAnimation(area->upperLineItem()); |
|
159 | m_animator->addAnimation(area->upperLineItem()); | |
161 | if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem()); |
|
160 | if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem()); | |
162 | } |
|
161 | } | |
163 | m_chartTheme->decorate(area, areaSeries, m_dataset->seriesIndex(series)); |
|
162 | m_chartTheme->decorate(area, areaSeries, m_dataset->seriesIndex(series)); | |
164 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&))); |
|
163 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&))); | |
165 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),area,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
164 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),area,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
166 | item=area; |
|
165 | item=area; | |
167 | break; |
|
166 | break; | |
168 | } |
|
167 | } | |
169 |
|
168 | |||
170 | case QSeries::SeriesTypeBar: { |
|
169 | case QSeries::SeriesTypeBar: { | |
171 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
170 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); | |
172 | BarPresenter* bar = new BarPresenter(barSeries,m_chart); |
|
171 | BarPresenter* bar = new BarPresenter(barSeries,m_chart); | |
173 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
172 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
174 | // m_animator->addAnimation(bar); |
|
173 | // m_animator->addAnimation(bar); | |
175 | } |
|
174 | } | |
176 | m_chartTheme->decorate(bar, barSeries, m_dataset->seriesIndex(barSeries)); |
|
175 | m_chartTheme->decorate(bar, barSeries, m_dataset->seriesIndex(barSeries)); | |
177 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
|
176 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); | |
178 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
177 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
179 | item=bar; |
|
178 | item=bar; | |
180 | break; |
|
179 | break; | |
181 | } |
|
180 | } | |
182 |
|
181 | |||
183 | case QSeries::SeriesTypeStackedBar: { |
|
182 | case QSeries::SeriesTypeStackedBar: { | |
184 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
183 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); | |
185 | StackedBarPresenter* bar = new StackedBarPresenter(stackedBarSeries,m_chart); |
|
184 | StackedBarPresenter* bar = new StackedBarPresenter(stackedBarSeries,m_chart); | |
186 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
185 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
187 | // m_animator->addAnimation(bar); |
|
186 | // m_animator->addAnimation(bar); | |
188 | } |
|
187 | } | |
189 | m_chartTheme->decorate(bar, stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries)); |
|
188 | m_chartTheme->decorate(bar, stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries)); | |
190 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
|
189 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); | |
191 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
190 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
192 | item=bar; |
|
191 | item=bar; | |
193 | break; |
|
192 | break; | |
194 | } |
|
193 | } | |
195 |
|
194 | |||
196 | case QSeries::SeriesTypePercentBar: { |
|
195 | case QSeries::SeriesTypePercentBar: { | |
197 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
196 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); | |
198 | PercentBarPresenter* bar = new PercentBarPresenter(percentBarSeries,m_chart); |
|
197 | PercentBarPresenter* bar = new PercentBarPresenter(percentBarSeries,m_chart); | |
199 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
198 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
200 | // m_animator->addAnimation(bar); |
|
199 | // m_animator->addAnimation(bar); | |
201 | } |
|
200 | } | |
202 | m_chartTheme->decorate(bar, percentBarSeries, m_dataset->seriesIndex(percentBarSeries)); |
|
201 | m_chartTheme->decorate(bar, percentBarSeries, m_dataset->seriesIndex(percentBarSeries)); | |
203 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
|
202 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); | |
204 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
203 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
205 | item=bar; |
|
204 | item=bar; | |
206 | break; |
|
205 | break; | |
207 | } |
|
206 | } | |
208 |
|
207 | |||
209 | case QSeries::SeriesTypeScatter: { |
|
208 | case QSeries::SeriesTypeScatter: { | |
210 | QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series); |
|
209 | QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series); | |
211 | ScatterChartItem *scatter = new ScatterChartItem(scatterSeries, m_chart); |
|
210 | ScatterChartItem *scatter = new ScatterChartItem(scatterSeries, m_chart); | |
212 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
211 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
213 | m_animator->addAnimation(scatter); |
|
212 | m_animator->addAnimation(scatter); | |
214 | } |
|
213 | } | |
215 | m_chartTheme->decorate(scatter, scatterSeries, m_dataset->seriesIndex(series)); |
|
214 | m_chartTheme->decorate(scatter, scatterSeries, m_dataset->seriesIndex(series)); | |
216 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),scatter,SLOT(handleGeometryChanged(const QRectF&))); |
|
215 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),scatter,SLOT(handleGeometryChanged(const QRectF&))); | |
217 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),scatter,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
216 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),scatter,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
218 | item = scatter; |
|
217 | item = scatter; | |
219 | break; |
|
218 | break; | |
220 | } |
|
219 | } | |
221 |
|
220 | |||
222 | case QSeries::SeriesTypePie: { |
|
221 | case QSeries::SeriesTypePie: { | |
223 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
222 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
224 | PiePresenter* pie = new PiePresenter(m_chart, pieSeries); |
|
223 | PiePresenter* pie = new PiePresenter(m_chart, pieSeries); | |
225 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
224 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
226 | // m_animator->addAnimation(pie); |
|
225 | // m_animator->addAnimation(pie); | |
227 | } |
|
226 | } | |
228 | m_chartTheme->decorate(pie, pieSeries, m_dataset->seriesIndex(series)); |
|
227 | m_chartTheme->decorate(pie, pieSeries, m_dataset->seriesIndex(series)); | |
229 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),pie,SLOT(handleGeometryChanged(const QRectF&))); |
|
228 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),pie,SLOT(handleGeometryChanged(const QRectF&))); | |
230 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),pie,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
229 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),pie,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
231 | // Hide all from background when there is only piechart |
|
230 | // Hide all from background when there is only piechart | |
232 | // TODO: refactor this ugly code... should be one setting for this |
|
231 | // TODO: refactor this ugly code... should be one setting for this | |
233 | if (m_chartItems.count() == 0) { |
|
232 | if (m_chartItems.count() == 0) { | |
234 | m_chart->axisX()->hide(); |
|
233 | m_chart->axisX()->hide(); | |
235 | m_chart->axisY()->hide(); |
|
234 | m_chart->axisY()->hide(); | |
236 | m_chart->setChartBackgroundBrush(Qt::transparent); |
|
235 | m_chart->setChartBackgroundBrush(Qt::transparent); | |
237 | } |
|
236 | } | |
238 | item=pie; |
|
237 | item=pie; | |
239 | break; |
|
238 | break; | |
240 | } |
|
239 | } | |
241 |
|
240 | |||
242 | case QSeries::SeriesTypeSpline: { |
|
241 | case QSeries::SeriesTypeSpline: { | |
243 | QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series); |
|
242 | QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series); | |
244 | SplineChartItem* spline = new SplineChartItem(splineSeries, m_chart); |
|
243 | SplineChartItem* spline = new SplineChartItem(splineSeries, m_chart); | |
245 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
244 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
246 | m_animator->addAnimation(spline); |
|
245 | m_animator->addAnimation(spline); | |
247 | } |
|
246 | } | |
248 | m_chartTheme->decorate(spline, splineSeries, m_dataset->seriesIndex(series)); |
|
247 | m_chartTheme->decorate(spline, splineSeries, m_dataset->seriesIndex(series)); | |
249 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),spline,SLOT(handleGeometryChanged(const QRectF&))); |
|
248 | 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))); |
|
249 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),spline,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
251 | item=spline; |
|
250 | item=spline; | |
252 | break; |
|
251 | break; | |
253 | } |
|
252 | } | |
254 | default: { |
|
253 | default: { | |
255 | qDebug()<< "Series type" << series->type() << "not implemented."; |
|
254 | qDebug()<< "Series type" << series->type() << "not implemented."; | |
256 | break; |
|
255 | break; | |
257 | } |
|
256 | } | |
258 | } |
|
257 | } | |
259 |
|
258 | |||
260 | //initialize |
|
259 | //initialize | |
261 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); |
|
260 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); | |
262 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
261 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
263 | m_chartItems.insert(series,item); |
|
262 | m_chartItems.insert(series,item); | |
264 | zoomReset(); |
|
263 | zoomReset(); | |
265 | } |
|
264 | } | |
266 |
|
265 | |||
267 | void ChartPresenter::handleSeriesRemoved(QSeries* series) |
|
266 | void ChartPresenter::handleSeriesRemoved(QSeries* series) | |
268 | { |
|
267 | { | |
269 | ChartItem* item = m_chartItems.take(series); |
|
268 | ChartItem* item = m_chartItems.take(series); | |
270 | Q_ASSERT(item); |
|
269 | Q_ASSERT(item); | |
271 | if(m_animator) { |
|
270 | if(m_animator) { | |
272 | //small hack to handle area animations |
|
271 | //small hack to handle area animations | |
273 | if(series->type()==QSeries::SeriesTypeArea){ |
|
272 | if(series->type()==QSeries::SeriesTypeArea){ | |
274 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); |
|
273 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); | |
275 | AreaChartItem* area = static_cast<AreaChartItem*>(item); |
|
274 | AreaChartItem* area = static_cast<AreaChartItem*>(item); | |
276 | m_animator->removeAnimation(area->upperLineItem()); |
|
275 | m_animator->removeAnimation(area->upperLineItem()); | |
277 | if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem()); |
|
276 | if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem()); | |
278 | }else |
|
277 | }else | |
279 | m_animator->removeAnimation(item); |
|
278 | m_animator->removeAnimation(item); | |
280 | } |
|
279 | } | |
281 | delete item; |
|
280 | delete item; | |
282 | } |
|
281 | } | |
283 |
|
282 | |||
284 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) |
|
283 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) | |
285 | { |
|
284 | { | |
286 | if(m_chartTheme && m_chartTheme->id() == theme) return; |
|
285 | if(m_chartTheme && m_chartTheme->id() == theme) return; | |
287 | delete m_chartTheme; |
|
286 | delete m_chartTheme; | |
288 | m_chartTheme = ChartTheme::createTheme(theme); |
|
287 | m_chartTheme = ChartTheme::createTheme(theme); | |
289 | m_chartTheme->decorate(m_chart); |
|
288 | m_chartTheme->decorate(m_chart); | |
290 | m_chartTheme->decorate(m_chart->legend()); |
|
289 | m_chartTheme->decorate(m_chart->legend()); | |
291 | resetAllElements(); |
|
290 | resetAllElements(); | |
292 | } |
|
291 | } | |
293 |
|
292 | |||
294 | QChart::ChartTheme ChartPresenter::chartTheme() |
|
293 | QChart::ChartTheme ChartPresenter::chartTheme() | |
295 | { |
|
294 | { | |
296 | return m_chartTheme->id(); |
|
295 | return m_chartTheme->id(); | |
297 | } |
|
296 | } | |
298 |
|
297 | |||
299 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
298 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |
300 | { |
|
299 | { | |
301 | if(m_options!=options) { |
|
300 | if(m_options!=options) { | |
302 |
|
301 | |||
303 | m_options=options; |
|
302 | m_options=options; | |
304 |
|
303 | |||
305 | if(m_options!=QChart::NoAnimation && !m_animator) { |
|
304 | if(m_options!=QChart::NoAnimation && !m_animator) { | |
306 | m_animator= new ChartAnimator(this); |
|
305 | m_animator= new ChartAnimator(this); | |
307 |
|
306 | |||
308 | } |
|
307 | } | |
309 | resetAllElements(); |
|
308 | resetAllElements(); | |
310 | } |
|
309 | } | |
311 |
|
310 | |||
312 | } |
|
311 | } | |
313 |
|
312 | |||
314 | void ChartPresenter::resetAllElements() |
|
313 | void ChartPresenter::resetAllElements() | |
315 | { |
|
314 | { | |
316 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); |
|
315 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); | |
317 | QList<QSeries*> seriesList = m_chartItems.uniqueKeys(); |
|
316 | QList<QSeries*> seriesList = m_chartItems.uniqueKeys(); | |
318 |
|
317 | |||
319 | foreach(QChartAxis* axis, axisList) { |
|
318 | foreach(QChartAxis* axis, axisList) { | |
320 | handleAxisRemoved(axis); |
|
319 | handleAxisRemoved(axis); | |
321 | handleAxisAdded(axis,m_dataset->domain(axis)); |
|
320 | handleAxisAdded(axis,m_dataset->domain(axis)); | |
322 | } |
|
321 | } | |
323 | foreach(QSeries* series, seriesList) { |
|
322 | foreach(QSeries* series, seriesList) { | |
324 | handleSeriesRemoved(series); |
|
323 | handleSeriesRemoved(series); | |
325 | handleSeriesAdded(series,m_dataset->domain(series)); |
|
324 | handleSeriesAdded(series,m_dataset->domain(series)); | |
326 | } |
|
325 | } | |
327 | } |
|
326 | } | |
328 |
|
327 | |||
329 | void ChartPresenter::zoomIn() |
|
328 | void ChartPresenter::zoomIn() | |
330 | { |
|
329 | { | |
331 | QRectF rect = geometry(); |
|
330 | QRectF rect = geometry(); | |
332 | rect.setWidth(rect.width()/2); |
|
331 | rect.setWidth(rect.width()/2); | |
333 | rect.setHeight(rect.height()/2); |
|
332 | rect.setHeight(rect.height()/2); | |
334 | rect.moveCenter(geometry().center()); |
|
333 | rect.moveCenter(geometry().center()); | |
335 | zoomIn(rect); |
|
334 | zoomIn(rect); | |
336 | } |
|
335 | } | |
337 |
|
336 | |||
338 | void ChartPresenter::zoomIn(const QRectF& rect) |
|
337 | void ChartPresenter::zoomIn(const QRectF& rect) | |
339 | { |
|
338 | { | |
340 | QRectF r = rect.normalized(); |
|
339 | QRectF r = rect.normalized(); | |
341 | r.translate(-m_marginSize, -m_marginSize); |
|
340 | r.translate(-m_marginSize, -m_marginSize); | |
342 | if(m_animator) { |
|
341 | if(m_animator) { | |
343 |
|
342 | |||
344 | QPointF point(r.center().x()/geometry().width(),r.center().y()/geometry().height()); |
|
343 | QPointF point(r.center().x()/geometry().width(),r.center().y()/geometry().height()); | |
345 | m_animator->setState(ChartAnimator::ZoomInState,point); |
|
344 | m_animator->setState(ChartAnimator::ZoomInState,point); | |
346 | } |
|
345 | } | |
347 | m_dataset->zoomInDomain(r,geometry().size()); |
|
346 | m_dataset->zoomInDomain(r,geometry().size()); | |
348 | m_zoomStack<<r; |
|
347 | m_zoomStack<<r; | |
349 | m_zoomIndex++; |
|
348 | m_zoomIndex++; | |
350 | if(m_animator) { |
|
349 | if(m_animator) { | |
351 | m_animator->setState(ChartAnimator::ShowState); |
|
350 | m_animator->setState(ChartAnimator::ShowState); | |
352 | } |
|
351 | } | |
353 | } |
|
352 | } | |
354 |
|
353 | |||
355 | void ChartPresenter::zoomOut() |
|
354 | void ChartPresenter::zoomOut() | |
356 | { |
|
355 | { | |
357 | if(m_zoomIndex==0) return; |
|
356 | if(m_zoomIndex==0) return; | |
358 | if(m_animator) |
|
357 | if(m_animator) | |
359 | { |
|
358 | { | |
360 | m_animator->setState(ChartAnimator::ZoomOutState); |
|
359 | m_animator->setState(ChartAnimator::ZoomOutState); | |
361 | } |
|
360 | } | |
362 | m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size()); |
|
361 | m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size()); | |
363 | m_zoomIndex--; |
|
362 | m_zoomIndex--; | |
364 | m_zoomStack.resize(m_zoomIndex); |
|
363 | m_zoomStack.resize(m_zoomIndex); | |
365 | if(m_animator){ |
|
364 | if(m_animator){ | |
366 | m_animator->setState(ChartAnimator::ShowState); |
|
365 | m_animator->setState(ChartAnimator::ShowState); | |
367 | } |
|
366 | } | |
368 | } |
|
367 | } | |
369 |
|
368 | |||
370 | void ChartPresenter::zoomReset() |
|
369 | void ChartPresenter::zoomReset() | |
371 | { |
|
370 | { | |
372 | m_zoomIndex=0; |
|
371 | m_zoomIndex=0; | |
373 | m_zoomStack.resize(m_zoomIndex); |
|
372 | m_zoomStack.resize(m_zoomIndex); | |
374 | } |
|
373 | } | |
375 |
|
374 | |||
376 | void ChartPresenter::scroll(int dx,int dy) |
|
375 | void ChartPresenter::scroll(int dx,int dy) | |
377 | { |
|
376 | { | |
378 | if(m_animator){ |
|
377 | if(m_animator){ | |
379 | if(dx<0) m_animator->setState(ChartAnimator::ScrollLeftState,QPointF()); |
|
378 | if(dx<0) m_animator->setState(ChartAnimator::ScrollLeftState,QPointF()); | |
380 | if(dx>0) m_animator->setState(ChartAnimator::ScrollRightState,QPointF()); |
|
379 | if(dx>0) m_animator->setState(ChartAnimator::ScrollRightState,QPointF()); | |
381 | if(dy<0) m_animator->setState(ChartAnimator::ScrollUpState,QPointF()); |
|
380 | if(dy<0) m_animator->setState(ChartAnimator::ScrollUpState,QPointF()); | |
382 | if(dy>0) m_animator->setState(ChartAnimator::ScrollDownState,QPointF()); |
|
381 | if(dy>0) m_animator->setState(ChartAnimator::ScrollDownState,QPointF()); | |
383 | } |
|
382 | } | |
384 |
|
383 | |||
385 | m_dataset->scrollDomain(dx,dy,geometry().size()); |
|
384 | m_dataset->scrollDomain(dx,dy,geometry().size()); | |
386 |
|
385 | |||
387 | if(m_animator){ |
|
386 | if(m_animator){ | |
388 | m_animator->setState(ChartAnimator::ShowState); |
|
387 | m_animator->setState(ChartAnimator::ShowState); | |
389 | } |
|
388 | } | |
390 | } |
|
389 | } | |
391 |
|
390 | |||
392 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
|
391 | QChart::AnimationOptions ChartPresenter::animationOptions() const | |
393 | { |
|
392 | { | |
394 | return m_options; |
|
393 | return m_options; | |
395 | } |
|
394 | } | |
396 |
|
395 | |||
397 |
|
396 | |||
398 | #include "moc_chartpresenter_p.cpp" |
|
397 | #include "moc_chartpresenter_p.cpp" | |
399 |
|
398 | |||
400 | QTCOMMERCIALCHART_END_NAMESPACE |
|
399 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,326 +1,326 | |||||
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(AreaChartItem* item, QAreaSeries* series, int index) |
|
74 | void ChartTheme::decorate(AreaChartItem* item, 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(LineChartItem* item, QLineSeries* series,int index) |
|
92 | void ChartTheme::decorate(LineChartItem* item, 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(ScatterChartItem* item, QScatterSeries* series, int index) |
|
162 | void ChartTheme::decorate(ScatterChartItem* item, QScatterSeries* series, int index) | |
163 | { |
|
163 | { | |
164 | Q_ASSERT(item); |
|
164 | Q_ASSERT(item); | |
165 | Q_ASSERT(series); |
|
165 | Q_ASSERT(series); | |
166 |
|
166 | |||
167 | QPen pen; |
|
167 | QPen pen; | |
168 | QBrush brush; |
|
168 | QBrush brush; | |
169 |
|
169 | |||
170 | if (pen == series->pen()) { |
|
170 | if (pen == series->pen()) { | |
171 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0)); |
|
171 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0)); | |
172 | pen.setWidthF(2); |
|
172 | pen.setWidthF(2); | |
173 | series->setPen(pen); |
|
173 | series->setPen(pen); | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | if (brush == series->brush()) { |
|
176 | if (brush == series->brush()) { | |
177 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
177 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
178 | series->setBrush(brush); |
|
178 | series->setBrush(brush); | |
179 | } |
|
179 | } | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 | void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int index) |
|
182 | void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int index) | |
183 | { |
|
183 | { | |
184 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
184 | // 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++) { |
|
185 | for (int i(0); i < series->slices().count(); i++) { | |
186 | qreal pos = (qreal) i / (qreal) series->count(); |
|
186 | qreal pos = (qreal) i / (qreal) series->count(); | |
187 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.1); |
|
187 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.1); | |
188 | series->slices().at(i)->setSlicePen(penColor); |
|
188 | series->slices().at(i)->setSlicePen(penColor); | |
189 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
189 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
190 | series->slices().at(i)->setSliceBrush(brushColor); |
|
190 | series->slices().at(i)->setSliceBrush(brushColor); | |
191 | } |
|
191 | } | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | void ChartTheme::decorate(SplineChartItem* item, QSplineSeries* series, int index) |
|
194 | void ChartTheme::decorate(SplineChartItem* item, QSplineSeries* series, int index) | |
195 | { |
|
195 | { | |
196 | Q_ASSERT(item); |
|
196 | Q_ASSERT(item); | |
197 | Q_ASSERT(series); |
|
197 | Q_ASSERT(series); | |
198 |
|
198 | |||
199 | QPen pen; |
|
199 | QPen pen; | |
200 |
|
200 | |||
201 | if(pen != series->pen()){ |
|
201 | if(pen != series->pen()){ | |
202 | item->setLinePen(series->pen()); |
|
202 | item->setLinePen(series->pen()); | |
203 | }else{ |
|
203 | }else{ | |
204 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
204 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
205 | pen.setWidthF(series->pen().widthF()); |
|
205 | pen.setWidthF(series->pen().widthF()); | |
206 | item->setLinePen(series->pen()); |
|
206 | item->setLinePen(series->pen()); | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 | // QColor color = m_seriesColors.at(index % m_seriesColors.size()); |
|
209 | // QColor color = m_seriesColors.at(index % m_seriesColors.size()); | |
210 | // TODO: define alpha in the theme? or in the series? |
|
210 | // TODO: define alpha in the theme? or in the series? | |
211 | //color.setAlpha(120); |
|
211 | //color.setAlpha(120); | |
212 |
|
212 | |||
213 | // QBrush brush(color, Qt::SolidPattern); |
|
213 | // QBrush brush(color, Qt::SolidPattern); | |
214 | // presenter->m_markerBrush = brush; |
|
214 | // presenter->m_markerBrush = brush; | |
215 |
|
215 | |||
216 | // QPen pen(brush, 3); |
|
216 | // QPen pen(brush, 3); | |
217 | // pen.setColor(color); |
|
217 | // pen.setColor(color); | |
218 | // presenter->m_markerPen = pen; |
|
218 | // presenter->m_markerPen = pen; | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 |
void ChartTheme::decorate(QChartAxis* axis, |
|
221 | void ChartTheme::decorate(QChartAxis* axis, QChart* parent) | |
222 | { |
|
222 | { | |
223 | Q_ASSERT(axis); |
|
223 | Q_ASSERT(axis); | |
224 |
Q_ASSERT( |
|
224 | Q_ASSERT(parent); | |
225 |
|
225 | |||
226 | if (axis->isAxisVisible()) { |
|
226 | if (axis->isAxisVisible()) { | |
227 | axis->setLabelsBrush(m_axisLabelBrush); |
|
227 | axis->setLabelsBrush(m_axisLabelBrush); | |
228 | axis->setLabelsPen(m_axisLabelPen); |
|
228 | axis->setLabelsPen(m_axisLabelPen); | |
229 | // TODO: check the axis type (x or y) should define whether to show the shades or not |
|
229 | // TODO: check the axis type (x or y) should define whether to show the shades or not | |
230 | if (m_backgroundShades == BackgroundShadesBoth |
|
230 | if (m_backgroundShades == BackgroundShadesBoth | |
231 |
|| m_backgroundShades == BackgroundShadesVertical |
|
231 | || (m_backgroundShades == BackgroundShadesVertical && parent->axisX() == axis) | |
232 |
|| m_backgroundShades == BackgroundShadesHorizontal |
|
232 | || (m_backgroundShades == BackgroundShadesHorizontal && parent->axisY() == axis)) { | |
233 | axis->setShadesPen(m_backgroundShadesPen); |
|
233 | axis->setShadesPen(m_backgroundShadesPen); | |
234 | axis->setShadesBrush(m_backgroundShadesBrush); |
|
234 | axis->setShadesBrush(m_backgroundShadesBrush); | |
235 | } else { |
|
235 | } else { | |
236 | // The shades not supposed to be shown for this axis, clear possible brush and pen |
|
236 | // The shades not supposed to be shown for this axis, clear possible brush and pen | |
237 | axis->setShadesPen(Qt::NoPen); |
|
237 | axis->setShadesPen(Qt::NoPen); | |
238 | axis->setShadesBrush(Qt::NoBrush); |
|
238 | axis->setShadesBrush(Qt::NoBrush); | |
239 | } |
|
239 | } | |
240 | axis->setAxisPen(m_axisLinePen); |
|
240 | axis->setAxisPen(m_axisLinePen); | |
241 | axis->setGridLinePen(m_gridLinePen); |
|
241 | axis->setGridLinePen(m_gridLinePen); | |
242 | axis->setLabelsFont(m_masterFont); |
|
242 | axis->setLabelsFont(m_masterFont); | |
243 | } |
|
243 | } | |
244 | } |
|
244 | } | |
245 |
|
245 | |||
246 | void ChartTheme::generateSeriesGradients() |
|
246 | void ChartTheme::generateSeriesGradients() | |
247 | { |
|
247 | { | |
248 | // Generate gradients in HSV color space |
|
248 | // Generate gradients in HSV color space | |
249 | foreach (QColor color, m_seriesColors) { |
|
249 | foreach (QColor color, m_seriesColors) { | |
250 | QLinearGradient g; |
|
250 | QLinearGradient g; | |
251 | qreal h = color.hsvHueF(); |
|
251 | qreal h = color.hsvHueF(); | |
252 | qreal s = color.hsvSaturationF(); |
|
252 | qreal s = color.hsvSaturationF(); | |
253 |
|
253 | |||
254 | // TODO: tune the algorithm to give nice results with most base colors defined in |
|
254 | // 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 |
|
255 | // most themes. The rest of the gradients we can define manually in theme specific | |
256 | // implementation. |
|
256 | // implementation. | |
257 | QColor start = color; |
|
257 | QColor start = color; | |
258 | start.setHsvF(h, 0.05, 0.95); |
|
258 | start.setHsvF(h, 0.05, 0.95); | |
259 | g.setColorAt(0.0, start); |
|
259 | g.setColorAt(0.0, start); | |
260 |
|
260 | |||
261 | g.setColorAt(0.5, color); |
|
261 | g.setColorAt(0.5, color); | |
262 |
|
262 | |||
263 | QColor end = color; |
|
263 | QColor end = color; | |
264 | end.setHsvF(h, s, 0.25); |
|
264 | end.setHsvF(h, s, 0.25); | |
265 | g.setColorAt(1.0, end); |
|
265 | g.setColorAt(1.0, end); | |
266 |
|
266 | |||
267 | m_seriesGradients << g; |
|
267 | m_seriesGradients << g; | |
268 | } |
|
268 | } | |
269 | } |
|
269 | } | |
270 |
|
270 | |||
271 |
|
271 | |||
272 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) |
|
272 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) | |
273 | { |
|
273 | { | |
274 | Q_ASSERT(pos >=0.0 && pos <= 1.0); |
|
274 | Q_ASSERT(pos >=0.0 && pos <= 1.0); | |
275 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); |
|
275 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); | |
276 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); |
|
276 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); | |
277 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); |
|
277 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); | |
278 | QColor c; |
|
278 | QColor c; | |
279 | c.setRgbF(r, g, b); |
|
279 | c.setRgbF(r, g, b); | |
280 | return c; |
|
280 | return c; | |
281 | } |
|
281 | } | |
282 |
|
282 | |||
283 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) |
|
283 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) | |
284 | { |
|
284 | { | |
285 | Q_ASSERT(pos >=0 && pos <= 1.0); |
|
285 | Q_ASSERT(pos >=0 && pos <= 1.0); | |
286 |
|
286 | |||
287 | // another possibility: |
|
287 | // another possibility: | |
288 | // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient |
|
288 | // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient | |
289 |
|
289 | |||
290 | QGradientStops stops = gradient.stops(); |
|
290 | QGradientStops stops = gradient.stops(); | |
291 | int count = stops.count(); |
|
291 | int count = stops.count(); | |
292 |
|
292 | |||
293 | // find previous stop relative to position |
|
293 | // find previous stop relative to position | |
294 | QGradientStop prev = stops.first(); |
|
294 | QGradientStop prev = stops.first(); | |
295 | for (int i=0; i<count; i++) { |
|
295 | for (int i=0; i<count; i++) { | |
296 | QGradientStop stop = stops.at(i); |
|
296 | QGradientStop stop = stops.at(i); | |
297 | if (pos > stop.first) |
|
297 | if (pos > stop.first) | |
298 | prev = stop; |
|
298 | prev = stop; | |
299 |
|
299 | |||
300 | // given position is actually a stop position? |
|
300 | // given position is actually a stop position? | |
301 | if (pos == stop.first) { |
|
301 | if (pos == stop.first) { | |
302 | //qDebug() << "stop color" << pos; |
|
302 | //qDebug() << "stop color" << pos; | |
303 | return stop.second; |
|
303 | return stop.second; | |
304 | } |
|
304 | } | |
305 | } |
|
305 | } | |
306 |
|
306 | |||
307 | // find next stop relative to position |
|
307 | // find next stop relative to position | |
308 | QGradientStop next = stops.last(); |
|
308 | QGradientStop next = stops.last(); | |
309 | for (int i=count-1; i>=0; i--) { |
|
309 | for (int i=count-1; i>=0; i--) { | |
310 | QGradientStop stop = stops.at(i); |
|
310 | QGradientStop stop = stops.at(i); | |
311 | if (pos < stop.first) |
|
311 | if (pos < stop.first) | |
312 | next = stop; |
|
312 | next = stop; | |
313 | } |
|
313 | } | |
314 |
|
314 | |||
315 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; |
|
315 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; | |
316 |
|
316 | |||
317 | qreal range = next.first - prev.first; |
|
317 | qreal range = next.first - prev.first; | |
318 | qreal posDelta = pos - prev.first; |
|
318 | qreal posDelta = pos - prev.first; | |
319 | qreal relativePos = posDelta / range; |
|
319 | qreal relativePos = posDelta / range; | |
320 |
|
320 | |||
321 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; |
|
321 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; | |
322 |
|
322 | |||
323 | return colorAt(prev.second, next.second, relativePos); |
|
323 | return colorAt(prev.second, next.second, relativePos); | |
324 | } |
|
324 | } | |
325 |
|
325 | |||
326 | QTCOMMERCIALCHART_END_NAMESPACE |
|
326 | 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(LineChartItem* item, QLineSeries* series, int index); |
|
51 | void decorate(LineChartItem* item, QLineSeries* series, int index); | |
52 | void decorate(AreaChartItem* item, QAreaSeries* series, int index); |
|
52 | void decorate(AreaChartItem* item, QAreaSeries* series, int index); | |
53 | void decorate(ScatterChartItem* presenter, QScatterSeries* series, int index); |
|
53 | void decorate(ScatterChartItem* presenter, 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(SplineChartItem* presenter, QSplineSeries* series, int index); |
|
55 | void decorate(SplineChartItem* presenter, QSplineSeries* series, int index); | |
56 |
void decorate(QChartAxis* axis, |
|
56 | void decorate(QChartAxis* axis, QChart* parent); | |
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,36 +1,39 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | class ChartThemeScientific: public ChartTheme |
|
5 | class ChartThemeScientific: public ChartTheme | |
6 | { |
|
6 | { | |
7 | public: |
|
7 | public: | |
8 | ChartThemeScientific():ChartTheme(QChart::ChartThemeScientific) |
|
8 | ChartThemeScientific():ChartTheme(QChart::ChartThemeScientific) | |
9 | { |
|
9 | { | |
10 | // Series |
|
10 | // Series | |
11 | m_seriesColors << QRgb(0xFFAD00); |
|
11 | m_seriesColors << QRgb(0xFFAD00); | |
12 | m_seriesColors << QRgb(0x596A75); |
|
12 | m_seriesColors << QRgb(0x596A75); | |
13 | m_seriesColors << QRgb(0x202020); |
|
13 | m_seriesColors << QRgb(0x202020); | |
14 | m_seriesColors << QRgb(0x474747); |
|
14 | m_seriesColors << QRgb(0x474747); | |
15 | generateSeriesGradients(); |
|
15 | generateSeriesGradients(); | |
16 |
|
16 | |||
17 | // Background |
|
17 | // Background | |
18 | QLinearGradient backgroundGradient; |
|
18 | QLinearGradient backgroundGradient; | |
19 | backgroundGradient.setColorAt(0.0, QRgb(0xfffefc)); |
|
19 | backgroundGradient.setColorAt(0.0, QRgb(0xfffefc)); | |
20 | backgroundGradient.setColorAt(1.0, QRgb(0xfffefc)); |
|
20 | backgroundGradient.setColorAt(1.0, QRgb(0xfffefc)); | |
21 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
21 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
22 | m_backgroundGradient = backgroundGradient; |
|
22 | m_backgroundGradient = backgroundGradient; | |
23 |
|
23 | |||
24 | // Axes and other |
|
24 | // Axes and other | |
25 | m_masterFont = QFont(); |
|
25 | m_masterFont = QFont(); | |
26 | m_axisLinePen = QPen(QRgb(0x0f0f0f)); |
|
26 | m_axisLinePen = QPen(QRgb(0x0f0f0f)); | |
27 | m_axisLinePen.setWidth(2); |
|
27 | m_axisLinePen.setWidth(2); | |
28 | m_axisLabelBrush = QBrush(QRgb(0x3f3f3f)); |
|
28 | m_axisLabelBrush = QBrush(QRgb(0x3f3f3f)); | |
29 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons |
|
29 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons | |
30 | m_backgroundShadesPen = Qt::NoPen; |
|
30 | m_backgroundShadesPen = Qt::NoPen; | |
|
31 | // m_backgroundShadesBrush = QBrush(QColor(0x0f, 0x0f, 0x0f, 0x80)); | |||
|
32 | m_backgroundShadesBrush = QBrush(QColor(0xff, 0xad, 0x00, 0x50)); | |||
|
33 | m_backgroundShades = BackgroundShadesHorizontal; | |||
31 | m_gridLinePen = QPen(QRgb(0x0f0f0f)); |
|
34 | m_gridLinePen = QPen(QRgb(0x0f0f0f)); | |
32 | m_gridLinePen.setWidth(2); |
|
35 | m_gridLinePen.setWidth(2); | |
33 | } |
|
36 | } | |
34 | }; |
|
37 | }; | |
35 |
|
38 | |||
36 | QTCOMMERCIALCHART_END_NAMESPACE |
|
39 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now