##// END OF EJS Templates
Enabled chartwidgettest again
Tero Ahola -
r815:95ff7d5d8d6a
parent child
Show More
@@ -1,8 +1,9
1 1 #include "mainwidget.h"
2 2 #include "dataseriedialog.h"
3 #include <qpieseries.h>
4 #include <qscatterseries.h>
5 #include <qlineseries.h>
3 #include "qchartview.h"
4 #include "qpieseries.h"
5 #include "qscatterseries.h"
6 #include "qlineseries.h"
6 7 #include <qareaseries.h>
7 8 #include <qsplineseries.h>
8 9 #include <qbarset.h>
@@ -28,10 +29,9 QTCOMMERCIALCHART_USE_NAMESPACE
28 29 MainWidget::MainWidget(QWidget *parent) :
29 30 QWidget(parent),
30 31 m_addSerieDialog(0),
31 m_chartView(0)
32 m_chart(0)
32 33 {
33 m_chartView = new QChartView(this);
34 m_chartView->setRubberBandPolicy(QChartView::HorizonalRubberBand);
34 m_chart = new QChart();
35 35
36 36 // Grid layout for the controls for configuring the chart widget
37 37 QGridLayout *grid = new QGridLayout();
@@ -47,11 +47,13 MainWidget::MainWidget(QWidget *parent) :
47 47 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
48 48 grid->setRowStretch(grid->rowCount() - 1, 1);
49 49
50 // Create chart view with the chart
51 m_chartView = new QChartView(m_chart, this);
52 m_chartView->setRubberBand(QChartView::HorizonalRubberBand);
53
50 54 // Another grid layout as a main layout
51 55 QGridLayout *mainLayout = new QGridLayout();
52 56 mainLayout->addLayout(grid, 0, 0);
53
54 // Add layouts and the chart widget to the main layout
55 57 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
56 58 setLayout(mainLayout);
57 59 }
@@ -133,7 +135,7 void MainWidget::initCheckboxes(QGridLayout *grid)
133 135 {
134 136 // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off
135 137 QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
136 connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool)));
138 // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool)));
137 139 zoomCheckBox->setChecked(true);
138 140 grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
139 141
@@ -208,40 +210,36 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QS
208 210 for (int j(0); j < data.count(); j ++) {
209 211 QList<qreal> column = data.at(j);
210 212 QLineSeries *series = new QLineSeries();
211 for (int i(0); i < column.count(); i++) {
212 series->add(i, column.at(i));
213 }
214 m_chartView->addSeries(series);
213 for (int i(0); i < column.count(); i++)
214 series->append(i, column.at(i));
215 m_chart->addSeries(series);
215 216 }
216 217 } else if (seriesName == "Area") {
217 218 // TODO: lower series for the area?
218 219 for (int j(0); j < data.count(); j ++) {
219 220 QList<qreal> column = data.at(j);
220 221 QLineSeries *lineSeries = new QLineSeries();
221 for (int i(0); i < column.count(); i++) {
222 lineSeries->add(i, column.at(i));
223 }
222 for (int i(0); i < column.count(); i++)
223 lineSeries->append(i, column.at(i));
224 224 QAreaSeries *areaSeries = new QAreaSeries(lineSeries);
225 m_chartView->addSeries(areaSeries);
225 m_chart->addSeries(areaSeries);
226 226 }
227 227 } else if (seriesName == "Scatter") {
228 228 for (int j(0); j < data.count(); j++) {
229 229 QList<qreal> column = data.at(j);
230 230 QScatterSeries *series = new QScatterSeries();
231 for (int i(0); i < column.count(); i++) {
232 (*series) << QPointF(i, column.at(i));
233 }
234 m_chartView->addSeries(series);
231 for (int i(0); i < column.count(); i++)
232 series->append(i, column.at(i));
233 m_chart->addSeries(series);
235 234 }
236 235 } else if (seriesName == "Pie") {
237 236 QStringList labels = generateLabels(rowCount);
238 237 for (int j(0); j < data.count(); j++) {
239 238 QPieSeries *series = new QPieSeries();
240 239 QList<qreal> column = data.at(j);
241 for (int i(0); i < column.count(); i++) {
242 series->add(column.at(i), labels.at(i));
243 }
244 m_chartView->addSeries(series);
240 for (int i(0); i < column.count(); i++)
241 series->append(column.at(i), labels.at(i));
242 m_chart->addSeries(series);
245 243 }
246 244 } else if (seriesName == "Bar"
247 245 || seriesName == "Stacked bar"
@@ -261,24 +259,22 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QS
261 259 for (int j(0); j < data.count(); j++) {
262 260 QList<qreal> column = data.at(j);
263 261 QBarSet *set = new QBarSet("set" + QString::number(j));
264 for (int i(0); i < column.count(); i++) {
262 for (int i(0); i < column.count(); i++)
265 263 *set << column.at(i);
266 }
267 series->addBarSet(set);
264 series->appendBarSet(set);
268 265 }
269 266
270 267 // TODO: new implementation of setFloatingValuesEnabled with signals
271 268 //series->setFloatingValuesEnabled(true);
272 269 series->setToolTipEnabled(true);
273 m_chartView->addSeries(series);
270 m_chart->addSeries(series);
274 271 } else if (seriesName == "Spline") {
275 272 for (int j(0); j < data.count(); j ++) {
276 273 QList<qreal> column = data.at(j);
277 274 QSplineSeries *series = new QSplineSeries();
278 for (int i(0); i < column.count(); i++) {
279 series->add(i, column.at(i));
280 }
281 m_chartView->addSeries(series);
275 for (int i(0); i < column.count(); i++)
276 series->append(i, column.at(i));
277 m_chart->addSeries(series);
282 278 }
283 279 }
284 280 }
@@ -325,7 +321,7 void MainWidget::yMaxChanged(int value)
325 321 void MainWidget::changeChartTheme(int themeIndex)
326 322 {
327 323 qDebug() << "changeChartTheme: " << themeIndex;
328 m_chartView->setChartTheme((QChart::ChartTheme) themeIndex);
324 m_chart->setTheme((QChart::ChartTheme) themeIndex);
329 325 //TODO: remove this hack. This is just to make it so that theme change is seen immediately.
330 326 QSize s = size();
331 327 s.setWidth(s.width()+1);
@@ -1,8 +1,9
1 1 #ifndef MAINWIDGET_H
2 2 #define MAINWIDGET_H
3 3
4 #include <qchartglobal.h>
5 #include <qchartview.h>
4 #include "qchartglobal.h"
5 #include "qchart.h"
6 #include "qchartview.h"
6 7 #include <QWidget>
7 8
8 9 class QSpinBox;
@@ -44,6 +45,7 private slots:
44 45
45 46 private:
46 47 DataSerieDialog *m_addSerieDialog;
48 QChart *m_chart;
47 49 QChartView *m_chartView;
48 50 QCheckBox *m_autoScaleCheck;
49 51 QSpinBox *m_xMinSpin;
@@ -1,6 +1,6
1 1 TEMPLATE = subdirs
2 2 SUBDIRS += \
3 #chartwidgettest \
3 chartwidgettest \
4 4 qmlchart
5 5
6 6 !win32:{
General Comments 0
You need to be logged in to leave comments. Login now