@@ -1,433 +1,433 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qchartseries.h" |
|
2 | #include "qchartseries.h" | |
3 | #include "qscatterseries.h" |
|
3 | #include "qscatterseries.h" | |
4 | #include "qscatterseries_p.h" |
|
4 | #include "qscatterseries_p.h" | |
5 | #include "qpieseries.h" |
|
5 | #include "qpieseries.h" | |
6 | #include "qpieseries_p.h" |
|
6 | #include "qpieseries_p.h" | |
7 | #include "qxychartseries.h" |
|
7 | #include "qxychartseries.h" | |
8 | #include "qchartaxis.h" |
|
8 | #include "qchartaxis.h" | |
9 | #include "barchartseries.h" |
|
9 | #include "barchartseries.h" | |
10 | #include "bargroup.h" |
|
10 | #include "bargroup.h" | |
11 | #include "stackedbarchartseries.h" |
|
11 | #include "stackedbarchartseries.h" | |
12 | #include "stackedbargroup.h" |
|
12 | #include "stackedbargroup.h" | |
13 | #include "percentbarchartseries.h" |
|
13 | #include "percentbarchartseries.h" | |
14 | #include "percentbargroup.h" |
|
14 | #include "percentbargroup.h" | |
15 | #include "charttheme_p.h" |
|
15 | #include "charttheme_p.h" | |
16 | #include "chartitem_p.h" |
|
16 | #include "chartitem_p.h" | |
17 |
|
17 | |||
18 | #include "xylinechartitem_p.h" |
|
18 | #include "xylinechartitem_p.h" | |
19 | #include "plotdomain_p.h" |
|
19 | #include "plotdomain_p.h" | |
20 | #include "axisitem_p.h" |
|
20 | #include "axisitem_p.h" | |
21 | #include <QGraphicsScene> |
|
21 | #include <QGraphicsScene> | |
22 | #include <QGraphicsSceneResizeEvent> |
|
22 | #include <QGraphicsSceneResizeEvent> | |
23 | #include <QDebug> |
|
23 | #include <QDebug> | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
27 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
28 | m_backgroundItem(0), |
|
28 | m_backgroundItem(0), | |
29 | m_titleItem(0), |
|
29 | m_titleItem(0), | |
30 | m_axisXItem(new AxisItem(AxisItem::X_AXIS, this)), |
|
30 | m_axisXItem(new AxisItem(AxisItem::X_AXIS, this)), | |
31 | m_plotDataIndex(0), |
|
31 | m_plotDataIndex(0), | |
32 | m_marginSize(0), |
|
32 | m_marginSize(0), | |
33 | m_chartTheme(new ChartTheme(this)) |
|
33 | m_chartTheme(new ChartTheme(this)) | |
34 | { |
|
34 | { | |
35 | // TODO: the default theme? |
|
35 | // TODO: the default theme? | |
36 | setTheme(QChart::ChartThemeDefault); |
|
36 | setTheme(QChart::ChartThemeDefault); | |
37 |
|
37 | |||
38 | PlotDomain domain; |
|
38 | PlotDomain domain; | |
39 | m_plotDomainList << domain; |
|
39 | m_plotDomainList << domain; | |
40 | m_axisYItem << new AxisItem(AxisItem::Y_AXIS,this); |
|
40 | m_axisYItem << new AxisItem(AxisItem::Y_AXIS,this); | |
41 | m_chartItems << m_axisXItem; |
|
41 | m_chartItems << m_axisXItem; | |
42 | m_chartItems << m_axisYItem.at(0); |
|
42 | m_chartItems << m_axisYItem.at(0); | |
43 | } |
|
43 | } | |
44 |
|
44 | |||
45 | QChart::~QChart(){} |
|
45 | QChart::~QChart(){} | |
46 |
|
46 | |||
47 | void QChart::addSeries(QChartSeries* series) |
|
47 | void QChart::addSeries(QChartSeries* series) | |
48 | { |
|
48 | { | |
49 | // TODO: we should check the series not already added |
|
49 | // TODO: we should check the series not already added | |
50 | Q_ASSERT(series); |
|
50 | Q_ASSERT(series); | |
51 | Q_ASSERT(series->type() != QChartSeries::SeriesTypeInvalid); |
|
51 | Q_ASSERT(series->type() != QChartSeries::SeriesTypeInvalid); | |
52 |
|
52 | |||
53 | m_chartSeries << series; |
|
53 | m_chartSeries << series; | |
54 |
|
54 | |||
55 | m_plotDataIndex = 0 ; |
|
55 | m_plotDataIndex = 0 ; | |
56 | m_plotDomainList.resize(1); |
|
56 | m_plotDomainList.resize(1); | |
57 | PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; |
|
57 | PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; | |
58 |
|
58 | |||
59 | switch(series->type()) |
|
59 | switch(series->type()) | |
60 | { |
|
60 | { | |
61 | case QChartSeries::SeriesTypeLine: { |
|
61 | case QChartSeries::SeriesTypeLine: { | |
62 |
|
62 | |||
63 | QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series); |
|
63 | QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series); | |
64 |
|
64 | |||
65 | for (int i = 0 ; i < xyseries->count() ; i++) { |
|
65 | for (int i = 0 ; i < xyseries->count() ; i++) { | |
66 | qreal x = xyseries->x(i); |
|
66 | qreal x = xyseries->x(i); | |
67 | qreal y = xyseries->y(i); |
|
67 | qreal y = xyseries->y(i); | |
68 | domain.m_minX = qMin(domain.m_minX,x); |
|
68 | domain.m_minX = qMin(domain.m_minX,x); | |
69 | domain.m_minY = qMin(domain.m_minY,y); |
|
69 | domain.m_minY = qMin(domain.m_minY,y); | |
70 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
70 | domain.m_maxX = qMax(domain.m_maxX,x); | |
71 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
71 | domain.m_maxY = qMax(domain.m_maxY,y); | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 |
XYLineChartItem* item = new XYLineChartItem(xyseries, |
|
74 | XYLineChartItem* item = new XYLineChartItem(xyseries, this); | |
75 |
|
75 | |||
76 | m_chartItems << item; |
|
76 | m_chartItems << item; | |
77 | // TODO: |
|
77 | // TODO: | |
78 | //m_chartTheme->addObserver(xyseries); |
|
78 | //m_chartTheme->addObserver(xyseries); | |
79 |
|
79 | |||
80 | break; |
|
80 | break; | |
81 | } |
|
81 | } | |
82 | case QChartSeries::SeriesTypeBar: { |
|
82 | case QChartSeries::SeriesTypeBar: { | |
83 |
|
83 | |||
84 | qDebug() << "barSeries added"; |
|
84 | qDebug() << "barSeries added"; | |
85 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); |
|
85 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); | |
86 | BarGroup* barGroup = new BarGroup(*barSeries,this); |
|
86 | BarGroup* barGroup = new BarGroup(*barSeries,this); | |
87 |
|
87 | |||
88 | // Add some fugly colors for 5 fist series... |
|
88 | // Add some fugly colors for 5 fist series... | |
89 | barGroup->addColor(QColor(255,0,0,128)); |
|
89 | barGroup->addColor(QColor(255,0,0,128)); | |
90 | barGroup->addColor(QColor(255,255,0,128)); |
|
90 | barGroup->addColor(QColor(255,255,0,128)); | |
91 | barGroup->addColor(QColor(0,255,0,128)); |
|
91 | barGroup->addColor(QColor(0,255,0,128)); | |
92 | barGroup->addColor(QColor(0,0,255,128)); |
|
92 | barGroup->addColor(QColor(0,0,255,128)); | |
93 | barGroup->addColor(QColor(255,128,0,128)); |
|
93 | barGroup->addColor(QColor(255,128,0,128)); | |
94 |
|
94 | |||
95 | m_chartItems << barGroup; |
|
95 | m_chartItems << barGroup; | |
96 | childItems().append(barGroup); |
|
96 | childItems().append(barGroup); | |
97 |
|
97 | |||
98 | qreal x = barSeries->countColumns(); |
|
98 | qreal x = barSeries->countColumns(); | |
99 | qreal y = barSeries->max(); |
|
99 | qreal y = barSeries->max(); | |
100 | domain.m_minX = qMin(domain.m_minX,x); |
|
100 | domain.m_minX = qMin(domain.m_minX,x); | |
101 | domain.m_minY = qMin(domain.m_minY,y); |
|
101 | domain.m_minY = qMin(domain.m_minY,y); | |
102 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
102 | domain.m_maxX = qMax(domain.m_maxX,x); | |
103 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
103 | domain.m_maxY = qMax(domain.m_maxY,y); | |
104 | m_axisXItem->setVisible(false); |
|
104 | m_axisXItem->setVisible(false); | |
105 | break; |
|
105 | break; | |
106 | } |
|
106 | } | |
107 | case QChartSeries::SeriesTypeStackedBar: { |
|
107 | case QChartSeries::SeriesTypeStackedBar: { | |
108 |
|
108 | |||
109 | qDebug() << "barSeries added"; |
|
109 | qDebug() << "barSeries added"; | |
110 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); |
|
110 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); | |
111 | StackedBarGroup* stackedBarGroup = new StackedBarGroup(*stackedBarSeries,this); |
|
111 | StackedBarGroup* stackedBarGroup = new StackedBarGroup(*stackedBarSeries,this); | |
112 |
|
112 | |||
113 | // Add some fugly colors for 5 fist series... |
|
113 | // Add some fugly colors for 5 fist series... | |
114 | stackedBarGroup->addColor(QColor(255,0,0,128)); |
|
114 | stackedBarGroup->addColor(QColor(255,0,0,128)); | |
115 | stackedBarGroup->addColor(QColor(255,255,0,128)); |
|
115 | stackedBarGroup->addColor(QColor(255,255,0,128)); | |
116 | stackedBarGroup->addColor(QColor(0,255,0,128)); |
|
116 | stackedBarGroup->addColor(QColor(0,255,0,128)); | |
117 | stackedBarGroup->addColor(QColor(0,0,255,128)); |
|
117 | stackedBarGroup->addColor(QColor(0,0,255,128)); | |
118 | stackedBarGroup->addColor(QColor(255,128,0,128)); |
|
118 | stackedBarGroup->addColor(QColor(255,128,0,128)); | |
119 |
|
119 | |||
120 | m_chartItems << stackedBarGroup; |
|
120 | m_chartItems << stackedBarGroup; | |
121 | childItems().append(stackedBarGroup); |
|
121 | childItems().append(stackedBarGroup); | |
122 |
|
122 | |||
123 | qreal x = stackedBarSeries->countColumns(); |
|
123 | qreal x = stackedBarSeries->countColumns(); | |
124 | qreal y = stackedBarSeries->maxColumnSum(); |
|
124 | qreal y = stackedBarSeries->maxColumnSum(); | |
125 | domain.m_minX = qMin(domain.m_minX,x); |
|
125 | domain.m_minX = qMin(domain.m_minX,x); | |
126 | domain.m_minY = qMin(domain.m_minY,y); |
|
126 | domain.m_minY = qMin(domain.m_minY,y); | |
127 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
127 | domain.m_maxX = qMax(domain.m_maxX,x); | |
128 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
128 | domain.m_maxY = qMax(domain.m_maxY,y); | |
129 | m_axisXItem->setVisible(false); |
|
129 | m_axisXItem->setVisible(false); | |
130 | break; |
|
130 | break; | |
131 | } |
|
131 | } | |
132 | case QChartSeries::SeriesTypePercentBar: { |
|
132 | case QChartSeries::SeriesTypePercentBar: { | |
133 |
|
133 | |||
134 | qDebug() << "barSeries added"; |
|
134 | qDebug() << "barSeries added"; | |
135 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); |
|
135 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); | |
136 | PercentBarGroup* percentBarGroup = new PercentBarGroup(*percentBarSeries,this); |
|
136 | PercentBarGroup* percentBarGroup = new PercentBarGroup(*percentBarSeries,this); | |
137 |
|
137 | |||
138 | // Add some fugly colors for 5 fist series... |
|
138 | // Add some fugly colors for 5 fist series... | |
139 | percentBarGroup->addColor(QColor(255,0,0,128)); |
|
139 | percentBarGroup->addColor(QColor(255,0,0,128)); | |
140 | percentBarGroup->addColor(QColor(255,255,0,128)); |
|
140 | percentBarGroup->addColor(QColor(255,255,0,128)); | |
141 | percentBarGroup->addColor(QColor(0,255,0,128)); |
|
141 | percentBarGroup->addColor(QColor(0,255,0,128)); | |
142 | percentBarGroup->addColor(QColor(0,0,255,128)); |
|
142 | percentBarGroup->addColor(QColor(0,0,255,128)); | |
143 | percentBarGroup->addColor(QColor(255,128,0,128)); |
|
143 | percentBarGroup->addColor(QColor(255,128,0,128)); | |
144 |
|
144 | |||
145 | m_chartItems << percentBarGroup; |
|
145 | m_chartItems << percentBarGroup; | |
146 | childItems().append(percentBarGroup); |
|
146 | childItems().append(percentBarGroup); | |
147 |
|
147 | |||
148 | qreal x = percentBarSeries->countColumns(); |
|
148 | qreal x = percentBarSeries->countColumns(); | |
149 | domain.m_minX = qMin(domain.m_minX,x); |
|
149 | domain.m_minX = qMin(domain.m_minX,x); | |
150 | domain.m_minY = 0; |
|
150 | domain.m_minY = 0; | |
151 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
151 | domain.m_maxX = qMax(domain.m_maxX,x); | |
152 | domain.m_maxY = 100; |
|
152 | domain.m_maxY = 100; | |
153 | m_axisXItem->setVisible(false); |
|
153 | m_axisXItem->setVisible(false); | |
154 | break; |
|
154 | break; | |
155 | } |
|
155 | } | |
156 | case QChartSeries::SeriesTypeScatter: { |
|
156 | case QChartSeries::SeriesTypeScatter: { | |
157 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
157 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
158 | scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); |
|
158 | scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); | |
159 | scatterSeries->d->setParentItem(this); |
|
159 | scatterSeries->d->setParentItem(this); | |
160 | scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
160 | scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
161 | m_chartItems << scatterSeries->d; |
|
161 | m_chartItems << scatterSeries->d; | |
162 | m_chartTheme->addObserver(scatterSeries->d); |
|
162 | m_chartTheme->addObserver(scatterSeries->d); | |
163 |
|
163 | |||
164 | foreach (qreal x, scatterSeries->d->m_x) { |
|
164 | foreach (qreal x, scatterSeries->d->m_x) { | |
165 | domain.m_minX = qMin(domain.m_minX, x); |
|
165 | domain.m_minX = qMin(domain.m_minX, x); | |
166 | domain.m_maxX = qMax(domain.m_maxX, x); |
|
166 | domain.m_maxX = qMax(domain.m_maxX, x); | |
167 | } |
|
167 | } | |
168 | foreach (qreal y, scatterSeries->d->m_y) { |
|
168 | foreach (qreal y, scatterSeries->d->m_y) { | |
169 | domain.m_minY = qMin(domain.m_minY, y); |
|
169 | domain.m_minY = qMin(domain.m_minY, y); | |
170 | domain.m_maxY = qMax(domain.m_maxY, y); |
|
170 | domain.m_maxY = qMax(domain.m_maxY, y); | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | break; |
|
173 | break; | |
174 | } |
|
174 | } | |
175 | case QChartSeries::SeriesTypePie: { |
|
175 | case QChartSeries::SeriesTypePie: { | |
176 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); |
|
176 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); | |
177 | pieSeries->d->setParentItem(this); |
|
177 | pieSeries->d->setParentItem(this); | |
178 | m_chartItems << pieSeries->d; |
|
178 | m_chartItems << pieSeries->d; | |
179 | pieSeries->d->m_chartTheme = m_chartTheme; |
|
179 | pieSeries->d->m_chartTheme = m_chartTheme; | |
180 | m_chartTheme->addObserver(pieSeries->d); |
|
180 | m_chartTheme->addObserver(pieSeries->d); | |
181 | break; |
|
181 | break; | |
182 | } |
|
182 | } | |
183 | default: |
|
183 | default: | |
184 | break; |
|
184 | break; | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | // Update all the items to match the new visible area of the chart |
|
187 | // Update all the items to match the new visible area of the chart | |
188 | foreach(ChartItem* i, m_chartItems) |
|
188 | foreach(ChartItem* i, m_chartItems) | |
189 | i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex)); |
|
189 | i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex)); | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) |
|
192 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) | |
193 | { |
|
193 | { | |
194 | // TODO: support also other types; not only scatter and pie |
|
194 | // TODO: support also other types; not only scatter and pie | |
195 |
|
195 | |||
196 | QChartSeries *series(0); |
|
196 | QChartSeries *series(0); | |
197 |
|
197 | |||
198 | switch (type) { |
|
198 | switch (type) { | |
199 | case QChartSeries::SeriesTypeLine: { |
|
199 | case QChartSeries::SeriesTypeLine: { | |
200 | series = QXYChartSeries::create(); |
|
200 | series = QXYChartSeries::create(); | |
201 | break; |
|
201 | break; | |
202 | } |
|
202 | } | |
203 | case QChartSeries::SeriesTypeBar: { |
|
203 | case QChartSeries::SeriesTypeBar: { | |
204 | series = new BarChartSeries(this); |
|
204 | series = new BarChartSeries(this); | |
205 | break; |
|
205 | break; | |
206 | } |
|
206 | } | |
207 | case QChartSeries::SeriesTypeStackedBar: { |
|
207 | case QChartSeries::SeriesTypeStackedBar: { | |
208 | series = new StackedBarChartSeries(this); |
|
208 | series = new StackedBarChartSeries(this); | |
209 | break; |
|
209 | break; | |
210 | } |
|
210 | } | |
211 | case QChartSeries::SeriesTypePercentBar: { |
|
211 | case QChartSeries::SeriesTypePercentBar: { | |
212 | series = new PercentBarChartSeries(this); |
|
212 | series = new PercentBarChartSeries(this); | |
213 | break; |
|
213 | break; | |
214 | } |
|
214 | } | |
215 | case QChartSeries::SeriesTypeScatter: { |
|
215 | case QChartSeries::SeriesTypeScatter: { | |
216 | series = new QScatterSeries(this); |
|
216 | series = new QScatterSeries(this); | |
217 | break; |
|
217 | break; | |
218 | } |
|
218 | } | |
219 | case QChartSeries::SeriesTypePie: { |
|
219 | case QChartSeries::SeriesTypePie: { | |
220 | series = new QPieSeries(this); |
|
220 | series = new QPieSeries(this); | |
221 | break; |
|
221 | break; | |
222 | } |
|
222 | } | |
223 | default: |
|
223 | default: | |
224 | Q_ASSERT(false); |
|
224 | Q_ASSERT(false); | |
225 | break; |
|
225 | break; | |
226 | } |
|
226 | } | |
227 |
|
227 | |||
228 | addSeries(series); |
|
228 | addSeries(series); | |
229 | return series; |
|
229 | return series; | |
230 | } |
|
230 | } | |
231 |
|
231 | |||
232 | void QChart::setBackground(const QColor& startColor, const QColor& endColor, GradientOrientation orientation) |
|
232 | void QChart::setBackground(const QColor& startColor, const QColor& endColor, GradientOrientation orientation) | |
233 | { |
|
233 | { | |
234 |
|
234 | |||
235 | if(!m_backgroundItem){ |
|
235 | if(!m_backgroundItem){ | |
236 | m_backgroundItem = new QGraphicsRectItem(this); |
|
236 | m_backgroundItem = new QGraphicsRectItem(this); | |
237 | m_backgroundItem->setZValue(-1); |
|
237 | m_backgroundItem->setZValue(-1); | |
238 | } |
|
238 | } | |
239 |
|
239 | |||
240 | m_bacgroundOrinetation = orientation; |
|
240 | m_bacgroundOrinetation = orientation; | |
241 | m_backgroundGradient.setColorAt(0.0, startColor); |
|
241 | m_backgroundGradient.setColorAt(0.0, startColor); | |
242 | m_backgroundGradient.setColorAt(1.0, endColor); |
|
242 | m_backgroundGradient.setColorAt(1.0, endColor); | |
243 | m_backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
243 | m_backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
244 |
|
244 | |||
245 | if(orientation == VerticalGradientOrientation){ |
|
245 | if(orientation == VerticalGradientOrientation){ | |
246 | m_backgroundGradient.setFinalStop(0,1); |
|
246 | m_backgroundGradient.setFinalStop(0,1); | |
247 | }else{ |
|
247 | }else{ | |
248 | m_backgroundGradient.setFinalStop(1,0); |
|
248 | m_backgroundGradient.setFinalStop(1,0); | |
249 | } |
|
249 | } | |
250 |
|
250 | |||
251 | m_backgroundItem->setBrush(m_backgroundGradient); |
|
251 | m_backgroundItem->setBrush(m_backgroundGradient); | |
252 | m_backgroundItem->setPen(Qt::NoPen); |
|
252 | m_backgroundItem->setPen(Qt::NoPen); | |
253 | m_backgroundItem->update(); |
|
253 | m_backgroundItem->update(); | |
254 | } |
|
254 | } | |
255 |
|
255 | |||
256 | void QChart::setChartBackgroundBrush(const QBrush& brush) |
|
256 | void QChart::setChartBackgroundBrush(const QBrush& brush) | |
257 | { |
|
257 | { | |
258 |
|
258 | |||
259 | if(!m_backgroundItem){ |
|
259 | if(!m_backgroundItem){ | |
260 | m_backgroundItem = new QGraphicsRectItem(this); |
|
260 | m_backgroundItem = new QGraphicsRectItem(this); | |
261 | m_backgroundItem->setZValue(-1); |
|
261 | m_backgroundItem->setZValue(-1); | |
262 | } |
|
262 | } | |
263 |
|
263 | |||
264 | m_backgroundItem->setBrush(brush); |
|
264 | m_backgroundItem->setBrush(brush); | |
265 | m_backgroundItem->update(); |
|
265 | m_backgroundItem->update(); | |
266 | } |
|
266 | } | |
267 |
|
267 | |||
268 | void QChart::setChartBackgroundPen(const QPen& pen) |
|
268 | void QChart::setChartBackgroundPen(const QPen& pen) | |
269 | { |
|
269 | { | |
270 |
|
270 | |||
271 | if(!m_backgroundItem){ |
|
271 | if(!m_backgroundItem){ | |
272 | m_backgroundItem = new QGraphicsRectItem(this); |
|
272 | m_backgroundItem = new QGraphicsRectItem(this); | |
273 | m_backgroundItem->setZValue(-1); |
|
273 | m_backgroundItem->setZValue(-1); | |
274 | } |
|
274 | } | |
275 |
|
275 | |||
276 | m_backgroundItem->setPen(pen); |
|
276 | m_backgroundItem->setPen(pen); | |
277 | m_backgroundItem->update(); |
|
277 | m_backgroundItem->update(); | |
278 | } |
|
278 | } | |
279 |
|
279 | |||
280 | void QChart::setTitle(const QString& title,const QFont& font) |
|
280 | void QChart::setTitle(const QString& title,const QFont& font) | |
281 | { |
|
281 | { | |
282 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); |
|
282 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); | |
283 | m_titleItem->setPlainText(title); |
|
283 | m_titleItem->setPlainText(title); | |
284 | m_titleItem->setFont(font); |
|
284 | m_titleItem->setFont(font); | |
285 | } |
|
285 | } | |
286 |
|
286 | |||
287 | int QChart::margin() const |
|
287 | int QChart::margin() const | |
288 | { |
|
288 | { | |
289 | return m_marginSize; |
|
289 | return m_marginSize; | |
290 | } |
|
290 | } | |
291 |
|
291 | |||
292 | void QChart::setMargin(int margin) |
|
292 | void QChart::setMargin(int margin) | |
293 | { |
|
293 | { | |
294 | m_marginSize = margin; |
|
294 | m_marginSize = margin; | |
295 | } |
|
295 | } | |
296 |
|
296 | |||
297 | void QChart::setTheme(QChart::ChartThemeId theme) |
|
297 | void QChart::setTheme(QChart::ChartThemeId theme) | |
298 | { |
|
298 | { | |
299 | m_chartTheme->setTheme(theme); |
|
299 | m_chartTheme->setTheme(theme); | |
300 | setBackground(m_chartTheme->d->m_gradientStartColor, |
|
300 | setBackground(m_chartTheme->d->m_gradientStartColor, | |
301 | m_chartTheme->d->m_gradientEndColor, |
|
301 | m_chartTheme->d->m_gradientEndColor, | |
302 | m_bacgroundOrinetation); |
|
302 | m_bacgroundOrinetation); | |
303 |
|
303 | |||
304 | // TODO: Move the controlling of the series presentations into private implementation of the |
|
304 | // TODO: Move the controlling of the series presentations into private implementation of the | |
305 | // series instead of QChart controlling themes for each |
|
305 | // series instead of QChart controlling themes for each | |
306 | // In other words, the following should be used when creating xy series: |
|
306 | // In other words, the following should be used when creating xy series: | |
307 | // m_chartTheme->addObserver(xyseries) |
|
307 | // m_chartTheme->addObserver(xyseries) | |
308 | foreach (QChartSeries *series, m_chartSeries) { |
|
308 | foreach (QChartSeries *series, m_chartSeries) { | |
309 | if (series->type() == QChartSeries::SeriesTypeLine) { |
|
309 | if (series->type() == QChartSeries::SeriesTypeLine) { | |
310 | QXYChartSeries *xyseries = static_cast<QXYChartSeries *>(series); |
|
310 | QXYChartSeries *xyseries = static_cast<QXYChartSeries *>(series); | |
311 | SeriesTheme seriesTheme = m_chartTheme->themeForSeries(); |
|
311 | SeriesTheme seriesTheme = m_chartTheme->themeForSeries(); | |
312 | xyseries->setPen(seriesTheme.linePen); |
|
312 | xyseries->setPen(seriesTheme.linePen); | |
313 | } |
|
313 | } | |
314 | } |
|
314 | } | |
315 |
|
315 | |||
316 | update(); |
|
316 | update(); | |
317 | } |
|
317 | } | |
318 |
|
318 | |||
319 | QChart::ChartThemeId QChart::theme() |
|
319 | QChart::ChartThemeId QChart::theme() | |
320 | { |
|
320 | { | |
321 | return (QChart::ChartThemeId) m_chartTheme->d->m_currentTheme; |
|
321 | return (QChart::ChartThemeId) m_chartTheme->d->m_currentTheme; | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 | void QChart::zoomInToRect(const QRectF& rectangle) |
|
324 | void QChart::zoomInToRect(const QRectF& rectangle) | |
325 | { |
|
325 | { | |
326 |
|
326 | |||
327 | if(!rectangle.isValid()) return; |
|
327 | if(!rectangle.isValid()) return; | |
328 |
|
328 | |||
329 | qreal margin = this->margin(); |
|
329 | qreal margin = this->margin(); | |
330 |
|
330 | |||
331 | QRectF rect = rectangle.normalized(); |
|
331 | QRectF rect = rectangle.normalized(); | |
332 | rect.translate(-margin, -margin); |
|
332 | rect.translate(-margin, -margin); | |
333 |
|
333 | |||
334 | PlotDomain& oldDomain = m_plotDomainList[m_plotDataIndex]; |
|
334 | PlotDomain& oldDomain = m_plotDomainList[m_plotDataIndex]; | |
335 |
|
335 | |||
336 | PlotDomain domain = oldDomain.subDomain(rect,m_rect.width() - 2 * margin,m_rect.height() - 2 * margin); |
|
336 | PlotDomain domain = oldDomain.subDomain(rect,m_rect.width() - 2 * margin,m_rect.height() - 2 * margin); | |
337 |
|
337 | |||
338 | m_plotDomainList.resize(m_plotDataIndex + 1); |
|
338 | m_plotDomainList.resize(m_plotDataIndex + 1); | |
339 | m_plotDomainList<<domain; |
|
339 | m_plotDomainList<<domain; | |
340 | m_plotDataIndex++; |
|
340 | m_plotDataIndex++; | |
341 |
|
341 | |||
342 | foreach (ChartItem* item, m_chartItems) |
|
342 | foreach (ChartItem* item, m_chartItems) | |
343 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); |
|
343 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); | |
344 | update(); |
|
344 | update(); | |
345 | } |
|
345 | } | |
346 |
|
346 | |||
347 | void QChart::zoomIn() |
|
347 | void QChart::zoomIn() | |
348 | { |
|
348 | { | |
349 | if (m_plotDataIndex < m_plotDomainList.count() - 1) { |
|
349 | if (m_plotDataIndex < m_plotDomainList.count() - 1) { | |
350 | m_plotDataIndex++; |
|
350 | m_plotDataIndex++; | |
351 | foreach (ChartItem* item, m_chartItems) |
|
351 | foreach (ChartItem* item, m_chartItems) | |
352 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); |
|
352 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); | |
353 | update(); |
|
353 | update(); | |
354 | } else { |
|
354 | } else { | |
355 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
355 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
356 | rect.setWidth(rect.width()/2); |
|
356 | rect.setWidth(rect.width()/2); | |
357 | rect.setHeight(rect.height()/2); |
|
357 | rect.setHeight(rect.height()/2); | |
358 | rect.moveCenter(m_rect.center()); |
|
358 | rect.moveCenter(m_rect.center()); | |
359 | zoomInToRect(rect); |
|
359 | zoomInToRect(rect); | |
360 | } |
|
360 | } | |
361 | } |
|
361 | } | |
362 |
|
362 | |||
363 | void QChart::zoomOut() |
|
363 | void QChart::zoomOut() | |
364 | { |
|
364 | { | |
365 | if (m_plotDataIndex > 0) { |
|
365 | if (m_plotDataIndex > 0) { | |
366 | m_plotDataIndex--; |
|
366 | m_plotDataIndex--; | |
367 | foreach (ChartItem* item, m_chartItems) |
|
367 | foreach (ChartItem* item, m_chartItems) | |
368 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); |
|
368 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); | |
369 | update(); |
|
369 | update(); | |
370 | } |
|
370 | } | |
371 | } |
|
371 | } | |
372 |
|
372 | |||
373 | void QChart::zoomReset() |
|
373 | void QChart::zoomReset() | |
374 | { |
|
374 | { | |
375 | if (m_plotDataIndex > 0) { |
|
375 | if (m_plotDataIndex > 0) { | |
376 | m_plotDataIndex = 0; |
|
376 | m_plotDataIndex = 0; | |
377 | foreach (ChartItem* item, m_chartItems) |
|
377 | foreach (ChartItem* item, m_chartItems) | |
378 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); |
|
378 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); | |
379 | update(); |
|
379 | update(); | |
380 | } |
|
380 | } | |
381 | } |
|
381 | } | |
382 |
|
382 | |||
383 | void QChart::setAxisX(const QChartAxis& axis) |
|
383 | void QChart::setAxisX(const QChartAxis& axis) | |
384 | { |
|
384 | { | |
385 | setAxis(m_axisXItem,axis); |
|
385 | setAxis(m_axisXItem,axis); | |
386 | } |
|
386 | } | |
387 | void QChart::setAxisY(const QChartAxis& axis) |
|
387 | void QChart::setAxisY(const QChartAxis& axis) | |
388 | { |
|
388 | { | |
389 | setAxis(m_axisYItem.at(0),axis); |
|
389 | setAxis(m_axisYItem.at(0),axis); | |
390 | } |
|
390 | } | |
391 |
|
391 | |||
392 | void QChart::setAxisY(const QList<QChartAxis>& axis) |
|
392 | void QChart::setAxisY(const QList<QChartAxis>& axis) | |
393 | { |
|
393 | { | |
394 | //TODO not implemented |
|
394 | //TODO not implemented | |
395 | } |
|
395 | } | |
396 |
|
396 | |||
397 | void QChart::setAxis(AxisItem *item, const QChartAxis& axis) |
|
397 | void QChart::setAxis(AxisItem *item, const QChartAxis& axis) | |
398 | { |
|
398 | { | |
399 | item->setVisible(axis.isAxisVisible()); |
|
399 | item->setVisible(axis.isAxisVisible()); | |
400 | } |
|
400 | } | |
401 |
|
401 | |||
402 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
402 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
403 | { |
|
403 | { | |
404 |
|
404 | |||
405 | m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
405 | m_rect = QRectF(QPoint(0,0),event->newSize()); | |
406 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
406 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
407 |
|
407 | |||
408 | // recalculate title position |
|
408 | // recalculate title position | |
409 | if (m_titleItem) { |
|
409 | if (m_titleItem) { | |
410 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
410 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
411 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); |
|
411 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); | |
412 | } |
|
412 | } | |
413 |
|
413 | |||
414 | //recalculate background gradient |
|
414 | //recalculate background gradient | |
415 | if (m_backgroundItem) { |
|
415 | if (m_backgroundItem) { | |
416 | m_backgroundItem->setRect(rect); |
|
416 | m_backgroundItem->setRect(rect); | |
417 | } |
|
417 | } | |
418 |
|
418 | |||
419 | // resize and reposition childs |
|
419 | // resize and reposition childs | |
420 | foreach (ChartItem *item, m_chartItems) { |
|
420 | foreach (ChartItem *item, m_chartItems) { | |
421 | item->setPos(rect.topLeft()); |
|
421 | item->setPos(rect.topLeft()); | |
422 | item->setSize(rect.size()); |
|
422 | item->setSize(rect.size()); | |
423 | } |
|
423 | } | |
424 |
|
424 | |||
425 | QGraphicsWidget::resizeEvent(event); |
|
425 | QGraphicsWidget::resizeEvent(event); | |
426 | update(); |
|
426 | update(); | |
427 | } |
|
427 | } | |
428 |
|
428 | |||
429 |
|
429 | |||
430 |
|
430 | |||
431 | #include "moc_qchart.cpp" |
|
431 | #include "moc_qchart.cpp" | |
432 |
|
432 | |||
433 | QTCOMMERCIALCHART_END_NAMESPACE |
|
433 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now