##// END OF EJS Templates
Fixed line series usage in the test app
Tero Ahola -
r65:51e529f06d1a
parent child
Show More
@@ -49,6 +49,9 void QChart::addSeries(QChartSeries* series)
49 case QChartSeries::SeriesTypeLine: {
49 case QChartSeries::SeriesTypeLine: {
50
50
51 QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series);
51 QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series);
52 // Use color defined by theme in case the series does not define a custom color
53 if (!xyseries->color().isValid() && m_themeColors.count())
54 xyseries->setColor(m_themeColors.takeFirst());
52
55
53 XYPlotDomain domain;
56 XYPlotDomain domain;
54 //TODO "nice numbers algorithm"
57 //TODO "nice numbers algorithm"
@@ -71,16 +74,6 void QChart::addSeries(QChartSeries* series)
71 m_xyLineChartItems<<item;
74 m_xyLineChartItems<<item;
72 break;
75 break;
73 }
76 }
74 // TODO: Not tested:
75 // case QChartSeries::SeriesTypeScatter: {
76 // QScatterSeries *scatter = qobject_cast<QScatterSeries *>(series);
77 // if (scatter) {
78 // scatter->d->setParentItem(this);
79 // scene()->addItem(scatter->d);
80 // }
81 // break;
82 // }
83
84 case QChartSeries::SeriesTypeBar: {
77 case QChartSeries::SeriesTypeBar: {
85
78
86 qDebug() << "barSeries added";
79 qDebug() << "barSeries added";
@@ -92,39 +85,56 void QChart::addSeries(QChartSeries* series)
92 m_BarGroupItems.append(group); // If we need to access group later
85 m_BarGroupItems.append(group); // If we need to access group later
93 break;
86 break;
94 }
87 }
95 }
96 }
97
98 QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type)
99 {
100 // TODO: support also other types; not only scatter and pie
101
102 switch (type) {
103 case QChartSeries::SeriesTypeScatter: {
88 case QChartSeries::SeriesTypeScatter: {
104 QScatterSeries *scatterSeries = new QScatterSeries(this);
89 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
105 connect(this, SIGNAL(sizeChanged(QRectF)),
90 connect(this, SIGNAL(sizeChanged(QRectF)),
106 scatterSeries, SLOT(chartSizeChanged(QRectF)));
91 scatterSeries, SLOT(chartSizeChanged(QRectF)));
107 scatterSeries->d->setParentItem(this);
92 scatterSeries->d->setParentItem(this);
108 QColor nextColor = m_themeColors.takeFirst();
93 QColor nextColor = m_themeColors.takeFirst();
109 nextColor.setAlpha(150); // TODO: default opacity?
94 nextColor.setAlpha(150); // TODO: default opacity?
110 scatterSeries->setMarkerColor(nextColor);
95 scatterSeries->setMarkerColor(nextColor);
111 return scatterSeries;
112 }
96 }
113 case QChartSeries::SeriesTypePie: {
97 case QChartSeries::SeriesTypePie: {
114 // TODO: we now have also a list of y values as a parameter, it is ignored
98 // TODO: we now have also a list of y values as a parameter, it is ignored
115 // we should use a generic data class instead of list of x and y values
99 // we should use a generic data class instead of list of x and y values
116 QPieSeries *pieSeries = new QPieSeries(this);
100 QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series);
117 connect(this, SIGNAL(sizeChanged(QRectF)),
101 connect(this, SIGNAL(sizeChanged(QRectF)),
118 pieSeries, SLOT(chartSizeChanged(QRectF)));
102 pieSeries, SLOT(chartSizeChanged(QRectF)));
119 // TODO: how to define the color for all the slices of a pie?
103 // TODO: how to define the color for all the slices of a pie?
120 return pieSeries;
104 }
105 }
106 }
107
108 QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type)
109 {
110 // TODO: support also other types; not only scatter and pie
111
112 QChartSeries *series(0);
113
114 switch (type) {
115 case QChartSeries::SeriesTypeLine: {
116 series = QXYChartSeries::create();
117 break;
118 }
119 case QChartSeries::SeriesTypeBar: {
120 series = new BarChartSeries(this);
121 break;
122 }
123 case QChartSeries::SeriesTypeScatter: {
124 series = new QScatterSeries(this);
125 break;
126 }
127 case QChartSeries::SeriesTypePie: {
128 series = new QPieSeries(this);
129 break;
121 }
130 }
122 default:
131 default:
123 Q_ASSERT(false);
132 Q_ASSERT(false);
124 break;
133 break;
125 }
134 }
126
135
127 return 0;
136 addSeries(series);
137 return series;
128 }
138 }
129
139
130 void QChart::setSize(const QSizeF& size)
140 void QChart::setSize(const QSizeF& size)
@@ -3,7 +3,7
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
4
5 QXYChartSeries::QXYChartSeries(QObject* parent):QChartSeries(parent),
5 QXYChartSeries::QXYChartSeries(QObject* parent):QChartSeries(parent),
6 m_color(Qt::black)
6 m_color()
7 {
7 {
8 }
8 }
9
9
@@ -170,8 +170,19 void MainWidget::addSeries(QString series, QString data)
170 newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie);
170 newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie);
171 Q_ASSERT(newSeries->setData(y));
171 Q_ASSERT(newSeries->setData(y));
172 } else if (series == "Line") {
172 } else if (series == "Line") {
173 newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie);
173 // TODO: adding data to an existing line series does not give any visuals for some reason
174 Q_ASSERT(newSeries->setData(x, y));
174 // newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeLine);
175 // QXYChartSeries *lineSeries = static_cast<QXYChartSeries *>(newSeries);
176 // lineSeries->setColor(Qt::blue);
177 // for (int i(0); i < x.count() && i < y.count(); i++) {
178 // lineSeries->add(x.at(i), y.at(i));
179 // }
180 //Q_ASSERT(newSeries->setData(x, y));
181 QXYChartSeries* series0 = QXYChartSeries::create();
182 for (int i(0); i < x.count() && i < y.count(); i++)
183 series0->add(x.at(i), y.at(i));
184 m_chartWidget->addSeries(series0);
185 newSeries = series0;
175 } else {
186 } else {
176 // TODO
187 // TODO
177 }
188 }
General Comments 0
You need to be logged in to leave comments. Login now