@@ -1,283 +1,283 | |||||
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 | //series |
|
6 | //series | |
7 | #include "qbarseries.h" |
|
7 | #include "qbarseries.h" | |
8 | #include "qstackedbarseries.h" |
|
8 | #include "qstackedbarseries.h" | |
9 | #include "qpercentbarseries.h" |
|
9 | #include "qpercentbarseries.h" | |
10 | #include "qlineseries.h" |
|
10 | #include "qlineseries.h" | |
11 | #include "qpieseries.h" |
|
11 | #include "qpieseries.h" | |
12 | #include "qscatterseries.h" |
|
12 | #include "qscatterseries.h" | |
13 | //items |
|
13 | //items | |
14 | #include "axisitem_p.h" |
|
14 | #include "axisitem_p.h" | |
15 | #include "axisanimationitem_p.h" |
|
15 | #include "axisanimationitem_p.h" | |
16 | #include "barpresenter.h" |
|
16 | #include "barpresenter.h" | |
17 | #include "stackedbarpresenter.h" |
|
17 | #include "stackedbarpresenter.h" | |
18 | #include "linechartitem_p.h" |
|
18 | #include "linechartitem_p.h" | |
19 | #include "percentbarpresenter.h" |
|
19 | #include "percentbarpresenter.h" | |
20 | #include "linechartanimationitem_p.h" |
|
20 | #include "linechartanimationitem_p.h" | |
21 | #include "piepresenter_p.h" |
|
21 | #include "piepresenter_p.h" | |
22 | #include "scatterpresenter_p.h" |
|
22 | #include "scatterpresenter_p.h" | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
26 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), | |
27 | m_chart(chart), |
|
27 | m_chart(chart), | |
28 | m_dataset(dataset), |
|
28 | m_dataset(dataset), | |
29 | m_chartTheme(0), |
|
29 | m_chartTheme(0), | |
30 | m_marginSize(0), |
|
30 | m_marginSize(0), | |
31 | m_rect(QRectF(QPoint(0,0),m_chart->size())), |
|
31 | m_rect(QRectF(QPoint(0,0),m_chart->size())), | |
32 | m_options(0) |
|
32 | m_options(0) | |
33 | { |
|
33 | { | |
34 | createConnections(); |
|
34 | createConnections(); | |
35 | setChartTheme(QChart::ChartThemeDefault); |
|
35 | setChartTheme(QChart::ChartThemeDefault); | |
36 |
|
36 | |||
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | ChartPresenter::~ChartPresenter() |
|
39 | ChartPresenter::~ChartPresenter() | |
40 | { |
|
40 | { | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | void ChartPresenter::createConnections() |
|
43 | void ChartPresenter::createConnections() | |
44 | { |
|
44 | { | |
45 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
45 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); | |
46 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*)),this,SLOT(handleSeriesAdded(QSeries*))); |
|
46 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*)),this,SLOT(handleSeriesAdded(QSeries*))); | |
47 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*))); |
|
47 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*))); | |
48 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*)),this,SLOT(handleAxisAdded(QChartAxis*))); |
|
48 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*)),this,SLOT(handleAxisAdded(QChartAxis*))); | |
49 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); |
|
49 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); | |
50 | QObject::connect(m_dataset,SIGNAL(seriesDomainChanged(QSeries*,const Domain&)),this,SLOT(handleSeriesDomainChanged(QSeries*,const Domain&))); |
|
50 | QObject::connect(m_dataset,SIGNAL(seriesDomainChanged(QSeries*,const Domain&)),this,SLOT(handleSeriesDomainChanged(QSeries*,const Domain&))); | |
51 | QObject::connect(m_dataset,SIGNAL(axisLabelsChanged(QChartAxis*,const QStringList&)),this,SLOT(handleAxisLabelsChanged(QChartAxis*,const QStringList&))); |
|
51 | QObject::connect(m_dataset,SIGNAL(axisLabelsChanged(QChartAxis*,const QStringList&)),this,SLOT(handleAxisLabelsChanged(QChartAxis*,const QStringList&))); | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 |
|
54 | |||
55 | QRectF ChartPresenter::geometry() const |
|
55 | QRectF ChartPresenter::geometry() const | |
56 | { |
|
56 | { | |
57 | return m_rect; |
|
57 | return m_rect; | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | void ChartPresenter::handleGeometryChanged() |
|
60 | void ChartPresenter::handleGeometryChanged() | |
61 | { |
|
61 | { | |
62 | m_rect = QRectF(QPoint(0,0),m_chart->size()); |
|
62 | m_rect = QRectF(QPoint(0,0),m_chart->size()); | |
63 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); |
|
63 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); | |
64 | Q_ASSERT(m_rect.isValid()); |
|
64 | Q_ASSERT(m_rect.isValid()); | |
65 | emit geometryChanged(m_rect); |
|
65 | emit geometryChanged(m_rect); | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | int ChartPresenter::margin() const |
|
68 | int ChartPresenter::margin() const | |
69 | { |
|
69 | { | |
70 | return m_marginSize; |
|
70 | return m_marginSize; | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | void ChartPresenter::setMargin(int margin) |
|
73 | void ChartPresenter::setMargin(int margin) | |
74 | { |
|
74 | { | |
75 | m_marginSize = margin; |
|
75 | m_marginSize = margin; | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | void ChartPresenter::handleAxisAdded(QChartAxis* axis) |
|
78 | void ChartPresenter::handleAxisAdded(QChartAxis* axis) | |
79 | { |
|
79 | { | |
80 |
|
80 | |||
81 | AxisItem* item ; |
|
81 | AxisItem* item ; | |
82 |
|
82 | |||
83 | if(!m_options.testFlag(QChart::GridAxisAnimations)) |
|
83 | if(!m_options.testFlag(QChart::GridAxisAnimations)) | |
84 | { |
|
84 | { | |
85 | item = new AxisItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); |
|
85 | item = new AxisItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); | |
86 | }else{ |
|
86 | }else{ | |
87 | item = new AxisAnimationItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); |
|
87 | item = new AxisAnimationItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
90 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
91 | QObject::connect(axis,SIGNAL(update(QChartAxis*)),item,SLOT(handleAxisUpdate(QChartAxis*))); |
|
91 | QObject::connect(axis,SIGNAL(update(QChartAxis*)),item,SLOT(handleAxisUpdate(QChartAxis*))); | |
92 |
|
92 | |||
93 | item->handleAxisUpdate(axis); |
|
93 | item->handleAxisUpdate(axis); | |
94 | item->handleGeometryChanged(m_rect); |
|
94 | item->handleGeometryChanged(m_rect); | |
95 | m_chartTheme->decorate(axis,item); |
|
95 | m_chartTheme->decorate(axis,item); | |
96 | m_axisItems.insert(axis,item); |
|
96 | m_axisItems.insert(axis,item); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) |
|
99 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) | |
100 | { |
|
100 | { | |
101 | AxisItem* item = m_axisItems.take(axis); |
|
101 | AxisItem* item = m_axisItems.take(axis); | |
102 | Q_ASSERT(item); |
|
102 | Q_ASSERT(item); | |
103 | delete item; |
|
103 | delete item; | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 |
|
106 | |||
107 | void ChartPresenter::handleSeriesAdded(QSeries* series) |
|
107 | void ChartPresenter::handleSeriesAdded(QSeries* series) | |
108 | { |
|
108 | { | |
109 | switch(series->type()) |
|
109 | switch(series->type()) | |
110 | { |
|
110 | { | |
111 | case QSeries::SeriesTypeLine: { |
|
111 | case QSeries::SeriesTypeLine: { | |
112 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); |
|
112 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); | |
113 | LineChartItem* item; |
|
113 | LineChartItem* item; | |
114 | if(m_options.testFlag(QChart::SeriesAnimations)){ |
|
114 | if(m_options.testFlag(QChart::SeriesAnimations)){ | |
115 | item = new LineChartAnimationItem(this,lineSeries,m_chart); |
|
115 | item = new LineChartAnimationItem(this,lineSeries,m_chart); | |
116 | }else{ |
|
116 | }else{ | |
117 | item = new LineChartItem(this,lineSeries,m_chart); |
|
117 | item = new LineChartItem(this,lineSeries,m_chart); | |
118 | } |
|
118 | } | |
119 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); |
|
119 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); | |
120 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
120 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
121 |
QObject::connect(lineSeries,SIGNAL( |
|
121 | QObject::connect(lineSeries,SIGNAL(pointChanged(int)),item,SLOT(handleModelChanged(int))); | |
122 | m_chartItems.insert(series,item); |
|
122 | m_chartItems.insert(series,item); | |
123 | break; |
|
123 | break; | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | case QSeries::SeriesTypeBar: { |
|
126 | case QSeries::SeriesTypeBar: { | |
127 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
127 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); | |
128 | BarPresenter* item = new BarPresenter(barSeries,m_chart); |
|
128 | BarPresenter* item = new BarPresenter(barSeries,m_chart); | |
129 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); |
|
129 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); | |
130 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
130 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
131 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
131 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
132 | m_chartItems.insert(series,item); |
|
132 | m_chartItems.insert(series,item); | |
133 | // m_axisXItem->setVisible(false); |
|
133 | // m_axisXItem->setVisible(false); | |
134 | break; |
|
134 | break; | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | case QSeries::SeriesTypeStackedBar: { |
|
137 | case QSeries::SeriesTypeStackedBar: { | |
138 |
|
138 | |||
139 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
139 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); | |
140 | StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart); |
|
140 | StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart); | |
141 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); |
|
141 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); | |
142 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
142 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
143 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
143 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
144 | m_chartItems.insert(series,item); |
|
144 | m_chartItems.insert(series,item); | |
145 | break; |
|
145 | break; | |
146 | } |
|
146 | } | |
147 |
|
147 | |||
148 | case QSeries::SeriesTypePercentBar: { |
|
148 | case QSeries::SeriesTypePercentBar: { | |
149 |
|
149 | |||
150 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
150 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); | |
151 | PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart); |
|
151 | PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart); | |
152 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); |
|
152 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); | |
153 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
153 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
154 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
154 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
155 | m_chartItems.insert(series,item); |
|
155 | m_chartItems.insert(series,item); | |
156 | break; |
|
156 | break; | |
157 | } |
|
157 | } | |
158 | case QSeries::SeriesTypeScatter: { |
|
158 | case QSeries::SeriesTypeScatter: { | |
159 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
159 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
160 | ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart); |
|
160 | ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart); | |
161 | QObject::connect(scatterPresenter, SIGNAL(clicked()), scatterSeries, SIGNAL(clicked())); |
|
161 | QObject::connect(scatterPresenter, SIGNAL(clicked()), scatterSeries, SIGNAL(clicked())); | |
162 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), |
|
162 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), | |
163 | scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); |
|
163 | scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); | |
164 | m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count()); |
|
164 | m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count()); | |
165 | m_chartItems.insert(scatterSeries, scatterPresenter); |
|
165 | m_chartItems.insert(scatterSeries, scatterPresenter); | |
166 | break; |
|
166 | break; | |
167 | } |
|
167 | } | |
168 | case QSeries::SeriesTypePie: { |
|
168 | case QSeries::SeriesTypePie: { | |
169 | QPieSeries *s = qobject_cast<QPieSeries *>(series); |
|
169 | QPieSeries *s = qobject_cast<QPieSeries *>(series); | |
170 | PiePresenter* pie = new PiePresenter(m_chart, s); |
|
170 | PiePresenter* pie = new PiePresenter(m_chart, s); | |
171 | m_chartTheme->decorate(pie, s, m_chartItems.count()); |
|
171 | m_chartTheme->decorate(pie, s, m_chartItems.count()); | |
172 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); |
|
172 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); | |
173 |
|
173 | |||
174 | // Hide all from background when there is only piechart |
|
174 | // Hide all from background when there is only piechart | |
175 | // TODO: refactor this ugly code... should be one setting for this |
|
175 | // TODO: refactor this ugly code... should be one setting for this | |
176 | if (m_chartItems.count() == 0) { |
|
176 | if (m_chartItems.count() == 0) { | |
177 | m_chart->axisX()->setAxisVisible(false); |
|
177 | m_chart->axisX()->setAxisVisible(false); | |
178 | m_chart->axisY()->setAxisVisible(false); |
|
178 | m_chart->axisY()->setAxisVisible(false); | |
179 | m_chart->axisX()->setGridVisible(false); |
|
179 | m_chart->axisX()->setGridVisible(false); | |
180 | m_chart->axisY()->setGridVisible(false); |
|
180 | m_chart->axisY()->setGridVisible(false); | |
181 | m_chart->axisX()->setLabelsVisible(false); |
|
181 | m_chart->axisX()->setLabelsVisible(false); | |
182 | m_chart->axisY()->setLabelsVisible(false); |
|
182 | m_chart->axisY()->setLabelsVisible(false); | |
183 | m_chart->axisX()->setShadesVisible(false); |
|
183 | m_chart->axisX()->setShadesVisible(false); | |
184 | m_chart->axisY()->setShadesVisible(false); |
|
184 | m_chart->axisY()->setShadesVisible(false); | |
185 | m_chart->setChartBackgroundBrush(Qt::transparent); |
|
185 | m_chart->setChartBackgroundBrush(Qt::transparent); | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | m_chartItems.insert(series, pie); |
|
188 | m_chartItems.insert(series, pie); | |
189 | break; |
|
189 | break; | |
190 | } |
|
190 | } | |
191 | default: { |
|
191 | default: { | |
192 | qDebug()<< "Series type" << series->type() << "not implemented."; |
|
192 | qDebug()<< "Series type" << series->type() << "not implemented."; | |
193 | break; |
|
193 | break; | |
194 | } |
|
194 | } | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | if(m_rect.isValid()) emit geometryChanged(m_rect); |
|
197 | if(m_rect.isValid()) emit geometryChanged(m_rect); | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | void ChartPresenter::handleSeriesRemoved(QSeries* series) |
|
200 | void ChartPresenter::handleSeriesRemoved(QSeries* series) | |
201 | { |
|
201 | { | |
202 | ChartItem* item = m_chartItems.take(series); |
|
202 | ChartItem* item = m_chartItems.take(series); | |
203 | delete item; |
|
203 | delete item; | |
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 | void ChartPresenter::handleSeriesChanged(QSeries* series) |
|
206 | void ChartPresenter::handleSeriesChanged(QSeries* series) | |
207 | { |
|
207 | { | |
208 | //TODO: |
|
208 | //TODO: | |
209 | } |
|
209 | } | |
210 |
|
210 | |||
211 | void ChartPresenter::handleSeriesDomainChanged(QSeries* series, const Domain& domain) |
|
211 | void ChartPresenter::handleSeriesDomainChanged(QSeries* series, const Domain& domain) | |
212 | { |
|
212 | { | |
213 | m_chartItems.value(series)->handleDomainChanged(domain); |
|
213 | m_chartItems.value(series)->handleDomainChanged(domain); | |
214 | } |
|
214 | } | |
215 |
|
215 | |||
216 | void ChartPresenter::handleAxisLabelsChanged(QChartAxis* axis,const QStringList& labels) |
|
216 | void ChartPresenter::handleAxisLabelsChanged(QChartAxis* axis,const QStringList& labels) | |
217 | { |
|
217 | { | |
218 | m_axisItems.value(axis)->handleLabelsChanged(axis,labels); |
|
218 | m_axisItems.value(axis)->handleLabelsChanged(axis,labels); | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) |
|
221 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) | |
222 | { |
|
222 | { | |
223 | delete m_chartTheme; |
|
223 | delete m_chartTheme; | |
224 |
|
224 | |||
225 | m_chartTheme = ChartTheme::createTheme(theme); |
|
225 | m_chartTheme = ChartTheme::createTheme(theme); | |
226 |
|
226 | |||
227 | m_chartTheme->decorate(m_chart); |
|
227 | m_chartTheme->decorate(m_chart); | |
228 | QMapIterator<QSeries*,ChartItem*> i(m_chartItems); |
|
228 | QMapIterator<QSeries*,ChartItem*> i(m_chartItems); | |
229 |
|
229 | |||
230 | int index=0; |
|
230 | int index=0; | |
231 | while (i.hasNext()) { |
|
231 | while (i.hasNext()) { | |
232 | i.next(); |
|
232 | i.next(); | |
233 | m_chartTheme->decorate(i.value(),i.key(),index); |
|
233 | m_chartTheme->decorate(i.value(),i.key(),index); | |
234 | index++; |
|
234 | index++; | |
235 | } |
|
235 | } | |
236 |
|
236 | |||
237 | QMapIterator<QChartAxis*,AxisItem*> j(m_axisItems); |
|
237 | QMapIterator<QChartAxis*,AxisItem*> j(m_axisItems); | |
238 | while (j.hasNext()) { |
|
238 | while (j.hasNext()) { | |
239 | j.next(); |
|
239 | j.next(); | |
240 | m_chartTheme->decorate(j.key(),j.value()); |
|
240 | m_chartTheme->decorate(j.key(),j.value()); | |
241 | } |
|
241 | } | |
242 | } |
|
242 | } | |
243 |
|
243 | |||
244 | QChart::ChartTheme ChartPresenter::chartTheme() |
|
244 | QChart::ChartTheme ChartPresenter::chartTheme() | |
245 | { |
|
245 | { | |
246 | return m_chartTheme->id(); |
|
246 | return m_chartTheme->id(); | |
247 | } |
|
247 | } | |
248 |
|
248 | |||
249 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
249 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |
250 | { |
|
250 | { | |
251 | if(m_options!=options) { |
|
251 | if(m_options!=options) { | |
252 |
|
252 | |||
253 | m_options=options; |
|
253 | m_options=options; | |
254 |
|
254 | |||
255 | //recreate elements |
|
255 | //recreate elements | |
256 |
|
256 | |||
257 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); |
|
257 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); | |
258 | QList<QSeries*> seriesList = m_chartItems.uniqueKeys(); |
|
258 | QList<QSeries*> seriesList = m_chartItems.uniqueKeys(); | |
259 |
|
259 | |||
260 | foreach(QChartAxis* axis, axisList) { |
|
260 | foreach(QChartAxis* axis, axisList) { | |
261 | handleAxisRemoved(axis); |
|
261 | handleAxisRemoved(axis); | |
262 | handleAxisAdded(axis); |
|
262 | handleAxisAdded(axis); | |
263 | } |
|
263 | } | |
264 | foreach(QSeries* series, seriesList) { |
|
264 | foreach(QSeries* series, seriesList) { | |
265 | handleSeriesRemoved(series); |
|
265 | handleSeriesRemoved(series); | |
266 | handleSeriesAdded(series); |
|
266 | handleSeriesAdded(series); | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 | //now reintialize view data |
|
269 | //now reintialize view data | |
270 | //TODO: make it more nice |
|
270 | //TODO: make it more nice | |
271 | m_dataset->setDomain(m_dataset->domainIndex()); |
|
271 | m_dataset->setDomain(m_dataset->domainIndex()); | |
272 | } |
|
272 | } | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
|
275 | QChart::AnimationOptions ChartPresenter::animationOptions() const | |
276 | { |
|
276 | { | |
277 | return m_options; |
|
277 | return m_options; | |
278 | } |
|
278 | } | |
279 |
|
279 | |||
280 |
|
280 | |||
281 | #include "moc_chartpresenter_p.cpp" |
|
281 | #include "moc_chartpresenter_p.cpp" | |
282 |
|
282 | |||
283 | QTCOMMERCIALCHART_END_NAMESPACE |
|
283 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,203 +1,213 | |||||
1 | #include "qlineseries.h" |
|
1 | #include "qlineseries.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | /*! |
|
5 | /*! | |
6 | \class QLineSeries |
|
6 | \class QLineSeries | |
7 | \brief The QLineSeries class is used for making line charts. |
|
7 | \brief The QLineSeries class is used for making line charts. | |
8 |
|
8 | |||
9 | \mainclass |
|
9 | \mainclass | |
10 |
|
10 | |||
11 | A line chart is used to show information as a series of data points |
|
11 | A line chart is used to show information as a series of data points | |
12 | connected by straight lines. |
|
12 | connected by straight lines. | |
13 |
|
13 | |||
14 | \image linechart.png |
|
14 | \image linechart.png | |
15 |
|
15 | |||
16 | Creating basic line chart is simple: |
|
16 | Creating basic line chart is simple: | |
17 | \code |
|
17 | \code | |
18 | QLineSeries* series = new QLineSeries(); |
|
18 | QLineSeries* series = new QLineSeries(); | |
19 | series->add(0, 6); |
|
19 | series->add(0, 6); | |
20 | series->add(2, 4); |
|
20 | series->add(2, 4); | |
21 | ... |
|
21 | ... | |
22 | chartView->addSeries(series); |
|
22 | chartView->addSeries(series); | |
23 | \endcode |
|
23 | \endcode | |
24 | */ |
|
24 | */ | |
25 |
|
25 | |||
26 | /*! |
|
26 | /*! | |
27 | \fn virtual QSeriesType QLineSeries::type() const |
|
27 | \fn virtual QSeriesType QLineSeries::type() const | |
28 | \brief Returns type of series. |
|
28 | \brief Returns type of series. | |
29 | \sa QSeries, QSeriesType |
|
29 | \sa QSeries, QSeriesType | |
30 | */ |
|
30 | */ | |
31 |
|
31 | |||
32 | /*! |
|
32 | /*! | |
33 | \fn QPen QLineSeries::pen() const |
|
33 | \fn QPen QLineSeries::pen() const | |
34 | \brief Returns the pen used to draw line for this series. |
|
34 | \brief Returns the pen used to draw line for this series. | |
35 | \sa setPen() |
|
35 | \sa setPen() | |
36 | */ |
|
36 | */ | |
37 |
|
37 | |||
38 | /*! |
|
38 | /*! | |
39 | \fn bool QLineSeries::pointsVisible() const |
|
39 | \fn bool QLineSeries::pointsVisible() const | |
40 | \brief Returns if the points are drawn for this series. |
|
40 | \brief Returns if the points are drawn for this series. | |
41 | \sa setPointsVisible() |
|
41 | \sa setPointsVisible() | |
42 | */ |
|
42 | */ | |
43 |
|
43 | |||
44 |
|
44 | |||
45 | /*! |
|
45 | /*! | |
46 |
\fn void QLineSeries:: |
|
46 | \fn void QLineSeries::pointChanged(int index) | |
|
47 | \brief \internal \a index | |||
|
48 | */ | |||
|
49 | ||||
|
50 | /*! | |||
|
51 | \fn void QLineSeries::pointAdded(int index) | |||
|
52 | \brief \internal \a index | |||
|
53 | */ | |||
|
54 | ||||
|
55 | /*! | |||
|
56 | \fn void QLineSeries::pointRemoved(int index) | |||
47 | \brief \internal \a index |
|
57 | \brief \internal \a index | |
48 | */ |
|
58 | */ | |
49 |
|
59 | |||
50 | /*! |
|
60 | /*! | |
51 | Constructs empty series object which is a child of \a parent. |
|
61 | Constructs empty series object which is a child of \a parent. | |
52 | When series object is added to QChartView or QChart instance ownerships is transfered. |
|
62 | When series object is added to QChartView or QChart instance ownerships is transfered. | |
53 | */ |
|
63 | */ | |
54 | QLineSeries::QLineSeries(QObject* parent):QSeries(parent), |
|
64 | QLineSeries::QLineSeries(QObject* parent):QSeries(parent), | |
55 | m_pointsVisible(false) |
|
65 | m_pointsVisible(false) | |
56 | { |
|
66 | { | |
57 | } |
|
67 | } | |
58 | /*! |
|
68 | /*! | |
59 | Destroys the object. Series added to QChartView or QChart instances are owned by those, |
|
69 | Destroys the object. Series added to QChartView or QChart instances are owned by those, | |
60 | and are deleted when mentioned object are destroyed. |
|
70 | and are deleted when mentioned object are destroyed. | |
61 | */ |
|
71 | */ | |
62 | QLineSeries::~QLineSeries() |
|
72 | QLineSeries::~QLineSeries() | |
63 | { |
|
73 | { | |
64 | } |
|
74 | } | |
65 |
|
75 | |||
66 | /*! |
|
76 | /*! | |
67 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. |
|
77 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. | |
68 | */ |
|
78 | */ | |
69 | void QLineSeries::add(qreal x,qreal y) |
|
79 | void QLineSeries::add(qreal x,qreal y) | |
70 | { |
|
80 | { | |
71 | Q_ASSERT(m_x.size() == m_y.size()); |
|
81 | Q_ASSERT(m_x.size() == m_y.size()); | |
72 | m_x<<x; |
|
82 | m_x<<x; | |
73 | m_y<<y; |
|
83 | m_y<<y; | |
|
84 | emit pointAdded(m_x.size()-1); | |||
74 | } |
|
85 | } | |
75 |
|
86 | |||
76 | /*! |
|
87 | /*! | |
77 | This is an overloaded function. |
|
88 | This is an overloaded function. | |
78 | Adds data \a point to the series. Points are connected with lines on the chart. |
|
89 | Adds data \a point to the series. Points are connected with lines on the chart. | |
79 | */ |
|
90 | */ | |
80 | void QLineSeries::add(const QPointF& point) |
|
91 | void QLineSeries::add(const QPointF& point) | |
81 | { |
|
92 | { | |
82 | m_x<<point.x(); |
|
93 | add(point.x(),point.y()); | |
83 | m_y<<point.y(); |
|
|||
84 | } |
|
94 | } | |
85 |
|
95 | |||
86 | /*! |
|
96 | /*! | |
87 | Modifies \a y value for given \a x a value. |
|
97 | Modifies \a y value for given \a x a value. | |
88 | */ |
|
98 | */ | |
89 | void QLineSeries::replace(qreal x,qreal y) |
|
99 | void QLineSeries::replace(qreal x,qreal y) | |
90 | { |
|
100 | { | |
91 | int index = m_x.indexOf(x); |
|
101 | int index = m_x.indexOf(x); | |
92 | m_x[index]=x; |
|
102 | m_x[index]=x; | |
93 | m_y[index]=y; |
|
103 | m_y[index]=y; | |
94 |
emit |
|
104 | emit pointChanged(index); | |
95 | } |
|
105 | } | |
96 |
|
106 | |||
97 | /*! |
|
107 | /*! | |
98 | This is an overloaded function. |
|
108 | This is an overloaded function. | |
99 | Replaces current y value of for given \a point x value with \a point y value. |
|
109 | Replaces current y value of for given \a point x value with \a point y value. | |
100 | */ |
|
110 | */ | |
101 | void QLineSeries::replace(const QPointF& point) |
|
111 | void QLineSeries::replace(const QPointF& point) | |
102 | { |
|
112 | { | |
103 | int index = m_x.indexOf(point.x()); |
|
113 | replace(point.x(),point.y()); | |
104 | m_x[index]=point.x(); |
|
|||
105 | m_y[index]=point.y(); |
|
|||
106 | emit changed(index); |
|
|||
107 | } |
|
114 | } | |
108 |
|
115 | |||
109 | /*! |
|
116 | /*! | |
110 | Removes current \a x and y value. |
|
117 | Removes current \a x and y value. | |
111 | */ |
|
118 | */ | |
112 | void QLineSeries::remove(qreal x) |
|
119 | void QLineSeries::remove(qreal x) | |
113 | { |
|
120 | { | |
114 |
|
121 | int index = m_x.indexOf(x); | ||
|
122 | m_x.remove(index); | |||
|
123 | m_y.remove(index); | |||
|
124 | emit pointRemoved(index); | |||
115 | } |
|
125 | } | |
116 |
|
126 | |||
117 | /*! |
|
127 | /*! | |
118 | Removes current \a point x value. Note \a point y value is ignored. |
|
128 | Removes current \a point x value. Note \a point y value is ignored. | |
119 | */ |
|
129 | */ | |
120 | void QLineSeries::remove(const QPointF& point) |
|
130 | void QLineSeries::remove(const QPointF& point) | |
121 | { |
|
131 | { | |
122 |
|
132 | remove(point.x()); | ||
123 | } |
|
133 | } | |
124 |
|
134 | |||
125 | /*! |
|
135 | /*! | |
126 | Clears all the data. |
|
136 | Clears all the data. | |
127 | */ |
|
137 | */ | |
128 | void QLineSeries::clear() |
|
138 | void QLineSeries::clear() | |
129 | { |
|
139 | { | |
130 | m_x.clear(); |
|
140 | m_x.clear(); | |
131 | m_y.clear(); |
|
141 | m_y.clear(); | |
132 | } |
|
142 | } | |
133 |
|
143 | |||
134 | /*! |
|
144 | /*! | |
135 | \internal \a pos |
|
145 | \internal \a pos | |
136 | */ |
|
146 | */ | |
137 | qreal QLineSeries::x(int pos) const |
|
147 | qreal QLineSeries::x(int pos) const | |
138 | { |
|
148 | { | |
139 | return m_x.at(pos); |
|
149 | return m_x.at(pos); | |
140 | } |
|
150 | } | |
141 |
|
151 | |||
142 | /*! |
|
152 | /*! | |
143 | \internal \a pos |
|
153 | \internal \a pos | |
144 | */ |
|
154 | */ | |
145 | qreal QLineSeries::y(int pos) const |
|
155 | qreal QLineSeries::y(int pos) const | |
146 | { |
|
156 | { | |
147 | return m_y.at(pos); |
|
157 | return m_y.at(pos); | |
148 | } |
|
158 | } | |
149 |
|
159 | |||
150 | /*! |
|
160 | /*! | |
151 | Returns number of data points within series. |
|
161 | Returns number of data points within series. | |
152 | */ |
|
162 | */ | |
153 | int QLineSeries::count() const |
|
163 | int QLineSeries::count() const | |
154 | { |
|
164 | { | |
155 | Q_ASSERT(m_x.size() == m_y.size()); |
|
165 | Q_ASSERT(m_x.size() == m_y.size()); | |
156 |
|
166 | |||
157 | return m_x.size(); |
|
167 | return m_x.size(); | |
158 |
|
168 | |||
159 | } |
|
169 | } | |
160 |
|
170 | |||
161 | /*! |
|
171 | /*! | |
162 | Sets \a pen used for drawing given series.. |
|
172 | Sets \a pen used for drawing given series.. | |
163 | */ |
|
173 | */ | |
164 | void QLineSeries::setPen(const QPen& pen) |
|
174 | void QLineSeries::setPen(const QPen& pen) | |
165 | { |
|
175 | { | |
166 | m_pen=pen; |
|
176 | m_pen=pen; | |
167 | } |
|
177 | } | |
168 |
|
178 | |||
169 | /*! |
|
179 | /*! | |
170 | Sets if data points are \a visible and should be drawn on line. |
|
180 | Sets if data points are \a visible and should be drawn on line. | |
171 | */ |
|
181 | */ | |
172 | void QLineSeries::setPointsVisible(bool visible) |
|
182 | void QLineSeries::setPointsVisible(bool visible) | |
173 | { |
|
183 | { | |
174 | m_pointsVisible=visible; |
|
184 | m_pointsVisible=visible; | |
175 | } |
|
185 | } | |
176 |
|
186 | |||
177 | QDebug operator<< (QDebug debug, const QLineSeries series) |
|
187 | QDebug operator<< (QDebug debug, const QLineSeries series) | |
178 | { |
|
188 | { | |
179 | Q_ASSERT(series.m_x.size() == series.m_y.size()); |
|
189 | Q_ASSERT(series.m_x.size() == series.m_y.size()); | |
180 |
|
190 | |||
181 | int size = series.m_x.size(); |
|
191 | int size = series.m_x.size(); | |
182 |
|
192 | |||
183 | for (int i=0;i<size;i++) { |
|
193 | for (int i=0;i<size;i++) { | |
184 | debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") "; |
|
194 | debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") "; | |
185 | } |
|
195 | } | |
186 | return debug.space(); |
|
196 | return debug.space(); | |
187 | } |
|
197 | } | |
188 |
|
198 | |||
189 | /*! |
|
199 | /*! | |
190 | Stream operator for adding a data \a point to the series. |
|
200 | Stream operator for adding a data \a point to the series. | |
191 | \sa add() |
|
201 | \sa add() | |
192 | */ |
|
202 | */ | |
193 |
|
203 | |||
194 | QLineSeries& QLineSeries::operator<< (const QPointF &point) |
|
204 | QLineSeries& QLineSeries::operator<< (const QPointF &point) | |
195 | { |
|
205 | { | |
196 | add(point); |
|
206 | add(point); | |
197 | return *this; |
|
207 | return *this; | |
198 | } |
|
208 | } | |
199 |
|
209 | |||
200 |
|
210 | |||
201 | #include "moc_qlineseries.cpp" |
|
211 | #include "moc_qlineseries.cpp" | |
202 |
|
212 | |||
203 | QTCOMMERCIALCHART_END_NAMESPACE |
|
213 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,55 +1,56 | |||||
1 | #ifndef QLINESERIES_H_ |
|
1 | #ifndef QLINESERIES_H_ | |
2 | #define QLINESERIES_H_ |
|
2 | #define QLINESERIES_H_ | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "qseries.h" |
|
5 | #include "qseries.h" | |
6 | #include <QDebug> |
|
6 | #include <QDebug> | |
7 | #include <QPen> |
|
7 | #include <QPen> | |
8 | #include <QBrush> |
|
8 | #include <QBrush> | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 |
|
11 | |||
12 | class QTCOMMERCIALCHART_EXPORT QLineSeries : public QSeries |
|
12 | class QTCOMMERCIALCHART_EXPORT QLineSeries : public QSeries | |
13 | { |
|
13 | { | |
14 | Q_OBJECT |
|
14 | Q_OBJECT | |
15 | public: |
|
15 | public: | |
16 | QLineSeries(QObject* parent=0); |
|
16 | QLineSeries(QObject* parent=0); | |
17 | virtual ~QLineSeries(); |
|
17 | virtual ~QLineSeries(); | |
18 |
|
18 | |||
19 | public: // from QChartSeries |
|
19 | public: // from QChartSeries | |
20 | virtual QSeriesType type() const { return QSeries::SeriesTypeLine;} |
|
20 | virtual QSeriesType type() const { return QSeries::SeriesTypeLine;} | |
21 | void add(qreal x, qreal y); |
|
21 | void add(qreal x, qreal y); | |
22 | void add(const QPointF& point); |
|
22 | void add(const QPointF& point); | |
23 | void replace(qreal x,qreal y); |
|
23 | void replace(qreal x,qreal y); | |
24 | void replace(const QPointF& point); |
|
24 | void replace(const QPointF& point); | |
25 | void remove(qreal x); |
|
25 | void remove(qreal x); | |
26 | void remove(const QPointF& point); |
|
26 | void remove(const QPointF& point); | |
27 | void clear(); |
|
27 | void clear(); | |
28 |
|
28 | |||
29 | void setPen(const QPen& pen); |
|
29 | void setPen(const QPen& pen); | |
30 | QPen pen() const { return m_pen;} |
|
30 | QPen pen() const { return m_pen;} | |
31 |
|
31 | |||
32 | void setPointsVisible(bool visible); |
|
32 | void setPointsVisible(bool visible); | |
33 | bool pointsVisible() const {return m_pointsVisible;} |
|
33 | bool pointsVisible() const {return m_pointsVisible;} | |
34 |
|
34 | |||
35 | int count() const; |
|
35 | int count() const; | |
36 | qreal x(int pos) const; |
|
36 | qreal x(int pos) const; | |
37 | qreal y(int pos) const; |
|
37 | qreal y(int pos) const; | |
38 |
|
38 | |||
39 | QLineSeries& operator << (const QPointF &point); |
|
39 | QLineSeries& operator << (const QPointF &point); | |
40 | friend QDebug operator<< (QDebug d, const QLineSeries series); |
|
40 | friend QDebug operator<< (QDebug d, const QLineSeries series); | |
41 |
|
41 | |||
42 |
|
||||
43 | signals: |
|
42 | signals: | |
44 |
void |
|
43 | void pointChanged(int index); | |
|
44 | void pointRemoved(int index); | |||
|
45 | void pointAdded(int index); | |||
45 |
|
46 | |||
46 | private: |
|
47 | private: | |
47 | QVector<qreal> m_x; |
|
48 | QVector<qreal> m_x; | |
48 | QVector<qreal> m_y; |
|
49 | QVector<qreal> m_y; | |
49 | QPen m_pen; |
|
50 | QPen m_pen; | |
50 | bool m_pointsVisible; |
|
51 | bool m_pointsVisible; | |
51 | }; |
|
52 | }; | |
52 |
|
53 | |||
53 | QTCOMMERCIALCHART_END_NAMESPACE |
|
54 | QTCOMMERCIALCHART_END_NAMESPACE | |
54 |
|
55 | |||
55 | #endif |
|
56 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now