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