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