@@ -1,395 +1,394 | |||||
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 "qxychartseries.h" |
|
6 | #include "qxychartseries.h" | |
7 | #include "qchartaxis.h" |
|
7 | #include "qchartaxis.h" | |
8 | #include "barchartseries.h" |
|
8 | #include "barchartseries.h" | |
9 | #include "bargroup.h" |
|
9 | #include "bargroup.h" | |
10 |
|
10 | |||
11 | #include "xylinechartitem_p.h" |
|
11 | #include "xylinechartitem_p.h" | |
12 | #include "plotdomain_p.h" |
|
12 | #include "plotdomain_p.h" | |
13 | #include "axisitem_p.h" |
|
13 | #include "axisitem_p.h" | |
14 | #include <QGraphicsScene> |
|
14 | #include <QGraphicsScene> | |
15 | #include <QDebug> |
|
15 | #include <QDebug> | |
16 |
|
16 | |||
17 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
17 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
18 |
|
18 | |||
19 | QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent), |
|
19 | QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent), | |
20 | m_backgroundItem(0), |
|
20 | m_backgroundItem(0), | |
21 | m_titleItem(0), |
|
21 | m_titleItem(0), | |
22 | m_axisXItem(new AxisItem(AxisItem::X_AXIS,this)), |
|
22 | m_axisXItem(new AxisItem(AxisItem::X_AXIS,this)), | |
23 | m_plotDataIndex(0), |
|
23 | m_plotDataIndex(0), | |
24 | m_marginSize(0) |
|
24 | m_marginSize(0) | |
25 | { |
|
25 | { | |
26 | // TODO: the default theme? |
|
26 | // TODO: the default theme? | |
27 |
|
|
27 | setTheme(QChart::ChartThemeDefault); | |
28 |
|
28 | |||
29 | PlotDomain domain; |
|
29 | PlotDomain domain; | |
30 | m_plotDomainList<<domain; |
|
30 | m_plotDomainList<<domain; | |
31 | m_axisYItem << new AxisItem(AxisItem::Y_AXIS,this); |
|
31 | m_axisYItem << new AxisItem(AxisItem::Y_AXIS,this); | |
32 | m_chartItems<<m_axisXItem; |
|
32 | m_chartItems<<m_axisXItem; | |
33 | m_chartItems<<m_axisYItem.at(0); |
|
33 | m_chartItems<<m_axisYItem.at(0); | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | QChart::~QChart(){} |
|
36 | QChart::~QChart(){} | |
37 |
|
37 | |||
38 | QRectF QChart::boundingRect() const |
|
38 | QRectF QChart::boundingRect() const | |
39 | { |
|
39 | { | |
40 | return m_rect; |
|
40 | return m_rect; | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | void QChart::addSeries(QChartSeries* series) |
|
43 | void QChart::addSeries(QChartSeries* series) | |
44 | { |
|
44 | { | |
45 | // TODO: we should check the series not already added |
|
45 | // TODO: we should check the series not already added | |
46 |
|
46 | |||
47 | m_chartSeries << series; |
|
47 | m_chartSeries << series; | |
48 |
|
48 | |||
49 | switch(series->type()) |
|
49 | switch(series->type()) | |
50 | { |
|
50 | { | |
51 | case QChartSeries::SeriesTypeLine: { |
|
51 | case QChartSeries::SeriesTypeLine: { | |
52 |
|
52 | |||
53 | QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series); |
|
53 | QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series); | |
54 | // Use color defined by theme in case the series does not define a custom color |
|
54 | // Use color defined by theme in case the series does not define a custom color | |
55 |
|
55 | |||
56 | if (!xyseries->pen().color().isValid() && m_themeColors.count()) //TODO: wtf |
|
56 | if (!xyseries->pen().color().isValid() && m_themeColors.count()) //TODO: wtf | |
57 | xyseries->setPen(nextColor()); |
|
57 | xyseries->setPen(nextColor()); | |
58 |
|
58 | |||
59 | m_plotDataIndex = 0 ; |
|
59 | m_plotDataIndex = 0 ; | |
60 | m_plotDomainList.resize(1); |
|
60 | m_plotDomainList.resize(1); | |
61 |
|
61 | |||
62 | PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; |
|
62 | PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; | |
63 |
|
63 | |||
64 | for (int i = 0 ; i < xyseries->count() ; i++) |
|
64 | for (int i = 0 ; i < xyseries->count() ; i++) | |
65 | { |
|
65 | { | |
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,this); |
|
74 | XYLineChartItem* item = new XYLineChartItem(xyseries,this); | |
75 | m_chartItems<<item; |
|
75 | m_chartItems<<item; | |
76 |
|
76 | |||
77 | foreach(ChartItem* i ,m_chartItems) |
|
77 | foreach(ChartItem* i ,m_chartItems) | |
78 | i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex)); |
|
78 | i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex)); | |
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 | break; |
|
97 | break; | |
98 | } |
|
98 | } | |
99 | case QChartSeries::SeriesTypeScatter: { |
|
99 | case QChartSeries::SeriesTypeScatter: { | |
100 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
100 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
101 | scatterSeries->d->setParentItem(this); |
|
101 | scatterSeries->d->setParentItem(this); | |
102 | // Set pre-defined colors in case the series has no colors defined |
|
102 | // Set pre-defined colors in case the series has no colors defined | |
103 | if (!scatterSeries->markerColor().isValid()) |
|
103 | if (!scatterSeries->markerColor().isValid()) | |
104 | scatterSeries->setMarkerColor(nextColor()); |
|
104 | scatterSeries->setMarkerColor(nextColor()); | |
105 | connect(this, SIGNAL(sizeChanged(QRectF)), |
|
105 | connect(this, SIGNAL(sizeChanged(QRectF)), | |
106 | scatterSeries, SLOT(chartSizeChanged(QRectF))); |
|
106 | scatterSeries, SLOT(chartSizeChanged(QRectF))); | |
107 | // QColor nextColor = m_themeColors.takeFirst(); |
|
107 | // QColor nextColor = m_themeColors.takeFirst(); | |
108 | // nextColor.setAlpha(150); // TODO: default opacity? |
|
108 | // nextColor.setAlpha(150); // TODO: default opacity? | |
109 | // scatterSeries->setMarkerColor(nextColor); |
|
109 | // scatterSeries->setMarkerColor(nextColor); | |
110 | break; |
|
110 | break; | |
111 | } |
|
111 | } | |
112 | case QChartSeries::SeriesTypePie: { |
|
112 | case QChartSeries::SeriesTypePie: { | |
113 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); |
|
113 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); | |
114 | for (int i(0); i < pieSeries->sliceCount(); i++) { |
|
114 | for (int i(0); i < pieSeries->sliceCount(); i++) { | |
115 | if (!pieSeries->sliceColor(i).isValid()) |
|
115 | if (!pieSeries->sliceColor(i).isValid()) | |
116 | pieSeries->setSliceColor(i, nextColor()); |
|
116 | pieSeries->setSliceColor(i, nextColor()); | |
117 | } |
|
117 | } | |
118 | connect(this, SIGNAL(sizeChanged(QRectF)), |
|
118 | connect(this, SIGNAL(sizeChanged(QRectF)), | |
119 | pieSeries, SLOT(chartSizeChanged(QRectF))); |
|
119 | pieSeries, SLOT(chartSizeChanged(QRectF))); | |
120 |
|
120 | |||
121 | // Set pre-defined colors in case the series has no colors defined |
|
121 | // Set pre-defined colors in case the series has no colors defined | |
122 | // TODO: how to define the color for all the slices of a pie? |
|
122 | // TODO: how to define the color for all the slices of a pie? | |
123 | // for (int (i); i < pieSeries.sliceCount(); i++) |
|
123 | // for (int (i); i < pieSeries.sliceCount(); i++) | |
124 | break; |
|
124 | break; | |
125 | } |
|
125 | } | |
126 | } |
|
126 | } | |
127 | } |
|
127 | } | |
128 |
|
128 | |||
129 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) |
|
129 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) | |
130 | { |
|
130 | { | |
131 | // TODO: support also other types; not only scatter and pie |
|
131 | // TODO: support also other types; not only scatter and pie | |
132 |
|
132 | |||
133 | QChartSeries *series(0); |
|
133 | QChartSeries *series(0); | |
134 |
|
134 | |||
135 | switch (type) { |
|
135 | switch (type) { | |
136 | case QChartSeries::SeriesTypeLine: { |
|
136 | case QChartSeries::SeriesTypeLine: { | |
137 | series = QXYChartSeries::create(); |
|
137 | series = QXYChartSeries::create(); | |
138 | break; |
|
138 | break; | |
139 | } |
|
139 | } | |
140 | case QChartSeries::SeriesTypeBar: { |
|
140 | case QChartSeries::SeriesTypeBar: { | |
141 | series = new BarChartSeries(this); |
|
141 | series = new BarChartSeries(this); | |
142 | break; |
|
142 | break; | |
143 | } |
|
143 | } | |
144 | case QChartSeries::SeriesTypeScatter: { |
|
144 | case QChartSeries::SeriesTypeScatter: { | |
145 | series = new QScatterSeries(this); |
|
145 | series = new QScatterSeries(this); | |
146 | break; |
|
146 | break; | |
147 | } |
|
147 | } | |
148 | case QChartSeries::SeriesTypePie: { |
|
148 | case QChartSeries::SeriesTypePie: { | |
149 | series = new QPieSeries(this); |
|
149 | series = new QPieSeries(this); | |
150 | break; |
|
150 | break; | |
151 | } |
|
151 | } | |
152 | default: |
|
152 | default: | |
153 | Q_ASSERT(false); |
|
153 | Q_ASSERT(false); | |
154 | break; |
|
154 | break; | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | addSeries(series); |
|
157 | addSeries(series); | |
158 | return series; |
|
158 | return series; | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | void QChart::setSize(const QSize& size) |
|
161 | void QChart::setSize(const QSize& size) | |
162 | { |
|
162 | { | |
163 | m_rect = QRect(QPoint(0,0),size); |
|
163 | m_rect = QRect(QPoint(0,0),size); | |
164 | QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
164 | QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
165 |
|
165 | |||
166 | //recaculate title |
|
166 | //recaculate title | |
167 | if(m_titleItem){ |
|
167 | if(m_titleItem){ | |
168 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
168 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
169 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); |
|
169 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); | |
170 |
|
170 | |||
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | //recalculate background gradient |
|
173 | //recalculate background gradient | |
174 | if(m_backgroundItem){ |
|
174 | if(m_backgroundItem){ | |
175 | m_backgroundItem->setRect(rect); |
|
175 | m_backgroundItem->setRect(rect); | |
176 | if(m_bacgroundOrinetation==HorizonatlGradientOrientation) |
|
176 | if(m_bacgroundOrinetation==HorizonatlGradientOrientation) | |
177 | m_backgroundGradient.setFinalStop(m_backgroundItem->rect().width(),0); |
|
177 | m_backgroundGradient.setFinalStop(m_backgroundItem->rect().width(),0); | |
178 | else |
|
178 | else | |
179 | m_backgroundGradient.setFinalStop(0,m_backgroundItem->rect().height()); |
|
179 | m_backgroundGradient.setFinalStop(0,m_backgroundItem->rect().height()); | |
180 |
|
180 | |||
181 | m_backgroundItem->setBrush(m_backgroundGradient); |
|
181 | m_backgroundItem->setBrush(m_backgroundGradient); | |
182 | } |
|
182 | } | |
183 |
|
183 | |||
184 | //resize elements |
|
184 | //resize elements | |
185 | foreach (ChartItem* item ,m_chartItems) { |
|
185 | foreach (ChartItem* item ,m_chartItems) { | |
186 | item->setPos(rect.topLeft()); |
|
186 | item->setPos(rect.topLeft()); | |
187 | item->setSize(rect.size()); |
|
187 | item->setSize(rect.size()); | |
188 |
|
188 | |||
189 | } |
|
189 | } | |
190 | // TODO: TTD for setting scale |
|
190 | // TODO: TTD for setting scale | |
191 | //emit scaleChanged(100, 100); |
|
191 | //emit scaleChanged(100, 100); | |
192 | // TODO: calculate the origo |
|
192 | // TODO: calculate the origo | |
193 | // TODO: not sure if emitting a signal here is the best from performance point of view |
|
193 | // TODO: not sure if emitting a signal here is the best from performance point of view | |
194 | emit sizeChanged(QRectF(0, 0, size.width(), size.height())); |
|
194 | emit sizeChanged(QRectF(0, 0, size.width(), size.height())); | |
195 |
|
195 | |||
196 | update(); |
|
196 | update(); | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | void QChart::setBackground(const QColor& startColor, const QColor& endColor, GradientOrientation orientation) |
|
199 | void QChart::setBackground(const QColor& startColor, const QColor& endColor, GradientOrientation orientation) | |
200 | { |
|
200 | { | |
201 |
|
201 | |||
202 | if(!m_backgroundItem){ |
|
202 | if(!m_backgroundItem){ | |
203 | m_backgroundItem = new QGraphicsRectItem(this); |
|
203 | m_backgroundItem = new QGraphicsRectItem(this); | |
204 | m_backgroundItem->setZValue(-1); |
|
204 | m_backgroundItem->setZValue(-1); | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | m_bacgroundOrinetation = orientation; |
|
207 | m_bacgroundOrinetation = orientation; | |
208 | m_backgroundGradient.setColorAt( 0.0, startColor); |
|
208 | m_backgroundGradient.setColorAt( 0.0, startColor); | |
209 | m_backgroundGradient.setColorAt( 1.0, endColor); |
|
209 | m_backgroundGradient.setColorAt( 1.0, endColor); | |
210 | m_backgroundGradient.setStart(0,0); |
|
210 | m_backgroundGradient.setStart(0,0); | |
211 |
|
211 | |||
212 | if(orientation == VerticalGradientOrientation){ |
|
212 | if(orientation == VerticalGradientOrientation){ | |
213 | m_backgroundGradient.setFinalStop(0,m_rect.height()); |
|
213 | m_backgroundGradient.setFinalStop(0,m_rect.height()); | |
214 | }else{ |
|
214 | }else{ | |
215 | m_backgroundGradient.setFinalStop(m_rect.width(),0); |
|
215 | m_backgroundGradient.setFinalStop(m_rect.width(),0); | |
216 | } |
|
216 | } | |
217 |
|
217 | |||
218 | m_backgroundItem->setBrush(m_backgroundGradient); |
|
218 | m_backgroundItem->setBrush(m_backgroundGradient); | |
219 | m_backgroundItem->setPen(Qt::NoPen); |
|
219 | m_backgroundItem->setPen(Qt::NoPen); | |
220 | m_backgroundItem->update(); |
|
220 | m_backgroundItem->update(); | |
221 | } |
|
221 | } | |
222 |
|
222 | |||
223 | void QChart::setTitle(const QString& title,const QFont& font) |
|
223 | void QChart::setTitle(const QString& title,const QFont& font) | |
224 | { |
|
224 | { | |
225 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); |
|
225 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); | |
226 | m_titleItem->setPlainText(title); |
|
226 | m_titleItem->setPlainText(title); | |
227 | m_titleItem->setFont(font); |
|
227 | m_titleItem->setFont(font); | |
228 | } |
|
228 | } | |
229 |
|
229 | |||
230 | int QChart::margin() const |
|
230 | int QChart::margin() const | |
231 | { |
|
231 | { | |
232 | return m_marginSize; |
|
232 | return m_marginSize; | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | void QChart::setMargin(int margin) |
|
235 | void QChart::setMargin(int margin) | |
236 | { |
|
236 | { | |
237 | m_marginSize = margin; |
|
237 | m_marginSize = margin; | |
238 | } |
|
238 | } | |
239 |
|
239 | |||
240 | void QChart::setTheme(QChart::ChartThemeId theme) |
|
240 | void QChart::setTheme(QChart::ChartThemeId theme) | |
241 | { |
|
241 | { | |
242 | // if (theme != m_currentTheme) { |
|
242 | // if (theme != m_currentTheme) { | |
243 | m_themeColors.clear(); |
|
243 | m_themeColors.clear(); | |
244 |
|
244 | |||
245 | // TODO: define color themes |
|
245 | // TODO: define color themes | |
246 | switch (theme) { |
|
246 | switch (theme) { | |
247 | case QChart::ChartThemeDefault: |
|
247 | case QChart::ChartThemeDefault: | |
248 | // TODO: define the default theme based on the OS |
|
248 | // TODO: define the default theme based on the OS | |
249 | // For now we just fallthrough to "vanilla" |
|
249 | m_themeColors.append(QColor(QRgb(0xff000000))); | |
|
250 | m_themeColors.append(QColor(QRgb(0xff707070))); | |||
|
251 | setBackground(QColor(QRgb(0xffffffff)), QColor(QRgb(0xffafafaf)), VerticalGradientOrientation); | |||
|
252 | break; | |||
250 | case QChart::ChartThemeVanilla: |
|
253 | case QChart::ChartThemeVanilla: | |
251 | m_themeColors.append(QColor(217, 197, 116)); |
|
254 | m_themeColors.append(QColor(217, 197, 116)); | |
252 | m_themeColors.append(QColor(214, 168, 150)); |
|
255 | m_themeColors.append(QColor(214, 168, 150)); | |
253 | m_themeColors.append(QColor(160, 160, 113)); |
|
256 | m_themeColors.append(QColor(160, 160, 113)); | |
254 | m_themeColors.append(QColor(210, 210, 52)); |
|
257 | m_themeColors.append(QColor(210, 210, 52)); | |
255 | m_themeColors.append(QColor(136, 114, 58)); |
|
258 | m_themeColors.append(QColor(136, 114, 58)); | |
256 |
|
259 | |||
257 | m_backgroundGradient.setColorAt(0.0, QColor(QRgb(0xff9d844d))); |
|
260 | setBackground(QColor(QRgb(0xff9d844d)), QColor(QRgb(0xffafafaf)), VerticalGradientOrientation); | |
258 | m_backgroundGradient.setColorAt(1.0, QColor(QRgb(0xffafafaf))); |
|
|||
259 | break; |
|
261 | break; | |
260 | case QChart::ChartThemeIcy: |
|
262 | case QChart::ChartThemeIcy: | |
261 | m_themeColors.append(QColor(0, 3, 165)); |
|
263 | m_themeColors.append(QColor(0, 3, 165)); | |
262 | m_themeColors.append(QColor(49, 52, 123)); |
|
264 | m_themeColors.append(QColor(49, 52, 123)); | |
263 | m_themeColors.append(QColor(71, 114, 187)); |
|
265 | m_themeColors.append(QColor(71, 114, 187)); | |
264 | m_themeColors.append(QColor(48, 97, 87)); |
|
266 | m_themeColors.append(QColor(48, 97, 87)); | |
265 | m_themeColors.append(QColor(19, 71, 90)); |
|
267 | m_themeColors.append(QColor(19, 71, 90)); | |
266 | m_themeColors.append(QColor(110, 70, 228)); |
|
268 | m_themeColors.append(QColor(110, 70, 228)); | |
267 |
|
269 | |||
268 | m_backgroundGradient.setColorAt(0.0, QColor(QRgb(0xffe4ffff))); |
|
270 | setBackground(QColor(QRgb(0xffe4ffff)), QColor(QRgb(0xffe4ffff)), VerticalGradientOrientation); | |
269 | m_backgroundGradient.setColorAt(1.0, QColor(QRgb(0xffe4ffff))); |
|
|||
270 | break; |
|
271 | break; | |
271 | case QChart::ChartThemeGrayscale: |
|
272 | case QChart::ChartThemeGrayscale: | |
272 | m_themeColors.append(QColor(0, 0, 0)); |
|
273 | m_themeColors.append(QColor(0, 0, 0)); | |
273 | m_themeColors.append(QColor(50, 50, 50)); |
|
274 | m_themeColors.append(QColor(50, 50, 50)); | |
274 | m_themeColors.append(QColor(100, 100, 100)); |
|
275 | m_themeColors.append(QColor(100, 100, 100)); | |
275 | m_themeColors.append(QColor(140, 140, 140)); |
|
276 | m_themeColors.append(QColor(140, 140, 140)); | |
276 | m_themeColors.append(QColor(180, 180, 180)); |
|
277 | m_themeColors.append(QColor(180, 180, 180)); | |
277 |
|
278 | |||
278 | m_backgroundGradient.setColorAt(0.0, QColor(QRgb(0xffffffff))); |
|
279 | setBackground(QColor(QRgb(0xffffffff)), QColor(QRgb(0xffafafaf)), VerticalGradientOrientation); | |
279 | m_backgroundGradient.setColorAt(1.0, QColor(QRgb(0xffafafaf))); |
|
|||
280 | break; |
|
280 | break; | |
281 | case QChart::ChartThemeUnnamed1: |
|
281 | case QChart::ChartThemeUnnamed1: | |
282 | m_themeColors.append(QColor(QRgb(0xff3fa9f5))); |
|
282 | m_themeColors.append(QColor(QRgb(0xff3fa9f5))); | |
283 | m_themeColors.append(QColor(QRgb(0xff7AC943))); |
|
283 | m_themeColors.append(QColor(QRgb(0xff7AC943))); | |
284 | m_themeColors.append(QColor(QRgb(0xffFF931E))); |
|
284 | m_themeColors.append(QColor(QRgb(0xffFF931E))); | |
285 | m_themeColors.append(QColor(QRgb(0xffFF1D25))); |
|
285 | m_themeColors.append(QColor(QRgb(0xffFF1D25))); | |
286 | m_themeColors.append(QColor(QRgb(0xffFF7BAC))); |
|
286 | m_themeColors.append(QColor(QRgb(0xffFF7BAC))); | |
287 |
|
287 | |||
288 | m_backgroundGradient.setColorAt(0.0, QColor(QRgb(0xfff3dc9e))); |
|
288 | setBackground(QColor(QRgb(0xfff3dc9e)), QColor(QRgb(0xffafafaf)), VerticalGradientOrientation); | |
289 | m_backgroundGradient.setColorAt(1.0, QColor(QRgb(0xffafafaf))); |
|
|||
290 | break; |
|
289 | break; | |
291 | default: |
|
290 | default: | |
292 | Q_ASSERT(false); |
|
291 | Q_ASSERT(false); | |
293 | break; |
|
292 | break; | |
294 | } |
|
293 | } | |
295 |
|
294 | |||
296 | if(m_backgroundItem){ |
|
295 | if(m_backgroundItem){ | |
297 | m_backgroundItem->setBrush(m_backgroundGradient); |
|
296 | m_backgroundItem->setBrush(m_backgroundGradient); | |
298 | m_backgroundItem->setPen(Qt::NoPen); |
|
297 | m_backgroundItem->setPen(Qt::NoPen); | |
299 | } |
|
298 | } | |
300 |
|
299 | |||
301 | foreach(QChartSeries* series, m_chartSeries) { |
|
300 | foreach(QChartSeries* series, m_chartSeries) { | |
302 | // TODO: other series interested on themes? |
|
301 | // TODO: other series interested on themes? | |
303 | if (series->type() == QChartSeries::SeriesTypeLine) { |
|
302 | if (series->type() == QChartSeries::SeriesTypeLine) { | |
304 | QXYChartSeries *lineseries = reinterpret_cast<QXYChartSeries *>(series); |
|
303 | QXYChartSeries *lineseries = reinterpret_cast<QXYChartSeries *>(series); | |
305 | lineseries->setPen(nextColor()); |
|
304 | lineseries->setPen(nextColor()); | |
306 | } else if (series->type() == QChartSeries::SeriesTypeScatter) { |
|
305 | } else if (series->type() == QChartSeries::SeriesTypeScatter) { | |
307 | QScatterSeries *scatter = qobject_cast<QScatterSeries *>(series); |
|
306 | QScatterSeries *scatter = qobject_cast<QScatterSeries *>(series); | |
308 | scatter->setMarkerColor(nextColor()); |
|
307 | scatter->setMarkerColor(nextColor()); | |
309 | } else if (series->type() == QChartSeries::SeriesTypePie) { |
|
308 | } else if (series->type() == QChartSeries::SeriesTypePie) { | |
310 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); |
|
309 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); | |
311 | for (int i(0); i < pieSeries->sliceCount(); i++) |
|
310 | for (int i(0); i < pieSeries->sliceCount(); i++) | |
312 | pieSeries->setSliceColor(i, nextColor()); |
|
311 | pieSeries->setSliceColor(i, nextColor()); | |
313 | } |
|
312 | } | |
314 | } |
|
313 | } | |
315 | update(); |
|
314 | update(); | |
316 | } |
|
315 | } | |
317 |
|
316 | |||
318 | QColor QChart::nextColor() |
|
317 | QColor QChart::nextColor() | |
319 | { |
|
318 | { | |
320 | QColor nextColor = m_themeColors.first(); |
|
319 | QColor nextColor = m_themeColors.first(); | |
321 | m_themeColors.move(0, m_themeColors.size() - 1); |
|
320 | m_themeColors.move(0, m_themeColors.size() - 1); | |
322 | return nextColor; |
|
321 | return nextColor; | |
323 | } |
|
322 | } | |
324 |
|
323 | |||
325 | void QChart::zoomInToRect(const QRect& rectangle) |
|
324 | void QChart::zoomInToRect(const QRect& rectangle) | |
326 | { |
|
325 | { | |
327 |
|
326 | |||
328 | if(!rectangle.isValid()) return; |
|
327 | if(!rectangle.isValid()) return; | |
329 |
|
328 | |||
330 | qreal margin = this->margin(); |
|
329 | qreal margin = this->margin(); | |
331 |
|
330 | |||
332 | QRect rect = rectangle.normalized(); |
|
331 | QRect rect = rectangle.normalized(); | |
333 | rect.translate(-margin, -margin); |
|
332 | rect.translate(-margin, -margin); | |
334 |
|
333 | |||
335 | PlotDomain& oldDomain = m_plotDomainList[m_plotDataIndex]; |
|
334 | PlotDomain& oldDomain = m_plotDomainList[m_plotDataIndex]; | |
336 |
|
335 | |||
337 | 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); | |
338 |
|
337 | |||
339 | m_plotDomainList.resize(m_plotDataIndex + 1); |
|
338 | m_plotDomainList.resize(m_plotDataIndex + 1); | |
340 | m_plotDomainList<<domain; |
|
339 | m_plotDomainList<<domain; | |
341 | m_plotDataIndex++; |
|
340 | m_plotDataIndex++; | |
342 |
|
341 | |||
343 | foreach (ChartItem* item ,m_chartItems) |
|
342 | foreach (ChartItem* item ,m_chartItems) | |
344 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); |
|
343 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); | |
345 | update(); |
|
344 | update(); | |
346 | } |
|
345 | } | |
347 |
|
346 | |||
348 | void QChart::zoomIn() |
|
347 | void QChart::zoomIn() | |
349 | { |
|
348 | { | |
350 | if (m_plotDataIndex < m_plotDomainList.count() - 1) { |
|
349 | if (m_plotDataIndex < m_plotDomainList.count() - 1) { | |
351 | m_plotDataIndex++; |
|
350 | m_plotDataIndex++; | |
352 | foreach (ChartItem* item ,m_chartItems) |
|
351 | foreach (ChartItem* item ,m_chartItems) | |
353 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); |
|
352 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); | |
354 | update(); |
|
353 | update(); | |
355 | }else{ |
|
354 | }else{ | |
356 | QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
355 | QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
357 | rect.setWidth(rect.width()/2); |
|
356 | rect.setWidth(rect.width()/2); | |
358 | rect.setHeight(rect.height()/2); |
|
357 | rect.setHeight(rect.height()/2); | |
359 | rect.moveCenter(m_rect.center()); |
|
358 | rect.moveCenter(m_rect.center()); | |
360 | zoomInToRect(rect); |
|
359 | zoomInToRect(rect); | |
361 | } |
|
360 | } | |
362 | } |
|
361 | } | |
363 |
|
362 | |||
364 | void QChart::zoomOut() |
|
363 | void QChart::zoomOut() | |
365 | { |
|
364 | { | |
366 | if (m_plotDataIndex > 0) { |
|
365 | if (m_plotDataIndex > 0) { | |
367 | m_plotDataIndex--; |
|
366 | m_plotDataIndex--; | |
368 | foreach (ChartItem* item ,m_chartItems) |
|
367 | foreach (ChartItem* item ,m_chartItems) | |
369 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); |
|
368 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); | |
370 | update(); |
|
369 | update(); | |
371 | } |
|
370 | } | |
372 | } |
|
371 | } | |
373 |
|
372 | |||
374 | void QChart::setAxisX(const QChartAxis& axis) |
|
373 | void QChart::setAxisX(const QChartAxis& axis) | |
375 | { |
|
374 | { | |
376 | setAxis(m_axisXItem,axis); |
|
375 | setAxis(m_axisXItem,axis); | |
377 | } |
|
376 | } | |
378 | void QChart::setAxisY(const QChartAxis& axis) |
|
377 | void QChart::setAxisY(const QChartAxis& axis) | |
379 | { |
|
378 | { | |
380 | setAxis(m_axisYItem.at(0),axis); |
|
379 | setAxis(m_axisYItem.at(0),axis); | |
381 | } |
|
380 | } | |
382 |
|
381 | |||
383 | void QChart::setAxisY(const QList<QChartAxis>& axis) |
|
382 | void QChart::setAxisY(const QList<QChartAxis>& axis) | |
384 | { |
|
383 | { | |
385 | //TODO not implemented |
|
384 | //TODO not implemented | |
386 | } |
|
385 | } | |
387 |
|
386 | |||
388 | void QChart::setAxis(AxisItem *item, const QChartAxis& axis) |
|
387 | void QChart::setAxis(AxisItem *item, const QChartAxis& axis) | |
389 | { |
|
388 | { | |
390 | item->setVisible(axis.isAxisVisible()); |
|
389 | item->setVisible(axis.isAxisVisible()); | |
391 | } |
|
390 | } | |
392 |
|
391 | |||
393 | #include "moc_qchart.cpp" |
|
392 | #include "moc_qchart.cpp" | |
394 |
|
393 | |||
395 | QTCOMMERCIALCHART_END_NAMESPACE |
|
394 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,38 +1,40 | |||||
1 | #ifndef QSCATTERSERIES_H |
|
1 | #ifndef QSCATTERSERIES_H | |
2 | #define QSCATTERSERIES_H |
|
2 | #define QSCATTERSERIES_H | |
3 |
|
3 | |||
4 | #include "qchartseries.h" |
|
4 | #include "qchartseries.h" | |
5 | #include <QRectF> |
|
5 | #include <QRectF> | |
6 | #include <QColor> |
|
6 | #include <QColor> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 | class QScatterSeriesPrivate; |
|
9 | class QScatterSeriesPrivate; | |
10 |
|
10 | |||
11 | class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QChartSeries |
|
11 | class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QChartSeries | |
12 | { |
|
12 | { | |
13 | Q_OBJECT |
|
13 | Q_OBJECT | |
14 | public: |
|
14 | public: | |
15 | //QScatterSeries(QSeriesData *data, QObject *chart); |
|
15 | //QScatterSeries(QSeriesData *data, QObject *chart); | |
16 | QScatterSeries(QObject *parent = 0); |
|
16 | QScatterSeries(QObject *parent = 0); | |
17 | ~QScatterSeries(); |
|
17 | ~QScatterSeries(); | |
18 |
|
18 | |||
19 | public: // from QChartSeries |
|
19 | public: // from QChartSeries | |
20 | QChartSeriesType type() const { return QChartSeries::SeriesTypeScatter; } |
|
20 | QChartSeriesType type() const { return QChartSeries::SeriesTypeScatter; } | |
21 | bool setData(QList<qreal> x, QList<qreal> y); |
|
21 | bool setData(QList<qreal> x, QList<qreal> y); | |
22 |
|
22 | |||
23 | public Q_SLOTS: |
|
23 | public Q_SLOTS: | |
24 | void chartSizeChanged(QRectF rect); |
|
24 | void chartSizeChanged(QRectF rect); | |
|
25 | // TODO: also affects opacity of the marker...? To be documented | |||
25 | void setMarkerColor(QColor color); |
|
26 | void setMarkerColor(QColor color); | |
26 | QColor markerColor(); |
|
27 | QColor markerColor(); | |
27 | //void chartScaleChanged(qreal xscale, qreal yscale); |
|
28 | // TODO: marker shapes: "x", star, rectangle, tilted rect, triangle, circle, dot | |
|
29 | //void setMarkerShape(QChartSeries::MarkerShape/QScatterSeries::MarkerShape shape); | |||
28 |
|
30 | |||
29 | private: |
|
31 | private: | |
30 | Q_DECLARE_PRIVATE(QScatterSeries) |
|
32 | Q_DECLARE_PRIVATE(QScatterSeries) | |
31 | Q_DISABLE_COPY(QScatterSeries) |
|
33 | Q_DISABLE_COPY(QScatterSeries) | |
32 | friend class QChart; |
|
34 | friend class QChart; | |
33 | QScatterSeriesPrivate *const d; |
|
35 | QScatterSeriesPrivate *const d; | |
34 | }; |
|
36 | }; | |
35 |
|
37 | |||
36 | QTCOMMERCIALCHART_END_NAMESPACE |
|
38 | QTCOMMERCIALCHART_END_NAMESPACE | |
37 |
|
39 | |||
38 | #endif // QSCATTERSERIES_H |
|
40 | #endif // QSCATTERSERIES_H |
General Comments 0
You need to be logged in to leave comments.
Login now