@@ -1,111 +1,112 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "tablewidget.h" |
|
21 | #include "tablewidget.h" | |
22 | #include "customtablemodel.h" |
|
22 | #include "customtablemodel.h" | |
23 | #include <QGridLayout> |
|
23 | #include <QGridLayout> | |
24 | #include <QTableView> |
|
24 | #include <QTableView> | |
25 | #include <QChart> |
|
25 | #include <QChart> | |
26 | #include <QChartView> |
|
26 | #include <QChartView> | |
27 | #include <QLineSeries> |
|
27 | #include <QLineSeries> | |
28 | #include <QVXYModelMapper> |
|
28 | #include <QVXYModelMapper> | |
29 | #include <QHeaderView> |
|
29 | #include <QHeaderView> | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
31 | QTCOMMERCIALCHART_USE_NAMESPACE | |
32 |
|
32 | |||
33 | TableWidget::TableWidget(QWidget *parent) |
|
33 | TableWidget::TableWidget(QWidget *parent) | |
34 | : QWidget(parent) |
|
34 | : QWidget(parent) | |
35 | { |
|
35 | { | |
36 | // create simple model for storing data |
|
36 | // create simple model for storing data | |
37 | // user's table data model |
|
37 | // user's table data model | |
38 | //! [1] |
|
38 | //! [1] | |
39 | CustomTableModel *model = new CustomTableModel; |
|
39 | CustomTableModel *model = new CustomTableModel; | |
40 | //! [1] |
|
40 | //! [1] | |
41 |
|
41 | |||
42 | //! [2] |
|
42 | //! [2] | |
43 | // create table view and add model to it |
|
43 | // create table view and add model to it | |
44 | QTableView *tableView = new QTableView; |
|
44 | QTableView *tableView = new QTableView; | |
45 | tableView->setModel(model); |
|
45 | tableView->setModel(model); | |
46 | tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); |
|
46 | tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); | |
47 | tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); |
|
47 | tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); | |
48 | //! [2] |
|
48 | //! [2] | |
49 |
|
49 | |||
50 | //! [3] |
|
50 | //! [3] | |
51 | QChart *chart = new QChart; |
|
51 | QChart *chart = new QChart; | |
52 | chart->setAnimationOptions(QChart::AllAnimations); |
|
52 | chart->setAnimationOptions(QChart::AllAnimations); | |
53 | //! [3] |
|
53 | //! [3] | |
54 |
|
54 | |||
55 | // series 1 |
|
55 | // series 1 | |
56 | //! [4] |
|
56 | //! [4] | |
57 | QLineSeries *series = new QLineSeries; |
|
57 | QLineSeries *series = new QLineSeries; | |
58 | series->setName("Line 1"); |
|
58 | series->setName("Line 1"); | |
59 | QVXYModelMapper *mapper = new QVXYModelMapper(this); |
|
59 | QVXYModelMapper *mapper = new QVXYModelMapper(this); | |
60 | mapper->setXColumn(0); |
|
60 | mapper->setXColumn(0); | |
61 | mapper->setYColumn(1); |
|
61 | mapper->setYColumn(1); | |
62 | mapper->setSeries(series); |
|
62 | mapper->setSeries(series); | |
63 | mapper->setModel(model); |
|
63 | mapper->setModel(model); | |
64 | chart->addSeries(series); |
|
64 | chart->addSeries(series); | |
65 | //! [4] |
|
65 | //! [4] | |
66 |
|
66 | |||
67 | //! [5] |
|
67 | //! [5] | |
68 | // for storing color hex from the series |
|
68 | // for storing color hex from the series | |
69 | QString seriesColorHex = "#000000"; |
|
69 | QString seriesColorHex = "#000000"; | |
70 |
|
70 | |||
71 | // get the color of the series and use it for showing the mapped area |
|
71 | // get the color of the series and use it for showing the mapped area | |
72 | seriesColorHex = "#" + QString::number(series->pen().color().rgb(), 16).right(6).toUpper(); |
|
72 | seriesColorHex = "#" + QString::number(series->pen().color().rgb(), 16).right(6).toUpper(); | |
73 | model->addMapping(seriesColorHex, QRect(0, 0, 2, model->rowCount())); |
|
73 | model->addMapping(seriesColorHex, QRect(0, 0, 2, model->rowCount())); | |
74 | //! [5] |
|
74 | //! [5] | |
75 |
|
75 | |||
76 |
|
76 | |||
77 | // series 2 |
|
77 | // series 2 | |
78 | //! [6] |
|
78 | //! [6] | |
79 | series = new QLineSeries; |
|
79 | series = new QLineSeries; | |
80 | series->setName("Line 2"); |
|
80 | series->setName("Line 2"); | |
81 |
|
81 | |||
82 | mapper = new QVXYModelMapper(this); |
|
82 | mapper = new QVXYModelMapper(this); | |
83 | mapper->setXColumn(2); |
|
83 | mapper->setXColumn(2); | |
84 | mapper->setYColumn(3); |
|
84 | mapper->setYColumn(3); | |
85 | mapper->setSeries(series); |
|
85 | mapper->setSeries(series); | |
86 | mapper->setModel(model); |
|
86 | mapper->setModel(model); | |
87 | chart->addSeries(series); |
|
87 | chart->addSeries(series); | |
88 | //! [6] |
|
88 | //! [6] | |
89 |
|
89 | |||
90 | //! [7] |
|
90 | //! [7] | |
91 | // get the color of the series and use it for showing the mapped area |
|
91 | // get the color of the series and use it for showing the mapped area | |
92 | seriesColorHex = "#" + QString::number(series->pen().color().rgb(), 16).right(6).toUpper(); |
|
92 | seriesColorHex = "#" + QString::number(series->pen().color().rgb(), 16).right(6).toUpper(); | |
93 | model->addMapping(seriesColorHex, QRect(2, 0, 2, model->rowCount())); |
|
93 | model->addMapping(seriesColorHex, QRect(2, 0, 2, model->rowCount())); | |
94 | //! [7] |
|
94 | //! [7] | |
95 |
|
95 | |||
96 | //! [8] |
|
96 | //! [8] | |
|
97 | chart->createDefaultAxes(); | |||
97 | QChartView *chartView = new QChartView(chart); |
|
98 | QChartView *chartView = new QChartView(chart); | |
98 | chartView->setRenderHint(QPainter::Antialiasing); |
|
99 | chartView->setRenderHint(QPainter::Antialiasing); | |
99 | chartView->setMinimumSize(640, 480); |
|
100 | chartView->setMinimumSize(640, 480); | |
100 | //! [8] |
|
101 | //! [8] | |
101 |
|
102 | |||
102 | //! [9] |
|
103 | //! [9] | |
103 | // create main layout |
|
104 | // create main layout | |
104 | QGridLayout* mainLayout = new QGridLayout; |
|
105 | QGridLayout* mainLayout = new QGridLayout; | |
105 | mainLayout->addWidget(tableView, 1, 0); |
|
106 | mainLayout->addWidget(tableView, 1, 0); | |
106 | mainLayout->addWidget(chartView, 1, 1); |
|
107 | mainLayout->addWidget(chartView, 1, 1); | |
107 | mainLayout->setColumnStretch(1, 1); |
|
108 | mainLayout->setColumnStretch(1, 1); | |
108 | mainLayout->setColumnStretch(0, 0); |
|
109 | mainLayout->setColumnStretch(0, 0); | |
109 | setLayout(mainLayout); |
|
110 | setLayout(mainLayout); | |
110 | //! [9] |
|
111 | //! [9] | |
111 | } |
|
112 | } |
@@ -1,363 +1,364 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "mainwidget.h" |
|
21 | #include "mainwidget.h" | |
22 | #include "dataseriedialog.h" |
|
22 | #include "dataseriedialog.h" | |
23 | #include "qchartview.h" |
|
23 | #include "qchartview.h" | |
24 | #include "qpieseries.h" |
|
24 | #include "qpieseries.h" | |
25 | #include "qscatterseries.h" |
|
25 | #include "qscatterseries.h" | |
26 | #include "qlineseries.h" |
|
26 | #include "qlineseries.h" | |
27 | #include <qareaseries.h> |
|
27 | #include <qareaseries.h> | |
28 | #include <qsplineseries.h> |
|
28 | #include <qsplineseries.h> | |
29 | #include <qbarset.h> |
|
29 | #include <qbarset.h> | |
30 | #include <qbarseries.h> |
|
30 | #include <qbarseries.h> | |
31 | #include <qgroupedbarseries.h> |
|
31 | #include <qgroupedbarseries.h> | |
32 | #include <qstackedbarseries.h> |
|
32 | #include <qstackedbarseries.h> | |
33 | #include <qpercentbarseries.h> |
|
33 | #include <qpercentbarseries.h> | |
34 | #include <QPushButton> |
|
34 | #include <QPushButton> | |
35 | #include <QComboBox> |
|
35 | #include <QComboBox> | |
36 | #include <QSpinBox> |
|
36 | #include <QSpinBox> | |
37 | #include <QCheckBox> |
|
37 | #include <QCheckBox> | |
38 | #include <QGridLayout> |
|
38 | #include <QGridLayout> | |
39 | #include <QHBoxLayout> |
|
39 | #include <QHBoxLayout> | |
40 | #include <QLabel> |
|
40 | #include <QLabel> | |
41 | #include <QSpacerItem> |
|
41 | #include <QSpacerItem> | |
42 | #include <QMessageBox> |
|
42 | #include <QMessageBox> | |
43 | #include <cmath> |
|
43 | #include <cmath> | |
44 | #include <QDebug> |
|
44 | #include <QDebug> | |
45 | #include <QStandardItemModel> |
|
45 | #include <QStandardItemModel> | |
46 | #include <QCategoriesAxis> |
|
46 | #include <QCategoriesAxis> | |
47 |
|
47 | |||
48 |
|
48 | |||
49 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
49 | QTCOMMERCIALCHART_USE_NAMESPACE | |
50 |
|
50 | |||
51 | MainWidget::MainWidget(QWidget *parent) : |
|
51 | MainWidget::MainWidget(QWidget *parent) : | |
52 | QWidget(parent), |
|
52 | QWidget(parent), | |
53 | m_addSerieDialog(0), |
|
53 | m_addSerieDialog(0), | |
54 | m_chart(0) |
|
54 | m_chart(0) | |
55 | { |
|
55 | { | |
56 | m_chart = new QChart(); |
|
56 | m_chart = new QChart(); | |
57 |
|
57 | |||
58 | // Grid layout for the controls for configuring the chart widget |
|
58 | // Grid layout for the controls for configuring the chart widget | |
59 | QGridLayout *grid = new QGridLayout(); |
|
59 | QGridLayout *grid = new QGridLayout(); | |
60 | QPushButton *addSeriesButton = new QPushButton("Add series"); |
|
60 | QPushButton *addSeriesButton = new QPushButton("Add series"); | |
61 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
61 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); | |
62 | grid->addWidget(addSeriesButton, 0, 1); |
|
62 | grid->addWidget(addSeriesButton, 0, 1); | |
63 | initBackroundCombo(grid); |
|
63 | initBackroundCombo(grid); | |
64 | initScaleControls(grid); |
|
64 | initScaleControls(grid); | |
65 | initThemeCombo(grid); |
|
65 | initThemeCombo(grid); | |
66 | initCheckboxes(grid); |
|
66 | initCheckboxes(grid); | |
67 |
|
67 | |||
68 | // add row with empty label to make all the other rows static |
|
68 | // add row with empty label to make all the other rows static | |
69 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); |
|
69 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); | |
70 | grid->setRowStretch(grid->rowCount() - 1, 1); |
|
70 | grid->setRowStretch(grid->rowCount() - 1, 1); | |
71 |
|
71 | |||
72 | // Create chart view with the chart |
|
72 | // Create chart view with the chart | |
73 | m_chartView = new QChartView(m_chart, this); |
|
73 | m_chartView = new QChartView(m_chart, this); | |
74 | m_chartView->setRubberBand(QChartView::HorizonalRubberBand); |
|
74 | m_chartView->setRubberBand(QChartView::HorizonalRubberBand); | |
75 |
|
75 | |||
76 | // Another grid layout as a main layout |
|
76 | // Another grid layout as a main layout | |
77 | QGridLayout *mainLayout = new QGridLayout(); |
|
77 | QGridLayout *mainLayout = new QGridLayout(); | |
78 | mainLayout->addLayout(grid, 0, 0); |
|
78 | mainLayout->addLayout(grid, 0, 0); | |
79 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); |
|
79 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); | |
80 | setLayout(mainLayout); |
|
80 | setLayout(mainLayout); | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | // Combo box for selecting the chart's background |
|
83 | // Combo box for selecting the chart's background | |
84 | void MainWidget::initBackroundCombo(QGridLayout *grid) |
|
84 | void MainWidget::initBackroundCombo(QGridLayout *grid) | |
85 | { |
|
85 | { | |
86 | QComboBox *backgroundCombo = new QComboBox(this); |
|
86 | QComboBox *backgroundCombo = new QComboBox(this); | |
87 | backgroundCombo->addItem("Color"); |
|
87 | backgroundCombo->addItem("Color"); | |
88 | backgroundCombo->addItem("Gradient"); |
|
88 | backgroundCombo->addItem("Gradient"); | |
89 | backgroundCombo->addItem("Image"); |
|
89 | backgroundCombo->addItem("Image"); | |
90 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
90 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), | |
91 | this, SLOT(backgroundChanged(int))); |
|
91 | this, SLOT(backgroundChanged(int))); | |
92 |
|
92 | |||
93 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); |
|
93 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); | |
94 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); |
|
94 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | // Scale related controls (auto-scale vs. manual min-max values) |
|
97 | // Scale related controls (auto-scale vs. manual min-max values) | |
98 | void MainWidget::initScaleControls(QGridLayout *grid) |
|
98 | void MainWidget::initScaleControls(QGridLayout *grid) | |
99 | { |
|
99 | { | |
100 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
100 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); | |
101 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
101 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); | |
102 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
102 | // Allow setting also non-sense values (like -2147483648 and 2147483647) | |
103 | m_xMinSpin = new QSpinBox(); |
|
103 | m_xMinSpin = new QSpinBox(); | |
104 | m_xMinSpin->setMinimum(INT_MIN); |
|
104 | m_xMinSpin->setMinimum(INT_MIN); | |
105 | m_xMinSpin->setMaximum(INT_MAX); |
|
105 | m_xMinSpin->setMaximum(INT_MAX); | |
106 | m_xMinSpin->setValue(0); |
|
106 | m_xMinSpin->setValue(0); | |
107 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
107 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); | |
108 | m_xMaxSpin = new QSpinBox(); |
|
108 | m_xMaxSpin = new QSpinBox(); | |
109 | m_xMaxSpin->setMinimum(INT_MIN); |
|
109 | m_xMaxSpin->setMinimum(INT_MIN); | |
110 | m_xMaxSpin->setMaximum(INT_MAX); |
|
110 | m_xMaxSpin->setMaximum(INT_MAX); | |
111 | m_xMaxSpin->setValue(10); |
|
111 | m_xMaxSpin->setValue(10); | |
112 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
112 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); | |
113 | m_yMinSpin = new QSpinBox(); |
|
113 | m_yMinSpin = new QSpinBox(); | |
114 | m_yMinSpin->setMinimum(INT_MIN); |
|
114 | m_yMinSpin->setMinimum(INT_MIN); | |
115 | m_yMinSpin->setMaximum(INT_MAX); |
|
115 | m_yMinSpin->setMaximum(INT_MAX); | |
116 | m_yMinSpin->setValue(0); |
|
116 | m_yMinSpin->setValue(0); | |
117 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
117 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); | |
118 | m_yMaxSpin = new QSpinBox(); |
|
118 | m_yMaxSpin = new QSpinBox(); | |
119 | m_yMaxSpin->setMinimum(INT_MIN); |
|
119 | m_yMaxSpin->setMinimum(INT_MIN); | |
120 | m_yMaxSpin->setMaximum(INT_MAX); |
|
120 | m_yMaxSpin->setMaximum(INT_MAX); | |
121 | m_yMaxSpin->setValue(10); |
|
121 | m_yMaxSpin->setValue(10); | |
122 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
122 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); | |
123 |
|
123 | |||
124 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); |
|
124 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); | |
125 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); |
|
125 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); | |
126 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); |
|
126 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); | |
127 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); |
|
127 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); | |
128 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); |
|
128 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); | |
129 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); |
|
129 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); | |
130 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); |
|
130 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); | |
131 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); |
|
131 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); | |
132 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); |
|
132 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); | |
133 |
|
133 | |||
134 | m_autoScaleCheck->setChecked(true); |
|
134 | m_autoScaleCheck->setChecked(true); | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | // Combo box for selecting theme |
|
137 | // Combo box for selecting theme | |
138 | void MainWidget::initThemeCombo(QGridLayout *grid) |
|
138 | void MainWidget::initThemeCombo(QGridLayout *grid) | |
139 | { |
|
139 | { | |
140 | QComboBox *chartTheme = new QComboBox(); |
|
140 | QComboBox *chartTheme = new QComboBox(); | |
141 | chartTheme->addItem("Default"); |
|
141 | chartTheme->addItem("Default"); | |
142 | chartTheme->addItem("Light"); |
|
142 | chartTheme->addItem("Light"); | |
143 | chartTheme->addItem("Blue Cerulean"); |
|
143 | chartTheme->addItem("Blue Cerulean"); | |
144 | chartTheme->addItem("Dark"); |
|
144 | chartTheme->addItem("Dark"); | |
145 | chartTheme->addItem("Brown Sand"); |
|
145 | chartTheme->addItem("Brown Sand"); | |
146 | chartTheme->addItem("Blue NCS"); |
|
146 | chartTheme->addItem("Blue NCS"); | |
147 | chartTheme->addItem("High Contrast"); |
|
147 | chartTheme->addItem("High Contrast"); | |
148 | chartTheme->addItem("Blue Icy"); |
|
148 | chartTheme->addItem("Blue Icy"); | |
149 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
149 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), | |
150 | this, SLOT(changeChartTheme(int))); |
|
150 | this, SLOT(changeChartTheme(int))); | |
151 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); |
|
151 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); | |
152 | grid->addWidget(chartTheme, 8, 1); |
|
152 | grid->addWidget(chartTheme, 8, 1); | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | // Different check boxes for customizing chart |
|
155 | // Different check boxes for customizing chart | |
156 | void MainWidget::initCheckboxes(QGridLayout *grid) |
|
156 | void MainWidget::initCheckboxes(QGridLayout *grid) | |
157 | { |
|
157 | { | |
158 | // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off |
|
158 | // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off | |
159 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); |
|
159 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); | |
160 | // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool))); |
|
160 | // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool))); | |
161 | zoomCheckBox->setChecked(true); |
|
161 | zoomCheckBox->setChecked(true); | |
162 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); |
|
162 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); | |
163 |
|
163 | |||
164 | QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias"); |
|
164 | QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias"); | |
165 | connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool))); |
|
165 | connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool))); | |
166 | aliasCheckBox->setChecked(false); |
|
166 | aliasCheckBox->setChecked(false); | |
167 | grid->addWidget(aliasCheckBox, grid->rowCount(), 0); |
|
167 | grid->addWidget(aliasCheckBox, grid->rowCount(), 0); | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | void MainWidget::antiAliasToggled(bool enabled) |
|
170 | void MainWidget::antiAliasToggled(bool enabled) | |
171 | { |
|
171 | { | |
172 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); |
|
172 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); | |
173 | } |
|
173 | } | |
174 |
|
174 | |||
175 | void MainWidget::addSeries() |
|
175 | void MainWidget::addSeries() | |
176 | { |
|
176 | { | |
177 | if (!m_addSerieDialog) { |
|
177 | if (!m_addSerieDialog) { | |
178 | m_addSerieDialog = new DataSerieDialog(this); |
|
178 | m_addSerieDialog = new DataSerieDialog(this); | |
179 | connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)), |
|
179 | connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)), | |
180 | this, SLOT(addSeries(QString,int,int,QString,bool))); |
|
180 | this, SLOT(addSeries(QString,int,int,QString,bool))); | |
181 | } |
|
181 | } | |
182 | m_addSerieDialog->exec(); |
|
182 | m_addSerieDialog->exec(); | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) |
|
185 | QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) | |
186 | { |
|
186 | { | |
187 | // TODO: dataCharacteristics |
|
187 | // TODO: dataCharacteristics | |
188 | QList<RealList> testData; |
|
188 | QList<RealList> testData; | |
189 | for (int j(0); j < columnCount; j++) { |
|
189 | for (int j(0); j < columnCount; j++) { | |
190 | QList <qreal> newColumn; |
|
190 | QList <qreal> newColumn; | |
191 | for (int i(0); i < rowCount; i++) { |
|
191 | for (int i(0); i < rowCount; i++) { | |
192 | if (dataCharacteristics == "Sin") { |
|
192 | if (dataCharacteristics == "Sin") { | |
193 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); |
|
193 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); | |
194 | } else if (dataCharacteristics == "Sin + random") { |
|
194 | } else if (dataCharacteristics == "Sin + random") { | |
195 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); |
|
195 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); | |
196 | } else if (dataCharacteristics == "Random") { |
|
196 | } else if (dataCharacteristics == "Random") { | |
197 | newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX); |
|
197 | newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX); | |
198 | } else if (dataCharacteristics == "Linear") { |
|
198 | } else if (dataCharacteristics == "Linear") { | |
199 | //newColumn.append(i * (j + 1.0)); |
|
199 | //newColumn.append(i * (j + 1.0)); | |
200 | // TODO: temporary hack to make pie work; prevent zero values: |
|
200 | // TODO: temporary hack to make pie work; prevent zero values: | |
201 | newColumn.append(i * (j + 1.0) + 0.1); |
|
201 | newColumn.append(i * (j + 1.0) + 0.1); | |
202 | } else { // "constant" |
|
202 | } else { // "constant" | |
203 | newColumn.append((j + 1.0)); |
|
203 | newColumn.append((j + 1.0)); | |
204 | } |
|
204 | } | |
205 | } |
|
205 | } | |
206 | testData.append(newColumn); |
|
206 | testData.append(newColumn); | |
207 | } |
|
207 | } | |
208 | return testData; |
|
208 | return testData; | |
209 | } |
|
209 | } | |
210 |
|
210 | |||
211 | QStringList MainWidget::generateLabels(int count) |
|
211 | QStringList MainWidget::generateLabels(int count) | |
212 | { |
|
212 | { | |
213 | QStringList result; |
|
213 | QStringList result; | |
214 | for (int i(0); i < count; i++) |
|
214 | for (int i(0); i < count; i++) | |
215 | result.append("label" + QString::number(i)); |
|
215 | result.append("label" + QString::number(i)); | |
216 | return result; |
|
216 | return result; | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 | void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) |
|
219 | void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) | |
220 | { |
|
220 | { | |
221 | qDebug() << "addSeries: " << seriesName |
|
221 | qDebug() << "addSeries: " << seriesName | |
222 | << " columnCount: " << columnCount |
|
222 | << " columnCount: " << columnCount | |
223 | << " rowCount: " << rowCount |
|
223 | << " rowCount: " << rowCount | |
224 | << " dataCharacteristics: " << dataCharacteristics |
|
224 | << " dataCharacteristics: " << dataCharacteristics | |
225 | << " labels enabled: " << labelsEnabled; |
|
225 | << " labels enabled: " << labelsEnabled; | |
226 | m_defaultSeriesName = seriesName; |
|
226 | m_defaultSeriesName = seriesName; | |
227 |
|
227 | |||
228 | QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); |
|
228 | QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); | |
229 |
|
229 | |||
230 | // Line series and scatter series use similar data |
|
230 | // Line series and scatter series use similar data | |
231 | if (seriesName == "Line") { |
|
231 | if (seriesName == "Line") { | |
232 | for (int j(0); j < data.count(); j ++) { |
|
232 | for (int j(0); j < data.count(); j ++) { | |
233 | QList<qreal> column = data.at(j); |
|
233 | QList<qreal> column = data.at(j); | |
234 | QLineSeries *series = new QLineSeries(); |
|
234 | QLineSeries *series = new QLineSeries(); | |
235 | series->setName("line" + QString::number(j)); |
|
235 | series->setName("line" + QString::number(j)); | |
236 | for (int i(0); i < column.count(); i++) |
|
236 | for (int i(0); i < column.count(); i++) | |
237 | series->append(i, column.at(i)); |
|
237 | series->append(i, column.at(i)); | |
238 | m_chart->addSeries(series); |
|
238 | m_chart->addSeries(series); | |
239 | } |
|
239 | } | |
240 | } else if (seriesName == "Area") { |
|
240 | } else if (seriesName == "Area") { | |
241 | // TODO: lower series for the area? |
|
241 | // TODO: lower series for the area? | |
242 | for (int j(0); j < data.count(); j ++) { |
|
242 | for (int j(0); j < data.count(); j ++) { | |
243 | QList<qreal> column = data.at(j); |
|
243 | QList<qreal> column = data.at(j); | |
244 | QLineSeries *lineSeries = new QLineSeries(); |
|
244 | QLineSeries *lineSeries = new QLineSeries(); | |
245 | for (int i(0); i < column.count(); i++) |
|
245 | for (int i(0); i < column.count(); i++) | |
246 | lineSeries->append(i, column.at(i)); |
|
246 | lineSeries->append(i, column.at(i)); | |
247 | QAreaSeries *areaSeries = new QAreaSeries(lineSeries); |
|
247 | QAreaSeries *areaSeries = new QAreaSeries(lineSeries); | |
248 | areaSeries->setName("area" + QString::number(j)); |
|
248 | areaSeries->setName("area" + QString::number(j)); | |
249 | m_chart->addSeries(areaSeries); |
|
249 | m_chart->addSeries(areaSeries); | |
250 | } |
|
250 | } | |
251 | } else if (seriesName == "Scatter") { |
|
251 | } else if (seriesName == "Scatter") { | |
252 | for (int j(0); j < data.count(); j++) { |
|
252 | for (int j(0); j < data.count(); j++) { | |
253 | QList<qreal> column = data.at(j); |
|
253 | QList<qreal> column = data.at(j); | |
254 | QScatterSeries *series = new QScatterSeries(); |
|
254 | QScatterSeries *series = new QScatterSeries(); | |
255 | series->setName("scatter" + QString::number(j)); |
|
255 | series->setName("scatter" + QString::number(j)); | |
256 | for (int i(0); i < column.count(); i++) |
|
256 | for (int i(0); i < column.count(); i++) | |
257 | series->append(i, column.at(i)); |
|
257 | series->append(i, column.at(i)); | |
258 | m_chart->addSeries(series); |
|
258 | m_chart->addSeries(series); | |
259 | } |
|
259 | } | |
260 | } else if (seriesName == "Pie") { |
|
260 | } else if (seriesName == "Pie") { | |
261 | QStringList labels = generateLabels(rowCount); |
|
261 | QStringList labels = generateLabels(rowCount); | |
262 | for (int j(0); j < data.count(); j++) { |
|
262 | for (int j(0); j < data.count(); j++) { | |
263 | QPieSeries *series = new QPieSeries(); |
|
263 | QPieSeries *series = new QPieSeries(); | |
264 | QList<qreal> column = data.at(j); |
|
264 | QList<qreal> column = data.at(j); | |
265 | for (int i(0); i < column.count(); i++) |
|
265 | for (int i(0); i < column.count(); i++) | |
266 | series->append(labels.at(i), column.at(i)); |
|
266 | series->append(labels.at(i), column.at(i)); | |
267 | m_chart->addSeries(series); |
|
267 | m_chart->addSeries(series); | |
268 | } |
|
268 | } | |
269 | } else if (seriesName == "Bar" |
|
269 | } else if (seriesName == "Bar" | |
270 | || seriesName == "Grouped bar" |
|
270 | || seriesName == "Grouped bar" | |
271 | || seriesName == "Stacked bar" |
|
271 | || seriesName == "Stacked bar" | |
272 | || seriesName == "Percent bar") { |
|
272 | || seriesName == "Percent bar") { | |
273 | QStringList category; |
|
273 | QStringList category; | |
274 | QStringList labels = generateLabels(rowCount); |
|
274 | QStringList labels = generateLabels(rowCount); | |
275 | foreach(QString label, labels) |
|
275 | foreach(QString label, labels) | |
276 | category << label; |
|
276 | category << label; | |
277 | QBarSeries* series = 0; |
|
277 | QBarSeries* series = 0; | |
278 | if (seriesName == "Bar") { |
|
278 | if (seriesName == "Bar") { | |
279 | series = new QBarSeries(this); |
|
279 | series = new QBarSeries(this); | |
280 | QCategoriesAxis* axis = new QCategoriesAxis(); |
|
280 | QCategoriesAxis* axis = new QCategoriesAxis(); | |
281 | axis->append(category); |
|
281 | axis->append(category); | |
282 | m_chart->setAxisX(axis,series); |
|
282 | m_chart->setAxisX(axis,series); | |
283 | } else if (seriesName == "Grouped bar") { |
|
283 | } else if (seriesName == "Grouped bar") { | |
284 | series = new QGroupedBarSeries(this); |
|
284 | series = new QGroupedBarSeries(this); | |
285 | QCategoriesAxis* axis = new QCategoriesAxis(); |
|
285 | QCategoriesAxis* axis = new QCategoriesAxis(); | |
286 | axis->append(category); |
|
286 | axis->append(category); | |
287 | m_chart->setAxisX(axis,series); |
|
287 | m_chart->setAxisX(axis,series); | |
288 | } else if (seriesName == "Stacked bar") { |
|
288 | } else if (seriesName == "Stacked bar") { | |
289 | series = new QStackedBarSeries(this); |
|
289 | series = new QStackedBarSeries(this); | |
290 | QCategoriesAxis* axis = new QCategoriesAxis(); |
|
290 | QCategoriesAxis* axis = new QCategoriesAxis(); | |
291 | axis->append(category); |
|
291 | axis->append(category); | |
292 | m_chart->setAxisX(axis,series); |
|
292 | m_chart->setAxisX(axis,series); | |
293 | } else { |
|
293 | } else { | |
294 | series = new QPercentBarSeries(this); |
|
294 | series = new QPercentBarSeries(this); | |
295 | QCategoriesAxis* axis = new QCategoriesAxis(); |
|
295 | QCategoriesAxis* axis = new QCategoriesAxis(); | |
296 | axis->append(category); |
|
296 | axis->append(category); | |
297 | m_chart->setAxisX(axis,series); |
|
297 | m_chart->setAxisX(axis,series); | |
298 | } |
|
298 | } | |
299 |
|
299 | |||
300 | for (int j(0); j < data.count(); j++) { |
|
300 | for (int j(0); j < data.count(); j++) { | |
301 | QList<qreal> column = data.at(j); |
|
301 | QList<qreal> column = data.at(j); | |
302 | QBarSet *set = new QBarSet("set" + QString::number(j)); |
|
302 | QBarSet *set = new QBarSet("set" + QString::number(j)); | |
303 | for (int i(0); i < column.count(); i++) |
|
303 | for (int i(0); i < column.count(); i++) | |
304 | *set << column.at(i); |
|
304 | *set << column.at(i); | |
305 | series->append(set); |
|
305 | series->append(set); | |
306 | } |
|
306 | } | |
307 |
|
307 | |||
308 | m_chart->addSeries(series); |
|
308 | m_chart->addSeries(series); | |
309 | } else if (seriesName == "Spline") { |
|
309 | } else if (seriesName == "Spline") { | |
310 | for (int j(0); j < data.count(); j ++) { |
|
310 | for (int j(0); j < data.count(); j ++) { | |
311 | QList<qreal> column = data.at(j); |
|
311 | QList<qreal> column = data.at(j); | |
312 | QSplineSeries *series = new QSplineSeries(); |
|
312 | QSplineSeries *series = new QSplineSeries(); | |
313 | for (int i(0); i < column.count(); i++) |
|
313 | for (int i(0); i < column.count(); i++) | |
314 | series->append(i, column.at(i)); |
|
314 | series->append(i, column.at(i)); | |
315 | m_chart->addSeries(series); |
|
315 | m_chart->addSeries(series); | |
316 | } |
|
316 | } | |
317 | } |
|
317 | } | |
|
318 | m_chart->createDefaultAxes(); | |||
318 | } |
|
319 | } | |
319 |
|
320 | |||
320 | void MainWidget::backgroundChanged(int itemIndex) |
|
321 | void MainWidget::backgroundChanged(int itemIndex) | |
321 | { |
|
322 | { | |
322 | qDebug() << "backgroundChanged: " << itemIndex; |
|
323 | qDebug() << "backgroundChanged: " << itemIndex; | |
323 | } |
|
324 | } | |
324 |
|
325 | |||
325 | void MainWidget::autoScaleChanged(int value) |
|
326 | void MainWidget::autoScaleChanged(int value) | |
326 | { |
|
327 | { | |
327 | if (value) { |
|
328 | if (value) { | |
328 | // TODO: enable auto scaling |
|
329 | // TODO: enable auto scaling | |
329 | } else { |
|
330 | } else { | |
330 | // TODO: set scaling manually (and disable auto scaling) |
|
331 | // TODO: set scaling manually (and disable auto scaling) | |
331 | } |
|
332 | } | |
332 |
|
333 | |||
333 | m_xMinSpin->setEnabled(!value); |
|
334 | m_xMinSpin->setEnabled(!value); | |
334 | m_xMaxSpin->setEnabled(!value); |
|
335 | m_xMaxSpin->setEnabled(!value); | |
335 | m_yMinSpin->setEnabled(!value); |
|
336 | m_yMinSpin->setEnabled(!value); | |
336 | m_yMaxSpin->setEnabled(!value); |
|
337 | m_yMaxSpin->setEnabled(!value); | |
337 | } |
|
338 | } | |
338 |
|
339 | |||
339 | void MainWidget::xMinChanged(int value) |
|
340 | void MainWidget::xMinChanged(int value) | |
340 | { |
|
341 | { | |
341 | qDebug() << "xMinChanged: " << value; |
|
342 | qDebug() << "xMinChanged: " << value; | |
342 | } |
|
343 | } | |
343 |
|
344 | |||
344 | void MainWidget::xMaxChanged(int value) |
|
345 | void MainWidget::xMaxChanged(int value) | |
345 | { |
|
346 | { | |
346 | qDebug() << "xMaxChanged: " << value; |
|
347 | qDebug() << "xMaxChanged: " << value; | |
347 | } |
|
348 | } | |
348 |
|
349 | |||
349 | void MainWidget::yMinChanged(int value) |
|
350 | void MainWidget::yMinChanged(int value) | |
350 | { |
|
351 | { | |
351 | qDebug() << "yMinChanged: " << value; |
|
352 | qDebug() << "yMinChanged: " << value; | |
352 | } |
|
353 | } | |
353 |
|
354 | |||
354 | void MainWidget::yMaxChanged(int value) |
|
355 | void MainWidget::yMaxChanged(int value) | |
355 | { |
|
356 | { | |
356 | qDebug() << "yMaxChanged: " << value; |
|
357 | qDebug() << "yMaxChanged: " << value; | |
357 | } |
|
358 | } | |
358 |
|
359 | |||
359 | void MainWidget::changeChartTheme(int themeIndex) |
|
360 | void MainWidget::changeChartTheme(int themeIndex) | |
360 | { |
|
361 | { | |
361 | qDebug() << "changeChartTheme: " << themeIndex; |
|
362 | qDebug() << "changeChartTheme: " << themeIndex; | |
362 | m_chart->setTheme((QChart::ChartTheme) themeIndex); |
|
363 | m_chart->setTheme((QChart::ChartTheme) themeIndex); | |
363 | } |
|
364 | } |
General Comments 0
You need to be logged in to leave comments.
Login now