##// END OF EJS Templates
Checkbox for anti-alias to chartwidgettest
Tero Ahola -
r379:ef3b0565576e
parent child
Show More
@@ -26,10 +26,10 QTCOMMERCIALCHART_USE_NAMESPACE
26 MainWidget::MainWidget(QWidget *parent) :
26 MainWidget::MainWidget(QWidget *parent) :
27 QWidget(parent),
27 QWidget(parent),
28 m_addSerieDialog(0),
28 m_addSerieDialog(0),
29 m_chartWidget(0)
29 m_chartView(0)
30 {
30 {
31 m_chartWidget = new QChartView(this);
31 m_chartView = new QChartView(this);
32 m_chartWidget->setRubberBandPolicy(QChartView::HorizonalRubberBand);
32 m_chartView->setRubberBandPolicy(QChartView::HorizonalRubberBand);
33
33
34 // Grid layout for the controls for configuring the chart widget
34 // Grid layout for the controls for configuring the chart widget
35 QGridLayout *grid = new QGridLayout();
35 QGridLayout *grid = new QGridLayout();
@@ -39,10 +39,8 MainWidget::MainWidget(QWidget *parent) :
39 initBackroundCombo(grid);
39 initBackroundCombo(grid);
40 initScaleControls(grid);
40 initScaleControls(grid);
41 initThemeCombo(grid);
41 initThemeCombo(grid);
42 QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
42 initCheckboxes(grid);
43 connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartWidget, SLOT(setZoomEnabled(bool)));
43
44 zoomCheckBox->setChecked(true);
45 grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
46 // add row with empty label to make all the other rows static
44 // add row with empty label to make all the other rows static
47 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
45 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
48 grid->setRowStretch(grid->rowCount() - 1, 1);
46 grid->setRowStretch(grid->rowCount() - 1, 1);
@@ -61,7 +59,7 MainWidget::MainWidget(QWidget *parent) :
61 // mainLayout->addLayout(m_scatterLayout, 1, 0);
59 // mainLayout->addLayout(m_scatterLayout, 1, 0);
62
60
63 // Add layouts and the chart widget to the main layout
61 // Add layouts and the chart widget to the main layout
64 mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1);
62 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
65 setLayout(mainLayout);
63 setLayout(mainLayout);
66 }
64 }
67
65
@@ -135,6 +133,26 void MainWidget::initThemeCombo(QGridLayout *grid)
135 grid->addWidget(chartTheme, 8, 1);
133 grid->addWidget(chartTheme, 8, 1);
136 }
134 }
137
135
136 // Different check boxes for customizing chart
137 void MainWidget::initCheckboxes(QGridLayout *grid)
138 {
139 // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off
140 QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
141 connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool)));
142 zoomCheckBox->setChecked(true);
143 grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
144
145 QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias");
146 connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool)));
147 aliasCheckBox->setChecked(false);
148 grid->addWidget(aliasCheckBox, grid->rowCount(), 0);
149 }
150
151 void MainWidget::antiAliasToggled(bool enabled)
152 {
153 m_chartView->setRenderHint(QPainter::Antialiasing, enabled);
154 }
155
138 void MainWidget::initPieControls()
156 void MainWidget::initPieControls()
139 {
157 {
140 // Pie series specific settings
158 // Pie series specific settings
@@ -225,7 +243,7 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QS
225 for (int i(0); i < column.count(); i++) {
243 for (int i(0); i < column.count(); i++) {
226 series->add(i, column.at(i));
244 series->add(i, column.at(i));
227 }
245 }
228 m_chartWidget->addSeries(series);
246 m_chartView->addSeries(series);
229 setCurrentSeries(series);
247 setCurrentSeries(series);
230 }
248 }
231 } else if (seriesName.contains("scatter", Qt::CaseInsensitive)) {
249 } else if (seriesName.contains("scatter", Qt::CaseInsensitive)) {
@@ -235,7 +253,7 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QS
235 for (int i(0); i < column.count(); i++) {
253 for (int i(0); i < column.count(); i++) {
236 (*series) << QPointF(i, column.at(i));
254 (*series) << QPointF(i, column.at(i));
237 }
255 }
238 m_chartWidget->addSeries(series);
256 m_chartView->addSeries(series);
239 setCurrentSeries(series);
257 setCurrentSeries(series);
240 }
258 }
241 } else if (seriesName.contains("pie", Qt::CaseInsensitive)) {
259 } else if (seriesName.contains("pie", Qt::CaseInsensitive)) {
@@ -246,7 +264,7 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QS
246 for (int i(0); i < column.count(); i++) {
264 for (int i(0); i < column.count(); i++) {
247 series->add(column.at(i), labels.at(i));
265 series->add(column.at(i), labels.at(i));
248 }
266 }
249 m_chartWidget->addSeries(series);
267 m_chartView->addSeries(series);
250 setCurrentSeries(series);
268 setCurrentSeries(series);
251 }
269 }
252 } else if (seriesName == "Bar"
270 } else if (seriesName == "Bar"
@@ -275,7 +293,7 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QS
275 series->setFloatingValuesEnabled(true);
293 series->setFloatingValuesEnabled(true);
276 series->setToolTipEnabled(true);
294 series->setToolTipEnabled(true);
277 series->setSeparatorsEnabled(false);
295 series->setSeparatorsEnabled(false);
278 m_chartWidget->addSeries(series);
296 m_chartView->addSeries(series);
279 setCurrentSeries(series);
297 setCurrentSeries(series);
280 }
298 }
281
299
@@ -351,7 +369,7 void MainWidget::yMaxChanged(int value)
351 void MainWidget::changeChartTheme(int themeIndex)
369 void MainWidget::changeChartTheme(int themeIndex)
352 {
370 {
353 qDebug() << "changeChartTheme: " << themeIndex;
371 qDebug() << "changeChartTheme: " << themeIndex;
354 m_chartWidget->setChartTheme((QChart::ChartTheme) themeIndex);
372 m_chartView->setChartTheme((QChart::ChartTheme) themeIndex);
355 //TODO: remove this hack. This is just to make it so that theme change is seen immediately.
373 //TODO: remove this hack. This is just to make it so that theme change is seen immediately.
356 QSize s = size();
374 QSize s = size();
357 s.setWidth(s.width()+1);
375 s.setWidth(s.width()+1);
@@ -26,6 +26,7 private:
26 void initBackroundCombo(QGridLayout *grid);
26 void initBackroundCombo(QGridLayout *grid);
27 void initScaleControls(QGridLayout *grid);
27 void initScaleControls(QGridLayout *grid);
28 void initThemeCombo(QGridLayout *grid);
28 void initThemeCombo(QGridLayout *grid);
29 void initCheckboxes(QGridLayout *grid);
29 void initPieControls();
30 void initPieControls();
30
31
31 private slots:
32 private slots:
@@ -37,6 +38,7 private slots:
37 void xMaxChanged(int value);
38 void xMaxChanged(int value);
38 void yMinChanged(int value);
39 void yMinChanged(int value);
39 void yMaxChanged(int value);
40 void yMaxChanged(int value);
41 void antiAliasToggled(bool enabled);
40 void setCurrentSeries(QSeries *series);
42 void setCurrentSeries(QSeries *series);
41 void changeChartTheme(int themeIndex);
43 void changeChartTheme(int themeIndex);
42 void setPieSizeFactor(double margin);
44 void setPieSizeFactor(double margin);
@@ -46,7 +48,7 private slots:
46
48
47 private:
49 private:
48 DataSerieDialog *m_addSerieDialog;
50 DataSerieDialog *m_addSerieDialog;
49 QChartView *m_chartWidget;
51 QChartView *m_chartView;
50 QCheckBox *m_autoScaleCheck;
52 QCheckBox *m_autoScaleCheck;
51 QSpinBox *m_xMinSpin;
53 QSpinBox *m_xMinSpin;
52 QSpinBox *m_xMaxSpin;
54 QSpinBox *m_xMaxSpin;
General Comments 0
You need to be logged in to leave comments. Login now